glib: alloca brain damages



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.

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
"In film you will find four basic story lines. Man versus man, man
 versus nature, nature versus nature, and dog versus vampire."
    - Steven Spielberg





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