Commit Graph

121378 Commits

Author SHA1 Message Date
Guido van Rossum 97ba910e47
gh-108716:: Remove _PyStaticCode_Init/Fini (#117141)
More deepfreeze cleanup.
2024-03-22 01:27:48 +00:00
Eric Snow b3d25df8d3
gh-105716: Fix _PyInterpreterState_IsRunningMain() For Embedders (gh-117140)
When I added _PyInterpreterState_IsRunningMain() and friends last year, I tried to accommodate applications that embed Python but don't call _PyInterpreterState_SetRunningMain() (not that they're expected to).  That mostly worked fine until my recent changes in gh-117049, where the subtleties with the fallback code led to failures; the change ended up breaking test_tools.test_freeze, which exercises a basic embedding situation.

The simplest fix is to drop the fallback code I originally added to _PyInterpreterState_IsRunningMain() (and later to _PyThreadState_IsRunningMain()).  I've kept the fallback in the _xxsubinterpreters module though.  I've also updated Py_FrozenMain() to call _PyInterpreterState_SetRunningMain().
2024-03-21 18:20:20 -06:00
Thomas A Caswell c4bf58a14f
gh-116745: Remove all internal usage of @LIBPYTHON@ (#116746)
Replace with MODULE_LDFLAGS.
2024-03-22 00:54:50 +01:00
Malcolm Smith 3ec57307e7
gh-71052: Add Android build script and instructions (#116426) 2024-03-22 00:52:29 +01:00
Victor Stinner 50f9b0b1e0
gh-117061: Fix test_posix.test_sched_setaffinity() on RHEL9 (#117126)
On RHEL9, sched_setaffinity(0, []) does not fail.
2024-03-21 22:17:09 +00:00
Ned Batchelder 0907871d43
docs: fix over-linking in dataclasses.rst (#117005) 2024-03-21 12:47:09 -07:00
Guido van Rossum 570a82d46a
gh-117045: Add code object to function version cache (#117028)
Changes to the function version cache:

- In addition to the function object, also store the code object,
  and allow the latter to be retrieved even if the function has been evicted.
- Stop assigning new function versions after a critical attribute (e.g. `__code__`)
  has been modified; the version is permanently reset to zero in this case.
- Changes to `__annotations__` are no longer considered critical. (This fixes gh-109998.)

Changes to the Tier 2 optimization machinery:

- If we cannot map a function version to a function, but it is still mapped to a code object,
  we continue projecting the trace.
  The operand of the `_PUSH_FRAME` and `_POP_FRAME` opcodes can be either NULL,
  a function object, or a code object with the lowest bit set.

This allows us to trace through code that calls an ephemeral function,
i.e., a function that may not be alive when we are constructing the executor,
e.g. a generator expression or certain nested functions.
We will lose globals removal inside such functions,
but we can still do other peephole operations
(and even possibly [call inlining](https://github.com/python/cpython/pull/116290),
if we decide to do it), which only need the code object.
As before, if we cannot retrieve the code object from the cache, we stop projecting.
2024-03-21 12:37:41 -07:00
Will Childs-Klein c85d84166a
gh-116333: Relax error string text expectations in SSL-related tests (GH-116334)
* Relax error string text expectations in SSL-related tests

As suggested [here][1], this change relaxes the OpenSSL error string
text expectations in a number of tests. This was specifically done in
support of more easily building CPython [AWS-LC][2], but because AWS-LC
is a fork of [BoringSSL][3], it should increase compatibility with that
library as well.

In addition to the error string relaxations, we also add some guards
around the `tls-unique` channel binding being used with TLSv1.3, as that
feature (described in [RFC 6929][4]) is [not defined][5] for TLSv1.3.

[1]: https://discuss.python.org/t/support-building-ssl-and-hashlib-modules-against-aws-lc/44505/4
[2]: https://github.com/aws/aws-lc
[3]: https://github.com/google/boringssl
[4]: https://datatracker.ietf.org/doc/html/rfc5929#section-3
[5]: https://datatracker.ietf.org/doc/html/rfc8446#appendix-C.5
2024-03-21 19:16:36 +00:00
Sam Gross 1f72fb5447
gh-116522: Refactor `_PyThreadState_DeleteExcept` (#117131)
Split `_PyThreadState_DeleteExcept` into two functions:

- `_PyThreadState_RemoveExcept` removes all thread states other than one
  passed as an argument. It returns the removed thread states as a
  linked list.

- `_PyThreadState_DeleteList` deletes those dead thread states. It may
  call destructors, so we want to "start the world" before calling
  `_PyThreadState_DeleteList` to avoid potential deadlocks.
2024-03-21 11:21:02 -07:00
Michael Droettboom 50369e6c34
gh-116996: Add pystats about _Py_uop_analyse_and_optimize (GH-116997) 2024-03-22 01:27:46 +08:00
Eric Snow 617158e078
gh-76785: Drop PyInterpreterID_Type (gh-117101)
I added it quite a while ago as a strategy for managing interpreter lifetimes relative to the PEP 554 (now 734) implementation.  Relatively recently I refactored that implementation to no longer rely on InterpreterID objects.  Thus now I'm removing it.
2024-03-21 17:15:02 +00:00
Victor Stinner abdd1f938f
gh-85283: Build _testconsole extension with limited C API (#117125) 2024-03-21 17:45:43 +01:00
Victor Stinner 8bea6c411d
gh-115754: Add Py_GetConstant() function (#116883)
Add Py_GetConstant() and Py_GetConstantBorrowed() functions.

In the limited C API version 3.13, getting Py_None, Py_False,
Py_True, Py_Ellipsis and Py_NotImplemented singletons is now
implemented as function calls at the stable ABI level to hide
implementation details. Getting these constants still return borrowed
references.

Add _testlimitedcapi/object.c and test_capi/test_object.py to test
Py_GetConstant() and Py_GetConstantBorrowed() functions.
2024-03-21 16:07:00 +00:00
Eric Snow 5a76d1be8e
gh-105716: Update interp->threads.main After Fork (gh-117049)
I missed this in gh-109921.

We also update Py_Exit() to call _PyInterpreterState_SetNotRunningMain(), if necessary.
2024-03-21 10:06:35 -06:00
Eric Snow bbee57fa8c
gh-76785: Clean Up Interpreter ID Conversions (gh-117048)
Mostly we unify the two different implementations of the conversion code (from PyObject * to int64_t.  We also drop the PyArg_ParseTuple()-style converter function, as well as rename and move PyInterpreterID_LookUp().
2024-03-21 09:56:12 -06:00
Sam Gross e728303532
gh-116522: Stop the world before fork() and during shutdown (#116607)
This changes the free-threaded build to perform a stop-the-world pause
before deleting other thread states when forking and during shutdown.
This fixes some crashes when using multiprocessing and during shutdown
when running with `PYTHON_GIL=0`.

This also changes `PyOS_BeforeFork` to acquire the runtime lock
(i.e., `HEAD_LOCK(&_PyRuntime)`) before forking to ensure that data
protected by the runtime lock (and not just the GIL or stop-the-world)
is in a consistent state before forking.
2024-03-21 10:01:16 -04:00
Malcolm Smith 1f8b24ef69
gh-71052: Implement `ctypes.util.find_library` on Android (GH-116379) 2024-03-21 14:20:57 +01:00
Tian Gao d16c9d1278
gh-116987: Support class code objects in inspect.findsource() (GH-117025) 2024-03-21 10:30:10 +00:00
Adam Turner 6547330f4e
GH-109653: Defer import of ``importlib.metadata._adapters`` (#109829)
* adapters

* Add comments for deferred imports with links to rationale.

* Add blurb

---------

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
2024-03-21 03:49:10 +00:00
Jason R. Coombs 667294d5b2
gh-117089: Apply changes from importlib_metadata 7.1.0 (#117094)
* Apply changes from importlib_metadata 7.1.0

* Include the data sources in the makefile (even though they're not needed)
2024-03-20 23:01:24 -04:00
Victor Stinner f4cc77d494
gh-116869: Enable -Werror in test_cext for Free Threading (#117106)
Check for warnings, but don't enable the compiler flag
-Werror=declaration-after-statement.
2024-03-21 00:06:24 +01:00
Victor Stinner 104602a607
gh-105927: Limit PyWeakref_GetRef() to limited C API 3.13 (#117091) 2024-03-20 23:52:23 +01:00
Jason R. Coombs 8ad8898420
gh-117089: Move importlib.metadata tests to their own package (#117092)
* Ensure importlib.metadata tests do not leak references in sys.modules.

* Move importlib.metadata tests to their own package for easier syncing with importlib_metadata.

* Update owners and makefile for new directories.

* Add blurb
2024-03-20 17:11:00 -04:00
Carol Willing 7d446548ef
Fix sort order for "locale encoding" glossary item (#115794)
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
2024-03-20 15:00:59 -06:00
Mark Shannon 63289b9dfb
GH-117066: Tier 2 optimizer: Don't throw away good traces if we can't optimize them perfectly. (GH-117067) 2024-03-20 18:24:02 +00:00
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
Russell Keith-Magee 44fbab43d8
gh-117058: Update GUI and packaging recommendations for macOS. (#117059) 2024-03-20 17:32:56 +02:00
Brett Simmers 9221ef2d8c
gh-116908: Only write to `_pending_calls.calls_to_do` with atomic operations (#117044)
These writes to `pending->calls_to_do` need to be atomic, because other threads
can read (atomically) from `calls_to_do` without holding `pending->mutex`.
2024-03-20 11:18:26 -04: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
Serhiy Storchaka 2d17309cc7
gh-117041: Add "-X gil" in the Python CLI help (GH-117042) 2024-03-19 23:30:25 +02:00
Ned Batchelder 332ac46c09
docs: announce venv creation before installing packages (#117036) 2024-03-19 21:55:20 +02:00
Hugo van Kemenade 9080e9ed50
gh-101100: Fix Sphinx warnings in `library/pydoc.rst` (#116913) 2024-03-19 21:48:08 +02:00
Łukasz Langa 1ab0d0b116
gh-116886: Temporarily disable CIfuzz (memory) (#117018) 2024-03-19 21:06:06 +02: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
Terry Jan Reedy 025ef7a5f7
gh-56374: Clarify documentation of nonlocal (#116942)
Define 'nonlocal scopes' in a way that excludes class scopes.
Rearrange the rest of the doc.  Add "Programmer's note".
2024-03-19 13:55:21 -04:00
Serhiy Storchaka b85572c47d
gh-90300: Improve the Python CLI help output (GH-115853)
* document equivalent command-line options for all environment variables
* document equivalent environment variables for all command-line options
* reduce the size of variable and option descriptions to minimum
* remove the ending period in single-sentence descriptions

Co-authored-by: Éric <merwok@netwok.org>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2024-03-19 19:26:32 +02: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
Sunghyun Kim 7f64ae30dd
gh-107607: Update comment about utf-8 BOM being ignored (#107858)
---------
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
2024-03-19 11:51:12 -04:00
Brandt Bucher 2c82592ab4
GH-116017: Put JIT code and data on the same page (GH-116845) 2024-03-19 08:47:28 -07: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