More rb_protect rewrite to use rb_rescue for Ruby 1.9

This commit is contained in:
William S Fulton 2013-04-06 00:30:50 +01:00
commit 8484c2de9b

View file

@ -172,17 +172,14 @@ namespace swig {
return rb_inspect(_obj); return rb_inspect(_obj);
} }
static VALUE swig_rescue_funcall( VALUE ) static VALUE swig_rescue_swallow( VALUE )
{ {
/* // VALUE errstr = rb_obj_as_string(rb_errinfo());
VALUE err = rb_errinfo(); // printf("Swallowing error: '%s'\n", RSTRING_PTR(StringValue(errstr)));
VALUE errstr = rb_obj_as_string(err); return Qnil; /* Swallow Ruby exception */
std::cout << "Error is: '" << RSTRING_PTR(StringValue(errstr)) << "'" << std::endl;
*/
return Qnil;/* Swallow Ruby exception */
} }
static VALUE swig_protect_funcall( VALUE p ) static VALUE swig_rescue_funcall( VALUE p )
{ {
OpArgs* args = (OpArgs*) p; OpArgs* args = (OpArgs*) p;
return rb_funcall( args->src, args->id, args->nargs, args->target ); return rb_funcall( args->src, args->id, args->nargs, args->target );
@ -206,8 +203,8 @@ namespace swig {
args.id = op_id; \ args.id = op_id; \
args.nargs = 1; \ args.nargs = 1; \
args.target = VALUE(other); \ args.target = VALUE(other); \
ret = rb_rescue(RUBY_METHOD_FUNC(swig_protect_funcall), VALUE(&args), \ ret = rb_rescue(RUBY_METHOD_FUNC(swig_rescue_funcall), VALUE(&args), \
(RUBY_METHOD_FUNC(swig_rescue_funcall)), Qnil); \ (RUBY_METHOD_FUNC(swig_rescue_swallow)), Qnil); \
} \ } \
if ( ret == Qnil ) { \ if ( ret == Qnil ) { \
VALUE a = rb_funcall( _obj, hash_id, 0 ); \ VALUE a = rb_funcall( _obj, hash_id, 0 ); \
@ -240,14 +237,13 @@ namespace swig {
{ \ { \
VALUE ret = Qnil; \ VALUE ret = Qnil; \
SWIG_RUBY_THREAD_BEGIN_BLOCK; \ SWIG_RUBY_THREAD_BEGIN_BLOCK; \
int status; \
OpArgs args; \ OpArgs args; \
args.src = _obj; \ args.src = _obj; \
args.id = proc_id; \ args.id = proc_id; \
args.nargs = 0; \ args.nargs = 0; \
args.target = Qnil; \ args.target = Qnil; \
ret = rb_protect( PROTECTFUNC(swig_protect_funcall), VALUE(&args), \ ret = rb_rescue(RUBY_METHOD_FUNC(swig_rescue_funcall), VALUE(&args), \
&status ); \ (RUBY_METHOD_FUNC(swig_rescue_swallow)), Qnil); \
SWIG_RUBY_THREAD_END_BLOCK; \ SWIG_RUBY_THREAD_END_BLOCK; \
return ret; \ return ret; \
} }
@ -262,14 +258,13 @@ namespace swig {
{ \ { \
VALUE ret = Qnil; \ VALUE ret = Qnil; \
SWIG_RUBY_THREAD_BEGIN_BLOCK; \ SWIG_RUBY_THREAD_BEGIN_BLOCK; \
int status; \
OpArgs args; \ OpArgs args; \
args.src = _obj; \ args.src = _obj; \
args.id = proc_id; \ args.id = proc_id; \
args.nargs = 1; \ args.nargs = 1; \
args.target = VALUE(other); \ args.target = VALUE(other); \
ret = rb_protect( PROTECTFUNC(swig_protect_funcall), VALUE(&args), \ ret = rb_rescue(RUBY_METHOD_FUNC(swig_rescue_funcall), VALUE(&args), \
&status ); \ (RUBY_METHOD_FUNC(swig_rescue_swallow)), Qnil); \
SWIG_RUBY_THREAD_END_BLOCK; \ SWIG_RUBY_THREAD_END_BLOCK; \
return GC_VALUE(ret); \ return GC_VALUE(ret); \
} }