cobject.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. CObjects are marked Pending Deprecation as of Python 2.7.
  3. The full schedule for 2.x is as follows:
  4. - CObjects are marked Pending Deprecation in Python 2.7.
  5. - CObjects will be marked Deprecated in Python 2.8
  6. (if there is one).
  7. - CObjects will be removed in Python 2.9 (if there is one).
  8. Additionally, for the Python 3.x series:
  9. - CObjects were marked Deprecated in Python 3.1.
  10. - CObjects will be removed in Python 3.2.
  11. You should switch all use of CObjects to capsules. Capsules
  12. have a safer and more consistent API. For more information,
  13. see Include/pycapsule.h, or read the "Capsules" topic in
  14. the "Python/C API Reference Manual".
  15. Python 2.7 no longer uses CObjects itself; all objects which
  16. were formerly CObjects are now capsules. Note that this change
  17. does not by itself break binary compatibility with extensions
  18. built for previous versions of Python--PyCObject_AsVoidPtr()
  19. has been changed to also understand capsules.
  20. */
  21. /* original file header comment follows: */
  22. /* C objects to be exported from one extension module to another.
  23. C objects are used for communication between extension modules.
  24. They provide a way for an extension module to export a C interface
  25. to other extension modules, so that extension modules can use the
  26. Python import mechanism to link to one another.
  27. */
  28. #ifndef Py_COBJECT_H
  29. #define Py_COBJECT_H
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. PyAPI_DATA(PyTypeObject) PyCObject_Type;
  34. #define PyCObject_Check(op) (Py_TYPE(op) == &PyCObject_Type)
  35. /* Create a PyCObject from a pointer to a C object and an optional
  36. destructor function. If the second argument is non-null, then it
  37. will be called with the first argument if and when the PyCObject is
  38. destroyed.
  39. */
  40. PyAPI_FUNC(PyObject *) PyCObject_FromVoidPtr(
  41. void *cobj, void (*destruct)(void*));
  42. /* Create a PyCObject from a pointer to a C object, a description object,
  43. and an optional destructor function. If the third argument is non-null,
  44. then it will be called with the first and second arguments if and when
  45. the PyCObject is destroyed.
  46. */
  47. PyAPI_FUNC(PyObject *) PyCObject_FromVoidPtrAndDesc(
  48. void *cobj, void *desc, void (*destruct)(void*,void*));
  49. /* Retrieve a pointer to a C object from a PyCObject. */
  50. PyAPI_FUNC(void *) PyCObject_AsVoidPtr(PyObject *);
  51. /* Retrieve a pointer to a description object from a PyCObject. */
  52. PyAPI_FUNC(void *) PyCObject_GetDesc(PyObject *);
  53. /* Import a pointer to a C object from a module using a PyCObject. */
  54. PyAPI_FUNC(void *) PyCObject_Import(char *module_name, char *cobject_name);
  55. /* Modify a C object. Fails (==0) if object has a destructor. */
  56. PyAPI_FUNC(int) PyCObject_SetVoidPtr(PyObject *self, void *cobj);
  57. typedef struct {
  58. PyObject_HEAD
  59. void *cobject;
  60. void *desc;
  61. void (*destructor)(void *);
  62. } PyCObject;
  63. #ifdef __cplusplus
  64. }
  65. #endif
  66. #endif /* !Py_COBJECT_H */