[Python-Dev] Fun with numbers (original) (raw)

Steve Holden sholden@holdenweb.com
Fri, 26 Apr 2002 12:08:32 -0400


----- Original Message ----- From: "Guido van Rossum" <guido@python.org> To: "Barry A. Warsaw" <barry@zope.com> Cc: <python-dev@python.org> Sent: Thursday, April 25, 2002 9:02 PM Subject: Re: [Python-Dev] Fun with numbers

> Tim, Jeremy, and I are having so much fun... [...] > >>> 23000 .class = bool > Debug memory block at address p=0x814f544: > 485823496 bytes originally requested > the 4 pad bytes at p-4 are not all FORBIDDENBYTE (0xfb): > at p-4: 0x7a *** OUCH > at p-3: 0x61 *** OUCH > at p-2: 0xc8 *** OUCH > at p-1: 0x3c *** OUCH > the 4 pad bytes at tail=0x250a094c are Segmentation fault

Ouch. Fixed in CVS for this particular case, but I think you may still be able provoke this with a built-in type that derives from another built-in type without adding any new fields, if the base type has a funky allocator that the derived type doesn't inherit. Also, the fix means that if an extension defines a type that inherits from int but doesn't override tpalloc and tpfree, it inherits a tpalloc that's not matched to the tpfree. But why would anyone do that...? Probably because they don't know what they're doing. Expect to see my bug report in SourceForge.

Inspired by this, I tried something else.

>>> print True True >>> True.class = int >>> print True 1 >>> There are no ill side effects. Handy for bool-haters. :-) Now that's neat.

regards Steve

home: http://www.holdenweb.com/ Python Web Programming: http://pydish.holdenweb.com/pwp/