2012/10/11 Armin Rigo <ar...@tunes.org>:
> On Thu, Oct 11, 2012 at 7:41 AM, Stefan Behnel <stefan...@behnel.de> wrote:
>> it crashes in line 606 of obmalloc.c, which reads as follows:
>>
>>     583    block *bp;
>>     [...]
>>     604         bp = pool->freeblock;
>>     605         assert(bp != NULL);
>>     606         if ((pool->freeblock = *(block **)bp) != NULL) {
>>
>> The cast looks a bit smelly to me. Could someone who knows that code please
>> take a look to see if it makes any sense?
>
> This obmalloc.c is straight from CPython.  It's very unlikely at this
> point to contain problems.

It looks like the typical hack of a "free list" implementation.
Freed blocks form a linked list, and the address of the next free
block is stored in the block itself.

So the line above effectively pops the first item in the list:
pool->freeblock is the address of the first free block,
PyObject_Malloc() will return it,
and pool->freeblock is changed to point to the next free block.

Everything looks normal to me, even if a bit obscure.

-- 
Amaury Forgeot d'Arc
_______________________________________________
pypy-dev mailing list
pypy-dev@python.org
http://mail.python.org/mailman/listinfo/pypy-dev

Reply via email to