[Python-3000] Free list for small longs

Christian Heimes lists at cheimes.de
Tue Feb 5 21:26:44 CET 2008


skip at pobox.com wrote:
> I'm not sure what you mean by "size of 1 or -1".  Do you mean you only keep
> the numbers 1 and -1 on the free list?  It's not obvious to me what a size
> of -1 is.  Do you mean positive and negative numbers which fit in one byte
> or one long word?

I should have explained how longs use the object size. The absolute
value of Python long is stored is an array of digits (unsigned short).
For Negative values Python longs set the ob_size to a negative value.

>From Include/longintpr.h:

/* Long integer representation.
   The absolute value of a number is equal to
        SUM(for i=0 through abs(ob_size)-1) ob_digit[i] * 2**(SHIFT*i)
   Negative numbers are represented with ob_size < 0;
   zero is represented by ob_size == 0.
   In a normalized number, ob_digit[abs(ob_size)-1] (the most significant
   digit) is never zero.  Also, in all cases, for all valid i,
        0 <= ob_digit[i] <= MASK.
   The allocation function takes care of allocating extra memory
   so that ob_digit[0] ... ob_digit[abs(ob_size)-1] are actually available.

   CAUTION:  Generic code manipulating subtypes of PyVarObject has to
   aware that longs abuse  ob_size's sign bit.
*/

Christian


More information about the Python-3000 mailing list