From: Diptansu Das
Subject: Newbie question about Alien interface in CMUCL
Date: 
Message-ID: <Xns92ED6F315E0A6diptansuyahoocom@66.150.105.46>
Hi,
  I am interested in using LISP for an analysis routine that I am writting. 
I normally use a package called ROOT (used in the High Energy Physics 
community and written in C++) to store and read my data. I am trying to 
read each event, and then do my analysis. To read the events I have made 
some small wrapper functions in C which initializes ROOT and another which 
will read any event. the event record is being passed from ROOT to LISP 
using 3 globally declared structures. So my code looks like:

struct foo_ {
.......
} foo;

foo *  root_init() {
.....;
return &foo;
}

void getentry(int i) {
.......
}

*******************************************************************

(def-alien-type nil
   (struct foo
.......)))

(def-alien-routine root_init
.....)))
(def-alien-routine getentry
.....)))

(defun startprocessing ()
  (root_init)
  (dotime (j 500)
     (getentry j)))

the program works flawlessly till the second garbage collection, at which 
point it gives an error like:

 *** Break *** segmentation violation


Error in function UNIX::SIGABRT-HANDLER:  SIGABRT at #x4007C801.

This error always happens during garbage collection. I have used (ext:gc) 
twice and seen it to crash during the second time. ROOT malloc's lots of 
buffers and other stuff internally. It is not possible for me to declare 
all the buffers and stuff as def-alien-variable in LISP.

My question is: During garbage collection, does LISP overwrite globally 
declared variables in the foreign library that I am loading for the ROOT 
code?

Thanx in advance for any help.

 Cheers,
   Diptansu
From: Eric Marsden
Subject: Re: Newbie question about Alien interface in CMUCL
Date: 
Message-ID: <wzibs33ledd.fsf@melbourne.laas.fr>
>>>>> "dd" == Diptansu Das <·······@hotmail.com> writes:

  dd> Error in function UNIX::SIGABRT-HANDLER:  SIGABRT at #x4007C801.
  dd> 
  dd> This error always happens during garbage collection. I have used
  dd> (ext:gc) twice and seen it to crash during the second time. ROOT
  dd> malloc's lots of buffers and other stuff internally. It is not
  dd> possible for me to declare all the buffers and stuff as
  dd> def-alien-variable in LISP.
  dd> 
  dd> My question is: During garbage collection, does LISP overwrite
  dd> globally declared variables in the foreign library that I am
  dd> loading for the ROOT code?

your question is very specific to the CMUCL implementation; you may
obtain more useful responses to questions of this nature on the
cmucl-help mailing list (see <URL:http://www.cons.org/cmucl/support.html>).

CMUCL partitions the address space available to it on startup, and
reserves most of the available space for the lisp heap. Only 128MB or
256MB (depending on the platform) is available to memory allocated
from foreign code via the brk() system call, for example stuff that is
allocated with malloc() from C code, or via the MAKE-ALIEN function in
CMUCL, which allocates in foreign space.

It is possible that your problem is due to allocating more than this
amount from foreign code. The only solution that I see is to rebuild
CMUCL with a modified memory map that allocates more space to foreign
allocation. There is a description of how to do so on the CMUCL web
site (be warned that building CMUCL is not a trivial undertaking).

-- 
Eric Marsden                          <URL:http://www.laas.fr/~emarsden/>