blob: eafac0e7b4bf1933a74d25130dc2699ecaa256c2 [file] [log] [blame]
Georg Brandlf6842722008-01-19 22:08:21 +00001.. highlightlang:: c
2
3.. _cobjects:
4
5CObjects
6--------
7
8.. index:: object: CObject
9
Georg Brandlf6842722008-01-19 22:08:21 +000010
Larry Hastings402b73f2010-03-25 00:54:54 +000011.. warning::
12
13 The CObject API is deprecated as of Python 2.7. Please switch to the new
14 :ref:`capsules` API.
Georg Brandlf6842722008-01-19 22:08:21 +000015
Sandro Tosi98ed08f2012-01-14 16:42:02 +010016.. c:type:: PyCObject
Georg Brandlf6842722008-01-19 22:08:21 +000017
Sandro Tosi98ed08f2012-01-14 16:42:02 +010018 This subtype of :c:type:`PyObject` represents an opaque value, useful for C
19 extension modules who need to pass an opaque value (as a :c:type:`void\*`
Georg Brandlf6842722008-01-19 22:08:21 +000020 pointer) through Python code to other C code. It is often used to make a C
21 function pointer defined in one module available to other modules, so the
22 regular import mechanism can be used to access C APIs defined in dynamically
23 loaded modules.
24
25
Sandro Tosi98ed08f2012-01-14 16:42:02 +010026.. c:function:: int PyCObject_Check(PyObject *p)
Georg Brandlf6842722008-01-19 22:08:21 +000027
Sandro Tosi98ed08f2012-01-14 16:42:02 +010028 Return true if its argument is a :c:type:`PyCObject`.
Georg Brandlf6842722008-01-19 22:08:21 +000029
30
Sandro Tosi98ed08f2012-01-14 16:42:02 +010031.. c:function:: PyObject* PyCObject_FromVoidPtr(void* cobj, void (*destr)(void *))
Georg Brandlf6842722008-01-19 22:08:21 +000032
Sandro Tosi98ed08f2012-01-14 16:42:02 +010033 Create a :c:type:`PyCObject` from the ``void *`` *cobj*. The *destr* function
Georg Brandlf6842722008-01-19 22:08:21 +000034 will be called when the object is reclaimed, unless it is *NULL*.
35
36
Sandro Tosi98ed08f2012-01-14 16:42:02 +010037.. c:function:: PyObject* PyCObject_FromVoidPtrAndDesc(void* cobj, void* desc, void (*destr)(void *, void *))
Georg Brandlf6842722008-01-19 22:08:21 +000038
Sandro Tosi98ed08f2012-01-14 16:42:02 +010039 Create a :c:type:`PyCObject` from the :c:type:`void \*` *cobj*. The *destr*
Georg Brandlf6842722008-01-19 22:08:21 +000040 function will be called when the object is reclaimed. The *desc* argument can
41 be used to pass extra callback data for the destructor function.
42
43
Sandro Tosi98ed08f2012-01-14 16:42:02 +010044.. c:function:: void* PyCObject_AsVoidPtr(PyObject* self)
Georg Brandlf6842722008-01-19 22:08:21 +000045
Sandro Tosi98ed08f2012-01-14 16:42:02 +010046 Return the object :c:type:`void \*` that the :c:type:`PyCObject` *self* was
Georg Brandlf6842722008-01-19 22:08:21 +000047 created with.
48
49
Sandro Tosi98ed08f2012-01-14 16:42:02 +010050.. c:function:: void* PyCObject_GetDesc(PyObject* self)
Georg Brandlf6842722008-01-19 22:08:21 +000051
Sandro Tosi98ed08f2012-01-14 16:42:02 +010052 Return the description :c:type:`void \*` that the :c:type:`PyCObject` *self* was
Georg Brandlf6842722008-01-19 22:08:21 +000053 created with.
54
55
Sandro Tosi98ed08f2012-01-14 16:42:02 +010056.. c:function:: int PyCObject_SetVoidPtr(PyObject* self, void* cobj)
Georg Brandlf6842722008-01-19 22:08:21 +000057
Sandro Tosi98ed08f2012-01-14 16:42:02 +010058 Set the void pointer inside *self* to *cobj*. The :c:type:`PyCObject` must not
Georg Brandlf6842722008-01-19 22:08:21 +000059 have an associated destructor. Return true on success, false on failure.