Looking at http://clang.llvm.org/doxygen/CXString_8h_source.html
it seems that CXString as returned by clang_getCursorSpelling() is not a pointer: typedef struct { const void *data; unsigned private_flags; } CXString; If that's right, I'm a little surprised that `cursor-spelling` works --- but when you get representation wrong, strange things can happen, including something working when it shouldn't. Am I looking at the right library/definitions? At Sun, 28 Sep 2014 10:48:06 -0700, Eric Dobson wrote: > I'm trying to debug an FFI crash that I'm seeing, and because it is > dealing with C code the error just presents as a segfault. I believe I > have tracked down what is causing the problem, but don't understand > how it could be doing so. > > I have two racket functions which take a "cursor" (the foreign > libraries object) and return a string representation of it, which I'm > trying to use for debugging. > > (define raw-clang-get-cstring > (get-ffi-obj "clang_getCString" lib-clang > (_fun _pointer -> _string))) > > (define raw-cursor-spelling > (get-ffi-obj "clang_getCursorSpelling" lib-clang > (_fun _CXCursor -> _pointer))) > > (define (cursor-spelling c) > (raw-clang-get-cstring (raw-cursor-spelling c))) > > (define cursor-spelling2 > (get-ffi-obj "clang_getCursorSpelling" lib-clang > (_fun _CXCursor -> (make-ctype _pointer values (λ (v) > (raw-clang-get-cstring v)))))) > > If I use cursor-spelling, I have not been able to trigger a crash. But > if I use cursor-spelling2 I can reliably trigger a crash. > > Is there anything obvious on how these functions are different? > Because they look to me like they should be doing the same thing. If > it would be helpful I can try to get my code in a portable enough > shape so that it will work/crash on another machine. > > ____________________ > Racket Users list: > http://lists.racket-lang.org/users ____________________ Racket Users list: http://lists.racket-lang.org/users