Commit 49ef0f6b authored by Lisandro Dalcin's avatar Lisandro Dalcin

Public module C-API is broken under Python 3.2 (ticket #407)

--HG--
extra : rebase_source : b760de58ec941046c86e5ecadb5afc4c56d9ddaa
parent 78642940
...@@ -2198,11 +2198,6 @@ static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *s ...@@ -2198,11 +2198,6 @@ static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *s
""", """,
impl = r""" impl = r"""
static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig) { static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig) {
#if PY_VERSION_HEX < 0x02050000
char *api = (char *)"%(API)s";
#else
const char *api = "%(API)s";
#endif
PyObject *d = 0; PyObject *d = 0;
PyObject *cobj = 0; PyObject *cobj = 0;
union { union {
...@@ -2210,19 +2205,22 @@ static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *s ...@@ -2210,19 +2205,22 @@ static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *s
void *p; void *p;
} tmp; } tmp;
d = PyObject_GetAttrString(%(MODULE)s, (char *)"%(API)s");
d = PyObject_GetAttrString(%(MODULE)s, api);
if (!d) { if (!d) {
PyErr_Clear(); PyErr_Clear();
d = PyDict_New(); d = PyDict_New();
if (!d) if (!d)
goto bad; goto bad;
Py_INCREF(d); Py_INCREF(d);
if (PyModule_AddObject(%(MODULE)s, api, d) < 0) if (PyModule_AddObject(%(MODULE)s, (char *)"%(API)s", d) < 0)
goto bad; goto bad;
} }
tmp.fp = f; tmp.fp = f;
#if PY_VERSION_HEX < 0x03010000
cobj = PyCObject_FromVoidPtrAndDesc(tmp.p, (void *)sig, 0); cobj = PyCObject_FromVoidPtrAndDesc(tmp.p, (void *)sig, 0);
#else
cobj = PyCapsule_New(tmp.p, sig, 0);
#endif
if (!cobj) if (!cobj)
goto bad; goto bad;
if (PyDict_SetItemString(d, name, cobj) < 0) if (PyDict_SetItemString(d, name, cobj) < 0)
...@@ -2238,8 +2236,6 @@ bad: ...@@ -2238,8 +2236,6 @@ bad:
""" % {'MODULE': Naming.module_cname, 'API': Naming.api_name} """ % {'MODULE': Naming.module_cname, 'API': Naming.api_name}
) )
#------------------------------------------------------------------------------------
function_import_utility_code = UtilityCode( function_import_utility_code = UtilityCode(
proto = """ proto = """
static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig); /*proto*/ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig); /*proto*/
...@@ -2248,21 +2244,17 @@ impl = """ ...@@ -2248,21 +2244,17 @@ impl = """
#ifndef __PYX_HAVE_RT_ImportFunction #ifndef __PYX_HAVE_RT_ImportFunction
#define __PYX_HAVE_RT_ImportFunction #define __PYX_HAVE_RT_ImportFunction
static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig) { static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig) {
#if PY_VERSION_HEX < 0x02050000
char *api = (char *)"%(API)s";
#else
const char *api = "%(API)s";
#endif
PyObject *d = 0; PyObject *d = 0;
PyObject *cobj = 0; PyObject *cobj = 0;
const char *desc;
const char *s1, *s2;
union { union {
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, api); d = PyObject_GetAttrString(module, (char *)"%(API)s");
if (!d) if (!d)
goto bad; goto bad;
cobj = PyDict_GetItemString(d, funcname); cobj = PyDict_GetItemString(d, funcname);
...@@ -2272,6 +2264,7 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (** ...@@ -2272,6 +2264,7 @@ 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
desc = (const char *)PyCObject_GetDesc(cobj); desc = (const char *)PyCObject_GetDesc(cobj);
if (!desc) if (!desc)
goto bad; goto bad;
...@@ -2284,7 +2277,18 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (** ...@@ -2284,7 +2277,18 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**
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
*f = tmp.fp; *f = tmp.fp;
if (!(*f))
goto bad;
Py_DECREF(d); Py_DECREF(d);
return 0; return 0;
bad: bad:
...@@ -2295,6 +2299,8 @@ bad: ...@@ -2295,6 +2299,8 @@ bad:
""" % dict(API = Naming.api_name) """ % dict(API = Naming.api_name)
) )
#------------------------------------------------------------------------------------
register_cleanup_utility_code = UtilityCode( register_cleanup_utility_code = UtilityCode(
proto = """ proto = """
static int __Pyx_RegisterCleanup(void); /*proto*/ static int __Pyx_RegisterCleanup(void); /*proto*/
......
...@@ -5425,22 +5425,20 @@ static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/ ...@@ -5425,22 +5425,20 @@ 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) {
PyObject *pycobj = 0; #if PY_VERSION_HEX < 0x03010000
int result; PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
#else
pycobj = PyCObject_FromVoidPtr(vtable, 0); PyObject *ob = PyCapsule_New(vtable, 0, 0);
if (!pycobj) #endif
if (!ob)
goto bad; goto bad;
if (PyDict_SetItemString(dict, "__pyx_vtable__", pycobj) < 0) if (PyDict_SetItemString(dict, "__pyx_vtable__", ob) < 0)
goto bad; goto bad;
result = 0; Py_DECREF(ob);
goto done; return 0;
bad: bad:
result = -1; Py_XDECREF(ob);
done: return -1;
Py_XDECREF(pycobj);
return result;
} }
""") """)
...@@ -5452,23 +5450,21 @@ static int __Pyx_GetVtable(PyObject *dict, void *vtabptr); /*proto*/ ...@@ -5452,23 +5450,21 @@ static int __Pyx_GetVtable(PyObject *dict, void *vtabptr); /*proto*/
""", """,
impl = r""" impl = r"""
static int __Pyx_GetVtable(PyObject *dict, void *vtabptr) { static int __Pyx_GetVtable(PyObject *dict, void *vtabptr) {
int result; PyObject *ob = PyMapping_GetItemString(dict, (char *)"__pyx_vtable__");
PyObject *pycobj; if (!ob)
pycobj = PyMapping_GetItemString(dict, (char *)"__pyx_vtable__");
if (!pycobj)
goto bad; goto bad;
*(void **)vtabptr = PyCObject_AsVoidPtr(pycobj); #if PY_VERSION_HEX < 0x03010000
*(void **)vtabptr = PyCObject_AsVoidPtr(ob);
#else
*(void **)vtabptr = PyCapsule_GetPointer(ob, 0);
#endif
if (!*(void **)vtabptr) if (!*(void **)vtabptr)
goto bad; goto bad;
result = 0; Py_DECREF(ob);
goto done; return 0;
bad: bad:
result = -1; Py_XDECREF(ob);
done: return -1;
Py_XDECREF(pycobj);
return result;
} }
""") """)
......
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