develooper Front page | perl.perl5.porters | Postings from March 2003

should we have an equivalent of eval trapping for perl api functions?

Thread Next
From:
Stas Bekman
Date:
March 9, 2003 23:16
Subject:
should we have an equivalent of eval trapping for perl api functions?
Message ID:
3E6C3B5C.8060806@stason.org
I'm using Perl_load_module and I need to be able to trap its failure, just 
like eval { require Foo } does. I'm after speed, so I can't use 
eval_pv/require_pv.

Is it possible to provide a set of macros for XS writer to emulate the 
eval-like setup for Perl_ function which call Perl_die? something like:

    START_EVAL_BLOCK;
    Perl_whatever(...);
    END_EVAL_BLOCK;
    if (SvTRUE(ERRSV)) {
       /* decide what to do about the error */
    }

I've almost succeeded with the following code:

     int ret;
     const char *pv = "do::not::exists";
     dTHX;
     dJMPENV;

     JMPENV_PUSH(ret);

     if (!ret) {
         PL_in_eval = EVAL_INEVAL | EVAL_KEEPERR;
         Perl_load_module(aTHX_ PERL_LOADMOD_NOIMPORT, newSVpv(pv, 0), Nullsv);
     }

     JMPENV_POP;

     if (SvTRUE(ERRSV)) {
        /* decide what to do about the error */
     }

I do get the trapping working, as I get the control back. However when 
Perl_vdie invokes the longjump on the way it falls through Perl_call_list 
which logs the error (perl.c:3972), making it not-so eval way:

	case 0:
             ...
	    atsv = ERRSV;
	    (void)SvPV(atsv, len);
	    if (len) {
                 ...
		JMPENV_POP;
		Perl_croak(aTHX_ "%"SVf"", atsv);
	    }

Any ideas how to avoid this logging problem? And if so would it make sense to 
have such a set of macros, so one doesn't have to mess with JMPENV?

Thank you!

__________________________________________________________________
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


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About