Commit graph

7879 commits

Author SHA1 Message Date
Serhiy Storchaka
f699151c87
[3.12] gh-128198: Add missing error checks for usages of PyIter_Next() (GH-128199) (GH-128273)
(cherry picked from commit 5c814c83cd)

Co-authored-by: Yan Yanchii <yyanchiy@gmail.com>
2024-12-26 10:38:48 +00:00
Miss Islington (bot)
320a1dcd97
[3.12] gh-127563: use dk_log2_index_bytes=3 in empty dicts (GH-127568) (GH-127813)
This fixes a UBSan failure (unaligned zero-size memcpy) in `dictobject.c`.
(cherry picked from commit 9af96f4406)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-12-12 12:50:51 +01:00
Miss Islington (bot)
0964f9f184
[3.12] GH-117195: Avoid assertion error in object.__sizeof__ (GH-117220) (#127605)
GH-117195: Avoid assertion error in `object.__sizeof__` (GH-117220)
(cherry picked from commit 406ffb5293)

Co-authored-by: Mark Shannon <mark@hotpy.org>
2024-12-11 12:21:07 +01: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
Miss Islington (bot)
8fffbb0982
[3.12] gh-113841: fix possible undefined division by 0 in _Py_c_pow() (GH-127211) (GH-127216) (GH-127530)
[3.13] gh-113841: fix possible undefined division by 0 in _Py_c_pow() (GH-127211) (GH-127216)

Note, that transformed expression is not an equivalent for original one (1/exp(-x) != exp(x) in general for floating-point numbers). Though, the difference seems to be ~1ULP for good libm implementations.

It's more interesting why division was used from beginning. Closest algorithm I've found (no error checks, of course;)) - it's Algorithm 190 from ACM: https://dl.acm.org/doi/10.1145/366663.366679. It uses subtraction in the exponent.

(cherry picked from commit f7bb658124)

(cherry picked from commit f41d8d89e7)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
2024-12-02 19:47:42 +00:00
Bénédikt Tran
9f0d6b71d6
[3.12] Fix Unicode encode_wstr_utf8() (#127420) (#127504)
Fix Unicode encode_wstr_utf8() (#127420)

Raise RuntimeError instead of RuntimeWarning.

Co-authored-by: Victor Stinner <vstinner@python.org>
2024-12-02 13:24:26 +01: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
Miss Islington (bot)
9345dc165c
[3.12] gh-126594: Fix typeobject.c wrap_buffer() cast (GH-126754) (#127005)
gh-126594: Fix typeobject.c wrap_buffer() cast (GH-126754)

Reject flags smaller than INT_MIN.

(cherry picked from commit 84f07c3a4c)

Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-11-19 08:33:18 +00:00
Miss Islington (bot)
0bdcc84ae9
[3.12] gh-126341: add release check to __iter__ method of memoryview (GH-126759) (#126779)
gh-126341: add release check to `__iter__` method of `memoryview` (GH-126759)
(cherry picked from commit a12690ef49)

Co-authored-by: Ritvik Pasham <ritvikpasham@gmail.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: sobolevn <mail@sobolevn.me>
2024-11-13 20:44:01 +02:00
Serhiy Storchaka
844d908adb
[3.12] gh-126303: Fix pickling and copying of os.sched_param objects (GH-126336) (GH-126424)
(cherry picked from commit d3840503b0)
2024-11-05 06:52:51 +00:00
Miss Islington (bot)
1fc1a185ed
[3.12] gh-116938: Fix dict.update docstring and remove erraneous full stop from dict documentation (GH-125421) (#126151)
gh-116938: Fix `dict.update` docstring and remove erraneous full stop from `dict` documentation (GH-125421)
(cherry picked from commit 5527c4051c)

Co-authored-by: Prometheus3375 <35541026+Prometheus3375@users.noreply.github.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
2024-10-29 23:22:20 +00:00
Miss Islington (bot)
d3b437cb78
[3.12] gh-123378: fix a crash in UnicodeError.__str__ (GH-124935) (#125098)
gh-123378: fix a crash in `UnicodeError.__str__` (GH-124935)
(cherry picked from commit ba14dfafd9)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-10-08 11:56:18 +00:00
Petr Viktorin
b3e2c02915
[3.12] gh-113993: For string interning, do not rely on (or assert) _Py_IsImmortal (GH-121358) (GH-124938)
gh-113993: For string interning, do not rely on (or assert) _Py_IsImmortal (GH-121358)

Older stable ABI extensions are allowed to make immortal objects mortal.
Instead, use `_PyUnicode_STATE` (`interned` and `statically_allocated`).
(cherry picked from commit 956270d08d)

Co-authored-by: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
2024-10-04 16:50:34 +02:00
Neil Schemenauer
ffc6a10149
[3.12] gh-124785: Revert "[3.12] gh-116510: Fix a crash due to shared immortal interned strings. (gh-124541)" (#124814)
Revert "[3.12] gh-116510: Fix a crash due to shared immortal interned strings. (gh-124541)"

This reverts commit 5dd07ebc0c.
2024-09-30 18:54:41 -07: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
Miss Islington (bot)
1d70dd257b
[3.12] gh-119004: fix a crash in equality testing between OrderedDict (GH-121329) (#124508)
gh-119004: fix a crash in equality testing between `OrderedDict` (GH-121329)
(cherry picked from commit 38a887dc3e)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-09-27 11:33:44 -07:00
Neil Schemenauer
5dd07ebc0c
[3.12] gh-116510: Fix a crash due to shared immortal interned strings. (gh-124541)
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.
2024-09-26 18:04:03 -07:00
Miss Islington (bot)
4659026e1d
[3.12] gh-124498: Fix TypeAliasType not to be generic, when type_params=() (GH-124499) (#124604)
gh-124498: Fix `TypeAliasType` not to be generic, when `type_params=()` (GH-124499)
(cherry picked from commit abe5f799e6)

Co-authored-by: sobolevn <mail@sobolevn.me>
2024-09-26 14:46:29 +00:00
Serhiy Storchaka
90e5bd7ed2
[3.12] gh-77894: Fix a crash when the GC breaks a loop containing a memoryview (GH-123898) (GH-123937)
Now a memoryview object can only be cleared if there are no buffers
that refer it.
(cherry picked from commit a1dbf2ea69)
2024-09-11 09:32:39 +00:00
Sam Gross
1bfb58cf2f
[3.12] gh-122527: Fix a crash on deallocation of PyStructSequence (GH-122577) (#122626)
The `PyStructSequence` destructor would crash if it was deallocated after
its type's dictionary was cleared by the GC, because it couldn't compute
the "real size" of the instance. This could occur with relatively
straightforward code in the free-threaded build or with a reference
cycle involving the type in the default build, due to differing orders
in which `tp_clear()` was called.

Account for the non-sequence fields in `tp_basicsize` and use that,
along with `Py_SIZE()`, to compute the "real" size of a
`PyStructSequence` in the dealloc function. This avoids the accesses to
the type's dictionary during dealloc, which were unsafe.
(cherry picked from commit 4b63cd170e)
2024-09-06 15:46:56 +02:00
Miss Islington (bot)
93d4a191ff
[3.12] gh-122982: Extend the deprecation period for bool inversion by two years (GH-123306) (#123317)
gh-122982: Extend the deprecation period for bool inversion by two years (GH-123306)
(cherry picked from commit 249b083ed8)

Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
2024-08-25 19:40:11 +00:00
Dino Viehland
c8f5ca6810
[3.12] gh-122208: Don't delivery PyDict_EVENT_ADDED until it can't fail (#122327)
Don't delivery PyDict_EVENT_ADDED until it can't fail
2024-07-30 09:13:40 -07:00
Eric Snow
5bd2ea2b94
[3.12] gh-117482: Fix the Slot Wrapper Inheritance Tests (gh-122250)
The tests were only checking cases where the slot wrapper was present in the initial case.  They were missing when the slot wrapper was added in the additional initializations.  This fixes that.

(cherry-picked from commit 490e0ad83a, AKA gh-122248)
2024-07-29 10:25:17 -06:00
Eric Snow
dd4c8aca61
[3.12] gh-117482: Simplify the Fix For Builtin Types Slot Wrappers (gh-122241)
In gh-121602, I applied a fix to a builtin types initialization bug.
That fix made sense in the context of some broader future changes,
but introduced a little bit of extra complexity.  For earlier versions
those future changes are not relevant; we can avoid the extra complexity.
Thus we can revert that earlier change and replace it with this one,
which is more focused and conceptually simpler.  This is essentially
the implementation of an idea that @markshannon pointed out to me.

Note that this change would be much smaller if we didn't have to deal
with repr compatibility for builtin types that explicitly inherit tp slots
(see expect_manually_inherited()).  The alternative is to stop
*explicitly* inheriting tp slots in static PyTypeObject values,
which is churn that we can do separately.

(cherry picked from commit 716c6771fc, AKA gh-121932)
2024-07-24 19:07:32 +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
Miss Islington (bot)
7a4b55d602
[3.12] gh-121660: Fix ga_getitem by explicitly checking for NULL result (GH-121661) (#121762)
gh-121660: Fix `ga_getitem` by explicitly checking for `NULL` result (GH-121661)
(cherry picked from commit bb802db8cf)

Co-authored-by: sobolevn <mail@sobolevn.me>
2024-07-14 11:37:00 +00:00
Eric Snow
0ec761a96a
[3.12] gh-117482: Fix Builtin Types Slot Wrappers (gh-121632)
When builtin static types are initialized for a subinterpreter, various "tp" slots have already been inherited (for the main interpreter).  This was interfering with the logic in add_operators() (in Objects/typeobject.c), causing a wrapper to get created when it shouldn't.  This change fixes that by preserving the original data from the static type struct and checking that.

(cherry picked from commit 5250a03133, AKA gh-121602)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2024-07-11 21:20:08 +00:00
Miss Islington (bot)
ac4276cc7a
[3.12] GH-121439: Allow PyTupleObjects with an ob_size of 20 in the free_list to be reused (gh-121428) (#121566)
GH-121439: Allow PyTupleObjects with an ob_size of 20 in the free_list to be reused (gh-121428)
(cherry picked from commit 9585a1a2a2)

Co-authored-by: satori1995 <132636720+satori1995@users.noreply.github.com>
2024-07-10 08:06:41 +00:00
Miss Islington (bot)
d75eddcf36
[3.12] gh-120384: Fix array-out-of-bounds crash in list_ass_subscript (GH-120442) (#120825)
gh-120384: Fix array-out-of-bounds crash in `list_ass_subscript` (GH-120442)
(cherry picked from commit 8334a1b55c)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2024-06-21 11:08:22 +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
Ken Jin
e8a9f0c9e7
gh-120198: Fix race condition when editing __class__ with an audit hook active (GH-120195)
Co-authored-by: Nadeshiko Manju <me@manjusaka.me>
2024-06-12 14:06:24 +01:00
Miss Islington (bot)
b8845369aa
[3.12] gh-120298: Fix use-after-free in list_richcompare_impl (GH-120303) (#120339)
gh-120298: Fix use-after-free in `list_richcompare_impl` (GH-120303)
(cherry picked from commit 141babad9b)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-06-11 07:22:59 +00:00
Serhiy Storchaka
7545b7cb63
[3.12] bpo-24766: doc= argument to subclasses of property not handled correctly (GH-2487) (GH-120312)
(cherry picked from commit 4829522b8d)

Co-authored-by: E. M. Bray <erik.bray@lri.fr>
2024-06-10 10:32:45 +00:00
Miss Islington (bot)
ec7c9d330f
[3.12] gh-120155: Fix copy/paste error in HAVE_SUBOFFSETS_IN_LAST_DIM() (GH-120228) (#120240)
gh-120155: Fix copy/paste error in HAVE_SUBOFFSETS_IN_LAST_DIM() (GH-120228)

Don't hardcode 'dest' in HAVE_SUBOFFSETS_IN_LAST_DIM() macro of
memoryobject.c, but use its 'view' parameter instead.

Fix the Coverity issue:

Error: COPY_PASTE_ERROR (CWE-398):
Python-3.12.2/Objects/memoryobject.c:273:14: original: ""dest->suboffsets + (dest->ndim - 1)"" looks like the original copy.
Python-3.12.2/Objects/memoryobject.c:274:14: copy_paste_error: ""dest"" in ""src->suboffsets + (dest->ndim - 1)"" looks like a copy-paste error.
Python-3.12.2/Objects/memoryobject.c:274:14: remediation: Should it say ""src"" instead?
GH-  272|       assert(dest->ndim > 0 && src->ndim > 0);
GH-  273|       return (!HAVE_SUBOFFSETS_IN_LAST_DIM(dest) &&
GH-  274|->             !HAVE_SUBOFFSETS_IN_LAST_DIM(src) &&
GH-  275|               dest->strides[dest->ndim-1] == dest->itemsize &&
GH-  276|               src->strides[src->ndim-1] == src->itemsize);
(cherry picked from commit 90b7540526)

Co-authored-by: Victor Stinner <vstinner@python.org>
2024-06-07 16:26:03 +00:00
Serhiy Storchaka
207d1b032f
[3.12] gh-109218: Improve documentation for the complex() constructor (GH-119687) (ПР-119805)
* Remove the equivalence with real+imag*1j which can be incorrect in corner
  cases (non-finite numbers, the sign of zeroes).
* Separately document the three roles of the constructor: parsing a string,
  converting a number, and constructing a complex from components.
* Document positional-only parameters of complex(), float(), int() and bool()
  as positional-only.
* Add examples for complex() and int().
* Specify the grammar of the string for complex().
* Improve the grammar of the string for float().
* Describe more explicitly the behavior when real and/or imag arguments are
  complex numbers. (This will be deprecated in future.)
(cherry picked from commit ec1ba26460)
2024-05-30 20:52:44 +00:00
Jelle Zijlstra
7f06cd335e
[3.12] gh-119011: type.__type_params__ now return an empty tuple (GH-119296) (#119681)
(cherry picked from commit 6b240c2308)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2024-05-28 19:54:47 +00:00
Miss Islington (bot)
8bfaf3a5f0
Fix some missing null checks. (GH-118721)
(cherry picked from commit 7e6fcab200)

Co-authored-by: Steve Dower <steve.dower@python.org>
2024-05-10 09:51:57 +00:00
Irit Katriel
238efbecab
[3.12] gh-118272: Clear generator frame's locals when the generator is closed (#118451) 2024-05-02 16:22:50 +01:00
Thomas Grainger
c48e0ef7dd
[3.12] GH-117881: fix athrow().throw()/asend().throw() concurrent access (GH-117882) (#118458)
GH-117881: fix athrow().throw()/asend().throw() concurrent access (GH-117882)

(cherry picked from commit fc7e1aa3c0)
2024-05-02 10:23:25 +02:00
Thomas Grainger
fc1732ce3f
[3.12] GH-117894: prevent aclose()/athrow() being re-used after StopIteration (GH-117851) (GH-118226)
(cherry picked from commit 7d369d471c)
2024-04-25 09:13:47 +02:00
Sam Gross
92564331de
[3.12] gh-113964: Don't prevent new threads until all non-daemon threads exit (GH-116677) (#117029)
Starting in Python 3.12, we prevented calling fork() and starting new threads
during interpreter finalization (shutdown). This has led to a number of
regressions and flaky tests. We should not prevent starting new threads
(or `fork()`) until all non-daemon threads exit and finalization starts in
earnest.

This changes the checks to use `_PyInterpreterState_GetFinalizing(interp)`,
which is set immediately before terminating non-daemon threads.

(cherry picked from commit 60e105c1c1)
2024-03-19 15:22:42 -04:00
Miss Islington (bot)
fc81b6497b
[3.12] gh-116714: Handle errors correctly in PyFloat_GetInfo (GH-116715) (#116722)
gh-116714: Handle errors correctly in `PyFloat_GetInfo` (GH-116715)
(cherry picked from commit fcd49b4f47)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-03-13 16:40:38 +03:00
Miss Islington (bot)
4ea9d15761
[3.12] gh-110819: Fix ‘kind’ may be used uninitialized warning in longobject (GH-116599) (#116648)
gh-110819: Fix ‘kind’ may be used uninitialized warning in `longobject` (GH-116599)
(cherry picked from commit eb947cdc13)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2024-03-12 11:09:15 +00:00
Miss Islington (bot)
d8a56ea439
[3.12] gh-116296: Fix refleak in reduce_newobj() corner case (GH-116297) (#116299)
(cherry picked from commit 17c4849981)

Co-authored-by: Erlend E. Aasland <erlend@python.org>
Co-authored-by: Brandt Bucher <brandtbucher@microsoft.com>
2024-03-04 10:04:44 +00:00
Miss Islington (bot)
eb4774d2b7
[3.12] gh-100762: Fix optimization in gen_close (GH-111069) (#115818)
gh-100762: Fix optimization in gen_close  (GH-111069)
(cherry picked from commit 0db2517687)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2024-02-22 14:05:59 +00:00
Serhiy Storchaka
b9d1efa696
[3.12] gh-115618: Remove improper Py_XDECREFs in property methods (GH-115619) (GH-115620)
(cherry picked from commit 090dd21ab9)
2024-02-17 21:43:59 +00:00
Donghee Na
5ec52c35eb
[3.12] gh-112087: Fix reduce logic for the empty reverse iterator for list (gh-115471) 2024-02-14 18:44:26 +00:00
Miss Islington (bot)
5c21f3d9e5
[3.12] gh-113560: Improve docstrings for set.issubset() and set.issuperset() (GH-113562) (GH-114644)
(cherry picked from commit 11c582235d)

Co-authored-by: Charlie Zhao <zhaoyu_hit@qq.com>
2024-01-27 11:29:26 +00:00
Miss Islington (bot)
b201a6a1f1
[3.12] gh-106293: Fix typos in Objects/object_layout.md (GH-106294) (#114158)
(cherry picked from commit 60ca37fdee)

Co-authored-by: Mano Sriram <mano.sriram0@gmail.com>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
2024-01-16 23:35:20 +00:00