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