ruby-changes:30807
From: suke <ko1@a...>
Date: Sun, 8 Sep 2013 14:06:27 +0900 (JST)
Subject: [ruby-changes:30807] suke:r42886 (trunk): * ext/win32ole/win32ole.c (folevariant_initialize): check type of
suke 2013-09-08 14:06:20 +0900 (Sun, 08 Sep 2013) New Revision: 42886 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42886 Log: * ext/win32ole/win32ole.c (folevariant_initialize): check type of element of array. * test/win32ole/test_win32ole_variant.rb (test_s_new_ary): ditto. Modified files: trunk/ChangeLog trunk/ext/win32ole/win32ole.c trunk/test/win32ole/test_win32ole_variant.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 42885) +++ ChangeLog (revision 42886) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sun Sep 8 13:56:38 2013 Masaki Suketa <masaki.suketa@n...> + + * ext/win32ole/win32ole.c (folevariant_initialize): check type of + element of array. + + * test/win32ole/test_win32ole_variant.rb (test_s_new_ary): ditto. + Sat Sep 7 21:33:10 2013 Tanaka Akira <akr@f...> * math.c (math_log): Test the sign for bignums. Index: ext/win32ole/win32ole.c =================================================================== --- ext/win32ole/win32ole.c (revision 42885) +++ ext/win32ole/win32ole.c (revision 42886) @@ -143,7 +143,7 @@ const IID IID_IMultiLanguage2 = {0xDCCFC https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L143 #define WC2VSTR(x) ole_wc2vstr((x), TRUE) -#define WIN32OLE_VERSION "1.5.4" +#define WIN32OLE_VERSION "1.5.5" typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX) (REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*); @@ -584,6 +584,7 @@ static VALUE evs_length(void); https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L584 static void olevariant_free(struct olevariantdata *pvar); static VALUE folevariant_s_allocate(VALUE klass); static VALUE folevariant_s_array(VALUE klass, VALUE dims, VALUE vvt); +static void check_type_val2variant(VALUE val); static VALUE folevariant_initialize(VALUE self, VALUE args); static long *ary2safe_array_index(int ary_size, VALUE *ary, SAFEARRAY *psa); static void unlock_safe_array(SAFEARRAY *psa); @@ -8744,6 +8745,38 @@ folevariant_s_array(VALUE klass, VALUE e https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L8745 return obj; } +static void +check_type_val2variant(VALUE val) +{ + VALUE elem; + int len = 0; + int i = 0; + if(!rb_obj_is_kind_of(val, cWIN32OLE) && + !rb_obj_is_kind_of(val, cWIN32OLE_VARIANT) && + !rb_obj_is_kind_of(val, rb_cTime)) { + switch (TYPE(val)) { + case T_ARRAY: + len = RARRAY_LEN(val); + for(i = 0; i < len; i++) { + elem = rb_ary_entry(val, i); + check_type_val2variant(elem); + } + break; + case T_STRING: + case T_FIXNUM: + case T_BIGNUM: + case T_FLOAT: + case T_TRUE: + case T_FALSE: + case T_NIL: + break; + default: + rb_raise(rb_eTypeError, "can not convert WIN32OLE_VARIANT from type %s", + rb_obj_classname(val)); + } + } +} + /* * call-seq: * WIN32OLE_VARIANT.new(val, vartype) #=> WIN32OLE_VARIANT object. @@ -8779,24 +8812,7 @@ folevariant_initialize(VALUE self, VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L8812 VariantInit(&var); val = rb_ary_entry(args, 0); - if(!rb_obj_is_kind_of(val, cWIN32OLE) && - !rb_obj_is_kind_of(val, cWIN32OLE_VARIANT) && - !rb_obj_is_kind_of(val, rb_cTime)) { - switch (TYPE(val)) { - case T_ARRAY: - case T_STRING: - case T_FIXNUM: - case T_BIGNUM: - case T_FLOAT: - case T_TRUE: - case T_FALSE: - case T_NIL: - break; - default: - rb_raise(rb_eTypeError, "can not convert WIN32OLE_VARIANT from type %s", - rb_obj_classname(val)); - } - } + check_type_val2variant(val); Data_Get_Struct(self, struct olevariantdata, pvar); if (len == 1) { Index: test/win32ole/test_win32ole_variant.rb =================================================================== --- test/win32ole/test_win32ole_variant.rb (revision 42885) +++ test/win32ole/test_win32ole_variant.rb (revision 42886) @@ -27,6 +27,14 @@ if defined?(WIN32OLE_VARIANT) https://github.com/ruby/ruby/blob/trunk/test/win32ole/test_win32ole_variant.rb#L27 } end + def test_s_new_ary + obj = WIN32OLE_VARIANT.new([1]) + assert_instance_of(WIN32OLE_VARIANT, obj) + assert_raise(TypeError) { + WIN32OLE_VARIANT.new([/foo/]) + } + end + def test_s_new_no_argument ex = nil begin -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/