pycobject.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #ifndef Py_COBJECT_H
  2. #define Py_COBJECT_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. PyAPI_DATA(PyTypeObject) PyCObject_Type;
  7. #define PyCObject_Check(op) ((op)->ob_type == &PyCObject_Type)
  8. /* Create a PyCObject from a pointer to a C object and an optional
  9. destructor function. If the second argument is non-null, then it
  10. will be called with the first argument if and when the PyCObject is
  11. destroyed.
  12. */
  13. PyAPI_FUNC(PyObject *) PyCObject_FromVoidPtr(
  14. void *cobj, void (*destruct)(void*));
  15. /* Create a PyCObject from a pointer to a C object, a description object,
  16. and an optional destructor function. If the third argument is non-null,
  17. then it will be called with the first and second arguments if and when
  18. the PyCObject is destroyed.
  19. */
  20. PyAPI_FUNC(PyObject *) PyCObject_FromVoidPtrAndDesc(
  21. void *cobj, void *desc, void (*destruct)(void*,void*));
  22. /* Retrieve a pointer to a C object from a PyCObject. */
  23. PyAPI_FUNC(void *) PyCObject_AsVoidPtr(PyObject *);
  24. /* Retrieve a pointer to a description object from a PyCObject. */
  25. PyAPI_FUNC(void *) PyCObject_GetDesc(PyObject *);
  26. /* Import a pointer to a C object from a module using a PyCObject. */
  27. PyAPI_FUNC(void *) PyCObject_Import(const char *module_name, const char *cobject_name);
  28. /* Modify a C object. Fails (==0) if object has a destructor. */
  29. PyAPI_FUNC(int) PyCObject_SetVoidPtr(PyObject *self, void *cobj);
  30. #if (PY_VERSION_HEX >= 0x02060000 || defined(Py_BUILD_CORE))
  31. typedef struct {
  32. PyObject_HEAD
  33. void *cobject;
  34. void *desc;
  35. void (*destructor)(void *);
  36. } PyCObject;
  37. #endif
  38. PyAPI_FUNC(PyTypeObject *) _Py_get_cobject_type(void);
  39. #ifdef __cplusplus
  40. }
  41. #endif
  42. #endif /* !Py_COBJECT_H */