[mercury-users] Re-definition of malloc

Jonathan Morgan jonmmorgan at gmail.com
Wed Jun 21 21:54:16 AEST 2006


When trying to build the curs samples under Linux (Fedora Core 3,
mercury-0.12.0), I get the following errors.

/usr/lib/gcc/i386-redhat-linux/3.4.2/../../../libc.a(malloc.o)(.text+0x1380):
In function `free':
: multiple definition of `free'
Mercury/os/curs.o(.text+0x1800): first defined here
/usr/bin/ld: Warning: size of symbol `free' changed from 9 in
Mercury/os/curs.o to 175 in
/usr/lib/gcc/i386-redhat-linux/3.4.2/../../../libc.a(malloc.o)
/usr/lib/gcc/i386-redhat-linux/3.4.2/../../../libc.a(malloc.o)(.text+0x2c70):
In function `malloc':
: multiple definition of `malloc'
Mercury/os/curs.o(.text+0x17b8): first defined here
/usr/bin/ld: Warning: size of symbol `malloc' changed from 9 in
Mercury/os/curs.o to 373 in
/usr/lib/gcc/i386-redhat-linux/3.4.2/../../../libc.a(malloc.o)
/usr/lib/gcc/i386-redhat-linux/3.4.2/../../../libc.a(malloc.o)(.text+0x30a0):
In function `realloc':
: multiple definition of `realloc'
Mercury/os/curs.o(.text+0x17f4): first defined here
/usr/bin/ld: Warning: size of symbol `realloc' changed from 9 in
Mercury/os/curs.o to 531 in
/usr/lib/gcc/i386-redhat-linux/3.4.2/../../../libc.a(malloc.o)
collect2: ld returned 1 exit status
gmake: *** [demo] Error 1

I presume that the problem is with the following code, re-defining
*alloc in terms of GC_*ALLOC.  Does anyone have any suggestions?

:- pragma foreign_code("C","

#ifdef MR_CONSERVATIVE_GC

/*
** The addresses of the closures that we pass to curses
** will be stored by curses in malloc()'ed memory.
** However, it is essential that these pointers be
** visible to the garbage collector, otherwise it will
** think that the closures are unreferenced and reuse the storage.
** Hence we redefine malloc() and friends to call GC_malloc().
*/

void *malloc(size_t s)
{
        return GC_MALLOC(s);
}

void *calloc(size_t s, size_t n)
{
        void *t;
        t = GC_MALLOC(s*n);
        memset(t, 0, s*n);
        return t;
}

void *realloc(void *ptr, size_t s)
{
        return GC_REALLOC(ptr, s);
}

void free(void *ptr)
{
        GC_FREE(ptr);
}

#endif

").

Jon
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list