blob: 15850d916e3db51179318f380ceca2de4318d2af [file] [log] [blame]
Guido van Rossum77654a71996-01-12 00:44:03 +00001/***********************************************************
Guido van Rossumfd71b9e2000-06-30 23:50:40 +00002Copyright (c) 2000, BeOpen.com.
3Copyright (c) 1995-2000, Corporation for National Research Initiatives.
4Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
5All rights reserved.
Guido van Rossum77654a71996-01-12 00:44:03 +00006
Guido van Rossumfd71b9e2000-06-30 23:50:40 +00007See the file "Misc/COPYRIGHT" for information on usage and
8redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
Guido van Rossum77654a71996-01-12 00:44:03 +00009******************************************************************/
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 Drakeea9cb5a2000-07-09 00:20:36 +000020#ifndef Py_COBJECT_H
21#define Py_COBJECT_H
22#ifdef __cplusplus
23extern "C" {
24#endif
25
Guido van Rossum77654a71996-01-12 00:44:03 +000026extern 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 Rossum43466ec1998-12-04 18:48:25 +000036extern DL_IMPORT(PyObject *)
Fred Drakeea9cb5a2000-07-09 00:20:36 +000037PyCObject_FromVoidPtr(void *cobj, void (*destruct)(void*));
Guido van Rossum77654a71996-01-12 00:44:03 +000038
Guido van Rossum1f844491997-10-21 19:48:35 +000039
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 Rossum43466ec1998-12-04 18:48:25 +000045extern DL_IMPORT(PyObject *)
Fred Drakeea9cb5a2000-07-09 00:20:36 +000046PyCObject_FromVoidPtrAndDesc(void *cobj, void *desc,
47 void (*destruct)(void*,void*));
Guido van Rossum1f844491997-10-21 19:48:35 +000048
Guido van Rossum77654a71996-01-12 00:44:03 +000049/* Retrieve a pointer to a C object from a PyCObject. */
Guido van Rossum43466ec1998-12-04 18:48:25 +000050extern DL_IMPORT(void *)
Fred Drakeea9cb5a2000-07-09 00:20:36 +000051PyCObject_AsVoidPtr(PyObject *);
Guido van Rossum77654a71996-01-12 00:44:03 +000052
Guido van Rossum1f844491997-10-21 19:48:35 +000053/* Retrieve a pointer to a description object from a PyCObject. */
Guido van Rossum43466ec1998-12-04 18:48:25 +000054extern DL_IMPORT(void *)
Fred Drakeea9cb5a2000-07-09 00:20:36 +000055PyCObject_GetDesc(PyObject *);
Guido van Rossum1f844491997-10-21 19:48:35 +000056
Guido van Rossume0e69621997-01-22 20:48:48 +000057/* Import a pointer to a C object from a module using a PyCObject. */
Guido van Rossum43466ec1998-12-04 18:48:25 +000058extern DL_IMPORT(void *)
Fred Drakeea9cb5a2000-07-09 00:20:36 +000059PyCObject_Import(char *module_name, char *cobject_name);
Guido van Rossume0e69621997-01-22 20:48:48 +000060
Guido van Rossum77654a71996-01-12 00:44:03 +000061#ifdef __cplusplus
62}
63#endif
64#endif /* !Py_COBJECT_H */