[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lua_resume and a C-function as the main coroutine function problem
- From: Tony Finch <dot@...>
- Date: Wed, 14 Apr 2010 14:34:32 +0100
On Wed, 14 Apr 2010, Robert G. Jakabosky wrote:
>
> Using the jmp_buf hacks or assembly code, allows the program to allocate the
> stacks using malloc() or mmap().
You can use alloca() or C99 variable-length arrays to move the stack to
the heap. For example (assuming the stack grows downwards),
#define STACKSIZE (16*1024)
#define SLOP 16
void newstack(void f(void)) {
vois *osp = &f;
void *nsp = malloc(STACKSIZE) + STACKSIZE - SLOP;
void *dummy = alloca(osp - nsp);
f(); // runs with its stack on the heap
}
alloca() is just a way of subtracting some number from the stack pointer.
Tony.
--
f.anthony.n.finch <dot@dotat.at> http://dotat.at/
GERMAN BIGHT HUMBER: SOUTHWEST 5 TO 7. MODERATE OR ROUGH. SQUALLY SHOWERS.
MODERATE OR GOOD.