malloc problem on ix86/darwin

Jasper Taylor <[email protected]>
Newsgroups gmane.comp.gnu.prolog.bugs
Message-ID <[email protected]>
Hello all,

I am using c code to add a structured database to my gprolog  
application. This code calls malloc() to extend the database when  
needed. It works OK under Linux (32- and 64-bit) and Windows but I am  
having problems under MacOS.

What happens is it works OK to start with but when the database  
reaches a certain size I get "child killed: bus error". Looking  
through the archives I saw that there are occasionally problems with  
the bits used in the addresses returned by malloc, so I added a  
wrapper that kept a mask of all bits so far used in malloced  
addresses and printed out whenever there were new ones. Here's the  
code for anyone interested:

long usedBits = NULL;
void* safe_malloc(count) {
   long ptr;

   ptr = (long)malloc(count);
   if (ptr & ~usedBits) {
     usedBits = usedBits|ptr;
     printf("debug_c malloc uses new bits, mask now %lx\n", usedBits);
   }
   return (void*)ptr;
}

What happened was interesting: as long as everything was working  
properly, the mask of used bits was stable at 0x017ffff0. But every  
bus error was preceded by the mask growing to 0x117ffff0, i.e., the  
first time bit 28 is used, even though bits 27-25 and 23 are still so  
far unused. This is MacOS 10.4.9 with gcc 4.0.1 and gprolog 1.3.1

Is it possible that I should be using some alternative to malloc(),  
provided in gprolog.h? I can't find any reference to such a  
requirement in the documentation.

Any help very much appreciated!
	--Jasper
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.