Commit ea4db01b authored by Lisandro Dalcin's avatar Lisandro Dalcin

use PyCapsule for Py 2.7+ (but not in Py 3.0)

parent bcfa729f
...@@ -2246,10 +2246,10 @@ static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *s ...@@ -2246,10 +2246,10 @@ static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *s
goto bad; goto bad;
} }
tmp.fp = f; tmp.fp = f;
#if PY_VERSION_HEX < 0x03010000 #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
cobj = PyCObject_FromVoidPtrAndDesc(tmp.p, (void *)sig, 0);
#else
cobj = PyCapsule_New(tmp.p, sig, 0); cobj = PyCapsule_New(tmp.p, sig, 0);
#else
cobj = PyCObject_FromVoidPtrAndDesc(tmp.p, (void *)sig, 0);
#endif #endif
if (!cobj) if (!cobj)
goto bad; goto bad;
...@@ -2280,9 +2280,6 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (** ...@@ -2280,9 +2280,6 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**
void (*fp)(void); void (*fp)(void);
void *p; void *p;
} tmp; } tmp;
#if PY_VERSION_HEX < 0x03010000
const char *desc, *s1, *s2;
#endif
d = PyObject_GetAttrString(module, (char *)"%(API)s"); d = PyObject_GetAttrString(module, (char *)"%(API)s");
if (!d) if (!d)
...@@ -2294,7 +2291,16 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (** ...@@ -2294,7 +2291,16 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**
PyModule_GetName(module), funcname); PyModule_GetName(module), funcname);
goto bad; goto bad;
} }
#if PY_VERSION_HEX < 0x03010000 #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
if (!PyCapsule_IsValid(cobj, sig)) {
PyErr_Format(PyExc_TypeError,
"C function %%s.%%s has wrong signature (expected %%s, got %%s)",
PyModule_GetName(module), funcname, sig, PyCapsule_GetName(cobj));
goto bad;
}
tmp.p = PyCapsule_GetPointer(cobj, sig);
#else
{const char *desc, *s1, *s2;
desc = (const char *)PyCObject_GetDesc(cobj); desc = (const char *)PyCObject_GetDesc(cobj);
if (!desc) if (!desc)
goto bad; goto bad;
...@@ -2306,15 +2312,7 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (** ...@@ -2306,15 +2312,7 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**
PyModule_GetName(module), funcname, sig, desc); PyModule_GetName(module), funcname, sig, desc);
goto bad; goto bad;
} }
tmp.p = PyCObject_AsVoidPtr(cobj); tmp.p = PyCObject_AsVoidPtr(cobj);}
#else
if (!PyCapsule_IsValid(cobj, sig)) {
PyErr_Format(PyExc_TypeError,
"C function %%s.%%s has wrong signature (expected %%s, got %%s)",
PyModule_GetName(module), funcname, sig, PyCapsule_GetName(cobj));
goto bad;
}
tmp.p = PyCapsule_GetPointer(cobj, sig);
#endif #endif
*f = tmp.fp; *f = tmp.fp;
if (!(*f)) if (!(*f))
......
...@@ -5931,10 +5931,10 @@ static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/ ...@@ -5931,10 +5931,10 @@ static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/
""", """,
impl = """ impl = """
static int __Pyx_SetVtable(PyObject *dict, void *vtable) { static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
#if PY_VERSION_HEX < 0x03010000 #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
#else
PyObject *ob = PyCapsule_New(vtable, 0, 0); PyObject *ob = PyCapsule_New(vtable, 0, 0);
#else
PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
#endif #endif
if (!ob) if (!ob)
goto bad; goto bad;
...@@ -5959,10 +5959,10 @@ static int __Pyx_GetVtable(PyObject *dict, void *vtabptr) { ...@@ -5959,10 +5959,10 @@ static int __Pyx_GetVtable(PyObject *dict, void *vtabptr) {
PyObject *ob = PyMapping_GetItemString(dict, (char *)"__pyx_vtable__"); PyObject *ob = PyMapping_GetItemString(dict, (char *)"__pyx_vtable__");
if (!ob) if (!ob)
goto bad; goto bad;
#if PY_VERSION_HEX < 0x03010000 #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
*(void **)vtabptr = PyCObject_AsVoidPtr(ob);
#else
*(void **)vtabptr = PyCapsule_GetPointer(ob, 0); *(void **)vtabptr = PyCapsule_GetPointer(ob, 0);
#else
*(void **)vtabptr = PyCObject_AsVoidPtr(ob);
#endif #endif
if (!*(void **)vtabptr) if (!*(void **)vtabptr)
goto bad; goto bad;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment