racket / ChezScheme

Chez Scheme
Apache License 2.0
110 stars 8 forks source link

Library definition can't use shared objects. #47

Closed swatson555 closed 2 years ago

swatson555 commented 2 years ago

Scheme libraries that export foreign procedures can't find their foreign code. In the original variant of Chez it was possible to do the following:

(library (foo)
  (export bar)
  (import (chezscheme))
  (define library-init
    (begin
      (load-shared-object "foobar.so")))
  (define bar (foreign-procedure "foobar" (string unsigned) (* void))))

so that the foreign procedure would be in bar and would be exported when imported into a different location.

Currently this doesn't work in the Racket variant and there aren't any practical workarounds. In the Racket variant trying to import this would result in everything exported from the library producing an exception that the foreign code has no entry. This includes trying to get the value of unrelated variables in the library. Calling foreign-entry? and checking if the code is there still works fine inside libraries.

swatson555 commented 2 years ago

I've updated the title because it doesn't matter whether load-shared-object is called inside or outside a library definition.

mflatt commented 2 years ago

Thanks for the report!

Can you provide a more complete example? I don't know what might be different, exception possible something related to cross-library inlining, and I'm not able to replicate a problem.

I think (* void) isn't allowed as a return type in either the original Chez Scheme branch or the Racket one, so I wonder whether I'm misunderstanding something around that part.

swatson555 commented 2 years ago

It looks like this has been fixed in a recent version of Racket Chez.