Ruby 1.9 fixes.
SF Bug#1292 - Runtime fixes for Proc changes in ruby-1.9 when using STL wrappers that override the default predicate, such as: %template(Map) std::map<swig::LANGUAGE_OBJ, swig::LANGUAGE_OBJ, swig::BinaryPredicate<> >; Fixes li_std_functors testcases for Ruby 1.9. Also rb_respond_to return values have changed subtely in 1.9 and return should be treated as a flag instead of checking for Qtrue, see SF Bug #1159. Also fix li_std_map, li_std_set silently failing - rb_protect behaviour seems to have changed when an exception is thrown, so code has been changed to use rb_rescue. A call to 'rb_set_errinfo(Qnil)' could have solved this after the rb_protect call, but it is only available in 1.9+ and Ruby API changes are not easily and transparently detectable.
This commit is contained in:
parent
ee92a26819
commit
5d529d5a76
5 changed files with 34 additions and 9 deletions
|
|
@ -5,6 +5,16 @@ See the RELEASENOTES file for a summary of changes in each release.
|
|||
Version 2.0.10 (in progress)
|
||||
============================
|
||||
|
||||
2013-04-05: wsfulton
|
||||
[Ruby] SF Bug #1292 - Runtime fixes for Proc changes in ruby-1.9 when using STL
|
||||
wrappers that override the default predicate, such as:
|
||||
|
||||
%template(Map) std::map<swig::LANGUAGE_OBJ, swig::LANGUAGE_OBJ, swig::BinaryPredicate<> >;
|
||||
|
||||
2013-04-05: wsfulton
|
||||
[Ruby] SF Bug #1159 - Correctly check rb_respond_to call return values to fix some
|
||||
further 1.9 problems with functors and use of Complex wrappers.
|
||||
|
||||
2013-04-02: wsfulton
|
||||
[Ruby] Runtime fixes for std::complex wrappers for ruby-1.9 - new native Ruby complex numbers are used.
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,12 @@ def _set(container)
|
|||
EOF
|
||||
end
|
||||
|
||||
def b_lessthan_a(b, a)
|
||||
res = b < a
|
||||
# print b, "<", a, "=", res
|
||||
return res
|
||||
end
|
||||
|
||||
def _map(container)
|
||||
swig_assert_each_line(<<EOF, binding)
|
||||
cont = #{container}.new
|
||||
|
|
@ -43,7 +49,7 @@ def _map(container)
|
|||
cont['w'] = 2
|
||||
cont.to_a == [['w',2],['x',8],['y',1],['z',9]]
|
||||
|
||||
cont = #{container}.new(proc { |a,b| b < a } )
|
||||
cont = #{container}.new(proc { |a,b| b_lessthan_a(b, a) } )
|
||||
cont['z'] = 9
|
||||
cont['y'] = 1
|
||||
cont['x'] = 8
|
||||
|
|
|
|||
|
|
@ -172,6 +172,16 @@ namespace swig {
|
|||
return rb_inspect(_obj);
|
||||
}
|
||||
|
||||
static VALUE swig_rescue_funcall( VALUE )
|
||||
{
|
||||
/*
|
||||
VALUE err = rb_errinfo();
|
||||
VALUE errstr = rb_obj_as_string(err);
|
||||
std::cout << "Error is: '" << RSTRING_PTR(StringValue(errstr)) << "'" << std::endl;
|
||||
*/
|
||||
return Qnil;/* Swallow Ruby exception */
|
||||
}
|
||||
|
||||
static VALUE swig_protect_funcall( VALUE p )
|
||||
{
|
||||
OpArgs* args = (OpArgs*) p;
|
||||
|
|
@ -189,16 +199,15 @@ namespace swig {
|
|||
bool res = false; \
|
||||
VALUE ret = Qnil; \
|
||||
SWIG_RUBY_THREAD_BEGIN_BLOCK; \
|
||||
if ( rb_respond_to( _obj, op_id ) == Qtrue ) \
|
||||
if ( rb_respond_to( _obj, op_id ) ) \
|
||||
{ \
|
||||
int status; \
|
||||
OpArgs args; \
|
||||
args.src = _obj; \
|
||||
args.id = op_id; \
|
||||
args.nargs = 1; \
|
||||
args.target = VALUE(other); \
|
||||
ret = rb_protect( PROTECTFUNC(swig_protect_funcall), \
|
||||
VALUE(&args), &status ); \
|
||||
ret = rb_rescue(RUBY_METHOD_FUNC(swig_protect_funcall), VALUE(&args), \
|
||||
(RUBY_METHOD_FUNC(swig_rescue_funcall)), Qnil); \
|
||||
} \
|
||||
if ( ret == Qnil ) { \
|
||||
VALUE a = rb_funcall( _obj, hash_id, 0 ); \
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ VALUE rb_complex_new(VALUE x, VALUE y) {
|
|||
static int SWIG_Is_Complex( VALUE obj ) {
|
||||
static ID real_id = rb_intern("real");
|
||||
static ID imag_id = rb_intern("imag");
|
||||
return ( (rb_respond_to( obj, real_id ) == Qtrue) &&
|
||||
(rb_respond_to( obj, imag_id ) == Qtrue) );
|
||||
return ( (rb_respond_to( obj, real_id ) ) &&
|
||||
(rb_respond_to( obj, imag_id ) ) );
|
||||
}
|
||||
%#else
|
||||
static int SWIG_Is_Complex( VALUE obj ) {
|
||||
|
|
|
|||
|
|
@ -411,7 +411,7 @@ SWIG_Ruby_SetModule(swig_module_info *pointer)
|
|||
SWIGINTERN
|
||||
int SWIG_Ruby_isCallable( VALUE proc )
|
||||
{
|
||||
if ( rb_respond_to( proc, swig_call_id ) == Qtrue )
|
||||
if ( rb_respond_to( proc, swig_call_id ) )
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -424,7 +424,7 @@ int SWIG_Ruby_isCallable( VALUE proc )
|
|||
SWIGINTERN
|
||||
int SWIG_Ruby_arity( VALUE proc, int minimal )
|
||||
{
|
||||
if ( rb_respond_to( proc, swig_arity_id ) == Qtrue )
|
||||
if ( rb_respond_to( proc, swig_arity_id ) )
|
||||
{
|
||||
VALUE num = rb_funcall( proc, swig_arity_id, 0 );
|
||||
int arity = NUM2INT(num);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue