home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / perl / 5332 < prev    next >
Encoding:
Internet Message Format  |  1992-08-15  |  3.3 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!usc!news!netlabs!lwall
  2. From: lwall@netlabs.com (Larry Wall)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: Bad label: _EVAL_, inconsistent behavior
  5. Keywords: eval, setuidness, etc.
  6. Message-ID: <1992Aug15.192751.10406@netlabs.com>
  7. Date: 15 Aug 92 19:27:51 GMT
  8. References: <1992Aug14.184402.25912@rayssd.ssd.ray.com>
  9. Sender: news@netlabs.com
  10. Distribution: usa
  11. Organization: NetLabs, Inc.
  12. Lines: 53
  13. Nntp-Posting-Host: scalpel.netlabs.com
  14.  
  15. In article <1992Aug14.184402.25912@rayssd.ssd.ray.com> ras@rayssd.ssd.ray.com (Shaw) writes:
  16. : ...
  17. : Bad label: _EVAL_ at passutils.pl line 375, <STDIN> line 3.
  18. : I've also tried:
  19. :     eval "return \$answer if (\$answer =~ $test)";
  20. : and
  21. :     eval qq:return $answer if (\$answer =~ $test):;
  22. : as well as a few other combnations.  The "Bad label:" message
  23. : comes out on the next call to the subroutine after I've changed
  24. : something, and refers to <STDIN> line N, where N is the number of
  25. : times it's run the sub and gotten an answer.
  26. : Any clues?  I find no reference to _EVAL_ in the Book, and mysterious
  27. : references to the "qq" mechanism didn't seem to help either.
  28.  
  29. You're basically confusing the heck out of the runtime system by
  30. returning from something that isn't a subroutine.  The text of an eval
  31. is considered its own thing, like a parameterless subroutine.  If
  32. return were to mean anything in an eval, it should probably mean to
  33. terminate the eval itself rather than the surrounding subroutine, if any.
  34.  
  35. The gory details go like this: the subroutine, if it contains a return
  36. (and that means an ordinary return, not one embedded in an eval, which
  37. the parser can't see at compile time--your subroutine happens to have
  38. one, but your program would have blown up differently if it hadn't),
  39. pushes a mystical label _SUB_ on the label stack so the return will
  40. know where to longjmp() out to.  The eval then sets the global Boolean
  41. variable in_eval and pushes a mystical label _EVAL_ onto the label
  42. stack so that fatal errors know they are being trapped and should
  43. longjmp() back to the eval code.  When you do a return in an eval, it
  44. pops the _EVAL_ label, finds the _SUB_ label, and does a longjmp()
  45. around the eval "destructor" code that turns off the global in_eval
  46. flag, so the NEXT time you get a fatal error it tries to return to a
  47. no-longer existing _EVAL_ label.  (Yes, I could just look for an _EVAL_
  48. label instead of testing in_eval, but in_eval is used other places
  49. too.  Among other things, the tokener has to know whether it's reading
  50. from a string or from a file.  I'm planning on doing away with
  51. longjmp() anyway, so it's not really an issue in Perl 5--the
  52. "destructor" code will presumably reset in_eval correctly.)
  53.  
  54. Anyway, I'm not going to advertise a fix for it until I decide what
  55. "return" really should mean in an eval.  I don't think it's reasonable
  56. to try to pretend that evaled code is inlined--for one thing, it would
  57. mean I'd have to turn off many of the optimizations that are done in a
  58. subroutine containing an eval.  And it would be nice to have a way to
  59. short-circuit an eval or a require.  There's no way to do that
  60. conveniently at the moment without faking a fatal error, which is
  61. useless in require and even in eval has the unwanted side effect of
  62. setting $@.  If you expect return to terminate an eval in Perl 5,
  63. you're unlikely to be surprised...   :-)
  64.  
  65. Larry
  66.