Commit graph

8928 commits

Author SHA1 Message Date
Stan Ulbrych
a3ce2f77f0
gh-55531: Implement normalize_encoding in C (#136643)
Closes gh-55531
2025-10-30 15:31:47 +01:00
Victor Stinner
efc37ba49e
gh-139353: Add Objects/unicode_writer.c file (#139911)
Move the public PyUnicodeWriter API and the private _PyUnicodeWriter
API to a new Objects/unicode_writer.c file.

Rename a few helper functions to share them between unicodeobject.c
and unicode_writer.c, such as resize_compact() or unicode_result().
2025-10-30 14:36:15 +01:00
Stan Ulbrych
dbe3950a76
gh-129117: Add unicodedata.isxidstart() function (#140269)
Expose `_PyUnicode_IsXidContinue/Start` in `unicodedata`:
add isxidstart() and isxidcontinue() functions.

Co-authored-by: Victor Stinner <vstinner@python.org>
2025-10-30 10:18:12 +00:00
Mikhail Efimov
02202c117b
gh-140551: Fix dict crash if clear is called at lookup stage (#140558)
Co-authored-by: Inada Naoki <songofacandy@gmail.com>
2025-10-29 14:36:23 +05:30
Shamil
7d70a147f5
Remove dead stores to 'size' in UTF-8 decoder (unicodeobject.c) (#140637) 2025-10-27 11:55:57 +03:00
Kumar Aditya
df07364106
gh-140544: use faster _PyInterpreterState_GET for type lock (#140584) 2025-10-25 14:53:26 +00:00
Sam Gross
574405c19e
gh-140431: Fix GC crash due to partially initialized coroutines (gh-140470)
The `make_gen()` function creates and tracks generator/coro objects, but
doesn't fully initialize all the fields. At a minimum, we need to
initialize all the fields that may be accessed by gen_traverse because
the call to `compute_cr_origin()` can trigger a GC.
2025-10-23 10:18:13 -04:00
Emma Smith
a8edca62fc
gh-132835: Add defensive NULL checks to MRO resolution (GH-134763)
Currently, there are a few places where tp_mro could theoretically
become NULL, but do not in practice. This commit adds defensive checks for
NULL values to ensure that any changes do not introduce a crash and that
state invariants are upheld.

The assertions added in this commit are all instances where a NULL value would get passed to something not expecting a NULL, so it is better to catch an assertion failure than crash later on.

There are a few cases where it is OK for the return of lookup_tp_mro to be NULL, such as when passed to is_subtype_with_mro, which handles this explicitly.
2025-10-21 14:48:29 -07:00
Mark Shannon
0c01090ad9
GH-139951: Fix major GC performance regression (GH-140262)
* Count number of actually tracked objects, instead of trackable objects. This ensures that untracking tuples has the desired effect of reducing GC overhead

* Do not track most untrackable tuples during creation. This prevents large numbers of small tuples causing execessive GCs.
2025-10-21 15:22:15 +01:00
Peter Bierma
71db05a12d
gh-140406: Fix memory leak upon __hash__ returning a non-integer (GH-140411) 2025-10-21 08:10:01 -04:00
Petr Viktorin
ea4cc585cd
gh-139817: Fix refleak in TypeAliasType(qualname=non_string) (GH-140197) 2025-10-16 11:04:04 +00:00
Mikhail Efimov
f673f0e7b4
gh-139817: Attribute __qualname__ is added to TypeAliasType (#139919) 2025-10-15 09:08:17 -07:00
Sergey Miryanov
32c264982e
gh-140061: Use _PyObject_IsUniquelyReferenced() to check if objects are uniquely referenced (gh-140062)
The previous `Py_REFCNT(x) == 1` checks can have data races in the free
threaded build. `_PyObject_IsUniquelyReferenced(x)` is a more conservative
check that is safe in the free threaded build and is identical to
`Py_REFCNT(x) == 1` in the default GIL-enabled build.
2025-10-15 09:48:21 -04:00
Cody Maloney
6416e6ebe5
gh-129559: Remove extra dot in bytearray.resize AC (#140134) 2025-10-15 02:39:17 +00:00
Neil Schemenauer
1e1f435196
gh-140126: Fix compile error if --with-assertions is enabled (#140133)
The `types_world_is_stopped()` function needs to be defined if NDEBUG
is not defined.
2025-10-14 23:34:30 +00:00
Sergey Miryanov
ded59f7e8e
GH-140058: Clear key and value if PyTuple_New fails in dictiter_iternextitem (#140059) 2025-10-14 18:15:39 +05:30
Mikhail Efimov
be60e4b4f3
gh-140000: Traverse name attribute for TypeVar, TypeVarTuple, TypeAliasType, ParamSpec (#140016) 2025-10-13 13:10:39 -07:00
Kumar Aditya
6481539a6d
gh-125996: fix thread safety of collections.OrderedDict (#133734) 2025-10-13 22:55:07 +05:30
Pieter Eendebak
e6aa515296
gh-140009: Improve performance of list_extend_dictitems by using PyTuple_FromArray (#140010) 2025-10-13 15:58:25 +05:30
Bénédikt Tran
6710156bd2
gh-139988: fix a leak when failing to create a Union type (#139990) 2025-10-12 12:51:44 +02:00
Victor Stinner
166cdaa6fb
gh-111489: Remove _PyTuple_FromArray() alias (#139973)
Replace _PyTuple_FromArray() with PyTuple_FromArray().
Remove pycore_tuple.h includes.
2025-10-11 22:58:14 +02:00
Dino Viehland
ff7bb565d8
gh-139924: Add PyFunction_PYFUNC_EVENT_MODIFY_QUALNAME event for function watchers (#139925)
Add PyFunction_PYFUNC_EVENT_MODIFY_QUALNAME event for function watchers
2025-10-10 15:25:38 -07:00
Victor Stinner
4c119714d5
gh-139353: Add Objects/unicode_format.c file (#139491)
* Move PyUnicode_Format() implementation from unicodeobject.c
  to unicode_format.c.
* Replace unicode_modifiable() with _PyUnicode_IsModifiable()
* Add empty lines to have two empty lines between functions.
2025-10-10 12:52:59 +02:00
Victor Stinner
e31c22dbf9
gh-111489: Add PyTuple_FromArray() function (#139691) 2025-10-10 08:54:12 +02:00
Victor Stinner
3d3f126e86
gh-139353: Rename formatter_unicode.c to unicode_formatter.c (#139723)
* Move Python/formatter_unicode.c to Objects/unicode_formatter.c.
* Move Objects/stringlib/localeutil.h content into
  unicode_formatter.c. Remove localeutil.h.
* Move _PyUnicode_InsertThousandsGrouping() to unicode_formatter.c
  and mark the function as static.
* Rename unicode_fill() to _PyUnicode_Fill() and export it in
  pycore_unicodeobject.h.
* Move MAX_UNICODE to pycore_unicodeobject.h as _Py_MAX_UNICODE.
2025-10-08 14:56:00 +02:00
Sergey Miryanov
e6e376a760
gh-132042: Remove resolve_slotdups() to speedup class creation (#132156)
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-10-03 11:58:00 +02:00
Victor Stinner
e9c538dd54
gh-139156: Optimize _PyUnicode_EncodeCharmap() (#139306)
Specialize _PyUnicode_EncodeCharmap() for EncodingMapType which is
used by Python codecs such as iso8859_15.
2025-09-25 11:42:16 +02:00
Victor Stinner
8d83b7df3f
gh-139156: Optimize the UTF-7 encoder (#139253)
Remove base64SetO and base64WhiteSpace parameters.
2025-09-24 17:57:29 +02:00
Victor Stinner
c7b11b7546
gh-139156: Use PyBytesWriter in PyUnicode_EncodeCodePage() (#139259)
Replace PyBytes_FromStringAndSize() and _PyBytes_Resize() with the
PyBytesWriter API.
2025-09-24 16:39:40 +02:00
Victor Stinner
c9a79a02a8
gh-139156: Use PyBytesWriter in _PyUnicode_EncodeCharmap() (#139251)
Replace PyBytes_FromStringAndSize() and _PyBytes_Resize() with the
PyBytesWriter API.

Add _PyBytesWriter_GetSize() and _PyBytesWriter_GetData() static
inline functions.
2025-09-24 16:15:34 +02:00
Bénédikt Tran
a5e0562350
gh-133644: remove PyWeakref_GetObject and PyWeakref_GET_OBJECT (GH-133657) 2025-09-24 11:25:56 +02:00
Victor Stinner
dd45179fa0
gh-129813, PEP 782: Remove the private _PyBytesWriter API (#139264)
It is now replaced with the new public PyBytesWriter API (PEP 782).
2025-09-23 15:29:55 +00:00
Victor Stinner
8cfd7b4ecf
gh-129813, PEP 782: Use PyBytesWriter in utf8_encoder() (#138874)
Replace the private _PyBytesWriter API with the new public
PyBytesWriter API in utf8_encoder() and unicode_encode_ucs1().
2025-09-23 11:47:09 +02:00
Victor Stinner
49e83e31bd
gh-139156: Use PyBytesWriter in PyUnicode_AsRawUnicodeEscapeString() (#139250)
Replace PyBytes_FromStringAndSize() and _PyBytes_Resize() with the
PyBytesWriter API.
2025-09-22 23:46:19 +02:00
Victor Stinner
c497694f77
gh-139156: Use PyBytesWriter in UTF-16 encoder (#139233)
Replace PyBytes_FromStringAndSize() and _PyBytes_Resize() with the
PyBytesWriter API.
2025-09-22 23:36:05 +02:00
Victor Stinner
e578a9e6a5
gh-139156: Use PyBytesWriter in PyUnicode_AsUnicodeEscapeString() (#139249)
Replace PyBytes_FromStringAndSize() and _PyBytes_Resize() with the
PyBytesWriter API.
2025-09-22 23:22:27 +02:00
Victor Stinner
c863349f98
gh-139156: Use PyBytesWriter in the UTF-7 encoder (#139248)
Replace PyBytes_FromStringAndSize() and _PyBytes_Resize() with the
PyBytesWriter API.
2025-09-22 22:49:25 +02:00
Victor Stinner
92ba2c92c4
gh-139156: Use PyBytesWriter in UTF-32 encoder (#139157)
Replace PyBytes_FromStringAndSize() and _PyBytes_Resize() with the
PyBytesWriter API.
2025-09-22 20:05:35 +00:00
da-woods
ac5c5d42a2
gh-119494: Fix error messages for deleting/setting type attributes (#119495) 2025-09-18 22:08:49 +01:00
Victor Stinner
9f7bbafffe
gh-129813, PEP 782: Optimize byteswriter_resize() (#139101)
There is no need to copy the small_buffer in PyBytesWriter_Create().
2025-09-18 09:52:16 +00:00
Sergey Miryanov
b42af37ced
GH-138355: Remove trash_delete_later from _gc_runtime_state (#138767)
Remove trash_delete_later and trash_delete_nesting from _gc_runtime_state.
2025-09-17 21:25:24 +01:00
Victor Stinner
c72ffe71f1
gh-129813, PEP 782: Set invalid bytes in PyBytesWriter (#139054)
Initialize the buffer with 0xFF byte pattern when creating a writer
object, but also when resizing/growing the writer.
2025-09-17 17:58:32 +02:00
Victor Stinner
263242613f
gh-129813, PEP 782: Use PyBytesWriter in _Py_bytes_maketrans() (#139044)
Replace PyBytes_FromStringAndSize(NULL, size) with the new public
PyBytesWriter API.
2025-09-17 17:43:30 +02:00
Dino Viehland
299de38e61
gh-131776: Expose functions called from the interpreter loop via PyAPI_FUNC (#134242) 2025-09-17 08:04:02 -07:00
Serhiy Storchaka
a1cf6e92b6
gh-71679: Share the repr implementation between bytes and bytearray (GH-138181)
This allows to use the smart quotes algorithm in the bytearray's repr.
2025-09-17 11:10:29 +03:00
Victor Stinner
4e00e2504f
gh-129813, PEP 782: Add PyBytesWriter.overallocate (#138941)
Disable overallocation in _PyBytes_FormatEx() at the last write.
2025-09-16 00:15:32 +02:00
Serhiy Storchaka
29d026f93e
gh-37817: Allow assignment to __bases__ of direct subclasses of builtin classes (GH-137585) 2025-09-15 16:40:28 +00:00
Kumar Aditya
5c4bb9b7f6
gh-137992: fix PyRefTracer_SetTracer to start world before returning (#138925)
fix deadlock in PyRefTracer_SetTracer
2025-09-15 15:39:15 +01:00
Victor Stinner
7c6efc3a4f
gh-129813, PEP 782: Init small_buffer in PyBytesWriter_Create() (#138924)
Fill small_buffer with 0xFF byte pattern to detect the usage of
uninitialized bytes in debug build.
2025-09-15 16:23:11 +02:00
Petr Viktorin
32b2c5de16
gh-137956: Guard against non-free-threaded extensions in free-threaded builds (GH-137957) 2025-09-15 11:24:16 +00:00