source: owl_perl.h @ eb497a9

release-1.10release-1.9
Last change on this file since eb497a9 was f271129, checked in by Jason Gross <jgross@mit.edu>, 13 years ago
Fix up headers The additions to owl.h and some of the removals were done by Alejandro Sedeño <asedeno@mit.edu> in commit 77a0258b3919468fc9d7f7602588ac427ab36e6c. Notes: * I think owl.c lost the need for sys/time.h when we punted select() in favor of glib's main loop. * We don't actually need to include things like stdarg.h, stdio.h, glib/gstdio.h, glib-object.h. I think they get indirectly included via owl.h and/or glib.h. They're left in (or added in to) the files that use functions/types from them. * I'm not entirely sure what sys/socket.h is doing in message.c. It is there from the initial commit. I suspect it might have had something to do with the call to getnameinfo. message.c compiles without it, but http://pubs.opengroup.org/onlinepubs/009695399/functions/getnameinfo.html suggests that we're supposed to include it? *shrugs* I'm leaving it in, for now. (Rather, I'll leave one copy of the #include in.)
  • Property mode set to 100644
File size: 1.4 KB
Line 
1#ifndef INC_BARNOWL_OWL_PERL_H
2#define INC_BARNOWL_OWL_PERL_H
3
4#include <stdio.h>
5
6#define OWL_PERL_VOID_CALL (void)POPs;
7
8/*
9 * This macro defines a convenience wrapper around the boilerplate of
10 * calling a method on a perl object (SV*) from C.
11 *
12 * 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
19 *
20 * See also: `perldoc perlcall', `perldoc perlapi'
21 */
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();                                                   \
39    } \
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; \
55}
56
57#endif /* INC_BARNOWL_OWL_PERL_H */
Note: See TracBrowser for help on using the repository browser.