From: Martin Zaidel
Subject: Lucid 4.1 foreign-function problem
Date: 
Message-ID: <129099@netnews.upenn.edu>
I've run into a problem while running C code under Lucid 4.1's foreign function
interface.  I've run into a wall of ignorance, so I'd appreciate hearing from
anyone who's solved a similar problem or of any suggestions of what to try
next.  Much appreciated are pointers to information about foreign memory
allocation and limits.

The problem occurs in memory allocation.  The C package that I'm loading builds
a large linked-list data structure during its initialization.  A data file is
read in by a "while" loop:

	while (input = read(data_file)) {
	   procA(input);
	   procB(input);
        }


The behavior is remarkably consistent.  First, a flurry of error messages
generated by Lucid's realloc() code: "Bad pointer 0xee0140 given to realloc".
Then, after about twenty such messages, referring 4 or 5 times to the same 4 or
5 addresses, the program exits with a segmentation fault.  On the largest data
file, the segmentation fault occurs within Lucid's realloc() at the SAME point
in the data file (i.e., at the same input line), and within procB().  On the
midsized data file, the segmentation faults occurs within a call to Lucid's
malloc() inside procA(), again consistently at the same point in the data file.
On the smallest data file, the data file is read without any problems.  Also
when the same C code is compiled into an executable program and run (i.e., not
from within a Lisp process) the program loads without problems on all data
sets.

I've tried changing the size of the allocated foreign space, but without
success: Lucid allows you to increase the reserved space (out of which the
foreign space is allocated), but not the foreign space directly.

My theory is that the foreign data structure overflows Lucid's foreign memory
space, so that Lucid's calls to malloc()-family functions fail, generating
the error messages.  While these failed calls are not fatal, they succeed in
corrupting the run-time stack so that ultimately a segmentation violation
occurs.  But on smaller data files that don't build over-large structures, the
program functions without error.

Many thanks for your help.

Martin