home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!gatech!usenet.ins.cwru.edu!agate!sprite.Berkeley.EDU!ouster
- From: ouster@sprite.Berkeley.EDU (John Ousterhout)
- Newsgroups: comp.lang.tcl
- Subject: Re: Tcl 6.4 Tcl_ParseVar bug OR gcc 2.2.2 bug?
- Date: 26 Dec 1992 21:42:34 GMT
- Organization: U.C. Berkeley Sprite Project
- Lines: 46
- Distribution: world
- Message-ID: <1hijkaINNddg@agate.berkeley.edu>
- References: <BzMCBy.2IB7@austin.ibm.com> <krisna.725385831@cs.wisc.edu>
- NNTP-Posting-Host: tyranny.berkeley.edu
-
- In article <krisna.725385831@cs.wisc.edu>, krisna@cs.wisc.edu (Krishna Kunchithapadam) writes:
- |>
- |> madere@austin.ibm.com (Steve Madere) writes:
- |> :
- |> :When I call Tcl_Eval() repeatedly using string constants as code
- |> :arguments, it causes a segmentation violation. This occurs when
- |> :Tcl_ParseVar overwrites individual characters of my string constant
- |> :with a null (to mark the end of a local string) during parsing.
- |> :
- |>
- |> This is the crux of the problem. `gcc' stores string _constants_
- |> in the text segment of the `a.out' file that it creates. Hence,
- |> any attempt by the process (in this case Tcl_Parse()) to write
- |> temporary `\0' markers into these addresses *will* cause a
- |> segmentation fault. `gcc' has documented this in its man pages
- |> under the `-fwritable-strings' option, so it is more in the realm
- |> of a Tcl bug.
- |>
- |> Moreover, the code for Tcl_Parse() states that there are no
- |> side-effects, whereas, depending on your compiler, there is this
- |> very nasty problem.
- |>
- |>
- |> In my opinion, Tcl should reallocate new space for its input and
- |> manipulate that. With the use of gcc (and other ANSI conformant)
- |> compilers becoming more widespread, this problem will crop up on
- |> other platforms as well. Until, Tcl makes that change, I suggest
- |> you specify the `-fwritable-strings' (and/or the `-traditional')
- |> flag on the gcc compilation command line (just add it to CFLAGS
- |> in the Makefile) and recompile your Tcl libraries---or use
- |> alloced space to hold your input to the Tcl interpreter.
- |>
- |>
-
- Yeah, I agree that this is a bug. I did it as a quick-and-dirty way
- to avoid the overhead of copying, and I didn't think it would cause
- problems for many people. Unfortunately, though, lots of people have
- stumbled on it. Another solution besides the -fwritable-strings
- approach is to declare these strings as initialized static arrays,
- which will be writable:
-
- char foo[] = "...";
- Tcl_Eval(interp, foo, ...);
-
- Ultimately I should fix Tcl, but this probably isn't going to happen
- for version 7.0.
-