- Notifications
You must be signed in to change notification settings - Fork768
Drop LoadLibrary#880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Drop LoadLibrary#880
Changes from8 commits
d1928dcf000e08f882400b7715ee41ac665c6dae9e653a263b3e889b04d6dfb5150e6165e209e431d6442b84394b7797d3File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -292,26 +292,18 @@ internal static void Initialize(bool initSigs = false) | ||
| Error = new IntPtr(-1); | ||
| _PyObject_NextNotImplemented = Get_PyObject_NextNotImplemented(); | ||
| { | ||
| IntPtr sys = PyImport_ImportModule("sys"); | ||
| PyModuleType = PyObject_Type(sys); | ||
| XDecref(sys); | ||
| } | ||
| // Initialize data about the platform we're running on. We need | ||
| // this for the type manager and potentially other details. Must | ||
| // happen after caching the python types, above. | ||
| InitializePlatformData(); | ||
| // Initialize modules that depend on the runtime class. | ||
| AssemblyManager.Initialize(); | ||
| PyCLRMetaType = MetaType.Initialize(); | ||
| @@ -328,6 +320,29 @@ internal static void Initialize(bool initSigs = false) | ||
| AssemblyManager.UpdatePath(); | ||
| } | ||
| private static IntPtr Get_PyObject_NextNotImplemented() | ||
| { | ||
| IntPtr globals = PyDict_New(); | ||
| if (PyDict_SetItemString(globals, "__builtins__", PyEval_GetBuiltins()) != 0) | ||
| ||
| { | ||
| XDecref(globals); | ||
| throw new PythonException(); | ||
| } | ||
| const string code = "class A(object): pass"; | ||
| IntPtr res = PyRun_String(code, (IntPtr)RunFlagType.File, globals, globals); | ||
| if (res == IntPtr.Zero) | ||
| { | ||
| XDecref(globals); | ||
| throw new PythonException(); | ||
| ||
| } | ||
| XDecref(res); | ||
| IntPtr A = PyDict_GetItemString(globals, "A"); | ||
| IntPtr iternext = Marshal.ReadIntPtr(A, TypeOffset.tp_iternext); | ||
| XDecref(globals); | ||
| XDecref(A); | ||
| return iternext; | ||
| } | ||
| /// <summary> | ||
| /// Initializes the data about platforms. | ||
| /// | ||
| @@ -1893,25 +1908,24 @@ internal static IntPtr PyMem_Realloc(IntPtr ptr, long size) | ||
| internal static void SetNoSiteFlag() | ||
| { | ||
| if (_PythonDll == "__Internal") | ||
| { | ||
| throw new NotSupportedException("SetNoSiteFlag didn't support on static compile"); | ||
| ||
| } | ||
| var loader = LibraryLoader.Get(OperatingSystem); | ||
| IntPtr dllLocal = loader.Load(_PythonDll); | ||
| if (dllLocal == IntPtr.Zero) | ||
| { | ||
| throw new Exception($"Cannot load {_PythonDll}"); | ||
| ||
| } | ||
| try | ||
| { | ||
| Py_NoSiteFlag = loader.GetFunction(dllLocal, "Py_NoSiteFlag"); | ||
| Marshal.WriteInt32(Py_NoSiteFlag, 1); | ||
| } | ||
| finally | ||
| { | ||
| loader.Free(dllLocal); | ||
| } | ||
| } | ||
| } | ||