Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 1 | |
| 2 | /* C objects to be exported from one extension module to another. |
| 3 | |
| 4 | C objects are used for communication between extension modules. |
| 5 | They provide a way for an extension module to export a C interface |
| 6 | to other extension modules, so that extension modules can use the |
| 7 | Python import mechanism to link to one another. |
| 8 | |
| 9 | */ |
| 10 | |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 11 | #ifndef Py_COBJECT_H |
| 12 | #define Py_COBJECT_H |
| 13 | #ifdef __cplusplus |
| 14 | extern "C" { |
| 15 | #endif |
| 16 | |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 17 | extern DL_IMPORT(PyTypeObject) PyCObject_Type; |
| 18 | |
| 19 | #define PyCObject_Check(op) ((op)->ob_type == &PyCObject_Type) |
| 20 | |
| 21 | /* 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] | 22 | destructor function. If the second argument is non-null, then it |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 23 | will be called with the first argument if and when the PyCObject is |
| 24 | destroyed. |
| 25 | |
| 26 | */ |
Guido van Rossum | 43466ec | 1998-12-04 18:48:25 +0000 | [diff] [blame] | 27 | extern DL_IMPORT(PyObject *) |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 28 | PyCObject_FromVoidPtr(void *cobj, void (*destruct)(void*)); |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 29 | |
Guido van Rossum | 1f84449 | 1997-10-21 19:48:35 +0000 | [diff] [blame] | 30 | |
| 31 | /* 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] | 32 | 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] | 33 | then it will be called with the first and second arguments if and when |
| 34 | the PyCObject is destroyed. |
| 35 | */ |
Guido van Rossum | 43466ec | 1998-12-04 18:48:25 +0000 | [diff] [blame] | 36 | extern DL_IMPORT(PyObject *) |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 37 | PyCObject_FromVoidPtrAndDesc(void *cobj, void *desc, |
| 38 | void (*destruct)(void*,void*)); |
Guido van Rossum | 1f84449 | 1997-10-21 19:48:35 +0000 | [diff] [blame] | 39 | |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 40 | /* Retrieve a pointer to a C object from a PyCObject. */ |
Guido van Rossum | 43466ec | 1998-12-04 18:48:25 +0000 | [diff] [blame] | 41 | extern DL_IMPORT(void *) |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 42 | PyCObject_AsVoidPtr(PyObject *); |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 43 | |
Guido van Rossum | 1f84449 | 1997-10-21 19:48:35 +0000 | [diff] [blame] | 44 | /* Retrieve a pointer to a description object from a PyCObject. */ |
Guido van Rossum | 43466ec | 1998-12-04 18:48:25 +0000 | [diff] [blame] | 45 | extern DL_IMPORT(void *) |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 46 | PyCObject_GetDesc(PyObject *); |
Guido van Rossum | 1f84449 | 1997-10-21 19:48:35 +0000 | [diff] [blame] | 47 | |
Guido van Rossum | e0e6962 | 1997-01-22 20:48:48 +0000 | [diff] [blame] | 48 | /* Import a pointer to a C object from a module using a PyCObject. */ |
Guido van Rossum | 43466ec | 1998-12-04 18:48:25 +0000 | [diff] [blame] | 49 | extern DL_IMPORT(void *) |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 50 | PyCObject_Import(char *module_name, char *cobject_name); |
Guido van Rossum | e0e6962 | 1997-01-22 20:48:48 +0000 | [diff] [blame] | 51 | |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 52 | #ifdef __cplusplus |
| 53 | } |
| 54 | #endif |
| 55 | #endif /* !Py_COBJECT_H */ |