[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] FFI string with embedded nulls
From: |
Thomas Chust |
Subject: |
Re: [Chicken-users] FFI string with embedded nulls |
Date: |
Wed, 03 Aug 2005 18:48:22 +0200 |
User-agent: |
Mozilla Thunderbird 1.0.2 (Macintosh/20050317) |
Toby Butzon wrote:
[...]
I'm stumped. How do I get the string to turn into a Scheme string
without truncating it at the first embedded null?
[...]
Hello,
as far as I know, there is no way to tell the FFI to do this properly,
so you will have to do it by hand. Try something like this:
(define (c-memcpy from)
((foreign-primitive scheme-object ((scheme-pointer from) (int size))
"C_word *store = C_alloc(C_SIZEOF_STRING(size));\n"
"C_word to = C_string(&store, size, from);\n"
"C_values(2+1, C_SCHEME_UNDEFINED, C_k, to);")
from (string-length from)))
(define from (string #\1 #\nul #\2 #\nul #\3))
(display "from: ") (write (string->list from)) (newline)
(display "to: ") (write (string->list (c-memcpy from))) (newline)
cu,
Thomas Chust