Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Guido van Rossum | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame] | 2 | Copyright (c) 2000, BeOpen.com. |
| 3 | Copyright (c) 1995-2000, Corporation for National Research Initiatives. |
| 4 | Copyright (c) 1990-1995, Stichting Mathematisch Centrum. |
| 5 | All rights reserved. |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 6 | |
Guido van Rossum | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame] | 7 | See the file "Misc/COPYRIGHT" for information on usage and |
| 8 | redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 9 | ******************************************************************/ |
| 10 | |
| 11 | /* C objects to be exported from one extension module to another. |
| 12 | |
| 13 | C objects are used for communication between extension modules. |
| 14 | They provide a way for an extension module to export a C interface |
| 15 | to other extension modules, so that extension modules can use the |
| 16 | Python import mechanism to link to one another. |
| 17 | |
| 18 | */ |
| 19 | |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 20 | #ifndef Py_COBJECT_H |
| 21 | #define Py_COBJECT_H |
| 22 | #ifdef __cplusplus |
| 23 | extern "C" { |
| 24 | #endif |
| 25 | |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 26 | extern DL_IMPORT(PyTypeObject) PyCObject_Type; |
| 27 | |
| 28 | #define PyCObject_Check(op) ((op)->ob_type == &PyCObject_Type) |
| 29 | |
| 30 | /* Create a PyCObject from a pointer to a C object and an optional |
| 31 | destrutor function. If the second argument is non-null, then it |
| 32 | will be called with the first argument if and when the PyCObject is |
| 33 | destroyed. |
| 34 | |
| 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_FromVoidPtr(void *cobj, void (*destruct)(void*)); |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 38 | |
Guido van Rossum | 1f84449 | 1997-10-21 19:48:35 +0000 | [diff] [blame] | 39 | |
| 40 | /* Create a PyCObject from a pointer to a C object, a description object, |
| 41 | and an optional destrutor function. If the third argument is non-null, |
| 42 | then it will be called with the first and second arguments if and when |
| 43 | the PyCObject is destroyed. |
| 44 | */ |
Guido van Rossum | 43466ec | 1998-12-04 18:48:25 +0000 | [diff] [blame] | 45 | extern DL_IMPORT(PyObject *) |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 46 | PyCObject_FromVoidPtrAndDesc(void *cobj, void *desc, |
| 47 | void (*destruct)(void*,void*)); |
Guido van Rossum | 1f84449 | 1997-10-21 19:48:35 +0000 | [diff] [blame] | 48 | |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 49 | /* Retrieve a pointer to a C object from a PyCObject. */ |
Guido van Rossum | 43466ec | 1998-12-04 18:48:25 +0000 | [diff] [blame] | 50 | extern DL_IMPORT(void *) |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 51 | PyCObject_AsVoidPtr(PyObject *); |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 52 | |
Guido van Rossum | 1f84449 | 1997-10-21 19:48:35 +0000 | [diff] [blame] | 53 | /* Retrieve a pointer to a description object from a PyCObject. */ |
Guido van Rossum | 43466ec | 1998-12-04 18:48:25 +0000 | [diff] [blame] | 54 | extern DL_IMPORT(void *) |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 55 | PyCObject_GetDesc(PyObject *); |
Guido van Rossum | 1f84449 | 1997-10-21 19:48:35 +0000 | [diff] [blame] | 56 | |
Guido van Rossum | e0e6962 | 1997-01-22 20:48:48 +0000 | [diff] [blame] | 57 | /* 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] | 58 | extern DL_IMPORT(void *) |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 59 | PyCObject_Import(char *module_name, char *cobject_name); |
Guido van Rossum | e0e6962 | 1997-01-22 20:48:48 +0000 | [diff] [blame] | 60 | |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 61 | #ifdef __cplusplus |
| 62 | } |
| 63 | #endif |
| 64 | #endif /* !Py_COBJECT_H */ |