question about embedding ruby 1.9 and handling exceptions
I'm embedding ruby 1.9, and so far everything works *almost* ok: there
is a problem with the exception handling when one is raised from code
evaluated in ruby code (or ruby-c code) referenced from plain-c code.
I'll try to explain it with a simple flux:
+--- 1) init ruby (load main.rb, which in turn load other ruby files)
+--- 2) do some c stuff
+--- 3) some c code will call a ruby method in a ruby object
+- 4) ruby code is executed, which might raise an exception
If an exception is raised on (1), it works as expected (I'm using
rb_protect(RUBY_METHOD_FUNC(rb_require), (VALUE)"main", &state) to
"start" ruby). However, is an exception is raised during (4), I get an
invalid access and the code crashes (when calling longjump), here's
the backtrace, which is always the same:
#0 0x91627288 in longjmp
#1 0x0010cc62 in vm_exec at vm.c:1261
#2 0x00107037 in vm_call0 at vm_eval.c:57
#3 0x00107ec6 in rb_call0 at vm_eval.c:249
#4 0x00107b63 in rb_call at vm_eval.c:255
#5 0x00107f8b in rb_funcall at vm_eval.c:427
#6 0x000d1d16 in -[CocosNode(SC_Extension) textFieldShouldReturn:] at
#6 is the where I call the ruby code. If the exception is not raised,
everything works just fine. The problem here is that this makes hard
to track bugs in the ruby code...
Any idea why this might be happening? Do I have to do something
special when calling ruby code from the C world?
Oh, and everything is in the same thread...
PS: using ruby 1.9.1 (checked out from svn branch 1_9_1):
$ cat ruby/version.h
#define RUBY_VERSION "1.9.1"
#define RUBY_RELEASE_DATE "2009-05-22"
#define RUBY_PATCHLEVEL 154
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 9
#define RUBY_VERSION_TEENY 1
#define RUBY_RELEASE_YEAR 2009
#define RUBY_RELEASE_MONTH 5
#define RUBY_RELEASE_DAY 22
Rolando Abarca M.
|All times are GMT. The time now is 08:33 PM.|
SEO by vBSEO ©2010, Crawlability, Inc.