/Doc/includes/noddy.c

http://unladen-swallow.googlecode.com/ · C · 54 lines · 46 code · 7 blank · 1 comment · 1 complexity · 1314f7681acd02c60316680f62dcebb8 MD5 · raw file

  1. #include <Python.h>
  2. typedef struct {
  3. PyObject_HEAD
  4. /* Type-specific fields go here. */
  5. } noddy_NoddyObject;
  6. static PyTypeObject noddy_NoddyType = {
  7. PyObject_HEAD_INIT(NULL)
  8. 0, /*ob_size*/
  9. "noddy.Noddy", /*tp_name*/
  10. sizeof(noddy_NoddyObject), /*tp_basicsize*/
  11. 0, /*tp_itemsize*/
  12. 0, /*tp_dealloc*/
  13. 0, /*tp_print*/
  14. 0, /*tp_getattr*/
  15. 0, /*tp_setattr*/
  16. 0, /*tp_compare*/
  17. 0, /*tp_repr*/
  18. 0, /*tp_as_number*/
  19. 0, /*tp_as_sequence*/
  20. 0, /*tp_as_mapping*/
  21. 0, /*tp_hash */
  22. 0, /*tp_call*/
  23. 0, /*tp_str*/
  24. 0, /*tp_getattro*/
  25. 0, /*tp_setattro*/
  26. 0, /*tp_as_buffer*/
  27. Py_TPFLAGS_DEFAULT, /*tp_flags*/
  28. "Noddy objects", /* tp_doc */
  29. };
  30. static PyMethodDef noddy_methods[] = {
  31. {NULL} /* Sentinel */
  32. };
  33. #ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
  34. #define PyMODINIT_FUNC void
  35. #endif
  36. PyMODINIT_FUNC
  37. initnoddy(void)
  38. {
  39. PyObject* m;
  40. noddy_NoddyType.tp_new = PyType_GenericNew;
  41. if (PyType_Ready(&noddy_NoddyType) < 0)
  42. return;
  43. m = Py_InitModule3("noddy", noddy_methods,
  44. "Example module that creates an extension type.");
  45. Py_INCREF(&noddy_NoddyType);
  46. PyModule_AddObject(m, "Noddy", (PyObject *)&noddy_NoddyType);
  47. }