[Python-Dev] Possible bug in complexobject.c (still in Python 2.5) (original) (raw)

Travis E. Oliphant oliphant.travis at ieee.org
Thu Jun 1 05:59:03 CEST 2006


Guido van Rossum wrote:

I wouldn't be surprised if this is a genuine bug; the complex type doesn't get a lot of love from core developers.

Could you come up with a proposed fix, and a unit test showing that it works (and that the old version doesn't)? (Maybe a good unit test would require writing a custome C extension; in that case just show some sample code.)

Attached is a sample module that exposes the problem. The problem goes away by replacing

op = PyType_GenericAlloc(type, 0);

with

op = type->tp_alloc(type, 0);

in the function

complex_subtype_from_c_complex

in the file complexobject.c (about line #191).

The problem with a unit test is that it might not fail. On my Linux system, it doesn't complain about the problem unless I first use strict pointer checking with

export MALLOC_CHECK_=2

Then the code

import bugtest a = bugtest.newcomplex(3.0) del a

Aborts

Valgrind also shows the error when running the simple code. It seems pretty clear to me that the subtype code should be calling the sub-types tp_alloc code instead of the generic one.

Best regards,

-Travis

-------------- next part -------------- A non-text attachment was scrubbed... Name: bugtest.c Type: text/x-csrc Size: 1035 bytes Desc: not available Url : http://mail.python.org/pipermail/python-dev/attachments/20060531/db6f3342/attachment-0001.c



More information about the Python-Dev mailing list