[Gridflow-cvs] [svn] commit: r3597 - in /trunk: base/flow_objects.c base/grid.h base/source_filter.rb rubyext.c

gridflow-cvs at artengine.ca gridflow-cvs at artengine.ca
Fri Apr 18 16:49:23 EDT 2008


Author: matju
Date: Fri Apr 18 16:49:23 2008
New Revision: 3597

Log:
pass FObject *self instead of Ruby rself, for all method calls

Modified:
    trunk/base/flow_objects.c
    trunk/base/grid.h
    trunk/base/source_filter.rb
    trunk/rubyext.c

Modified: trunk/base/flow_objects.c
==============================================================================
--- trunk/base/flow_objects.c (original)
+++ trunk/base/flow_objects.c Fri Apr 18 16:49:23 2008
@@ -2501,14 +2501,14 @@
 	}
 };
 static void display_getrectfn(t_gobj *x, t_glist *glist, int *x1, int *y1, int *x2, int *y2) {
-	BFObject *bself = (BFObject*)x; Ruby rself = bself->rself; DGS(Display); self->canvas = glist;
+	BFObject *bself = (BFObject*)x; Display *self = (Display *)bself->self; self->canvas = glist;
 	*x1 = bself->te_xpix-1;
 	*y1 = bself->te_ypix-1;
 	*x2 = bself->te_xpix+1+self->sx;
 	*y2 = bself->te_ypix+1+self->sy;
 }
 static void display_displacefn(t_gobj *x, t_glist *glist, int dx, int dy) {
-	BFObject *bself = (BFObject*)x; Ruby rself = bself->rself; DGS(Display); self->canvas = glist;
+	BFObject *bself = (BFObject*)x; Display *self = (Display *)bself->self; self->canvas = glist;
 	bself->te_xpix+=dx;
 	bself->te_ypix+=dy;
 	self->canvas = glist_getcanvas(glist);
@@ -2516,17 +2516,17 @@
 	canvas_fixlinesfor(glist, (t_text *)x);
 }
 static void display_selectfn(t_gobj *x, t_glist *glist, int state) {
-	BFObject *bself = (BFObject*)x; Ruby rself = bself->rself; DGS(Display); self->canvas = glist;
+	BFObject *bself = (BFObject*)x; Display *self = (Display *)bself->self; self->canvas = glist;
 	self->selected=!!state;
 	sys_vgui(".x%x.c itemconfigure %s -outline %s\n",glist_getcanvas(glist),self->rsym->s_name,self->selected?"#0000ff":"#000000");
 }
 static void display_deletefn(t_gobj *x, t_glist *glist) {
-	BFObject *bself = (BFObject*)x; Ruby rself = bself->rself; DGS(Display); self->canvas = glist;
+	BFObject *bself = (BFObject*)x; Display *self = (Display *)bself->self; self->canvas = glist;
 	if (self->vis) sys_vgui(".x%x.c delete %s %sTEXT\n",glist_getcanvas(glist),self->rsym->s_name,self->rsym->s_name);
 	canvas_deletelinesfor(glist, (t_text *)x);
 }
 static void display_visfn(t_gobj *x, t_glist *glist, int flag) {
-	BFObject *bself = (BFObject*)x; Ruby rself = bself->rself; DGS(Display); self->canvas = glist;
+	BFObject *bself = (BFObject*)x; Display *self = (Display *)bself->self; self->canvas = glist;
 	self->vis = !!flag;
 	display_update(self);
 }

Modified: trunk/base/grid.h
==============================================================================
--- trunk/base/grid.h (original)
+++ trunk/base/grid.h Fri Apr 18 16:49:23 2008
@@ -127,16 +127,11 @@
 //****************************************************************
 // my own little Ruby <-> C++ layer
 
-#ifdef USE_RUBY
 static inline bool INTEGER_P(Ruby x) {return FIXNUM_P(x)||TYPE(x)==T_BIGNUM;}
 static inline bool FLOAT_P(Ruby x)   {return TYPE(x)==T_FLOAT;}
 static Ruby convert(Ruby x, Ruby *bogus) { return x; }
-typedef Ruby (*RMethod)(...); /* !@#$ fishy */
-#else
-//#define Qnil 4
-#define Qnil 0
-typedef void *(*RMethod)(...); /* !@#$ fishy */
-#endif // USE_RUBY
+struct FObject;
+typedef Ruby (*RMethod)(FObject *, int, Ruby *);
 typedef std::string string;
 
 #define BUILTIN_SYMBOLS(MACRO) \
@@ -377,7 +372,6 @@
 
 // you shouldn't use MethodDecl directly (used by source_filter.rb)
 struct MethodDecl { const char *selector; RMethod method; };
-void define_many_methods(Ruby rself, int n, MethodDecl *methods);
 extern Ruby mGridFlow, cFObject, cFormat;
 
 #undef check
@@ -891,7 +885,7 @@
 #ifdef HAVE_GEM
 	void *gemself; // a CPPExtern * for binary-compat with GEM's Obj_header class
 #endif
-	Ruby rself;
+	FObject *self;
 	int nin,nout;   // per object settings (not class)
 	BFProxy  **in;  // direct access to  inlets (not linked lists)
 	t_outlet **out; // direct access to outlets (not linked lists)

Modified: trunk/base/source_filter.rb
==============================================================================
--- trunk/base/source_filter.rb (original)
+++ trunk/base/source_filter.rb Fri Apr 18 16:49:23 2008
@@ -140,7 +140,7 @@
 	Out.print "#{m.rettype} #{m.selector}(VA"
 	Out.print ", #{unparse_arglist m.arglist}" if m.arglist.length>0
 	Out.print ");"
-	Out.print "static Ruby #{m.selector}_wrap(VA, Ruby rself); "
+	Out.print "static Ruby #{m.selector}_wrap(#{classname} *self, VA); "
 end
 
 def handle_def(line)
@@ -160,9 +160,8 @@
 	else
 		qlass.methods[m.selector] = m
 	end
-	Out.print "Ruby #{classname}::#{m.selector}_wrap(VA, Ruby rself) {"
+	Out.print "Ruby #{classname}::#{m.selector}_wrap(#{classname} *self, VA) {"
 	Out.print "static const char *methodspec = \"#{qlass.name}::#{m.selector}(#{unparse_arglist m.arglist,false})\";"
-	Out.print "DGS(#{classname});"
 	Out.print "#{m.rettype} foo;" if m.rettype!="void"
 	Out.print "try {"
 	Out.print "if (argc<#{m.minargs}"

Modified: trunk/rubyext.c
==============================================================================
--- trunk/rubyext.c (original)
+++ trunk/rubyext.c Fri Apr 18 16:49:23 2008
@@ -58,14 +58,12 @@
 #endif
 
 // call f(x) and if fails call g(y)
-#define RESCUE(f,x,g,y) rb_rescue2((RMethod)(f),(Ruby)(x),(RMethod)(g),(Ruby)(y),rb_eException,0);
+#define RESCUE(f,x,g,y) rb_rescue2((VALUE (*)(...))(f),(Ruby)(x),(VALUE (*)(...))(g),(Ruby)(y),rb_eException,0);
 
 std::map<string,FClass *> fclasses;
 std::map<t_class *,FClass *> fclasses_pd;
 
 /* **************************************************************** */
-struct BFObject;
-
 struct FMessage {
 	BFObject *self;
 	int winlet;
@@ -118,7 +116,7 @@
 	if (method) {
 		Ruby argv2[argc];
 		pd2ruby(argc,argv2,argv);
-		method(argc,argv2,bself->rself);
+		method(bself->self,argc,argv2);
 		return;
 	}
 	if (!silent) pd_error((t_pd *)bself, "method not found: '%s'",sel);
@@ -227,10 +225,7 @@
 
 static void BFObject_method_missing (BFObject *bself, int winlet, t_symbol *selector, int ac, t_atom *at) {
 	FMessage fm = { bself, winlet, selector, ac, at, false };
-	if (!bself->rself) {pd_error(bself,"message to a dead object. (supposed to be impossible)"); return;}
-	try {
-		RESCUE(BFObject_method_missing_1,&fm,BFObject_rescue,(Ruby)&fm);
-	} catch (Barf *oozy) {post("error: %s",oozy->text);}
+	try {RESCUE(BFObject_method_missing_1,&fm,BFObject_rescue,(Ruby)&fm);} catch (Barf *oozy) {post("error: %s",oozy->text);}
 }
 static void BFObject_method_missing0 (BFObject *self, t_symbol *s, int argc, t_atom *argv) {
 	BFObject_method_missing(self,0,s,argc,argv);
@@ -272,7 +267,7 @@
 	Ruby rself = FObject_s_new(j,argv,fm->selector->s_name);
 	DGS(FObject);
 	self->bself = bself;
-	bself->rself = rself;
+	bself->self = self;
 	bself->mom = 0;
 #ifdef HAVE_GEM
 	bself->gemself = (CPPExtern *)((void **)self+11); /* not 64-bit-safe */
@@ -430,21 +425,10 @@
 
 //----------------------------------------------------------------
 
-void define_many_methods(Ruby rself, int n, MethodDecl *methods) {
-	for (int i=0; i<n; i++) {
-		MethodDecl *md = &methods[i];
-		char *buf = strdup(md->selector);
-		if (strlen(buf)>2 && strcmp(buf+strlen(buf)-2,"_m")==0) buf[strlen(buf)-2]=0;
-		rb_define_method(rself,buf,(RMethod)md->method,-1);
-		free(buf);
-	}
-}
-
 void fclass_install(FClass *fclass, const char *super) {
 	fclass->rself = super ?
 		rb_define_class_under(mGridFlow, fclass->rubyname, rb_funcall(mGridFlow,SI(const_get),1,rb_str_new2(super))) :
 		rb_funcall(mGridFlow,SI(const_get),1,rb_str_new2(fclass->rubyname));
-	define_many_methods(fclass->rself,fclass->methodsn,fclass->methods);
 	if (fclass->startup) fclass->startup(fclass);
 }
 
@@ -553,9 +537,8 @@
 	mGridFlow = EVAL("module GridFlow; CObject = ::Object; self end");
 	rb_ivar_set(mGridFlow, SI(@fobjects), rb_hash_new());
 	cFObject = rb_define_class_under(mGridFlow, "FObject", rb_cObject);
-	define_many_methods(cFObject,COUNT(FObject_methods),FObject_methods);
 	\startall
-	rb_define_singleton_method(EVAL("GridFlow::Pointer"),"new", (RMethod)Pointer_s_new, 1);
+	rb_define_singleton_method(EVAL("GridFlow::Pointer"),"new", (VALUE (*)(...))Pointer_s_new, 1);
 	cPointer = EVAL("GridFlow::Pointer");
 	startup_number();
 	startup_grid();



More information about the Gridflow-cvs mailing list