blob: e5e246b126d671b69267c88545f4893a532482ae [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
Larry Hastings402b73f2010-03-25 00:54:54 +00009 DEPRECATED - Use PyCapsule objects instead.
10 CObject will be removed in 2.8 (if there is one).
Guido van Rossum77654a71996-01-12 00:44:03 +000011*/
12
Fred Drakeea9cb5a2000-07-09 00:20:36 +000013#ifndef Py_COBJECT_H
14#define Py_COBJECT_H
15#ifdef __cplusplus
16extern "C" {
17#endif
18
Mark Hammond91a681d2002-08-12 07:21:58 +000019PyAPI_DATA(PyTypeObject) PyCObject_Type;
Guido van Rossum77654a71996-01-12 00:44:03 +000020
Christian Heimese93237d2007-12-19 02:37:44 +000021#define PyCObject_Check(op) (Py_TYPE(op) == &PyCObject_Type)
Guido van Rossum77654a71996-01-12 00:44:03 +000022
23/* Create a PyCObject from a pointer to a C object and an optional
Thomas Wouters7e474022000-07-16 12:04:32 +000024 destructor function. If the second argument is non-null, then it
Guido van Rossum77654a71996-01-12 00:44:03 +000025 will be called with the first argument if and when the PyCObject is
26 destroyed.
27
28*/
Mark Hammond91a681d2002-08-12 07:21:58 +000029PyAPI_FUNC(PyObject *) PyCObject_FromVoidPtr(
30 void *cobj, void (*destruct)(void*));
Guido van Rossum77654a71996-01-12 00:44:03 +000031
Guido van Rossum1f844491997-10-21 19:48:35 +000032
33/* Create a PyCObject from a pointer to a C object, a description object,
Thomas Wouters7e474022000-07-16 12:04:32 +000034 and an optional destructor function. If the third argument is non-null,
Guido van Rossum1f844491997-10-21 19:48:35 +000035 then it will be called with the first and second arguments if and when
36 the PyCObject is destroyed.
37*/
Mark Hammond91a681d2002-08-12 07:21:58 +000038PyAPI_FUNC(PyObject *) PyCObject_FromVoidPtrAndDesc(
39 void *cobj, void *desc, void (*destruct)(void*,void*));
Guido van Rossum1f844491997-10-21 19:48:35 +000040
Guido van Rossum77654a71996-01-12 00:44:03 +000041/* Retrieve a pointer to a C object from a PyCObject. */
Mark Hammond91a681d2002-08-12 07:21:58 +000042PyAPI_FUNC(void *) PyCObject_AsVoidPtr(PyObject *);
Guido van Rossum77654a71996-01-12 00:44:03 +000043
Guido van Rossum1f844491997-10-21 19:48:35 +000044/* Retrieve a pointer to a description object from a PyCObject. */
Mark Hammond91a681d2002-08-12 07:21:58 +000045PyAPI_FUNC(void *) PyCObject_GetDesc(PyObject *);
Guido van Rossum1f844491997-10-21 19:48:35 +000046
Guido van Rossume0e69621997-01-22 20:48:48 +000047/* Import a pointer to a C object from a module using a PyCObject. */
Mark Hammond91a681d2002-08-12 07:21:58 +000048PyAPI_FUNC(void *) PyCObject_Import(char *module_name, char *cobject_name);
Guido van Rossume0e69621997-01-22 20:48:48 +000049
Martin v. Löwis01a74b22003-10-19 18:30:01 +000050/* Modify a C object. Fails (==0) if object has a destructor. */
51PyAPI_FUNC(int) PyCObject_SetVoidPtr(PyObject *self, void *cobj);
52
Antoine Pitroud4ae97b2008-08-29 18:39:48 +000053
54typedef struct {
55 PyObject_HEAD
56 void *cobject;
57 void *desc;
58 void (*destructor)(void *);
59} PyCObject;
60
61
Guido van Rossum77654a71996-01-12 00:44:03 +000062#ifdef __cplusplus
63}
64#endif
65#endif /* !Py_COBJECT_H */