Proper tail recursion

Chris King squirrel at wpi.edu
Sat Jul 10 01:20:46 EDT 2004


Christopher T King wrote:
> I take that back. The intertwinement of C functions and Python calls on
> the stack makes this nearly impossible -- there's no easy way to pop both
> the C and Python stacks before calling the next function (it could be
> partially done popping only the Python stack, though). Methinks tail calls 
> will have to wait for Stackless.

Here I am, replying to myself again :)

I'm trying a new implementation, making good use of a loop around the 
entirety of PyEval_EvalFrame(). Unfortunately, my changes cause the 
interpreter to segfault after a couple of tail calls. A debugger shows 
that 0xffffffff is getting stuck into a pool->freeblock in 
PyObject_Free(), and then is subsequently dereferenced in 
PyObject_Malloc() (causing the segfault).

Could this be caused by my code Py_DECREFing an object too many times, 
but leaving a pointer to it somewhere? (My changes don't explicitly set 
anything to 0xffffffff or -1.) Or am I just in way over my head? :P



More information about the Python-list mailing list