incorrect code order for single type-qualified argument

Bug #206821 reported by Felix Wu
4
Affects Status Importance Assigned to Milestone
Cython
Fix Committed
Undecided
Unassigned

Bug Description

For methods taking a single, required argument with type qualifier, the code generated will do type conversion first before increment the reference count of the "self" argument (in 0.9.6.12 and later), this can cause reference mis-count should error occur in the type conversion (which will jump to the exit code and decrement the ref count). This does not happen in 0.9.6.11b.

Here is an example:

    def setDouble(self, double d):
        self._this.setDouble(d)

Code generated:

static PyObject *__pyx_pf_4test_7pyCTest_setDouble(PyObject *__pyx_v_self, PyObject *__pyx_arg_d) {
  double __pyx_v_d;
  PyObject *__pyx_r;
  assert(__pyx_arg_d); {
    __pyx_v_d = __pyx_PyFloat_AsDouble(__pyx_arg_d); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} /* THIS GOTO WILL SKIP THE FOLLOWING INCREF ON self */
  }
  Py_INCREF(__pyx_v_self); /* THIS LINE SHOULD COME BEFORE THE PREVIOUS BLOCK */
   ((struct yCTest *)__pyx_v_self)->_this.setDouble(__pyx_v_d);

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("test.pyCTest.setDouble");
  __pyx_r = NULL;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

Revision history for this message
robertwb (robertwb) wrote :

Fixed and improved the error returned too.

Changed in cython:
status: New → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.