Commit graph

930 commits

Author SHA1 Message Date
Pablo Galindo
ea120fc6e9 Regen stuff 2025-12-06 15:44:07 +00:00
Pablo Galindo
db151a5192 Merge remote-tracking branch 'upstream/main' into lazy 2025-12-06 15:40:02 +00:00
Pablo Galindo
e6cb131a53 Implement more of PEP 810 2025-12-06 15:21:17 +00:00
Petr Viktorin
bf66bce4ee
gh-141780: Make PyModule_FromSlotsAndSpec enable GIL if needed (GH-141785) 2025-11-24 13:26:35 +01:00
Sam Gross
2d50dd242e
gh-137422: Fix race condition in PyImport_AddModuleRef (gh-141822) 2025-11-21 13:30:33 -05:00
Itamar Oren
1e4e59bb37
gh-116146: Add C-API to create module from spec and initfunc (GH-139196)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-11-14 10:43:25 +01:00
Petr Viktorin
a4dd66275b
gh-140550: Use a bool for the Py_mod_gil value (GH-141519)
This needs a single bit, but was stored as a void* in the module
struct. This didn't matter due to packing, but now that there's
another bool in the struct, we can save a bit of memory by
making md_gil a bool.

Variables that changed type are renamed, to detect conflicts.
2025-11-14 10:38:49 +01:00
Victor Stinner
8435a2278f
gh-141376: Fix exported symbols (GH-141377)
* gh-141376: Fix exported symbols

* _io module: add "_Py_" prefix to "spec" variables. For example,
  rename bufferedrandom_spec to _Py_bufferedrandom_spec.
* typevarobject.c: add "static" to "spec" and "slots" variables.
* import.c: add "static" to "pkgcontext" variable.

* No longer export textiowrapper_slots
2025-11-11 09:21:24 +01:00
Petr Viktorin
589a03a8ce
gh-140550: Initial implementation of PEP 793 – PyModExport (GH-140556)
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-11-05 12:31:42 +01:00
Dino Viehland
8d57aca95a Merge remote-tracking branch 'origin/main' into HEAD 2025-11-03 10:10:28 -08:00
Peter Bierma
2cefa70eb9
gh-140544: Always assume that thread locals are available (GH-140690)
Python has required thread local support since 3.12 (see GH-103324). By assuming that thread locals are always supported, we can improve the performance of third-party extensions by allowing them to access the attached thread and interpreter states directly.
2025-10-28 09:07:19 -04:00
Itamar Oren
e8b5cb8f33
gh-140641: Break out of inittab search on match (GH-140642) 2025-10-27 15:18:58 +02:00
Pablo Galindo Salgado
2e197658cc Fix another race 2025-10-21 17:18:43 +01:00
Pablo Galindo Salgado
c3b4807dac Fix bug in specialization and make reification atomic 2025-10-21 16:55:35 +01:00
Dino Viehland
06b9110569 Update sys module to conform with the PEP, add matching C API 2025-10-09 13:37:28 -07:00
Dino Viehland
d9ad012e5d Fix leaks and LOAD_ATTR specialization 2025-10-08 16:21:15 -07:00
Dino Viehland
0c246bc79d __import__ is loaded at reification time 2025-10-08 13:33:16 -07:00
Dino Viehland
c5efb20d48 Expose LazyImportType in types module 2025-10-08 13:31:57 -07:00
Dino Viehland
c63198cba4 Move eager check for from imports into import from 2025-10-07 16:20:47 -07:00
Dino Viehland
c8c8838b1c Move __lazy_imports__ check into the interpreter 2025-10-02 13:22:54 -07:00
Pablo Galindo Salgado
9078f571e4 Fix __lazy_modules__ 2025-10-02 13:22:54 -07:00
Dino Viehland
b179da2cf5 Re-enable eagerly returning imported module 2025-10-02 13:22:54 -07:00
Dino Viehland
9be59ecebd Publish lazy imported packages on parent 2025-10-02 13:22:54 -07:00
Dino Viehland
781eedb9d4 Add PyExc_ImportCycleError and raise it when a cycle is detected 2025-10-02 13:22:54 -07:00
Dino Viehland
00e7800e4c Implement disabling imports in try/except and * imports, report errors on bad usage of lazy 2025-10-02 13:22:54 -07:00
Pablo Galindo Salgado
164423b42b Fix submodules crash 2025-10-02 13:22:54 -07:00
Pablo Galindo Salgado
44a3e46770 fix offset in addr2line 2025-10-02 13:22:54 -07:00
Pablo Galindo Salgado
f3f5795e31 Fix recursive lazy imports and error path in bytecodes.c 2025-10-02 13:22:54 -07:00
Pablo Galindo Salgado
6a911327d0 Implement better error 2025-10-02 13:22:54 -07:00
Dino Viehland
058bc6e884 Flow import func through to lazy imports object and __lazy_import__ 2025-10-02 13:22:54 -07:00
Dino Viehland
41ab092407 Add compatiblity mode 2025-10-02 13:22:53 -07:00
Dino Viehland
de281fd894 Add lazy import filter 2025-10-02 13:22:53 -07:00
Dino Viehland
9eef03cc80 Export lazy_import in imp module 2025-10-02 13:22:53 -07:00
Dino Viehland
3b0d745e73 Add __lazy_import__, check sys.modules before import 2025-10-02 13:22:53 -07:00
Dino Viehland
1c691ea756 Lazy imports grammar / AST changes 2025-10-02 13:22:53 -07:00
Lisa Roach
2fd43a1ffe
gh-138310: Adds sys.audit event for import_module (#138311)
* Updates sys.audit calls for imports to include import_module
* Adds unit tests for existing and new functionality
2025-09-19 06:21:42 -07:00
Adam Turner
918e3ba6c0
GH-137623: Use an AC decorator for docstring line length enforcement (#137690) 2025-08-18 18:29:00 +01:00
Eric Snow
a450a0ddec
gh-135443: Sometimes Fall Back to __main__.__dict__ For Globals (gh-135491)
For several builtin functions, we now fall back to __main__.__dict__ for the globals
when there is no current frame and _PyInterpreterState_IsRunningMain() returns
true.  This allows those functions to be run with Interpreter.call().

The affected builtins:

* exec()
* eval()
* globals()
* locals()
* vars()
* dir()

We take a similar approach with "stateless" functions, which don't use any
global variables.
2025-06-16 17:34:19 -06:00
Eric Snow
52deabefd0
gh-132775: Expand the Capability of Interpreter.call() (gh-133484)
It now supports most callables, full args, and return values.
2025-05-30 09:15:00 -06:00
Serhiy Storchaka
bac3fcba5b
gh-108512: Add and use new replacements for PySys_GetObject() (GH-111035)
Add functions PySys_GetAttr(), PySys_GetAttrString(),
PySys_GetOptionalAttr() and PySys_GetOptionalAttrString().
2025-05-28 20:11:09 +03:00
Nico-Posada
4e9005d32f
gh-134100: Fix use-after-free in PyImport_ImportModuleLevelObject (#134117) 2025-05-18 12:41:38 +05:30
Bénédikt Tran
a2c4467d06
gh-133644: remove deprecated PyImport_ImportModuleNoBlock (#133655) 2025-05-08 13:08:43 +00:00
Noah Kim
c4bcc6a778
gh-102567: Add -X importtime=2 for logging an importtime message for already-loaded modules (#118655)
Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
2025-05-06 01:03:55 +01:00
Eric Snow
fe462f5a91
gh-132775: Drop PyUnstable_InterpreterState_GetMainModule() (gh-132978)
We replace it with _Py_GetMainModule(), and add _Py_CheckMainModule(), but both in the internal-only C-API.  We also add _PyImport_GetModulesRef(), which is the equivalent of _PyImport_GetModules(), but which increfs before the lock is released.

This is used by a later change related to pickle and handling __main__.
2025-04-28 12:46:22 -06:00
Victor Stinner
20c5f969dd
gh-131238: Remove more includes from pycore_interp.h (#131480) 2025-03-19 23:01:32 +01:00
Mark Shannon
a45f25361d
GH-131238: More refactoring of core header files (GH-131351)
Adds new pycore_stats.h header file to help break dependencies involving the pycore_code.h header.
2025-03-17 14:41:05 +00:00
Victor Stinner
9a63138e09
gh-111178: Fix function signatures in misc files (#131180) 2025-03-13 16:55:08 +01:00
Serhiy Storchaka
0ef4ffeefd
gh-130163: Fix crashes related to PySys_GetObject() (GH-130503)
The use of PySys_GetObject() and _PySys_GetAttr(), which return a borrowed
reference, has been replaced by using one of the following functions, which
return a strong reference and distinguish a missing attribute from an error:
_PySys_GetOptionalAttr(), _PySys_GetOptionalAttrString(),
_PySys_GetRequiredAttr(), and _PySys_GetRequiredAttrString().
2025-02-25 23:04:27 +02:00
Sam Gross
ca22147547
gh-111924: Fix data races when swapping allocators (gh-130287)
CPython current temporarily changes `PYMEM_DOMAIN_RAW` to the default
allocator during initialization and shutdown. The motivation is to
ensure that core runtime structures are allocated and freed using the
same allocator. However, modifying the current allocator changes global
state and is not thread-safe even with the GIL. Other threads may be
allocating or freeing objects use PYMEM_DOMAIN_RAW; they are not
required to hold the GIL to call PyMem_RawMalloc/PyMem_RawFree.

This adds new internal-only functions like `_PyMem_DefaultRawMalloc`
that aren't affected by calls to `PyMem_SetAllocator()`, so they're
appropriate for Python runtime initialization and finalization. Use
these calls in places where we previously swapped to the default raw
allocator.
2025-02-20 11:31:15 -05:00
Victor Stinner
95504f429e
gh-129354: Fix grammar in PyErr_FormatUnraisable() (#129475)
Replace "on verb+ing" with "while verb+ing".
2025-01-31 09:45:35 +01:00