On 2005-01-02, at 22:07:30 +0100, Marcus Holland-Moritz wrote:

> I've posted the question below on perl-xs.
> 
> It seems that at least Nick I-S and me are interested in
> an easy way to catch Perl_croak() from within XS code
> without using call_xx().
> 
> I've proposed a set of macros to hide the JMPENV_* stuff,
> which isn't part of the public API. If nobody has objections,
> I'd like to add these (or similar) macros to the core (and
> Devel::PPPort).

I've put the macros into XSUB.h, along with the following
documentation in perlguts:

: =head2 Exception Handling
: 
: There are a couple of macros to do very basic exception handling in
: XS modules. You can use these macros if you call code that may croak,
: but you need to do some cleanup before giving control back to Perl.
: For example:
: 
:         dXCPT;    /* set up neccessary variables */
: 
:         XCPT_TRY_START {
:           code_that_may_croak();
:         } XCPT_TRY_END
: 
:         XCPT_CATCH
:         {
:           /* do cleanup here */
:           XCPT_RETHROW;
:         }
: 
: Note that you always have to rethrow an exception that has been
: caught. Using these macros, it is not possible to just catch the
: exception and ignore it. If you have to ignore the exception, you
: have to use the C<call_*> function.
: 
: The advantage of using the above macros is that you don't have
: to setup an extra function for C<call_*>, and that using these
: macros is faster than using C<call_*>.

The macros are also available in Devel::PPPort 3.05, and
work back to perl 5.003.

Marcus

-- 
After a number of decimal places, nobody gives a damn.

Reply via email to