Skip to content

Commit b2fa5cc

Browse files
committed
Fix a bug where clr wasn't in sys.modules after reload
1 parent 1915008 commit b2fa5cc

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

src/domain_tests/TestRunner.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,46 @@ assert sys.my_obj is not None
888888
foo = sys.my_obj.Inner()
889889
print(foo)
890890
891+
",
892+
},
893+
new TestCase
894+
{
895+
// The C# code for this test doesn't matter.
896+
Name = "import_after_reload",
897+
DotNetBefore = @"
898+
namespace TestNamespace
899+
{
900+
[System.Serializable]
901+
public class Cls
902+
{
903+
}
904+
}",
905+
DotNetAfter = @"
906+
namespace TestNamespace
907+
{
908+
[System.Serializable]
909+
public class WithNestedType
910+
{
911+
[System.Serializable]
912+
public class Cls
913+
{
914+
}
915+
}
916+
}",
917+
PythonCode = @"
918+
import sys
919+
920+
def before_reload():
921+
import clr
922+
import System
923+
924+
925+
def after_reload():
926+
assert 'System' in sys.modules
927+
assert 'clr' in sys.modules
928+
import clr
929+
import System
930+
891931
",
892932
},
893933
};

src/domain_tests/test_domain_reload.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,7 @@ def test_out_to_ref_param():
8686
@pytest.mark.skipif(platform.system() == 'Darwin', reason='FIXME: macos can\'t find the python library')
8787
def test_nested_type():
8888
_run_test("nested_type")
89+
90+
@pytest.mark.skipif(platform.system() == 'Darwin', reason='FIXME: macos can\'t find the python library')
91+
def test_import_after_reload():
92+
_run_test("import_after_reload")

src/runtime/importhook.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ internal static void RestoreRuntimeData(RuntimeDataStorage storage)
134134
storage.GetValue("py_clr_module", out py_clr_module);
135135
var rootHandle = storage.GetValue<IntPtr>("root");
136136
root = (CLRModule)ManagedType.GetManagedObject(rootHandle);
137+
IntPtr dict = Runtime.PyImport_GetModuleDict();
138+
Runtime.PyDict_SetItemString(dict, "CLR", py_clr_module);
139+
Runtime.PyDict_SetItemString(dict, "clr", py_clr_module);
137140
SetupNamespaceTracking();
138141
}
139142

0 commit comments

Comments
 (0)