From: rif

Subject: Question on Foreign Types

Date: 2003-4-8 11:19


I'm trying to work with a foreign library, fftw.  The "modus operandi"
is that I call an initialization function in the library, which
allocates a data structure and returns it to me as a (void *).  Then,
when I call the functions to "use" the library, I pass in this data
structure.

So my question is, do I have to do anything to "protect" this data.
Right now, I just define a type as syntactic sugar for a (void *):

(def-foreign-type fftw-plan (* :void))

Then I wrap the following function to generate the plan:

(def-foreign-call (fftw-plan-r2r-1d "fftw_plan_r2r_1d")
    ((n :int)
     (in (:array :double))
     (out (:array :double))
     (kind :fixnum)
     (flags :fixnum))
  :returning fftw-plan)

And then use the plan via:

(def-foreign-call (fftw-execute "fftw_execute")
    ((plan fftw-plan))
  :returning :void)

(This works because the input and output array are fixed at
plan-creation time.)

So my question is, do I have to do anything to "protect" the memory in
the fftw-plan object generated by fftw-plan-r2r-1d from ACL?  My
intuition is that it would be allocated statically on the C heap by
the library, and that this approach was all I needed --- I never need
to access the internals of the fftw-plan object, I merely need to pass
it to fftw-execute.  However, what is happening when I try to use it
is that it works a number of times, and then causes my ACL to
segfault, which makes me suspicious.

Any thoughts or ideas?

Cheers,

rif

ps.  Please reply directly to <mit.edu at rif> as well to the list;
although I have ubmitted a request to be added, I do not believe I
have been added (as of yesterday).