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

ruby-changes:34998

From: suke <ko1@a...>
Date: Wed, 6 Aug 2014 18:47:52 +0900 (JST)
Subject: [ruby-changes:34998] suke:r47080 (trunk): * ext/win32ole/win32ole.c: separate src of WIN32OLERuntimeError

suke	2014-08-06 18:47:39 +0900 (Wed, 06 Aug 2014)

  New Revision: 47080

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

  Log:
    * ext/win32ole/win32ole.c: separate src of WIN32OLERuntimeError
      from win32ole.c.
    
    * ext/win32ole/win32ole.h: ditto
    * ext/win32ole/depend: ditto.
    * ext/win32ole/win32ole_error.c: ditto.
    * ext/win32ole/win32ole_error.h: ditto.

  Added files:
    trunk/ext/win32ole/win32ole_error.c
    trunk/ext/win32ole/win32ole_error.h
  Modified files:
    trunk/ChangeLog
    trunk/ext/win32ole/depend
    trunk/ext/win32ole/win32ole.c
    trunk/ext/win32ole/win32ole.h
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47079)
+++ ChangeLog	(revision 47080)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Aug  6 18:42:58 2014  Masaki Suketa <masaki.suketa@n...>
+
+	* ext/win32ole/win32ole.c: separate src of WIN32OLERuntimeError
+	  from win32ole.c.
+
+	* ext/win32ole/win32ole.h: ditto
+	* ext/win32ole/depend: ditto.
+	* ext/win32ole/win32ole_error.c: ditto.
+	* ext/win32ole/win32ole_error.h: ditto.
+
 Wed Aug  6 04:33:58 2014  NARUSE, Yui  <naruse@r...>
 
 	* lib/net/http.rb (Net::HTTP.proxy_uri): use initializer instead
Index: ext/win32ole/depend
===================================================================
--- ext/win32ole/depend	(revision 47079)
+++ ext/win32ole/depend	(revision 47080)
@@ -1,3 +1,4 @@ https://github.com/ruby/ruby/blob/trunk/ext/win32ole/depend#L1
 WIN32OLE_HEADERS = $(HDRS) $(ruby_headers)
 win32ole.o : win32ole.c $(WIN32OLE_HEADERS)
 win32ole_variant_m.o : win32ole_variant_m.c $(WIN32OLE_HEADERS)
+win32ole_error.o : win32ole_error.c $(WIN32OLE_HEADERS)
Index: ext/win32ole/win32ole_error.h
===================================================================
--- ext/win32ole/win32ole_error.h	(revision 0)
+++ ext/win32ole/win32ole_error.h	(revision 47080)
@@ -0,0 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_error.h#L1
+#ifndef WIN32OLE_ERROR_H
+#define WIN32OLE_ERROR_H 1
+
+VALUE eWIN32OLERuntimeError;
+void ole_raise(HRESULT hr, VALUE ecs, const char *fmt, ...);
+void Init_win32ole_error();
+
+#endif
Index: ext/win32ole/win32ole.c
===================================================================
--- ext/win32ole/win32ole.c	(revision 47079)
+++ ext/win32ole/win32ole.c	(revision 47080)
@@ -128,7 +128,6 @@ VALUE cWIN32OLE_METHOD; https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L128
 VALUE cWIN32OLE_PARAM;
 VALUE cWIN32OLE_EVENT;
 VALUE cWIN32OLE_VARIANT;
-VALUE eWIN32OLERuntimeError;
 VALUE cWIN32OLE_PROPERTY;
 VALUE cWIN32OLE_RECORD;
 
@@ -153,7 +152,6 @@ static FNCOCREATEINSTANCEEX *gCoCreateIn https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L152
 static VALUE com_hash;
 static IDispatchVtbl com_vtbl;
 static UINT cWIN32OLE_cp = CP_ACP;
-static LCID cWIN32OLE_lcid = LOCALE_SYSTEM_DEFAULT;
 static rb_encoding *cWIN32OLE_enc;
 static UINT g_cp_to_check = CP_ACP;
 static char g_lcid_to_check[8 + 1];
@@ -239,10 +237,8 @@ static void load_conv_function51932(void https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L237
 #endif
 static UINT ole_init_cp(void);
 static char *ole_wc2mb(LPWSTR pw);
-static VALUE ole_hresult2msg(HRESULT hr);
 static void ole_freeexceptinfo(EXCEPINFO *pExInfo);
 static VALUE ole_excepinfo2msg(EXCEPINFO *pExInfo);
-static void ole_raise(HRESULT hr, VALUE ecs, const char *fmt, ...);
 static void ole_initialize(void);
 static void ole_msg_loop(void);
 static void ole_free(struct oledata *pole);
@@ -1055,46 +1051,6 @@ ole_wc2mb(LPWSTR pw) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L1051
     return ole_wc2mb_alloc(pw, ole_alloc_str, NULL);
 }
 
-static VALUE
-ole_hresult2msg(HRESULT hr)
-{
-    VALUE msg = Qnil;
-    char *p_msg = NULL;
-    char *term = NULL;
-    DWORD dwCount;
-
-    char strhr[100];
-    sprintf(strhr, "    HRESULT error code:0x%08x\n      ", (unsigned)hr);
-    msg = rb_str_new2(strhr);
-    dwCount = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
-                            FORMAT_MESSAGE_FROM_SYSTEM |
-                            FORMAT_MESSAGE_IGNORE_INSERTS,
-                            NULL, hr,
-                            MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
-                            (LPTSTR)&p_msg, 0, NULL);
-    if (dwCount == 0) {
-        dwCount = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
-                                FORMAT_MESSAGE_FROM_SYSTEM |
-                                FORMAT_MESSAGE_IGNORE_INSERTS,
-                                NULL, hr, cWIN32OLE_lcid,
-                                (LPTSTR)&p_msg, 0, NULL);
-    }
-    if (dwCount > 0) {
-	term = p_msg + strlen(p_msg);
-	while (p_msg < term) {
-	    term--;
-	    if (*term == '\r' || *term == '\n')
-	        *term = '\0';
-	    else break;
-	}
-        if (p_msg[0] != '\0') {
-            rb_str_cat2(msg, p_msg);
-        }
-    }
-    LocalFree(p_msg);
-    return msg;
-}
-
 static void
 ole_freeexceptinfo(EXCEPINFO *pExInfo)
 {
@@ -1145,24 +1101,6 @@ ole_excepinfo2msg(EXCEPINFO *pExInfo) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L1101
     return error_msg;
 }
 
-static void
-ole_raise(HRESULT hr, VALUE ecs, const char *fmt, ...)
-{
-    va_list args;
-    VALUE msg;
-    VALUE err_msg;
-    va_init_list(args, fmt);
-    msg = rb_vsprintf(fmt, args);
-    va_end(args);
-
-    err_msg = ole_hresult2msg(hr);
-    if(err_msg != Qnil) {
-	rb_str_cat2(msg, "\n");
-	rb_str_append(msg, err_msg);
-    }
-    rb_exc_raise(rb_exc_new_str(ecs, msg));
-}
-
 void
 ole_uninitialize(void)
 {
@@ -9676,6 +9614,7 @@ free_enc2cp(void) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L9614
 void
 Init_win32ole(void)
 {
+    cWIN32OLE_lcid = LOCALE_SYSTEM_DEFAULT;
     g_ole_initialized_init();
     ary_ole_event = rb_ary_new();
     rb_gc_register_mark_object(ary_ole_event);
@@ -9972,23 +9911,7 @@ Init_win32ole(void) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L9911
     rb_define_method(cWIN32OLE_RECORD, "ole_instance_variable_set", folerecord_ole_instance_variable_set, 2);
     rb_define_method(cWIN32OLE_RECORD, "inspect", folerecord_inspect, 0);
 
-    /*
-     * Document-class: WIN32OLERuntimeError
-     *
-     * Raised when OLE processing failed.
-     *
-     * EX:
-     *
-     *   obj = WIN32OLE.new("NonExistProgID")
-     *
-     * raises the exception:
-     *
-     *   WIN32OLERuntimeError: unknown OLE server: `NonExistProgID'
-     *       HRESULT error code:0x800401f3
-     *         Invalid class string
-     *
-     */
-    eWIN32OLERuntimeError = rb_define_class("WIN32OLERuntimeError", rb_eRuntimeError);
+    Init_win32ole_error();
 
     init_enc2cp();
     atexit((void (*)(void))free_enc2cp);
Index: ext/win32ole/win32ole.h
===================================================================
--- ext/win32ole/win32ole.h	(revision 47079)
+++ ext/win32ole/win32ole.h	(revision 47080)
@@ -35,11 +35,11 @@ https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.h#L35
 #endif
 #include <objidl.h>
 
-#define DOUT fprintf(stderr,"[%d]\n",__LINE__)
-#define DOUTS(x) fprintf(stderr,"[%d]:" #x "=%s\n",__LINE__,x)
-#define DOUTMSG(x) fprintf(stderr, "[%d]:" #x "\n",__LINE__)
-#define DOUTI(x) fprintf(stderr, "[%ld]:" #x "=%d\n",__LINE__,x)
-#define DOUTD(x) fprintf(stderr, "[%d]:" #x "=%f\n",__LINE__,x)
+#define DOUT fprintf(stderr,"%s(%d)\n", __FILE__, __LINE__)
+#define DOUTS(x) fprintf(stderr,"%s(%d):" #x "=%s\n",__FILE__, __LINE__,x)
+#define DOUTMSG(x) fprintf(stderr, "%s(%d):" #x "\n",__FILE__, __LINE__)
+#define DOUTI(x) fprintf(stderr, "%s(%d):" #x "=%d\n",__FILE__, __LINE__,x)
+#define DOUTD(x) fprintf(stderr, "%s(%d):" #x "=%f\n",__FILE__, __LINE__,x)
 
 #if (defined(__GNUC__)) && (GNUC_OLDER_3_4_4)
 #define V_UNION1(X, Y) ((X)->u.Y)
@@ -85,6 +85,9 @@ https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.h#L85
 
 VALUE cWIN32OLE;
 
+LCID cWIN32OLE_lcid;
+
 #include "win32ole_variant_m.h"
+#include "win32ole_error.h"
 
 #endif
Index: ext/win32ole/win32ole_error.c
===================================================================
--- ext/win32ole/win32ole_error.c	(revision 0)
+++ ext/win32ole/win32ole_error.c	(revision 47080)
@@ -0,0 +1,82 @@ https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_error.c#L1
+#include "win32ole.h"
+
+static VALUE ole_hresult2msg(HRESULT hr);
+
+static VALUE
+ole_hresult2msg(HRESULT hr)
+{
+    VALUE msg = Qnil;
+    char *p_msg = NULL;
+    char *term = NULL;
+    DWORD dwCount;
+
+    char strhr[100];
+    sprintf(strhr, "    HRESULT error code:0x%08x\n      ", (unsigned)hr);
+    msg = rb_str_new2(strhr);
+    dwCount = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+                            FORMAT_MESSAGE_FROM_SYSTEM |
+                            FORMAT_MESSAGE_IGNORE_INSERTS,
+                            NULL, hr,
+                            MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
+                            (LPTSTR)&p_msg, 0, NULL);
+    if (dwCount == 0) {
+        dwCount = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+                                FORMAT_MESSAGE_FROM_SYSTEM |
+                                FORMAT_MESSAGE_IGNORE_INSERTS,
+                                NULL, hr, cWIN32OLE_lcid,
+                                (LPTSTR)&p_msg, 0, NULL);
+    }
+    if (dwCount > 0) {
+        term = p_msg + strlen(p_msg);
+        while (p_msg < term) {
+            term--;
+            if (*term == '\r' || *term == '\n')
+                *term = '\0';
+            else break;
+        }
+        if (p_msg[0] != '\0') {
+            rb_str_cat2(msg, p_msg);
+        }
+    }
+    LocalFree(p_msg);
+    return msg;
+}
+
+void
+ole_raise(HRESULT hr, VALUE ecs, const char *fmt, ...)
+{
+    va_list args;
+    VALUE msg;
+    VALUE err_msg;
+    va_init_list(args, fmt);
+    msg = rb_vsprintf(fmt, args);
+    va_end(args);
+
+    err_msg = ole_hresult2msg(hr);
+    if(err_msg != Qnil) {
+        rb_str_cat2(msg, "\n");
+        rb_str_append(msg, err_msg);
+    }
+    rb_exc_raise(rb_exc_new_str(ecs, msg));
+}
+
+void 
+Init_win32ole_error() {
+    /*
+     * Document-class: WIN32OLERuntimeError
+     *
+     * Raised when OLE processing failed.
+     *
+     * EX:
+     *
+     *   obj = WIN32OLE.new("NonExistProgID")
+     *
+     * raises the exception:
+     *
+     *   WIN32OLERuntimeError: unknown OLE server: `NonExistProgID'
+     *       HRESULT error code:0x800401f3
+     *         Invalid class string
+     *
+     */
+    eWIN32OLERuntimeError = rb_define_class("WIN32OLERuntimeError", rb_eRuntimeError);
+}

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

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