How Python Implements "long integer"?

Mark Dickinson dickinsm at
Tue Jul 7 11:10:31 CEST 2009

On Jul 6, 4:13 pm, Pedram <pm567... at> wrote:
> 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 an
> array (Or if not how it'll store in this mode)?

No:  a PyLongObject is stored the same way (ob_size giving sign and
number of digits, ob_digit giving the digits themselves) whether or
not a debug build is in use.

A debug build does various things (extra checks, extra information) to
make it easier to track down problems.  On Unix-like systems, you can
get a debug build by configuring with the --with-pydebug flag.

The _ob_next and _ob_prev fields have nothing particularly to do with
Python longs; for a debug build, these two fields are added to *all*
Python objects, and provide a doubly-linked list that links all 'live'
Python objects together.  I'm not really sure what, if anything, the
extra information is used for within Python---it might be used by some
external tools, I guess.

Have you looked at the C-API documentation?

_ob_next and _ob_prev are described here:

(These docs are for Python 2.6;  I'm not sure what version you're
working with.)


More information about the Python-list mailing list