Commit Graph
62 Commits
Author SHA1 Message Date
Luan Taraschi 0c9fa4219d Stop skipping six tests whose reason no longer reproduces (#8583)
Three skips in test_array say "Hangs", one in test_marshal carries no
reason at all, and two in test_thread say "panic" on Linux. None of the
six does any of that now. Each ran three to five times in a row and
passed, and the array trio was also checked case by case against CPython
3.14, including the mutation-during-index-conversion shapes the tests
were written for.

The neighbouring markers that say "Flaky", "Flakey on CI" and "flaky
EOFError" are left alone. One green run says nothing about those.

Assisted-by: Claude Code:claude-opus-5
2026-08-23 08:33:33 +09:00
Shahar Naveh e71a955c99 Update some libs and tests to 3.14.7 (#8559)
* Update some libs

* Update some tests

* more tests

* test_pydoc.py

* test_mimetypes.py

* Restore json decoder

* reapply updaye
2026-08-23 00:13:15 +09:00
Jeong, YunWon 4fab5c966e Raise where the fuzzer found aborts and stack overflows, and collect with the count in the object header (#8551)
* Correct what the non-unix frame stack is for

The comment said non-unix threading builds have no stop-the-world.
CollectStopTheWorld is gated on `feature = "threading"` alone, and
sys._current_frames stops the world on both paths; the field is the
fallback a reader uses when there is no `top_iframe` to materialize from.

Assisted-by: Claude

* Seek by the whole file position on Windows

`SetFilePointer` answers with the low half of the new position and signals
failure with INVALID_SET_FILE_POINTER, which is also that half of a
position four gigabytes in; telling them apart takes the error code, which
this did not read, so such a seek was reported as an error. Deciding
seekability from it also called such a file unseekable.

`SetFilePointerEx` returns the whole position and a success flag of its
own, which also removes the transmute of the position into halves.

Assisted-by: Claude

* memoryview: tell a value of the wrong kind from one that does not fit

Assigning an item reported every packing failure as a TypeError, so
m[0] = 300 on a 'B' view said the value was the wrong type rather than out
of range. Packing now says which of the two it was, and whether the value's
own code raised, in which case that error is the answer as it is:

    m[0] = 300                       ValueError: invalid value for format 'B'
    m[0] = "x"                       TypeError: invalid type for format 'B'
    m[0] = <__index__ that raises>   the raised error

`struct` reports both as `struct.error` and is unchanged; the kind travels
beside the exception for the caller that tells them apart.

Also: None was read as a deletion, so m[0] = None answered "cannot delete
memory" instead of packing it; and deleting through the mapping protocol
never reached the read-only check, which comes first.

Assisted-by: Claude

* Raise MemoryError for allocations sized by Python input

os.read, _RawIOBase.read, int.to_bytes, struct.pack, ctypes array
creation and the _ssl RAND functions sized a Vec from a Python-supplied
length with vec![], which calls handle_alloc_error and, under
panic = "abort", ends the process. They now allocate through
vm.new_zeroed_bytes and raise MemoryError.

itertools.product built its pools without checking that
len(iterables) * repeat is representable; it now raises OverflowError
"repeat argument too large" and reserves the pool and index vectors
fallibly. repeat is read as isize, so a negative one raises ValueError
"repeat argument cannot be negative" instead of the conversion's message.

_ssl.RAND_bytes and RAND_pseudo_bytes read n as i32, matching the int
they are declared with.

Assisted-by: Claude

* Collect with the count in the object header

A collection kept the count it was working with in a table keyed by the
object's address, and the objects it had proved reachable in a second one.
Between them they were hashed once per candidate and twice per edge in the
heap, which is where most of a collection over a live heap went.

The count now lives in `PyInner::gc_refs`, with `GcBits::COLLECTING` saying
it is meaningful, and reachability is `gc_refs == GC_REACHABLE` rather than
membership in a set. Step 5 splits the candidates and clears the bit in one
pass. gcbench, five interleaved pairs, median: a live heap of 423k objects
goes from 0.101s to 0.055s and a dead one from 0.402s to 0.383s.

The bits, generation, owner and count take eight bytes between them. A
64-bit header had those eight as the padding its alignment forces, so it is
unchanged at 48 bytes; a 32-bit header grows from 24 to 28.

Assisted-by: Claude

* Take an explicit thread stack size as a floor in debug builds

A debug build already started Python threads on 8 MiB rather than Rust's
2 MiB default, but an explicit threading.stack_size(N) went through
verbatim. test_threading asks for 256 KiB, and starting a thread on that
walked off the end of the stack: the guard page fault landed in the
prologue of ExecutingFrame::run.

Unoptimized, that prologue reserves 80,848 bytes where the optimized one
reserves 656 -- execute_instruction is #[inline(always)] and LLVM only
colors stack slots from opt-level 1, so the frame is the sum of all 200
instruction arms' temporaries rather than the largest. A Python call costs
88,672 bytes of native stack there, and threading's bootstrap is six
frames deep, so 256 KiB holds less than half of what starting a thread
takes.

The floor reaches thread::Builder only; threading.stack_size() still
answers with what was asked for, and release builds are unchanged.

Assisted-by: Claude

* Check the native stack on every frame entry

The C-stack guard ran on one frame entry in eight. That asks the margin to
cover eight frames rather than one, and it does not: an unoptimized frame
entered through native code takes 88,672 bytes against a debug margin of
262,144. A recursion whose steps re-enter that way -- `__add__` calling
itself, a sort key that sorts -- ran off the end of the stack instead of
raising RecursionError. On a debug build `class Add: __add__ = lambda s, o:
s + o; Add() + 1` segfaulted on the main thread; it now raises, as it does
under CPython and in release builds.

enter_iframe checked and then called enter_iframe_unchecked, which checked
again; it now leaves the check to the one call.

Measured on a call-dominated benchmark, five interleaved pairs: instructions
retired go up 0.17%, about four per call, which is the stack pointer read
and the compare.

Assisted-by: Claude

* Take an iterable's length hint when a list is filled from it

`map_py_iter` read `__length_hint__` only to pass it to `PyIterIter`, and
returned an empty vector when the hint was `isize::MAX` or more. Collecting
through `PyResult` dropped the iterator's lower bound, so nothing reserved
the room the hint asked for.

`list()`, `list.extend()` and `list.__iadd__()` now reserve it and report a
hint they cannot honour as `MemoryError`; a hint that leaves no room for the
elements the list already holds is passed over, as `list_extend()` does.
`tuple()` and the other callers keep filling up without reserving.

`length_hint_opt` errors other than the `TypeError` it already turns into
`None` now reach the caller instead of being dropped.

`__iadd__` and `inplace_concat` went through `extract_cloned`, which reads
`__len__` and not `__length_hint__`; both call `PyList::extend` now, the way
`list_inplace_concat()` calls `list_extend()`.

The tuple, list and dict fast paths of `extract_elements_inner` reserve their
known length, which the `collect()` they used dropped.

Assisted-by: Claude

* Drop map.__length_hint__

`map_methods` has no `__length_hint__`, so `operator.length_hint()` on a map
answers 0, not the length of what it draws from.

The method walked into the length hint of every iterator it holds, and a
chain of maps 10000 long overflowed the native stack answering for the
outermost one. It also took the longest of its iterators, where a map stops
at the shortest.

Assisted-by: Claude

* Ask for a length hint where each caller asks for it

`map_py_iter` asked the iterable it was handed, for every caller, and reported
what asking raised. Only some callers ask it: `list_extend()` and
`_PyBytes_FromIterator()` ask the iterable, `PySequence_Tuple()` asks the
iterator, and the bytearray constructor asks nothing. `tuple()`, `min()`,
`max()`, `collections.deque()` and `f(*x)` raised for an iterable whose
`__len__` or `__length_hint__` does, where they answer.

Which object is asked is now the caller's to say. `sorted()` asks the iterable,
being `PySequence_List()`.

`bytes_from_object()` stood in for `PyBytes_FromObject()`, for
`bytearray_extend()` and for the bytearray constructor, which do not agree on
this: the first two ask, the last does not. It is split, and assigning to a
bytearray slice takes the constructor's side with `PyByteArray_FromObject()`.

`list.extend()` counted what it held before the iterable had been asked, where
`list_extend()` reads `Py_SIZE(self)` after. A `__length_hint__` that adds to
the list made the overflow guard read a count too small and raise `MemoryError`
where nothing is wrong; one that empties it made the guard skip a reservation
that cannot be served.

Assisted-by: Claude

* Settle product's pool count before it reads its arguments

`product_new()` checks `repeat` and works out `npools` before it calls
`PySequence_Tuple()` on any argument, and fills the pools `npools` times.

The pools were filled by repeating the arguments `repeat` times instead, which
walks that many steps even with no arguments to repeat: `product(repeat=2**62)`
counted up to it rather than answering `[()]`. The count was also worked out
after the arguments had been read, so a repeat too large to serve ran their
code first.

Assisted-by: Claude

* Let the bool format answer with the error its value raised

`pack_single()` leaves `'?'` to `PyObject_IsTrue()` and returns what that
raised. Packing classified the error instead, so a `ValueError` from a
`__bool__` came back as "memoryview: invalid value for format '?'".

Assisted-by: Claude

* Release a cell's old value after the lock

`PyCell::set` dropped what it replaced while still holding the mutex guarding
the cell contents. A `__del__` running from that drop and reading the same cell
waited on a lock its own caller held, so `del it` on a closure variable whose
value has such a `__del__` deadlocked.

The replaced value is now released once the guard is gone, as `Py_XSETREF`
stores before it decrefs.

Assisted-by: Claude

* Have a set iterator hold the set it iterates

The iterator kept only a reference to the inner hash table, so in
`it = iter(A(*args))` the `A()` temporary was the last owner and died as the
call returned, before `it` was bound. A `__del__` reading `it` there saw an
unbound name and its error was printed and ignored.

The iterator now holds the set object, as `si_set` does, and releases it once
exhausted. That release happens after the lock is dropped, where
`setiter_iternext()` puts its `Py_DECREF(so)` past `Py_END_CRITICAL_SECTION()`,
so a `__del__` that iterates again does not wait on a lock the call holds.

Assisted-by: Claude

* Release an exhausted iterator's container after the lock

`PositionIterInternal::_next` overwrote its `IterStatus::Active` while the
caller still held the mutex around it. Dropping the container there ran any
`__del__` under that lock, and a `__del__` that iterated the same object again
blocked on it.

`exhaust()` now hands the container back instead of dropping it, and
`locked_step()` releases it after the guard. list, list_reverseiterator, tuple,
str, dict and its views and reverse views, bytes, bytearray, memoryview,
array, deque, and the enumerate and sequence iterators all go through it.

Assisted-by: Claude

* Unskip test_free_after_iterating

Assisted-by: Claude

* Stop listing test_set as an environment polluter

`check_free_after_iterating` no longer leaves an ignored exception behind, and
the job that reruns the listed tests ten times fails once one of them stops
polluting.

Assisted-by: Claude

* Drop winsound imports left unused

`TryFromBorrowedObject`, `exceptions`, and `ToWideString` have no reference in
the module, which fails the Windows clippy line under `-Dwarnings`.

Assisted-by: Claude

* Ask nothing where the caller takes no room

`map_py_iter` asked the iterator for a length hint on behalf of every caller
that does not reserve, and reported what asking raised. Those callers ask
nothing at all: `tuple()`, `f(*x)`, `bytearray(x)`, `min()`, `max()` and
`collections.deque()` answer for an iterator whose `__length_hint__` raises,
where they had been raising it.

The answer was also never spent. It reached `PyIterIter` for a `size_hint()`
the push loop does not read, so the lookup and any call it made were work
thrown away: `tuple()` over a generator drops 22% of its instructions, and 17%
over an iterator with a `__length_hint__` written in Python.

Assisted-by: Claude

* Stop asking an iterator how long it is to walk it

`PyIter::iter` and `PyIter::into_iter` asked for a length hint and reported
what asking raised. Nothing spent the answer: it reached `PyIterIter` for a
`size_hint()` that every caller either loops past or drops, since collecting
into a `Result` reports no lower bound.

23 operations answered for an iterator whose `__length_hint__` raises, where
they had been raising it: `set`, `frozenset` and the nine `set` methods that
take an iterable, `dict.fromkeys` and the dict view operators, `array` and
`array.extend`, `all`, `any`, `sum`, `io.writelines`, `math.fsum`,
`math.prod`, and `csv.writerow` and `writerows`.

Over a generator, `set()` drops 16% of its instructions and `all()` 23%.

`str.join` and `bytes.join` do ask, reaching their elements through
`PySequence_Fast()`, which fills a list from the iterator. They take
`iter_sized()`, which is now the only way to ask. `iter_without_hint` is gone,
its callers being what `iter` already does.

Assisted-by: Claude

* Name the matrix jobs rather than let the matrix name them

A generated job name lists every value in the matrix entry, so `cargo check`
carried the booleans its dependencies and `skip_ssl` keys expand to, and the
snippets job carried its test arguments and timeout. Adding or removing a key
renames the check, which drops it from the required list until that list is
edited to match. Emptying `env_polluting_tests` renamed three checks this way.

`Run rust tests` and `clippy` keep the names they had. `cargo check` drops the
booleans from six of its nine, and the snippets job drops its arguments and
timeout from all three.

Assisted-by: Claude

* Keep a sequence iterator active when an element raises

`PositionIterInternal::_next` exhausted the iterator for any non-`Return`
result, so an error from `__getitem__` ended the walk. `iter_iternext()`
lets go of its sequence for `IndexError` and `StopIteration` alone, and
`PyIterReturn::from_getitem_result` has already turned the first of those
into the second, so only `StopIteration` exhausts now.

Both deque iterators keep exhausting on their own mutation guard, which
`deque_iternext()` does by zeroing the counter before it raises; they
share one step function for it, and the message it raises is lowercased
to match the three other sites in the module.

Assisted-by: Claude

* Name the caller in the bytes conversion TypeError

An object with no iteration protocol reached `PyObject_GetIter`'s "not
iterable" message, and `bytearray.extend()` reported bytes. Each entry
point now checks for the protocol first and names itself:

    bytes(object())               cannot convert 'object' object to bytes
    bytearray(object())           cannot convert 'object' object to bytearray
    bytearray().extend(object())  can't extend bytearray with object

Assisted-by: Claude

* Take a strong count too large to hold as reachable

`start_gc_refs` clipped a count at `GC_REACHABLE - 1`, a number the
per-reference subtraction could still walk down to zero and collect a
live object. It now stores `GC_REACHABLE`, and `subtract_gc_ref` leaves
that value alone.

Assisted-by: Claude

* Raise AssertionError where a snippet asserts False

`assert False` is removed under `-O`, which the snippet suite may run.

Assisted-by: Claude

* Keep raising for a collection that moved under its iterator

A deque, set or dict iterator raised once and then read as spent. The
guard is sticky: `deque_iternext()` looks at the deque's state before the
count it keeps, and `dictiter_iternextkey()` and `setiter_iternext()`
write a size no collection can have, so every later call finds the same
thing and raises again. `dequereviter_next()` is the one exception,
looking at its count first, so it runs out after the first raise.

Both deque iterators now carry `dequeiterobject.counter` rather than
reading a length back from the deque, and the dict and set iterators
compare the size they captured against the collection's own every time
they are asked how much is left, which is what makes that answer nothing
from the moment the collection changes rather than only once the
iterator has raised.

The set's message is capitalized to match `setiter_iternext()`.

Measured against 3.14.6, for each of deque, reversed deque, set, dict
and a reversed dict view: the hint after the change, the error, the hint
after the error, and what a later call answers.

Assisted-by: Claude

* Give apt-get update a deadline to fail on

The step waits on `apt-get update`, which has no deadline of its own, so
a source that takes the connection and then stops answering holds the
job until the workflow's own timeout. The retry that disables the
Microsoft and azure-cli sources runs only when the update exits
non-zero, which a held connection never does; three jobs on this branch
sat on this step for 20 minutes to five and a half hours.

Each attempt is now bounded, and the transports are given a timeout, so
a source that stops answering reaches the retry.

Assisted-by: Claude
2026-08-20 07:08:03 +09:00
박효종 76ca1ff106 Add 'w' (Py_UCS4) typecode support to array (#8266)
* Support array 'w' (Py_UCS4) typecode

Python 3.13 added the 'w' typecode holding fixed 4-byte unicode code
points, unlike 'u' which is platform-dependent wchar_t. Add a Ucs4Char
element type and route it through the existing unicode-array paths:
constructor from str, fromunicode()/tounicode(), __reduce_ex__, repr,
byteswap, and the machine-format code (Utf32). Also register 'w' as a
struct format char in vm::buffer.

Remove the now-passing expectedFailure markers for 'w' tests in
test_array.py.

Assisted-by: Claude

* Reject non-native byte order for the 'w' format char

FormatType::parse accepted 'w' after '<', '>', '!', or '=', but the
non-native branch of FormatType::info has no Ucs4Char arm and hits
unreachable!(), so struct.calcsize('>w') panicked the interpreter.
Add Ucs4Char to the existing native-only filter in FormatCode::parse
(alongside SSizeT/SizeT/VoidP) so those formats fail with the regular
"bad char in struct format" error instead. Native 'w' and
memoryview(array('w', ...)) are unaffected.

Assisted-by: Claude

* Unmark 'w'-typecode tests in test_re and test_csv

test_re's test_empty_array and test_csv's test_char_write construct
array('w', ...) and were marked expectedFailure while the typecode was
unsupported. Now that 'w' works they pass, and regrtest counts the
unexpected successes as failures in CI. Remove the two markers, which
restores both tests to their CPython v3.14.6 form; test_re, test_csv,
and test_array all pass.

Assisted-by: Claude
2026-07-15 23:18:03 +09:00
Shahar Naveh 8ff3141f3f Update test/support to 3.14.5 (#7896)
* Update `test/support` to 3.14.5

* Adjuat test markers

* Add `test_set` to env polluting tests
2026-05-18 00:23:06 +09:00
Lee Dogeon 0475671421 Emit deprecation warning for array typecode u (#7157) 2026-02-15 20:34:19 +09:00
ShaharNaveh 36cb4c2e0e Update test_array.py from 3.14.3 2026-02-10 13:16:46 +02:00
Jeong, YunWon b6e7d71e2e Remove static cache for builtins iter/reversed reduce
- Replace static_cell! cached builtins_iter/builtins_reversed with
  per-call vm.builtins.get_attr lookups to support runtime builtins
  mutation (CPython issue #101765)
- Refactor PositionIterInternal::reduce to take func, active, and
  empty callbacks; resolve builtins outside the lock to prevent
  deadlock from reentrant iterator access
- Add __reduce__ and fix reentrant next() in PyCallableIterator
- Remove expectedFailure from test_reverse_iterator_picking and
  test_reduce_mutating_builtins_iter
2026-02-10 00:49:12 +09:00
Jeong, YunWon 0dac28ff50 Implement UTF-32 encode/decode and fix UTF-16 empty encode
- Add UTF-32, UTF-32-LE, UTF-32-BE encode/decode in _pycodecs.py
- Register utf_32 codec functions in codecs.rs via delegate_pycodecs
- Fix PyUnicode_EncodeUTF16 returning "" instead of [] for empty input
- Remove resolved expectedFailure decorators in test_codecs.py
- Add failure reasons to remaining expectedFailure comments
2026-02-02 12:50:34 +09:00
Jiseok CHOI ff35dcd95a feat(vm/slot): implement Py_TPFLAGS_MANAGED_DICT for class objects (#5949) 2025-07-20 14:11:36 +09:00
Jeong YunWon 0a6e1e80d7 docs 2025-06-23 01:05:54 +09:00
Jiwoo Ahn 7188e0486a Update test_array.py from Cpython v3.11.2 2023-03-25 12:48:34 +09:00
John Pham 27233364bc Add init for array.rs (#4667) 2023-03-09 19:45:58 +09:00
Moreal 778b8fdb2b Unmark resolved tests 2023-01-24 05:56:52 +09:00
Daeun Lee e6452d86d0 update array.index for optional range 2022-07-21 21:12:21 +09:00
Jeong YunWon 48241839aa Merge pull request #3868 from maong0927/arrayiter_reduce
add arrayiter.__reduce__
2022-07-19 06:53:40 +09:00
Jeong Yunwon b1c29aacb1 adjust failing markers for array tests 2022-07-18 03:54:46 +09:00
CPython developers 8d3bac9c1e Update test_array from CPython 3.10.5 2022-07-18 03:54:46 +09:00
Kim, YeonWoo 21a7369953 Add weakproxy mapping 2022-07-15 00:49:20 +09:00
hyezzangandYaminyam ab284c87fc update test_iterator_pickle
Co-authored-by: Yaminyam <siontama@gmail.com>
2022-07-13 18:04:17 +09:00
Dean Li 5ee4fb899b test: use os_helper 2021-11-28 20:51:32 +08:00
Jeong YunWon 913b78ca44 Revert "Merge pull request #3433 from deantvv/test-update"
This reverts commit 9fa5c5ac66, reversing
changes made to e7fa32c687.
2021-11-17 17:06:51 +09:00
Dean Li 49a5805d11 test: use os_helper 2021-11-13 02:18:33 +00:00
Kangzhi Shi de47cd0acb Impl __reduce_ex__ with _array_reconstructor 2021-10-10 14:43:20 +02:00
Kangzhi Shi ff0adc1204 Impl __reduce__ for array 2021-10-10 14:43:16 +02:00
Kangzhi Shi 52b7f3a5f7 unmark successful test 2021-09-16 15:29:26 +02:00
Steve Shi c064118e6b Impl array.fromfile (#3065) 2021-09-16 03:18:13 +09:00
Frank King c1aaac02ed Implement array::_array_reconstructor 2021-08-30 22:21:53 +08:00
jfh 97b8d7ca7b Add checking for repeat on sequences. 2021-08-29 17:43:47 +03:00
Frank King e652ae8fc0 Support unicode array type. 2021-08-21 20:18:05 +08:00
Robert Booth af6b230dad Change int type checking, amend tests
- add a special_retrieve fudge function to the PyValue trait
- define the special_retrieve function for PyInt
- remove blocks on successful tests to reflect effect of changes
2021-04-25 01:18:57 +09:00
Kangzhi Shi 8522d120e5 fix array from bytes 2021-04-16 09:17:13 +02:00
Padraic Fanning 4ba5829fe1 Delete code smell 2021-02-27 19:37:01 -05:00
Padraic Fanning 79ac9ab93c Delete code smell 2021-02-27 14:01:45 -05:00
Padraic Fanning 138d0f8556 Unskip tests in test_array 2021-02-25 16:55:28 -05:00
Padraic Fanning f909c7d9f6 Explain test_alloc_overflow skip 2021-02-07 15:49:41 -05:00
Padraic Fanning 2259ceee48 Explain UnicodeTest skip 2021-02-07 15:49:41 -05:00
Padraic Fanning 3d6179dce8 Explain test_tofrombytes skip 2021-02-07 15:49:41 -05:00
Kangzhi Shi e1ddbda4fc fix unittest test_array.test_buffer 2020-10-10 16:59:44 +09:00
Kangzhi Shi 3cdab86444 test_array remove @skip for successed test 2020-10-09 10:58:37 +02:00
Kangzhi Shi fa3fd724ac Fix array extend and improve 2020-09-15 09:10:38 +02:00
Noah bd92c7eea0 Merge pull request #2196 from qingshi163/dev_array_byteswap
Implement array byteswap()
2020-09-10 17:52:20 -05:00
Kangzhi Shi 1f756dbbf4 Implement array __copy__() and __deepcopy__() 2020-09-10 08:12:11 +02:00
Kangzhi Shi 4a1cda77f8 Implement array fromlist 2020-09-09 20:01:14 +02:00
Kangzhi Shi 78ab0a225a Implement array byteswap() 2020-09-09 12:03:53 +02:00
Kangzhi Shi 48909327db Fix array compare oparation 2020-09-06 13:53:20 +02:00
Steve Shi 05b7acc95f Merge branch 'master' into dev_array_del 2020-09-04 10:25:47 +02:00
Kangzhi Shi a056e7b86a Remove comment 2020-09-02 11:40:25 +02:00
Kangzhi Shi fa6b8208ec Implement array delitem by slice 2020-09-02 11:37:27 +02:00
Kangzhi Shi 2cd634f956 Implement array delitem 2020-09-02 08:41:35 +02:00