[gnu.g++.lib.bug] calloc/cfree

sps@mcnc.org (Stephen Schaefer) (01/12/90)

In libg++ 1.36.2, ChangeLog top reading Wed Jan 3 08:29:43 1990 Doug
Lea, malloc.c defines calloc, but does not define cfree.  I understand
that cfree is superfluous, and may be replaced by free, but we're
linking some C++ code with some old C code.  The old C code calls
calloc and cfree, and when the loader doesn't find cfree in libg++.a,
it looks in libc.a.  There, cfree is defined in the same module with
calloc, and we get a multiply defined error for calloc.  The following
change to malloc.c prevents the problem:

RCS file: RCS/malloc.c,v, file: RCS/malloc.c,v
retrieving revision 1.1, file: RCS/malloc.c,v
diff -c -r1.1 malloc.c, file: RCS/malloc.c,v
*** /tmp/,RCSt1015847	Thu Jan 11 11:56:00 1990
--- malloc.c	Wed Jan 10 17:50:51 1990
***************
*** 961,966 ****
--- 961,973 ----
  };
  
  
+ /* cfree does nothing except free, but when old code uses it, it would
+    otherwise drag in a conflicting calloc definition from libc.a */
+ inline void cfree(void* mem)
+ {
+   free(mem);
+ }
+ 
  unsigned int malloc_usable_size(void* mem)
  {
    mchunkptr p = (mchunkptr)((char*)mem - SIZE_SZ); 

--
	Stephen P. Schaefer, Postmaster	MCNC
	sps@mcnc.org			P.O. Box 12889
	...!mcnc!sps			RTP, NC 27709