[1041] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[D-O-H] r1025 - trunk/owl

daemon@ATHENA.MIT.EDU (nelhage@MIT.EDU)
Thu Oct 29 18:12:25 2009

Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
X-Original-To: nelhage@nelhage.com
To: dirty-owl-hackers@MIT.EDU
From: nelhage@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU
Date: Tue, 29 Apr 2008 01:21:12 -0400 (EDT)

Author: nelhage
Date: 2008-04-29 01:21:12 -0400 (Tue, 29 Apr 2008)
New Revision: 1025

Added:
   trunk/owl/owl_perl.h
Modified:
   trunk/owl/owl.h
Log:
Clone owl_perl from the sqlite branch because I'm about to make use of it.


Modified: trunk/owl/owl.h
===================================================================
--- trunk/owl/owl.h	2008-04-29 03:33:12 UTC (rev 1024)
+++ trunk/owl/owl.h	2008-04-29 05:21:12 UTC (rev 1025)
@@ -67,6 +67,7 @@
 /* aim.h defines bool */
 #define HAS_BOOL
 #include <perl.h>
+#include "owl_perl.h"
 #undef logout
 #include "XSUB.h"
 #else
@@ -143,9 +144,6 @@
 #define OWL_SCROLLMODE_PAGED       4
 #define OWL_SCROLLMODE_PAGEDCENTER 5
 
-#define OWL_STYLE_TYPE_INTERNAL  0
-#define OWL_STYLE_TYPE_PERL      1
-
 #define OWL_TAB               3  /* This *HAS* to be the size of TABSTR below */
 #define OWL_TABSTR        "   "
 #define OWL_MSGTAB            7
@@ -361,10 +359,7 @@
 
 typedef struct _owl_style {
   char *name;
-  char *description;
-  int type;
-  char *perlfuncname;
-  void (*formatfunc) (owl_fmtext *fm, owl_message *m);
+  SV *perlobj;
 } owl_style;
 
 typedef struct _owl_mainwin {

Added: trunk/owl/owl_perl.h
===================================================================
--- trunk/owl/owl_perl.h	                        (rev 0)
+++ trunk/owl/owl_perl.h	2008-04-29 05:21:12 UTC (rev 1025)
@@ -0,0 +1,55 @@
+#ifndef INC_OWL_PERL_H
+#define INC_OWL_PERL_H
+
+#define OWL_PERL_VOID_CALL (void)POPs;
+
+/*
+ * This macro defines a convenience wrapper around the boilerplate of
+ * calling a method on a perl object (SV*) from C.
+ *
+ * Arguments are
+ * * obj    - the SV* to call the method on
+ * * meth   - a char* method name
+ * * args   - a code block responsible for pushing args (other than the object)
+ * * err    - a string with a %s format specifier to log in case of error
+ * * fatalp - if true, perl errors terminate barnowl
+ * * ret    - a code block executed if the call succeeded
+ *
+ * See also: `perldoc perlcall', `perldoc perlapi'
+ */
+#define OWL_PERL_CALL_METHOD(obj, meth, args, err, fatalp, ret) { \
+    int count; \
+    dSP; \
+    ENTER; \
+    SAVETMPS; \
+    PUSHMARK(SP); \
+    XPUSHs(obj); \
+    {args} \
+    PUTBACK; \
+    \
+    count = call_method(meth, G_SCALAR|G_EVAL); \
+    \
+    SPAGAIN; \
+    \
+    if(count != 1) { \
+      fprintf(stderr, "perl returned wrong count: %d\n", count); \
+      abort();                                                   \
+    } \
+    if (SvTRUE(ERRSV)) { \
+      if(fatalp) { \
+        printf(err, SvPV_nolen(ERRSV)); \
+        exit(-1); \
+      } else { \
+        owl_function_error(err, SvPV_nolen(ERRSV)); \
+        (void)POPs; \
+        sv_setsv(ERRSV, &PL_sv_undef); \
+      } \
+    } else { \
+      ret; \
+    } \
+    PUTBACK; \
+    FREETMPS; \
+    LEAVE; \
+}
+
+#endif //INC_PERL_PERL_H


home help back first fref pref prev next nref lref last post