How Python Implements "long integer"?

Eric Wong wsysdu at
Tue Jul 7 02:56:40 EDT 2009

Pedram wrote:

> Hello Mr. Dickinson. Glad to see you again :)
> On Jul 6, 5:46 pm, Mark Dickinson <dicki... at> wrote:
>> On Jul 6, 1:24 pm, Pedram <pm567... at> wrote:
>> > OK, fine, I read longobject.c at last! :)
>> > I found that longobject is a structure like this:
>> > struct _longobject {
>> > struct _object *_ob_next;
>> > struct _object *_ob_prev;
>> For current CPython, these two fields are only present in debug
>> builds;  for a normal build they won't exist.
> I couldn't understand the difference between them. What are debug
> build and normal build themselves? And You mean in debug build
> PyLongObject is a doubly-linked-list but in normal build it is just 
> array (Or if not how it'll store in this mode)?
we use the macro Py_TRACE_REFS to differ the code for debug build and 
normal build, that's to say, in debug build and normal build the codes 
are actually *different*. In debug build, not only PyLongObject but 
all Objects are linked by a doubly-linked-list and it can make the 
debug process less painful. But in normal build, objects are 
seperated! After an object is created, it will never be moved, so we 
can and should refer to an object only by it's address(pointer). 
There's no one-big-container like a list or an array for objects.

More information about the Python-list mailing list