[pypy-issue] [issue1106] [cpyext] reassignments to tp_dict items don't have an effect

Stefan Behnel tracker at bugs.pypy.org
Mon Apr 2 09:23:09 CEST 2012


New submission from Stefan Behnel <stefan_ml at behnel.de>:

Cython's "exttypebody" test fails. It tries to reassign values to the type dict
as follows:

cdef class Spam:
    a = 1
    b = a + 2 # 3
    a = b - 1 # 2
    c = 3     # 3
    b = c + a # 5

But only the values that were assign first prevail (i.e. a==1, b==3).

The C code is basically as follows:

  /* a */
  if (PyDict_SetItem((PyObject *)__pyx_ptype_12extclassbody_Spam->tp_dict,
__pyx_n_s__a, __pyx_int_1) < 0) {...}
  PyType_Modified(__pyx_ptype_12extclassbody_Spam);

  /* a */
  __pyx_t_1 = __Pyx_GetName((PyObject *)__pyx_ptype_12extclassbody_Spam,
__pyx_n_s__a); if (unlikely(!__pyx_t_1)) {...}
  __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_int_2); if (unlikely(!__pyx_t_2)) {...}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem((PyObject *)__pyx_ptype_12extclassbody_Spam->tp_dict,
__pyx_n_s__b, __pyx_t_2) < 0) {...}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_12extclassbody_Spam);

  /* a */
  __pyx_t_2 = __Pyx_GetName((PyObject *)__pyx_ptype_12extclassbody_Spam,
__pyx_n_s__b); if (unlikely(!__pyx_t_2)) {...}
  __pyx_t_1 = PyNumber_Subtract(__pyx_t_2, __pyx_int_1); if
(unlikely(!__pyx_t_1)) {...}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem((PyObject *)__pyx_ptype_12extclassbody_Spam->tp_dict,
__pyx_n_s__a, __pyx_t_1) < 0) {...}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  PyType_Modified(__pyx_ptype_12extclassbody_Spam);

(__pyx_n_* and __pyx_int_* are Python object constants with the obvious value)

----------
messages: 4167
nosy: pypy-issue, sbehnel
priority: bug
status: unread
title: [cpyext] reassignments to tp_dict items don't have an effect

________________________________________
PyPy bug tracker <tracker at bugs.pypy.org>
<https://bugs.pypy.org/issue1106>
________________________________________


More information about the pypy-issue mailing list