Commit graph

8182 commits

Author SHA1 Message Date
sobolevn
492a554cfc
[3.12] gh-130775: Allow negative locations in ast (GH-130795) (#132260)
(cherry picked from commit bc5233b6a5)

Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-04-08 10:19:23 +00:00
Miss Islington (bot)
55b230333f
[3.12] GH-107674: Avoid allocating boxed ints for sys.settrace line events (GH-107780) (#107841)
GH-107674: Avoid allocating boxed ints for `sys.settrace` line events (GH-107780)
(cherry picked from commit 37d8b904f8)

Co-authored-by: Mark Shannon <mark@hotpy.org>
2025-04-06 19:48:53 +00:00
Tomasz Pytel
3d3e7b0ada
[3.12] gh-128632: fix segfault on nested __classdict__ type param (GH… (#132090)
(cherry picked from commit 891c61c1fa)

Co-authored-by: Tomasz Pytel <tompytel@gmail.com>
2025-04-04 15:48:57 +00:00
Miss Islington (bot)
b3cf1f27e9
[3.12] gh-132002: Fix crash of ContextVar on unhashable str subtype (GH-132003) (#132008)
gh-132002: Fix crash of `ContextVar` on unhashable `str` subtype (GH-132003)
(cherry picked from commit ab2a3dda1d)

Co-authored-by: sobolevn <mail@sobolevn.me>
2025-04-02 12:05:30 +00:00
Miss Islington (bot)
0c88f414b8
[3.12] gh-131818: Add imply -P in -I's help message (GH-131819) (#131823)
gh-131818: Add imply `-P` in `-I`'s help message (GH-131819)
(cherry picked from commit 8bd88e2827)

Co-authored-by: Hang <bebound@gmail.com>
2025-03-28 08:09:03 +00:00
Miss Islington (bot)
76e911a040
[3.12] gh-131670: Fix crash in anext() when __anext__ is sync and raises (GH-131682) (#131687)
gh-131670: Fix crash in `anext()` when `__anext__` is sync and raises (GH-131682)
(cherry picked from commit 929afd1d6e)

Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-03-24 19:18:29 +00:00
Victor Stinner
3f226c5a7f
[3.12] gh-131082: Add missing guards for WIN32_LEAN_AND_MEAN (#131044) (#131085)
gh-131082: Add missing guards for WIN32_LEAN_AND_MEAN (#131044)

(cherry picked from commit de8818ae23)

Co-authored-by: Max Bachmann <kontakt@maxbachmann.de>
2025-03-11 11:55:13 +00:00
Bénédikt Tran
7ce5f15981
[3.12] gh-130740: Move some stdbool.h includes after Python.h (#130738) (#130757)
gh-130740: Move some `stdbool.h` includes after `Python.h` (#130738)

Move some `#include <stdbool.h>` after `#include "Python.h"` when `pyconfig.h` is not
included first and when we are in a platform-agnostic context. This is to avoid having
features defined by `stdbool.h` before those decided by `Python.h` (this caused some
build failures when compiling CPython with `zig cc`).

(cherry-picked from commit 214562ed4d)

---------

Co-authored-by: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
2025-03-04 10:38:24 +01:00
Serhiy Storchaka
89a79fc919
[3.12] gh-130163: Fix crashes related to PySys_GetObject() (GH-130503) (GH-130556) (GH-130576)
The use of PySys_GetObject() and _PySys_GetAttr(), which return a borrowed
reference, has been replaced by using one of the following functions, which
return a strong reference and distinguish a missing attribute from an error:
_PySys_GetOptionalAttr(), _PySys_GetOptionalAttrString(),
_PySys_GetRequiredAttr(), and _PySys_GetRequiredAttrString().

(cherry picked from commit 0ef4ffeefd)
(cherry picked from commit 7c1b76fce8)
(cherry picked from commit 2ab7e1135a)
2025-02-26 17:20:47 +02:00
sobolevn
f841099dc0
[3.12] gh-107526: Revert "gh-100357: Convert several functions in bltinsmodule to AC" (GH-107542) (#130371) 2025-02-26 12:27:33 +03:00
Miss Islington (bot)
40d7f745e9
[3.12] gh-126108: Fix potential null pointer dereference in PySys_AddWarnOptionUnicode (GH-126118) (#129522)
gh-126108: Fix potential null pointer dereference in `PySys_AddWarnOptionUnicode` (GH-126118)
(cherry picked from commit fad36bf382)

Co-authored-by: Valery Fedorenko <federicovalenso@gmail.com>
2025-01-31 20:32:30 +05:30
Irit Katriel
d2f551db12
[3.12] gh-128799: Add frame of except* to traceback when wrapping a naked exception (GH-128971) (#129328) 2025-01-30 12:02:46 +00:00
Victor Stinner
bb7c54d5ba
[3.12] gh-129185: Fix PyTraceMalloc_Untrack() at Python exit (#129191) (#129217) (#129221)
[3.13] gh-129185: Fix PyTraceMalloc_Untrack() at Python exit (#129191) (#129217)

gh-129185: Fix PyTraceMalloc_Untrack() at Python exit (#129191)

Support calling PyTraceMalloc_Track() and PyTraceMalloc_Untrack()
during late Python finalization.

* Call _PyTraceMalloc_Fini() later in Python finalization.
* Test also PyTraceMalloc_Untrack() without the GIL
* PyTraceMalloc_Untrack() now gets the GIL.
* Test also PyTraceMalloc_Untrack() in test_tracemalloc_track_race().

(cherry picked from commit 46c7e13c05)
(cherry picked from commit e3b3e01d6a)
2025-01-23 13:29:46 +00:00
Victor Stinner
6df22cbf60
[3.12] gh-128679: Fix tracemalloc.stop() race conditions (#128897) (#129022)
[3.13] gh-128679: Fix tracemalloc.stop() race conditions (#128897)

tracemalloc_alloc(), tracemalloc_realloc(), PyTraceMalloc_Track(),
PyTraceMalloc_Untrack() and _PyTraceMalloc_TraceRef() now check
tracemalloc_config.tracing after calling TABLES_LOCK().

_PyTraceMalloc_Stop() now protects more code with TABLES_LOCK(),
especially setting tracemalloc_config.tracing to 1.

Add a test using PyTraceMalloc_Track() to test tracemalloc.stop()
race condition.

Call _PyTraceMalloc_Init() at Python startup.

(cherry picked from commit 6b47499510)
2025-01-19 13:24:14 +00:00
Miss Islington (bot)
f65ac86ca1
[3.12] gh-128049: Fix type confusion bug with the return value of a custom ExceptionGroup split function (GH-128079) (#128140)
gh-128049: Fix type confusion bug with the return value of a custom ExceptionGroup split function (GH-128079)
(cherry picked from commit 3879ca0100)

Co-authored-by: Nico-Posada <102486290+Nico-Posada@users.noreply.github.com>
2024-12-20 20:19:12 +00:00
Bénédikt Tran
e0b61ffa38
[3.12] gh-126742: Add _PyErr_SetLocaleString, use it for gdbm & dlerror messages (GH-126746) (GH-128027)
- Add a helper to set an error from locale-encoded `char*`
- Use the helper for gdbm & dlerror messages

Co-authored-by: Victor Stinner <vstinner@python.org>
2024-12-17 14:53:16 +02:00
Nice Zombies
487a51a1b9
[3.12] gh-111609: end_offset is ignored in subclasses of SyntaxError (#127554)
* `end_offset` is ignored in subclasses of SyntaxError

* 📜🤖 Added by blurb_it.

* Add test

---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2024-12-11 09:09:34 +00:00
Miss Islington (bot)
49da170709
[3.12] gh-116510: Fix a Crash Due to Shared Immortal Interned Strings (gh-125205)
Fix a crash caused by immortal interned strings being shared between
sub-interpreters that use basic single-phase init. In that case, the string
can be used by an interpreter that outlives the interpreter that created and
interned it. For interpreters that share obmalloc state, also share the
interned dict with the main interpreter.

This is an un-revert of gh-124646 that then addresses the Py_TRACE_REFS
failures identified by gh-124785 (i.e. backporting gh-125709 too).

(cherry picked from commit f2cb399470, AKA gh-124865)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2024-12-03 10:26:25 -07:00
Victor Stinner
e7ab97862d
[3.12] gh-127208: Reject null character in _imp.create_dynamic() (#127400) (#127419)
gh-127208: Reject null character in _imp.create_dynamic() (#127400)

_imp.create_dynamic() now rejects embedded null characters in the
path and in the module name.

Backport also the _PyUnicode_AsUTF8NoNUL() function.

(cherry picked from commit b14fdadc6c)
2024-11-29 17:03:24 +01:00
Victor Stinner
f4c9f39165
[3.12] gh-123967: Fix faulthandler for trampoline frames (#127329) (#127363)
gh-123967: Fix faulthandler for trampoline frames (#127329)

If the top-most frame is a trampoline frame, skip it.

(cherry picked from commit 58e334e143)
2024-11-28 13:57:35 +00:00
Serhiy Storchaka
f1e7424802
[3.12] gh-109746: Make _thread.start_new_thread delete state of new thread on its startup failure (GH-109761) (GH-127173)
If Python fails to start newly created thread
due to failure of underlying PyThread_start_new_thread() call,
its state should be removed from interpreter' thread states list
to avoid its double cleanup.

(cherry picked from commit ca3ea9ad05)

Co-authored-by: Radislav Chugunov <52372310+chgnrdv@users.noreply.github.com>
2024-11-22 19:56:39 +00:00
Miss Islington (bot)
fc1e9e606b
[3.12] gh-126171: fix possible null dereference in _imp_find_frozen_impl (GH-126566) (#126568)
gh-126171: fix possible null dereference in _imp_find_frozen_impl (GH-126566)
(cherry picked from commit 9ecd8f7f40)

Co-authored-by: Valery Fedorenko <federicovalenso@gmail.com>
2024-11-08 16:26:08 +05:30
Valery Fedorenko
2f39370f4a
[3.12] Fix possible null pointer dereference of freevars in _PyCompile_LookupArg (gh-126238) (#126474)
[3.12] gh-126238: Fix possible null pointer dereference of freevars in _PyCompile_LookupArg (GH-126239)

* Replace Py_DECREF by Py_XDECREF

(cherry picked from commit 8525c9375f)

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2024-11-06 07:56:12 +00:00
Donghee Na
4afa129ed0
[3.12] gh-125832: Clarify comment for inlined comprehensions as per P… (gh-126345)
* [3.12] gh-125832: Clarify comment for inlined comprehensions as per PEP-709 (gh-126322)

* Fix comprehensions comment to inlined by pep 709

* Update spacing

Co-authored-by: RUANG (James Roy) <longjinyii@outlook.com>

* Add reference to PEP 709

---------

Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
Co-authored-by: RUANG (James Roy) <longjinyii@outlook.com>

* Add space

---------

Co-authored-by: rimchoi <hyerimc858@gmail.com>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
Co-authored-by: RUANG (James Roy) <longjinyii@outlook.com>
2024-11-03 04:00:52 +00:00
Brian Schubert
e5c7543f12
[3.12] gh-126139: Improve error message location for future statement with unknown feature (GH-126140) (#126160)
(cherry picked from commit 224c370a36)
2024-10-30 00:54:32 +00:00
Kirill Podoprigora
515a5d3498
[3.12] gh-126105: Fix crash in ast module, when ._fields is delet… (#126132)
[3.12] gh-126105: Fix crash in `ast` module, when `._fields` is deleted (GH-126115)

Previously, if the `ast.AST._fields` attribute was deleted, attempts to create a new `as`t node would crash due to the assumption that `_fields` always had a non-NULL value. Now it has been fixed by adding an extra check to ensure that `_fields` does not have a NULL value (this can happen when you manually remove `_fields` attribute).
(cherry picked from commit b2eaa75b17)

Co-authored-by: sobolevn <mail@sobolevn.me>
2024-10-29 20:20:40 +02:00
Petr Viktorin
49f6beb56a
[3.12] gh-113993: Make interned strings mortal (GH-120520, GH-121364, GH-121903, GH-122303) (#123065)
This backports several PRs for gh-113993, making interned strings mortal so they can be garbage-collected when no longer needed.

* Allow interned strings to be mortal, and fix related issues (GH-120520)

  * Add an InternalDocs file describing how interning should work and how to use it.

  * Add internal functions to *explicitly* request what kind of interning is done:
    - `_PyUnicode_InternMortal`
    - `_PyUnicode_InternImmortal`
    - `_PyUnicode_InternStatic`

  * Switch uses of `PyUnicode_InternInPlace` to those.

  * Disallow using `_Py_SetImmortal` on strings directly.
    You should use `_PyUnicode_InternImmortal` instead:
    - Strings should be interned before immortalization, otherwise you're possibly
      interning a immortalizing copy.
    - `_Py_SetImmortal` doesn't handle the `SSTATE_INTERNED_MORTAL` to
      `SSTATE_INTERNED_IMMORTAL` update, and those flags can't be changed in
      backports, as they are now part of public API and version-specific ABI.

  * Add private `_only_immortal` argument for `sys.getunicodeinternedsize`, used in refleak test machinery.

   Make sure the statically allocated string singletons are unique. This means these sets are now disjoint:
    - `_Py_ID`
    - `_Py_STR` (including the empty string)
    - one-character latin-1 singletons

    Now, when you intern a singleton, that exact singleton will be interned.

  * Add a `_Py_LATIN1_CHR` macro, use it instead of `_Py_ID`/`_Py_STR` for one-character latin-1 singletons everywhere (including Clinic).

  * Intern `_Py_STR` singletons at startup.

  * Beef up the tests. Cover internal details (marked with `@cpython_only`).

  * Add lots of assertions

* Don't immortalize in PyUnicode_InternInPlace; keep immortalizing in other API (GH-121364)

  * Switch PyUnicode_InternInPlace to _PyUnicode_InternMortal, clarify docs

  * Document immortality in some functions that take `const char *`

  This is PyUnicode_InternFromString;
  PyDict_SetItemString, PyObject_SetAttrString;
  PyObject_DelAttrString; PyUnicode_InternFromString;
  and the PyModule_Add convenience functions.

  Always point out a non-immortalizing alternative.

  * Don't immortalize user-provided attr names in _ctypes

* Immortalize names in code objects to avoid crash (GH-121903)

* Intern latin-1 one-byte strings at startup (GH-122303)

There are some 3.12-specific changes, mainly to allow statically allocated strings in deepfreeze. (In 3.13, deepfreeze switched to the general `_Py_ID`/`_Py_STR`.)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2024-09-27 13:28:48 -07:00
Serhiy Storchaka
18542240c2
[3.12] gh-124188: Fix PyErr_ProgramTextObject() (GH-124189) (GH-124426)
* Detect source file encoding.
* Use the "replace" error handler even for UTF-8 (default) encoding.
* Remove the BOM.
* Fix detection of too long lines if they contain NUL.
* Return the head rather than the tail for truncated long lines.
(cherry picked from commit e2f710792b)
2024-09-24 08:53:54 +00:00
Miss Islington (bot)
ffde4cddc9
[3.12] gh-98442: fix locations of with statement's cleanup instructions (GH-120763) (#120787)
gh-98442: fix locations of with statement's cleanup instructions (GH-120763)
(cherry picked from commit 55596ae044)


gh-98442: fix location of with statement's cleanup instructions

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2024-09-15 19:14:19 +00:00
Miss Islington (bot)
1248524940
[3.12] gh-123892: Add "_wmi" to sys.stdlib_module_names (GH-123893) (#123897)
gh-123892: Add "_wmi" to sys.stdlib_module_names (GH-123893)
(cherry picked from commit fb1b51a58d)

Co-authored-by: Victor Stinner <vstinner@python.org>
2024-09-10 10:11:56 +00:00
Miss Islington (bot)
22ec9cb823
[3.12] gh-93691: fix too broad source locations of with-statement instructions (GH-120125) (#123605)
gh-93691: fix too broad source locations of with-statement instructions (GH-120125)
(cherry picked from commit eca3f7762c)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2024-09-02 14:45:09 +00:00
Irit Katriel
0181aa2e3e
[3.12] gh-123142: fix too wide source location of GET_ITER/GET_AITER (GH-123420). (#123436)
(cherry picked from commit 61bef6245c)
2024-08-28 18:41:40 +01:00
Donghee Na
6e6855950a
[3.12] gh-123083: Fix a potential use-after-free in ``STORE_ATTR_WITH… (#123237)
[3.12] gh-123083: Fix a potential use-after-free in ``STORE_ATTR_WITH_HINT`` (gh-123092)
(cherry picked from commit 297f2e093e)
2024-08-23 01:37:40 +09:00
Irit Katriel
fbbde4dc6a
[3.12] gh-123142: Fix too wide source locations in tracebacks of exceptions from broken iterables in comprehensions (GH-123173). (#123210)
(cherry picked from commit ec89620e5e)
2024-08-22 10:22:43 +01:00
Serhiy Storchaka
f2cc8ad989
[3.12] gh-118814: Fix the TypeVar constructor when name is passed by keyword (GH-122664) (GH-122807)
Fix _PyArg_UnpackKeywordsWithVararg for the case when argument for
positional-or-keyword parameter is passed by keyword.
There was only one such case in the stdlib -- the TypeVar constructor.
(cherry picked from commit 540fcc62f5)
2024-08-08 09:49:50 +03:00
neonene
6b8a9a1061
[3.12] gh-122334: Fix crash when importing ssl after re-initialization (GH-122481) (#122495)
Fix crash when importing ssl after re-initialization

The current METH_FASTCALL|METH_KEYWORDS functions in a non-builtin module can cause segfaults after restarting the main interpreter, invoking _PyArg_UnpackKeywords() with an insufficiently cleared _PyArg_Parser struct.

This patch fixes the invalidation of the static argument parsers.
2024-08-02 13:44:55 +00:00
Miss Islington (bot)
257c413cd1
[3.12] gh-122029: Log call events in sys.setprofile when it's a method with c function (GH-122072) (GH-122206)
gh-122029: Log call events in sys.setprofile when it's a method with c function (GH-122072)

Log call events in sys.setprofile when it is a method with a C function.
(cherry picked from commit e91ef13861)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
2024-07-23 22:44:43 +00:00
Serhiy Storchaka
39dea212f4
[3.12] gh-121905: Consistently use "floating-point" instead of "floating point" (GH-121907) (GH-122013)
(cherry picked from commit 1a0c7b9ba4)
2024-07-19 09:08:33 +00:00
Serhiy Storchaka
874eed6cfe
[3.12] gh-121153: Fix some errors with use of _PyLong_CompactValue() (GH-121154)
* The result has type Py_ssize_t, not intptr_t.
* Type cast between unsigned and signed integer types should be explicit.
* Downcasting should be explicit.
* Fix integer overflow check in sum().
(cherry picked from commit 1801545)
2024-07-17 07:58:25 +00:00
Kirill Podoprigora
b455a5a55c
[3.12] gh-121657: Display correct error message for yield from outsid… (GH-121769)
(cherry picked from commit 178e44de8f)

Co-authored-by: Gregor <36135323+gege-hoho@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-07-15 21:26:10 +02:00
Miss Islington (bot)
9e542f9a46
[3.12] gh-121390: tracemalloc: Fix tracebacks memory leak (GH-121391) (#121393)
gh-121390: tracemalloc: Fix tracebacks memory leak (GH-121391)

The tracemalloc_tracebacks hash table has traceback keys and NULL
values, but its destructors do not reflect this -- key_destroy_func is
NULL while value_destroy_func is raw_free. Swap these to free the
traceback keys instead.
(cherry picked from commit db39bc42f9)

Co-authored-by: Josh Brobst <jbrobst@proton.me>
2024-07-05 06:59:06 +00:00
Miss Islington (bot)
b1bccab588
[3.12] gh-120811: Fix reference leak upon _PyContext_Exit failure (GH-120812) (#120844)
gh-120811: Fix reference leak upon `_PyContext_Exit` failure (GH-120812)
(cherry picked from commit aed31beca9)

Co-authored-by: Peter <zintensitydev@gmail.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2024-06-22 16:44:31 +05:30
Jelle Zijlstra
d62cbba235
[3.12] gh-120722: Set position on RETURN_VALUE in lambda (GH-120724) (#120739)
(cherry picked from commit d8f27cb114)
2024-06-19 13:19:39 +00:00
Irit Katriel
5d997b5d4e
[3.12] gh-119897: Revert buggy optimization which was removed in 3.13 (#120467) 2024-06-18 10:45:40 +01:00
Irit Katriel
5a6cc3c67f
[3.12] gh-93691: fix too broad source locations of for statement iterators (GH-120330 (#120405)
[3.12] gh-93691: fix too broad source locations of for statement iterators (GH-120330).
(cherry picked from commit 97b69db167)
2024-06-13 11:38:36 +01:00
Miss Islington (bot)
f75abf8bcf
[3.12] gh-120343: Fix column offsets of multiline tokens in tokenize (GH-120391) (#120428)
(cherry picked from commit 4b5d3e0e72)

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
2024-06-12 19:10:35 +00:00
Miss Islington (bot)
0315fdc24d
[3.12] gh-120343: Do not reset byte_col_offset_diff after multiline tokens (GH-120352) (#120356)
(cherry picked from commit 1b62bcee94)

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2024-06-11 17:22:16 +00:00
Miss Islington (bot)
82c93ea55a
[3.12] gh-119666: fix multiple class-scope comprehensions referencing __class__ (GH-120295) (#120300) 2024-06-10 00:37:15 -04:00
Victor Stinner
b3b5278475
[3.12] gh-120155: Fix optimize_and_assemble_code_unit() error handling (#120231)
gh-120155: Fix optimize_and_assemble_code_unit() error handling

Don't use 'g' before it's being initialized: don't use the 'error'
label if consts_dict_keys_inorder() failed.

Fix the Coverity issue:

Error: UNINIT (CWE-457):
Python-3.12.2/Python/compile.c:7670:5: skipped_decl: Jumping over declaration of ""g"".
Python-3.12.2/Python/compile.c:7714:5: uninit_use_in_call: Using uninitialized value ""g.g_block_list"" when calling ""_PyCfgBuilder_Fini"".
Python-3.12.2/Python/compile.c:7714:5: uninit_use_in_call: Using uninitialized value ""g.g_entryblock"" when calling ""_PyCfgBuilder_Fini"".
  7712|       Py_XDECREF(consts);
  7713|       instr_sequence_fini(&optimized_instrs);
  7714|->     _PyCfgBuilder_Fini(&g);
  7715|       return co;
  7716|   }
2024-06-07 17:17:06 +02:00
Jelle Zijlstra
dc40226ea1
[3.12] gh-119311: Fix name mangling with PEP 695 generic classes (#119464) (#119644)
* [3.12] gh-119311: Fix name mangling with PEP 695 generic classes (#119464)

Fixes #119311. Fixes #119395.

(cherry picked from commit a9a74da4a0)
2024-06-04 19:55:45 +00:00