summaryrefslogtreecommitdiffstats
path: root/Objects/cobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-01-22 20:48:48 (GMT)
committerGuido van Rossum <guido@python.org>1997-01-22 20:48:48 (GMT)
commite0e696282feea175d82920e0cf13e90bd7a9252e (patch)
tree5212693bae144e7fd978a7be79801d0a248fb37b /Objects/cobject.c
parent43d287ad7383d3194153b6dba96912437fc6ba17 (diff)
downloadcpython-e0e696282feea175d82920e0cf13e90bd7a9252e.zip
cpython-e0e696282feea175d82920e0cf13e90bd7a9252e.tar.gz
cpython-e0e696282feea175d82920e0cf13e90bd7a9252e.tar.bz2
Added PyCObject_Import.
Diffstat (limited to 'Objects/cobject.c')
-rw-r--r--Objects/cobject.c57
1 files changed, 39 insertions, 18 deletions
diff --git a/Objects/cobject.c b/Objects/cobject.c
index 4016b91..49b7bc9 100644
--- a/Objects/cobject.c
+++ b/Objects/cobject.c
@@ -57,6 +57,44 @@ PyCObject_FromVoidPtr(cobj, destr)
return (PyObject *)self;
}
+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;
+}
+
+void *
+PyCObject_Import(module_name, name)
+ char *module_name;
+ char *name;
+{
+ PyObject *m, *c;
+ void *r=NULL;
+
+ if(m=PyImport_ImportModule(module_name))
+ {
+ if(c=PyObject_GetAttrString(m,name))
+ {
+ r=PyCObject_AsVoidPtr(c);
+ Py_DECREF(c);
+ }
+ Py_DECREF(m);
+ }
+
+ return r;
+}
+
static void
PyCObject_dealloc(self)
PyCObject *self;
@@ -65,6 +103,7 @@ PyCObject_dealloc(self)
PyMem_DEL(self);
}
+
static char PyCObject_Type__doc__[] =
"C objects to be exported from one extension module to another\n\
\n\
@@ -98,21 +137,3 @@ 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;
-}