[issue34592] cdll.LoadLibrary allows None as an argument

2021-11-18 Thread Gregory P. Smith


Gregory P. Smith  added the comment:

We do need to document this in ctypes.rst.  Quite a bit of code depends on 
ctypes.CDLL(None) and similar to get at symbols linked into the interpreter or 
already dlopened into the process these days.  It works on Linux; I'm assuming 
it likely does on everything POSIXy.

--
assignee:  -> docs@python
components: +Documentation
nosy: +docs@python, gregory.p.smith
stage: resolved -> needs patch
status: closed -> open
versions: +Python 3.11 -Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 
3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34592] cdll.LoadLibrary allows None as an argument

2020-02-11 Thread STINNER Victor


STINNER Victor  added the comment:

In clear, it's a feature, not a bug.

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34592] cdll.LoadLibrary allows None as an argument

2020-02-10 Thread STINNER Victor


STINNER Victor  added the comment:

I'm using LoadLibrary(None) commonly to load symbols in Python itself ;-)

--
nosy: +vstinner

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34592] cdll.LoadLibrary allows None as an argument

2020-02-10 Thread Malcolm Smith


Malcolm Smith  added the comment:

This isn't documented, but CDLL(None) is translated to dlopen(NULL), which 
"causes a search for a symbol in the main program, followed by all shared 
libraries loaded at program startup, and then all shared libraries loaded by 
dlopen() with the flag RTLD_GLOBAL" (https://linux.die.net/man/3/dlopen).

This is sometimes useful because it lets you look up a symbol in an 
already-loaded library without needing to give the library's name. For example:

>>> import ctypes
>>> dll = ctypes.CDLL(None)
>>> dll.printf
<_FuncPtr object at 0x7f3427d547c0>
>>> dll.PyObject_Str
<_FuncPtr object at 0x7f3427d54880>

--
nosy: +Malcolm Smith

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34592] cdll.LoadLibrary allows None as an argument

2018-09-05 Thread Sergei Lebedev


New submission from Sergei Lebedev :

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)


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 "", line 1, in 
  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"))


--
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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com