From: Daniel J S. <dan...@ie...> - 2004-07-27 20:28:30
|
Ethan Merritt wrote: >gp_alloc() >========== >I assume the intent is to use this function everywhere >rather than to use malloc() directly. Without this >restriction, gnuplot's memory use code in alloc.c dies >dramatically if you use the free() macro. >So is it correct that all uses of malloc() are bugs? >getcolor.c in particular is an offender in this regard. >Should the guidelines in CodeStyle mention this restriction? > In what sense do you mean the memory use code dies dramatically? The gp_alloc() routine could be made a definition or a function, e.g., in alloc.h define #if USE_MEMORY_CHECK generic *gp_alloc __PROTO((size_t size, const char *message)); generic *gp_realloc __PROTO((generic *p, size_t size, const char *message)); void gpfree __PROTO((generic *p)); #define alloc <some kind of error macro saying "use gp_alloc"> #define realloc <some kind of error macro saying "use gp_realloc"> #define free <some kind of error macro saying "use gpfree"> #else #define gp_alloc alloc #define gp_realloc realloc #define gpfree free #endif That will force developers to use gp_alloc consistently, but users--who likely won't know how to use gp_alloc--can leave that code out. Dan PS: Why isn't gpfree, gp_free; consistent with gp_alloc, etc.? |