chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] FFI with callbacks for gnu readline


From: Levi Pearson
Subject: [Chicken-users] FFI with callbacks for gnu readline
Date: Wed, 18 Jan 2006 15:25:05 -0700

I'm writing a command-line app that I would like to have a readline interface to, complete with custom tab-completion. The readline.egg package doesn't do tab-completion, so I've been working on my own, but I've run into some problems.

The readline library expects to be able to call a generator function with a string and an index and get back a newly-allocated string that it can use and then free(). To accommodate this, I wrote a C function that calls a define-external'd scheme function that returns a scheme-object containing the string. I found that returning a c- string would sometimes give me some garbage characters as the strings were not always null-terminated at the right spot. The C function gets the string length and c-string pointer out of the scheme-object, makes a newly-allocated copy, and passes it back to readline.

This all seems to work well, but after a bit of use of the tab- completion functionality, the program segfaults or otherwise dies on a call to the readline interface. I've packaged up a pretty minimal test case, which can be downloaded from http://lifeoflevi.com/ crasher.tar.gz

I'd appreciate any help I can get, as this problem has been haunting me for a couple of days now.

                --Levi




reply via email to

[Prev in Thread] Current Thread [Next in Thread]