Changes in owl_perl.h [f271129:92ffd89]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
owl_perl.h
rf271129 r92ffd89 4 4 #include <stdio.h> 5 5 6 #define OWL_PERL_VOID_CALL (void)POPs; 6 /* 7 * This macro defines a convenience wrapper around the boilerplate 8 * of pushing char * arguments on to the stack for perl calling. 9 * 10 * Arguments are 11 * * i - the counter variable to use, which must be declared prior 12 * to calling this macro 13 * * argc - the number of arguments 14 * * argv - an array of char*s, of length at least argc; the arguments 15 * to push on to the stack 16 */ 17 #define OWL_PERL_PUSH_ARGS(i, argc, argv) { \ 18 for (i = 0; i < argc; i++) { \ 19 XPUSHs(sv_2mortal(owl_new_sv(argv[i]))); \ 20 } \ 21 } 7 22 8 23 /* 9 24 * This macro defines a convenience wrapper around the boilerplate of 10 * calling a method on a perl object (SV*) from C.25 * the perlcall methods. 11 26 * 12 27 * Arguments are 13 * * obj - the SV* to call the method on 14 * * meth - a char* method name 15 * * args - a code block responsible for pushing args (other than the object) 16 * * err - a string with a %s format specifier to log in case of error 17 * * fatalp - if true, perl errors terminate BarnOwl 18 * * ret - a code block executed if the call succeeded 28 * * call - the line of code to make the perl call 29 * * args - a code block responsible for pushing args 30 * * err - a string with a %s format specifier to log in case of error 31 * * fatalp - if true, perl errors terminate BarnOwl 32 * * discardret - should be true if no return is expected 33 * (if the call is passed the flag G_DISCARD or G_VOID) 34 * * ret - a code block executed if the call succeeded 19 35 * 20 36 * See also: `perldoc perlcall', `perldoc perlapi' 21 37 */ 22 #define OWL_PERL_CALL_METHOD(obj, meth, args, err, fatalp, ret) { \ 23 int count; \ 24 dSP; \ 25 ENTER; \ 26 SAVETMPS; \ 27 PUSHMARK(SP); \ 28 XPUSHs(obj); \ 29 {args} \ 30 PUTBACK; \ 31 \ 32 count = call_method(meth, G_SCALAR|G_EVAL); \ 33 \ 34 SPAGAIN; \ 35 \ 36 if(count != 1) { \ 37 fprintf(stderr, "perl returned wrong count: %d\n", count); \ 38 abort(); \ 38 #define OWL_PERL_CALL(call, args, err, fatalp, discardret, ret) { \ 39 int count; \ 40 dSP; \ 41 \ 42 ENTER; \ 43 SAVETMPS; \ 44 \ 45 PUSHMARK(SP); \ 46 {args} \ 47 PUTBACK; \ 48 \ 49 count = call; \ 50 \ 51 SPAGAIN; \ 52 \ 53 if (!discardret && count != 1) { \ 54 croak("Perl returned wrong count: %d\n", count); \ 55 } \ 56 \ 57 if (SvTRUE(ERRSV)) { \ 58 if (fatalp) { \ 59 fprintf(stderr, err, SvPV_nolen(ERRSV)); \ 60 exit(-1); \ 61 } else { \ 62 owl_function_error(err, SvPV_nolen(ERRSV)); \ 63 if (!discardret) (void)POPs; \ 64 sv_setsv(ERRSV, &PL_sv_undef); \ 39 65 } \ 40 if (SvTRUE(ERRSV)) { \ 41 if(fatalp) { \ 42 printf(err, SvPV_nolen(ERRSV)); \ 43 exit(-1); \ 44 } else { \ 45 owl_function_error(err, SvPV_nolen(ERRSV)); \ 46 (void)POPs; \ 47 sv_setsv(ERRSV, &PL_sv_undef); \ 48 } \ 49 } else { \ 50 ret; \ 51 } \ 52 PUTBACK; \ 53 FREETMPS; \ 54 LEAVE; \ 66 } else if (!discardret) { \ 67 ret; \ 68 } \ 69 PUTBACK; \ 70 FREETMPS; \ 71 LEAVE; \ 55 72 } 56 73
Note: See TracChangeset
for help on using the changeset viewer.