blob: f710d4af77248eaf3c93eae8efaed1b4a3852ba7 [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
Guido van Rossum77654a71996-01-12 00:44:03 +000017extern 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 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*/
Guido van Rossum43466ec1998-12-04 18:48:25 +000027extern DL_IMPORT(PyObject *)
Fred Drakeea9cb5a2000-07-09 00:20:36 +000028PyCObject_FromVoidPtr(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*/
Guido van Rossum43466ec1998-12-04 18:48:25 +000036extern DL_IMPORT(PyObject *)
Fred Drakeea9cb5a2000-07-09 00:20:36 +000037PyCObject_FromVoidPtrAndDesc(void *cobj, void *desc,
38 void (*destruct)(void*,void*));
Guido van Rossum1f844491997-10-21 19:48:35 +000039
Guido van Rossum77654a71996-01-12 00:44:03 +000040/* Retrieve a pointer to a C object from a PyCObject. */
Guido van Rossum43466ec1998-12-04 18:48:25 +000041extern DL_IMPORT(void *)
Fred Drakeea9cb5a2000-07-09 00:20:36 +000042PyCObject_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. */
Guido van Rossum43466ec1998-12-04 18:48:25 +000045extern DL_IMPORT(void *)
Fred Drakeea9cb5a2000-07-09 00:20:36 +000046PyCObject_GetDesc(PyObject *);
Guido van Rossum1f844491997-10-21 19:48:35 +000047
Guido van Rossume0e69621997-01-22 20:48:48 +000048/* Import a pointer to a C object from a module using a PyCObject. */
Guido van Rossum43466ec1998-12-04 18:48:25 +000049extern DL_IMPORT(void *)
Fred Drakeea9cb5a2000-07-09 00:20:36 +000050PyCObject_Import(char *module_name, char *cobject_name);
Guido van Rossume0e69621997-01-22 20:48:48 +000051
Guido van Rossum77654a71996-01-12 00:44:03 +000052#ifdef __cplusplus
53}
54#endif
55#endif /* !Py_COBJECT_H */