tromey / emacs-ffi

FFI for Emacs
99 stars 17 forks source link

Perform work in macro calling environment #19

Open nnicandro opened 6 years ago

nnicandro commented 6 years ago

Call ffi--prep-cif and the definer-function of ffi--struct-union-helper in the calling environment of the macros not during the macro expansion. This is so that compiling programs that use define-ffi-function, define-ffi-struct, etc. work. See https://www.gnu.org/software/emacs/manual/html_node/elisp/Wrong-Time.html#Wrong-Time.

Also instead of defining the library as a function in define-ffi-library I thought it would be better to mark it as a constant since a library is only every opened once. Note that define-ffi-library also had the problem of performing work when expanding the macro as described above.

Finally, I changed the expansion of define-ffi-function based on the expansion of lexical-let. In the previous implementation, a variable which holds the ffi function object returned by ffi--dlsym was using the global obarray symbol table (this holds all the variable and function symbols visible to emacs. This means that describe-variable and the like would show the variable holding the ffi function object when really this is only ever used inside the function returned by define-ffi-function. In this re-implementation, the variables which hold the cif and the ffi function objects are not added to the global obarray and are only visible to the function returned by define-ffi-function.