MagLev/maglev — Issue #109: Cannot rescue error raised during rb_funcall
Author: timfel
Created: 2011-11-17 22:51:17+00:00
State: open

Seen in the json gem tests.

In generator.c `cState_generate` causes execution of `rb_funcall`, calling the Ruby method `to_json` on an object. If that Ruby method raises an error, this error will propagate back into the C function, but instead of propagating out of there back into Ruby land to be rescued, it kills the process.

Run the following to reproduce:

$ maglev-gem install json
* will pick json-maglev- *

Then run this:

require "json"
require "json/add/core"

begin
JSON(Struct.new(:foo).new(42))
rescue Exception
p "rescued"
end

You should see "rescued", but instead the VM dies with `ERROR 2702 , Only named structs are supported! (JSON::JSONError)`