Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use function pointer arguments in import/export api functions (by Lis…

…andro)
  • Loading branch information...
commit 5cf5559b0281143632bf5c889a9f00bc762d9dee 1 parent 12f0814
Stefan Behnel authored
Showing with 25 additions and 14 deletions.
  1. +25 −14 Cython/Compiler/ModuleNode.py
View
39 Cython/Compiler/ModuleNode.py
@@ -201,7 +201,7 @@ def generate_api_code(self, env, result):
for entry in api_funcs:
sig = entry.type.signature_string()
h_code.putln(
- 'if (__Pyx_ImportFunction(module, "%s", (void**)&%s, "%s") < 0) goto bad;' % (
+ 'if (__Pyx_ImportFunction(module, "%s", (void (**)(void))&%s, "%s") < 0) goto bad;' % (
entry.name,
entry.cname,
sig))
@@ -1802,7 +1802,7 @@ def generate_c_function_export_code(self, env, code):
if entry.api or entry.defined_in_pxd:
env.use_utility_code(function_export_utility_code)
signature = entry.type.signature_string()
- code.putln('if (__Pyx_ExportFunction("%s", (void*)%s, "%s") < 0) %s' % (
+ code.putln('if (__Pyx_ExportFunction("%s", (void (*)(void))%s, "%s") < 0) %s' % (
entry.name,
entry.cname,
signature,
@@ -1834,7 +1834,7 @@ def generate_c_function_import_code_for_module(self, module, env, code):
code.error_goto(self.pos)))
for entry in entries:
code.putln(
- 'if (__Pyx_ImportFunction(%s, "%s", (void**)&%s, "%s") < 0) %s' % (
+ 'if (__Pyx_ImportFunction(%s, "%s", (void (**)(void))&%s, "%s") < 0) %s' % (
temp,
entry.name,
entry.cname,
@@ -2133,17 +2133,22 @@ def generate_utility_functions(self, env, code, h_code):
function_export_utility_code = UtilityCode(
proto = """
-static int __Pyx_ExportFunction(const char *name, void *f, const char *sig); /*proto*/
+static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig); /*proto*/
""",
impl = r"""
-static int __Pyx_ExportFunction(const char *name, void *f, 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 *p = 0;
+ PyObject *cobj = 0;
+ union {
+ void (*fp)(void);
+ void *p;
+ } tmp;
+
d = PyObject_GetAttrString(%(MODULE)s, api);
if (!d) {
@@ -2155,16 +2160,17 @@ def generate_utility_functions(self, env, code, h_code):
if (PyModule_AddObject(%(MODULE)s, api, d) < 0)
goto bad;
}
- p = PyCObject_FromVoidPtrAndDesc(f, (void *)sig, 0);
- if (!p)
+ tmp.fp = f;
+ cobj = PyCObject_FromVoidPtrAndDesc(tmp.p, (void *)sig, 0);
+ if (!cobj)
goto bad;
- if (PyDict_SetItemString(d, name, p) < 0)
+ if (PyDict_SetItemString(d, name, cobj) < 0)
goto bad;
- Py_DECREF(p);
+ Py_DECREF(cobj);
Py_DECREF(d);
return 0;
bad:
- Py_XDECREF(p);
+ Py_XDECREF(cobj);
Py_XDECREF(d);
return -1;
}
@@ -2175,12 +2181,12 @@ def generate_utility_functions(self, env, code, h_code):
function_import_utility_code = UtilityCode(
proto = """
-static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void **f, const char *sig); /*proto*/
+static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig); /*proto*/
""",
impl = """
#ifndef __PYX_HAVE_RT_ImportFunction
#define __PYX_HAVE_RT_ImportFunction
-static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void **f, 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
@@ -2190,6 +2196,10 @@ def generate_utility_functions(self, env, code, h_code):
PyObject *cobj = 0;
const char *desc;
const char *s1, *s2;
+ union {
+ void (*fp)(void);
+ void *p;
+ } tmp;
d = PyObject_GetAttrString(module, api);
if (!d)
@@ -2212,7 +2222,8 @@ def generate_utility_functions(self, env, code, h_code):
PyModule_GetName(module), funcname, sig, desc);
goto bad;
}
- *f = PyCObject_AsVoidPtr(cobj);
+ tmp.p = PyCObject_AsVoidPtr(cobj);
+ *f = tmp.fp;
Py_DECREF(d);
return 0;
bad:
Please sign in to comment.
Something went wrong with that request. Please try again.