When I step through the code, I can see that the Engines dictionary has 3 entries. One is the InvariantLanguage and two are keyed on RubyContext.
It appears that the comparison of the RubyContext object that is already in the dictionary and the new one (the one passed in by the Kernel#require method) are not "equal" and so the code creates a new entry in the dictionary for the second RubyContext object. I am not exactly sure what comparison algorithm is being used but certainly if you look at the two RubyContext objects they have different HashCodes. I did briefly try overriding GetHashCode on RubyContext to see if this made any difference but it didn't appear to. Pete -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tomas Matousek Sent: Friday,16 May 16, 2008 16:40 To: [email protected] Subject: Re: [Ironruby-core] IR SVN 107 changes behavior of 'require' (compared to SVN 103) That shouldn't be the case. There can be at most one engine per language per ScriptRuntime. The program seems to work on my machine. Tomas -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Peter Bacon Darwin Sent: Thursday, May 15, 2008 11:03 PM To: [email protected] Subject: Re: [Ironruby-core] IR SVN 107 changes behavior of 'require' (compared to SVN 103) I believe the problem is that a two engines are being created. One by the call to ScriptRuntime.GetEngine(typeof(RubyContext)); inside Robert's code and another one inside Kernel#require. Pete -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of John Lam (IRONRUBY) Sent: Thursday,15 May 15, 2008 17:05 To: [email protected] Subject: Re: [Ironruby-core] IR SVN 107 changes behavior of 'require' (compared to SVN 103) Hi Robert, I just tried and it didn't repro here with 108/109. Can you grab 109 and see if this repros on your machine? I hope this isn't some strange locale thing again ... Thanks, -John -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Robert Brotherus Sent: Thursday, May 15, 2008 6:26 AM To: [email protected] Subject: [Ironruby-core] IR SVN 107 changes behavior of 'require' (compared to SVN 103) IR 103 -> IR 107 update broke my program that relies on execution of "require '...'" strings. I don't know wether this is bug in IR 107 (or incorrect behaviour on IR 103 and earlier), so I did not file a bug report yet. I made a simplified version of my program that exposes this difference with minimal amount of code (this is a fully contained functional program): ------------------------------------------------------------------------ --- using System; using Microsoft.Scripting; using Microsoft.Scripting.Hosting; using Ruby.Runtime; class Program { static void Main(string[] args) { try { new Program().Run(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } private void Run() { System.IO.File.WriteAllText("f.rb", @" module F def F.hello puts 'F:Hello' end end "); ExecuteStr("require 'f.rb'"); ExecuteStr("F.hello"); // IR SVN 107 fails here: "uninitialized constant Object::F" } private ScriptRuntime _scriptRuntime; private ScriptScope _sharedScope; public ScriptRuntime ScriptRuntime { get { if (_scriptRuntime == null) { _scriptRuntime = ScriptRuntime.Create(); _scriptRuntime.GlobalOptions.DebugMode = true; } return _scriptRuntime; } } public ScriptEngine Engine { get { return ScriptRuntime.GetEngine(typeof(RubyContext)); } } public ScriptScope SharedScope { get { if (_sharedScope == null) _sharedScope = Engine.CreateScope(); return _sharedScope; } } public object ExecuteStr(string code) { return Engine.CreateScriptSourceFromString(code).Execute(SharedScope); } } // class ------------------------------------------------------------------------ --- Program behaves in following way in IR SVN 103 / 107: SVN 103 F:Hello Press any key to continue . . . SVN 107: System.MemberAccessException: uninitialized constant Object::F at Ruby.Builtins.ModuleOps.ConstantMissing(RubyModule self, SymbolId name) in C:\programs\IronRuby\trunk\src\IronRuby.Libraries\Builtins\ModuleOps.cs: line 642 at _stub_##6(Closure , CallSite , CodeContext , RubyModule , SymbolId ) at Microsoft.Scripting.Utils.InvokeHelper`6.Invoke(Object arg0, Object arg1, Object arg2, Object arg3, Object arg4) in C:\programs\IronRuby\trunk\src\Microsoft.Scripting.Core\Utils\ReflectedC aller.Generated.cs:line 374 at Microsoft.Scripting.Utils.ReflectedCaller.InvokeInstance(Object instance, Object[] args) in C:\programs\IronRuby\trunk\src\Microsoft.Scripting.Core\Utils\ReflectedC aller.Generated.cs:line 38 ... at Microsoft.Scripting.Hosting.ScriptSource.Execute[T](ScriptScope scope) in C:\programs\IronRuby\trunk\src\Microsoft.Scripting\Hosting\ScriptSource. cs:line153 at IronRubyTest1.Program.ExecuteStr[T](String code, Object[] par) in C:\DATA\IronRubyTest1\Program.cs:line 92 at IronRubyTest1.Program.ExecuteStr(String code, Object[] par) in C:\DATA\IronRubyTest1\Program.cs:line 86 at IronRubyTest1.Program.Run() in C:\DATA\IronRubyTest1\Program.cs:line 40 at IronRubyTest1.Program.Main(String[] args) in C:\DATA\IronRubyTest1\Program.cs:line 19 Press any key to continue . . . ------------------- I will continue to use SVN 103 for now. If it turns out that SVN 107 behavior is "as designed" (and SVN 103 behavior that I relied on faulty), I will change my client code to deal with it. Robert Brotherus Software architect Napa Ltd Tammasaarenkatu 3, Helsinki FI-00180 P.O.Box 470, Helsinki FI-00181 Tel. +358 9 22 813 1 Direct. +358 9 22 813 611 GSM +358 45 11 456 02 Fax. +358 9 22 813 800 Email: [EMAIL PROTECTED] www.napa.fi _______________________________________________ Ironruby-core mailing list [email protected] http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list [email protected] http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list [email protected] http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list [email protected] http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list [email protected] http://rubyforge.org/mailman/listinfo/ironruby-core
