How Python Implements "long integer"?

Pedram pm567426 at gmail.com
Tue Jul 7 07:06:07 EDT 2009


On Jul 7, 1:10 pm, Mark Dickinson <dicki... at gmail.com> wrote:
> On Jul 6, 4:13 pm, Pedram <pm567... at gmail.com> wrote:
>
>
>
> > On Jul 6, 5:46 pm, Mark Dickinson <dicki... at gmail.com> wrote:
> > > On Jul 6, 1:24 pm, Pedram <pm567... at gmail.com> 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?
>
> http://docs.python.org/c-api/index.html
>
> _ob_next and _ob_prev are described here:
>
> http://docs.python.org/c-api/typeobj.html#_ob_next
>
> (These docs are for Python 2.6;  I'm not sure what version you're
> working with.)
>
> Mark

It seems there's an island named Python!
Thanks for links, I'm on reading them.



More information about the Python-list mailing list