Repository navigation
Drop LoadLibrary - #880
Closed
amos402 wants to merge 14 commits into
pythonnet:master from
amos402:drop-dlopen
Closed
Conversation
Copy link
Copy Markdown
Member
What does this implement/fix? Explain your changes.
There are some limitations to dynamic load a library on some systems(e. g. Android).
LoadLibrary just called for once for getting the _PyObject_NextNotImplemented,
we can use another ways to get this function.
Does this close any currently open issues?
No
Any other comments?
Checklist
Check all those that are applicable and complete.
- Make sure to include one or more tests for your change
- If an enhancement PR, please create docs and at best an example
- Add yourself to
AUTHORS
- Updated the
CHANGELOG
amos402
added 3 commits
June 14, 2019 02:35
Drop LoadLibrary dependency
d1928dc
Explain for getting _PyObject_NextNotImplemented
f000e08
Update changelog and authors
f882400
Copy link
Copy Markdown
Member
|
I'll have to look a bit more into this. I thought that this LoadLibrary call there is not only pulling in that one symbol but that it serves as a "proxy" to enforce loading the library into memory s.t. the P/Invoke bindings work. Since your patch passes all tests (apart from the known failing one) I must have misunderstood something and will test this in our use-case to verify. Thank you already for your contribution, if this works out this will help a lot in simplifying the build process :)
|
Copy link
Copy Markdown
Member
|
@filmor @amos402 I made a single Python.Runtime.dll to work with any Python 3.x interpreter in my fork (could have included 2.x, but its lifetime is ending) via extensive use of LoadLibrary and related methods. Which I intended to upstream once 2.7 is dropped (or, for example, if we had a separate 2.x branch in maintenance mode).
|
Copy link
Copy Markdown
Member
|
@lostmsu What do you mean by "extensive use"? Isn't it enough to load libpython*.so once at startup? Could you point me to that code?
|
Copy link
Copy Markdown
Member
|
@filmor well, the LoadLibrary is called once, but all the functions are obtained using GetProcAddress/dlsym.
See losttech@ 672258f
And also losttech@ 80aa07f
All of that happens once at startup too. But there are many functions.
There is probably a performance impact too, due to the use of delegates in place of PInvoke calls.
|
filmor
and others
added 3 commits
June 20, 2019 19:29
Merge branch 'master' into drop-dlopen
b7715ee
Merge remote-tracking branch 'remotes/upstream/master' into drop-dlopen
41ac665
Merge branch 'master' into drop-dlopen
c6dae9e
Copy link
Copy Markdown
Member
|
@lostmsu What's your conclusion on keeping LoadLibrary? Does the code using delegates run reasonably or not?
|
benoithudson
reviewed
Nov 21, 2019
View reviewed changes
Comment thread
src/runtime/runtime.cs
Outdated
|
|
@@ -297,16 +297,20 @@ internal static void Initialize(bool initSigs = false) |
|
|
IntPtr dllLocal = IntPtr.Zero;
|
|
|
var loader = LibraryLoader.Get(OperatingSystem);
|
benoithudson
reviewed
Nov 21, 2019
View reviewed changes
Copy link
Copy Markdown
Contributor
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
This seems a quite reasonable patch, I think we should merge it.
I've had trouble in the past with this LoadLibrary/FreeLibrary screwing up the dlopen flags.
Merge branch 'master' into drop-dlopen
653a263
amos402
force-pushed
the
drop-dlopen
branch
from
4d9c632 to
18d8da4
Compare
December 1, 2019 13:35
* Load PyModuleType without LibraryLoader
b3e889b
* Drop C module dependency when getting _PyObject_NextNotImplemented
* Exception details for SetNoSiteFlag
amos402
force-pushed
the
drop-dlopen
branch
from
18d8da4 to
b3e889b
Compare
December 1, 2019 13:40
Copy link
Copy Markdown
Merging #880 into master will not change coverage.
The diff coverage is n/a.
@@ Coverage Diff @@
## master #880 +/- ##
=======================================
Coverage 86.71% 86.71%
=======================================
Files 1 1
Lines 301 301
=======================================
Hits 261 261
Misses 40 40
| Flag |
Coverage Δ |
|
| #setup_linux |
65.44% <ø> (ø) |
⬆️ |
| #setup_windows |
71.42% <ø> (ø) |
⬆️ |
Continue to review full report at Codecov .
Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov . Last update 5f56ebc...65e209e . Read the comment docs .
|
Copy link
Copy Markdown
Member
Author
|
I removed the dependency of zipimport. But still have no solution for SetNoSiteFlag, maybe we should add a docs for it(like please use -S when using static compile).
|
lostmsu
reviewed
Dec 3, 2019
View reviewed changes
Comment thread
src/runtime/runtime.cs
Outdated
|
|
if (dllLocal == IntPtr.Zero)
|
|
|
{
|
|
|
dllLocal = loader.Load( _PythonDll);
|
|
|
throw new Exception($"Cannot load { _PythonDll }" );
|
Comment thread
src/runtime/runtime.cs
Outdated
|
|
private static IntPtr Get_PyObject_NextNotImplemented()
|
|
|
{
|
|
|
IntPtr globals = PyDict_New();
|
|
|
if (PyDict_SetItemString(globals, "__builtins__", PyEval_GetBuiltins()) != 0)
|
Comment thread
src/runtime/runtime.cs
Outdated
Comment on lines
+335
to
+336
|
|
XDecref(globals);
|
|
|
throw new PythonException();
|
amos402
mentioned this pull request
Dec 14, 2019
Optimize for Runtime.InitializePlatformData
#891
Closed
amos402
added 2 commits
December 15, 2019 02:26
Merge remote-tracking branch 'remotes/upstream/master' into drop-dlop...
04d6dfb
...en-2
Prevent exception override
5150e61
filmor
reviewed
Dec 15, 2019
View reviewed changes
Comment thread
src/runtime/runtime.cs
Outdated
|
|
{
|
|
|
if (_PythonDll == "__Internal")
|
|
|
{
|
|
|
throw new NotSupportedException("SetNoSiteFlag didn't support on static compile");
|
Rollback symbol loading for __Internal
65e209e
Copy link
Copy Markdown
Contributor
|
I believe issues #891 , #946 , and #967 all point to a fundamental problem with this PR.
On certain Linux distributions (Debian for example), Python C extension libraries are deliberately not linked to libpython.
Yet .NET Core's [DllImport] does not load libpython with RTLD_GLOBAL.
So if this PR removes dllLocal = loader.Load(_PythonDll); from runtime.cs, where the salient line in LibraryLoader.cs is var res = dlopen(filename, RTLD_NOW | RTLD_GLOBAL);, won't this PR break Python.NET's "Embedding" mode on .NET Core?
As Victor Stinner put it in Python issue issue 21536 :
...libpython must always be loaded with RTLD_GLOBAL.
Unless we can get [DllImport] to set the RTLD_GLOBAL flag, I'm afraid we need the explicit loader.Load, at least for Linux .NET Core embedding.
|
amos402
added 3 commits
February 13, 2020 01:07
Merge branch 'master' into drop-dlopen
431d644
* Fix refcnt error
2b84394
* Pick `SlotHelper` from pythonnet#958
Merge 'master' into drop-dlopen
b7797d3
Copy link
Copy Markdown
Member
Author
|
@Jeff17Robbins This PR won't break "Embedding" mode on .NET Core, moreover it improve the compatibility since it didn't need call the dlopen.
|
amos402
mentioned this pull request
Feb 13, 2020
Add soft shutdown
#958
Merged
4 tasks
Copy link
Copy Markdown
Member
Author
amos402
closed this
Oct 9, 2020
Sign up for free
to join this conversation on GitHub .
Already have an account?
Sign in to comment
Labels
None yet
6 participants