Eric Schulte | 30 Jun 2012 19:15
Picon
Favicon
Gravatar

requesting help debugging error in libclang bindings

Hello,

I'm working to write CFFI binding for libclang [1], I've used swig to
generate CFFI declarations of all libclang bindings, and I'm hoping to
wrap those in a nice CLOS-based interface (my code is up here [2]).

However I've run into an error which I'm having trouble getting past.
Although the following simple C code [3] compiles and runs w/o problem.
A direct translation into lisp [4] using the swig-generated cffi
bindings throws this error [5].  For some reason the
`clang_getTranslationUnitCursor' function always throws an error.  FWIW
I'll include the original C function headers [6] and the swig-generate
CFFI declarations [7] below.

I'm using SBCL version 1.0.57 and CFFI version 0.10.6 installed with
quicklisp.

Any idea what could be causing this error?  Could the problem lie in
SBCL, in CFFI, or possibly in some difference in state between the C
world and the lisp world?

Thanks,

Footnotes: 
[1]  http://clang.llvm.org/doxygen/group__CINDEX.html

[2]  https://github.com/eschulte/cl-libclang

[3]  hello-cursor.c
     // -*- C -*-
(Continue reading)

Luís Oliveira | 2 Jul 2012 00:38
Picon
Gravatar

Re: requesting help debugging error in libclang bindings

On Sat, Jun 30, 2012 at 6:15 PM, Eric Schulte <eric.schulte <at> gmx.com> wrote:
>      (cffi:defcstruct CXCursor
>        (kind CXCursorKind)
>        (xdata :int)
>        (data :pointer))
>      ;; ...
>      (cffi:defcfun ("clang_getTranslationUnitCursor" clang_getTranslationUnitCursor)
>          CXCursor
>        (arg0 :pointer))

IIUC, this is the problem: clang_getTranslationUnitCursor() returns a
structure by value, but SWIG has erroneously declared it to return a
structure by reference. (If you have the chance, please report this
bug to the SWIG maintainers, or if there's no one maintaining SWIG's
CFFI backend, you can report it at CFFI's bugtracker.)

If you grab CFFI from its git repository, you'll find a new system
called "cffi-libffii" which implements the passing of structures by
value. (The syntax in this case would be (defcfun ... (:struct
CXCursor) ...).) Let us know if you have trouble using it.

HTH,

--

-- 
Luís Oliveira
http://r42.eu/~luis/

Gmane