[Openmcl-devel] foreign variables

Gary Byers gb at clozure.com
Wed Aug 4 14:06:42 PDT 2004

On Wed, 4 Aug 2004, Eric Blood wrote:

> I want to dynamically access a variable in a shared library, and this
> is what I have at the moment:
>     (in-package :ccl)
>     (open-shared-library "foo.dylib")
>     (setf foo-val (load-fv "_testval" :unsigned-char))
>     (extract-foreign-value (fv.addr foo-val) 0
> 		       (info-foreign-type-definition :unsigned-char))
>     (deposit-foreign-value (fv.addr foo-val) 0
> 		       (info-foreign-type-definition :unsigned-char) 101)
> Is this even the right way to go?  I have poked around the cdb stuff,
> and didn't see an (easy?) way to inject type information so that I
> could use #?.

The foreign type information is ordinarily recorded in the .cdb file
by the interface translator.

CCL::LOAD-FV wants its second argument to be a "foreign type object",
not a "foreign type specifier". (It doesn't check this.)

I -think- that you can do:

? (load-fv "_testval" (parse-foreign-type :unsigned-char))

and #? should then work on "testval".  (Not that there's a bug - fixed
in CVS - that keeps foreign variables from being saved correctly in
fasl files.)

It sounds like there really should be a

(DEFINE-FOREIGN-VARIABLE foreign-name foreign-type &key other-args-maybe)

that does this for you (e.g., a little type/sanity-checking around

> --
> eblood
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel

More information about the Openmcl-devel mailing list