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

Re: gEDA-dev: PCB MyFree



DJ -

On Thu, Jun 22, 2006 at 02:25:43PM -0400, DJ Delorie wrote:
> In our case, we could also try to save the current board to a new /tmp
> file, after the message and before we exit.  It might work.

Scary thought.

> > Does the code depend on the "set pointer to null" feature?
> 
> I don't know.  I use MyFree for consistency.  We can still define
> MyFree as a macro, passing *x to xfree and then setting *x=0.

Umm, except I would pass x to xfree, and then set (x)=0.

> Plus it gives us a hook for other things, like if we always pass
> file/line to all malloc/free, we can actually allocate extra memory
> and store the file/line in it, to help us track down memory problems.

Given the choice, I'd rather add this feature to dmalloc.
Maybe dmalloc already has it?

> > I don't see the "missing second argument to the ternary operator"
> > feature documented in my C99 draft, and I _know_ it wasn't in the
> > C89 standard, but gcc -Wall -std=c{8,9}9 doesn't complain about it.
> 
> It's a gcc extension.  Try -ansi -pedantic.

Ah.  Thanks.  man gcc:
  "The -ansi option does not cause non-ISO programs to be rejected
  gratuitously.  For that, -pedantic is required in addition to -ansi."

> > #define xcalloc(count, size) xcalloc_function(__FILE__, __LINE__, count, size)
> 
> Yeah, like that.

void *xcalloc_function(const char *file, int line, size_t nmemb, size_t size)
{
	void *rv;
#ifdef __DMALLOC_H__
	rv = dmalloc_malloc(file, line, (nmemb)*(size), DMALLOC_FUNC_CALLOC, 0, 0);
#else
	rv = malloc((nmemb)*(size));
#endif
	if (rv == NULL) {
		perror("xcalloc");
		exit(1);
	}
	return rv;
}

At least compiles without warnings.  This has to be duplicated
four times (calloc, malloc, realloc, strdup).  It should work
on my machine, but it seems a little too chummy with the dmalloc
implementation.  How about

#ifdef __DMALLOC_H__
#if DMALLOC_VERSION_MAJOR != 5 || DMALLOC_VERSION_MINOR != 4
#warning this code untested against this dmalloc version
#endif
#endif

Of course, #warning is itself a gcc extension.  :-(

     - Larry
_______________________________________________
geda-dev mailing list
geda-dev@moria.seul.org
http://www.seul.org/cgi-bin/mailman/listinfo/geda-dev