[New-bugs-announce] [issue42569] Callers of _Py_fopen/_Py_wfopen may be broken after addition of audit hooks
report at bugs.python.org
Fri Dec 4 11:12:33 EST 2020
New submission from Alexey Izbyshev <izbyshev at ispras.ru>:
Before addition of audit hooks in 3.8, _Py_fopen() and _Py_wfopen() were simple wrappers around corresponding C runtime functions. They didn't require GIL, reported errors via errno and could be safely called during early interpreter initialization.
With the addition of PySys_Audit() calls, they can also raise an exception, which makes it unclear how they should be used. At least one caller is confused, so an early-added hook (e.g. from sitecustomize.py) that raises a RuntimeError on at attempt to open the main file causes the following:
$ ./python /home/test/test.py
./python: can't open file '/home/test/test.py': [Errno 22] Invalid argument
Traceback (most recent call last):
File "/home/test/.local/lib/python3.10/site-packages/sitecustomize.py", line 10, in hook
"Invalid argument" is reported by pymain_run_file() due to a bogus errno, and the real problem (exception from the hook) is noticed only later.
Could somebody share the current intended status/role of these helpers? Understanding that seems to be required to deal with issue 32381.
components: Interpreter Core
nosy: izbyshev, steve.dower, vstinner
title: Callers of _Py_fopen/_Py_wfopen may be broken after addition of audit hooks
versions: Python 3.10, Python 3.8, Python 3.9
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce