blob: 9efe4ce845789a05357330eab307c70829be1786 [file] [log] [blame]
Guido van Rossum77654a71996-01-12 00:44:03 +00001
Benjamin Petersonb173f782009-05-05 22:31:58 +00002/*
Guido van Rossum77654a71996-01-12 00:44:03 +00003
Benjamin Petersonb173f782009-05-05 22:31:58 +00004The CObject module is now *deprecated* as of Python 3.1.
5Please use the Capsule API instead; see "pycapsule.h".
Guido van Rossum77654a71996-01-12 00:44:03 +00006
7*/
8
Fred Drakeea9cb5a2000-07-09 00:20:36 +00009#ifndef Py_COBJECT_H
10#define Py_COBJECT_H
11#ifdef __cplusplus
12extern "C" {
13#endif
14
Mark Hammond91a681d2002-08-12 07:21:58 +000015PyAPI_DATA(PyTypeObject) PyCObject_Type;
Guido van Rossum77654a71996-01-12 00:44:03 +000016
Christian Heimes90aa7642007-12-19 02:45:37 +000017#define PyCObject_Check(op) (Py_TYPE(op) == &PyCObject_Type)
Guido van Rossum77654a71996-01-12 00:44:03 +000018
19/* Create a PyCObject from a pointer to a C object and an optional
Thomas Wouters7e474022000-07-16 12:04:32 +000020 destructor function. If the second argument is non-null, then it
Guido van Rossum77654a71996-01-12 00:44:03 +000021 will be called with the first argument if and when the PyCObject is
22 destroyed.
23
24*/
Mark Hammond91a681d2002-08-12 07:21:58 +000025PyAPI_FUNC(PyObject *) PyCObject_FromVoidPtr(
26 void *cobj, void (*destruct)(void*));
Guido van Rossum77654a71996-01-12 00:44:03 +000027
Guido van Rossum1f844491997-10-21 19:48:35 +000028
29/* Create a PyCObject from a pointer to a C object, a description object,
Thomas Wouters7e474022000-07-16 12:04:32 +000030 and an optional destructor function. If the third argument is non-null,
Guido van Rossum1f844491997-10-21 19:48:35 +000031 then it will be called with the first and second arguments if and when
32 the PyCObject is destroyed.
33*/
Mark Hammond91a681d2002-08-12 07:21:58 +000034PyAPI_FUNC(PyObject *) PyCObject_FromVoidPtrAndDesc(
35 void *cobj, void *desc, void (*destruct)(void*,void*));
Guido van Rossum1f844491997-10-21 19:48:35 +000036
Guido van Rossum77654a71996-01-12 00:44:03 +000037/* Retrieve a pointer to a C object from a PyCObject. */
Mark Hammond91a681d2002-08-12 07:21:58 +000038PyAPI_FUNC(void *) PyCObject_AsVoidPtr(PyObject *);
Guido van Rossum77654a71996-01-12 00:44:03 +000039
Guido van Rossum1f844491997-10-21 19:48:35 +000040/* Retrieve a pointer to a description object from a PyCObject. */
Mark Hammond91a681d2002-08-12 07:21:58 +000041PyAPI_FUNC(void *) PyCObject_GetDesc(PyObject *);
Guido van Rossum1f844491997-10-21 19:48:35 +000042
Guido van Rossume0e69621997-01-22 20:48:48 +000043/* Import a pointer to a C object from a module using a PyCObject. */
Mark Hammond91a681d2002-08-12 07:21:58 +000044PyAPI_FUNC(void *) PyCObject_Import(char *module_name, char *cobject_name);
Guido van Rossume0e69621997-01-22 20:48:48 +000045
Martin v. Löwis01a74b22003-10-19 18:30:01 +000046/* Modify a C object. Fails (==0) if object has a destructor. */
47PyAPI_FUNC(int) PyCObject_SetVoidPtr(PyObject *self, void *cobj);
48
Antoine Pitrouf71995782008-08-29 18:37:05 +000049
50typedef struct {
51 PyObject_HEAD
52 void *cobject;
53 void *desc;
54 void (*destructor)(void *);
55} PyCObject;
56
57
Guido van Rossum77654a71996-01-12 00:44:03 +000058#ifdef __cplusplus
59}
60#endif
61#endif /* !Py_COBJECT_H */