[Ecls-list] Foreign variables setting problem

Goffioul Michael goffioul at imec.be
Mon Oct 24 00:09:16 UTC 2005


Hi,

I was trying to update the CFFI support for ECL and implemented the
missing features using the recent changes in ECL regarding FFI and
callbacks. Now, ECL can pass all CFFI tests except one: FOREIGN-GLOBALS.REF.STRING

The problem is the following: *VAR-STRING* is defined as a foreign
variable contained in a DLL with type "char*" (defined as :STRING
in CFFI). At some point in the tests suite, there is something like:

	(let ((old-value *var-string*))
	  (setf *var-string* new-value)
	  (...<do something>...)
	  (setf *var-string* old-value))

When setting such a foreign var with a LISP string, a foreign string
is allocated and set to the LISP string, then the foreign var is set
to point to the allocated memory. However, the foreign memory is allocated
in ECL using si::allocate-foreign-data, which uses cl_alloc_atomic().
So, the memory allocated is GC-able and the memory pointed by the foreign
var is quickly overwritten (indeed, si::allocate-foreign-data creates
a foreign-data object, which is discarded after the setf call and the
allocated memory is not referenced anymore).

One solution could be to use plain malloc in si::allocate-foreign-data.
Indeed, the user is expected to explicitely free the memory allocated,
so it shouldn't be necessary to handle it through GC. However, there might
be other side-effects I'm overlooking. Any suggestion?

Bye.
Michael.




More information about the ecl-devel mailing list