Re: glib: alloca brain damages
- From: Tim Janik <timj gtk org>
- To: gtk-devel-list redhat com
- cc: Elliot Lee <sopwith cuc edu>
- Subject: Re: glib: alloca brain damages
- Date: Mon, 4 Jan 1999 22:22:26 +0100 (CET)
On Mon, 4 Jan 1999, Elliot Lee wrote:
> 1.
>
> # define g_new0_a(type, count) \
> ((type *) memset (alloca ((unsigned) sizeof (type) * (count)), 0, \
> ((unsigned) sizeof (type) * (count))))
>
> Very bad - this is allocating a place on the stack while the compiler is
> trying to set up the stack for the function call. It should be something
> like
>
> # define g_new0_a(type, count) \
> G_STMT_STRT { \
> char *newblock;
> newblock = alloca(sizeof(type) * count);
> memset(newblock, 0, sizeof(type) * count);
> } G_STMT_END
>
>
> The problem is that G_STMT_STRT casts the block to (void), and ANSI C does
> not permit ({expr;}), so there's really no way to do it portably.
>
> 2. There's the whole problem of doing all these macros at all. On some
> arches/OS's, alloca() won't work inside conditionals, or inside {} blocks.
hm, sopwith, can you eventually provide concrete reports about such
behaviour? we shouldn't provide alloca using macros at all if that's affecting
any system that glib currently runs on.
>
> MHO is that the only thing that glib should be doing is ensuring that
> alloca() exists and works, nothing more. The actual usage should be done
> directly by the programmer.
>
> -- Elliot
---
ciaoTJ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]