[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: gEDA-user: Small patch to aid use of lib dmalloc
On Tue, 2010-12-07 at 14:59 +1100, Stephen Ecob wrote:
> I propose the following solution:
>
> 1. replace all calls to MyCalloc() with calls to calloc()
> 2. replace all calls to MyMalloc() with calls to malloc()
> 3. replace all calls to MyRealloc() with calls to realloc()
> 4. replace all calls to SaveFree() with calls to free()
> 5. retain the MYFREE() macro as its pointer clearing side effect is required
> 6. treat calls to MyStrdup() on a case by case basis:
> 6a. calls known to never supply a NULL pointer: replace MyStrdup(x,
> y) with strdup(x)
> 6b. calls known to sometimes supply a NULL pointer: replace
> MyStrdup(x, y) with: (x) ? strdup(x) : (x)
I propose similar, but with the convenience macro:
STRDUP(x) ((x) ? strdup(x) : (x))
Then any callers of MyStrdup can be safely swapped to STRDUP() rather
then strdup().
FWIW, g_strdup from glib allows the passed string to be NULL (and will
return NULL in that case).
> 8. Instead of simply retaining MYFREE(p) (point 5), we could replace
> each use of it with an explicit:
> free(p);
> p = NULL;
I dropped the p = NULL; for cases where p was then immediately
reassigned, or I noted that the code was discarding or memset zeroing he
container of p within the same function. (Common in our destructors /
cleanup code).
I've got the basis for the patch which I can send. (Just not all cases
of MyStrdup have been fixed).
--
Peter Clifton
Electrical Engineering Division,
Engineering Department,
University of Cambridge,
9, JJ Thomson Avenue,
Cambridge
CB3 0FA
Tel: +44 (0)7729 980173 - (No signal in the lab!)
Tel: +44 (0)1223 748328 - (Shared lab phone, ask for me)
_______________________________________________
geda-user mailing list
geda-user@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user