Re: [Chicken-users] Easyffi question
On Mon, Dec 22, 2008 at 3:28 PM, John Cowan wrote: > BTW, there is a bug in this code: if it's passed an improper list, it > goes off into hyperspace. Yes. It will also crash if there is a non-string element in the list. I also forget, every time, that C_c_string does not null-terminate its return string. I attached a safer version. stringlist.scm Description: Binary data ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Easyffi question
Jim Ursetto scripsit: > The `sx` egg does something similar -- transforming a list of strings > into a null-terminated array of C strings. I derived a quick example > from it and attached the code. BTW, there is a bug in this code: if it's passed an improper list, it goes off into hyperspace. It's never a good idea to test for () as a list terminator in either C or Scheme: you should use something like this: (define (end? x) (cond ((pair? x) #f) ((eq? x '()) #t) (else (error "A proper list should not end with" x (This is based on the Common Lisp predicate ENDP.) -- But you, Wormtongue, you have done what you could for your true master. Some reward you have earned at least. Yet Saruman is apt to overlook his bargains. I should advise you to go quickly and remind him, lest he forget your faithful service. --Gandalf John Cowan ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Easyffi question
On Mon, Dec 22, 2008 at 8:49 AM, William Ramsay wrote: > Can anyone explain to me how I convert a string to a null terminated > c-pointer that points to a list of strings. > > For example the c function I need to use looks like: > >foo (char **str, int cnt, c-struct result) The `sx` egg does something similar -- transforming a list of strings into a null-terminated array of C strings. I derived a quick example from it and attached the code. $ csc -X easyffi -s stringlist.scm $ csi -q -R stringlist #;1> (my-foo (list "bar" "baz" "quux")) string 0: bar string 1: baz string 2: quux An example of the opposite transformation (null-terminated C string array to a vector of Scheme strings) can be found in the `hostinfo` egg under array0->string-vector. stringlist.scm Description: Binary data ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] Easyffi question
Hi again, Can anyone explain to me how I convert a string to a null terminated c-pointer that points to a list of strings. For example the c function I need to use looks like: foo (char **str, int cnt, c-struct result) In other words I'm passing a list of cnt strings into the function to get back a structure that contains the strings. The problem is with the first parameter.In most cases I will pass only one string, but the function still expects it to be a list of strings - in this case a list of one string. Bill ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users