GeezerVison is showing github.com — [3.14] gh-81241: Fix importing `ctypes` from statically linked interp… · python/cpython@24ddd48
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: Doc/library/ctypes.rst +3Lines changed: 3 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1803,6 +1803,9 @@ object is available: |
1803 | 1803 | :c:expr:`int`, which is of course not always the truth, so you have to assign |
1804 | 1804 | the correct :attr:`!restype` attribute to use these functions. |
1805 | 1805 |
|
| 1806 | + Note that if the Python interpreter is statically linked, this will be |
| 1807 | + ``None``, as ``dlopen`` is not possible in this case. |
| 1808 | + |
1806 | 1809 | .. audit-event:: ctypes.dlopen name ctypes.LibraryLoader |
1807 | 1810 |
|
1808 | 1811 | Loading a library through any of these objects raises an |
|
Collapse file
Copy file name to clipboardExpand all lines: Lib/ctypes/__init__.py +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -564,7 +564,10 @@ def LoadLibrary(self, name): |
564 | 564 | # These are Unix-like platforms which use a dynamically-linked libpython. |
565 | 565 | pythonapi = PyDLL(_sysconfig.get_config_var("LDLIBRARY")) |
566 | 566 | else: |
567 | | - pythonapi = PyDLL(None) |
| 567 | + try: |
| 568 | + pythonapi = PyDLL(None) |
| 569 | + except OSError: |
| 570 | + pythonapi = None |
568 | 571 |
|
569 | 572 |
|
570 | 573 | if _os.name == "nt": |
|
Collapse file
Copy file name to clipboard +2Lines changed: 2 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +Fix :exc:`OSError` when importing :mod:`ctypes` from a statically linked |
| 2 | +interpreter. |