summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-10-21 19:48:35 (GMT)
committerGuido van Rossum <guido@python.org>1997-10-21 19:48:35 (GMT)
commit1f84449fd80ded6abf23d47147219e68dd65fc2f (patch)
tree0efa0b4b67a1344b65d1d656c6758ef18e00ab2b /Objects
parent16cb6f4612235b6b4ae1d50be7857d4e0e5852f8 (diff)
downloadcpython-1f84449fd80ded6abf23d47147219e68dd65fc2f.zip
cpython-1f84449fd80ded6abf23d47147219e68dd65fc2f.tar.gz
cpython-1f84449fd80ded6abf23d47147219e68dd65fc2f.tar.bz2
New CObject from Jim Fulton, adds PyCObject_FromVoidPtrAndDesc() and
PyCObject_GetDesc().
Diffstat (limited to 'Objects')
-rw-r--r--Objects/cobject.c53
1 files changed, 52 insertions, 1 deletions
diff --git a/Objects/cobject.c b/Objects/cobject.c
index 6b757d5..40e8672 100644
--- a/Objects/cobject.c
+++ b/Objects/cobject.c
@@ -36,9 +36,13 @@ PERFORMANCE OF THIS SOFTWARE.
/* Declarations for objects of type PyCObject */
+typedef void (*destructor1) Py_PROTO((void *));
+typedef void (*destructor2) Py_PROTO((void *, void*));
+
typedef struct {
PyObject_HEAD
void *cobject;
+ void *desc;
void (*destructor) Py_PROTO((void *));
} PyCObject;
@@ -54,6 +58,30 @@ PyCObject_FromVoidPtr(cobj, destr)
return NULL;
self->cobject=cobj;
self->destructor=destr;
+ self->desc=NULL;
+ return (PyObject *)self;
+}
+
+PyObject *
+PyCObject_FromVoidPtrAndDesc(cobj, desc, destr)
+ void *cobj;
+ void *desc;
+ void (*destr) Py_PROTO((void *, void *));
+{
+ PyCObject *self;
+
+ if(!desc) {
+ PyErr_SetString(PyExc_TypeError,
+ "PyCObject_FromVoidPtrAndDesc called with null description");
+ return NULL;
+ }
+
+ self = PyObject_NEW(PyCObject, &PyCObject_Type);
+ if (self == NULL)
+ return NULL;
+ self->cobject=cobj;
+ self->destructor=(destructor1)destr;
+ self->desc=desc;
return (PyObject *)self;
}
@@ -75,6 +103,23 @@ PyCObject_AsVoidPtr(self)
}
void *
+PyCObject_GetDesc(self)
+ PyObject *self;
+{
+ if(self)
+ {
+ if(self->ob_type == &PyCObject_Type)
+ return ((PyCObject *)self)->desc;
+ PyErr_SetString(PyExc_TypeError,
+ "PyCObject_GetDesc with non-C-object");
+ }
+ if(! PyErr_Occurred())
+ PyErr_SetString(PyExc_TypeError,
+ "PyCObject_GetDesc called with null pointer");
+ return NULL;
+}
+
+void *
PyCObject_Import(module_name, name)
char *module_name;
char *name;
@@ -99,7 +144,13 @@ static void
PyCObject_dealloc(self)
PyCObject *self;
{
- if(self->destructor) (self->destructor)(self->cobject);
+ if(self->destructor)
+ {
+ if(self->desc)
+ ((destructor2)(self->destructor))(self->cobject, self->desc);
+ else
+ (self->destructor)(self->cobject);
+ }
PyMem_DEL(self);
}