[plt-scheme] Access Violation on C++ Builder 5

From: RxQVW (rxqvw at yahoo.co.jp)
Date: Thu Jun 17 18:38:43 EDT 2004


> I am striving to embed MzScheme to my C++ Builder 5 
> application on Windows 2000.  I compiled MzScheme and GC 
> library from source (v207).
> But a simple console program (single-thread) as the following
> doesn't work well, and access violation happens
> at scheme_basic_env() function.
> (Program tries to read address 0x00000004.)

After debugging MzScheme source code for hours,
I have resolved this problem.

Access vilolation was being happened at
src/mzscheme/src/numstr.c (line 958)
    cpy = str;
    d = STRTOD(cpy + delta, &ptr);

When I dug into assembler code of strtod() function,
I found the exception happened when internal 
__getLocaleNumericInfo() function was called.

Then I searched source position where
strtod() will begin to raise excepotion,
and found the position is 
src/mzscheme/src/string.c (line 1526).

    if (!setlocale(LC_CTYPE, name))
      setlocale(LC_CTYPE, "C");
    if (!setlocale(LC_COLLATE, name))
      setlocale(LC_COLLATE, "C");

On C++ Builder 5 (+Update1),
passing empty string to setlocate() function
will make strtod() function buggy
through internal __getLocaleNumericInfo() function.
(Passing "C" or NULL is ok.)

The following simple code will reproduce
this access viloation.

#include <stdlib.h>
#include <locale.h>

int main(void)
    const char* str = "0.0";
    char* ptr;
    double d;

    setlocale(LC_CTYPE, "");
    d = strtod(str, &ptr);   // exception happens at this point.
    return 0;

To avoid this problem, I have defined DONT_USE_LOCALE macro
as a compiler option of libmzsch project,
and it went well at all with my application.

I have found another bug during building libmzsch library
with DONT_USE_LOCALE macro.

Current source code (v207) defines charLOC_LOCCOMP macro
in src/mzscheme/src/char.c (line 307) as follows.

# define charLOC_UPCASE(t, l, nl) nl;
# define charLOCCOMP(t, prev, c, comp, rv) /* empty */
# define charLOC_UPCASE(t, l, nl) if (t) { l; } else { nl; }
# define charLOC_LOCCOMP(t, prev, c, comp, rv) \

But it cannot compile char.c with this definition.
The maro name 'charLOCCOMP' should be 'charLOC_LOCCOMP'.

Chihiro Kuraya

Do You Yahoo!?

Posted on the users mailing list.