[plt-scheme] scheme/foreign issues - string conversion and DrScheme crashing

From: Eli Barzilay (eli at barzilay.org)
Date: Thu Dec 25 15:56:07 EST 2008

On Dec 25, Ben Simon wrote:
> I started in on it, and I've run into two major issues:
> 1) the MySQL C api (http://dev.mysql.com/doc/refman/5.0/en/c.html) is easy
> to use.  I'm able to get access to the C function call *mysql_real_connect*.
> If I hand it invalid connection information, it gracefully fails like I want
> it to. It calls the C function *mysql_error()* which is supposed to return
> back char*.  However, I get the following message from DrScheme:
>  bytes->string/utf8: string not well-formed UTF-8 encoding: #"0\344\22"
> Any thoughts as to why *mysql_error* is returning back a string scheme is
> choking on?

It's probably best to change the type to _bytes, then see what the
actual char* contents is.

> 2) DrScheme has been crashing nearly constantly since I started
> working on this.  I'm running on Vista, and after having DrScheme
> open for a minute or two, I'll inevitably get a pop-up: *PLT Scheme
> GUI Application has stopped working*.  It doesn't seem to correspond
> to any one statement I'm executing.  For example, I kicked off
> DrScheme, ran the test code mentioned above, got the error, started
> writing this e-mail, and flipped back to find DrScheme had crashed.

The most common cause of this is a bad memory reference, usually
because mzscheme uses a moving GC (by default).  Some things that you
can do to verify this are adding `collect-garbage' in various places
(maybe even a thread that keeps triggering GCs), and trying to run the
code with the CGC executables.  (You can get them as part of the
"Full" distribution from the nightly builds.)

Another thing to verify is that you don't call the close function
twice on aa handler or something similar.

Other than that -- yes, life in the (unsafe!) world can be hard...

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

Posted on the users mailing list.