Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

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

open
nobody
None
5
2012-12-21
2009-12-22
James Y Knight
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

     
    Attachments