[cffi-devel] Re: [Fwd: RE: [Ecls-list] Foreign variables setting problem]
Luis Oliveira
luismbo at gmail.com
Wed Oct 26 20:53:16 UTC 2005
Juan Jose Garcia Ripoll <lisp at arrakis.es> writes:
> Now some other component of the library overwrites this variable because
> a different error condition happened
>
> error_message = "File not found";
>
> and then your lisp code tries to
>
> (foreign-free (mem-ref (get-var-ptr '*error-message*) :pointer))
>
> Kaboom! :-)
Right. Well, at the momment the user will simply have to be careful in
such a situation by saving the pointer elsewhere. I can imagine other
situation where one would have to be careful; what if the foreign code
free()s our data? I'm not sure if this is common though.
> In ECL's implementation of UFFI, foreign variables are defined once and
> a property list is associated to the symbol. Whenever you set a foreign
> variable with some data, the foreign data generated by the lisp is
> stored in that property list, hence preventing garbage collection.
Is that the way UFFI works in other implementations though? I mean, in
other implementations you have to free the memory yourself, right?
> When you set the same variable a second time, the original lisp value is
> lost and then it is garbage collected. An alternative would be to free
> the value as soon as it is removed from the property list.
CFFI could certainly do the latter.
--
Luís Oliveira
luismbo (@) gmail (.) com
Equipa Portuguesa do Translation Project
http://www.iro.umontreal.ca/translation/registry.cgi?team=pt
More information about the cffi-devel
mailing list