[前][次][番号順一覧][スレッド一覧]

ruby-changes:35350

From: suke <ko1@a...>
Date: Sat, 6 Sep 2014 16:52:18 +0900 (JST)
Subject: [ruby-changes:35350] suke:r47432 (trunk): * ext/win32ole/win32ole_variant.c (ole_val2variant_err,

suke	2014-09-06 16:52:04 +0900 (Sat, 06 Sep 2014)

  New Revision: 47432

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47432

  Log:
    * ext/win32ole/win32ole_variant.c (ole_val2variant_err,
      ole_val2variantdata, Init_win32ole_variant): support VT_ERROR
      variant with error code. add WIN32OLE_VARIANT::NoParam.
    * test/win32ole/test_win32ole_variant.rb(test_c_noparam,
      test_vt_error_noparam): ditto.
    * ext/win32ole/win32ole.c: ditto.

  Modified files:
    trunk/ChangeLog
    trunk/ext/win32ole/win32ole.c
    trunk/ext/win32ole/win32ole_variant.c
    trunk/test/win32ole/test_win32ole_variant.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47431)
+++ ChangeLog	(revision 47432)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Sep  6 16:38:08 2014  Masaki Suketa <masaki.suketa@n...>
+
+	* ext/win32ole/win32ole_variant.c (ole_val2variant_err,
+	  ole_val2variantdata, Init_win32ole_variant): support VT_ERROR
+	  variant with error code. add WIN32OLE_VARIANT::NoParam.
+	* test/win32ole/test_win32ole_variant.rb(test_c_noparam,
+	  test_vt_error_noparam): ditto.
+	* ext/win32ole/win32ole.c: ditto.
+
 Sat Sep  6 11:08:52 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* parse.y (arg_ambiguous_gen): fix warning message, "even" does
Index: ext/win32ole/win32ole.c
===================================================================
--- ext/win32ole/win32ole.c	(revision 47431)
+++ ext/win32ole/win32ole.c	(revision 47432)
@@ -26,7 +26,7 @@ https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L26
 const IID IID_IMultiLanguage2 = {0xDCCFC164, 0x2B38, 0x11d2, {0xB7, 0xEC, 0x00, 0xC0, 0x4F, 0x8F, 0x5D, 0x9A}};
 #endif
 
-#define WIN32OLE_VERSION "1.8.0"
+#define WIN32OLE_VERSION "1.8.1"
 
 typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX)
     (REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*);
Index: ext/win32ole/win32ole_variant.c
===================================================================
--- ext/win32ole/win32ole_variant.c	(revision 47431)
+++ ext/win32ole/win32ole_variant.c	(revision 47432)
@@ -2,6 +2,7 @@ https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_variant.c#L2
 
 static void  olevariant_free(struct olevariantdata *pvar);
 static void ole_val2olevariantdata(VALUE val, VARTYPE vt, struct olevariantdata *pvar);
+static void ole_val2variant_err(VALUE val, VARIANT *var);
 static void ole_set_byref(VARIANT *realvar, VARIANT *var,  VARTYPE vt);
 static VALUE folevariant_s_allocate(VALUE klass);
 static VALUE folevariant_s_array(VALUE klass, VALUE dims, VALUE vvt);
@@ -83,6 +84,13 @@ ole_val2olevariantdata(VALUE val, VARTYP https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_variant.c#L84
             ole_set_byref(&(pvar->realvar), &(pvar->var), vt);
         }
 #endif
+    } else if ( (vt & ~VT_BYREF) == VT_ERROR) {
+        ole_val2variant_err(val, &(pvar->realvar));
+        if (vt & VT_BYREF) {
+            ole_set_byref(&(pvar->realvar), &(pvar->var), vt);
+        } else {
+            hr = VariantCopy(&(pvar->var), &(pvar->realvar));
+        }
     } else {
         if (val == Qnil) {
             V_VT(&(pvar->var)) = vt;
@@ -122,6 +130,24 @@ ole_val2olevariantdata(VALUE val, VARTYP https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_variant.c#L130
 }
 
 static void
+ole_val2variant_err(VALUE val, VARIANT *var)
+{
+    VALUE v = val;
+    if (rb_obj_is_kind_of(v, cWIN32OLE_VARIANT)) {
+        v = folevariant_value(v);
+    }
+    if (TYPE(v) != T_FIXNUM && TYPE(v) != T_BIGNUM && v != Qnil) {
+        rb_raise(eWIN32OLERuntimeError, "failed to convert VT_ERROR VARIANT:`%"PRIsVALUE"'", rb_inspect(v));
+    }
+    V_VT(var) = VT_ERROR;
+    if (v != Qnil) {
+        V_ERROR(var) = NUM2LONG(val);
+    } else {
+        V_ERROR(var) = 0;
+    }
+}
+
+static void
 ole_set_byref(VARIANT *realvar, VARIANT *var,  VARTYPE vt)
 {
     V_VT(var) = vt;
@@ -654,15 +680,28 @@ Init_win32ole_variant() https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_variant.c#L680
     /*
      * represents VT_EMPTY OLE object.
      */
-    rb_define_const(cWIN32OLE_VARIANT, "Empty", rb_funcall(cWIN32OLE_VARIANT, rb_intern("new"), 2, Qnil, INT2FIX(VT_EMPTY)));
+    rb_define_const(cWIN32OLE_VARIANT, "Empty",
+            rb_funcall(cWIN32OLE_VARIANT, rb_intern("new"), 2, Qnil, INT2FIX(VT_EMPTY)));
 
     /*
      * represents VT_NULL OLE object.
      */
-    rb_define_const(cWIN32OLE_VARIANT, "Null", rb_funcall(cWIN32OLE_VARIANT, rb_intern("new"), 2, Qnil, INT2FIX(VT_NULL)));
+    rb_define_const(cWIN32OLE_VARIANT, "Null",
+            rb_funcall(cWIN32OLE_VARIANT, rb_intern("new"), 2, Qnil, INT2FIX(VT_NULL)));
 
     /*
      * represents Nothing of VB.NET or VB.
      */
-    rb_define_const(cWIN32OLE_VARIANT, "Nothing", rb_funcall(cWIN32OLE_VARIANT, rb_intern("new"), 2, Qnil, INT2FIX(VT_DISPATCH)));
+    rb_define_const(cWIN32OLE_VARIANT, "Nothing",
+            rb_funcall(cWIN32OLE_VARIANT, rb_intern("new"), 2, Qnil, INT2FIX(VT_DISPATCH)));
+
+    /*
+     * represents VT_ERROR variant with DISP_E_PARAMNOTFOUND.
+     * This constants is used for not specified parameter.
+     *
+     *  fso = WIN32OLE.new("Scripting.FileSystemObject")
+     *  fso.openTextFile(filename, WIN32OLE_VARIANT::NoParam, false)
+     */
+    rb_define_const(cWIN32OLE_VARIANT, "NoParam",
+            rb_funcall(cWIN32OLE_VARIANT, rb_intern("new"), 2, INT2NUM(DISP_E_PARAMNOTFOUND), INT2FIX(VT_ERROR)));
 }
Index: test/win32ole/test_win32ole_variant.rb
===================================================================
--- test/win32ole/test_win32ole_variant.rb	(revision 47431)
+++ test/win32ole/test_win32ole_variant.rb	(revision 47432)
@@ -679,6 +679,34 @@ if defined?(WIN32OLE_VARIANT) https://github.com/ruby/ruby/blob/trunk/test/win32ole/test_win32ole_variant.rb#L679
       assert_nil(WIN32OLE_VARIANT::Null.value)
     end
 
+    def test_c_noparam
+      # DISP_E_PARAMNOTFOUND
+      assert_equal(-2147352572, WIN32OLE_VARIANT::NoParam.value)
+    end
+
+    def test_vt_error_noparam
+      v = WIN32OLE_VARIANT.new(-1, WIN32OLE::VARIANT::VT_ERROR)
+      assert_equal(-1, v.value)
+      fso = WIN32OLE.new("Scripting.FileSystemObject")
+      exc = assert_raise(WIN32OLERuntimeError) {
+        fso.openTextFile("NonExistingFile", v, false)
+      }
+      assert_match(/Type mismatch/i, exc.message)
+      exc = assert_raise(WIN32OLERuntimeError) {
+        fso.openTextFile("NonExistingFile", WIN32OLE_VARIANT::NoParam, false)
+      }
+      # 800A0035 is 'file not found' error.
+      assert_match(/800A0035/, exc.message)
+
+      # -2147352572 is DISP_E_PARAMNOTFOUND
+      v = WIN32OLE_VARIANT.new(-2147352572, WIN32OLE::VARIANT::VT_ERROR)
+      exc = assert_raise(WIN32OLERuntimeError) {
+        fso.openTextFile("NonExistingFile", WIN32OLE_VARIANT::NoParam, false)
+      }
+      # 800A0035 is 'file not found' error code.
+      assert_match(/800A0035/, exc.message)
+    end
+
   end
 end
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]