Author: mvidner Date: Mon Oct 3 17:23:22 2011 New Revision: 66198 URL: http://svn.opensuse.org/viewcvs/yast?rev=66198&view=rev Log: Don't raise a Ruby exception when returning to YCP (->segv). Log and return nil. Modified: trunk/ruby-bindings/src/ruby/Y2RubyTypeConv.cc trunk/ruby-bindings/src/ruby/Y2RubyTypeConv.h trunk/ruby-bindings/src/ruby/YRuby.cc Modified: trunk/ruby-bindings/src/ruby/Y2RubyTypeConv.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/Y2RubyTypeConv.cc?rev=66198&r1=66197&r2=66198&view=diff ============================================================================== --- trunk/ruby-bindings/src/ruby/Y2RubyTypeConv.cc (original) +++ trunk/ruby-bindings/src/ruby/Y2RubyTypeConv.cc Mon Oct 3 17:23:22 2011 @@ -45,6 +45,8 @@ #include <ycp/YCPVoid.h> #include <ycp/Import.h> +#include <y2util/stringutil.h> + #include "Y2RubyTypePath.h" #include "Y2RubyTypeTerm.h" @@ -184,7 +186,7 @@ */ YCPValue -rbvalue_2_ycpvalue( VALUE value ) +rbvalue_2_ycpvalue( VALUE value, ConversionFlags flags ) { //VALUE klass = rb_funcall( value, rb_intern("class"), 0); //std::cout << StringValuePtr( rb_funcall( klass, rb_intern("to_s"), 0)) << " | " << StringValuePtr(rb_funcall( value, rb_intern("inspect"), 0)) << std::endl; @@ -229,8 +231,14 @@ { return ryast_yterm_from_rterm(value); } - rb_raise( rb_eTypeError, "Conversion of Ruby type %s not supported", class_name); - return YCPValue(); + + string msg = stringutil::form("Conversion of Ruby type %s not supported", class_name); + if (flags & DONT_RAISE) { + y2error("%s", msg.c_str()); + } else { + rb_raise(rb_eTypeError, msg.c_str()); + } + return YCPVoid(); } } } Modified: trunk/ruby-bindings/src/ruby/Y2RubyTypeConv.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/Y2RubyTypeConv.h?rev=66198&r1=66197&r2=66198&view=diff ============================================================================== --- trunk/ruby-bindings/src/ruby/Y2RubyTypeConv.h (original) +++ trunk/ruby-bindings/src/ruby/Y2RubyTypeConv.h Mon Oct 3 17:23:22 2011 @@ -32,12 +32,17 @@ extern "C" VALUE ycpvalue_2_rbvalue( YCPValue ycpval ); +enum ConversionFlags { + NONE, + DONT_RAISE, +}; + /** * Converts a Ruby Value into a YCPValue * Supports neested lists and maps using recursion. */ YCPValue -rbvalue_2_ycpvalue( VALUE value ); +rbvalue_2_ycpvalue( VALUE value, ConversionFlags flags = NONE); /** Modified: trunk/ruby-bindings/src/ruby/YRuby.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/YRuby.cc?rev=66198&r1=66197&r2=66198&view=diff ============================================================================== --- trunk/ruby-bindings/src/ruby/YRuby.cc (original) +++ trunk/ruby-bindings/src/ruby/YRuby.cc Mon Oct 3 17:23:22 2011 @@ -222,6 +222,6 @@ //VALUE result = rb_funcall( module, rb_intern(function.c_str()), 2, INT2NUM(2), INT2NUM(3) ); y2milestone( "Called function '%s' in module '%s'", function.c_str(), module_name.c_str()); } - return rbvalue_2_ycpvalue(result); + return rbvalue_2_ycpvalue(result, DONT_RAISE); } -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org