barnowl_perlaimdebianrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change
on this file since 7d25006 was
120291c,
checked in by Nelson Elhage <nelhage@mit.edu>, 16 years ago
|
Clone owl_perl from the sqlite branch because I'm about to make use of it.
|
-
Property mode set to
100644
|
File size:
1.4 KB
|
Line | |
---|
1 | #ifndef INC_OWL_PERL_H |
---|
2 | #define INC_OWL_PERL_H |
---|
3 | |
---|
4 | #define OWL_PERL_VOID_CALL (void)POPs; |
---|
5 | |
---|
6 | /* |
---|
7 | * This macro defines a convenience wrapper around the boilerplate of |
---|
8 | * calling a method on a perl object (SV*) from C. |
---|
9 | * |
---|
10 | * 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 |
---|
17 | * |
---|
18 | * See also: `perldoc perlcall', `perldoc perlapi' |
---|
19 | */ |
---|
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(); \ |
---|
37 | } \ |
---|
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; \ |
---|
53 | } |
---|
54 | |
---|
55 | #endif //INC_PERL_PERL_H |
---|
Note: See
TracBrowser
for help on using the repository browser.