Merged revisions 78965 via svnmerge from
[python/dscho.git] / Include / cobject.h
blob9efe4ce845789a05357330eab307c70829be1786
2 /*
4 The CObject module is now *deprecated* as of Python 3.1.
5 Please use the Capsule API instead; see "pycapsule.h".
7 */
9 #ifndef Py_COBJECT_H
10 #define Py_COBJECT_H
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
15 PyAPI_DATA(PyTypeObject) PyCObject_Type;
17 #define PyCObject_Check(op) (Py_TYPE(op) == &PyCObject_Type)
19 /* Create a PyCObject from a pointer to a C object and an optional
20 destructor function. If the second argument is non-null, then it
21 will be called with the first argument if and when the PyCObject is
22 destroyed.
25 PyAPI_FUNC(PyObject *) PyCObject_FromVoidPtr(
26 void *cobj, void (*destruct)(void*));
29 /* Create a PyCObject from a pointer to a C object, a description object,
30 and an optional destructor function. If the third argument is non-null,
31 then it will be called with the first and second arguments if and when
32 the PyCObject is destroyed.
34 PyAPI_FUNC(PyObject *) PyCObject_FromVoidPtrAndDesc(
35 void *cobj, void *desc, void (*destruct)(void*,void*));
37 /* Retrieve a pointer to a C object from a PyCObject. */
38 PyAPI_FUNC(void *) PyCObject_AsVoidPtr(PyObject *);
40 /* Retrieve a pointer to a description object from a PyCObject. */
41 PyAPI_FUNC(void *) PyCObject_GetDesc(PyObject *);
43 /* Import a pointer to a C object from a module using a PyCObject. */
44 PyAPI_FUNC(void *) PyCObject_Import(char *module_name, char *cobject_name);
46 /* Modify a C object. Fails (==0) if object has a destructor. */
47 PyAPI_FUNC(int) PyCObject_SetVoidPtr(PyObject *self, void *cobj);
50 typedef struct {
51 PyObject_HEAD
52 void *cobject;
53 void *desc;
54 void (*destructor)(void *);
55 } PyCObject;
58 #ifdef __cplusplus
60 #endif
61 #endif /* !Py_COBJECT_H */