Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Closed
amos402 wants to merge14 commits intopythonnet:masterfromamos402:drop-dlopen
Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
14 commits
Select commitHold shift + click to select a range
d1928dc
Drop LoadLibrary dependency
amos402Jun 13, 2019
f000e08
Explain for getting _PyObject_NextNotImplemented
amos402Jun 13, 2019
f882400
Update changelog and authors
amos402Jun 13, 2019
b7715ee
Merge branch 'master' into drop-dlopen
filmorJun 20, 2019
41ac665
Merge remote-tracking branch 'remotes/upstream/master' into drop-dlopen
amos402Jul 1, 2019
c6dae9e
Merge branch 'master' into drop-dlopen
amos402Jul 5, 2019
653a263
Merge branch 'master' into drop-dlopen
amos402Dec 1, 2019
b3e889b
* Load PyModuleType without LibraryLoader
amos402Dec 1, 2019
04d6dfb
Merge remote-tracking branch 'remotes/upstream/master' into drop-dlop…
amos402Dec 14, 2019
5150e61
Prevent exception override
amos402Dec 14, 2019
65e209e
Rollback symbol loading for __Internal
amos402Dec 15, 2019
431d644
Merge branch 'master' into drop-dlopen
amos402Feb 12, 2020
2b84394
* Fix refcnt error
amos402Feb 12, 2020
b7797d3
Merge 'master' into drop-dlopen
amos402Feb 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletionsAUTHORS.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -60,6 +60,7 @@
- William Sardar ([@williamsardar])(https://github.com/williamsardar)
- Xavier Dupré ([@sdpython](https://github.com/sdpython))
- Zane Purvis ([@zanedp](https://github.com/zanedp))
- ([@amos402]https://github.com/amos402)
- ([@bltribble](https://github.com/bltribble))
- ([@civilx64](https://github.com/civilx64))
- ([@GSPP](https://github.com/GSPP))
Expand Down
1 change: 1 addition & 0 deletionsCHANGELOG.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,6 +58,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
- PythonEngine.Intialize will now call `Py_InitializeEx` with a default value of 0, so signals will not be configured by default on embedding. This is different from the previous behaviour, where `Py_Initialize` was called instead, which sets initSigs to 1. ([#449][i449])
- Refactored MethodBinder.Bind in preparation to make it extensible (#829)
- Look for installed Windows 10 sdk's during installation instead of relying on specific versions.
- Remove `LoadLibrary` call. ([#880][p880])

### Fixed

Expand Down
36 changes: 19 additions & 17 deletionssrc/runtime/runtime.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -310,26 +310,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();

IntPtr dllLocal = IntPtr.Zero;
var loader = LibraryLoader.Get(OperatingSystem);

if (_PythonDll != "__Internal")
{
dllLocal = loader.Load(_PythonDll);
}
_PyObject_NextNotImplemented = loader.GetFunction(dllLocal, "_PyObject_NextNotImplemented");
PyModuleType = loader.GetFunction(dllLocal, "PyModule_Type");

if (dllLocal != IntPtr.Zero)
{
loader.Free(dllLocal);
}

// Initialize modules that depend on the runtime class.
AssemblyManager.Initialize();
PyCLRMetaType = MetaType.Initialize();
Expand All@@ -346,6 +338,14 @@ internal static void Initialize(bool initSigs = false)
AssemblyManager.UpdatePath();
}

private static IntPtr Get_PyObject_NextNotImplemented()
{
IntPtr pyType = SlotHelper.CreateObjectType();
IntPtr iternext = Marshal.ReadIntPtr(pyType, TypeOffset.tp_iternext);
Runtime.XDecref(pyType);
return iternext;
}

/// <summary>
/// Initializes the data about platforms.
///
Expand DownExpand Up@@ -1964,13 +1964,15 @@ internal static IntPtr PyMem_Realloc(IntPtr ptr, long size)
internal static void SetNoSiteFlag()
{
var loader = LibraryLoader.Get(OperatingSystem);

IntPtr dllLocal;
if (_PythonDll != "__Internal")
{
dllLocal = loader.Load(_PythonDll);
if (dllLocal == IntPtr.Zero)
{
throw new Exception($"Cannot load {_PythonDll}");
}
}

try
{
Py_NoSiteFlag = loader.GetFunction(dllLocal, "Py_NoSiteFlag");
Expand Down
34 changes: 34 additions & 0 deletionssrc/runtime/typemanager.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
Expand DownExpand Up@@ -820,4 +821,37 @@ internal static void CopySlot(IntPtr from, IntPtr to, int offset)
Marshal.WriteIntPtr(to, offset, fp);
}
}


static class SlotHelper
{
public static IntPtr CreateObjectType()
{
IntPtr globals = Runtime.PyDict_New();
if (Runtime.PyDict_SetItemString(globals, "__builtins__", Runtime.PyEval_GetBuiltins()) != 0)
{
Runtime.XDecref(globals);
throw new PythonException();
}
const string code = "class A(object): pass";
IntPtr res = Runtime.PyRun_String(code, (IntPtr)RunFlagType.File, globals, globals);
if (res == IntPtr.Zero)
{
try
{
throw new PythonException();
}
finally
{
Runtime.XDecref(globals);
}
}
Runtime.XDecref(res);
IntPtr A = Runtime.PyDict_GetItemString(globals, "A");
Debug.Assert(A != IntPtr.Zero);
Runtime.XIncref(A);
Runtime.XDecref(globals);
return A;
}
}
}

[8]ページ先頭

©2009-2025 Movatter.jp