A question about fill_free_list(void) function

Christian Heimes lists at cheimes.de
Wed Jul 1 14:01:55 EDT 2009


Pedram schrieb:
> Hello community,
> I'm reading the CPython interpreter source code,
> first, if you have something that I should know for better reading
> this source code, I would much appreciate that :)
> second, in intobject.c file, I read the following code in
> fill_free_list function that I couldn't understand:
> <code>while (--q > p)
>     Py_TYPE(q) = (struct _typeobject *)(q-1);
> Py_TYPE(q) = NULL;
> </code>
> What does it mean?

The code is abusing the ob_type member to store a single linked, NULL
terminated list of free integer objects. It's a tricky optimization you
don't have to understand in order to understand the rest of the code.

And no, the code in ctypes.h is totally unrelated to the free list in
intobject.c.

Christian




More information about the Python-list mailing list