FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

ImportHook cleanup + PyObject.Length exception by lostmsu · Pull Request #1400 · pythonnet/pythonnet · GitHub

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension .cs  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
Prev Previous commit
Next Next commit
ImportHook: verify __import__ was not updated before overwriting it w…
…ith original value
  • Loading branch information
lostmsu committed Feb 27, 2021
commit b2c15a4dafd6bdc02e79cf80cc48a91c2f0cb39b
9 changes: 9 additions & 0 deletions src/runtime/importhook.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ static void RestoreImport()
{
IntPtr builtins = Runtime.GetBuiltins();

IntPtr existing = Runtime.PyObject_GetAttr(builtins, PyIdentifier.__import__);
Runtime.XDecref(existing);
if (existing != hook.ptr)
{
throw new NotSupportedException("Unable to restore original __import__.");
}

int res = Runtime.PyObject_SetAttr(builtins, PyIdentifier.__import__, py_import);
PythonException.ThrowIfIsNotZero(res);
Runtime.XDecref(py_import);
Expand Down Expand Up @@ -374,6 +381,8 @@ public static IntPtr __import__(IntPtr self, IntPtr argsRaw, IntPtr kw)

private static bool IsLoadAll(BorrowedReference fromList)
{
if (fromList == null) throw new ArgumentNullException(nameof(fromList));

if (CLRModule.preload)
{
return false;
Expand Down

Back | FazBrowse Home | New Git URL