From dc9621d502c87ea78e1e68212724eb9ffcc2037c Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sat, 6 Mar 2010 23:59:55 +0000 Subject: 3K: f2py: make create_cb_arglist work with Py3 functions --- numpy/f2py/cfuncs.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'numpy') diff --git a/numpy/f2py/cfuncs.py b/numpy/f2py/cfuncs.py index 74a0ab363..a6b1c933d 100644 --- a/numpy/f2py/cfuncs.py +++ b/numpy/f2py/cfuncs.py @@ -1032,14 +1032,24 @@ if (tmp_fun==NULL) { fprintf(stderr,\"Call-back argument must be function|instance|instance.__call__|f2py-function but got %s.\\n\",(fun==NULL?\"NULL\":Py_TYPE(fun)->tp_name)); goto capi_fail; } +#if PY_VERSION_HEX >= 0x03000000 +\tif (PyObject_HasAttrString(tmp_fun,\"__code__\")) { +\t\tif (PyObject_HasAttrString(tmp = PyObject_GetAttrString(tmp_fun,\"__code__\"),\"co_argcount\")) +#else \tif (PyObject_HasAttrString(tmp_fun,\"func_code\")) { \t\tif (PyObject_HasAttrString(tmp = PyObject_GetAttrString(tmp_fun,\"func_code\"),\"co_argcount\")) +#endif \t\t\ttot = PyInt_AsLong(PyObject_GetAttrString(tmp,\"co_argcount\")) - di; \t\tPy_XDECREF(tmp); \t} \t/* Get the number of optional arguments */ +#if PY_VERSION_HEX >= 0x03000000 +\tif (PyObject_HasAttrString(tmp_fun,\"__defaults__\")) +\t\tif (PyTuple_Check(tmp = PyObject_GetAttrString(tmp_fun,\"__defaults__\"))) +#else \tif (PyObject_HasAttrString(tmp_fun,\"func_defaults\")) \t\tif (PyTuple_Check(tmp = PyObject_GetAttrString(tmp_fun,\"func_defaults\"))) +#endif \t\t\topt = PyTuple_Size(tmp); \t\tPy_XDECREF(tmp); \t/* Get the number of extra arguments */ -- cgit v1.2.1