[racket] Help debugging a ffi crash
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.