blob: ad3cd9c98289b582af22c8d544aeb2be7f989135 [file] [log] [blame]
Larry Hastings5ac006d2010-04-02 11:01:35 +00001/*
2 CObjects are marked Pending Deprecation as of Python 2.7.
3 The full schedule for 2.x is as follows:
4 - CObjects are marked Pending Deprecation in Python 2.7.
5 - CObjects will be marked Deprecated in Python 2.8
6 (if there is one).
7 - CObjects will be removed in Python 2.9 (if there is one).
8
9 Additionally, for the Python 3.x series:
10 - CObjects were marked Deprecated in Python 3.1.
11 - CObjects will be removed in Python 3.2.
12
13 You should switch all use of CObjects to capsules. Capsules
14 have a safer and more consistent API. For more information,
15 see Include/pycapsule.h, or read the "Capsules" topic in
16 the "Python/C API Reference Manual".
17
18 Python 2.7 no longer uses CObjects itself; all objects which
19 were formerly CObjects are now capsules. Note that this change
20 does not by itself break binary compatibility with extensions
21 built for previous versions of Python--PyCObject_AsVoidPtr()
22 has been changed to also understand capsules.
23
24*/
25
26/* original file header comment follows: */
Guido van Rossum77654a71996-01-12 00:44:03 +000027
28/* C objects to be exported from one extension module to another.
29
30 C objects are used for communication between extension modules.
31 They provide a way for an extension module to export a C interface
32 to other extension modules, so that extension modules can use the
33 Python import mechanism to link to one another.
34
35*/
36
Fred Drakeea9cb5a2000-07-09 00:20:36 +000037#ifndef Py_COBJECT_H
38#define Py_COBJECT_H
39#ifdef __cplusplus
40extern "C" {
41#endif
42
Mark Hammond91a681d2002-08-12 07:21:58 +000043PyAPI_DATA(PyTypeObject) PyCObject_Type;
Guido van Rossum77654a71996-01-12 00:44:03 +000044
Christian Heimese93237d2007-12-19 02:37:44 +000045#define PyCObject_Check(op) (Py_TYPE(op) == &PyCObject_Type)
Guido van Rossum77654a71996-01-12 00:44:03 +000046
47/* Create a PyCObject from a pointer to a C object and an optional
Thomas Wouters7e474022000-07-16 12:04:32 +000048 destructor function. If the second argument is non-null, then it
Guido van Rossum77654a71996-01-12 00:44:03 +000049 will be called with the first argument if and when the PyCObject is
50 destroyed.
51
52*/
Mark Hammond91a681d2002-08-12 07:21:58 +000053PyAPI_FUNC(PyObject *) PyCObject_FromVoidPtr(
54 void *cobj, void (*destruct)(void*));
Guido van Rossum77654a71996-01-12 00:44:03 +000055
Guido van Rossum1f844491997-10-21 19:48:35 +000056
57/* Create a PyCObject from a pointer to a C object, a description object,
Thomas Wouters7e474022000-07-16 12:04:32 +000058 and an optional destructor function. If the third argument is non-null,
Guido van Rossum1f844491997-10-21 19:48:35 +000059 then it will be called with the first and second arguments if and when
60 the PyCObject is destroyed.
61*/
Mark Hammond91a681d2002-08-12 07:21:58 +000062PyAPI_FUNC(PyObject *) PyCObject_FromVoidPtrAndDesc(
63 void *cobj, void *desc, void (*destruct)(void*,void*));
Guido van Rossum1f844491997-10-21 19:48:35 +000064
Guido van Rossum77654a71996-01-12 00:44:03 +000065/* Retrieve a pointer to a C object from a PyCObject. */
Mark Hammond91a681d2002-08-12 07:21:58 +000066PyAPI_FUNC(void *) PyCObject_AsVoidPtr(PyObject *);
Guido van Rossum77654a71996-01-12 00:44:03 +000067
Guido van Rossum1f844491997-10-21 19:48:35 +000068/* Retrieve a pointer to a description object from a PyCObject. */
Mark Hammond91a681d2002-08-12 07:21:58 +000069PyAPI_FUNC(void *) PyCObject_GetDesc(PyObject *);
Guido van Rossum1f844491997-10-21 19:48:35 +000070
Guido van Rossume0e69621997-01-22 20:48:48 +000071/* Import a pointer to a C object from a module using a PyCObject. */
Mark Hammond91a681d2002-08-12 07:21:58 +000072PyAPI_FUNC(void *) PyCObject_Import(char *module_name, char *cobject_name);
Guido van Rossume0e69621997-01-22 20:48:48 +000073
Martin v. Löwis01a74b22003-10-19 18:30:01 +000074/* Modify a C object. Fails (==0) if object has a destructor. */
75PyAPI_FUNC(int) PyCObject_SetVoidPtr(PyObject *self, void *cobj);
76
Antoine Pitroud4ae97b2008-08-29 18:39:48 +000077
78typedef struct {
79 PyObject_HEAD
80 void *cobject;
81 void *desc;
82 void (*destructor)(void *);
83} PyCObject;
84
85
Guido van Rossum77654a71996-01-12 00:44:03 +000086#ifdef __cplusplus
87}
88#endif
89#endif /* !Py_COBJECT_H */