From 5aaf3003b63a19e4a772c6c17fa8407a42ccdaaf Mon Sep 17 00:00:00 2001 From: Gonzalo Garramuno Date: Sun, 20 May 2007 15:23:43 +0000 Subject: [PATCH] Added a partial specialization for swig::GC_VALUE to avoid the need to check each element in the container during copy constructors. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9828 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/ruby/rubycontainer.swg | 42 +++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/Lib/ruby/rubycontainer.swg b/Lib/ruby/rubycontainer.swg index 8c9a9df1c..814086807 100644 --- a/Lib/ruby/rubycontainer.swg +++ b/Lib/ruby/rubycontainer.swg @@ -400,7 +400,7 @@ namespace swig bool check(bool set_err = true) const { - int s = size(); + int s = (int) size(); for (int i = 0; i < s; ++i) { VALUE item = rb_ary_entry(_seq, i ); if (!swig::check(item)) { @@ -1072,6 +1072,46 @@ namespace swig { } }; + // Partial specialization for GC_VALUE's. No need to typecheck each + // element. + template< class Seq > + struct traits_asptr_stdseq< Seq, swig::GC_VALUE > { + typedef Seq sequence; + typedef swig::GC_VALUE value_type; + + static int asptr(VALUE obj, sequence **seq) { + if (rb_obj_is_kind_of(obj, rb_cArray) == Qtrue) { + try { + if (seq) { + RubySequence_Cont rubyseq(obj); + sequence *pseq = new sequence(); + assign(rubyseq, pseq); + *seq = pseq; + return SWIG_NEWOBJ; + } else { + return true; + } + } catch (std::exception& e) { + if (seq) { + VALUE lastErr = rb_gv_get("$!"); + if (lastErr == Qnil) { + rb_raise(rb_eTypeError, e.what()); + } + } + return SWIG_ERROR; + } + } else { + sequence *p; + if (SWIG_ConvertPtr(obj,(void**)&p, + swig::type_info(),0) == SWIG_OK) { + if (seq) *seq = p; + return SWIG_OLDOBJ; + } + } + return SWIG_ERROR; + } + }; + template struct traits_from_stdseq { typedef Seq sequence;