Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 1 | |
Benjamin Peterson | b173f78 | 2009-05-05 22:31:58 +0000 | [diff] [blame] | 2 | /* |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 3 | |
Benjamin Peterson | b173f78 | 2009-05-05 22:31:58 +0000 | [diff] [blame] | 4 | The CObject module is now *deprecated* as of Python 3.1. |
| 5 | Please use the Capsule API instead; see "pycapsule.h". |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 6 | |
| 7 | */ |
| 8 | |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 9 | #ifndef Py_COBJECT_H |
| 10 | #define Py_COBJECT_H |
| 11 | #ifdef __cplusplus |
| 12 | extern "C" { |
| 13 | #endif |
| 14 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 15 | PyAPI_DATA(PyTypeObject) PyCObject_Type; |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 16 | |
Christian Heimes | 90aa764 | 2007-12-19 02:45:37 +0000 | [diff] [blame] | 17 | #define PyCObject_Check(op) (Py_TYPE(op) == &PyCObject_Type) |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 18 | |
| 19 | /* Create a PyCObject from a pointer to a C object and an optional |
Thomas Wouters | 7e47402 | 2000-07-16 12:04:32 +0000 | [diff] [blame] | 20 | destructor function. If the second argument is non-null, then it |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 21 | will be called with the first argument if and when the PyCObject is |
| 22 | destroyed. |
| 23 | |
| 24 | */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 25 | PyAPI_FUNC(PyObject *) PyCObject_FromVoidPtr( |
| 26 | void *cobj, void (*destruct)(void*)); |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 27 | |
Guido van Rossum | 1f84449 | 1997-10-21 19:48:35 +0000 | [diff] [blame] | 28 | |
| 29 | /* Create a PyCObject from a pointer to a C object, a description object, |
Thomas Wouters | 7e47402 | 2000-07-16 12:04:32 +0000 | [diff] [blame] | 30 | and an optional destructor function. If the third argument is non-null, |
Guido van Rossum | 1f84449 | 1997-10-21 19:48:35 +0000 | [diff] [blame] | 31 | then it will be called with the first and second arguments if and when |
| 32 | the PyCObject is destroyed. |
| 33 | */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 34 | PyAPI_FUNC(PyObject *) PyCObject_FromVoidPtrAndDesc( |
| 35 | void *cobj, void *desc, void (*destruct)(void*,void*)); |
Guido van Rossum | 1f84449 | 1997-10-21 19:48:35 +0000 | [diff] [blame] | 36 | |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 37 | /* Retrieve a pointer to a C object from a PyCObject. */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 38 | PyAPI_FUNC(void *) PyCObject_AsVoidPtr(PyObject *); |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 39 | |
Guido van Rossum | 1f84449 | 1997-10-21 19:48:35 +0000 | [diff] [blame] | 40 | /* Retrieve a pointer to a description object from a PyCObject. */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 41 | PyAPI_FUNC(void *) PyCObject_GetDesc(PyObject *); |
Guido van Rossum | 1f84449 | 1997-10-21 19:48:35 +0000 | [diff] [blame] | 42 | |
Guido van Rossum | e0e6962 | 1997-01-22 20:48:48 +0000 | [diff] [blame] | 43 | /* Import a pointer to a C object from a module using a PyCObject. */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 44 | PyAPI_FUNC(void *) PyCObject_Import(char *module_name, char *cobject_name); |
Guido van Rossum | e0e6962 | 1997-01-22 20:48:48 +0000 | [diff] [blame] | 45 | |
Martin v. Löwis | 01a74b2 | 2003-10-19 18:30:01 +0000 | [diff] [blame] | 46 | /* Modify a C object. Fails (==0) if object has a destructor. */ |
| 47 | PyAPI_FUNC(int) PyCObject_SetVoidPtr(PyObject *self, void *cobj); |
| 48 | |
Antoine Pitrou | f7199578 | 2008-08-29 18:37:05 +0000 | [diff] [blame] | 49 | |
| 50 | typedef struct { |
| 51 | PyObject_HEAD |
| 52 | void *cobject; |
| 53 | void *desc; |
| 54 | void (*destructor)(void *); |
| 55 | } PyCObject; |
| 56 | |
| 57 | |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 58 | #ifdef __cplusplus |
| 59 | } |
| 60 | #endif |
| 61 | #endif /* !Py_COBJECT_H */ |