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

Conversation

@amos402
Copy link
Member

@amos402amos402 commentedJun 13, 2019
edited
Loading

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 toAUTHORS
  • Updated theCHANGELOG

@filmor
Copy link
Member

I'll have to look a bit more into this. I thought that thisLoadLibrary 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 :)

@lostmsu
Copy link
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 ofLoadLibrary 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).

@filmor
Copy link
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?

@lostmsu
Copy link
Member

lostmsu commentedJun 13, 2019
edited
Loading

@filmor well, theLoadLibrary is called once, but all the functions are obtained usingGetProcAddress/dlsym.
Seelosttech@672258f

And alsolosttech@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
Copy link
Member

@lostmsu What's your conclusion on keepingLoadLibrary? Does the code using delegates run reasonably or not?

InitializePlatformData();

IntPtrdllLocal=IntPtr.Zero;
varloader=LibraryLoader.Get(OperatingSystem);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Seems like you should delete these lines too, and line 295 as well since you moved it below.

Copy link
Contributor

@benoithudsonbenoithudson left a comment

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.

* Drop C module dependency when getting _PyObject_NextNotImplemented* Exception details for SetNoSiteFlag
@codecov-io
Copy link

codecov-io commentedDec 1, 2019
edited
Loading

Codecov Report

Merging#880 intomaster willnot change coverage.
The diff coverage isn/a.

Impacted file tree graph

@@           Coverage Diff           @@##           master     #880   +/-   ##=======================================  Coverage   86.71%   86.71%           =======================================  Files           1        1             Lines         301      301           =======================================  Hits          261      261             Misses         40       40
FlagCoverage Δ
#setup_linux65.44% <ø> (ø)⬆️
#setup_windows71.42% <ø> (ø)⬆️

Continue to review full report at Codecov.

Legend -Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered byCodecov. Last update5f56ebc...65e209e. Read thecomment docs.

@amos402
Copy link
MemberAuthor

I removed the dependency ofzipimport. But still have no solution forSetNoSiteFlag, maybe we should add a docs for it(like please use-S when using static compile).

if(dllLocal== IntPtr.Zero)
{
dllLocal= loader.Load(_PythonDll);
thrownew Exception($"Cannot load{_PythonDll}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Can you throw more informative exception?Win32Exception would automatically read last error on Windows, but I don't know what to do for *nix

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Generally it should throw inside fromLoad, the nullptr checking just for in case(if the loader implementation didn't throw an exception). I'm not going to insert any platform specific code here.

privatestaticIntPtrGet_PyObject_NextNotImplemented()
{
IntPtrglobals=PyDict_New();
if(PyDict_SetItemString(globals,"__builtins__",PyEval_GetBuiltins())!=0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

CanPyEval_GetBuiltins() return an error?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The globals dict is needed, but we don't seem to be using the__builtins__ in the string. Do we really need this line?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

If you don't setup a__builtins__ or setobject explicit,object may not be found.

Comment on lines 335 to 336
XDecref(globals);
thrownewPythonException();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You might want to construct an instance ofPythonException before doingXDecref, otherwise last error could potentially be overwritten byXDecref with something new.

filmor reacted with thumbs up emoji
{
if(_PythonDll== "__Internal")
{
thrownew NotSupportedException("SetNoSiteFlag didn't support onstatic compile");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Why should this not be supported? The symbol is just in the running DLL, soloader.Load(_PythonDll) has to return essentially the result ofdlopen(NULL, ...).

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes, it should be supported. Just a mistake according to my wrong tests. I will recover it back.

@Jeff17Robbins
Copy link
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 librariesare deliberately not linked tolibpython.

Yet .NET Core's[DllImport] does not loadlibpython withRTLD_GLOBAL.

So if this PR removesdllLocal = loader.Load(_PythonDll); fromruntime.cs, where the salient line inLibraryLoader.cs isvar 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 inPython issue issue 21536:

...libpython must always be loaded with RTLD_GLOBAL.

Unless we can get[DllImport] to set theRTLD_GLOBAL flag, I'm afraid we need the explicitloader.Load, at least for Linux .NET Core embedding.

@amos402
Copy link
MemberAuthor

@Jeff17Robbins This PR won't break "Embedding" mode on .NET Core, moreover it improve the compatibility since it didn't need call thedlopen.

@amos402amos402 mentioned this pull requestFeb 13, 2020
4 tasks
@amos402
Copy link
MemberAuthor

Contained in#958

@amos402amos402 closed thisOct 9, 2020
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@filmorfilmorfilmor left review comments

@lostmsulostmsulostmsu left review comments

+1 more reviewer

@benoithudsonbenoithudsonbenoithudson left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

6 participants

@amos402@filmor@lostmsu@codecov-io@Jeff17Robbins@benoithudson

[8]ページ先頭

©2009-2025 Movatter.jp