This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Statement expression with function-call variable lifetime
- From: Shaun Jackman <sjackman at gmail dot com>
- To: Russell Shaw <rjshaw at netspace dot net dot au>
- Cc: gcc at sources dot redhat dot com
- Date: Wed, 29 Jun 2005 23:08:48 -0700
- Subject: Re: Statement expression with function-call variable lifetime
- References: <7f45d93905062910344b524c33@mail.gmail.com> <42C357FE.30204@netspace.net.au>
- Reply-to: Shaun Jackman <sjackman at gmail dot com>
On 6/29/05, Russell Shaw <rjshaw@netspace.net.au> wrote:
> Alloca is like creating a stack variable, except it just gives you some
> generic bytes that don't mean anything. Exiting the local scope will
> trash the local variables and anything done with alloca(). You'll need
> to store some information in a global variable. This C exceptions method
> stores things as a linked list in nested stack frames and keeps a pointer
> to the list in a global variable. Well worth studying:
>
> http://ldeniau.home.cern.ch/ldeniau/html/exception/exception.html
Thanks! That linked was a very good reference. Here's the new and
improved vfork macro. It works nicely! If anyone's curious enough, I
can post the exit and waitpid macros that accompany it. I'm using
these macros to implement a Busybox system that does not need a fork
system call.
Thanks for all your help, Daniel and Russell! Cheers,
Shaun
struct vfork_context {
struct vfork_context *prev;
jmp_buf jmp;
} *vfork_context;
# define vfork() ({ \
int setjmp_ret; \
struct vfork_context *c = alloca(sizeof *c); \
c->prev = vfork_context; \
vfork_context = c; \
if( (setjmp_ret = setjmp(c->jmp)) != 0 ) \
vfork_context = vfork_context->prev; \
setjmp_ret; \
})