guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Guile: What's wrong with this?


From: Bruce Korb
Subject: Re: Guile: What's wrong with this?
Date: Fri, 06 Jan 2012 11:06:47 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111220 Thunderbird/9.0

On 01/06/12 10:13, Mark H Weaver wrote:
Imagine that you were evaluating Scheme by hand on paper.  You have your
program written on one page, and you have another scratch page used for
the data structures that your program creates during evaluation.
Suppose your program contains a very large lookup table, written as a
literal list.  This lookup table is on your program page.

Now, suppose....

That is where my mental model diverges!!

sprintf(buf, "(define %s \"%s\")", "foo", my_str);
scm_eval_string(buf);
sprintf(buf, "(string-upcase! %s)", "foo")
// the string from my_str in "buf" is now scribbled over and completely gone
scm_eval_string(buf);

Since I know the program I initially wrote (the define) is now gone,
the string must have been copied off somewhere.  I think one's first
guess is that it was copied to someplace modifiable.  However, that
would be incorrect.  It is copied off to writable memory, but marked
as read-only for the purposes of Guile.  Not intuitively obvious.

Guile 1.8's permissivity allowed Bruce to unwittingly create a large
body of code that was inherently buggy.  IMHO, it would have been much
better to nip that in the bud and alert him to the fact that he was
doing something that was almost certainly unwise.

Fail early and fail hard.  Yes.  But after all these discussions, I
now doubt I have too many places where I am expecting to change a
static value.  Most of the strings that I wind up  altering are
created with a scm_from_locale_string() C function call.  Very few
strings are ever actually initialized with (define foo "something"),
other than when creating placeholders because you cannot define
within a nested collection of functions.  e.g.
  (if (whatever)
      (define foo (get "this"))
      (define foo (get "that"))  )
  (string-upcase! foo)

====

Anyway, I did compile and build my toy and guile with CFLAGS='-g -O0'.
The error message did not show.  Instead it seg faulted while trying
to make this call:  scm_from_locale_string("");

There must be a corruption somewhere.  It is either asymptomatic with
Guile 1.8 (viz. my fault) or it is introduced with Guile 2.0 (meaning
a Guile code issue).  More in a few days.

Thank you.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]