[plt-scheme] strings?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Fri Apr 15 10:23:59 EDT 2005

At Fri, 15 Apr 2005 08:16:37 -0500, Mike wrote:
>     if(!SCHEME_CHAR_STRINGP(argv[0])) {
>         scheme_wrong_type("sqlite:open", "string", 0, argc, argv);
>     }
>     dbname = SCHEME_BYTE_STR_VAL(argv[0]);

SCHEME_BYTE_STR_VAL() should be used only on a value for which
SCHEME_BYTE_STRINGP() produces true.

SCHEME_CHAR_STR_VAL() should be used only on a value for which
SCHEME_CHAR_STRINGP() produces true.

The result of SCHEME_CHAR_STR_VAL() is a mzchar*, so I can see why
you're trying to use SCHEME_BYTE_STR_VAL() to get a char*, but it
doesn't work. (The actual layout of byte string and char string values
means that, on a little-endian machine, you end up with one byte when
trying to use a char string as a byte string. But that's just an
artifact of the current data layout.)

To turn a char string into a byte string, you can use
scheme_char_string_to_byte_string() or
scheme_char_string_to_byte_string_locale(), depending on whether you
want a UTF-8 or locale-based encoding of the string.


Posted on the users mailing list.