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.
Call
ffi--prep-cif
and thedefiner-function
offfi--struct-union-helper
in the calling environment of the macros not during the macro expansion. This is so that compiling programs that usedefine-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 thatdefine-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 oflexical-let
. In the previous implementation, a variable which holds theffi
function object returned byffi--dlsym
was using the globalobarray
symbol table (this holds all the variable and function symbols visible to emacs. This means thatdescribe-variable
and the like would show the variable holding theffi
function object when really this is only ever used inside the function returned bydefine-ffi-function
. In this re-implementation, the variables which hold thecif
and theffi
function objects are not added to the globalobarray
and are only visible to the function returned bydefine-ffi-function
.