@@ -200,19 +200,26 @@ def test_obj_call():
200
200
const string name = "test_domain_reload_mod" ;
201
201
using ( Py . GIL ( ) )
202
202
{
203
+ // Create a new module
203
204
IntPtr module = PyRuntime . PyModule_New ( name ) ;
204
205
Assert . That ( module != IntPtr . Zero ) ;
205
206
IntPtr globals = PyRuntime . PyObject_GetAttrString ( module , "__dict__" ) ;
206
207
Assert . That ( globals != IntPtr . Zero ) ;
207
208
try
208
209
{
210
+ // import builtins
211
+ // module.__dict__[__builtins__] = builtins
209
212
int res = PyRuntime . PyDict_SetItemString ( globals , "__builtins__" ,
210
213
PyRuntime . PyEval_GetBuiltins ( ) ) ;
211
214
PythonException . ThrowIfIsNotZero ( res ) ;
212
215
216
+ // Execute the code in the module's scope
213
217
PythonEngine . Exec ( code , globals ) ;
218
+ // import sys
219
+ // modules = sys.modules
214
220
IntPtr modules = PyRuntime . PyImport_GetModuleDict ( ) ;
215
- res = PyRuntime . PyDict_SetItemString ( modules , name , modules ) ;
221
+ // modules[name] = module
222
+ res = PyRuntime . PyDict_SetItemString ( modules , name , module ) ;
216
223
PythonException . ThrowIfIsNotZero ( res ) ;
217
224
}
218
225
catch
@@ -251,6 +258,11 @@ public override ValueType Execute(ValueType arg)
251
258
252
259
253
260
[ Test ]
261
+ /// <summary>
262
+ /// Create a new Python module, define a function in it.
263
+ /// Unload the domain, load a new one.
264
+ /// Make sure the function (and module) still exists.
265
+ /// </summary>
254
266
public void TestClassReference ( )
255
267
{
256
268
RunDomainReloadSteps < ReloadClassRefStep1 , ReloadClassRefStep2 > ( ) ;
0 commit comments