Commit Graph

14517 Commits

Author SHA1 Message Date
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
Bénédikt Tran e6dd71da3a
gh-123961: Clean up curses C API/capsule (#124907) 2024-10-03 10:48:50 +00:00
Jeremy Maitin-Shepard 8cc5aa47ee
gh-87135: Hang non-main threads that attempt to acquire the GIL during finalization (GH-105805)
Instead of surprise crashes and memory corruption, we now hang threads that attempt to re-enter the Python interpreter after Python runtime finalization has started. These are typically daemon threads (our long standing mis-feature) but could also be threads spawned by extension modules that then try to call into Python. This marks the `PyThread_exit_thread` public C API as deprecated as there is no plausible safe way to accomplish that on any supported platform in the face of things like C++ code with finalizers anywhere on a thread's stack. Doing this was the least bad option.

Co-authored-by: Gregory P. Smith <greg@krypto.org>
2024-10-02 09:17:49 -07:00
Peter Bierma c2ba931318
gh-120378: Fix crash caused by integer overflow in `curses` (#124555)
This is actually an upstream problem in curses, and has been reported
to them already:
https://lists.gnu.org/archive/html/bug-ncurses/2024-09/msg00101.html

This is a nice workaround in the meantime to prevent the segfault.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-10-02 14:31:23 +00:00
Victor Stinner 1d4e3e0585
gh-111178: Fix locale_free() signature (#124896) 2024-10-02 13:58:47 +00:00
Sam Gross 5aa91c56bf
gh-124296: Remove private dictionary version tag (PEP 699) (#124472) 2024-10-01 12:39:56 -04:00
Jeffrey R. Van Voorst 7e7223e18f
gh-116810: fix memory leak in ssl module (GH-123249)
Resolve a memory leak introduced in CPython 3.10's :mod:`ssl` when the :attr:`ssl.SSLSocket.session` property was accessed. Speeds up read and write access to said property by no longer unnecessarily cloning session objects via serialization.

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: Gregory P. Smith <greg@krypto.org>
Co-authored-by: Antoine Pitrou <antoine@python.org>
2024-09-30 12:43:50 -07:00
Bénédikt Tran 6d0d26eb8c
gh-111495: Add tests for `PyCodec_*` C API (#123343) 2024-09-29 15:22:39 +00:00
Bénédikt Tran 4d8e7c40a0
gh-123961: Add a global state to _curses (#124729) 2024-09-29 15:17:20 +00:00
Bénédikt Tran 12417a984c
gh-123290: Fix decref in _curses update_lines_cols() (#124767) 2024-09-29 15:02:43 +00:00
Serhiy Storchaka d08c788822
gh-123497: New limit for Python integers on 64-bit platforms (GH-123724)
Instead of be limited just by the size of addressable memory (2**63
bytes), Python integers are now also limited by the number of bits, so
the number of bit now always fit in a 64-bit integer.

Both limits are much larger than what might be available in practice,
so it doesn't affect users.

_PyLong_NumBits() and _PyLong_Frexp() are now always successful.
2024-09-29 10:40:20 +03:00
Bénédikt Tran c00964ecd5
gh-124665: Add `_PyCodec_UnregisterError` and `_codecs._unregister_error` (#124677) 2024-09-29 02:25:23 +02:00
neonene dc12237ab0
gh-124688: _decimal: Get module state from ctx for performance (#124691)
Get a module state from ctx objects for performance.
2024-09-28 16:12:53 +00:00
Malcolm Smith 0a3577bdfc
gh-123017: Add Android to the list of platforms where `strftime` doesn't support negative years (#124467)
Add Android to the list of platforms where `strftime` doesn't support negative years
2024-09-27 10:35:18 -04:00
neonene d7248cdbc3
gh-124153: Remove `_PyType_GetModuleByDef2` private function (GH-124261)
Thank you!
2024-09-26 18:21:11 +02:00
Kirill Podoprigora 9c98fdab7d
gh-124606: Fix reference leak in error path in `datetime_fromisoformat` in `_datetimemodule.c` (#124607)
Previously `tzdata` and `dtstr_clean` were not decrefed in the `invalid_iso_midnight` error path of the `datetime_isoformat` function.
2024-09-26 15:30:21 +00:00
Victor Stinner 257a20a817
gh-119127: Fix _functools.Placeholder singleton (#124601)
* The module state now stores a strong reference to the Placeholder
  singleton.
* Use a regular dealloc function.
* Add Py_TPFLAGS_HAVE_GC flag and a traverse function to help the GC
  to collect the type when a _functools extension is unloaded.
2024-09-26 16:50:38 +02:00
dgpb d9296529eb
gh-119127: functools.partial placeholders (gh-119827) 2024-09-26 01:04:38 +00:00
Nice Zombies 9968caa0cc
gh-41431: Add `datetime.time.strptime()` and `datetime.date.strptime()` (#120752)
* Python implementation

* C implementation

* Test `date.strptime`

* Test `time.strptime`

* 📜🤖 Added by blurb_it.

* Update whatsnew

* Update documentation

* Add leap year note

* Update 2024-06-19-19-53-42.gh-issue-41431.gnkUc5.rst

* Apply suggestions from code review

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

* Remove parentheses

* Use helper function

* Remove bad return

* Link to github issue

* Fix directive

* Apply suggestions from code review

Co-authored-by: Paul Ganssle <1377457+pganssle@users.noreply.github.com>

* Fix test cases

---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Paul Ganssle <1377457+pganssle@users.noreply.github.com>
2024-09-25 14:43:58 -07:00
TizzySaurus b0c6cf5f17
gh-102450: Add ISO-8601 alternative for midnight to `fromisoformat()` calls. (#105856)
* Add NEWS.d entry

* Allow ISO-8601 24:00 alternative to midnight on datetime.time.fromisoformat()

* Allow ISO-8601 24:00 alternative to midnight on datetime.datetime.fromisoformat()

* Add NEWS.d entry

* Improve error message when hour is 24 and minute/second/microsecond is not 0

* Add tests for 24:00 fromisoformat

* Remove duplicate call to days_in_month() by storing in variable

* Add Python implementation

* Fix Lint

* Fix differing error msg in datetime.fromisoformat implementations when 24hrs has non-zero time component(s)

* Fix using time components inside tzinfo in Python implementation

* Don't parse tzinfo in C implementation when invalid iso midnight

* Remove duplicated variable in datetime test assertion line

* Add self to acknowledgements

* Remove duplicate NEWS entry

* Linting

* Add missing test case for when wrapping the year makes it invalid (too large)
2024-09-25 14:32:51 -07:00
Raymond Hettinger 909c6f7189
gh-123884 Tee of tee was not producing n independent iterators (gh-124490) 2024-09-25 13:38:05 -07:00
Malcolm Smith c58c572a65
gh-123014: Disable pidfd API on older Android versions (#124458) 2024-09-25 16:23:30 +02:00
Sam Gross f4997bb3ac
gh-123923: Defer refcounting for `f_funcobj` in `_PyInterpreterFrame` (#124026)
Use a `_PyStackRef` and defer the reference to `f_funcobj` when
possible. This avoids some reference count contention in the common case
of executing the same code object from multiple threads concurrently in
the free-threaded build.
2024-09-24 20:08:18 +00:00
Serhiy Storchaka e670a113b5
gh-123978: Remove broken time.thread_time() on NetBSD (GH-124116) 2024-09-24 08:26:25 +00:00
Jason Fried d87482bc4e
gh-119333: Add C api to have contextvar enter/exit callbacks (#119335)
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2024-09-23 20:40:17 -07:00
Petr Viktorin be76e3f26e
gh-100980: ctypes: Test, document, and fix finalizing _fields_ (GH-124292)
- If setting `_fields_` fails, e.g. with AttributeError, don't set the attribute in `__dict__`
- Document the “finalization” behaviour
- Beef up tests: add `getattr`, test Union as well as Structure
- Put common functionality in a common function

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2024-09-24 02:40:53 +02:00
Brian Schubert 63f196090f
gh-124248: Fix crash in struct when processing 0p fields (#124251) 2024-09-20 12:08:59 +02:00
Petr Viktorin aee219f455
gh-123880: Allow recursive import of single-phase-init modules (GH-123950)
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Co-authored-by: Brett Cannon <brett@python.org>
2024-09-20 10:27:34 +02:00
sobolevn 3e36e5aef1
gh-123797: Check for runtime availability of `ptsname_r` on macos (#123806) 2024-09-20 09:30:27 +03:00
Victor Stinner 43cd7aa8cd
gh-120754: Fix memory leak in FileIO.__init__() (#124225)
Free 'self->stat_atopen' before assigning it, since
io.FileIO.__init__() can be called multiple times manually
(especially by test_io).
2024-09-19 00:11:50 +02:00
Cody Maloney 8b6c7c7877
gh-120754: Refactor I/O modules to stash whole stat result rather than individual members (#123412)
Multiple places in the I/O stack optimize common cases by using the
information from stat. Currently individual members are extracted from
the stat and stored into the fileio struct. Refactor the code to store
the whole stat struct instead.

Parallels the changes to _io. The `stat` Python object doesn't allow
changing members, so rather than modifying estimated_size, just clear
the value.
2024-09-18 17:47:57 +02:00
sobolevn 3b6bfa77aa
gh-102511: Change the `os.path.splitroot` param name from `path` back to `p` (GH-124097) 2024-09-18 15:17:32 +01:00
neonene 646f16bdee
gh-124153: Implement `PyType_GetBaseByToken()` and `Py_tp_token` slot (GH-124163) 2024-09-18 09:18:19 +02:00
Serhiy Storchaka 79a7410236
Revert "gh-123974: Fix time.get_clock_info() on NetBSD (#123975)" (GH-124115)
This reverts commit b1d6f8a2ee.
2024-09-18 09:29:24 +03:00
Sergey B Kirpichev f4dd440210
gh-123836: workaround fmod(x, y) bug on Windows (#124171)
Buildbot failure on Windows 10 with MSC v.1916 64 bit (AMD64):
FAIL: testFmod (test.test_math.MathTests.testFmod)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_math.py", line 605, in testFmod
    self.ftest('fmod(-10, 1)', math.fmod(-10, 1), -0.0)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_math.py", line 258, in ftest
    self.fail("{}: {}".format(name, failure))
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: fmod(-10, 1): expected -0.0, got 0.0 (zero has wrong sign)

Here Windows loose sign of the result; if y is nonzero, the result
should have the same sign as x.

This amends commit 28aea5d07d.
2024-09-17 17:16:15 +00:00
Jakub Kulík f15fff3f13
gh-110190: Fix ctypes structs with array on SPARC (GH-118233) 2024-09-17 19:06:53 +02:00
sobolevn a9c2bc1634
gh-121023: Improve `_xxtestfuzz/README.rst` (#121024)
Co-authored-by: Illia Volochii <illia.volochii@gmail.com>
2024-09-16 23:28:09 +03:00
Irit Katriel 453da532fe
gh-97588: remove unused functions in _ctypes/cfield.c (GH-124010) 2024-09-16 14:13:18 +02:00
Russell Keith-Magee ef530ce7c6
gh-123748: Add conditional compilation rules for HACL SIMD256 and SIMD128 on macOS (#123989)
Add conditional compilation rules to allow HACL SIMD256 and SIMD128 to be ignored on the ARM64 pass of universal2 macOS builds.
2024-09-16 12:23:05 +08:00
Furkan Onder b1d6f8a2ee
gh-123974: Fix time.get_clock_info() on NetBSD (#123975)
Fix OSError for thread_time clock on NetBSD by setting default resolution.
2024-09-13 22:34:25 +02:00
Wenzel Jakob 74330d992b
gh-100554: Add ``Py_tp_vectorcall`` slot to set ``PyTypeObject.tp_vectorcall`` using the ``PyType_FromSpec`` function family. (#123332) 2024-09-13 17:40:25 +02:00
Benjamin Peterson bb904e063d
closes gh-124016: update Unicode to 16.0.0 (#124017) 2024-09-13 07:47:04 -07:00
Bénédikt Tran acb3f875fb
gh-123961: Add `curses` prefix to global variables in `_cursesmodule.c` (#124047)
Use the `const char*` type instead of a `const *` for the encoding name.
2024-09-13 12:43:06 +00:00
Bénédikt Tran e49d1b44d3
gh-124044: protect macros expansions in `_cursesmodules.c` using `do { ... } while (0)` (#124045) 2024-09-13 11:26:19 +00:00
Bénédikt Tran 403f3ddedc
gh-123961: Remove global variable `ModDict` in `_cursesmodule.c` (#123962) 2024-09-13 10:33:13 +00:00
Sam Gross b2afe2aae4
gh-123923: Defer refcounting for `f_executable` in `_PyInterpreterFrame` (#123924)
Use a `_PyStackRef` and defer the reference to `f_executable` when
possible. This avoids some reference count contention in the common case
of executing the same code object from multiple threads concurrently in
the free-threaded build.
2024-09-12 12:37:06 -04:00
Bénédikt Tran 2938c3dec9
gh-123290: fix reference leaks in the error-branches of `_cursesmodule.c` (#123953) 2024-09-11 15:49:33 +00:00
Serhiy Storchaka c0c2aa7644
gh-122213: Add notes for pickle serialization errors (GH-122214)
This allows to identify the source of the error.
2024-09-09 21:28:55 +03:00
Jérôme Duval 65fcaa38ad
gh-84808: socket.connect_ex: Handle negative errno (GH-122304)
POSIX allows errno to be negative.
Even though all currently supported platforms have non-negative errno,
relying on a quirk like that would make Python less portable.
2024-09-09 14:59:13 +00:00
algonell 9017b95ff2
Fix typos (#123775) 2024-09-09 14:58:26 +02:00
Serhiy Storchaka b2a8c38bb2
gh-122311: Improve and unify pickle errors (GH-122771)
* Raise PicklingError instead of UnicodeEncodeError, ValueError
  and AttributeError in both implementations.
* Chain the original exception to the pickle-specific one as __context__.
* Include the error message of ImportError and some AttributeError in
  the PicklingError error message.
* Unify error messages between Python and C implementations.
* Refer to documented __reduce__ and __newobj__ callables instead of
  internal methods (e.g. save_reduce()) or pickle opcodes (e.g. NEWOBJ).
* Include more details in error messages (what expected, what got).
* Avoid including a potentially long repr of an arbitrary object in
  error messages.
2024-09-09 15:04:51 +03:00
Bénédikt Tran 05a401a5c3
chore: decimal module macro cleanup (#123791)
* protect macros expansion via `do { ... } while (0)` constructions in `_decimal.c`

* Use public macro `Py_UNUSED`

This replaces the usages of the `UNUSED` macro which
was not consistent with the `Py_UNUSED` macro itself.

In addition, this amends the parameter names so that
they match their semantic meanings.

* Remove redundant `PyCFunction` casts
2024-09-09 11:24:24 +02:00
Adam Turner 93b61bc124
gh-123843: Remove broken links to the Zope DateTimeWiki (#123846)
Co-authored-by: Conrad Bhuiyan-Volkoff <hi@cbv.im>
2024-09-08 22:39:23 -04:00
neonene 853588e24c
gh-123657: Fix crash and refleak in `decimal.getcontext()` (GH-123703) 2024-09-06 13:15:23 +02:00
Furkan Onder f8f7500168
gh-123718: Fix implicit declaration of 'explicit_memset' for NetBSD 10.0 (#123719)
Fix implicit declaration of 'explicit_memset' for NetBSD 10.0 in Lib_Memzero0.c.
2024-09-06 00:09:04 +00:00
nkinnan b5aa271f86
gh-123476: Add support for TCP_QUICKACK socket setting to Windows (#123478)
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Steve Dower <steve.dower@microsoft.com>
2024-09-05 22:59:48 +02:00
Petr Viktorin 16be8db6be
gh-123465: Allow Py_RELATIVE_OFFSET for __*offset__ members (GH-123474) 2024-09-05 14:14:05 +02:00
Petr Viktorin ce9f84a47b
gh-97588: Move ctypes struct/union layout logic to Python (GH-123352)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-09-05 11:20:07 +02:00
Seth Michael Larson 40bdb0deee
gh-123678: Upgrade libexpat 2.6.3 (#123689)
Upgrade libexpat 2.6.3
2024-09-04 12:57:16 -07:00
Peter Bierma 2daed5f7a7
gh-123504: Fix regression in `_tkinter` initializer (#123662)
* Add module traverse function to _tkinter.
* Set m_size to -1 (instead of 0).
2024-09-04 13:43:50 +02:00
Peter Bierma a8bc03696c
gh-123504: Fix reference leak in finalization of `_tkinter` (#123505) 2024-09-03 20:35:57 +00:00
Victor Stinner 33b790978d
gh-107954, PEP 741: Add PyConfig_Get()/Set() functions (#123472)
Add PyConfig_Get(), PyConfig_GetInt(), PyConfig_Set() and
PyConfig_Names() functions to get and set the current runtime Python
configuration.

Add visibility and "sys spec" to config and preconfig specifications.

_PyConfig_AsDict() now converts PyConfig.xoptions as a dictionary.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-09-02 23:25:08 +02:00
Petr Viktorin 57c471a688
gh-123091: Use more _Py_IsImmortalLoose() (GH-123602)
Switch more _Py_IsImmortal(...) assertions to _Py_IsImmortalLoose(...)

The remaining calls to _Py_IsImmortal are in free-threaded-only code,
initialization of core objects, tests, and guards that fall back to
code that works with mortal objects.
2024-09-02 18:17:48 +02:00
Victor Stinner d8e69b2c1b
gh-122854: Add Py_HashBuffer() function (#122855) 2024-08-30 15:42:27 +00:00
Victor Stinner 3d60dfbe17
gh-121645: Add PyBytes_Join() function (#121646)
* Replace _PyBytes_Join() with PyBytes_Join().
* Keep _PyBytes_Join() as an alias to PyBytes_Join().
2024-08-30 12:57:33 +00:00
Kirill Podoprigora 8aaf7525ab
gh-123189: [`Modules/blake2module.c`]: Move function definitions and their usage under the macros (#123190) 2024-08-30 13:28:32 +03:00
Serhiy Storchaka 32c7dbb2bc
gh-121485: Always use 64-bit integers for integers bits count (GH-121486)
Use 64-bit integers instead of platform specific size_t or Py_ssize_t
to represent the number of bits in Python integer.
2024-08-30 08:13:24 +03:00
sobolevn 58ce131037
gh-123446: Fix empty function names in `TypeError`s in `_csv` module (#123462) 2024-08-29 11:12:37 +03:00
sobolevn 303f92a9ce
gh-123446: Fix empty function names in `TypeError`s in `_csv` module (#123461) 2024-08-29 06:53:57 +00:00
Serhiy Storchaka 0c3ea30238
gh-123431: Harmonize extension code checks in pickle (GH-123434)
This checks are redundant in normal circumstances and can only work if
the extension registry was intentionally broken.

* The Python implementation now raises exception for the extension code
  with false boolean value.
* Simplify the C code. RuntimeError is now raised in explicit checks.
* Add many tests.
2024-08-29 08:26:16 +03:00
Peter Bierma c9930f5022
gh-123448: Move `_PyNoDefault_Type` to the static types array (#123449) 2024-08-28 18:27:40 -07:00
Wulian 9e108b8719
Fix typos in docs, error messages and comments (#123336)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-08-28 14:41:04 +03:00
Victor Stinner 4c6dca8292
gh-120389: Add PyLong_FromInt64() and PyLong_AsInt64() (#120390)
Add new functions to convert C <stdint.h> numbers from/to Python int:

* PyLong_FromInt32()
* PyLong_FromUInt32()
* PyLong_FromInt64()
* PyLong_FromUInt64()
* PyLong_AsInt32()
* PyLong_AsUInt32()
* PyLong_AsInt64()
* PyLong_AsUInt64()
2024-08-28 10:16:13 +00:00
Sergey B Kirpichev 2f20f5a9bc
gh-111495: Add tests for PyNumber C API (#111996) 2024-08-26 15:59:22 +02:00
Sergey B Kirpichev dbc1752d41
gh-111495: Add tests for PyTuple C API (#118757)
Co-authored-by: kalyanr <kalyan.ben10@live.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2024-08-26 11:57:52 +02:00
neonene 5ff638f1b5
gh-123243: Fix reference leak in `_decimal` (#123244) 2024-08-24 09:37:01 +05:30
blhsing 126910edba
gh-122272: Guarantee specifiers %F and %C for datetime.strftime to be 0-padded (GH-122436) 2024-08-23 18:45:03 +03:00
Bar Harel 90b6d0e0f8
gh-123213: Fixed xml.etree.ElementTree.Element.extend and assignment to no longer hide exceptions (GH-123214) 2024-08-23 12:12:58 +03:00
Jonathan Protzenko a64aa47302
GH-99108: Amend Modules/Setup (#123146) 2024-08-23 08:40:31 +02:00
Wulian 94036e43a8
Fix typos in comments (#123201) 2024-08-21 12:49:23 +00:00
Sergey B Kirpichev b9e10d1a0f
gh-122081: fixed crash in decimal.IEEEContext() (#122082)
* gh-122081: fixed crash in decimal.IEEEContext()

Now

$ ./configure CFLAGS=-DEXTRA_FUNCTIONALITY -q && make -s && \
     ./python -m test test_decimal

- PASS

* Apply suggestions from code review

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

* Update Misc/NEWS.d/next/Library/2024-07-21-10-45-24.gh-issue-122081.dNrYMq.rst

* Apply suggestions from code review

---------

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2024-08-19 07:51:38 +00:00
Sergey B Kirpichev 19be0ee931
gh-122681: remove m_atan2()/c_atan2() helpers (#122715) 2024-08-17 13:48:16 +05:30
Jonathan Protzenko 325e9b8ef4
gh-99108: Add HACL* Blake2 implementation to hashlib (GH-119316)
This replaces the existing hashlib Blake2 module with a single implementation that uses HACL\*'s Blake2b/Blake2s implementations. We added support for all the modes exposed by the Python API, including tree hashing, leaf nodes, and so on. We ported and merged all of these changes upstream in HACL\*, added test vectors based on Python's existing implementation, and exposed everything needed for hashlib.

This was joint work done with @R1kM.

See the PR for much discussion and benchmarking details.   TL;DR: On many systems, 8-50% faster (!) than `libb2`, on some systems it appeared 10-20% slower than `libb2`.
2024-08-13 21:42:19 +00:00
Eric Snow 503af8fe9a
gh-117482: Make the Slot Wrapper Inheritance Tests Much More Thorough (gh-122867)
There were a still a number of gaps in the tests, including not looking
at all the builtin types and not checking wrappers in subinterpreters
that weren't in the main interpreter. This fixes all that.

I considered incorporating the names of the PyTypeObject fields
(a la gh-122866), but figured doing so doesn't add much value.
2024-08-12 19:19:33 +00:00
Serhiy Storchaka f9ba1f35c7
gh-122688: Add more tests for var-positional parameters in Argument Clinic (GH-122900) 2024-08-12 16:52:48 +03:00
Kumar Aditya 3aaed083a3
GH-120974: make `_asyncio.all_tasks` thread safe (#122801)
Make `_asyncio.all_tasks` thread safe, also changes state lock to use critical section.
2024-08-11 20:49:31 +05:30
Nico Mexis 5580f31c56
gh-115808: Add ``is_none`` and ``is_not_none`` to ``operator`` (#115814)
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
2024-08-10 20:16:34 +01:00
Victor Stinner b4a316087c
gh-111495: Fix refleaks in test_capi.test_eval tests (#122851) 2024-08-09 09:47:00 +00:00
Serhiy Storchaka 8393608dd9
gh-122688: Fix support of var-positional parameter in Argument Clinic (GH-122689)
* Parameters after the var-positional parameter are now keyword-only
  instead of positional-or-keyword.
* Correctly calculate min_kw_only.
* Raise errors for invalid combinations of the var-positional parameter
  with "*", "/" and deprecation markers.
2024-08-09 09:22:41 +00:00
Sergey B Kirpichev b6e745a27e
gh-121268: Remove workarounds for non-IEEE 754 systems in cmath (#122716)
As now building Python now requires support of IEEE 754 floating point
numbers.
2024-08-09 11:17:40 +02:00
Malcolm Smith 2f5c3b09e4
gh-116622: Rename build variable MODULE_LDFLAGS back to LIBPYTHON (#122764)
(LIBPYTHON was renamed MODULE_LDFLAGS in commit 7f5e3f04f.)
2024-08-09 00:00:55 +02:00
Victor Stinner bf8b374639
gh-111495: Add more tests on PyEval C APIs (#122789)
* Add Lib/test/test_capi/test_eval.py
* Add Modules/_testlimitedcapi/eval.c
2024-08-08 14:16:20 +02:00
Erlend E. Aasland e006c7371d
gh-105201: Add PyIter_NextItem() (#122331)
Return -1 and set an exception on error; return 0 if the iterator is
exhausted, and return 1 if the next item was fetched successfully.

Prefer this API to PyIter_Next(), which requires the caller to use
PyErr_Occurred() to differentiate between iterator exhaustion and errors.

Co-authered-by: Irit Katriel <iritkatriel@yahoo.com>
2024-08-08 00:47:15 +02:00
Serhiy Storchaka 540fcc62f5
gh-118814: Fix the TypeVar constructor when name is passed by keyword (GH-122664)
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.
2024-08-07 23:30:10 +03:00
Lucas Esposito 0bd93755f3
gh-100256: Skip inaccessible registry keys in the WinAPI mimetype implementation (GH-122047) 2024-08-07 16:07:26 +01:00
Victor Stinner 4767a6e31c
gh-122728: Fix SystemError in PyEval_GetLocals() (#122735)
Fix PyEval_GetLocals() to avoid SystemError ("bad argument to
internal function"). Don't redefine the 'ret' variable in the if
block.

Add an unit test on PyEval_GetLocals().
2024-08-06 23:01:44 +02:00
Sergey B Kirpichev 0b433aa9df
gh-122681: merge m_atan2() and c_atan2() helper functions (#122682) 2024-08-06 14:43:13 +02:00
Kirill Podoprigora 94a4bd79a7
gh-122704: Fix reference leak in Modules/_pickle.c (GH-122705) 2024-08-06 08:57:36 +03:00
Serhiy Storchaka 1bb955a2fe
gh-122459: Optimize pickling by name objects without __module__ (GH-122460) 2024-08-05 16:21:32 +03:00
Sergey B Kirpichev e6fad7a0e3
gh-122637: fix tanh(±0+infj) and tanh(±0+nanj) to return ±0+nanj (#122638)
As per C11 DR#471, ctanh (0 + i NaN) and ctanh (0 + i Inf) should return
0 + i NaN (with "invalid" exception in the second case).  This has
corresponding implications for ctan(z), as its errors and special cases
are handled as if the operation is implemented by -i*ctanh(i*z).
This patch fixes cmath's code to do same.

Glibs patch: https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=d15e83c5f5231d971472b5ffc9219d54056ca0f1
2024-08-04 10:05:30 +01:00
Sergey B Kirpichev 3462a80d2c
gh-121889: cmath.acosh(0+nanj) returns nan+pi/2j (#121892)
As per C11 DR#471 (adjusted resolution accepted for C17), cacosh (0 +
iNaN) should return NaN ± i pi/2, not NaN + iNaN.  This patch
fixes cmath's code to do same.
2024-08-04 09:53:17 +01:00
Sam Gross b5e6fb39a2
gh-120974: Make asyncio `swap_current_task` safe in free-threaded build (#122317)
* gh-120974: Make asyncio `swap_current_task` safe in free-threaded build
2024-08-02 19:02:08 +05:30
Victor Stinner addbb73927
Update PyObject_Del() documentation (#122597)
Replace PyMem_Del() with PyMem_Free().
2024-08-02 12:13:33 +02:00
Victor Stinner fda6bd842a
Replace PyObject_Del with PyObject_Free (#122453)
PyObject_Del() is just a alias to PyObject_Free() kept for backward
compatibility. Use directly PyObject_Free() instead.
2024-08-01 14:12:33 +02:00
Malcolm Smith 06656e259b
gh-116622: Don't expose `FICLONE` ioctl on Android (#122522)
Don't expose `FICLONE` ioctl on Android

Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
2024-08-01 00:23:10 +00:00
Cody Maloney a9344cdffa
gh-121381 Remove subprocess._USE_VFORK escape hatch (#121383)
This flag was added as an escape hatch in gh-91401 and backported to
Python 3.10. The flag broke at some point between its addition and now.
As there is currently no publicly known environments that require this,
remove it rather than work on fixing it.

This leaves the flag in the subprocess module to not break code which
may have used / checked the flag itself.

discussion: https://discuss.python.org/t/subprocess-use-vfork-escape-hatch-broken-fix-or-remove/56915/2
2024-07-30 18:39:54 -07:00
Serhiy Storchaka 68840e91ac
gh-122311: Fix a refleak in pickle (GH-122411) 2024-07-29 21:52:48 +03:00
Serhiy Storchaka 3b034d26eb
gh-122311: Fix some error messages in pickle (GH-122386) 2024-07-29 11:49:13 +03:00
Peter Bierma c08696286f
gh-122332: Fix missing `NULL` check in `asyncio.Task.get_coro` (#122338) 2024-07-27 11:57:48 +05:30
Marc Mueller aef95eb107
gh-121489: Export private _PyBytes_Join() again (#122267) 2024-07-25 17:31:30 +02:00
Serhiy Storchaka dc07f65a53
gh-82951: Fix serializing by name in pickle protocols < 4 (GH-122149)
Serializing objects with complex __qualname__ (such as unbound methods and
nested classes) by name no longer involves serializing parent objects by value
in pickle protocols < 4.
2024-07-25 08:45:19 +00:00
Mikołaj Kuranowski a3327dbfd4
gh-113785: csv: fields starting with escapechar are not quoted (GH-122110) 2024-07-25 10:04:47 +03:00
Mark Shannon e55b05f29e
GH-121832: Assert that the version number of static builtin types is not changed by PyType_Modified. (GH-122182)
Update datetime module and test_type_cache.py to not call PyType_Modified.
2024-07-24 10:22:51 +01:00
Sam Gross a15feded71
gh-120974: Make _asyncio._leave_task atomic in the free-threaded build (#122139)
* gh-120974: Make _asyncio._leave_task atomic in the free-threaded build

Update `_PyDict_DelItemIf` to allow for an argument to be passed to the
predicate.
2024-07-23 17:06:03 +00:00
Serhiy Storchaka e6b25e9a09
gh-122163: Add notes for JSON serialization errors (GH-122165)
This allows to identify the source of the error.
2024-07-23 20:02:54 +03:00
Sam Gross c908d1f87d
gh-120974: Use common freelist code in asyncio (#122132)
This refactors asyncio to use the common freelist helper functions and
macros. As a side effect, the freelist for _asyncio.Future is now
re-enabled in the free-threaded build.
2024-07-23 21:54:24 +05:30
Sam Gross 47847aa8ef
gh-120974: Make _asyncio._enter_task atomic in the free-threaded build (#122138)
Use `PyDict_SetDefaultRef` to set the current task in a single operation
under the dictionary's lock.
2024-07-23 14:17:14 +05:30
Łukasz Langa dc93d1125f
gh-121957: Emit audit events for `python -i` and `python -m asyncio` (GH-121958)
Relatedly, emit the `cpython.run_startup` event from the Python version of
`PYTHONSTARTUP` handling.
2024-07-22 13:04:08 +02:00
Sam Gross 97248204a1
gh-121621: Disable asyncio freelist in free-threaded build (#122046)
The futureobj freelist isn't thread-safe. We intend to re-enable the
freelist in a thread-safe way for 3.14 (but not 3.13).
2024-07-19 15:26:29 -04:00
mpage e059aa6b01
gh-120973: Fix thread-safety issues with `threading.local` (#121655)
This is a small refactoring to the current design that allows us to
avoid manually iterating over threads.

This should also fix gh-118490.
2024-07-19 13:22:02 -04:00
Rodrigo Oliveira d66b06107b
gh-118830: Bump pickle.DEFAULT_PROTOCOL to 5 (GH-119340) 2024-07-19 16:47:10 +02:00
Serhiy Storchaka 1a0c7b9ba4
gh-121905: Consistently use "floating-point" instead of "floating point" (GH-121907) 2024-07-19 08:06:02 +00:00
Tian Gao eaf094c09b
gh-120289: Add external timer in traverse of _lsprof.Profiler (#121998) 2024-07-18 20:46:24 -07:00
Tian Gao 1ab1778283
gh-120289: Disallow disable() and clear() in external timer to prevent use-after-free (#120297) 2024-07-18 12:47:22 -07:00
Sam Gross 81fd625b5c
gh-121621: Move asyncio_running_loop to private struct (#121939)
This avoids changing the ABI and keeps the field in the private struct.
2024-07-17 15:21:24 -07:00
sobolevn f4bc84d261
gh-121925: Fix uninitialized variables in `main.c` (#121926) 2024-07-17 16:13:37 +00:00
Alex Waygood ac07451116
gh-120678: pyrepl: Include globals from modules passed with `-i` (GH-120904)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-07-17 16:18:42 +02:00
Ken Jin 69c68de43a
gh-121621: Move asyncio running loop to thread state (GH-121695) 2024-07-17 01:09:58 +08:00
Petr Viktorin b4aedb23ae
gh-113993: Don't immortalize in PyUnicode_InternInPlace; keep immortalizing in other API (#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
2024-07-16 15:36:21 +02:00
sobolevn 8b6d475581
gh-121791: Check for `NULL` in `MethodDescriptor2_new` in `_testcapi` (#121792) 2024-07-16 11:29:33 +03:00
Eric Snow 8b209fd4f8
gh-76785: Expand How Interpreter Channels Handle Interpreter Finalization (gh-121805)
See 6b98b274b6 for an explanation of the problem and solution.  Here I've applied the solution to channels.
2024-07-15 19:43:59 +00:00
Eric Snow 6b98b274b6
gh-76785: Expand How Interpreter Queues Handle Interpreter Finalization (gh-116431)
Any cross-interpreter mechanism for passing objects between interpreters must be very careful to respect isolation, even when the object is effectively immutable (e.g. int, str).  Here this especially relates to when an interpreter sends one of its objects, and then is destroyed while the inter-interpreter machinery (e.g. queue) still holds a reference to the object.

When I added interpreters.Queue, I dealt with that case (using an atexit hook) by silently removing all items from the queue that were added by the finalizing interpreter.

Later, while working on concurrent.futures.InterpreterPoolExecutor (gh-116430), I noticed it was somewhat surprising when items were silently removed from the queue when the originating interpreter was destroyed.  (See my comment on that PR.) 
 It took me a little while to realize what was going on.  I expect that users, which much less context than I have, would experience the same pain.

My approach, here, to improving the situation is to give users three options:

1. return a singleton (interpreters.queues.UNBOUND) from Queue.get() in place of each removed item
2. raise an exception (interpreters.queues.ItemInterpreterDestroyed) from Queue.get() in place of each removed item
3. existing behavior: silently remove each item (i.e. Queue.get() skips each one)

The default will now be (1), but users can still explicitly opt in any of them, including to the silent removal behavior.

The behavior for each item may be set with the corresponding Queue.put() call. and a queue-wide default may be set when the queue is created.  (This is the same as I did for "synconly".)
2024-07-15 12:49:23 -06:00
Kumar Aditya 48042c52a6
fix outdated comments in asyncio (#121783) 2024-07-15 05:59:19 +00:00
Ken Jin 5d6861ad06
gh-121621: Use PyMutex for writes to asyncio state (#121622)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2024-07-14 12:22:56 +00:00
Savannah Ostrowski 65fededf9c
Update retroactive comments from GH-117741 (segfault in `FutureIter_dealloc`) (GH-121638)
Address comments
2024-07-12 10:34:30 +02:00
Sam Gross e8c91d90ba
gh-121103: Put free-threaded libraries in `lib/python3.14t` (#121293)
On POSIX systems, excluding macOS framework installs, the lib directory
for the free-threaded build now includes a "t" suffix to avoid conflicts
with a co-located default build installation.
2024-07-11 16:21:37 -04:00
Sam Gross 44937d11a6
gh-121592: Make select.poll() and related objects thread-safe (#121594)
This makes select.poll() and kqueue() objects thread-safe in the
free-threaded build. Note that calling close() concurrently with other
functions is still not thread-safe due to races on file descriptors
(gh-121544).
2024-07-11 10:21:09 -04:00
Irit Katriel 6557af6698
gh-121554: remove unnecessary internal functions in compile.c (#121555)
Co-authored-by: Erlend E. Aasland <erlend@python.org>
2024-07-10 23:48:37 +01:00
Eric Snow 35a67e36aa
gh-121596: Fix Sharing Interpreter Channels (gh-121597)
This fixes a mistake in gh-113012 and adds a test that verifies the fix.
2024-07-10 21:31:09 +00:00
Sam Gross 1d3cf79a50
gh-121368: Fix seq lock memory ordering in _PyType_Lookup (#121388)
The `_PySeqLock_EndRead` function needs an acquire fence to ensure that
the load of the sequence happens after any loads within the read side
critical section. The missing fence can trigger bugs on macOS arm64.

Additionally, we need a release fence in `_PySeqLock_LockWrite` to
ensure that the sequence update is visible before any modifications to
the cache entry.
2024-07-08 14:52:07 -04:00
Max Muoto 5289550b33
gh-121374: Correct docstrings in `_interpchannels` (gh-121418) 2024-07-08 10:32:17 -06:00
Serhiy Storchaka 8ecb8962e3
gh-121288: Make error message for index() methods consistent (GH-121395)
Make error message for index() methods consistent

Remove the repr of the searched value (which can be arbitrary large)
from ValueError messages for list.index(), range.index(), deque.index(),
deque.remove() and ShareableList.index().  Make the error messages
consistent with error messages for other index() and remove()
methods.
2024-07-05 10:50:45 -07:00
Cody Maloney 06a1c3fb24
gh-120754: Update estimated_size in C truncate (#121357)
Sometimes a large file is truncated (test_largefile). While
estimated_size is used as a estimate (the read will stil get the number
of bytes in the file), that it is much larger than the actual size of
data can result in a significant over allocation and sometimes lead to
a MemoryError / running out of memory.

This brings the C implementation to match the Python _pyio
implementation.
2024-07-04 12:59:18 +00:00
Cody Maloney 2f5f19e783
gh-120754: Reduce system calls in full-file FileIO.readall() case (#120755)
This reduces the system call count of a simple program[0] that reads all
the `.rst` files in Doc by over 10% (5706 -> 4734 system calls on my
linux system, 5813 -> 4875 on my macOS)

This reduces the number of `fstat()` calls always and seek calls most
the time. Stat was always called twice, once at open (to error early on
directories), and a second time to get the size of the file to be able
to read the whole file in one read. Now the size is cached with the
first call.

The code keeps an optimization that if the user had previously read a
lot of data, the current position is subtracted from the number of bytes
to read. That is somewhat expensive so only do it on larger files,
otherwise just try and read the extra bytes and resize the PyBytes as
needeed.

I built a little test program to validate the behavior + assumptions
around relative costs and then ran it under `strace` to get a log of the
system calls. Full samples below[1].

After the changes, this is everything in one `filename.read_text()`:

```python3
openat(AT_FDCWD, "cpython/Doc/howto/clinic.rst", O_RDONLY|O_CLOEXEC) = 3`
fstat(3, {st_mode=S_IFREG|0644, st_size=343, ...}) = 0`
ioctl(3, TCGETS, 0x7ffdfac04b40)        = -1 ENOTTY (Inappropriate ioctl for device)
lseek(3, 0, SEEK_CUR)                   = 0
read(3, ":orphan:\n\n.. This page is retain"..., 344) = 343
read(3, "", 1)                          = 0
close(3)                                = 0
```

This does make some tradeoffs
1. If the file size changes between open() and readall(), this will
still get all the data but might have more read calls.
2. I experimented with avoiding the stat + cached result for small files
in general, but on my dev workstation at least that tended to reduce
performance compared to using the fstat().

[0]

```python3
from pathlib import Path

nlines = []
for filename in Path("cpython/Doc").glob("**/*.rst"):
    nlines.append(len(filename.read_text()))
```

[1]
Before small file:

```
openat(AT_FDCWD, "cpython/Doc/howto/clinic.rst", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=343, ...}) = 0
ioctl(3, TCGETS, 0x7ffe52525930)        = -1 ENOTTY (Inappropriate ioctl for device)
lseek(3, 0, SEEK_CUR)                   = 0
lseek(3, 0, SEEK_CUR)                   = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=343, ...}) = 0
read(3, ":orphan:\n\n.. This page is retain"..., 344) = 343
read(3, "", 1)                          = 0
close(3)                                = 0
```

After small file:

```
openat(AT_FDCWD, "cpython/Doc/howto/clinic.rst", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=343, ...}) = 0
ioctl(3, TCGETS, 0x7ffdfac04b40)        = -1 ENOTTY (Inappropriate ioctl for device)
lseek(3, 0, SEEK_CUR)                   = 0
read(3, ":orphan:\n\n.. This page is retain"..., 344) = 343
read(3, "", 1)                          = 0
close(3)                                = 0
```

Before large file:

```
openat(AT_FDCWD, "cpython/Doc/c-api/typeobj.rst", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=133104, ...}) = 0
ioctl(3, TCGETS, 0x7ffe52525930)        = -1 ENOTTY (Inappropriate ioctl for device)
lseek(3, 0, SEEK_CUR)                   = 0
lseek(3, 0, SEEK_CUR)                   = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=133104, ...}) = 0
read(3, ".. highlight:: c\n\n.. _type-struc"..., 133105) = 133104
read(3, "", 1)                          = 0
close(3)                                = 0
```

After large file:

```
openat(AT_FDCWD, "cpython/Doc/c-api/typeobj.rst", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=133104, ...}) = 0
ioctl(3, TCGETS, 0x7ffdfac04b40)        = -1 ENOTTY (Inappropriate ioctl for device)
lseek(3, 0, SEEK_CUR)                   = 0
lseek(3, 0, SEEK_CUR)                   = 0
read(3, ".. highlight:: c\n\n.. _type-struc"..., 133105) = 133104
read(3, "", 1)                          = 0
close(3)                                = 0
```

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2024-07-04 09:17:00 +02:00
Sergey B Kirpichev 51c4a324c0
gh-61103: Support float and long double complex types in ctypes module (#121248)
This amends 6988ff02a5: memory allocation for
stginfo->ffi_type_pointer.elements in PyCSimpleType_init() should be
more generic (perhaps someday fmt->pffi_type->elements will be not a
two-elements array).

It should finally resolve #61103.

Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-07-03 11:08:11 +02:00
AN Long 705a123898
gh-116181: Remove Py_BUILD_CORE_BUILTIN and Py_BUILD_CORE_MODULE in rotatingtree.c (#121260) 2024-07-03 13:05:05 +05:30