tags:

views:

490

answers:

3

I have a python program that uses a custom-built DLL. This DLL crashes due to a stack overflow. This overflow is not due to a recursive function gone bad, but to large allocations on the stack using alloca().

I want to increase stack size to get rid of this error. Is there any way to do this?

+1  A: 

The functions in a dll can have no control over the stack size available when they are executed (unless you spawn new threads under the control of your library).

If the dll is custom, then can't you allocate on the heap rather than stack (or statically allocate, if appropriate), and stop the problem that way?

Autopulated
+1  A: 

AFAIK a program can only change the stack size of new threads or processes (Windows' CreateThread function, for example). As Python (and the Win32 API for Python) does not expose such functionality, you should rather replace the stack allocation with heap memory. Or is there a specific reason for using the stack?? If you really have to use alloca you might want to create a separate thread for execution of DLL code (which is overkill I think).

EDIT: Correction - Python does allow for setting the stack size when creating new threads (see thread.stack_size)

AndiDog
The ODE engine (the DLL which causes the problem) uses alloca to speed-up large matrix computations. Fortunately, it has a compile flag that lets me switch it to malloc instead. It's a bit slower, but it works. Thanks!
Philippe Beaudoin
+3  A: 

The python thread module allows you to specify a new stack size for new threads. Try setting that to a value you feel is large enough, and then doing the work of this DLL in a new thread.

zdan