[replying to myself...]

Stefan Behnel wrote:
> When I add DECREF cleanup code to the return statement, the test suite
> passes just like before

and in fact, the code that the iter-dict transform generates for ticket
#124 shows that this is required. For this code

    def spam(dict d):
        for elm in d:
            return False
        return True

Cython now generates this when I add DEFREF cleanup code for new-style
temps to the return statement:

  [...]
  PyObject *__pyx_t_1 = NULL;
  [...]
  __pyx_t_2 = 0;
  Py_INCREF(((PyObject *)__pyx_v_d));
  Py_XDECREF(__pyx_t_1);
  __pyx_t_1 = ((PyObject *)__pyx_v_d);
  while (1) {
    if (!PyDict_Next(__pyx_t_1, (&__pyx_t_2),   \
                         ((PyObject **)(&__pyx_t_3)), NULL)) break;
    Py_INCREF(((PyObject *)__pyx_t_3));
    Py_DECREF(__pyx_v_elm);
    __pyx_v_elm = ((PyObject *)__pyx_t_3);

    __pyx_3 = __Pyx_PyBool_FromLong(0); if () [error goto];
    __pyx_r = __pyx_3;
    __pyx_3 = 0;
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    Py_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    goto __pyx_L0;
  }

Note the line where it says "Py_DECREF(__pyx_t_1); __pyx_t_1 = 0;", which
wasn't there before.

(BTW, the bogus "DECREF(__pyx_2)" is the reason why ticket 124 exists in
the first place).

The same applies to the error case, where Cython currently generates

  __pyx_L1_error:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("ticket124.spam");

This certainly lacks an XDECREF for __pyx_t_1, as the error goto inside the
loop ends up here.

One more thing: the above loop code also lacks a DECREF(__pyx_t_1) /after/
the loop. I currently have no idea how to put it there...

Stefan
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to