Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > question about embedding ruby 1.9 and handling exceptions

Thread Tools

question about embedding ruby 1.9 and handling exceptions

Rolando Abarca
Posts: n/a
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_RELEASE_YEAR 2009

Rolando Abarca M.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Exceptions - How do you make it work like built-in exceptions? Lie Python 3 01-14-2008 06:45 PM
Exceptions + Performance on path without exceptions C++ 3 04-16-2007 08:52 PM
Checked exceptions vs unchecked exceptions Ahmed Moustafa Java 5 07-14-2004 01:46 PM
Java Exceptions handling Question Shingitty Bunky Java 4 12-16-2003 07:36 PM
Custom exceptions -- inherit from exceptions.Exception? Paul Miller Python 3 11-12-2003 09:24 AM