7601 Commits

Author SHA1 Message Date
Diego Russo
6b37486184
[3.11] gh-106883 Fix deadlock in threaded application (#117332)
When using threaded applications, there is a high risk of a deadlock in
the interpreter. It's a lock ordering deadlock with HEAD_LOCK(&_PyRuntime); and the GIL.

By disabling the GC during the _PyThread_CurrentFrames() and
_PyThread_CurrentExceptions() calls fixes the issue.
2025-03-11 15:31:03 +00:00
Serhiy Storchaka
051b8a2589
[3.11] gh-90300: Improve the Python CLI help output (GH-115853) (GH-117022) (GH-117034)
* document equivalent command-line options for all environment variables
* document equivalent environment variables for all command-line options
* reduce the size of variable and option descriptions to minimum
* remove the ending period in single-sentence descriptions

(cherry picked from commit b85572c47dc7a8c65fc366a87a3660fc7a3ed244)

(cherry picked from commit 4be9fa896117bf07dc944a29c98dd18b71dd6c74)

Co-authored-by: Éric <merwok@netwok.org>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2024-03-19 20:08:00 +00:00
Miss Islington (bot)
d83b4c570c
[3.11] gh-90300: Fix undocumented envvars in the Python CLI help (GH-116765) (GH-116797) (GH-116803)
(cherry picked from commit fc4d5fdffe3d9829b118232f35ccee61a27392ee)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
(cherry picked from commit 19ac28bd08fdb16795e6f82ea7bfac73e8f3791b)
2024-03-14 15:41:52 +02:00
Miss Islington (bot)
0ecdaf0aa7
[3.11] gh-90300: Document equivalent -X options for envvars in the Python CLI help (GH-116756) (GH-116786) (GH-116796)
(cherry picked from commit 991710af022f27db862ff1399178bcc76b062669)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
(cherry picked from commit 8c6db45ce34df7081d7497e638daf3e130303295)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-03-14 10:39:32 +00:00
Serhiy Storchaka
1080dd166d
[3.11] gh-90300: Sort the -X options and some envvars in the Python CLI help (GH-116739) (GH-116766) (GH-116779)
(cherry picked from commit 870cd901ea72e85eea825425336305296ee443cc)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
(cherry picked from commit e54bdeab9ce2958a22ba08c1f1f1431c5e8056bd)
2024-03-14 12:07:31 +02:00
Miss Islington (bot)
76c4ab31c9
[3.11] gh-90300: Fix cmdline.rst (GH-116721) (GH-116725)
* Fix the description of the "-b" option.
* Add references to environment variables for "-s" and "-X dev" options.
(cherry picked from commit 33662d4e01d73cd4f29a25efc2ef09288129023f)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-03-13 13:56:25 +00:00
Miss Islington (bot)
3abf267787
[3.11] gh-116447: Fix possible UB in arraymodule and getargs (GH-116459) (#116497)
gh-116447: Fix possible UB in `arraymodule` and `getargs` (GH-116459)
(cherry picked from commit fdb2d90a274158aee23b526d972172bf41bd4b7e)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2024-03-08 11:25:39 +00:00
Łukasz Langa
e8fb762fa9
[3.11] gh-90300: Reformat the Python CLI help output (GH-115847) (GH-116418)
(cherry picked from commit 2e92ffd7fa89e3bd33ee2f31541d3dc53aaa2d12)
(cherry picked from commit 2bdd1d6f15d5507a9ed6dff10e9fb57e2a8c0b40)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-03-06 17:13:10 +01:00
Nikita Sobolev
23c17f3c1a
[3.11] gh-116326: Handler errors correctly in getwindowsversion in sysmodule (GH-116339) (#116388)
(cherry picked from commit c91bdf86ef1cf9365b61a46aa2e51e5d1932b00a)
2024-03-06 10:54:34 +03:00
Miss Islington (bot)
8ee7e91c38
[3.11] gh-115320: Refactor get_hash_info in sysmodule.c not to swallow errors (GH-115321) (#116324)
gh-115320: Refactor `get_hash_info` in `sysmodule.c` not to swallow errors (GH-115321)
(cherry picked from commit 207030f5527d405940b79c10c1413c1e8ff696c1)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2024-03-04 21:12:27 +00:00
Irit Katriel
99ab0d49e2
[3.11] gh-116034: fix location info on the error of a failed assertion (#116052) 2024-02-28 19:12:16 +00:00
Serhiy Storchaka
51b974b0ab
[3.11] gh-96497: Mangle name before symtable lookup in 'symtable_extend_namedexpr_scope' (GH-96561) (GH-115604)
(cherry picked from commit 664965a1c141e8af5eb465d29099781a6a2fc3f3)

Co-authored-by: wookie184 <wookie1840@gmail.com>
2024-02-17 13:13:26 +00:00
Serhiy Storchaka
7273a58a85
[3.11] gh-115011: Improve support of __index__() in setters of members with unsigned integer type (GH-115029) (GH-115295)
Setters for members with an unsigned integer type now support
the same range of valid values for objects that has a __index__()
method as for int.

Previously, Py_T_UINT, Py_T_ULONG and Py_T_ULLONG did not support
objects that has a __index__() method larger than LONG_MAX.

Py_T_ULLONG did not support negative ints. Now it supports them and
emits a RuntimeWarning.
(cherry picked from commit d9d6909697501a2604d5895f9f88aeec61274ab0)
2024-02-11 12:03:48 +00:00
Peter Lazorchak
a11312456d
[3.11] gh-89811: Check for valid tp_version_tag in specializer (GH-115045)
* gh-89811: Check for valid tp_version_tag in specializer (GH-113558)

* gh-113937 Fix failures in type cache tests due to re-running (GH-113953)

* Update backported code for 3.11 specifically
2024-02-06 21:58:30 +08:00
Serhiy Storchaka
0244e96d10
[3.11] gh-114388: Fix warnings when assign an unsigned integer member (GH-114391) (GH-115002)
* Fix a RuntimeWarning emitted when assign an integer-like value that
  is not an instance of int to an attribute that corresponds to a C
  struct member of type T_UINT and T_ULONG.
* Fix a double RuntimeWarning emitted when assign a negative integer value
  to an attribute that corresponds to a C struct member of type T_UINT.
(cherry picked from commit 3ddc5152550ea62280124c37d0b4339030ff7df4)
2024-02-04 17:54:26 +00:00
Miss Islington (bot)
ee3ca96359
[3.11] gh-114685: Fix incorrect use of PyBUF_READ in import.c (GH-114686) (GH-114701)
(cherry picked from commit 1ac1b2f9536a581f1656f0ac9330a7382420cda1)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2024-01-29 10:03:14 +00:00
Jérome Perrin
3bd4c3a86c
[3.11] gh-113358 Fix rendering tracebacks with exceptions with a broken __getattr__ : Normalize exception (#114379) 2024-01-21 17:25:55 +00:00
Miss Islington (bot)
d2cfb5b258
[3.11] gh-114384: Align sys.set_asyncgen_hooks signature in docs to reflect implementation (GH-114385) (#114387)
(cherry picked from commit 38768e4cdd1c4b6e03702da8a94e1c22479d6ed3)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2024-01-21 13:03:53 +00:00
Jérome Perrin
20f7cf2c7f
[3.11] gh-113358: Fix rendering tracebacks with exceptions with a broken __getattr__ (GH-113359) (#114118) 2024-01-19 20:35:57 +00:00
Miss Islington (bot)
50efd7db20
[3.11] gh-113842: Add missing error check for PyIter_Next() in Python/symtable.c (GH-113843) (GH-113852)
(cherry picked from commit fda901a1ff94ea6cc338b74928acdbc5ee165ed7)

Co-authored-by: Yan Yanchii <yyanchiy@gmail.com>
2024-01-09 11:09:32 +00:00
Serhiy Storchaka
4b358d754c
[3.11] gh-106905: Use separate structs to track recursion depth in each PyAST_mod2obj call. (GH-113035) (GH-113472) (GH-113476)
(cherry picked from commit 48c49739f5502fc7aa82f247ab2e4d7b55bdca62)
(cherry picked from commit d58a5f453f59f44ccf09b1a9b11a0b879ac6f35b)

Co-authored-by: Yilei Yang <yileiyang@google.com>
Co-authored-by: Gregory P. Smith [Google LLC] <greg@krypto.org>
2023-12-25 20:40:33 +00:00
Serhiy Storchaka
d4234937a1
[3.11] gh-112716: Fix SystemError when __builtins__ is not a dict (GH-112770) (GH-113105)
It was raised in two cases:
* in the import statement when looking up __import__
* in pickling some builtin type when looking up built-ins iter, getattr, etc.

(cherry picked from commit 1161c14e8c68296fc465cd48970b32be9bee012e)
2023-12-14 12:59:33 +00:00
Serhiy Storchaka
581b244155
[3.11] gh-112438: Fix support of format units with the "e" prefix in nested tuples in PyArg_Parse (gh-112439) (GH-112461)
(cherry picked from commit 4eea1e82369fbf7a795d1956e7a8212a1b58009f)
2023-11-27 18:11:09 +00:00
Miss Islington (bot)
8222ad01fe
[3.11] [3.12] gh-109181: Fix refleak in tb_get_lineno() (GH-111948) (#111951)
[3.12] gh-109181: Fix refleak in tb_get_lineno() (GH-111948)

PyFrame_GetCode() returns a strong reference.
(cherry picked from commit 4b0c875d91727440251a8427a80d8515e39d18cd)

Co-authored-by: Victor Stinner <vstinner@python.org>
2023-11-10 13:32:02 +00:00
Pablo Galindo Salgado
a4aa213b65
[3.11] gh-109181: Speed up Traceback object creation by lazily compute the line number (GH-111548) (#111550)
.
(cherry picked from commit abb15420c11d9dda9c89f74eac8417240b321109)
2023-10-31 15:59:31 +00:00
Pablo Galindo Salgado
22cde39fbf
[3.11] bpo-43950: handle wide unicode characters in tracebacks (GH-28150) (#111373) 2023-10-27 09:46:20 +09:00
Nikita Sobolev
e16922f070
[3.11] gh-109216: Fix possible memory leak in BUILD_MAP (#109323)
* [3.11] gh-109216: Fix possible memory leak in `BUILD_MAP`

* Add NEWS

* Update Python/ceval.c

Co-authored-by: Kumar Aditya <kumaraditya@python.org>

---------

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2023-10-12 12:52:03 +00:00
Miss Islington (bot)
f21c09ca03
[3.11] gh-110237: Check PyList_Append for errors in _PyEval_MatchClass (GH-110238) (#110512)
gh-110237: Check `PyList_Append` for errors in `_PyEval_MatchClass` (GH-110238)
(cherry picked from commit dd9d781da30aa3740e54c063a40413c542d78c25)

Co-authored-by: denballakh <47365157+denballakh@users.noreply.github.com>
2023-10-08 00:29:46 +00:00
Serhiy Storchaka
6a33529cf0
[3.11] gh-109521: Fix obscure cases handling in PyImport_GetImporter() (GH-109522) (GH-109781)
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 62c7015e89cbdedb5218d4fedd45f971885f67a8)
2023-10-07 16:05:13 +03:00
Victor Stinner
615d7fc34a
[3.11] gh-110052: Fix faulthandler for freed tstate (#110069) (#110072)
gh-110052: Fix faulthandler for freed tstate (#110069)

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

Backport to 3.11: add pycore_pymem.h include to traceback.c.

(cherry picked from commit 2e37a38bcbfbe1357436e030538290e7d00b668d)
2023-09-29 02:43:28 +00:00
Miss Islington (bot)
17a335dd02
[3.11] Fix error handling in _PySys_UpdateConfig() (GH-109524) (GH-109551)
(cherry picked from commit c829975428253568d47ebfc3104fa7386b5e0b58)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-09-18 21:24:41 +03:00
Miss Islington (bot)
f1f85a42ea
[3.11] gh-109351: Fix crash when compiling AST with invalid NamedExpr (GH-109352) (#109380)
gh-109351: Fix crash when compiling AST with invalid NamedExpr (GH-109352)
(cherry picked from commit 79101edb03b7381b514126c68acabfcbbba2f842)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-09-13 16:32:08 +00:00
Irit Katriel
1e8696133c
[3.11] gh-109179: Fix traceback display for SyntaxErrors with notes (#109197) (#109283)
gh-109179: Fix traceback display for SyntaxErrors with notes (#109197)

(cherry picked from commit ecd21a629a2a30bcae89902f7cad5670e9441e2c)
2023-09-12 09:57:28 +00:00
Victor Stinner
82a18069a1
[3.11] gh-108987: Fix _thread.start_new_thread() race condition (#109135) (#109272)
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 517cd82ea7d01b344804413ef05610934a43a241)
2023-09-11 19:33:08 +02:00
Miss Islington (bot)
c20658249d
[3.11] gh-109207: Fix SystemError when printing symtable entry object. (GH-109225) (GH-109228)
(cherry picked from commit 429749969621b149c1a7c3c004bd44f52bec8f44)

Co-authored-by: 云line <31395137+yunline@users.noreply.github.com>
2023-09-10 16:50:22 +03:00
Serhiy Storchaka
50e4143f8d
[3.11] Check the result of PySet_Contains() for error in Python/symtable.c (GH-109146) (GH-109158)
(cherry picked from commit 87a7faf6b68c8076e640a9a1347a255f132d8382)
2023-09-08 19:28:18 +00:00
Miss Islington (bot)
c1a2ef5efc
[3.11] gh-106922: Fix error location for constructs with spaces and parentheses (GH-108959) (#109148)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2023-09-08 16:56:10 +00:00
Victor Stinner
b55cf2c2d8
[3.11] gh-104690: thread_run() checks for tstate dangling pointer (#109056) (#109134)
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 f63d37877ad166041489a968233b57540f8456e8)
2023-09-08 11:10:33 +00:00
Serhiy Storchaka
b9fc536399
[3.11] gh-107913: Fix possible losses of OSError error codes (GH-107930) (GH-108524)
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 2b15536fa94d07e9e286826c23507402313ec7f4)
2023-08-27 12:18:58 +00:00
Miss Islington (bot)
ed67e60f48
[3.11] gh-107916: Save the error code before decoding the filename in PyErr_SetFromErrnoWithFilename() etc (GH-107929) (GH-108206)
(cherry picked from commit 80bdebdd8593f007a2232ec04a7729bba6ebf12c)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-08-21 11:53:05 +00:00
Serhiy Storchaka
92a578409b
[3.11] gh-107915: Handle errors in C API functions PyErr_Set*() and PyErr_Format() (GH-107918) (GH-108135)
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 633ea217a85f6b6ba5bdbc73094254d5811b3485)
2023-08-19 12:22:13 +00:00
Steve Dower
ccf81e1088
[3.11] gh-106242: Fix path truncation in os.path.normpath (GH-106816) (#107982)
Co-authored-by: Finn Womack <flan313@gmail.com>
2023-08-15 19:07:52 +02:00
Serhiy Storchaka
fced79f91e
[3.11] gh-86493: Fix possible leaks in some modules initialization (GH-106768) (GH-106855) (GH-106863)
[3.11] [3.12] gh-86493: Fix possible leaks in some modules initialization (GH-106768) (GH-106855)

Fix _ssl, _stat, _testinternalcapi, _threadmodule, cmath, math, posix, time.
(cherry picked from commit 3e65baee72131b49f4ce8ca2da568a6f2001ce93).
(cherry picked from commit a423ddbdeada8a2fd8657453b9e9f58ba0dd921d)
2023-07-19 09:40:38 +03:00
Miss Islington (bot)
ddfe8eb45f
[3.11] Document PYTHONSAFEPATH along side -P (GH-106122) (#106353)
(cherry picked from commit 0355625d94a50f4b816770bad946420d005900b8)

Co-authored-by: Jeremy Paige <ucodery@gmail.com>
2023-07-05 13:21:45 +02:00
Miss Islington (bot)
b937ca0a5a
[3.11] gh-101006: Improve error handling when read marshal data (GH-101007) (GH-106227)
* EOFError no longer overrides other errors such as MemoryError or OSError at
  the start of the object.
* Raise more relevant error when the NULL object occurs as a code object
  component.
* Minimize an overhead of calling PyErr_Occurred().
(cherry picked from commit 8bf6904b229583033035d91a3800da5604dcaad4)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-06-29 13:47:30 +03:00
Kumar Aditya
307c59a0c1
[3.11] gh-105979: Fix exception handling in unmarshal_frozen_code (Python/import.c) (GH-105980). (#106100)
* [3.11] gh-105979: Fix exception handling in `unmarshal_frozen_code` (`Python/import.c`) (GH-105980).
(cherry picked from commit cd5280367a3a7065d13b8f7234474f7a2e9a18fd)

Co-authored-by: chgnrdv <52372310+chgnrdv@users.noreply.github.com>
2023-06-26 09:00:51 +00:00
Serhiy Storchaka
dbe416b82b
[3.11] gh-106033: Get rid of new occurrences of PyDict_GetItem and Py… (#106040)
[3.11] gh-106033: Get rid of new occurrences of PyDict_GetItem and PyObject_HasAttr (GH-106034)

These functions are broken by design because they discard any exceptions raised
inside, including MemoryError and KeyboardInterrupt.  They should not be
used in new code..
(cherry picked from commit 1d33d5378058671bfabb6f4d4b5bfd4726973ff9)
2023-06-24 16:41:02 -07:00
Serhiy Storchaka
26d87fd5c7
[3.11] gh-106030: Miscellaneous fixes in Python/suggestions.c (GH-106… (GH-106039)
* PyUnicode_CompareWithASCIIString() only works if the second argument
  is ASCII string.
* Refleak in get_suggestions_for_name_error.
* Add some missing error checks.

(cherry picked from commit c8c162ef5294cddb7ac75fe93ab918e5661c68ee)
2023-06-23 21:13:07 +03:00
Miss Islington (bot)
2944a6cc0a
[3.11] GH-105840: Fix assertion failures when specializing calls with too many __defaults__ (GH-105864)
GH-105840: Fix assertion failures when specializing calls with too many __defaults__ (GH-105847)
(cherry picked from commit 2beab5bdef5fa2a00a59371e6137f769586b7404)

Co-authored-by: Brandt Bucher <brandtbucher@microsoft.com>
2023-06-16 18:30:22 +00:00
Miss Islington (bot)
c0c4186858
[3.11] GH-105588: Add missing error checks to some obj2ast_* converters (GH-105839)
GH-105588: Add missing error checks to some obj2ast_* converters (GH-105589)
(cherry picked from commit a4056c8f9c2d9970d39e3cb6bffb255cd4b8a42c)

Co-authored-by: Brandt Bucher <brandtbucher@microsoft.com>
2023-06-15 23:13:51 +00:00