Commit Graph

52190 Commits

Author SHA1 Message Date
Petr Viktorin dcaf33a41d
gh-114314: ctypes: remove stgdict and switch to heap types (GH-116458)
Before this change, ctypes classes used a custom dict subclass, `StgDict`,
as their `tp_dict`. This acts like a regular dict but also includes extra information
about the type.

This replaces stgdict by `StgInfo`, a C struct on the type, accessed by
`PyObject_GetTypeData()` (PEP-697).
All usage of `StgDict` (mainly variables named `stgdict`, `dict`, `edict` etc.) is
converted to `StgInfo` (named `stginfo`, `info`, `einfo`, etc.).
Where the dict is actually used for class attributes (as a regular PyDict), it's now
called `attrdict`.

This change -- not overriding `tp_dict` -- is made to make me comfortable with
the next part of this PR: moving the initialization logic from `tp_new` to `tp_init`.

The `StgInfo` is set up in `__init__` of each class, with a guard that prevents
calling `__init__` more than once. Note that abstract classes (like `Array` or
`Structure`) are created using `PyType_FromMetaclass` and do not have
`__init__` called.
Previously, this was done in `__new__`, which also wasn't called for abstract
classes.
Since `__init__` can be called from Python code or skipped, there is a tested
guard to ensure `StgInfo` is initialized exactly once before it's used.

Co-authored-by: neonene <53406459+neonene@users.noreply.github.com>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2024-03-20 17:33:08 +01:00
jkriegshauser fc45998007
gh-116773: Ensure overlapped objects on Windows are not deallocated too early by asyncio (GH-116774) 2024-03-20 14:33:28 +00:00
Serhiy Storchaka 519b2ae22b
gh-117021: Fix integer overflow in PyLong_AsPid() on non-Windows 64-bit platforms (GH-117064) 2024-03-20 15:39:53 +02:00
Nikita Sobolev 8182319de3
gh-94808: add tests covering `PyFunction_{Get,Set}Closure` (GH-99429) 2024-03-20 11:43:20 +01:00
Mark Shannon 15309329b6
GH-108362: Incremental Cycle GC (GH-116206) 2024-03-20 08:54:42 +00:00
Victor Stinner d5ebf8b71f
gh-116869: Fix test_cext for Free Threading (#117043)
Don't check for warnings on Free Threading.
2024-03-19 23:23:17 +01:00
Victor Stinner 438de10c16
gh-116869: Fix test_cext on RHEL7 (#117010)
Remove -std option from CC command line.

Skip C++14 test for now on non-Windows platforms (like RHEL7).
2024-03-19 22:58:13 +01:00
Sam Gross 60e105c1c1
gh-113964: Don't prevent new threads until all non-daemon threads exit (#116677)
Starting in Python 3.12, we prevented calling fork() and starting new threads
during interpreter finalization (shutdown). This has led to a number of
regressions and flaky tests. We should not prevent starting new threads
(or `fork()`) until all non-daemon threads exit and finalization starts in
earnest.

This changes the checks to use `_PyInterpreterState_GetFinalizing(interp)`,
which is set immediately before terminating non-daemon threads.
2024-03-19 14:40:20 -04:00
Victor Stinner 61c659e2dc
gh-116417: Move limited C API complex.c tests to _testlimitedcapi (#117014)
Split complex.c tests of _testcapi into two parts: limited C API
tests in _testlimitedcapi and non-limited C API tests in _testcapi.
2024-03-19 17:23:12 +01:00
Victor Stinner f55e1880c1
gh-116417: Move limited C API dict.c tests to _testlimitedcapi (#117006)
Split dict.c tests of _testcapi into two parts: limited C API tests
in _testlimitedcapi and non-limited C API tests in _testcapi.
2024-03-19 15:06:20 +00:00
et-repositories 75935746be
gh-116647: Fix recursive child in dataclasses (#116790) 2024-03-19 08:58:40 -06:00
Victor Stinner 3cac2af5ec
gh-116417: Move limited C API long.c tests to _testlimitedcapi (#117001)
* Split long.c tests of _testcapi into two parts: limited C API tests
  in _testlimitedcapi and non-limited C API tests in _testcapi.
* Move testcapi_long.h from Modules/_testcapi/ to
  Modules/_testlimitedcapi/.
* Add MODULE__TESTLIMITEDCAPI_DEPS to Makefile.pre.in.
2024-03-19 14:04:23 +00:00
Victor Stinner a114d08a89
gh-92906: Enable test_cext and test_cppext on Windows (#117000)
On Windows in release mode, the test_cext and test_cppext can now
build C and C++ extensions.

* test_cext now also builds the C extension without options.
* test_cppext now also builds the C++ extension without options.
* Add C++14 test to test_cppext; C++11 is not supported by MSVC.
* Make setup_venv_with_pip_setuptools_wheel() quiet when
  support.verbose is false. Only show stdout and stderr on failure.
2024-03-19 14:03:27 +00:00
Victor Stinner 27cf3ed00c
gh-90872: Fix subprocess.Popen.wait() for negative timeout (#116989)
On Windows, subprocess.Popen.wait() no longer calls
WaitForSingleObject() with a negative timeout: pass 0 ms if the
timeout is negative.
2024-03-19 14:42:44 +01:00
Russell Keith-Magee 408e127159
gh-114099 - Add iOS framework loading machinery. (GH-116454)
Co-authored-by: Malcolm Smith <smith@chaquo.com>
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2024-03-19 08:36:19 -04:00
Victor Stinner a557478987
gh-116417: Move limited C API unicode.c tests to _testlimitedcapi (#116993)
Split unicode.c tests of _testcapi into two parts: limited C API
tests in _testlimitedcapi and non-limited C API tests in _testcapi.

Update test_codecs.
2024-03-19 12:30:39 +00:00
Victor Stinner 1312094b39
gh-116869: Test the limited C API in test_cext (#116995) 2024-03-19 12:19:45 +00:00
Victor Stinner 5405e9e5b5
gh-116869: Build test_cext with -Werror=declaration-after-statement (#116990)
Make sure that the C API does not emit compiler warnings when built
with -Werror=declaration-after-statement.
2024-03-19 12:05:22 +01:00
Victor Stinner 039d20ae54
gh-116417: Move limited C API abstract.c tests to _testlimitedcapi (#116986)
Split abstract.c and float.c tests of _testcapi into two parts:
limited C API tests in _testlimitedcapi and non-limited C API tests
in _testcapi.

Update test_bytes and test_class.
2024-03-19 10:44:13 +00:00
David Röthlisberger b1bc37597f
gh-116957: configparser: Do post-process values after DuplicateOptionError (GH-116958)
If you catch DuplicateOptionError / DuplicateSectionError when reading a
config file (the intention is to skip invalid config files) and then
attempt to use the ConfigParser instance, any values it *had* read
successfully so far, were stored as a list instead of string! Later
`get` calls would raise "AttributeError: 'list' object has no attribute
'find'" from somewhere deep in the interpolation code.
2024-03-19 11:59:08 +02:00
Aviel Boag a22d05f04c
gh-105866: fix dataclass with slots=True, weakref_slot=True (#105870)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Co-authored-by: Carl Meyer <carl@oddbird.net>
2024-03-18 18:53:14 -06:00
Victor Stinner 1d82a41235
gh-116869: Enable test_cext and test_cppext on Free Threading build (#116973)
Remove the "if Py_GIL_DISABLED" skip and move all "skip" decorators
to the class. Use support.check_sanitizer()
2024-03-18 23:14:29 +00:00
Victor Stinner ecb4a2b711
gh-116417: Move limited C API list.c tests to _testlimitedcapi (#116602)
Split list.c and set.c tests of _testcapi into two parts: limited C
API tests in _testlimitedcapi and non-limited C API tests in
_testcapi.
2024-03-18 22:03:55 +01:00
Pierre Ossman (ThinLinc team) 4159644177
gh-113538: Add asycio.Server.{close,abort}_clients (redo) (#116784)
These give applications the option of more forcefully terminating client
connections for asyncio servers. Useful when terminating a service and
there is limited time to wait for clients to finish up their work.

This is a do-over with a test fix for gh-114432, which was reverted.
2024-03-18 13:15:53 -07:00
Victor Stinner 590a26010d
gh-116869: Add test_cext test: build a C extension (#116954) 2024-03-18 20:15:20 +01:00
Duprat 7707b14489
gh-115258: Fix hanging tests for threading queue shutdown (#115940)
This reinstates `test_shutdown_immediate_all_methods_in_many_threads`
and improves `test_shutdown_all_methods_in_many_threads`.
2024-03-18 16:15:29 +00:00
Sam Gross c80d2d3263
gh-116877: Update `wheel` to version `0.43.0` (#116878) 2024-03-18 11:50:32 -04:00
kernc 52ef4430a9
gh-71765: Fix inspect.getsource() on empty file (GH-20809)
* bpo-27578: Fix inspect.getsource() on empty file

For modules from empty files, `inspect.getsource()` now
returns an empty string, and `inspect.getsourcelines()` returns
a list of one empty string, fixing the expected invariant.

As indicated by `exec('')`, empty strings are valid Python
source code.

Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
2024-03-18 16:13:02 +01:00
Victor Stinner f6cdc6b4a1
Revert "gh-96844: Improve error message of list.remove (gh-106455)" (#116956)
This reverts commit 217f47d6e5.
2024-03-18 13:54:45 +00:00
Jakub Stasiak 2a4cbf17af
GH-65056: Improve the IP address' is_global/is_private documentation (GH-113186)
* GH-65056: Improve the IP address' is_global/is_private documentation

It wasn't clear what the semantics of is_global/is_private are and, when
one gets to the bottom of it, it's not quite so simple (hence the
exceptions listed).

Co-authored-by: Petr Viktorin <encukou@gmail.com>
2024-03-18 13:57:00 +01:00
Erlend E. Aasland e2fcaf19d3
gh-115874: Don't use module state in teedataobject tp_dealloc (#116204)
Co-authored-by: Brandt Bucher <brandtbucher@microsoft.com>
2024-03-18 13:24:24 +01:00
AN Long cd2ed91780
gh-115538: Emit warning when use bool as fd in _io.WindowsConsoleIO (GH-116925) 2024-03-18 11:48:50 +00:00
Barney Gale 0634201f53
GH-116377: Stop raising `ValueError` from `glob.translate()`. (#116378)
Stop raising `ValueError` from `glob.translate()` when a `**` sub-string
appears in a non-recursive pattern segment. This matches `glob.glob()`
behaviour.
2024-03-17 17:09:35 +00:00
Victor Stinner 8e3c953b3a
gh-73468: Add math.fma() function (#116667)
Added new math.fma() function, wrapping C99's ``fma()`` operation:
fused multiply-add function.

Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
2024-03-17 13:58:26 +00:00
Antoine Pitrou b8d808ddd7
GH-112536: Add more TSan tests (#116911)
These may all exercise some non-trivial aspects of thread synchronization.
2024-03-17 09:47:14 +01:00
John Sloboda 649857a157
gh-85287: Change codecs to raise precise UnicodeEncodeError and UnicodeDecodeError (#113674)
Co-authored-by: Inada Naoki <songofacandy@gmail.com>
2024-03-17 04:58:42 +00:00
Donghee Na bee7e290cd
gh-112536: Add more TSAN tests (#116896)
---------

Co-authored-by: Antoine Pitrou <antoine@python.org>
2024-03-16 14:52:44 +00:00
mpage 33da0e844c
gh-114271: Fix race in `Thread.join()` (#114839)
There is a race between when `Thread._tstate_lock` is released[^1] in `Thread._wait_for_tstate_lock()`
and when `Thread._stop()` asserts[^2] that it is unlocked. Consider the following execution
involving threads A, B, and C:

1. A starts.
2. B joins A, blocking on its `_tstate_lock`.
3. C joins A, blocking on its `_tstate_lock`.
4. A finishes and releases its `_tstate_lock`.
5. B acquires A's `_tstate_lock` in `_wait_for_tstate_lock()`, releases it, but is swapped
   out before calling `_stop()`.
6. C is scheduled, acquires A's `_tstate_lock` in `_wait_for_tstate_lock()` but is swapped
   out before releasing it.
7. B is scheduled, calls `_stop()`, which asserts that A's `_tstate_lock` is not held.
   However, C holds it, so the assertion fails.

The race can be reproduced[^3] by inserting sleeps at the appropriate points in
the threading code. To do so, run the `repro_join_race.py` from the linked repo.

There are two main parts to this PR:

1. `_tstate_lock` is replaced with an event that is attached to `PyThreadState`.
   The event is set by the runtime prior to the thread being cleared (in the same
   place that `_tstate_lock` was released). `Thread.join()` blocks waiting for the
   event to be set.
2. `_PyInterpreterState_WaitForThreads()` provides the ability to wait for all
   non-daemon threads to exit. To do so, an `is_daemon` predicate was added to
   `PyThreadState`. This field is set each time a thread is created. `threading._shutdown()`
   now calls into `_PyInterpreterState_WaitForThreads()` instead of waiting on
   `_tstate_lock`s.

[^1]: 441affc9e7/Lib/threading.py (L1201)
[^2]: 441affc9e7/Lib/threading.py (L1115)
[^3]: 8194653279

---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Antoine Pitrou <antoine@python.org>
2024-03-16 13:56:30 +01:00
Antoine Pitrou 86bc40dd41
gh-112536: Add test_threading to TSAN tests (#116898) 2024-03-16 11:55:46 +00:00
Serhiy Storchaka c61cb507c1
gh-116484: Fix collisions between Checkbutton and ttk.Checkbutton default names (GH-116495)
Change automatically generated tkinter.Checkbutton widget names to
avoid collisions with automatically generated tkinter.ttk.Checkbutton
widget names within the same parent widget.
2024-03-16 13:31:19 +02:00
Serhiy Storchaka 1069a462f6
gh-116764: Fix regressions in urllib.parse.parse_qsl() (GH-116801)
* Restore support of None and other false values.
* Raise TypeError for non-zero integers and non-empty sequences.

The regressions were introduced in gh-74668
(bdba8ef42b).
2024-03-16 12:36:05 +02:00
Serhiy Storchaka 269051d20e
gh-90535: Fix support of interval>1 in logging.TimedRotatingFileHandler (GH-116220)
Fix support of interval values > 1 in logging.TimedRotatingFileHandler
for when='MIDNIGHT' and when='Wx'.
2024-03-16 12:29:42 +02:00
Donghee Na 20578a1f68
gh-112536: Add TSAN builds on Github Actions (#116872) 2024-03-16 11:10:37 +01:00
Nikita Sobolev a1c4923d65
gh-116858: Add `@cpython_only` to several tests in `test_cmd_line` (#116859) 2024-03-16 11:54:42 +03:00
Raymond Hettinger 0c7dc494f2
Minor kde() docstring nit: make presentation order match the function signature (#116876) 2024-03-15 14:02:10 -05:00
Donghee Na ebf29b3a02
gh-112536: Add --tsan test for reasonable TSAN execution times. (gh-116601) 2024-03-16 01:07:16 +09:00
Tian Gao 59e30f41ed
gh-116735: Use `MISSING` for `CALL` event if argument is absent (GH-116737) 2024-03-15 14:46:18 +00:00
Zackery Spytz d180b507c4
gh-63283: IDNA prefix should be case insensitive (GH-17726)
Any capitalization of "xn--" should be acceptable for the ACE prefix
(see https://tools.ietf.org/html/rfc3490#section-5).

Co-authored-by: Pepijn de Vos <pepijndevos@gmail.com>
Co-authored-by: Erlend E. Aasland <erlend@python.org>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2024-03-15 15:38:13 +01:00
Tian Gao a50cf6c3d7
gh-90095: Ignore empty lines and comments in `.pdbrc` (#116834) 2024-03-15 09:36:04 +00:00
Victor Stinner 7bbb9b57e6
gh-111696, PEP 737: Add %T and %N to PyUnicode_FromFormat() (#116839) 2024-03-14 22:23:00 +00:00