In existing versions of the CLR (< 2.0), COM is not guaranteed to be
initialized. Most of the time it isn't, which is why all of the existing
Ruby <-> CLR bridges can call CoInitializeEx via
Thread.ApartmentStatewithout potentially breaking something. However,
there are some (rare)
scenarios where the CLR will initialize COM prior to the Ruby bridge being
called, which will hose folks who were attempting to change the
ApartmentState in their Ruby scripts (or in their bridge).
The Whidbey (V2.0) version of the CLR forces all threads into the MTA by
default - this gets rid of the indeterminate behavior of earlier versions of
the CLR. This currently will hose anyone using any of the existing bridges,
unless you jump through some exotic hoops. Once I release the source for my
bridge, you'll see what those exotic hoops look like. If any of the existing
bridge maintainers want to know the specifics, please feel free to ask away
>> But if I don't initialize
>> the CLR until after my Ruby program has already started running, I'm
going
>> to run into some nasty corner cases. For example, what if someone called
a
>> COM object via win32ole? By the time we get to my shim, COM will have
been
>> initialized already and there's not a lot I can do other than fail when I
>> attempt to initialize COM again.
>> I was wondering if folks would have some ideas about *how* I can declare
my
>> threading requirements at startup time?
I'm not sure I'm clear on when you need to declare the threading
requirements.
Would doing something like this as the first 2 lines in the .rb file work?
require 'clrshim'
setSTA
where 'setSTA' (or 'setMTA') is a method your shim defines.
as long as any win32ole stuff came after this, we should be OK.
Or am I overlooking something?
Wayne Vucenic
No Bugs Software
"Ruby and C++ Agile Contract Programming in Silicon Valley"
>> I'm really glad to see that someone is working on a shim for CLR 2.0!
Me too :)
>> Would doing something like this as the first 2 lines in the .rb file
work?
>> require 'clrshim'
>> setSTA
The problem is that require 'rubyshim' would have to be guaranteed to be the
first line of code in a *program*. I'm not sure at all how I can make that
guarantee given the semantics of require.
So hence my thinking around doing a platform-specific change to the Ruby
runtime to check for a configuration file.
-John
>> ruby -rclrshim $1
I really like your *simple* solution to this problem. There are still some
corner cases (like what if someone doesn't call the wrapper?)
But it's more than good enough, and let's me refocus my attention on the
hard parts of building the shim.
Thanks for the suggestion.
-John