Commit graph

28093 commits

Author SHA1 Message Date
Pablo Galindo Salgado b28ffaa193
gh-109596: Ensure repeated rules in the grammar are not allowed and fix incorrect soft keywords (#109606) 2023-09-22 19:03:23 +01:00
Irit Katriel 7c55399172
gh-109719: Fix missing jump target labels when compiler reorders cold/warm blocks (#109734) 2023-09-22 16:59:35 +00:00
Tian Gao 73ccfa28c5
gh-109164: Replace getopt with argparse in pdb (#109165)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2023-09-22 16:55:48 +00:00
Adam Turner 3e8fcb7df7
ACKS: Fix ordering; Correct Itamar Oren's surname; Add Adam Turner (#109737) 2023-09-22 16:56:07 +02:00
elfstrom 405b06375a
gh-105829: Fix concurrent.futures.ProcessPoolExecutor deadlock (#108513)
This fixes issue #105829, https://github.com/python/cpython/issues/105829

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Antoine Pitrou <antoine@python.org>
Co-authored-by: Chris Withers <chris@withers.org>
Co-authored-by: Thomas Moreau <thomas.moreau.2010@gmail.com>
2023-09-22 13:55:56 +01:00
EliseevEgor 8fc071345b
gh-106584: Fix exit code for unittest in Python 3.12 (#106588)
Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2023-09-22 14:26:27 +02:00
AN Long 4230d7ce93
gh-108996: fix and enable test_msvcrt (#109226)
* Add _testconsole.flush_console_input_buffer() function.
* test_kbhit(), test_getwch() and test_getwche() now call
  flush_console_input_buffer().
* Don't override sys.stdin anymore (not needed).
2023-09-22 02:19:48 +02:00
AN Long 869f177b5c
gh-74481: Add missing debug function docs and constants to msvcrt (GH-109650) 2023-09-21 16:44:24 +01:00
Victor Stinner d4cea794a7
gh-109613: _pystat_fromstructstat() checks for exceptions (#109618)
Fix os.stat() and os.DirEntry.stat(): check for exceptions.
Previously, on Python built in debug mode, these functions could
trigger a fatal Python error (and abort the process) when a function
succeeded with an exception set.

_pystat_fromstructstat() now exits immediately if an exception is
raised, rather only checking for exceptions at the end. It fix
following fatal error in fill_time():

    Fatal Python error: _Py_CheckSlotResult:
    Slot * of type int succeeded with an exception set
2023-09-21 09:55:06 +02:00
Adam Turner 712cb173f8
GH-109209: Bump the minimum Sphinx version to 4.2 (#109210) 2023-09-21 09:06:36 +03:00
Irit Katriel 9ccf0545ef
gh-109627: duplicated smalll exit blocks need to be assigned jump target labels (#109630) 2023-09-20 23:08:06 +00:00
Heinz-Alexander Fuetterer ef6d475db3
Fix typos in docs and comments (#109619) 2023-09-20 16:58:23 +00:00
James Gerity def828995a
fixes gh-109559: Update unicodedata for Unicode 15.1.0 (GH-109560)
---------

Co-authored-by: Benjamin Peterson <benjamin@python.org>
2023-09-19 22:07:47 -07:00
Jelle Zijlstra 1293fcc3c6
gh-109543: Remove unnecessary hasattr check (#109544)
Also added a new test case covering the scenario I thought this
might be about.
2023-09-19 20:15:52 -07:00
Victor Stinner 81cd1bd713
gh-103053: Skip test_freeze_simple_script() on PGO build (#109591)
Skip test_freeze_simple_script() of test_tools.test_freeze if Python
is built with "./configure --enable-optimizations", which means with
Profile Guided Optimization (PGO): it just makes the test too slow.
The freeze tool is tested by many other CIs with other (faster)
compiler flags.

test.pythoninfo now gets also get_build_info() of
test.libregrtests.utils.
2023-09-20 01:58:34 +00:00
Mateusz Nowak 5a740cd06e
gh-109109: Expose retrieving certificate chains in SSL module (#109113)
Adds APIs to get the TLS certificate chains, verified or full unverified, from SSLSocket and SSLObject.

Co-authored-by: Gregory P. Smith [Google LLC] <greg@krypto.org>
2023-09-20 01:20:54 +00:00
Ronan Pigott ddf2e953c2
gh-109033: Return filename with os.utime errors (#109034)
The filename was previously intentionally omitted from exception because
"it might confuse the user". Uncaught exceptions are not generally a
replacement for user-facing error messages, so obscuring this
information only has the effect of making the programmer's life more
difficult.
2023-09-20 01:18:23 +02:00
Victor Stinner 754519a9f8
gh-109580: Skip test_perf_profiler on ASAN build (#109584)
Skip test_perf_profiler if Python is built with ASAN, MSAN or UBSAN
sanitizer. Python does crash randomly in this test on such build.
2023-09-19 19:42:51 +02:00
Sam Gross 0c89056fe5
gh-108724: Add PyMutex and _PyParkingLot APIs (gh-109344)
PyMutex is a one byte lock with fast, inlineable lock and unlock functions for the common uncontended case.  The design is based on WebKit's WTF::Lock.

PyMutex is built using the _PyParkingLot APIs, which provides a cross-platform futex-like API (based on WebKit's WTF::ParkingLot).  This internal API will be used for building other synchronization primitives used to implement PEP 703, such as one-time initialization and events.

This also includes tests and a mini benchmark in Tools/lockbench/lockbench.py to compare with the existing PyThread_type_lock.

Uncontended acquisition + release:
* Linux (x86-64): PyMutex: 11 ns, PyThread_type_lock: 44 ns
* macOS (arm64): PyMutex: 13 ns, PyThread_type_lock: 18 ns
* Windows (x86-64): PyMutex: 13 ns, PyThread_type_lock: 38 ns

PR Overview:

The primary purpose of this PR is to implement PyMutex, but there are a number of support pieces (described below).

* PyMutex:  A 1-byte lock that doesn't require memory allocation to initialize and is generally faster than the existing PyThread_type_lock.  The API is internal only for now.
* _PyParking_Lot:  A futex-like API based on the API of the same name in WebKit.  Used to implement PyMutex.
* _PyRawMutex:  A word sized lock used to implement _PyParking_Lot.
* PyEvent:  A one time event.  This was used a bunch in the "nogil" fork and is useful for testing the PyMutex implementation, so I've included it as part of the PR.
* pycore_llist.h:  Defines common operations on doubly-linked list.  Not strictly necessary (could do the list operations manually), but they come up frequently in the "nogil" fork. ( Similar to https://man.freebsd.org/cgi/man.cgi?queue)

---------

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2023-09-19 09:54:29 -06:00
Xuehai Pan 74f315edd0
gh-102757: fix function signature mismatch for functools.reduce between code and documentation (#102759) 2023-09-18 10:42:58 -06:00
Victor Stinner 0bb0d88e2d
gh-109496: Detect Py_DECREF() after dealloc in debug mode (#109539)
On a Python built in debug mode, Py_DECREF() now calls
_Py_NegativeRefcount() if the object is a dangling pointer to
deallocated memory: memory filled with 0xDD "dead byte" by the debug
hook on memory allocators. The fix is to check the reference count
*before* checking for _Py_IsImmortal().

Add test_decref_freed_object() to test_capi.test_misc.
2023-09-18 14:59:09 +00:00
Tian Gao 412f5e85d6
gh-109371: Fix monitoring with instruction events set (gh-109385) 2023-09-18 23:30:08 +09:00
Shantanu 23f9f6f464
gh-108843: fix ast.unparse for f-string with many quotes (#108981) 2023-09-18 14:56:19 +01:00
Serhiy Storchaka add16f1a5e
gh-108511: Add C API functions which do not silently ignore errors (GH-109025)
Add the following functions:

* PyObject_HasAttrWithError()
* PyObject_HasAttrStringWithError()
* PyMapping_HasKeyWithError()
* PyMapping_HasKeyStringWithError()
2023-09-17 14:23:31 +03:00
Brett Cannon e218e5022e
GH-83417: Allow venv to add a .gitignore file to environments via a new scm_ignore_file parameter (GH-108125)
This feature is off by default via code but on by default via the CLI. The `.gitignore` file contains `*` which causes the entire directory to be ignored.

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
2023-09-15 22:38:08 +00:00
Hood Chatham 6b179adb8c
gh-106213: Make Emscripten trampolines work with JSPI (GH-106219)
There is a WIP proposal to enable webassembly stack switching which have been
implemented in v8:

https://github.com/WebAssembly/js-promise-integration

It is not possible to switch stacks that contain JS frames so the Emscripten JS
trampolines that allow calling functions with the wrong number of arguments
don't work in this case. However, the js-promise-integration proposal requires
the [type reflection for Wasm/JS API](https://github.com/WebAssembly/js-types)
proposal, which allows us to actually count the number of arguments a function
expects.

For better compatibility with stack switching, this PR checks if type reflection
is available, and if so we use a switch block to decide the appropriate
signature. If type reflection is unavailable, we should use the current EMJS
trampoline.

We cache the function argument counts since when I didn't cache them performance
was negatively affected.

Co-authored-by: T. Wouters <thomas@python.org>
Co-authored-by: Brett Cannon <brett@python.org>
2023-09-15 15:04:21 -07:00
Gregory P. Smith 59073c9ab8
gh-109096: Deprecate http.server.CGIHTTPRequestHandler (#109387)
Deprecate `http.server.CGIHTTPRequestHandler`.

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-09-15 14:26:45 -07:00
Victor Stinner 74c72a2fc7
gh-109425: regrtest decodes worker stdout with backslashreplace (#109428)
libregrtest now decodes stdout of test worker processes with the
"backslashreplace" error handler to log corrupted stdout, instead of
failing with an error and not logging the stdout.
2023-09-14 23:37:37 +00:00
buermarc 68a6f21f47
gh-109375: Fix bug where pdb registers an alias without an associated command (#109376) 2023-09-14 22:31:30 +01:00
Victor Stinner e091b9f20f
gh-109396: Fix test_socket.test_hmac_sha1() in FIPS mode (#109423)
Use a longer key: FIPS mode requires at least of at least 112 bits.
The previous key was only 32 bits.
2023-09-14 21:24:11 +00:00
Carl Meyer 909adb5092
gh-109219: propagate free vars through type param scopes (#109377)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-09-14 10:20:32 -06:00
Irit Katriel 4a54074a0f
gh-105658: fix excess trace events for except block ending with a conditional block (#109384) 2023-09-14 17:06:08 +01:00
Brandt Bucher 22e65eecaa
GH-105848: Replace KW_NAMES + CALL with LOAD_CONST + CALL_KW (GH-109300) 2023-09-13 10:25:45 -07:00
Jelle Zijlstra 987b4bc087
gh-109341: Fix crash on compiling invalid AST including TypeAlias (#109349) 2023-09-13 09:00:39 -07:00
Jelle Zijlstra 79101edb03
gh-109351: Fix crash when compiling AST with invalid NamedExpr (#109352) 2023-09-13 09:00:15 -07:00
Tian Gao d69805b38a
gh-109156: Add tests for de-instrumenting instructions with instrumented lines (GH-109157) 2023-09-13 09:47:35 +01:00
Victor Stinner 44d9a71ea2
gh-104736: Fix test_gdb tests on ppc64le with clang (#109360)
Fix test_gdb on Python built with LLVM clang 16 on Linux ppc64le (ex:
Fedora 38). Search patterns in gdb "bt" command output to detect
when gdb fails to retrieve the traceback. For example, skip a test if
"Backtrace stopped: frame did not save the PC" is found.
2023-09-13 04:24:32 +00:00
Irit Katriel b303d3ad3e
gh-109319: deprecate dis.HAVE_ARGUMENT (#109320) 2023-09-12 16:45:35 +01:00
Nikita Sobolev 66d1d7eb06
gh-84867: Do not load tests from TestCase and FunctionTestCase (GH-100497) 2023-09-12 16:33:30 +03:00
Irit Katriel 8b55adfa8f
gh-109256: allocate opcode IDs for internal opcodes in their own range (#109269) 2023-09-12 10:36:17 +00:00
Nikita Sobolev 247ee1bf84
gh-109216: Fix possible memory leak in BUILD_MAP (#109257) 2023-09-12 15:07:22 +05:30
Victor Stinner a84cb74d42
gh-109276: libregrtest calls random.seed() before each test (#109279)
libregrtest now calls random.seed() before running each test file
when -r/--randomize command line option is used. Moreover, it's also
called in worker processes. It should help to make tests more
deterministic. Previously, it was only called once in the main
process before running all test files and it was not called in worker
processes.

* Convert some f-strings to regular strings in test_regrtest when
  f-string is not needed.
* Remove unused all_methods variable from test_regrtest.
* Add RunTests members are now mandatory.
2023-09-12 05:35:08 +02:00
Tian Gao 391f3e3ca9
GH-106734: Disable tab completion in pdb's multiline mode (GH-106735) 2023-09-11 18:28:43 -07:00
Jelle Zijlstra b88d9e75f6
gh-109118: Disallow nested scopes within PEP 695 scopes within classes (#109196)
Fixes #109118. Fixes #109194.

Co-authored-by: Carl Meyer <carl@oddbird.net>
2023-09-11 17:11:06 -07:00
Carl Meyer ceeb4173ae
gh-109195: fix source location for super load before LOAD_SUPER_ATTR (#109289) 2023-09-11 17:35:49 -06:00
Irit Katriel ecd21a629a
gh-109179: Fix traceback display for SyntaxErrors with notes (#109197) 2023-09-11 19:18:34 +01:00
Victor Stinner de5f8f7d13
gh-109276: libregrtest: use separated file for JSON (#109277)
libregrtest now uses a separated file descriptor to write test result
as JSON.  Previously, if a test wrote debug messages late around the
JSON, the main test process failed to parse JSON.

Rename TestResult.write_json() to TestResult.write_json_into().

worker_process() no longer writes an empty line at the end. There is
no need to separate test process output from the JSON output anymore,
since JSON is now written into a separated file descriptor.

create_worker_process() now always spawn the process with
close_fds=True.
2023-09-11 19:33:42 +02:00
Victor Stinner 517cd82ea7
gh-108987: Fix _thread.start_new_thread() race condition (#109135)
Fix _thread.start_new_thread() race condition. If a thread is created
during Python finalization, the newly spawned thread now exits
immediately instead of trying to access freed memory and lead to a
crash.

thread_run() calls PyEval_AcquireThread() which checks if the thread
must exit. The problem was that tstate was dereferenced earlier in
_PyThreadState_Bind() which leads to a crash most of the time.

Move _PyThreadState_CheckConsistency() from thread_run() to
_PyThreadState_Bind().
2023-09-11 17:27:03 +02:00
Mark Shannon 4a69301ea4
GH-108976. Keep monitoring data structures valid during de-optimization during callback. (GH-109131) 2023-09-11 14:37:09 +01:00
Victor Stinner a9b1f84790
gh-107219: Fix concurrent.futures terminate_broken() (#109244)
Fix a race condition in concurrent.futures. When a process in the
process pool was terminated abruptly (while the future was running or
pending), close the connection write end. If the call queue is
blocked on sending bytes to a worker process, closing the connection
write end interrupts the send, so the queue can be closed.

Changes:

* _ExecutorManagerThread.terminate_broken() now closes
  call_queue._writer.
* multiprocessing PipeConnection.close() now interrupts
  WaitForMultipleObjects() in _send_bytes() by cancelling the
  overlapped operation.
2023-09-11 08:11:31 +00:00