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

Commitf7e9fba

Browse files
bpo-33591: Add support for path like objects toctypes.CDLL (#7032)
Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
1 parent90d85a9 commitf7e9fba

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

‎Doc/library/ctypes.rst‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,10 @@ way is to instantiate one of the following classes:
13801380
DLLs and determine which one is not found using Windows debugging and
13811381
tracing tools.
13821382

1383+
..versionchanged::3.12
1384+
1385+
The *name* parameter can now be a:term:`path-like object`.
1386+
13831387
..seealso::
13841388

13851389
`Microsoft DUMPBIN tool<https://docs.microsoft.com/cpp/build/reference/dependents>`_
@@ -1398,13 +1402,21 @@ way is to instantiate one of the following classes:
13981402
..versionchanged::3.3
13991403
:exc:`WindowsError` used to be raised.
14001404

1405+
..versionchanged::3.12
1406+
1407+
The *name* parameter can now be a:term:`path-like object`.
1408+
14011409

14021410
..class::WinDLL(name, mode=DEFAULT_MODE, handle=None, use_errno=False, use_last_error=False, winmode=None)
14031411

14041412
Windows only: Instances of this class represent loaded shared libraries,
14051413
functions in these libraries use the ``stdcall`` calling convention, and are
14061414
assumed to return:c:expr:`int` by default.
14071415

1416+
..versionchanged::3.12
1417+
1418+
The *name* parameter can now be a:term:`path-like object`.
1419+
14081420
The Python:term:`global interpreter lock` is released before calling any
14091421
function exported by these libraries, and reacquired afterwards.
14101422

@@ -1418,6 +1430,10 @@ function exported by these libraries, and reacquired afterwards.
14181430

14191431
Thus, this is only useful to call Python C api functions directly.
14201432

1433+
..versionchanged::3.12
1434+
1435+
The *name* parameter can now be a:term:`path-like object`.
1436+
14211437
All these classes can be instantiated by calling them with at least one
14221438
argument, the pathname of the shared library. If you have an existing handle to
14231439
an already loaded shared library, it can be passed as the ``handle`` named

‎Lib/ctypes/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ def __init__(self, name, mode=DEFAULT_MODE, handle=None,
344344
use_errno=False,
345345
use_last_error=False,
346346
winmode=None):
347+
ifname:
348+
name=_os.fspath(name)
347349
self._name=name
348350
flags=self._func_flags_
349351
ifuse_errno:

‎Lib/test/test_ctypes/test_loading.py‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,20 @@ class LoaderTest(unittest.TestCase):
2828
unknowndll="xxrandomnamexx"
2929

3030
deftest_load(self):
31-
iflibc_nameisNone:
32-
self.skipTest('could not find libc')
33-
CDLL(libc_name)
34-
CDLL(os.path.basename(libc_name))
31+
iflibc_nameisnotNone:
32+
test_lib=libc_name
33+
else:
34+
ifos.name=="nt":
35+
import_ctypes_test
36+
test_lib=_ctypes_test.__file__
37+
else:
38+
self.skipTest('could not find library to load')
39+
CDLL(test_lib)
40+
CDLL(os.path.basename(test_lib))
41+
classCTypesTestPathLikeCls:
42+
def__fspath__(self):
43+
returntest_lib
44+
CDLL(CTypesTestPathLikeCls())
3545
self.assertRaises(OSError,CDLL,self.unknowndll)
3646

3747
deftest_load_version(self):

‎Misc/ACKS‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,7 @@ Tim Hochberg
754754
Benjamin Hodgson
755755
Joerg-Cyril Hoehle
756756
Douwe Hoekstra
757+
Robert Hoelzl
757758
Gregor Hoffleit
758759
Chris Hoffman
759760
Tim Hoffmann
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:class:`ctypes.CDLL`,:class:`ctypes.OleDLL`,:class:`ctypes.WinDLL`,
2+
and:class:`ctypes.PyDLL` now accept:term:`path-like objects
3+
<path-like object>` as their ``name`` argument. Patch by Robert Hoelzl.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp