/Doc/c-api/cobject.rst

http://unladen-swallow.googlecode.com/ · ReStructuredText · 56 lines · 31 code · 25 blank · 0 comment · 0 complexity · eb05a3eaa806d11ad81deeb27c3473e8 MD5 · raw file

  1. .. highlightlang:: c
  2. .. _cobjects:
  3. CObjects
  4. --------
  5. .. index:: object: CObject
  6. Refer to :ref:`using-cobjects` for more information on using these objects.
  7. .. ctype:: PyCObject
  8. This subtype of :ctype:`PyObject` represents an opaque value, useful for C
  9. extension modules who need to pass an opaque value (as a :ctype:`void\*`
  10. pointer) through Python code to other C code. It is often used to make a C
  11. function pointer defined in one module available to other modules, so the
  12. regular import mechanism can be used to access C APIs defined in dynamically
  13. loaded modules.
  14. .. cfunction:: int PyCObject_Check(PyObject *p)
  15. Return true if its argument is a :ctype:`PyCObject`.
  16. .. cfunction:: PyObject* PyCObject_FromVoidPtr(void* cobj, void (*destr)(void *))
  17. Create a :ctype:`PyCObject` from the ``void *`` *cobj*. The *destr* function
  18. will be called when the object is reclaimed, unless it is *NULL*.
  19. .. cfunction:: PyObject* PyCObject_FromVoidPtrAndDesc(void* cobj, void* desc, void (*destr)(void *, void *))
  20. Create a :ctype:`PyCObject` from the :ctype:`void \*` *cobj*. The *destr*
  21. function will be called when the object is reclaimed. The *desc* argument can
  22. be used to pass extra callback data for the destructor function.
  23. .. cfunction:: void* PyCObject_AsVoidPtr(PyObject* self)
  24. Return the object :ctype:`void \*` that the :ctype:`PyCObject` *self* was
  25. created with.
  26. .. cfunction:: void* PyCObject_GetDesc(PyObject* self)
  27. Return the description :ctype:`void \*` that the :ctype:`PyCObject` *self* was
  28. created with.
  29. .. cfunction:: int PyCObject_SetVoidPtr(PyObject* self, void* cobj)
  30. Set the void pointer inside *self* to *cobj*. The :ctype:`PyCObject` must not
  31. have an associated destructor. Return true on success, false on failure.