summaryrefslogtreecommitdiff
path: root/Cython/Utility/CythonFunction.c
diff options
context:
space:
mode:
Diffstat (limited to 'Cython/Utility/CythonFunction.c')
-rw-r--r--Cython/Utility/CythonFunction.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/Cython/Utility/CythonFunction.c b/Cython/Utility/CythonFunction.c
index 4e3847529..65cce4f3e 100644
--- a/Cython/Utility/CythonFunction.c
+++ b/Cython/Utility/CythonFunction.c
@@ -1227,6 +1227,15 @@ __pyx_FusedFunction_descr_get(PyObject *self, PyObject *obj, PyObject *type)
if (obj == Py_None)
obj = NULL;
+ if (func->func.flags & __Pyx_CYFUNCTION_CLASSMETHOD)
+ obj = type;
+
+ if (obj == NULL) {
+ // We aren't actually binding to anything, save the effort of rebinding
+ Py_INCREF(self);
+ return self;
+ }
+
meth = (__pyx_FusedFunctionObject *) __pyx_FusedFunction_New(
((PyCFunctionObject *) func)->m_ml,
((__pyx_CyFunctionObject *) func)->flags,
@@ -1267,9 +1276,6 @@ __pyx_FusedFunction_descr_get(PyObject *self, PyObject *obj, PyObject *type)
Py_XINCREF(func->func.defaults_tuple);
meth->func.defaults_tuple = func->func.defaults_tuple;
- if (func->func.flags & __Pyx_CYFUNCTION_CLASSMETHOD)
- obj = type;
-
Py_XINCREF(obj);
meth->self = obj;