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

gh-119349: Add ctypes.util function to list loaded shared libraries by WardBrian · Pull Request #122946 · python/cpython · GitHub

Repository navigation

gh-119349: Add ctypes.util function to list loaded shared libraries - #122946

Merged
encukou merged 33 commits into
python:mainfrom
WardBrian:ctypes-util-list-libraries
Feb 8, 2025
Merged

encukou merged 33 commits into
python:mainfrom
WardBrian:ctypes-util-list-libraries

Conversation

WardBrian commented Aug 12, 2024 •
edited by github-actions Bot
Loading

Copy link
Copy Markdown
Contributor

The dllist() function calls platform-specific APIs in order to list the runtime libraries loaded by Python and any imported modules. If these fail for any reason, None is returned.

The name could surely be bikeshedded, at the moment it is taken from the Julia function of the same name

Previous discussions:

Code based on https://github.com/WardBrian/dllist by myself with a contribution from @eryksun


📚 Documentation preview 📚: https://cpython-previews--122946.org.readthedocs.build/

ghost commented Aug 12, 2024 •
edited by ghost
Loading

Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

Click the button to sign:

Comment thread Doc/library/ctypes.rst
Comment thread Lib/ctypes/util.py Outdated
Comment thread Lib/ctypes/util.py Outdated

Copy link
Copy Markdown
Member

I'm not a fan of returning None and emitting a warning instead of raising an error. That seems like a potential footgun; I could see developers being very confused as to why their code isn't working if they have warnings suppressed, or simply don't see them (e.g. they're buried in logs).

Comment thread Lib/test/test_ctypes/test_dllist.py Outdated

Copy link
Copy Markdown
Contributor Author

I'm not a fan of returning None and emitting a warning instead of raising an error. That seems like a potential footgun; I could see developers being very confused as to why their code isn't working if they have warnings suppressed, or simply don't see them (e.g. they're buried in logs).

Yes, what to do in the error case is certainly interesting. In my original implementation I returned [], but I can imagine a situation where the platform reports that there actually aren't any shared libraries (if you're in some MUSL, very static, environment, perhaps), so None seemed like a good distinction from [] and matched what ctypes.util.find_library() does

We certainly could let the error propagate, but there isn't much you can do as a user with the exceptions. Most use cases I can imagine would catch the error and then return something falsey, either None or [], and code that deals with this will need to handle that anyway.

Copy link
Copy Markdown
Member

We certainly could let the error propagate, but there isn't much you can do as a user with the exceptions. Most use cases I can imagine would catch the error and then return something falsey, either None or [], and code that deals with this will need to handle that anyway.

I think we should offload that choice to the user.

kailando commented Aug 13, 2024 via email

Copy link
Copy Markdown

Copy link
Copy Markdown
Member

I am seeing that we're special-casing not having support for AIX. Does CPython even officially support AIX?

Copy link
Copy Markdown
Contributor Author

It's not listed in PEP 11, but there are ~150 other mentions of the platform in the codebase, mostly in test code, like the mentions here.

picnixz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'm not a fan of emitting warnings. Either you silently skip the failed names, or you raise. Or you return bytes and you won't have decoding issues for instance. But if you can list the DLLs being loaded, you should always return the complete list, and if you can't, then you should return None (other functions seem to do it as well when they can't get the result for whatever reason).

Comment thread Lib/ctypes/util.py
Comment thread Lib/ctypes/util.py Outdated
Comment thread Lib/ctypes/util.py Outdated
Comment thread Lib/ctypes/util.py Outdated
Comment thread Lib/ctypes/util.py
Comment thread Lib/test/test_ctypes/test_dllist.py Outdated
Comment thread Lib/test/test_ctypes/test_dllist.py Outdated
Comment thread Lib/test/test_ctypes/test_dllist.py Outdated
Comment thread Lib/ctypes/util.py Outdated

Copy link
Copy Markdown
Contributor Author

I'm not sure how long it takes to be reviewed and for the bot to update, but I wanted to note that my employer has filled out the CLA at this point

Comment thread Lib/ctypes/util.py Outdated
Comment thread Lib/ctypes/util.py Outdated
Comment thread Lib/ctypes/util.py Outdated

Copy link
Copy Markdown
Member

Bikeshedding: if we're going to allow returning None in some cases, we should name this something like find_libraries, for consistency with the None return of find_library.

Comment thread Lib/ctypes/util.py Outdated
Comment thread Doc/library/ctypes.rst Outdated

ghost commented Oct 4, 2024 •
edited by ghost
Loading

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

The dllist() function calls platform-specific APIs in order to
list the runtime libraries loaded by Python and any imported modules.
If these fail for any reason, None is returned.
Comment thread Doc/library/ctypes.rst
Comment thread Lib/ctypes/util.py Outdated
encukou added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Feb 4, 2025

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @encukou for commit 5ab1b02 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F30617%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Feb 4, 2025
Comment thread Doc/library/ctypes.rst Outdated
On that platform, libc is called libc-2.28.so, not libc.so. Instead, the test searches for libffi.so, which is a dependency of ctypes
WardBrian changed the title gh-119349: Add function to list the currently loaded libraries to ctypes.util gh-119349: Add ctypes.util function to list loaded shared libraries Feb 4, 2025
encukou added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Feb 5, 2025

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @encukou for commit 80be2ab 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F30617%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Feb 5, 2025

encukou commented Feb 5, 2025

Copy link
Copy Markdown
Member

Android has libc.so, but not libffi.so :(

ZeroIntensity left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Pretty much LGTM, apart from my many nitpicks. Looking forward to seeing this merged!

Comment thread Doc/library/ctypes.rst Outdated
Comment thread Lib/test/test_ctypes/test_dllist.py Outdated
Comment thread Lib/test/test_ctypes/test_dllist.py Outdated
Comment thread Lib/test/test_ctypes/test_dllist.py Outdated
Comment thread Lib/ctypes/util.py
Comment thread Lib/ctypes/util.py
Comment thread Lib/test/test_ctypes/test_dllist.py Outdated
Comment thread Doc/library/ctypes.rst

mhsmith commented Feb 5, 2025

Copy link
Copy Markdown
Member

Android has libc.so, but not libffi.so :(

Android links ctypes against libffi statically. We could change this, but if it's only for this test, then it would be easier to just test for libc on Android instead.

Copy link
Copy Markdown
Contributor Author

Android has libc.so, but not libffi.so :(

Android links ctypes against libffi statically

I went ahead and updated the test to check if either libc.so or libffi.so is in the return on unix-alikes. Hopefully this guards against more platform issues, and we can always add a third candidate to this list if we end up with an even weirder platform that has neither...

encukou added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Feb 6, 2025

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @encukou for commit 1c3594e 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F30617%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Feb 6, 2025

ZeroIntensity left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM! Thanks for doing this and for your patience with reviews, @WardBrian

encukou merged commit 421ea12 into python:main Feb 8, 2025
WardBrian deleted the ctypes-util-list-libraries branch February 10, 2025 15:07
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants


Back | FazBrowse Home | New Git URL