From: Marcus Holland-Moritz Date: Wed, 2 Feb 2005 21:26:14 +0000 (+0000) Subject: Attempt to fix problems with new exception handling macros. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9b5c3821be1f2a9a84772171c8bbadbf9cfc4a53;p=p5sagit%2Fp5-mst-13.2.git Attempt to fix problems with new exception handling macros. p4raw-id: //depot/perl@23925 --- diff --git a/MANIFEST b/MANIFEST index 4ac5039..b71425f 100644 --- a/MANIFEST +++ b/MANIFEST @@ -920,6 +920,7 @@ ext/XS/APItest/APItest.xs XS::APItest extension ext/XS/APItest/Makefile.PL XS::APItest extension ext/XS/APItest/MANIFEST XS::APItest extension ext/XS/APItest/README XS::APItest extension +ext/XS/APItest/exception.c XS::APItest extension ext/XS/APItest/t/call.t XS::APItest extension ext/XS/APItest/t/exception.t XS::APItest extension ext/XS/APItest/t/hash.t XS::APItest extension diff --git a/XSUB.h b/XSUB.h index 6751572..c74d6f6 100644 --- a/XSUB.h +++ b/XSUB.h @@ -272,11 +272,13 @@ Rethrows a previously caught exception. See L. # define XS_VERSION_BOOTCHECK #endif -#define dXCPT dJMPENV; int rEtV = 0 -#define XCPT_TRY_START JMPENV_PUSH(rEtV); if (rEtV == 0) -#define XCPT_TRY_END JMPENV_POP; -#define XCPT_CATCH if (rEtV != 0) -#define XCPT_RETHROW JMPENV_JUMP(rEtV) +#ifdef NO_XSLOCKS +# define dXCPT dJMPENV; int rEtV = 0 +# define XCPT_TRY_START JMPENV_PUSH(rEtV); if (rEtV == 0) +# define XCPT_TRY_END JMPENV_POP; +# define XCPT_CATCH if (rEtV != 0) +# define XCPT_RETHROW JMPENV_JUMP(rEtV) +#endif /* The DBM_setFilter & DBM_ckFilter macros are only used by diff --git a/ext/XS/APItest/APItest.xs b/ext/XS/APItest/APItest.xs index 9b7da12..fcdcc9a 100644 --- a/ext/XS/APItest/APItest.xs +++ b/ext/XS/APItest/APItest.xs @@ -2,32 +2,8 @@ #include "perl.h" #include "XSUB.h" -static void throws_exception(int throw_e) -{ - if (throw_e) - croak("boo\n"); -} - -static int exception(int throw_e) -{ - dTHR; - dXCPT; - SV *caught = get_sv("XS::APItest::exception_caught", 0); - - XCPT_TRY_START { - throws_exception(throw_e); - } XCPT_TRY_END - - XCPT_CATCH - { - sv_setiv(caught, 1); - XCPT_RETHROW; - } - - sv_setiv(caught, 0); - - return 42; -} +/* from exception.c */ +int exception(int); MODULE = XS::APItest:Hash PACKAGE = XS::APItest::Hash diff --git a/ext/XS/APItest/MANIFEST b/ext/XS/APItest/MANIFEST index 1feded8..a8cfd5f 100644 --- a/ext/XS/APItest/MANIFEST +++ b/ext/XS/APItest/MANIFEST @@ -3,6 +3,7 @@ MANIFEST README APItest.pm APItest.xs +exception.c t/call.t t/hash.t t/printf.t diff --git a/ext/XS/APItest/Makefile.PL b/ext/XS/APItest/Makefile.PL index 4ff9403..e49da36 100644 --- a/ext/XS/APItest/Makefile.PL +++ b/ext/XS/APItest/Makefile.PL @@ -9,6 +9,8 @@ WriteMakefile( ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => 'APItest.pm', # retrieve abstract from module AUTHOR => 'Tim Jenness , Christian Soeller , Hugo van der Sanden ') : ()), + 'C' => ['exception.c'], + 'OBJECT' => '$(BASEEXT)$(OBJ_EXT) $(O_FILES)', 'LIBS' => [''], # e.g., '-lm' 'DEFINE' => '', # e.g., '-DHAVE_SOMETHING' 'INC' => '-I.', # e.g., '-I. -I/usr/include/other' diff --git a/ext/XS/APItest/exception.c b/ext/XS/APItest/exception.c new file mode 100644 index 0000000..9477ea9 --- /dev/null +++ b/ext/XS/APItest/exception.c @@ -0,0 +1,33 @@ +#include "EXTERN.h" +#include "perl.h" + +#define NO_XSLOCKS +#include "XSUB.h" + +static void throws_exception(int throw_e) +{ + if (throw_e) + croak("boo\n"); +} + +int exception(int throw_e) +{ + dTHR; + dXCPT; + SV *caught = get_sv("XS::APItest::exception_caught", 0); + + XCPT_TRY_START { + throws_exception(throw_e); + } XCPT_TRY_END + + XCPT_CATCH + { + sv_setiv(caught, 1); + XCPT_RETHROW; + } + + sv_setiv(caught, 0); + + return 42; +} + diff --git a/pod/perlguts.pod b/pod/perlguts.pod index 7f23169..d95d3e4 100644 --- a/pod/perlguts.pod +++ b/pod/perlguts.pod @@ -2262,10 +2262,15 @@ and =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: +There are a couple of macros to do very basic exception handling in XS +modules. You have to define C before including F to +be able to use these macros: + + #define NO_XSLOCKS + #include "XSUB.h" + +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 */