[New-bugs-announce] [issue34592] cdll.LoadLibrary allows None as an argument
Sergei Lebedev
report at bugs.python.org
Wed Sep 5 17:35:41 EDT 2018
New submission from Sergei Lebedev <superbobry at gmail.com>:
LoadLibrary in Python 2.7 through 3.7 accepts None as an argument. I wonder if this has been allowed for a reason? If not, it should probably be changed to raise a TypeError instead.
>>> ctypes.cdll.LoadLibrary(None)
<CDLL 'None', handle fffffffffffffffe at 10eedbe90>
Interestingly, on Python 2.7 LoadLibrary explicitly mentions None as allowed in the error message:
>>> ctypes.cdll.LoadLibrary(42)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "[...]/ctypes/__init__.py", line 444, in LoadLibrary
return self._dlltype(name)
File "[...]/ctypes/__init__.py", line 366, in __init__
self._handle = _dlopen(self._name, mode)
TypeError: dlopen() argument 1 must be string or None, not int
A side-effect of None being allowed is that chaining find_library and LoadLibrary is error-prone:
>>> ctypes.cdll.LoadLibrary(find_library("foobar"))
<CDLL 'None', handle fffffffffffffffe at 10ef35fd0>
----------
messages: 324654
nosy: superbobry
priority: normal
severity: normal
status: open
title: cdll.LoadLibrary allows None as an argument
versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34592>
_______________________________________
More information about the New-bugs-announce
mailing list