pycapsule.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* Capsule objects let you wrap a C "void *" pointer in a Python
  2. object. They're a way of passing data through the Python interpreter
  3. without creating your own custom type.
  4. Capsules are used for communication between extension modules.
  5. They provide a way for an extension module to export a C interface
  6. to other extension modules, so that extension modules can use the
  7. Python import mechanism to link to one another.
  8. For more information, please see "c-api/capsule.html" in the
  9. documentation.
  10. */
  11. #ifndef Py_CAPSULE_H
  12. #define Py_CAPSULE_H
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. PyAPI_DATA(PyTypeObject) PyCapsule_Type;
  17. typedef void (*PyCapsule_Destructor)(PyObject *);
  18. #define PyCapsule_CheckExact(op) (Py_TYPE(op) == &PyCapsule_Type)
  19. PyAPI_FUNC(PyObject *) PyCapsule_New(
  20. void *pointer,
  21. const char *name,
  22. PyCapsule_Destructor destructor);
  23. PyAPI_FUNC(void *) PyCapsule_GetPointer(PyObject *capsule, const char *name);
  24. PyAPI_FUNC(PyCapsule_Destructor) PyCapsule_GetDestructor(PyObject *capsule);
  25. PyAPI_FUNC(const char *) PyCapsule_GetName(PyObject *capsule);
  26. PyAPI_FUNC(void *) PyCapsule_GetContext(PyObject *capsule);
  27. PyAPI_FUNC(int) PyCapsule_IsValid(PyObject *capsule, const char *name);
  28. PyAPI_FUNC(int) PyCapsule_SetPointer(PyObject *capsule, void *pointer);
  29. PyAPI_FUNC(int) PyCapsule_SetDestructor(PyObject *capsule, PyCapsule_Destructor destructor);
  30. PyAPI_FUNC(int) PyCapsule_SetName(PyObject *capsule, const char *name);
  31. PyAPI_FUNC(int) PyCapsule_SetContext(PyObject *capsule, void *context);
  32. PyAPI_FUNC(void *) PyCapsule_Import(
  33. const char *name, /* UTF-8 encoded string */
  34. int no_block);
  35. #ifdef __cplusplus
  36. }
  37. #endif
  38. #endif /* !Py_CAPSULE_H */