[cffi-devel] Weird segfaults interfacing with libsane

Rupert Swarbrick rswarbrick at googlemail.com
Mon May 26 20:23:47 UTC 2008


"Luís Oliveira" <luismbo at gmail.com> writes:

> On Thu, May 22, 2008 at 12:01 AM, Rupert Swarbrick
> <rswarbrick at googlemail.com> wrote:
>> I realise that that's not the sort of question for the cffi list,
>> _but_ I wrote a trivial C program that I think should be equivalent
>> and it doesn't die. I can't work out *how* libsane can work in one
>> case and not the other (!) so I was wondering if anyone could make any
>> suggestions. I'm attaching the two source files here.
>
> The only difference I could spot between the C and Lisp programs is
> that version should be an :int, not a :pointer. (But that doesn't
> matter on 32-bit linux since they're the same size there.) In any
> case, it seems to work for me on Linux/amd64.
>
> Have you tried running the program in other Lisps? CLISP and/or CMUCL,
> for instance.
>
Hi there,

Thanks for the reply and sorry for the delay - I've been doing
exams. I have now tried with clisp and cmucl and they both
segfault. This is with the debian unstable versions of clisp, cmucl,
cl-cffi.

I presume there's something weird happening with my system's libsane
library, which would explain why no-one else's versions die, but I
would like to try and work out why the lisp versions are crashing and
the trivial C version not.

However, I tried starting up sbcl with gdb and it was a bit too
unpleasant - gdb reported about 5 [1] segfaults per line in the repl,
but everything carried on working (well until I loaded my test2.lisp
file [2]).

I'd be really interested to debug/analyse what's going on here - there
must be a problem somewhere! Can anyone recommend ways in which I can
somehow trap whatever's falling over and catch the segfault? Or
suggest how I might find what's going wrong? I have no idea who's bug
this is, but I'd like to understand why I can trigger it so reliably!

Thank you very much for any suggestions,

Rupert


[1] Er this was the other night. That's a rough estimate.
[2] Included below. Dies every time.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: test2.lisp
Type: application/octet-stream
Size: 578 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20080526/0f99f9e0/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 306 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20080526/0f99f9e0/attachment.sig>


More information about the cffi-devel mailing list