Menu

#232 CFFI: Fix %rename; fix -noswig-lisp

None
wont-fix
None
5
2019-02-05
2009-12-22
No

The CFFI bindings generated when using %rename are broken, because it changes both the name of the created function, *and* the name of the C function they call.

E.g., running "swig -noswig-lisp -cffi name.i" in Examples/test-suite should result in:
(cffi:defcfun ("foo_1" foo_2) :void)
(cffi:defcvar ("bar_1" bar_2)
:int)
(cl:defconstant Baz_2 47)

But currently results in:
(cffi:defcfun ("foo_2" foo_2) :void)
(cffi:defcvar ("bar_2" bar_2)
:int)
(cl:defconstant Baz_2 47)

Additionally, SWIG is checking the renamed-to variables against the identifier syntax for C, because the CFFI class didn't implement validIdentifier(). In particular, this forbids bindings like:
%rename foo_1 "%%foo_2";
void foo_1();

The % character a standard way of naming for "internal variant, don't use directly" in common lisp. CL is *much* more lax in which characters may be included, so I just told SWIG to not bother checking at all. The actual identifier rules for CL are way too complicated to implement, so I didn't think it was really worth reproducing them.

Finally, this fixes the -noswig-lisp command-line option. It is specified to omit the standard boilerplate code, but it *also* has the side-effect of removing all user-specified code output that is inserted like this:
%insert("swiglisp") %{
(defun hello () "hello"))
%}

Thus, this patch makes the internal use in Lib/cffi/cffi.swg instead use %insert("_swiglisp"), and the -noswig-lisp argument only disables "_swiglisp" sections, not "swiglisp" sections.

Thanks.

Discussion

  • James Y Knight

    James Y Knight - 2009-12-22
     
  • William Fulton

    William Fulton - 2019-02-05
    • status: open --> wont-fix
    • assigned_to: William Fulton
    • Group: -->
     
  • William Fulton

    William Fulton - 2019-02-05

    Closing all open CFFI issues as CFFI has been disabled, please see https://github.com/swig/swig/issues/1447

     

Log in to post a comment.