home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / tcl / 2254 < prev    next >
Encoding:
Internet Message Format  |  1992-12-26  |  2.5 KB

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