Changeset 2323e49 for owl_perl.h
- Timestamp:
- Jun 22, 2013, 9:49:34 PM (11 years ago)
- Parents:
- 96d80e9 (diff), 15a7aee (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
owl_perl.h
rb8a3e00 r92ffd89 2 2 #define INC_BARNOWL_OWL_PERL_H 3 3 4 #define OWL_PERL_VOID_CALL (void)POPs; 4 #include <stdio.h> 5 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 } 5 22 6 23 /* 7 24 * This macro defines a convenience wrapper around the boilerplate of 8 * calling a method on a perl object (SV*) from C.25 * the perlcall methods. 9 26 * 10 27 * Arguments are 11 * * obj - the SV* to call the method on 12 * * meth - a char* method name 13 * * args - a code block responsible for pushing args (other than the object) 14 * * err - a string with a %s format specifier to log in case of error 15 * * fatalp - if true, perl errors terminate BarnOwl 16 * * 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 17 35 * 18 36 * See also: `perldoc perlcall', `perldoc perlapi' 19 37 */ 20 #define OWL_PERL_CALL_METHOD(obj, meth, args, err, fatalp, ret) { \ 21 int count; \ 22 dSP; \ 23 ENTER; \ 24 SAVETMPS; \ 25 PUSHMARK(SP); \ 26 XPUSHs(obj); \ 27 {args} \ 28 PUTBACK; \ 29 \ 30 count = call_method(meth, G_SCALAR|G_EVAL); \ 31 \ 32 SPAGAIN; \ 33 \ 34 if(count != 1) { \ 35 fprintf(stderr, "perl returned wrong count: %d\n", count); \ 36 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); \ 37 65 } \ 38 if (SvTRUE(ERRSV)) { \ 39 if(fatalp) { \ 40 printf(err, SvPV_nolen(ERRSV)); \ 41 exit(-1); \ 42 } else { \ 43 owl_function_error(err, SvPV_nolen(ERRSV)); \ 44 (void)POPs; \ 45 sv_setsv(ERRSV, &PL_sv_undef); \ 46 } \ 47 } else { \ 48 ret; \ 49 } \ 50 PUTBACK; \ 51 FREETMPS; \ 52 LEAVE; \ 66 } else if (!discardret) { \ 67 ret; \ 68 } \ 69 PUTBACK; \ 70 FREETMPS; \ 71 LEAVE; \ 53 72 } 54 73
Note: See TracChangeset
for help on using the changeset viewer.