Skip to content

Commit 113c2e4

Browse files
committed
ImportHook: verify __import__ was not updated before overwriting it with original value
1 parent 676fbb4 commit 113c2e4

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/runtime/importhook.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ static void RestoreImport()
6161
{
6262
IntPtr builtins = Runtime.GetBuiltins();
6363

64+
#if DEBUG
65+
IntPtr existing = Runtime.PyObject_GetAttr(builtins, PyIdentifier.__import__);
66+
System.Diagnostics.Debug.Assert(existing == hook.ptr);
67+
Runtime.XDecref(existing);
68+
#endif
69+
6470
int res = Runtime.PyObject_SetAttr(builtins, PyIdentifier.__import__, py_import);
6571
PythonException.ThrowIfIsNotZero(res);
6672
Runtime.XDecref(py_import);

0 commit comments

Comments
 (0)