blob: 499dfadddfee163cd08dcf9e3143c20ff0a6d380 [file] [log] [blame]
Guido van Rossum77654a71996-01-12 00:44:03 +00001
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 Drakeea9cb5a2000-07-09 00:20:36 +000011#ifndef Py_COBJECT_H
12#define Py_COBJECT_H
13#ifdef __cplusplus
14extern "C" {
15#endif
16
Mark Hammond91a681d2002-08-12 07:21:58 +000017PyAPI_DATA(PyTypeObject) PyCObject_Type;
Guido van Rossum77654a71996-01-12 00:44:03 +000018
Christian Heimes90aa7642007-12-19 02:45:37 +000019#define PyCObject_Check(op) (Py_TYPE(op) == &PyCObject_Type)
Guido van Rossum77654a71996-01-12 00:44:03 +000020
21/* Create a PyCObject from a pointer to a C object and an optional
Thomas Wouters7e474022000-07-16 12:04:32 +000022 destructor function. If the second argument is non-null, then it
Guido van Rossum77654a71996-01-12 00:44:03 +000023 will be called with the first argument if and when the PyCObject is
24 destroyed.
25
26*/
Mark Hammond91a681d2002-08-12 07:21:58 +000027PyAPI_FUNC(PyObject *) PyCObject_FromVoidPtr(
28 void *cobj, void (*destruct)(void*));
Guido van Rossum77654a71996-01-12 00:44:03 +000029
Guido van Rossum1f844491997-10-21 19:48:35 +000030
31/* Create a PyCObject from a pointer to a C object, a description object,
Thomas Wouters7e474022000-07-16 12:04:32 +000032 and an optional destructor function. If the third argument is non-null,
Guido van Rossum1f844491997-10-21 19:48:35 +000033 then it will be called with the first and second arguments if and when
34 the PyCObject is destroyed.
35*/
Mark Hammond91a681d2002-08-12 07:21:58 +000036PyAPI_FUNC(PyObject *) PyCObject_FromVoidPtrAndDesc(
37 void *cobj, void *desc, void (*destruct)(void*,void*));
Guido van Rossum1f844491997-10-21 19:48:35 +000038
Guido van Rossum77654a71996-01-12 00:44:03 +000039/* Retrieve a pointer to a C object from a PyCObject. */
Mark Hammond91a681d2002-08-12 07:21:58 +000040PyAPI_FUNC(void *) PyCObject_AsVoidPtr(PyObject *);
Guido van Rossum77654a71996-01-12 00:44:03 +000041
Guido van Rossum1f844491997-10-21 19:48:35 +000042/* Retrieve a pointer to a description object from a PyCObject. */
Mark Hammond91a681d2002-08-12 07:21:58 +000043PyAPI_FUNC(void *) PyCObject_GetDesc(PyObject *);
Guido van Rossum1f844491997-10-21 19:48:35 +000044
Guido van Rossume0e69621997-01-22 20:48:48 +000045/* Import a pointer to a C object from a module using a PyCObject. */
Mark Hammond91a681d2002-08-12 07:21:58 +000046PyAPI_FUNC(void *) PyCObject_Import(char *module_name, char *cobject_name);
Guido van Rossume0e69621997-01-22 20:48:48 +000047
Martin v. Löwis01a74b22003-10-19 18:30:01 +000048/* Modify a C object. Fails (==0) if object has a destructor. */
49PyAPI_FUNC(int) PyCObject_SetVoidPtr(PyObject *self, void *cobj);
50
Guido van Rossum77654a71996-01-12 00:44:03 +000051#ifdef __cplusplus
52}
53#endif
54#endif /* !Py_COBJECT_H */