summaryrefslogtreecommitdiffstats
path: root/Python/importdl.c
Commit message (Collapse)AuthorAgeFilesLines
* gh-117953: Imply Single-phase Init if the Init Function Fails (gh-118684)Eric Snow2024-05-071-0/+7
| | | This ensures the kind is always either _Py_ext_module_kind_SINGLEPHASE or _Py_ext_module_kind_MULTIPHASE.
* gh-117953: Track Extra Details in Global Extensions Cache (gh-118532)Eric Snow2024-05-041-3/+21
| | | | | | | | | | | | We have only been tracking each module's PyModuleDef. However, there are some problems with that. For example, in some cases we load single-phase init extension modules from def->m_base.m_init or def->m_base.m_copy, but if multiple modules share a def then we can end up with unexpected behavior. With this change, we track the following: * PyModuleDef (same as before) * for some modules, its init function or a copy of its __dict__, but specific to that module * whether it is a builtin/core module or a "dynamic" extension * the interpreter (ID) that owns the cached __dict__ (only if cached) This also makes it easier to remember the module's kind (e.g. single-phase init) and if loading it previously failed, which I'm doing separately.
* gh-117953: Work Relative to Specific Extension Kinds in the Import Machinery ↵Eric Snow2024-05-011-28/+179
| | | | | (gh-118205) This change will make some later changes simpler.
* gh-117953: Share More Machinery Code Between Builtin and Dynamic Extensions ↵Eric Snow2024-04-291-3/+35
| | | | | (gh-118204) This change will make some later changes simpler. It also brings more consistent behavior and lower maintenance costs.
* gh-117953: Split Up _PyImport_LoadDynamicModuleWithSpec() (gh-118203)Eric Snow2024-04-291-46/+55
| | | | | | | Basically, I've turned most of _PyImport_LoadDynamicModuleWithSpec() into two new functions (_PyImport_GetModInitFunc() and _PyImport_RunModInitFunc()) and moved the rest of it out into _imp_create_dynamic_impl(). There shouldn't be any changes in behavior. This change makes some future changes simpler. This is particularly relevant to potentially calling each module init function in the main interpreter first. Thus the critical part of the PR is the addition of _PyImport_RunModInitFunc(), which is strictly focused on running the init func and validating the result. A later PR will take it a step farther by capturing error information rather than raising exceptions. FWIW, this change also helps readers by clarifying a bit more about what happens when an extension/builtin module is imported.
* gh-117953: Fix Refleaks Introduced by gh-118194 (gh-118250)Eric Snow2024-04-241-1/+5
| | | | | A couple of refleaks slipped through in gh-118194. This takes care of them. (AKA _Py_ext_module_loader_info_init() does not steal references.)
* gh-117953: Add Internal struct _Py_ext_module_loader_info (gh-118194)Eric Snow2024-04-241-53/+97
| | | This helps with a later change that splits up _PyImport_LoadDynamicModuleWithSpec().
* gh-117953: Cleanups For fix_up_extension() in import.c (gh-118192)Eric Snow2024-04-241-0/+5
| | | These are cleanups I've pulled out of gh-118116. Mostly, this change moves code around to align with some future changes and to improve clarity a little. There is one very small change in behavior: we now add the module to the per-interpreter caches after updating the global state, rather than before.
* gh-117953: Small Cleanup of Extensions-Related Machinery Code (gh-118167)Eric Snow2024-04-231-26/+19
| | | This is a collection of very basic cleanups I've pulled out of gh-118116. It is mostly renaming variables and moving a couple bits of code in functionally equivalent ways.
* gh-88402: Add new sysconfig variables on Windows (GH-110049)Sam Gross2023-10-041-1/+1
| | | | Co-authored-by: Filipe Laíns <filipe.lains@gmail.com>
* gh-106320: Remove private _PyErr C API functions (#106356)Victor Stinner2023-07-031-0/+1
| | | | Remove private _PyErr C API functions: move them to the internal C API (pycore_pyerrors.h).
* gh-106210 Remove Emscripten import trampoline (#106211)Hood Chatham2023-06-301-1/+1
| | | | | It's no longer necessary. Co-authored-by: Brett Cannon <brett@python.org>
* gh-98627: Add an Optional Check for Extension Module Subinterpreter ↵Eric Snow2023-02-161-0/+5
| | | | | | | | | | | | | | | Compatibility (gh-99040) Enforcing (optionally) the restriction set by PEP 489 makes sense. Furthermore, this sets the stage for a potential restriction related to a per-interpreter GIL. This change includes the following: * add tests for extension module subinterpreter compatibility * add _PyInterpreterConfig.check_multi_interp_extensions * add Py_RTFLAGS_MULTI_INTERP_EXTENSIONS * add _PyImport_CheckSubinterpIncompatibleExtensionAllowed() * fail iff the module does not implement multi-phase init and the current interpreter is configured to check https://github.com/python/cpython/issues/98627
* gh-101758: Clean Up Uses of Import State (gh-101919)Eric Snow2023-02-151-10/+7
| | | | | | | | | | | | | | | This change is almost entirely moving code around and hiding import state behind internal API. We introduce no changes to behavior, nor to non-internal API. (Since there was already going to be a lot of churn, I took this as an opportunity to re-organize import.c into topically-grouped sections of code.) The motivation is to simplify a number of upcoming changes. Specific changes: * move existing import-related code to import.c, wherever possible * add internal API for interacting with import state (both global and per-interpreter) * use only API outside of import.c (to limit churn there when changing the location, etc.) * consolidate the import-related state of PyInterpreterState into a single struct field (this changes layout slightly) * add macros for import state in import.c (to simplify changing the location) * group code in import.c into sections *remove _PyState_AddModule() https://github.com/python/cpython/issues/101758
* gh-99947: Ensure unreported errors are chained for SystemError during import ↵Sebastian Berg2022-12-231-2/+1
| | | | (GH-99946)
* gh-81057: Move More Globals in Core Code to _PyRuntimeState (gh-99516)Eric Snow2022-11-161-0/+2
| | | https://github.com/python/cpython/issues/81057
* bpo-47162: Add call trampoline to mitigate bad fpcasts on Emscripten (GH-32189)Christian Heimes2022-03-301-3/+3
|
* bpo-46541: Replace core use of _Py_IDENTIFIER() with statically initialized ↵Eric Snow2022-02-081-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | global objects. (gh-30928) We're no longer using _Py_IDENTIFIER() (or _Py_static_string()) in any core CPython code. It is still used in a number of non-builtin stdlib modules. The replacement is: PyUnicodeObject (not pointer) fields under _PyRuntimeState, statically initialized as part of _PyRuntime. A new _Py_GET_GLOBAL_IDENTIFIER() macro facilitates lookup of the fields (along with _Py_GET_GLOBAL_STRING() for non-identifier strings). https://bugs.python.org/issue46541#msg411799 explains the rationale for this change. The core of the change is in: * (new) Include/internal/pycore_global_strings.h - the declarations for the global strings, along with the macros * Include/internal/pycore_runtime_init.h - added the static initializers for the global strings * Include/internal/pycore_global_objects.h - where the struct in pycore_global_strings.h is hooked into _PyRuntimeState * Tools/scripts/generate_global_objects.py - added generation of the global string declarations and static initializers I've also added a --check flag to generate_global_objects.py (along with make check-global-objects) to check for unused global strings. That check is added to the PR CI config. The remainder of this change updates the core code to use _Py_GET_GLOBAL_IDENTIFIER() instead of _Py_IDENTIFIER() and the related _Py*Id functions (likewise for _Py_GET_GLOBAL_STRING() instead of _Py_static_string()). This includes adding a few functions where there wasn't already an alternative to _Py*Id(), replacing the _Py_Identifier * parameter with PyObject *. The following are not changed (yet): * stop using _Py_IDENTIFIER() in the stdlib modules * (maybe) get rid of _Py_IDENTIFIER(), etc. entirely -- this may not be doable as at least one package on PyPI using this (private) API * (maybe) intern the strings during runtime init https://bugs.python.org/issue46541
* Fix format string in _PyImport_LoadDynamicModuleWithSpec() (GH-28863)Serhiy Storchaka2021-10-121-1/+1
|
* Handle error when PyUnicode_GetLength returns a negative value. (GH-28859)Dong-hee Na2021-10-111-0/+3
|
* Fix a leak in _PyImport_LoadDynamicModuleWithSpec() after failing ↵Serhiy Storchaka2021-10-111-1/+1
| | | | PySys_Audit() (GH-28862)
* bpo-1635741: Fix ref leak in _PyWarnings_Init() error path (GH-23151)Victor Stinner2020-11-041-3/+2
| | | | | | Replace PyModule_AddObject() with PyModule_AddObjectRef() in the _warnings module to fix a reference leak on error. Use also PyModule_AddObjectRef() in importdl.c.
* bpo-39573: Finish converting to new Py_IS_TYPE() macro (GH-18601)Andy Lester2020-03-041-1/+1
|
* bpo-36842: Implement PEP 578 (GH-12613)Steve Dower2019-05-231-0/+5
| | | Adds sys.audit, sys.addaudithook, io.open_code, and associated C APIs.
* bpo-31315: Fix an assertion failure in imp.create_dynamic(), when spec.name ↵Oren Milman2017-09-191-0/+5
| | | | is not a string. (#3257)
* bpo-28411: Isolate PyInterpreterState.modules (#3575)Eric Snow2017-09-141-1/+2
| | | | | A bunch of code currently uses PyInterpreterState.modules directly instead of PyImport_GetModuleDict(). This complicates efforts to make changes relative to sys.modules. This patch switches to using PyImport_GetModuleDict() uniformly. Also, a number of related uses of sys.modules are updated for uniformity for the same reason. Note that this code was already reviewed and merged as part of #1638. I reverted that and am now splitting it up into more focused parts.
* bpo-31404: Revert "remove modules from Py_InterpreterState (#1638)" (#3565)Eric Snow2017-09-141-2/+1
| | | PR #1638, for bpo-28411, causes problems in some (very) edge cases. Until that gets sorted out, we're reverting the merge. PR #3506, a fix on top of #1638, is also getting reverted.
* bpo-28411: Remove "modules" field from Py_InterpreterState. (#1638)Eric Snow2017-09-041-1/+2
| | | sys.modules is the one true source.
* Issue #28748: Private variable _Py_PackageContext is now of type "const char *"Serhiy Storchaka2016-11-211-1/+1
| | | | rather of "char *".
* Issue #28715: Added error checks for PyUnicode_AsUTF8().Serhiy Storchaka2016-11-201-0/+4
|\
| * Issue #28715: Added error checks for PyUnicode_AsUTF8().Serhiy Storchaka2016-11-201-0/+4
| |
* | Issue #25923: Added the const qualifier to static constant arrays.Serhiy Storchaka2015-12-251-2/+2
|/
* fix importing one char extension modules (closes #24328)Benjamin Peterson2015-05-291-10/+9
|
* Issue #24285: fix importing extensions from packagesNick Coghlan2015-05-261-1/+1
|
* PEP 489: Multi-phase extension module initializationNick Coghlan2015-05-231-61/+166
| | | | | | | | | | | | | | | | | | | | | | | Known limitations of the current implementation: - documentation changes are incomplete - there's a reference leak I haven't tracked down yet The leak is most visible by running: ./python -m test -R3:3 test_importlib However, you can also see it by running: ./python -X showrefcount Importing the array or _testmultiphase modules, and then deleting them from both sys.modules and the local namespace shows significant increases in the total number of active references each cycle. By contrast, with _testcapi (which continues to use single-phase initialisation) the global refcounts stabilise after a couple of cycles.
* Issue #18408: Fix _PyImport_LoadDynamicModule(), handle ↵Victor Stinner2013-07-171-0/+2
| | | | PyUnicode_FromFormat() failure
* Issue #18426: improve exception message. Courtesy of AmauryChristian Heimes2013-07-111-1/+5
|
* Issue #18426: Fix NULL pointer dereference in C extension import whenChristian Heimes2013-07-111-0/+2
| | | | PyModule_GetDef() returns an error.
* Issue #14599: Generalize a test for ImportError.path and add supportBrett Cannon2012-04-201-4/+5
| | | | | | | in Python/dynload_shlibs.c. This should fix the remaining importlib test failure on Windows. Support in AIX and HP-UX will be in a separate checkin.
* Issue #2377: Make importlib the implementation of __import__().Brett Cannon2012-04-141-4/+0
| | | | | | | importlib._bootstrap is now frozen into Python/importlib.h and stored as _frozen_importlib in sys.modules. Py_Initialize() loads the frozen code along with sys and imp and then uses _frozen_importlib._install() to set builtins.__import__() w/ _frozen_importlib.__import__().
* _PyImport_LoadDynamicModule() encodes the module name explicitly to ASCIIVictor Stinner2011-05-071-15/+25
| | | | | | The name must be encodable to ASCII because dynamic module must have a function called "PyInit_NAME", they are written in C, and the C language doesn't accept non-ASCII identifiers.
* Issue #11619: _PyImport_LoadDynamicModule() doesn't encode the path to bytesVictor Stinner2011-04-041-0/+11
| | | | on Windows.
* Issue #3080: _PyImport_LoadDynamicModule() uses Unicode for name and pathVictor Stinner2011-03-141-41/+29
| | | | Document also that dynamic module names are ASCII only
* Issue #3080: Import builtins using Unicode stringsVictor Stinner2011-03-071-6/+18
| | | | | | | - is_builtin(), init_builtin(), load_builtin() and other builtin related functions use Unicode strings, instead of byte strings - Rename _PyImport_FixupExtensionUnicode() to _PyImport_FixupExtensionObject() - Rename _PyImport_FindExtensionUnicode() to _PyImport_FindExtensionObject()
* Issue #3080: Remove unused argument of _PyImport_GetDynLoadFunc()Victor Stinner2011-02-221-3/+2
| | | | The first argument, fqname, was not used.
* _PyImport_FixupExtension() and _PyImport_FindExtension() uses FS encodingVictor Stinner2010-10-171-10/+24
| | | | | | | * Rename _PyImport_FindExtension() to _PyImport_FindExtensionUnicode(): the filename becomes a Unicode object instead of byte string * Rename _PyImport_FixupExtension() to _PyImport_FixupExtensionUnicode(): the filename becomes a Unicode object instead of byte string
* Recorded merge of revisions 81029 via svnmerge fromAntoine Pitrou2010-05-091-58/+58
| | | | | | | | | | svn+ssh://pythondev@svn.python.org/python/trunk ........ r81029 | antoine.pitrou | 2010-05-09 16:46:46 +0200 (dim., 09 mai 2010) | 3 lines Untabify C files. Will watch buildbots. ........
* Implement PEP 3121: new module initialization and finalization API.Martin v. Löwis2008-06-111-11/+19
|
* Move decl so it compiles with C89.Neal Norwitz2007-10-151-1/+1
|
* Patch #1272, by Christian Heimes and Alexandre Vassalotti.Guido van Rossum2007-10-151-1/+3
| | | | | | | | | | Changes to make __file__ a proper Unicode object, using the default filesystem encoding. This is a bit tricky because the default filesystem encoding isn't set by the time we import the first modules; at that point we fudge things a bit. This is okay since __file__ isn't really used much except for error reporting. Tested on OSX and Linux only so far.