Ticket #151 (closed defect: fixed)
'with' statement doesn't compile on C++
| Reported by: | scoder | Owned by: | dagss |
|---|---|---|---|
| Priority: | critical | Milestone: | 0.11 |
| Component: | Code Generation | Keywords: | |
| Cc: |
Description (last modified by scoder) (diff)
This crashes due to incorrect temp deallocation:
with ContextManager(u"value") as x:
return x
The generated code is:
__pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_ContextManager); if [error goto]
/* __pyx_t_6 allocated */
__pyx_t_6 = PyTuple_New(1); if [error goto]
Py_INCREF(((PyObject *)__pyx_kp_8));
PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_kp_8));
/* __pyx_t_7 allocated */
__pyx_t_7 = PyObject_Call(__pyx_1, ((PyObject *)__pyx_t_6), NULL); if [error goto]
Py_DECREF(__pyx_1); __pyx_1 = 0;
Py_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
/* __pyx_t_6 released */
Py_XDECREF(__pyx_t_2);
__pyx_t_2 = __pyx_t_7;
__pyx_t_7 = 0;
...
/*try:*/ {
{
...
Py_DECREF(__pyx_t_6); __pyx_t_6 = 0;
Py_DECREF(__pyx_t_7); __pyx_t_7 = 0;
Py_DECREF(__pyx_t_8); __pyx_t_8 = 0;
goto __pyx_L5;
Note how __pyx_t_7 is DECREF-ed on return, as it is not released after retrieving the context manager in the temp variable and assigning it to a new temp.
There's a disabled test case in run/withstat.pyx that tests for this.
Change History
Note: See
TracTickets for help on using
tickets.
