lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 2010-04-14 14:34, Tony Finch wrote:
[...]
		vois *osp =&f;
		void *nsp = malloc(STACKSIZE) + STACKSIZE - SLOP;
		void *dummy = alloca(osp - nsp);

I would be very, very careful doing things like this --- you're utterly at mercy of the implementation. This will, for example, trigger any stack limit checking that your toolchain might be doing. And woe betide you if your alloca() implementations tries to memset() the data!

The Official(TM) way of changing stacks is to use setcontext()/getcontext(). However, that's still pretty fraught. I had one project that used C-based coroutines using setcontext()/getcontext() that produced obscure errors on certain libc versions on certain Linux kernels if you happened to link against a library that had been compiled with pthreads support, because pthreads was storing magic data at the top of the stack, and didn't work properly if you changed stacks...

--
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│
│ life←{ ↑1 ⍵∨.^3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵ }
│ --- Conway's Game Of Life, in one line of APL