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