mirror of https://github.com/python/cpython.git
bpo-33591: Add support for path like objects to `ctypes.CDLL` (#7032)
Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
This commit is contained in:
parent
90d85a9b41
commit
f7e9fbacb2
|
@ -1380,6 +1380,10 @@ way is to instantiate one of the following classes:
|
||||||
DLLs and determine which one is not found using Windows debugging and
|
DLLs and determine which one is not found using Windows debugging and
|
||||||
tracing tools.
|
tracing tools.
|
||||||
|
|
||||||
|
.. versionchanged:: 3.12
|
||||||
|
|
||||||
|
The *name* parameter can now be a :term:`path-like object`.
|
||||||
|
|
||||||
.. seealso::
|
.. seealso::
|
||||||
|
|
||||||
`Microsoft DUMPBIN tool <https://docs.microsoft.com/cpp/build/reference/dependents>`_
|
`Microsoft DUMPBIN tool <https://docs.microsoft.com/cpp/build/reference/dependents>`_
|
||||||
|
@ -1398,6 +1402,10 @@ way is to instantiate one of the following classes:
|
||||||
.. versionchanged:: 3.3
|
.. versionchanged:: 3.3
|
||||||
:exc:`WindowsError` used to be raised.
|
:exc:`WindowsError` used to be raised.
|
||||||
|
|
||||||
|
.. versionchanged:: 3.12
|
||||||
|
|
||||||
|
The *name* parameter can now be a :term:`path-like object`.
|
||||||
|
|
||||||
|
|
||||||
.. class:: WinDLL(name, mode=DEFAULT_MODE, handle=None, use_errno=False, use_last_error=False, winmode=None)
|
.. class:: WinDLL(name, mode=DEFAULT_MODE, handle=None, use_errno=False, use_last_error=False, winmode=None)
|
||||||
|
|
||||||
|
@ -1405,6 +1413,10 @@ way is to instantiate one of the following classes:
|
||||||
functions in these libraries use the ``stdcall`` calling convention, and are
|
functions in these libraries use the ``stdcall`` calling convention, and are
|
||||||
assumed to return :c:expr:`int` by default.
|
assumed to return :c:expr:`int` by default.
|
||||||
|
|
||||||
|
.. versionchanged:: 3.12
|
||||||
|
|
||||||
|
The *name* parameter can now be a :term:`path-like object`.
|
||||||
|
|
||||||
The Python :term:`global interpreter lock` is released before calling any
|
The Python :term:`global interpreter lock` is released before calling any
|
||||||
function exported by these libraries, and reacquired afterwards.
|
function exported by these libraries, and reacquired afterwards.
|
||||||
|
|
||||||
|
@ -1418,6 +1430,10 @@ function exported by these libraries, and reacquired afterwards.
|
||||||
|
|
||||||
Thus, this is only useful to call Python C api functions directly.
|
Thus, this is only useful to call Python C api functions directly.
|
||||||
|
|
||||||
|
.. versionchanged:: 3.12
|
||||||
|
|
||||||
|
The *name* parameter can now be a :term:`path-like object`.
|
||||||
|
|
||||||
All these classes can be instantiated by calling them with at least one
|
All these classes can be instantiated by calling them with at least one
|
||||||
argument, the pathname of the shared library. If you have an existing handle to
|
argument, the pathname of the shared library. If you have an existing handle to
|
||||||
an already loaded shared library, it can be passed as the ``handle`` named
|
an already loaded shared library, it can be passed as the ``handle`` named
|
||||||
|
|
|
@ -344,6 +344,8 @@ def __init__(self, name, mode=DEFAULT_MODE, handle=None,
|
||||||
use_errno=False,
|
use_errno=False,
|
||||||
use_last_error=False,
|
use_last_error=False,
|
||||||
winmode=None):
|
winmode=None):
|
||||||
|
if name:
|
||||||
|
name = _os.fspath(name)
|
||||||
self._name = name
|
self._name = name
|
||||||
flags = self._func_flags_
|
flags = self._func_flags_
|
||||||
if use_errno:
|
if use_errno:
|
||||||
|
|
|
@ -28,10 +28,20 @@ class LoaderTest(unittest.TestCase):
|
||||||
unknowndll = "xxrandomnamexx"
|
unknowndll = "xxrandomnamexx"
|
||||||
|
|
||||||
def test_load(self):
|
def test_load(self):
|
||||||
if libc_name is None:
|
if libc_name is not None:
|
||||||
self.skipTest('could not find libc')
|
test_lib = libc_name
|
||||||
CDLL(libc_name)
|
else:
|
||||||
CDLL(os.path.basename(libc_name))
|
if os.name == "nt":
|
||||||
|
import _ctypes_test
|
||||||
|
test_lib = _ctypes_test.__file__
|
||||||
|
else:
|
||||||
|
self.skipTest('could not find library to load')
|
||||||
|
CDLL(test_lib)
|
||||||
|
CDLL(os.path.basename(test_lib))
|
||||||
|
class CTypesTestPathLikeCls:
|
||||||
|
def __fspath__(self):
|
||||||
|
return test_lib
|
||||||
|
CDLL(CTypesTestPathLikeCls())
|
||||||
self.assertRaises(OSError, CDLL, self.unknowndll)
|
self.assertRaises(OSError, CDLL, self.unknowndll)
|
||||||
|
|
||||||
def test_load_version(self):
|
def test_load_version(self):
|
||||||
|
|
|
@ -754,6 +754,7 @@ Tim Hochberg
|
||||||
Benjamin Hodgson
|
Benjamin Hodgson
|
||||||
Joerg-Cyril Hoehle
|
Joerg-Cyril Hoehle
|
||||||
Douwe Hoekstra
|
Douwe Hoekstra
|
||||||
|
Robert Hoelzl
|
||||||
Gregor Hoffleit
|
Gregor Hoffleit
|
||||||
Chris Hoffman
|
Chris Hoffman
|
||||||
Tim Hoffmann
|
Tim Hoffmann
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
:class:`ctypes.CDLL`, :class:`ctypes.OleDLL`, :class:`ctypes.WinDLL`,
|
||||||
|
and :class:`ctypes.PyDLL` now accept :term:`path-like objects
|
||||||
|
<path-like object>` as their ``name`` argument. Patch by Robert Hoelzl.
|
Loading…
Reference in New Issue