Commit Graph

14462 Commits

Author SHA1 Message Date
sobolevn a64a1c9206
gh-126106: Fix `NULL` possible derefrence in `Modules/_ssl.c` (#126111)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-10-29 12:03:18 +03:00
Sergey B Kirpichev 9b14083497
Align functools.reduce() docstring with PEP-257 (#126045)
Yak-shave in preparation for Argument Clinic adaption in gh-125999.
2024-10-29 08:08:08 +00:00
Bénédikt Tran 19e93e2e26
gh-126035: add missing whitespace to *Py_EnterRecursiveCall() messages (#126036) 2024-10-27 22:55:48 +01:00
Bénédikt Tran ed5059eeb1
gh-125966: fix use-after-free on `fut->fut_callback0` due to an evil callback's `__eq__` in asyncio (#125967) 2024-10-27 22:40:10 +05:30
Bénédikt Tran f819d4301d
gh-125984: fix use-after-free on `fut->fut_{callback,context}0` due to an evil `loop.__getattribute__` (#126003) 2024-10-27 20:34:43 +05:30
Bénédikt Tran f6cc7c8bd0
gh-94512: Fix forced arg format in posixmodule.c clinic code (#122516) 2024-10-26 23:40:31 +02:00
Bénédikt Tran c5b99f5c2c
gh-125969: fix OOB in `future_schedule_callbacks` due to an evil `call_soon` (#125970)
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
2024-10-25 23:45:09 +05:30
Kumar Aditya cae853e3b4
GH-125789: fix `fut._callbacks` to always return a copy of callbacks (#125922)
Fix `asyncio.Future._callbacks` to always return a copy of the internal list of callbacks to avoid mutation from user code affecting the internal state.
2024-10-25 18:19:30 +05:30
Victor Stinner ebcc578dff
gh-115754: Use Py_GetConstant(Py_CONSTANT_EMPTY_STR) (#125583)
Replace PyUnicode_FromStringAndSize(NULL, 0)
with Py_GetConstant(Py_CONSTANT_EMPTY_STR).
2024-10-25 11:14:52 +02:00
Victor Stinner db96327203
gh-121654: Add PyType_Freeze() function (#122457)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2024-10-25 11:12:48 +02:00
Sam Gross 332356b880
gh-125900: Clean-up logic around immortalization in free-threading (#125901)
* Remove `@suppress_immortalization` decorator
* Make suppression flag per-thread instead of per-interpreter
* Suppress immortalization in `eval()` to avoid refleaks in three tests
  (test_datetime.test_roundtrip, test_logging.test_config8_ok, and
   test_random.test_after_fork).
* frozenset() is constant, but not a singleton. When run multiple times,
  the test could fail due to constant interning.
2024-10-24 18:09:59 -04:00
Eric Snow 4848b0b92c
gh-125716: Use A Global Mutex When Initializing Global State For The _interpqueues Module (gh-125803)
This includes a drive-by cleanup in _queues_init() and _queues_fini().

This change also applies to the _interpchannels module.
2024-10-21 15:49:58 -06:00
Eric Snow 44f841f01a
gh-125716: Raise an Exception If _globals_init() Fails In the _interpqueues Module (gh-125802)
The fix applies to the _interpchannels module as well.

I've also included a drive-by typo fix for _interpqueues.
2024-10-21 19:39:07 +00:00
Serhiy Storchaka dcc4fb2c90
gh-124969: Make locale.nl_langinfo(locale.ALT_DIGITS) returning a string again (GH-125774)
This is a follow up of GH-124974. Only Glibc needed a fix.
Now the returned value is a string consisting of semicolon-separated
symbols on all Posix platforms.
2024-10-21 18:54:12 +00:00
Peter Bierma 4c53b25775
gh-124984: Enhance `ssl` thread safety (#124993)
Make SSL objects thread safe in Free Theaded build by
using critical sections.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-10-19 23:16:36 +02:00
Serhiy Storchaka a7443a1735
gh-52551: Use wcsftime() to implement time.strftime() on Windows (GH-125658) 2024-10-19 11:29:51 +03:00
Eric Snow 6d93690954
gh-125604: Move _Py_AuditHookEntry, etc. Out of pycore_runtime.h (gh-125605)
This is essentially a cleanup, moving a handful of API declarations to the header files where they fit best, creating new ones when needed.

We do the following:

* add pycore_debug_offsets.h and move _Py_DebugOffsets, etc. there
* inline struct _getargs_runtime_state and struct _gilstate_runtime_state in _PyRuntimeState
* move struct _reftracer_runtime_state to the existing pycore_object_state.h
* add pycore_audit.h and move to it _Py_AuditHookEntry , _PySys_Audit(), and _PySys_ClearAuditHooks
* add audit.h and cpython/audit.h and move the existing audit-related API there
*move the perfmap/trampoline API from cpython/sysmodule.h to cpython/ceval.h, and remove the now-empty cpython/sysmodule.h
2024-10-18 09:26:08 -06:00
Eric Snow 7cf2dbc3cb
gh-125667: Statically Initialize the Arg Converter Data Values in _interpqueuesmodule.c (gh-125668) 2024-10-17 23:49:15 +00:00
chrysn b454662921
gh-118986: expose `socket.IPV6_RECVERR` (#118987) 2024-10-17 20:49:12 +03:00
Serhiy Storchaka ad3eac1963
gh-52551: Fix encoding issues in strftime() (GH-125193)
Fix time.strftime(), the strftime() method and formatting of the
datetime classes datetime, date and time.

* Characters not encodable in the current locale are now acceptable in
  the format string.
* Surrogate pairs and sequence of surrogatescape-encoded bytes are no
  longer recombinated.
* Embedded null character no longer terminates the format string.

This fixes also gh-78662 and gh-124531.
2024-10-17 15:46:59 +00:00
Jonathan Protzenko 528bbab96f
GH-99108: Make vectorized versions of Blake2 available on x86, too (#125244)
Accomplished by updating HACL* vendored code from hacl-star/hacl-star@a6a09496d9 to hacl-star/hacl-star@315a9e491d

Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
2024-10-17 15:08:43 +00:00
Kirill Podoprigora bee112a94d
gh-124872: Replace enter/exit events with "switched" (#125532)
Users want to know when the current context switches to a different
context object.  Right now this happens when and only when a context
is entered or exited, so the enter and exit events are synonymous with
"switched".  However, if the changes proposed for gh-99633 are
implemented, the current context will also switch for reasons other
than context enter or exit.  Since users actually care about context
switches and not enter or exit, replace the enter and exit events with
a single switched event.

The former exit event was emitted just before exiting the context.
The new switched event is emitted after the context is exited to match
the semantics users expect of an event with a past-tense name.  If
users need the ability to clean up before the switch takes effect,
another event type can be added in the future.  It is not added here
because YAGNI.

I skipped 0 in the enum as a matter of practice.  Skipping 0 makes it
easier to troubleshoot when code forgets to set zeroed memory, and it
aligns with best practices for other tools (e.g.,
https://protobuf.dev/programming-guides/dos-donts/#unspecified-enum).

Co-authored-by: Richard Hansen <rhansen@rhansen.org>
Co-authored-by: Victor Stinner <vstinner@python.org>
2024-10-16 13:53:21 +02:00
Mikhail Efimov aac89b54c5
gh-125206: Bug in ctypes with old libffi is fixed (#125322)
Workaround for old libffi versions is added.
Module ctypes now supports C11 double complex only with libffi >= 3.3.0.

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
2024-10-15 16:17:10 +00:00
Kirill Podoprigora d3c82b9cce
gh-125512: Revert "gh-124872: Replace enter/exit events with "switched" (#124776)" (#125513) 2024-10-15 17:42:16 +03:00
Steven Jin 1bffd7a2a7
gh-124944: Add socket.SO_ORIGINAL_DST (#124945) 2024-10-15 00:36:38 +02:00
Richard Hansen 843d28f59d
gh-124872: Replace enter/exit events with "switched" (#124776)
Users want to know when the current context switches to a different
context object.  Right now this happens when and only when a context
is entered or exited, so the enter and exit events are synonymous with
"switched".  However, if the changes proposed for gh-99633 are
implemented, the current context will also switch for reasons other
than context enter or exit.  Since users actually care about context
switches and not enter or exit, replace the enter and exit events with
a single switched event.

The former exit event was emitted just before exiting the context.
The new switched event is emitted after the context is exited to match
the semantics users expect of an event with a past-tense name.  If
users need the ability to clean up before the switch takes effect,
another event type can be added in the future.  It is not added here
because YAGNI.

I skipped 0 in the enum as a matter of practice.  Skipping 0 makes it
easier to troubleshoot when code forgets to set zeroed memory, and it
aligns with best practices for other tools (e.g.,
https://protobuf.dev/programming-guides/dos-donts/#unspecified-enum).
2024-10-14 12:28:41 -07:00
Bénédikt Tran c77121e9f1
gh-111178: fix USAN failures for `partialobject` (#124733) 2024-10-14 16:23:05 +02:00
Kumar Aditya 67f6e08147
gh-125139: use `_PyRecursiveMutex` in `_thread.RLock` (#125144) 2024-10-14 14:06:31 +05:30
Serhiy Storchaka 5217328f93
gh-121798: Add class method Decimal.from_number() (GH-121801)
It is an alternate constructor which only accepts a single numeric argument.
Unlike to Decimal.from_float() it accepts also Decimal.
Unlike to the standard constructor, it does not accept strings and tuples.
2024-10-14 08:24:01 +00:00
Sam Gross f1d33dbddd
gh-125243: Fix ZoneInfo data race in free threading build (#125281)
Lock `ZoneInfoType` to protect accesses to `ZONEINFO_STRONG_CACHE`.
Refactor the `tp_new` handler to use Argument Clinic so that we can just
use `@critical_section` annotations on the relevant functions.

Also use `PyDict_SetDefaultRef` instead of `PyDict_SetDefault` when
inserting into the `TIMEDELTA_CACHE`.
2024-10-13 16:17:51 -04:00
Richard Hansen 330c527299
gh-124872: Change PyContext_WatchCallback to take PyObject (#124737)
The PyContext struct is not intended to be public, and users of the
API don't need anything more specific than PyObject.  Also see
gh-78943.
2024-10-12 13:57:27 -07:00
Jelle Zijlstra cc2938a189
gh-124917: Allow keyword args to os.path.exists/lexists on Windows (#124918) 2024-10-11 12:41:59 -07:00
AN Long a00221e5a7
gh-116738: Make `_csv` module thread-safe (#118344) 2024-10-11 23:25:36 +05:30
Y5 b3aa1b5fe2
gh-125235: Keep `_tkinter` TCL paths pointing to base installation on Windows (#125250)
Signed-off-by: y5c4l3 <y5c4l3@proton.me>
2024-10-11 11:08:03 +02:00
Mark Shannon c9014374c5
GH-125174: Make immortal objects more robust, following design from PEP 683 (GH-125251) 2024-10-10 18:19:08 +01:00
Victor Stinner c914212474
gh-125196: Use PyUnicodeWriter for JSON encoder (#125249)
Replace the private _PyUnicodeWriter with the public PyUnicodeWriter.
2024-10-10 15:33:00 +02:00
Sergey B Kirpichev 87d7315ac5
gh-125118: don't copy arbitrary values to _Bool in the struct module (GH-125169)
memcopy'ing arbitrary values to _Bool variable triggers undefined
behaviour. Avoid this.
We assume that `false` is represented by all zero bytes.

Credits to Alex Gaynor.

Co-authored-by: Sam Gross <colesbury@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2024-10-10 14:42:03 +02:00
Victor Stinner b9a8ca0a6a
gh-115754: Use Py_GetConstant(Py_CONSTANT_EMPTY_STR) (#125194)
Replace PyUnicode_New(0, 0), PyUnicode_FromString("")
and PyUnicode_FromStringAndSize("", 0)
with Py_GetConstant(Py_CONSTANT_EMPTY_STR).
2024-10-09 17:15:23 +02:00
Victor Stinner 6a39e96ab8
gh-115754: Use Py_GetConstant(Py_CONSTANT_EMPTY_BYTES) (#125195)
Replace PyBytes_FromString("") and PyBytes_FromStringAndSize("", 0)
with Py_GetConstant(Py_CONSTANT_EMPTY_BYTES).
2024-10-09 17:12:11 +02:00
Serhiy Storchaka 21c04e1a97
gh-124969: Fix locale.nl_langinfo(locale.ALT_DIGITS) (GH-124974)
Now it returns a tuple of up to 100 strings (an empty tuple on most locales).
Previously it returned the first item of that tuple or an empty string.
2024-10-09 11:42:08 +03:00
Kumar Aditya fca552993d
gh-117721: use PyMutex in `_thread.lock` (#125110) 2024-10-08 20:17:32 +05:30
Bénédikt Tran e4292c0410
gh-123961: Convert _curses to a multi-phase init module (PEP-489) (#124965) 2024-10-08 13:42:44 +02:00
Serhiy Storchaka 93b9e6bd7d
gh-69998: Fix decoding error in locale.nl_langinfo() (GH-124963)
The function now sets temporarily the LC_CTYPE locale to the locale
of the category that determines the requested value if the locales are
different and the resulting string is non-ASCII.
This temporary change affects other threads.
2024-10-08 11:27:49 +03:00
Cody Maloney cc9b9bebb2
gh-90102: Remove isatty call during regular open (#124922)
Co-authored-by: Victor Stinner <vstinner@python.org>
2024-10-08 08:50:42 +02:00
Victor Stinner a7f0727ca5
gh-124502: Add PyUnicode_Equal() function (#124504) 2024-10-07 21:24:53 +00:00
sobolevn 51d426dc03
gh-124956: Use `#undef` for temp macros in `_csv.c` (#124957) 2024-10-07 23:05:56 +05:30
Victor Stinner d8f707420b
gh-111178: Fix function signatures in fileio.c (#125043)
* Add "fileio_" prefix to getter functions.
* Small refactoring.
2024-10-07 15:27:36 +02:00
Sergey B Kirpichev 7487db4c7a
gh-121249: Support _Complex types in the struct module (#121613)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2024-10-07 13:53:02 +02:00
Victor Stinner ddccd546a0
gh-111178: Fix function signatures in _threadmodule.c (#124964) 2024-10-04 12:50:01 +02:00
Bénédikt Tran f66d785861
gh-123961: Convert `curses.window` static type into a heap type (#124934) 2024-10-04 11:58:34 +02:00