1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

win32ole: OLE initialize per threads

* ext/win32ole/win32ole.c (ole_initialize): initialize OLE for each
  threads.  [Bug #2618] [ruby-core:27634]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38867 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-01-18 02:23:37 +00:00
parent 6a052813d0
commit 588504b20f
3 changed files with 29 additions and 29 deletions

View file

@ -1,3 +1,8 @@
Fri Jan 18 11:23:34 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/win32ole/win32ole.c (ole_initialize): initialize OLE for each
threads. [Bug #2618] [ruby-core:27634]
Thu Jan 17 22:10:35 2013 Kouhei Sutou <kou@cozmixng.org>
* lib/rubygems/ext/builder.rb (Gem::Ext::Builder.make): Remove

View file

@ -23,6 +23,14 @@ def create_win32ole_makefile
unless have_type("IMultiLanguage2", "mlang.h")
have_type("IMultiLanguage", "mlang.h")
end
spec = nil
checking_for('thread_specific', '%s') do
spec = %w[__declspec(thread) __thread].find {|th|
try_compile("#{th} int foo;", "", :werror => true)
}
spec or 'no'
end
$defs << "-DRB_THREAD_SPECIFIC=#{spec}" if spec
create_makefile("win32ole")
end
end

View file

@ -214,7 +214,16 @@ VALUE cWIN32OLE_PROPERTY;
static VALUE ary_ole_event;
static ID id_events;
static BOOL g_ole_initialized = FALSE;
#ifdef RB_THREAD_SPECIFIC
static RB_THREAD_SPECIFIC BOOL g_ole_initialized;
# define g_ole_initialized_init() ((void)0)
# define g_ole_initialized_set(val) (g_ole_initialized = (val))
#else
static volatile DWORD g_ole_initialized_key = TLS_OUT_OF_INDEXES;
# define g_ole_initialized (BOOL)TlsGetValue(g_ole_initialized_key)
# define g_ole_initialized_init() (g_ole_initialized_key = TlsAlloc())
# define g_ole_initialized_set(val) TlsSetValue(g_ole_initialized_key, (void*)(val))
#endif
static BOOL g_cp_installed = FALSE;
static BOOL g_lcid_installed = FALSE;
static HINSTANCE ghhctrl = NULL;
@ -370,9 +379,7 @@ static BOOL CALLBACK installed_lcid_proc(LPTSTR str);
static BOOL lcid_installed(LCID lcid);
static VALUE fole_s_set_locale(VALUE self, VALUE vlcid);
static VALUE fole_s_create_guid(VALUE self);
static void ole_pure_initialize(void);
static VALUE fole_s_ole_initialize(VALUE self);
static void ole_pure_uninitialize(void);
static VALUE fole_s_ole_uninitialize(VALUE self);
static VALUE fole_initialize(int argc, VALUE *argv, VALUE self);
static VALUE hash2named_arg(VALUE pair, struct oleparam* pOp);
@ -1204,7 +1211,7 @@ void
ole_uninitialize(void)
{
OleUninitialize();
g_ole_initialized = FALSE;
g_ole_initialized_set(FALSE);
}
static void
@ -1217,13 +1224,8 @@ ole_initialize(void)
if(FAILED(hr)) {
ole_raise(hr, rb_eRuntimeError, "fail: OLE initialize");
}
g_ole_initialized = TRUE;
/*
* In some situation, OleUninitialize does not work fine. ;-<
*/
/*
atexit((void (*)(void))ole_uninitialize);
*/
g_ole_initialized_set(TRUE);
hr = CoRegisterMessageFilter(&imessage_filter, &previous_filter);
if(FAILED(hr)) {
previous_filter = NULL;
@ -3141,27 +3143,11 @@ fole_s_create_guid(VALUE self)
* You must not use thease method.
*/
static void
ole_pure_initialize(void)
{
HRESULT hr;
hr = OleInitialize(NULL);
if(FAILED(hr)) {
ole_raise(hr, rb_eRuntimeError, "fail: OLE initialize");
}
}
static void
ole_pure_uninitialize(void)
{
OleUninitialize();
}
/* :nodoc */
static VALUE
fole_s_ole_initialize(VALUE self)
{
ole_pure_initialize();
ole_initialize();
return Qnil;
}
@ -3169,7 +3155,7 @@ fole_s_ole_initialize(VALUE self)
static VALUE
fole_s_ole_uninitialize(VALUE self)
{
ole_pure_uninitialize();
ole_uninitialize();
return Qnil;
}
@ -9080,6 +9066,7 @@ free_enc2cp(void)
void
Init_win32ole(void)
{
g_ole_initialized_init();
ary_ole_event = rb_ary_new();
rb_gc_register_mark_object(ary_ole_event);
id_events = rb_intern("events");