From: Charles Mills Date: 2005-01-14T04:06:17+09:00 Subject: Re: extending/embedding ruby (callbacks) [LONG] Peter Schrammel wrote: > Charles Mills schrieb: > > Peter Schrammel wrote: > > It may help if you explain what your trying to do a bit more. > OK: > The ruby part just does one thing: > extend the RFuse Class with some methods: > getdir > getattr > > Then it creates a RFuse object a calls main on it. > > main is in C: It registers the wrapper functions "rf_getdir", > "rf_getattr" to fuse and calls the main function of fuse, so the ruby > programm is sleeping and waiting. > > if somebody does a "ls /tmp/fuse" the fuse system calls the registered > function rf_getdir with 3 args: > path, handler, filler > where > path is the requested path > handler is a hanlde used by filler > filler is a function, that takes 3 args: handler,string,mode > > now rf_getdir should do the following: > create an object of RFiller(set the filler fuction and the handler) and > pass the path, and the Rfiller object to self.getdir (on the ruby side). > > self.getdir calls filler.push("filename",mode) and returns > > the RFiller object should be destroyed now and rf_getdir is done. > > The problem is: > even if I don't call ruby's getdir method I have endless recursions. > > > > > > > the function below should be registered using rb_define_alloc_func() > > and is typically called rfill_alloc() > > done that...thanks > > > > > you don't need this, if your worried about rfiller_instance being GC'ed > > make it volatile. > > how to do this? sorry my ruby extension programming is at newbie level :-) no worries. you should read this: http://www.rubygarden.com/ruby/ruby?action=browse&id=GCAndExtensions volatile is a C keyword/qualifier. > > > > > > > not sure how the flow of control goes in your program but seems pretty > > obvious you have infinite recursion going on right here. > > > ok: But if I do just this: > static int rf_getdir(const char *path, fuse_dirh_t h, fuse_dirfil_t f) > { > VALUE rfiller_class; > VALUE rfiller_instance; > rfiller_class=rb_const_get(rb_cObject,rb_intern("RFiller")); > rfiller_instance=rb_funcall(rfiller_class,rb_intern("new"),0); > // no call to anything! > return 0; > } > > I still get the same error... :-( > Commenting out the "rfiller_instance="... line everything is all right. > > To me it seems the GC wakes up one in a while does something ... > strange. Or I run out of memory because the GC never wakes up. > Maybe you should start with something smaller. Probably something that doesn't use function pointers. Perhaps there is a way to test the classes individually... or you could add some sanity tests. -Charlie