[Python-Dev] [Python-checkins] PyCapsule backport

Larry Hastings larry at hastings.org
Thu Mar 25 19:49:39 CET 2010


Just a reply to one part of your message, as I really need to get back 
to work for now.

Antoine Pitrou wrote:
> I think solution #1 would be the best one.
> #2 looks too complicated.
>   

#2 is a seven-line diff, below.


/larry/

Index: cobject.c
===================================================================
--- cobject.c   (revision 79396)
+++ cobject.c   (working copy)
@@ -50,7 +50,12 @@
 PyCObject_AsVoidPtr(PyObject *self)
 {
     if (self) {
-        if (self->ob_type == &PyCObject_Type)
+        if (PyCapsule_CheckExact(self)) {
+            const char *name = PyCapsule_GetName(self);
+            const void *value = PyCapsule_GetPointer(self, name);
+            return value;
+        }
+        else if (self->ob_type == &PyCObject_Type)
             return ((PyCObject *)self)->cobject;
         PyErr_SetString(PyExc_TypeError,
                         "PyCObject_AsVoidPtr with non-C-object");



More information about the Python-Dev mailing list