How can Perl XSUB die?

I wrote the Perl XS wrapper for a C library consisting of approximately ~ 80 functions. Now my general strategy is to replace the error with a C function with c PL_sv_undef, and the calling Perl code must explicitly check if there is no return undef. (For some C functions, this is more complicated since I convert their output to HV/ AVand use an empty list to report an error.)

Now that I have moved on to writing large Perl scripts using this library, I want to simplify the handling and use of errors, for example. regular eval {}/ dieexception mechanism for error handling.

At the moment, a simple XSUB in my XS looks like this:

SV *
simple_function( param1, param2 = 0, param3 = 0)
        int             param1
        int             param2
        int             param3
        CODE:
                int rc;
                rc = simple_function( param1, param2, param3 );
                RETVAL = (rc == 0) ? &PL_sv_yes : &PL_sv_undef;
        OUTPUT:
                RETVAL

, , "RaiseError", die on , - , . , "RaiseError" .pm, .xs, , Perl die. .pm, . , XS.

perlxs/perlguts. , Perl_croak() .c, .xs, - .

XS- Perl die? XSUB Perl? , RETVAL ? $@?

+5
1

Perl_croak() perlapi man. , , $@ NULL.

+6

All Articles