Question on Foreign Types

rif <[email protected]>
Newsgroups gmane.lisp.allegro
Message-ID <[email protected]>
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 [email protected] 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).
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.