[Gridflow-cvs] [svn] commit: r4039 - in /trunk: gridflow.c gridflow.h

gridflow-cvs at artengine.ca gridflow-cvs at artengine.ca
Thu Jul 17 11:59:21 EDT 2008


Author: matju
Date: Thu Jul 17 11:59:21 2008
New Revision: 4039

Log:
centralise use of pd_error, and make error generator (Barf) use std::ostringstream instead of char[]

Modified:
    trunk/gridflow.c
    trunk/gridflow.h

Modified: trunk/gridflow.c
==============================================================================
--- trunk/gridflow.c (original)
+++ trunk/gridflow.c Thu Jul 17 11:59:21 2008
@@ -55,23 +55,26 @@
 BuiltinSymbols bsym;
 
 Barf::Barf(const char *s, ...) {
-    char buf[1024];
+    std::ostringstream os;
     va_list ap;
     va_start(ap,s);
-    vsnprintf(buf,1024,s,ap);
-    buf[1023]=0;
+    voprintf(os,s,ap);
     va_end(ap);
-    text = strdup(buf);
-}
-Barf::Barf(const char *file, int line, const char *func, const char *s, ...) {
-    char buf[1024];
+    text = os.str();
+}
+Barf::Barf(const char *file, int line, const char *func, const char *fmt, ...) {
+    std::ostringstream os;
     va_list ap;
-    va_start(ap,s);
-    int n = vsnprintf(buf,1024,s,ap);
-    if (n<1024) snprintf(buf+n, 1024-n, "\n%s:%d:in `%s'", file, line, func);
-    buf[1023]=0;
+    va_start(ap,fmt);
+    voprintf(os,fmt,ap);
+    //oprintf(os,"\n%s:%d:in `%s'",file,line,func);
     va_end(ap);
-    text = strdup(buf);
+    text = os.str();
+}
+
+void Barf::error(BFObject *bself) {
+	if (bself) pd_error(bself,"%s",text.data());
+	else        ::error(      "%s",text.data());
 }
 
 void pd_oprint (std::ostream &o, int argc, t_atom *argv) {
@@ -562,7 +565,7 @@
 	m = funcall_lookup(bself,"anything");
 	if (m) {SETSYMBOL(argv+0,gensym(buf)); m(bself->self,argc+1,argv); return;}
 	pd_error((t_pd *)bself, "method '%s' not found for inlet %d in class '%s'",selector->s_name,winlet,pd_classname(bself));
-    } catch (Barf &oozy) {pd_error(bself,"%s",oozy.text);}
+    } catch (Barf &oozy) {oozy.error(bself);}
 }
 static void BFObject_anything0 (BFObject *self, t_symbol *s, int argc, t_atom2 *argv) {
 	BFObject_anything(self,0,s,argc,argv);
@@ -616,11 +619,11 @@
 		if (argv[k].a_type==A_SYMBOL) pd_typedmess((t_pd *)bself,argv[k].a_symbol,j-k-1,argv+k+1);
 	}
 	return bself;
-    } catch (Barf &oozy) {pd_error(bself,"%s",oozy.text); return 0;}
+    } catch (Barf &oozy) {oozy.error(bself); return 0;}
 }
 
 static void BFObject_delete (BFObject *bself) {
-	try {delete bself->self;} catch (Barf &oozy) {pd_error(bself,"%s",oozy.text);}
+	try {delete bself->self;} catch (Barf &oozy) {oozy.error(bself);}
 	bself->ninlets_set(1,false);
 	delete[] bself->inlets;
 	delete[] bself->outlets;
@@ -922,7 +925,7 @@
 	sys_vgui(".mbar.help add command -label \"GridFlow index\" -command {pd pd open index.pd %s/doc \\;}\n",dirresult);
 	delete[] dirresult;
 	delete[] dirname;
-    } catch (Barf &oozy) {post("gridflow_setup error: %s",oozy.text);}
+    } catch (Barf &oozy) {oozy.error(0);}
     signal(SIGSEGV,SIG_DFL);
     signal(SIGABRT,SIG_DFL);
     signal(SIGBUS, SIG_DFL);

Modified: trunk/gridflow.h
==============================================================================
--- trunk/gridflow.h (original)
+++ trunk/gridflow.h Thu Jul 17 11:59:21 2008
@@ -44,6 +44,8 @@
 #include <malloc.h>
 #endif
 
+typedef std::string string;
+
 #ifndef a_float
 #define a_float    a_w.w_float
 #define a_symbol   a_w.w_symbol
@@ -175,11 +177,13 @@
 		case 0:MACRO(0); case 1:MACRO(1); case 2:MACRO(2); case 3:MACRO(3); \
 		PTR+=4; N-=4; ARGS; if (N) goto start; }
 
+struct BFObject;
 struct Barf {
-  char *text;
+  string text;
   Barf(const char *s, ...);
   Barf(const char *file, int line, const char *func, const char *s, ...);
-  ~Barf() {free(text);}
+  void error(BFObject *bself);
+  ~Barf() {}
 };
 
 #include <stdio.h>
@@ -228,7 +232,6 @@
 struct FObject;
 struct t_atom2;
 typedef void (*FMethod)(FObject *, int, t_atom2 *);
-typedef std::string string;
 
 #define BUILTIN_SYMBOLS(MACRO) \
 	MACRO(_grid,"grid") MACRO(_bang,"bang") MACRO(_float,"float") \
@@ -748,7 +751,6 @@
 	string type;
 	AttrDecl(string name_, string type_) {name=name_; type=type_;}
 };
-struct BFObject;
 typedef FObject *(*t_allocator)(BFObject *,MESSAGE3);
 struct FClass {
 	t_allocator allocator; // returns a new C++ object



More information about the Gridflow-cvs mailing list