[New-bugs-announce] [issue13186] instance_ass_item() broken in classobject.c (Py2.7)

Stefan Behnel report at bugs.python.org
Sat Oct 15 15:30:38 CEST 2011

New submission from Stefan Behnel <scoder at users.sourceforge.net>:

Starting at line 1223 in classobject.c, you can find this code:

    if (item == NULL)
        arg = PyInt_FromSsize_t(i);
        arg = Py_BuildValue("(nO)", i, item);
    if (arg == NULL) {
        return -1;
    res = PyEval_CallObject(func, arg);

If item is NULL, arg will be assigned an int object. Otherwise, it will receive a tuple. Only the second case works in the subsequent call to PyEval_CallObject(), i.e. arg must always be assigned an argument tuple.

A quick fix would be to call Py_BuildValue("(n)", i) in the first case. The code just did a getattr(), so this is not performance critical anymore.

I found this bug because the test_class.py test suite was failing in Cython.

components: Interpreter Core
messages: 145590
nosy: scoder
priority: normal
severity: normal
status: open
title: instance_ass_item() broken in classobject.c (Py2.7)
type: behavior
versions: Python 2.7

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list