From: Lisandro Dalcin Date: Fri, 2 Jul 2010 18:57:21 +0000 (-0300) Subject: use PyCapsule for Py 2.7+ (but not in Py 3.0) X-Git-Tag: 0.13.beta0~42 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ea4db01b32d6d8d203ac7ac344a86b882f416dfb;p=cython.git use PyCapsule for Py 2.7+ (but not in Py 3.0) --- diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index d112d512..e06e83f1 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -2246,10 +2246,10 @@ static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *s goto bad; } tmp.fp = f; -#if PY_VERSION_HEX < 0x03010000 - cobj = PyCObject_FromVoidPtrAndDesc(tmp.p, (void *)sig, 0); -#else +#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0) cobj = PyCapsule_New(tmp.p, sig, 0); +#else + cobj = PyCObject_FromVoidPtrAndDesc(tmp.p, (void *)sig, 0); #endif if (!cobj) goto bad; @@ -2280,9 +2280,6 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (** void (*fp)(void); void *p; } tmp; -#if PY_VERSION_HEX < 0x03010000 - const char *desc, *s1, *s2; -#endif d = PyObject_GetAttrString(module, (char *)"%(API)s"); if (!d) @@ -2294,7 +2291,16 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (** PyModule_GetName(module), funcname); 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); if (!desc) goto bad; @@ -2306,15 +2312,7 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (** PyModule_GetName(module), funcname, sig, desc); goto bad; } - 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); + tmp.p = PyCObject_AsVoidPtr(cobj);} #endif *f = tmp.fp; if (!(*f)) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 9b4fa4c2..0f9c3e43 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -5931,10 +5931,10 @@ static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/ """, impl = """ static int __Pyx_SetVtable(PyObject *dict, void *vtable) { -#if PY_VERSION_HEX < 0x03010000 - PyObject *ob = PyCObject_FromVoidPtr(vtable, 0); -#else +#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0) PyObject *ob = PyCapsule_New(vtable, 0, 0); +#else + PyObject *ob = PyCObject_FromVoidPtr(vtable, 0); #endif if (!ob) goto bad; @@ -5959,10 +5959,10 @@ static int __Pyx_GetVtable(PyObject *dict, void *vtabptr) { PyObject *ob = PyMapping_GetItemString(dict, (char *)"__pyx_vtable__"); if (!ob) goto bad; -#if PY_VERSION_HEX < 0x03010000 - *(void **)vtabptr = PyCObject_AsVoidPtr(ob); -#else +#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0) *(void **)vtabptr = PyCapsule_GetPointer(ob, 0); +#else + *(void **)vtabptr = PyCObject_AsVoidPtr(ob); #endif if (!*(void **)vtabptr) goto bad;