You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Stas Bekman <st...@stason.org> on 2004/04/30 22:06:24 UTC

[mp2] making exit work inside eval

At the moment:

     eval { exit };

won't exit under mp2, since our exit-but-don't-exit emulation is implemented 
via die "". I couldn't come up with any solution to make it internally and 
looking at the longjump and perl op logic in Perl_die_where is a foreign land 
to me. I suppose someone who understands that could come up with a better 
solution. Meanwhile I came up with a workaround:

    eval { exit };
    exit if $@ == -1; # rethrow exit

next replace -1 with a nice ModPerl::Const::EXIT (which doesn't yet exist), 
and we are done.

Here is the required change in the code:

Index: src/modules/perl/modperl_util.c
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_util.c,v
retrieving revision 1.66
diff -u -r1.66 modperl_util.c
--- src/modules/perl/modperl_util.c     3 Apr 2004 02:35:47 -0000       1.66
+++ src/modules/perl/modperl_util.c     30 Apr 2004 20:04:14 -0000
@@ -576,10 +576,16 @@
      ENTER;
      SAVESPTR(PL_diehook);
      PL_diehook = Nullsv;
+
      sv_setpv(ERRSV, "");
+    (void)SvUPGRADE(ERRSV, SVt_PVNV);
+    SvIVX(ERRSV) = -1;
+    SvIOK_on(ERRSV);
+
  #ifdef MP_PERL_5_6_0
      pat = ""; /* NULL segvs in 5.6.0 */
  #endif
+
      Perl_croak(aTHX_ pat);
  }

I'm using the same dual var $@ trick I'm using in the new exception handling 
trick.

What do you think? Any better ideas?

I'm not sure what ModPerl::Const::EXIT should be set to, some negative value? 
like -1000?

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2] making exit work inside eval

Posted by Stas Bekman <st...@stason.org>.
Matt Sergeant wrote:
> On 30 Apr 2004, at 21:06, Stas Bekman wrote:
> 
>> What do you think? Any better ideas?
> 
> 
> <joking>
> sub CORE::GLOBAL::exit { dump }
> </joking>
> 
> (sorry, been a long week :-)

:)

I have the implementation ready, but it has a problem if exit wasn't called. 
You can't match "" == 1234. At the moment $@ is "" when exit is called or when 
eval was successfully completed.

So I'm planning to move to exception objects for exit as well. The new 
ModPerl::EXIT constant will match $@ when exit will be called in the eval context.

Meanwhile I provided the infrastructure for ModPerl::Const constants. So if 
you ever wanted to add a new constant specific to ModPerl, it should be easy 
now (after I commit the new stuff).

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2] making exit work inside eval

Posted by Matt Sergeant <ma...@sergeant.org>.
On 30 Apr 2004, at 21:06, Stas Bekman wrote:

> What do you think? Any better ideas?

<joking>
sub CORE::GLOBAL::exit { dump }
</joking>

(sorry, been a long week :-)


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org