[plt-scheme] strings?

From: Eli Barzilay (eli at barzilay.org)
Date: Thu Apr 14 23:38:45 EDT 2005

On Apr 14, Mike wrote:
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 
> I'm trying to add an extension to mzscheme. In
> the scheme code I do something like (sqlite:open "dbname").
> In the extension code I check for SCHEME_CHAR_STRINGP(argv[0]),
> and then I extract with char *p = SCHEME_BYTE_STR_VAL(argv[0]);
> I only get the first character of the actual string, the
> string is needed to pass to sqlite_open().

SCHEME_CHAR_STRINGP checks for a Scheme string, which contains UCS4
unicode characters, which usually means you get a single character
when you try to use it as a char* (since the first character is
encoded in 4 byts, usually (for ascii) the other three are zeros).

Use SCHEME_BYTE_STRINGP, and use only byte-strings on the Scheme
side.  You can then write some Scheme code that will translate normal
Scheme strings to bytes using utf8.

(Or you can use the foreign interface that does much of that for you.)

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!



Posted on the users mailing list.