From d0af6fd97d981b548ac37782763f0913eb8aaac8 Mon Sep 17 00:00:00 2001 From: Takashi Tamura Date: Mon, 6 Mar 2017 15:13:05 +0900 Subject: [PATCH] [ruby] must not do null check for VALUE obj, which can be 0x0 == Qfalse, a valid Ruby object. --- Examples/test-suite/ruby/std_containers_runme.rb | 2 ++ Examples/test-suite/std_containers.i | 4 ++++ Lib/ruby/rubyrun.swg | 2 +- Lib/ruby/rubystdcommon.swg | 10 +++++----- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Examples/test-suite/ruby/std_containers_runme.rb b/Examples/test-suite/ruby/std_containers_runme.rb index 73d443218..65a8b5b86 100644 --- a/Examples/test-suite/ruby/std_containers_runme.rb +++ b/Examples/test-suite/ruby/std_containers_runme.rb @@ -13,6 +13,8 @@ require 'swig_assert' require 'std_containers' include Std_containers +swig_assert_equal("[true, false]", "videntb([true, false])") + swig_assert_each_line(<<'EOF', binding) cube = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] diff --git a/Examples/test-suite/std_containers.i b/Examples/test-suite/std_containers.i index ae69b6418..80409a1f0 100644 --- a/Examples/test-suite/std_containers.i +++ b/Examples/test-suite/std_containers.i @@ -115,6 +115,10 @@ return v; } + std::vector videntb(const std::vector& v) + { + return v; + } int get_elem(const std::vector& v, int index) { diff --git a/Lib/ruby/rubyrun.swg b/Lib/ruby/rubyrun.swg index 249494ab0..94618db4e 100644 --- a/Lib/ruby/rubyrun.swg +++ b/Lib/ruby/rubyrun.swg @@ -246,7 +246,7 @@ typedef struct { SWIGRUNTIME swig_ruby_owntype SWIG_Ruby_AcquirePtr(VALUE obj, swig_ruby_owntype own) { swig_ruby_owntype oldown = {0, 0}; - if (obj) { + if (TYPE(obj) == T_DATA) { oldown.datafree = RDATA(obj)->dfree; RDATA(obj)->dfree = own.datafree; } diff --git a/Lib/ruby/rubystdcommon.swg b/Lib/ruby/rubystdcommon.swg index f72745b56..e32f46d1c 100644 --- a/Lib/ruby/rubystdcommon.swg +++ b/Lib/ruby/rubystdcommon.swg @@ -117,7 +117,7 @@ namespace swig { static Type as(VALUE obj, bool throw_error) { Type v; int res = asval(obj, &v); - if (!obj || !SWIG_IsOK(res)) { + if (!SWIG_IsOK(res)) { if (throw_error) throw std::invalid_argument("bad type"); VALUE lastErr = rb_gv_get("$!"); if (lastErr == Qnil) { @@ -132,7 +132,7 @@ namespace swig { struct traits_as { static Type as(VALUE obj, bool throw_error) { Type *v = 0; - int res = (obj ? traits_asptr::asptr(obj, &v) : SWIG_ERROR); + int res = traits_asptr::asptr(obj, &v); if (SWIG_IsOK(res) && v) { if (SWIG_IsNewObj(res)) { Type r(*v); @@ -159,7 +159,7 @@ namespace swig { struct traits_as { static Type* as(VALUE obj, bool throw_error) { Type *v = 0; - int res = (obj ? traits_asptr::asptr(obj, &v) : SWIG_ERROR); + int res = traits_asptr::asptr(obj, &v); if (SWIG_IsOK(res)) { return v; } else { @@ -181,7 +181,7 @@ namespace swig { template struct traits_check { static bool check(VALUE obj) { - int res = obj ? asval(obj, (Type *)(0)) : SWIG_ERROR; + int res = asval(obj, (Type *)(0)); return SWIG_IsOK(res) ? true : false; } }; @@ -189,7 +189,7 @@ namespace swig { template struct traits_check { static bool check(VALUE obj) { - int res = obj ? asptr(obj, (Type **)(0)) : SWIG_ERROR; + int res = asptr(obj, (Type **)(0)); return SWIG_IsOK(res) ? true : false; } };