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

ruby-changes:37414

From: suke <ko1@a...>
Date: Wed, 4 Feb 2015 20:30:52 +0900 (JST)
Subject: [ruby-changes:37414] suke:r49495 (trunk): * ext/win32ole/win32ole.c (Init_win32ole): should not use atexit to

suke	2015-02-04 20:30:37 +0900 (Wed, 04 Feb 2015)

  New Revision: 49495

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

  Log:
    * ext/win32ole/win32ole.c (Init_win32ole): should not use atexit to
      free allocated hash table to avoid error on Cygwin.

  Modified files:
    trunk/ChangeLog
    trunk/ext/win32ole/win32ole.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 49494)
+++ ChangeLog	(revision 49495)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Feb  4 20:26:54 2015  Masaki Suketa <masaki.suketa@n...>
+
+	* ext/win32ole/win32ole.c (Init_win32ole): should not use atexit to
+	  free allocated hash table to avoid error on Cygwin.
+
 Wed Feb  4 15:34:25 2015  Shugo Maeda  <shugo@r...>
 
 	* class.c (method_entry_i, class_instance_method_list,
Index: ext/win32ole/win32ole.c
===================================================================
--- ext/win32ole/win32ole.c	(revision 49494)
+++ ext/win32ole/win32ole.c	(revision 49495)
@@ -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.3"
+#define WIN32OLE_VERSION "1.8.4"
 
 typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX)
     (REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*);
@@ -54,13 +54,13 @@ static HINSTANCE ghhctrl = NULL; https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L54
 static HINSTANCE gole32 = NULL;
 static FNCOCREATEINSTANCEEX *gCoCreateInstanceEx = NULL;
 static VALUE com_hash;
+static VALUE enc2cp_hash;
 static IDispatchVtbl com_vtbl;
 static UINT cWIN32OLE_cp = CP_ACP;
 static rb_encoding *cWIN32OLE_enc;
 static UINT g_cp_to_check = CP_ACP;
 static char g_lcid_to_check[8 + 1];
 static VARTYPE g_nil_to = VT_ERROR;
-static st_table *enc2cp_table;
 static IMessageFilterVtbl message_filter;
 static IMessageFilter imessage_filter = { &message_filter };
 static IMessageFilter* previous_filter;
@@ -166,9 +166,6 @@ static VALUE ole_ptrtype2val(ITypeInfo * https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L166
 static VALUE fole_method_help(VALUE self, VALUE cmdname);
 static VALUE fole_activex_initialize(VALUE self);
 
-static void init_enc2cp(void);
-static void free_enc2cp(void);
-
 static void com_hash_free(void *ptr);
 static void com_hash_mark(void *ptr);
 static size_t com_hash_size(const void *ptr);
@@ -179,8 +176,8 @@ static const rb_data_type_t ole_datatype https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L176
     0, 0, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
-static const rb_data_type_t com_hash_datatype = {
-    "com_hash",
+static const rb_data_type_t win32ole_hash_datatype = {
+    "win32ole_hash",
     {com_hash_mark, com_hash_free, com_hash_size,},
     0, 0, RUBY_TYPED_FREE_IMMEDIATELY
 };
@@ -859,10 +856,11 @@ ole_vstr2wc(VALUE vstr) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L856
     UINT size = 0;
     LPWSTR pw;
     st_data_t data;
+    struct st_table *tbl = DATA_PTR(enc2cp_hash);
     enc = rb_enc_get(vstr);
 
-    if (st_lookup(enc2cp_table, (st_data_t)enc, &data)) {
-        cp = (int)data;
+    if (st_lookup(tbl, (VALUE)enc | FIXNUM_FLAG, &data)) {
+        cp = FIX2INT((VALUE)data);
     } else {
         cp = ole_encoding2cp(enc);
         if (code_page_installed(cp) ||
@@ -874,7 +872,7 @@ ole_vstr2wc(VALUE vstr) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L872
             cp == CP_UTF7 ||
             cp == CP_UTF8 ||
             cp == 51932) {
-            st_insert(enc2cp_table, (st_data_t)enc, (st_data_t)cp);
+            st_insert(tbl, (VALUE)enc | FIXNUM_FLAG, INT2FIX(cp));
         } else {
             rb_raise(eWIN32OLERuntimeError, "not installed Windows codepage(%d) according to `%s'", cp, rb_enc_name(enc));
         }
@@ -3870,18 +3868,6 @@ typelib_from_val(VALUE obj, ITypeLib **p https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L3868
 }
 
 static void
-init_enc2cp(void)
-{
-    enc2cp_table = st_init_numtable();
-}
-
-static void
-free_enc2cp(void)
-{
-    st_free_table(enc2cp_table);
-}
-
-static void
 com_hash_free(void *ptr)
 {
     st_table *tbl = ptr;
@@ -3923,7 +3909,10 @@ Init_win32ole(void) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L3909
     message_filter.RetryRejectedCall = mf_RetryRejectedCall;
     message_filter.MessagePending = mf_MessagePending;
 
-    com_hash = TypedData_Wrap_Struct(rb_cData, &com_hash_datatype, st_init_numtable());
+    enc2cp_hash = TypedData_Wrap_Struct(rb_cData, &win32ole_hash_datatype, st_init_numtable());
+    rb_gc_register_mark_object(enc2cp_hash);
+
+    com_hash = TypedData_Wrap_Struct(rb_cData, &win32ole_hash_datatype, st_init_numtable());
     rb_gc_register_mark_object(com_hash);
 
     cWIN32OLE = rb_define_class("WIN32OLE", rb_cObject);
@@ -4069,7 +4058,5 @@ Init_win32ole(void) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L4058
     Init_win32ole_record();
     Init_win32ole_error();
 
-    init_enc2cp();
-    atexit((void (*)(void))free_enc2cp);
     ole_init_cp();
 }

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

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