Commit graph

4718 commits

Author SHA1 Message Date
Victor Stinner
c77bfd768f
[3.12] gh-127906: Declare timeval struct in pytime.h on Windows (#127908)
gh-127906: Declare timeval struct in pytime.h on Windows

Fix the following MSVC compiler warning:

    include\cpython\pytime.h(192): warning C4115: 'timeval':
    named type definition in parentheses
2024-12-13 12:13:49 +00:00
Miss Islington (bot)
f3a689fd9d
[3.12] gh-107249: Implement Py_UNUSED() for MSVC (GH-107250) (#127907)
gh-107249: Implement Py_UNUSED() for MSVC (GH-107250)

Fix warnings C4100 in Py_UNUSED() when Python is built with "cl /W4".

Example with this function included by Python.h:

    static inline unsigned int
    PyUnicode_IS_READY(PyObject* Py_UNUSED(op))
    { return 1; }

Without this change, building a C program with "cl /W4" which just
includes Python.h emits the warning:

    Include\cpython/unicodeobject.h(199):
    warning C4100: '_unused_op': unreferenced formal parameter

This change fix this warning.
(cherry picked from commit 6a43cce32b)

Co-authored-by: Victor Stinner <vstinner@python.org>
2024-12-13 11:58:47 +00:00
Dmitry Shachnev
b184f4859a
[3.12] gh-127902: Make sure extern "C" is closed when using Py_LIMITED_API (#127904)
Fixes #127902.
2024-12-13 11:18:28 +00:00
Victor Stinner
65bca19db5
[3.12] Add extern "C" around PyTraceMalloc_ functions. (#127772) (#127817)
Add `extern "C"` around `PyTraceMalloc_` functions. (#127772)

Pretty much everything else exported by Python.h has an extern "C"
annotation, yet this header appears to be missing one.

(cherry picked from commit 2cdeb61b57)

Co-authored-by: Peter Hawkins <hawkinsp@cs.stanford.edu>
2024-12-11 14:08:23 +01:00
Thomas Wouters
f19c50a481 Post 3.12.8 2024-12-03 22:38:32 +01:00
Thomas Wouters
2dc476bcb9 Python 3.12.8 2024-12-03 19:42:41 +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
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
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
Thomas Wouters
1e26ec55e0 Post 3.12.7 2024-10-01 07:12:34 +02:00
Thomas Wouters
0b05ead877 Python 3.12.7 2024-10-01 04:05:46 +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
Thomas Wouters
916cedb6e4 Post 3.12.6 2024-09-07 00:22:27 +02:00
Thomas Wouters
a4a2d2b0d8 Python 3.12.6 2024-09-06 21:03:47 +02:00
Thomas Wouters
f4aad5a6d2 Post 3.12.5 2024-08-07 13:34:56 +02:00
Thomas Wouters
ff3bc82f7c Python 3.12.5 2024-08-06 21:08:49 +02:00
Jakub Kulík
6586b171ea
[3.12] gh-118124: fix assert related C++ checks on Solaris/Illumos (GH-121974) (#122109)
Fix check for static_assert() for C++ on some platforms..
(cherry picked from commit e88bd96d0d)
2024-07-22 07:45:17 +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
Victor Stinner
e0b9905ce6
[3.12] gh-119447: Fix build with _PY_SHORT_FLOAT_REPR == 0 (#121178) (#121180)
gh-119447: Fix build with _PY_SHORT_FLOAT_REPR == 0 (#121178)

(cherry picked from commit c3677befbe)

Co-authored-by: Yureka <yuka@yuka.dev>
2024-06-30 10:02:08 +00:00
Terry Jan Reedy
61e37dd4f5
[3.12] Fix typos in comments (GH-120481) (#120775)
Only 1 applicable change backported to 3.12.

(cherry picked from commit 656a1c8)

Co-authored-by: Xie Yanbo xieyanbo@gmail.com
2024-06-20 03:59:31 +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
Thomas Wouters
0e7b4d25d4 Post 3.12.4 2024-06-07 00:25:42 +02:00
Thomas Wouters
8e8a4baf65 Python 3.12.4 2024-06-06 20:26:44 +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
Eric Snow
0d5fe2c7b4
[3.12] gh-119213: Be More Careful About _PyArg_Parser.kwtuple Across Interpreters (gh-119331) (gh-119425)
_PyArg_Parser holds static global data generated for modules by Argument Clinic.  The _PyArg_Parser.kwtuple field is a tuple object, even though it's stored within a static global.  In some cases the tuple is statically allocated and thus it's okay that it gets shared by multiple interpreters.  However, in other cases the tuple is set lazily, allocated from the heap using the active interprepreter at the point the tuple is needed.

This is a problem once that interpreter is destroyed since _PyArg_Parser.kwtuple becomes at dangling pointer, leading to crashes.  It isn't a problem if the tuple is allocated under the main interpreter, since its lifetime is bound to the lifetime of the runtime.  The solution here is to temporarily switch to the main interpreter.  The alternative would be to always statically allocate the tuple.

This change also fixes a bug where only the most recent parser was added to the global linked list.

(cherry picked from commit 81865002ae)
2024-05-22 22:26:58 +00:00
Victor Stinner
bd1e9509a4
[3.12] gh-118997: Fix _Py_ClearImmortal() assertion (#119001)
Fix _Py_ClearImmortal() assertion: use _Py_IsImmortal() to tolerate
reference count lower than _Py_IMMORTAL_REFCNT. Fix the assertion for
the stable ABI, when a C extension is built with Python 3.11 or
lower.
2024-05-18 16:56:27 -04: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
Irit Katriel
ebef3c5ba4
[3.12] gh-116767: fix crash on 'async with' with many context managers (GH-118348) (#118477)
gh-116767: fix crash on 'async with' with many context managers (GH-118348)

Account for `add_stopiteration_handler` pushing a block for `async with`.
To allow generator functions that previously almost hit the `CO_MAXBLOCKS`
limit by nesting non-async blocks, the limit is increased by 1.
This increase allows one more block in non-generator functions.

(cherry picked from commit c1bf4874c1)
2024-05-01 18:23:29 +01:00
Miss Islington (bot)
82e26d6bd0
[3.12] gh-118207: Rename the COMMON_FIELDS macro in funcobject.h and undef it after use (GH-118208) (#118269)
gh-118207: Rename the COMMON_FIELDS macro in funcobject.h and undef it after use (GH-118208)
(cherry picked from commit 796b3fb280)

Co-authored-by: Itamar Oren <itamarost@gmail.com>
2024-04-25 22:29:45 -07:00
Miss Islington (bot)
04d07964f2
[3.12] gh-112536: Define _Py_THREAD_SANITIZER on GCC when TSan is enabled (GH-117702) (#117713)
gh-112536: Define `_Py_THREAD_SANITIZER` on GCC when TSan is enabled (GH-117702)

The `__has_feature(thread_sanitizer)` is a Clang-ism. Although new
versions of GCC implement `__has_feature`, the `defined(__has_feature)`
check still fails on GCC so we don't use that code path.
(cherry picked from commit 79eec66e3d)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-04-10 14:38:10 +00:00
Thomas Wouters
26831278d8 Post 3.12.3 2024-04-09 17:25:54 +02:00
Thomas Wouters
f6650f9ad7 Python 3.12.3 2024-04-09 10:09:14 +02:00
Serhiy Storchaka
da2f9d1417
[3.12] gh-117021: Fix integer overflow in PyLong_AsPid() on non-Windows 64-bit platforms (GH-117064) (GH-117070)
(cherry picked from commit 519b2ae22b)
2024-03-20 16:44:05 +02:00
Miss Islington (bot)
5da6e3082c
[3.12] gh-116869: Make C API compatible with ISO C90 (GH-116950) (#117011)
gh-116869: Make C API compatible with ISO C90 (GH-116950)

Make the C API compatible with -Werror=declaration-after-statement
compiler flag again.
(cherry picked from commit a9c304cf02)

Co-authored-by: Victor Stinner <vstinner@python.org>
2024-03-19 16:06:15 +00:00
Antoine Pitrou
2ac1b48a04
[3.12] gh-112536: Add support for thread sanitizer (TSAN) (gh-112648) (#116924)
* [3.12] gh-112536: Add support for thread sanitizer (TSAN) (gh-112648)
(cherry picked from commit 88cb972000)

* Remove doc for configure option (leave it hidden in this branch)

---------

Co-authored-by: Samet YASLAN <sametyaslan@gmail.com>
2024-03-17 16:33:35 +01:00
Sebastian Pipping
0a01ed6c2a
[3.12] gh-115398: Expose Expat >=2.6.0 reparse deferral API (CVE-2023-52425) (GH-115623) (GH-116248)
Allow controlling Expat >=2.6.0 reparse deferral (CVE-2023-52425) by adding five new methods:

- `xml.etree.ElementTree.XMLParser.flush`
- `xml.etree.ElementTree.XMLPullParser.flush`
- `xml.parsers.expat.xmlparser.GetReparseDeferralEnabled`
- `xml.parsers.expat.xmlparser.SetReparseDeferralEnabled`
- `xml.sax.expatreader.ExpatParser.flush`

Based on the "flush" idea from https://github.com/python/cpython/pull/115138#issuecomment-1932444270 .

- Please treat as a security fix related to CVE-2023-52425.

(cherry picked from commit 6a95676bb5)
(cherry picked from commit 73807eb634)
(cherry picked from commit eda2963378)

---------

Includes code suggested-by: Snild Dolkow <snild@sony.com>
and by core dev Serhiy Storchaka.
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2024-03-06 22:01:45 +00:00
Terry Jan Reedy
84b023d243
[3.12] chore: fix typos (#116345) (#116370)
Co-authored-by: cui fliter <imcusg@gmail.com>
(cherry picked from commit e7ba6e9dbe)
2024-03-05 18:51:17 +00:00
Mark Shannon
4d87832d87
[3.12] GH-112215: Backport C recursion changes (GH-115083) 2024-02-13 10:45:59 +01:00
Miss Islington (bot)
3a67d3272c
[3.12] gh-114828: parenthesize non-atomic macro definitions in pycore_symtable.h (GH-115143) (#115149)
gh-114828: parenthesize non-atomic macro definitions in pycore_symtable.h (GH-115143)
(cherry picked from commit 8f0998e844)

Co-authored-by: Carl Meyer <carl@oddbird.net>
2024-02-07 20:39:22 +00:00
Thomas Wouters
55cd0bff73 Post 3.12.2 2024-02-07 00:44:32 +01:00
Thomas Wouters
6abddd9f6a Python 3.12.2 2024-02-06 21:19:44 +01:00
Serhiy Storchaka
d58a5f453f
[3.12] gh-106905: Use separate structs to track recursion depth in each PyAST_mod2obj call. (GH-113035) (GH-113472)
(cherry picked from commit 48c49739f5)

Co-authored-by: Yilei Yang <yileiyang@google.com>
Co-authored-by: Gregory P. Smith [Google LLC] <greg@krypto.org>
2023-12-25 19:20:07 +00:00
Irit Katriel
9d72a5cae7
[3.12] gh-113297: Fix segfault in compiler for with statement with 19 context managers (#113327) (#113404) 2023-12-23 13:29:11 +00:00
Miss Islington (bot)
c34c9e3b9a
[3.12] gh-112867: fix for WITH_PYMALLOC_RADIX_TREE=0 (GH-112885) (#113068)
gh-112867: fix for WITH_PYMALLOC_RADIX_TREE=0 (GH-112885)

The _obmalloc_usage structure is only defined if the obmalloc radix tree
is enabled.
(cherry picked from commit 890ce430d9)

Co-authored-by: Neil Schemenauer <nas-github@arctrix.com>
2023-12-13 13:06:43 -08:00
Ronald Oussoren
65371511b9
[3.12] gh-110820: Disable test_signal.test_stress_modifying_handlers on macOS (GH-112834)
* gh-110820: Make sure processor specific defines are correct for Universal 2 build on macOS (#112828)

A number of processor specific defines are different for x86-64 and
arm64, and need to be adjusted in pymacconfig.h.

(cherry picked from commit 15a80b15af)
2023-12-09 15:53:16 +01:00
Thomas Wouters
71cbc6a78f Post 3.12.1 2023-12-08 01:39:55 +01:00
Thomas Wouters
2305ca5144 Python 3.12.1 2023-12-07 21:46:47 +01:00
Victor Stinner
f27271619e
[3.12] gh-112125: Fix None.__ne__(None) returning NotImplemented instead of … (#112827)
gh-112125: Fix None.__ne__(None) returning NotImplemented instead of False (#112504)

(cherry picked from commit 9c3458e058)

Co-authored-by: andrewluotechnologies <44252973+andrewluotechnologies@users.noreply.github.com>
2023-12-07 13:41:00 +00:00
Miss Islington (bot)
e005dabe13
[3.12] gh-106550: Fix sign conversion in pycore_code.h (GH-112613) (#112696)
gh-106550: Fix sign conversion in pycore_code.h (GH-112613)

Fix sign conversion in pycore_code.h: use unsigned integers and cast
explicitly when needed.
(cherry picked from commit a74902a14c)

Co-authored-by: Victor Stinner <vstinner@python.org>
2023-12-04 11:14:13 +00:00
Victor Stinner
05f5d416de
[3.12] gh-106560: Fix redundant declarations in Include/ (#112611) (#112650)
gh-106560: Fix redundant declarations in Include/ (#112611)

Don't declare PyBool_Type and PyLong_Type twice, but only once.

Compiler warnings seen by building Python with gcc -Wredundant-decls.
2023-12-03 11:45:32 +00:00