Commit 15d77968 authored by da-woods's avatar da-woods Committed by GitHub

Fixed issue where fused functions didn't register as cyfunctions (GH-3386)

* Fixed issue where fused functions didn't register as cyfunctions

Issue https://github.com/cython/cython/issues/3384

This happened where Cython was using a shared API because the
CyFunction type imported from the shared api wasn't the same as
used to initialize the fused function tp_base.
parent e8540c18
...@@ -1428,6 +1428,7 @@ static PyTypeObject __pyx_FusedFunctionType_type = { ...@@ -1428,6 +1428,7 @@ static PyTypeObject __pyx_FusedFunctionType_type = {
// __doc__ is None for the fused function type, but we need it to be // __doc__ is None for the fused function type, but we need it to be
// a descriptor for the instance's __doc__, so rebuild descriptors in our subclass // a descriptor for the instance's __doc__, so rebuild descriptors in our subclass
__pyx_CyFunction_getsets, /*tp_getset*/ __pyx_CyFunction_getsets, /*tp_getset*/
// NOTE: tp_base may be changed later during module initialisation when importing CyFunction across modules.
&__pyx_CyFunctionType_type, /*tp_base*/ &__pyx_CyFunctionType_type, /*tp_base*/
0, /*tp_dict*/ 0, /*tp_dict*/
__pyx_FusedFunction_descr_get, /*tp_descr_get*/ __pyx_FusedFunction_descr_get, /*tp_descr_get*/
...@@ -1466,6 +1467,8 @@ static int __pyx_FusedFunction_init(void) { ...@@ -1466,6 +1467,8 @@ static int __pyx_FusedFunction_init(void) {
__pyx_FusedFunctionType = __Pyx_FetchCommonTypeFromSpec(&__pyx_FusedFunctionType_spec, bases); __pyx_FusedFunctionType = __Pyx_FetchCommonTypeFromSpec(&__pyx_FusedFunctionType_spec, bases);
Py_DECREF(bases); Py_DECREF(bases);
#else #else
// Set base from __Pyx_FetchCommonTypeFromSpec, in case it's different from the local static value.
__pyx_FusedFunctionType_type.tp_base = __pyx_CyFunctionType;
__pyx_FusedFunctionType = __Pyx_FetchCommonType(&__pyx_FusedFunctionType_type); __pyx_FusedFunctionType = __Pyx_FetchCommonType(&__pyx_FusedFunctionType_type);
#endif #endif
if (__pyx_FusedFunctionType == NULL) { if (__pyx_FusedFunctionType == NULL) {
......
...@@ -7,6 +7,9 @@ Test Python def functions without extern types ...@@ -7,6 +7,9 @@ Test Python def functions without extern types
cy = __import__("cython") cy = __import__("cython")
cimport cython cimport cython
cdef extern from *:
int __Pyx_CyFunction_Check(object)
cdef class Base(object): cdef class Base(object):
def __repr__(self): def __repr__(self):
return type(self).__name__ return type(self).__name__
...@@ -128,6 +131,16 @@ def opt_func(fused_t obj, cython.floating myf = 1.2, cython.integral myi = 7): ...@@ -128,6 +131,16 @@ def opt_func(fused_t obj, cython.floating myf = 1.2, cython.integral myi = 7):
print cython.typeof(obj), cython.typeof(myf), cython.typeof(myi) print cython.typeof(obj), cython.typeof(myf), cython.typeof(myi)
print obj, "%.2f" % myf, myi, "%.2f" % f, i print obj, "%.2f" % myf, myi, "%.2f" % f, i
def run_cyfunction_check():
"""
tp_base of the fused function was being set incorrectly meaning
it wasn't being identified as a CyFunction
>>> run_cyfunction_check()
fused_cython_function
1
"""
print(type(opt_func).__name__)
print(__Pyx_CyFunction_Check(opt_func)) # should be True
def test_opt_func(): def test_opt_func():
""" """
......
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