: [Python-Dev] RE: Painful death in debug build

Tim Peters tim.one@home.com
Sat, 6 Oct 2001 01:32:44 -0400


This is enough to reproduce the problem under a debug Windows build:

---------------------------------------------------------------
class X(long):
    pass

x = X(0xffffL)
print "before del"
del x
print "after del"
---------------------------------------------------------------

It does not fail if the instance is created via

    x = X(0x7fffL)

instead.  It does fail on

    x = X(0x8000L)

The relevant difference is that Python uses 15-bit "digits" internally for
longs, so 0x8000 may be the smallest value that will cause it to allocate
more memory than already comes for free with the _longobject header:

struct _longobject {
	PyObject_HEAD
	int ob_size;
	digit ob_digit[1];
};

but-too-tired-to-do-more-now-ly y'rs  - tim