Commit graph

8091 commits

Author SHA1 Message Date
Pablo Galindo Salgado
11232c1299
[3.12] gh-112367: Only free perf trampoline arenas at shutdown (GH-112368) (#112590)
(cherry picked from commit a73aa48e6b)

Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
2023-12-01 16:05:31 +00:00
Dennis Sweeney
a99305e7fb
[3.12] gh-112356: LOAD_GLOBAL can only include one PUSH_NULL (#112566) 2023-12-01 00:35:49 +00:00
Eric Snow
1e1a30f9f4
[3.12] gh-110310: Add a Per-Interpreter XID Registry for Heap Types (gh-110311) (gh-110714)
We do the following:

* add a per-interpreter XID registry (PyInterpreterState.xidregistry)
* put heap types there (keep static types in _PyRuntimeState.xidregistry)
* clear the registries during interpreter/runtime finalization
* avoid duplicate entries in the registry (when _PyCrossInterpreterData_RegisterClass() is called more than once for a type)
* use Py_TYPE() instead of PyObject_Type() in _PyCrossInterpreterData_Lookup()

The per-interpreter registry helps preserve isolation between interpreters.  This is important when heap types are registered, which is something we haven't been doing yet but I will likely do soon.

(cherry-picked from commit 80dc39e1dc)
2023-11-28 02:36:29 +00:00
Eric Snow
0122b4d7c9
[3.12] gh-105716: Support Background Threads in Subinterpreters Consistently (gh-109921) (gh-110707)
The existence of background threads running on a subinterpreter was preventing interpreters from getting properly destroyed, as well as impacting the ability to run the interpreter again. It also affected how we wait for non-daemon threads to finish.

We add PyInterpreterState.threads.main, with some internal C-API functions.

(cherry-picked from commit 1dd9dee45d)
2023-11-27 19:01:05 -07:00
Eric Snow
82ae5a609d
[3.12] gh-109793: Allow Switching Interpreters During Finalization (gh-109794) (gh-110705)
Essentially, we should check the thread ID rather than the thread state pointer.
2023-11-28 00:58:02 +00:00
Eric Snow
4f71f1680d
[3.12] gh-106931: Intern Statically Allocated Strings Globally (gh-107272) (gh-110713)
We tried this before with a dict and for all interned strings.  That ran into problems due to interpreter isolation.  However, exclusively using a per-interpreter cache caused some inconsistency that can eliminate the benefit of interning.  Here we circle back to using a global cache, but only for statically allocated strings.  We also use a more-basic _Py_hashtable_t for that global cache instead of a dict.

Ideally we would only have the global cache, but the optional isolation of each interpreter's allocator means that a non-static string object must not outlive its interpreter.  Thus we would have to store a copy of each such interned string in the global cache, tied to the main interpreter.

(cherry-picked from commit b72947a8d2)
2023-11-27 23:51:12 +00:00
Eric Snow
313554457e
[3.12] gh-109853: Fix sys.path[0] For Subinterpreters (gh-109994) (gh-110701)
This change makes sure sys.path[0] is set properly for subinterpreters.  Before, it wasn't getting set at all.

This change does not address the broader concerns from gh-109853.

(cherry-picked from commit a040a32ea2)
2023-11-27 22:21:12 +00:00
Eric Snow
592a849fdf
[3.12] gh-76785: Use Pending Calls When Releasing Cross-Interpreter Data (gh-109556) (gh-112288)
This fixes some crashes in the _xxinterpchannels module, due to a race between interpreters.
(cherry picked from commit fd7e08a6f3)
2023-11-27 14:49:48 -07:00
Miss Islington (bot)
46047bb12b
[3.12] gh-112438: Fix support of format units with the "e" prefix in nested tuples in PyArg_Parse (gh-112439) (GH-112460)
(cherry picked from commit 4eea1e8236)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-11-27 17:57:30 +00:00
Miss Islington (bot)
dfdbfc548f
gh-111856: Fix os.fstat on windows with FAT32 and exFAT filesystem (GH-112038)
(cherry picked from commit 29af7369db)

Co-authored-by: AN Long <aisk@users.noreply.github.com>
2023-11-13 16:25:01 +00:00
Miss Islington (bot)
158a7e1acd
[3.12] gh-111933: fix broken link to A.Neumaier article (gh-111937) (gh-111993) 2023-11-12 01:22:44 +00:00
Victor Stinner
4b0c875d91
[3.12] gh-109181: Fix refleak in tb_get_lineno() (#111948)
PyFrame_GetCode() returns a strong reference.
2023-11-10 14:07:45 +01:00
Jelle Zijlstra
1a95ad68b4
[3.12] gh-111654: remove redundant decref in LOAD_FROM_DICT_OR_DEREF (GH-111655) (#111674)
(cherry picked from commit 3a1b09e6d0)

Co-authored-by: AN Long <aisk@users.noreply.github.com>
2023-11-03 07:02:07 -07:00
Pablo Galindo Salgado
4f619e83fe
[3.12] gh-109181: Speed up Traceback object creation by lazily compute the line number (GH-111548) (#111551)
.
(cherry picked from commit abb15420c1)
2023-10-31 18:18:11 +00:00
Pablo Galindo Salgado
c81ebf5b3d
[3.12] bpo-43950: handle wide unicode characters in tracebacks (GH-28150) (#111346) 2023-10-27 06:43:38 +09:00
Nikita Sobolev
b6755d81d4
[3.12] gh-109216: Fix possible memory leak in BUILD_MAP (#109324) 2023-10-15 07:08:40 +05:30
Miss Islington (bot)
dae3db1883
[3.12] gh-110514: Add PY_THROW to sys.setprofile events (GH-110524) (#110541)
gh-110514: Add PY_THROW to `sys.setprofile` events (GH-110524)
(cherry picked from commit dd4bb0529e)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
2023-10-09 09:11:51 +00:00
Miss Islington (bot)
ef4bd1b57f
[3.12] gh-110237: Check PyList_Append for errors in _PyEval_MatchClass (GH-110238) (#110511)
gh-110237: Check `PyList_Append` for errors in `_PyEval_MatchClass` (GH-110238)
(cherry picked from commit dd9d781da3)

Co-authored-by: denballakh <47365157+denballakh@users.noreply.github.com>
2023-10-08 00:40:38 +00:00
Miss Islington (bot)
2465fe0014
[3.12] GH-110455: Guard assert(tstate->thread_id > 0) with GH-ifndef HAVE_PTHREAD_STUBS (GH-110487) (GH-110491)
GH-110455: Guard `assert(tstate->thread_id > 0)` with `GH-ifndef HAVE_PTHREAD_STUBS` (GH-110487)
(cherry picked from commit 5fd8821cf8)

Co-authored-by: Brett Cannon <brett@python.org>
2023-10-06 23:48:48 +00:00
Victor Stinner
4936fa9541
[3.12] gh-108987: Fix _thread.start_new_thread() race condition (#109135) (#110342)
* 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().

(cherry picked from commit 517cd82ea7)

* gh-109795: `_thread.start_new_thread`: allocate thread bootstate using raw memory allocator (#109808)

(cherry picked from commit 1b8f2366b3)

---------

Co-authored-by: Radislav Chugunov <52372310+chgnrdv@users.noreply.github.com>
2023-10-04 11:20:31 +00:00
Victor Stinner
d0641ab676
[3.12] gh-110052: Fix faulthandler for freed tstate (#110069) (#110071)
gh-110052: Fix faulthandler for freed tstate (#110069)

faulthandler now detected freed interp and freed tstate, and no
longer dereference them.

(cherry picked from commit 2e37a38bcb)
2023-10-02 17:44:51 +02:00
Miss Islington (bot)
2b96102f29
[3.12] gh-109889: fix compiler's redundant NOP detection to look past NOPs with no lineno when looking for the next instruction's lineno (GH-109987) (#110048)
gh-109889: fix compiler's redundant NOP detection to look past NOPs with no lineno when looking for the next instruction's lineno (GH-109987)
(cherry picked from commit f580edcc6a)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2023-10-02 17:43:16 +02:00
Miss Islington (bot)
5e6e99646e
[3.12] gh-109521: Fix obscure cases handling in PyImport_GetImporter() (GH-109522) (#109777)
gh-109521: Fix obscure cases handling in PyImport_GetImporter() (GH-109522)

PyImport_GetImporter() now sets RuntimeError if it fails to get sys.path_hooks
or sys.path_importer_cache or they are not list and dict correspondingly.

Previously it could return NULL without setting error in obscure cases,
crash or raise SystemError if these attributes have wrong type.
(cherry picked from commit 62c7015e89)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-10-02 17:22:40 +02:00
Miss Islington (bot)
df2cdcf22f
[3.12] Fix error handling in _PySys_UpdateConfig() (GH-109524) (#109550)
Fix error handling in _PySys_UpdateConfig() (GH-109524)
(cherry picked from commit c829975428)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-10-02 16:58:58 +02:00
Miss Islington (bot)
4b2ba3d0b8
[3.12] gh-109351: Fix crash when compiling AST with invalid NamedExpr (GH-109352) (#109379)
gh-109351: Fix crash when compiling AST with invalid NamedExpr (GH-109352)
(cherry picked from commit 79101edb03)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-10-02 16:58:06 +02:00
Irit Katriel
a8431123c2
[3.12] gh-109179: Fix traceback display for SyntaxErrors with notes (#109197) (#109280)
(cherry picked from commit ecd21a629a)
2023-10-02 16:56:34 +02:00
Miss Islington (bot)
be8255ad8c
[3.12] gh-109207: Fix SystemError when printing symtable entry object. (GH-109225) (#109227)
gh-109207: Fix SystemError when printing symtable entry object. (GH-109225)
(cherry picked from commit 4297499696)

Co-authored-by: 云line <31395137+yunline@users.noreply.github.com>
2023-10-02 16:55:41 +02:00
Miss Islington (bot)
1c223ae58d
[3.12] Check the result of PySet_Contains() for error in Python/symtable.c (GH-109146) (#109153)
Check the result of PySet_Contains() for error in Python/symtable.c (GH-109146)
(cherry picked from commit 87a7faf6b6)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-10-02 16:55:24 +02:00
Victor Stinner
30748d36b3
[3.12] gh-104690: thread_run() checks for tstate dangling pointer (#109056) (#109133)
gh-104690: thread_run() checks for tstate dangling pointer (#109056)

thread_run() of _threadmodule.c now calls
_PyThreadState_CheckConsistency() to check if tstate is a dangling
pointer when Python is built in debug mode.

Rename ceval_gil.c is_tstate_valid() to
_PyThreadState_CheckConsistency() to reuse it in _threadmodule.c.

(cherry picked from commit f63d37877a)
2023-10-02 16:55:06 +02:00
Irit Katriel
648198c37f
[3.12] gh-109889: comment out assertion indicating a failed optimization of a redundant NOP (#109899)
* [3.12] gh-109889: comment out assertion indicating a failed optimization of a redundant NOP

* comment out the function to avoid warnings on it being unused
2023-09-26 17:17:32 +02:00
Miss Islington (bot)
538f505a37
[3.12] gh-109823: Adjust labels in compiler when removing an empty basic block which is a jump target (GH-109839) (#109865)
gh-109823: Adjust labels in compiler when removing an empty basic block which is a jump target (GH-109839)
(cherry picked from commit d73c12b88c)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2023-09-26 02:37:52 +02:00
Miss Islington (bot)
633bd6e428
[3.12] gh-109719: Fix missing jump target labels when compiler reorders cold/warm blocks (GH-109734) (#109749)
gh-109719: Fix missing jump target labels when compiler reorders cold/warm blocks (GH-109734)
(cherry picked from commit 7c55399172)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2023-09-24 13:51:30 +02:00
Irit Katriel
107e14820a
[3.12] gh-109627: duplicated small exit blocks need to be assigned jump target labels (#109630) (#109632)
gh-109627: duplicated smalll exit blocks need to be assigned jump target labels (#109630)

(cherry picked from commit 9ccf0545ef)
2023-09-22 15:27:29 +02:00
Miss Islington (bot)
9412a874a7
[3.12] gh-109371: Fix monitoring with instruction events set (gh-109385) (#109542)
gh-109371: Fix monitoring with instruction events set (gh-109385)
(cherry picked from commit 412f5e85d6)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
2023-09-18 17:40:51 +02:00
Miss Islington (bot)
35c633d245
[3.12] gh-109219: propagate free vars through type param scopes (GH-109377) (#109410)
gh-109219: propagate free vars through type param scopes (GH-109377)
(cherry picked from commit 909adb5092)

Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-09-15 00:42:39 +02:00
Irit Katriel
3eae45f94d
[3.12] gh-105658: fix excess trace events for except block ending with a conditional block (#109384) (#109411)
gh-105658: fix excess trace events for except block ending with a conditional block (#109384)

(cherry picked from commit 4a54074a0f)
2023-09-15 00:41:03 +02:00
Miss Islington (bot)
5c7e8c3b72
[3.12] gh-109341: Fix crash on compiling invalid AST including TypeAlias (GH-109349) (#109381)
gh-109341: Fix crash on compiling invalid AST including TypeAlias (GH-109349)
(cherry picked from commit 987b4bc087)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-09-15 00:40:19 +02:00
Miss Islington (bot)
8208657f3d
[3.12] gh-109118: Disallow nested scopes within PEP 695 scopes within classes (GH-109196) (#109297)
gh-109118: Disallow nested scopes within PEP 695 scopes within classes (GH-109196)

Fixes GH-109118. Fixes GH-109194.

(cherry picked from commit b88d9e75f6)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Carl Meyer <carl@oddbird.net>
2023-09-12 16:31:26 +02:00
Miss Islington (bot)
2004e12d8d
[3.12] gh-109195: fix source location for super load before LOAD_SUPER_ATTR (GH-109289) (#109291)
gh-109195: fix source location for super load before LOAD_SUPER_ATTR (GH-109289)
(cherry picked from commit ceeb4173ae)

Co-authored-by: Carl Meyer <carl@oddbird.net>
2023-09-12 16:20:41 +02:00
Mark Shannon
3efe7bc65f
[3.12] GH-108976. Keep monitoring data structures valid during de-optimization during callback. (GH-109131) (#109268)
GH-108976. Keep monitoring data structures valid during de-optimization during callback. (GH-109131)
2023-09-12 16:14:49 +02:00
Jelle Zijlstra
acde502e8a
[3.12] gh-109118: Fix runtime crash when NameError happens in PEP 695 function (GH-109123) (#109173)
* gh-109118: Fix runtime crash when NameError happens in PEP 695 function (#109123)

(cherry picked from commit 17f994174d)

* [3.12] gh-109118: Fix runtime crash when NameError happens in PEP 695 function (GH-109123).
(cherry picked from commit 17f994174d)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-09-12 15:59:09 +02:00
Miss Islington (bot)
af83d1e821
[3.12] gh-106922: Fix error location for constructs with spaces and parentheses (GH-108959) (#109147)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2023-09-08 17:04:28 +00:00
Mark Shannon
7ee021f999
[3.12] GH-108390: Prevent non-local events being set with sys.monitoring.set_local_events() (GH-108420) (#108899)
* GH-108390: Prevent non-local events being set with `sys.monitoring.set_local_events()` (GH-108420)

* Restore generated objects

* Restore size of monitoring arrays in code object for 3.12 ABI compatibility.

* Update ABI file
2023-09-05 11:29:38 +00:00
Miss Islington (bot)
1a15d20b75
[3.12] gh-108654: restore comprehension locals before handling exception (GH-108659) (#108700)
gh-108654: restore comprehension locals before handling exception (GH-108659)
(cherry picked from commit d52c4482a8)

Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
2023-08-31 15:32:17 +02:00
Miss Islington (bot)
3e20303717
[3.12] gh-107913: Fix possible losses of OSError error codes (GH-107930) (#108523)
gh-107913: Fix possible losses of OSError error codes (GH-107930)

Functions like PyErr_SetFromErrno() and SetFromWindowsErr() should be
called immediately after using the C API which sets errno or the Windows
error code.
(cherry picked from commit 2b15536fa9)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-08-27 01:24:40 +02:00
Guido van Rossum
bbdd8895a5
[3.12] gh-108487: Change assert that should've been DEOPT_IF (#108509)
* Remove assert that should've been DEOPT_IF

The assert(method != NULL) in CALL_NO_KW_LIST_APPEND is wrong --
this condition should lead to a deoptimization, and indeed there
is a DEOPT_IF two lines later that will trigger if method == NULL.

This would crash in a devious repro scenario (first seen live
in boto3 tests) when compiled with assertions enabled.
In a production version there is no crash, so impact is limited.

(The crash also appears in main; I will prepare a separate PR.)

* Add back a different assert(self != NULL)

* 📜🤖 Added by blurb_it.

---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2023-08-27 01:22:40 +02:00
Miss Islington (bot)
4ee9454792
[3.12] gh-107901: Fix missing line number on BACKWARD_JUMP at the end of a for loop (GH-108242) (#108275)
gh-107901: Fix missing line number on BACKWARD_JUMP at the end of a for loop (GH-108242)
(cherry picked from commit a1cc74c4ee)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2023-08-22 16:15:34 +02:00
Miss Islington (bot)
238c8d236b
[3.12] gh-107916: Save the error code before decoding the filename in PyErr_SetFromErrnoWithFilename() etc (GH-107929) (#108205)
gh-107916: Save the error code before decoding the filename in PyErr_SetFromErrnoWithFilename() etc (GH-107929)
(cherry picked from commit 80bdebdd85)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-08-21 14:33:46 +02:00
Miss Islington (bot)
97d67e9dab
[3.12] gh-107915: Handle errors in C API functions PyErr_Set*() and PyErr_Format() (GH-107918) (#108134)
* gh-107915: Handle errors in C API functions PyErr_Set*() and PyErr_Format() (GH-107918)

Such C API functions as PyErr_SetString(), PyErr_Format(),
PyErr_SetFromErrnoWithFilename() and many others no longer crash or
ignore errors if it failed to format the error message or decode the
filename. Instead, they keep a corresponding error.
(cherry picked from commit 633ea217a8)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>

* Define PY_SSIZE_T_CLEAN.

---------

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-08-20 23:07:24 +02:00
Steve Dower
ede9895881
[3.12] gh-106242: Fix path truncation in os.path.normpath (GH-106816) (#107981)
* gh-106242: Fix path truncation in os.path.normpath (GH-106816)
* gh-106242: Minor fixup to avoid compiler warnings

---------

Co-authored-by: Finn Womack <flan313@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-08-17 01:19:48 +02:00