@@ -36,9 +36,13 @@ PERFORMANCE OF THIS SOFTWARE.
3636
3737/* Declarations for objects of type PyCObject */
3838
39+ typedef void (* destructor1 ) Py_PROTO ((void * ) );
40+ typedef void (* destructor2 ) Py_PROTO ((void * , void * ) );
41+
3942typedef struct {
4043 PyObject_HEAD
4144 void * cobject ;
45+ void * desc ;
4246 void (* destructor ) Py_PROTO ((void * ));
4347} PyCObject ;
4448
@@ -54,6 +58,30 @@ PyCObject_FromVoidPtr(cobj, destr)
5458 return NULL ;
5559 self -> cobject = cobj ;
5660 self -> destructor = destr ;
61+ self -> desc = NULL ;
62+ return (PyObject * )self ;
63+ }
64+
65+ PyObject *
66+ PyCObject_FromVoidPtrAndDesc (cobj , desc , destr )
67+ void * cobj ;
68+ void * desc ;
69+ void (* destr ) Py_PROTO ((void * , void * ) );
70+ {
71+ PyCObject * self ;
72+
73+ if (!desc ) {
74+ PyErr_SetString (PyExc_TypeError ,
75+ "PyCObject_FromVoidPtrAndDesc called with null description" );
76+ return NULL ;
77+ }
78+
79+ self = PyObject_NEW (PyCObject , & PyCObject_Type );
80+ if (self == NULL )
81+ return NULL ;
82+ self -> cobject = cobj ;
83+ self -> destructor = (destructor1 )destr ;
84+ self -> desc = desc ;
5785 return (PyObject * )self ;
5886}
5987
@@ -74,6 +102,23 @@ PyCObject_AsVoidPtr(self)
74102 return NULL ;
75103}
76104
105+ void *
106+ PyCObject_GetDesc (self )
107+ PyObject * self ;
108+ {
109+ if (self )
110+ {
111+ if (self -> ob_type == & PyCObject_Type )
112+ return ((PyCObject * )self )-> desc ;
113+ PyErr_SetString (PyExc_TypeError ,
114+ "PyCObject_GetDesc with non-C-object" );
115+ }
116+ if (! PyErr_Occurred ())
117+ PyErr_SetString (PyExc_TypeError ,
118+ "PyCObject_GetDesc called with null pointer" );
119+ return NULL ;
120+ }
121+
77122void *
78123PyCObject_Import (module_name , name )
79124 char * module_name ;
@@ -99,7 +144,13 @@ static void
99144PyCObject_dealloc (self )
100145 PyCObject * self ;
101146{
102- if (self -> destructor ) (self -> destructor )(self -> cobject );
147+ if (self -> destructor )
148+ {
149+ if (self -> desc )
150+ ((destructor2 )(self -> destructor ))(self -> cobject , self -> desc );
151+ else
152+ (self -> destructor )(self -> cobject );
153+ }
103154 PyMem_DEL (self );
104155}
105156
0 commit comments