summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-12-05 21:53:15 (GMT)
committerGuido van Rossum <guido@python.org>1996-12-05 21:53:15 (GMT)
commit04f95d5238a5e17b8dbba29ee88b99b7cd58bdbf (patch)
treea37f6ebe60bc97a37768b82d24ea006034d37bfa
parentcbd1e4eb5f7ce78300387ae872d89153c2b4dd66 (diff)
downloadcpython-04f95d5238a5e17b8dbba29ee88b99b7cd58bdbf.zip
cpython-04f95d5238a5e17b8dbba29ee88b99b7cd58bdbf.tar.gz
cpython-04f95d5238a5e17b8dbba29ee88b99b7cd58bdbf.tar.bz2
Better implementation of PyCObject_AsVoidPtr().
-rw-r--r--Objects/cobject.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/Objects/cobject.c b/Objects/cobject.c
index 24b860e..4016b91 100644
--- a/Objects/cobject.c
+++ b/Objects/cobject.c
@@ -57,13 +57,6 @@ PyCObject_FromVoidPtr(cobj, destr)
return (PyObject *)self;
}
-void *
-PyCObject_AsVoidPtr(self)
- PyObject *self;
-{
- return ((PyCObject *)self)->cobject;
-}
-
static void
PyCObject_dealloc(self)
PyCObject *self;
@@ -105,3 +98,21 @@ PyTypeObject PyCObject_Type = {
0L,0L,0L,0L,
PyCObject_Type__doc__ /* Documentation string */
};
+
+void *
+PyCObject_AsVoidPtr(self)
+ PyObject *self;
+{
+ if(self)
+ {
+ if(self->ob_type == &PyCObject_Type)
+ return ((PyCObject *)self)->cobject;
+ PyErr_SetString(PyExc_TypeError,
+ "PyCObject_AsVoidPtr with non-C-object");
+ }
+ if(! PyErr_Occurred())
+ PyErr_SetString(
+ PyExc_TypeError,
+ "PyCObject_AsVoidPtr called with null pointer");
+ return NULL;
+}