summaryrefslogtreecommitdiff
path: root/Python/import.c
AgeCommit message (Collapse)AuthorLines
2020-04-14bpo-40268: Include explicitly pycore_interp.h (GH-19505)Victor Stinner-0/+1
pycore_pystate.h no longer includes pycore_interp.h: it's now included explicitly in files accessing PyInterpreterState.
2020-04-13bpo-40268: Add _PyInterpreterState_GetConfig() (GH-19492)Victor Stinner-6/+6
Don't access PyInterpreterState.config member directly anymore, but use new functions: * _PyInterpreterState_GetConfig() * _PyInterpreterState_SetConfig() * _Py_GetConfig()
2020-03-30bpo-39943: Remove unnecessary casts in import.c that remove constness (GH-19209)Andy Lester-2/+2
2020-03-27bpo-38644: Use _PySys_Audit(): pass tstate explicitly (GH-19183)Victor Stinner-4/+5
Add the dependency to tstate more explicit.
2020-03-25bpo-39882: Add _Py_FatalErrorFormat() function (GH-19157)Victor Stinner-3/+3
2020-03-13bpo-39947: Use _PyInterpreterState_GET_UNSAFE() (GH-18978)Victor Stinner-2/+2
Replace _PyInterpreterState_Get() function call with _PyInterpreterState_GET_UNSAFE() macro which is more efficient but don't check if tstate or interp is NULL. _Py_GetConfigsAsDict() now uses _PyThreadState_GET().
2020-03-07bpo-39882: Py_FatalError() logs the function name (GH-18819)Victor Stinner-3/+2
The Py_FatalError() function is replaced with a macro which logs automatically the name of the current function, unless the Py_LIMITED_API macro is defined. Changes: * Add _Py_FatalErrorFunc() function. * Remove the function name from the message of Py_FatalError() calls which included the function name. * Update tests.
2020-02-11bpo-39245: Switch to public API for Vectorcall (GH-18460)Petr Viktorin-1/+1
The bulk of this patch was generated automatically with: for name in \ PyObject_Vectorcall \ Py_TPFLAGS_HAVE_VECTORCALL \ PyObject_VectorcallMethod \ PyVectorcall_Function \ PyObject_CallOneArg \ PyObject_CallMethodNoArgs \ PyObject_CallMethodOneArg \ ; do echo $name git grep -lwz _$name | xargs -0 sed -i "s/\b_$name\b/$name/g" done old=_PyObject_FastCallDict new=PyObject_VectorcallDict git grep -lwz $old | xargs -0 sed -i "s/\b$old\b/$new/g" and then cleaned up: - Revert changes to in docs & news - Revert changes to backcompat defines in headers - Nudge misaligned comments
2020-02-04bpo-38076 Clear the interpreter state only after clearing module globals ↵Eddie Elizondo-2/+3
(GH-18039) Currently, during runtime destruction, `_PyImport_Cleanup` is clearing the interpreter state before clearing out the modules themselves. This leads to a segfault on modules that rely on the module state to clear themselves up. For example, let's take the small snippet added in the issue by @DinoV : ``` import _struct class C: def __init__(self): self.pack = _struct.pack def __del__(self): self.pack('I', -42) _struct.x = C() ``` The module `_struct` uses the module state to run `pack`. Therefore, the module state has to be alive until after the module has been cleared out to successfully run `C.__del__`. This happens at line 606, when `_PyImport_Cleanup` calls `_PyModule_Clear`. In fact, the loop that calls `_PyModule_Clear` has in its comments: > Now, if there are any modules left alive, clear their globals to minimize potential leaks. All C extension modules actually end up here, since they are kept alive in the interpreter state. That means that we can't clear the module state (which is used by C Extensions) before we run that loop. Moving `_PyInterpreterState_ClearModules` until after it, fixes the segfault in the code snippet. Finally, this updates a test in `io` to correctly assert the error that it now throws (since it now finds the io module state). The test that uses this is: `test_create_at_shutdown_without_encoding`. Given this test is now working is a proof that the module state now stays alive even when `__del__` is called at module destruction time. Thus, I didn't add a new tests for this. https://bugs.python.org/issue38076
2020-01-30bpo-39487: Merge duplicated _Py_IDENTIFIER identifiers in C code (GH-18254)Hai Shi-4/+3
Moving repetitive `_Py_IDENTIFIER` instances to a global location helps identify them more easily in regards to sub-interpreter support.
2020-01-28bpo-38960: DTrace build fix for FreeBSD. (GH-17451)David Carlier-2/+2
DTrace build fix for FreeBSD. - allowing passing an extra flag as it need to define the arch size. - casting some probe's arguments.
2019-11-22bpo-38858: new_interpreter() reuses pycore_init_builtins() (GH-17351)Victor Stinner-11/+0
new_interpreter() now calls _PyBuiltin_Init() to create the builtins module and calls _PyImport_FixupBuiltin(), rather than using _PyImport_FindBuiltin(tstate, "builtins"). pycore_init_builtins() is now responsible to initialize intepr->builtins_copy: inline _PyImport_Init() and remove this function.
2019-11-22bpo-38858: _PyImport_FixupExtensionObject() handles subinterpreters (GH-17350)Victor Stinner-29/+41
If _PyImport_FixupExtensionObject() is called from a subinterpreter, leave extensions unchanged and don't copy the module dictionary into def->m_base.m_copy.
2019-11-20bpo-36854: gcmodule.c gets its state from tstate (GH-17285)Victor Stinner-1/+1
* Add GCState type for readability * gcmodule.c now gets its gcstate from tstate * _PyGC_DumpShutdownStats() now expects tstate rather than runtime * Rename "state" to "gcstate" for readability: to avoid confusion between "state" and "tstate" for example. * collect() now only expects tstate: it gets gcstate from tstate. * Pass tstate to _PyErr_xxx() functions
2019-10-02bpo-38353: Cleanup includes in the internal C API (GH-16548)Victor Stinner-0/+1
Use forward declaration of types to avoid includes in the internal C API. Add also comment to justify other includes.
2019-09-11bpo-35943: Prevent PyImport_GetModule() from returning a ↵Joannah Nanjekye-23/+46
partially-initialized module (GH-15057)
2019-09-11bpo-37409: fix relative import with no parent (#14956)Ben Lewis-11/+13
Relative imports use resolve_name to get the absolute target name, which first seeks the current module's absolute package name from the globals: If __package__ (and __spec__.parent) are missing then import uses __name__, truncating the last segment if the module is a submodule rather than a package __init__.py (which it guesses from whether __path__ is defined). The __name__ attempt should fail if there is no parent package (top level modules), if __name__ is '__main__' (-m entry points), or both (scripts). That is, if both __name__ has no subcomponents and the module does not seem to be a package __init__ module then import should fail.
2019-08-02bpo-37444: Update differing exception between builtins and importlib (GH-14869)Ngalim Siregar-1/+1
Imports now raise `TypeError` instead of `ValueError` for relative import failures. This makes things consistent between `builtins.__import__` and `importlib.__import__` as well as using a more natural import for the failure. https://bugs.python.org/issue37444 Automerge-Triggered-By: @brettcannon
2019-07-30Fix typos in comments, docs and test names (#15018)Min ho Kim-1/+1
* Fix typos in comments, docs and test names * Update test_pyparse.py account for change in string length * Apply suggestion: splitable -> splittable Co-Authored-By: Terry Jan Reedy <tjreedy@udel.edu> * Apply suggestion: splitable -> splittable Co-Authored-By: Terry Jan Reedy <tjreedy@udel.edu> * Apply suggestion: Dealloccte -> Deallocate Co-Authored-By: Terry Jan Reedy <tjreedy@udel.edu> * Update posixmodule checksum. * Reverse idlelib changes.
2019-07-11bpo-37547: add _PyObject_CallMethodOneArg (GH-14685)Jeroen Demeyer-7/+5
2019-07-08bpo-37337: Add _PyObject_CallMethodNoArgs() (GH-14267)Jeroen Demeyer-1/+1
2019-07-04bpo-37483: add _PyObject_CallOneArg() function (#14558)Jeroen Demeyer-1/+1
2019-06-20bpo-36710: Use tstate in pylifecycle.c (GH-14249)Victor Stinner-4/+5
In pylifecycle.c: pass tstate argument, rather than interp argument, to functions.
2019-06-19bpo-36710: Remove PyImport_Cleanup() function (GH-14221)Victor Stinner-2/+1
* Rename PyImport_Cleanup() to _PyImport_Cleanup() and move it to the internal C API. Add 'tstate' parameters. * Remove documentation of _PyImport_Init(), PyImport_Cleanup(), _PyImport_Fini(). All three were documented as "For internal use only.".
2019-06-19bpo-36710: Add tstate parameter in import.c (GH-14218)Victor Stinner-155/+207
* Add 'tstate' parameter to many internal import.c functions. * _PyImportZip_Init() now gets 'tstate' parameter rather than 'interp'. * Add 'interp' parameter to _PyState_ClearModules() and rename it to _PyInterpreterState_ClearModules(). * Move private _PyImport_FindBuiltin() to the internal C API; add 'tstate' parameter to it. * Remove private _PyImport_AddModuleObject() from the C API: use public PyImport_AddModuleObject() instead. * Remove private _PyImport_FindExtensionObjectEx() from the C API: use private _PyImport_FindExtensionObject() instead.
2019-06-04Revert "bpo-36818: Add PyInterpreterState.runtime field. (gh-13129)" (GH-13795)Victor Stinner-2/+1
This reverts commit 396e0a8d9dc65453cb9d53500d0a620602656cfe.
2019-05-31bpo-36818: Add PyInterpreterState.runtime field. (gh-13129)Eric Snow-1/+2
https://bugs.python.org/issue36818
2019-05-30bpo-20602: Do not clear sys.flags and sys.float_info during shutdown (GH-8096)Zackery Spytz-2/+0
There is no need to clear these immutable objects during shutdown.
2019-05-27bpo-36763: Implement the PEP 587 (GH-13592)Victor Stinner-15/+15
* Add a whole new documentation page: "Python Initialization Configuration" * PyWideStringList_Append() return type is now PyStatus, instead of int * PyInterpreterState_New() now calls PyConfig_Clear() if PyConfig_InitPythonConfig() fails. * Rename files: * Python/coreconfig.c => Python/initconfig.c * Include/cpython/coreconfig.h => Include/cpython/initconfig.h * Include/internal/: pycore_coreconfig.h => pycore_initconfig.h * Rename structures * _PyCoreConfig => PyConfig * _PyPreConfig => PyPreConfig * _PyInitError => PyStatus * _PyWstrList => PyWideStringList * Rename PyConfig fields: * use_module_search_paths => module_search_paths_set * module_search_path_env => pythonpath_env * Rename PyStatus field: _func => func * PyInterpreterState: rename core_config field to config * Rename macros and functions: * _PyCoreConfig_SetArgv() => PyConfig_SetBytesArgv() * _PyCoreConfig_SetWideArgv() => PyConfig_SetArgv() * _PyCoreConfig_DecodeLocale() => PyConfig_SetBytesString() * _PyInitError_Failed() => PyStatus_Exception() * _Py_INIT_ERROR_TYPE_xxx enums => _PyStatus_TYPE_xxx * _Py_UnixMain() => Py_BytesMain() * _Py_ExitInitError() => Py_ExitStatusException() * _Py_PreInitializeFromArgs() => Py_PreInitializeFromBytesArgs() * _Py_PreInitializeFromWideArgs() => Py_PreInitializeFromArgs() * _Py_PreInitialize() => Py_PreInitialize() * _Py_RunMain() => Py_RunMain() * _Py_InitializeFromConfig() => Py_InitializeFromConfig() * _Py_INIT_XXX() => _PyStatus_XXX() * _Py_INIT_FAILED() => _PyStatus_EXCEPTION() * Rename 'err' PyStatus variables to 'status' * Convert RUN_CODE() macro to config_run_code() static inline function * Remove functions: * _Py_InitializeFromArgs() * _Py_InitializeFromWideArgs() * _PyInterpreterState_GetCoreConfig()
2019-05-23bpo-36842: Implement PEP 578 (GH-12613)Steve Dower-0/+11
Adds sys.audit, sys.addaudithook, io.open_code, and associated C APIs.
2019-05-13bpo-36900: import.c uses PyInterpreterState.core_config (GH-13278)Victor Stinner-26/+45
Move _PyImportZip_Init() to the internal C API and add an 'interp' parameter.
2019-05-08bpo-24048: Save the live exception during import.c's remove_module() (GH-13005)Zackery Spytz-3/+7
Save the live exception during the course of remove_module().
2019-05-01bpo-36763: Make _PyCoreConfig.check_hash_pycs_mode public (GH-13052)Victor Stinner-1/+1
_PyCoreConfig: Rename _check_hash_pycs_mode field to check_hash_pycs_mode (make it public) and change its type from "const char*" to "wchar_t*".
2019-04-26bpo-36710: Add runtime parameter in gcmodule.c (GH-12958)Victor Stinner-1/+1
Add 'state' or 'runtime' parameter to functions in gcmodule.c to avoid to rely directly on the global variable _PyRuntime.
2019-03-25bpo-36370: Check for PyErr_Occurred() after PyImport_GetModule() (GH-12504)Stefan Krah-5/+14
2019-03-19bpo-36362: Avoid unused variables when HAVE_DYNAMIC_LOADING is not defined ↵Stéphane Wirtel-2/+3
(GH-12430) https://bugs.python.org/issue36362
2019-02-25bpo-35459: Use PyDict_GetItemWithError() instead of PyDict_GetItem(). (GH-11112)Serhiy Storchaka-14/+29
2019-01-10bpo-35470: Fix a reference counting bug in ↵Zackery Spytz-1/+0
_PyImport_FindExtensionObjectEx(). (GH-11128)
2018-12-11bpo-35454: Fix miscellaneous minor issues in error handling. (#11077)Serhiy Storchaka-2/+2
* bpo-35454: Fix miscellaneous minor issues in error handling. * Fix a null pointer dereference.
2018-11-22bpo-35177, Python-ast.h: Fix "Yield" compiler warning (GH-10664)Victor Stinner-0/+1
Partially revert commit 5f2df88b63e50d23914e97ec778861a52abdeaad: add "#undef Yield" to .c files after including Python-ast.h. Fix the warning: winbase.h(102): warning C4005: 'Yield': macro redefinition
2018-11-12bpo-35081: Rename internal headers (GH-10275)Victor Stinner-4/+4
Rename Include/internal/ headers: * pycore_hash.h -> pycore_pyhash.h * pycore_lifecycle.h -> pycore_pylifecycle.h * pycore_mem.h -> pycore_pymem.h * pycore_state.h -> pycore_pystate.h Add missing headers to Makefile.pre.in and PCbuild: * pycore_condvar.h. * pycore_hamt.h * pycore_pyhash.h
2018-11-12bpo-35177: Add dependencies between header files (GH-10361)Victor Stinner-1/+0
* ast.h now includes Python-ast.h and node.h * parsetok.h now includes node.h and grammar.h * symtable.h now includes Python-ast.h * Modify asdl_c.py to enhance Python-ast.h: * Add #ifndef/#define Py_PYTHON_AST_H to be able to include the header twice * Add "extern { ... }" for C++ * Undefine "Yield" macro conflicting with winbase.h * Remove "#undef Yield" from C files, it's now done in Python-ast.h * Remove now useless includes in C files
2018-11-05bpo-35133: Fix mistakes when concatenate string literals on different lines. ↵Serhiy Storchaka-1/+1
(GH-10284) Two kind of mistakes: 1. Missed space. After concatenating there is no space between words. 2. Missed comma. Causes unintentional concatenating in a list of strings.
2018-11-01bpo-35081: And pycore_lifecycle.h and pycore_pathconfig.h (GH-10273)Victor Stinner-0/+1
* And pycore_lifecycle.h and pycore_pathconfig.h headers to Include/internal/ * Move Py_BUILD_CORE specific code from coreconfig.h and pylifecycle.h to pycore_pathconfig.h and pycore_lifecycle.h * Move _Py_wstrlist_XXX() definitions and _PyPathConfig code from pycore_state.h to pycore_pathconfig.h * Move "Init" and "Fini" function definitions from pylifecycle.c to pycore_lifecycle.h.
2018-11-01bpo-35081: Add pycore_ prefix to internal header files (GH-10263)Victor Stinner-3/+3
* Rename Include/internal/ header files: * pyatomic.h -> pycore_atomic.h * ceval.h -> pycore_ceval.h * condvar.h -> pycore_condvar.h * context.h -> pycore_context.h * pygetopt.h -> pycore_getopt.h * gil.h -> pycore_gil.h * hamt.h -> pycore_hamt.h * hash.h -> pycore_hash.h * mem.h -> pycore_mem.h * pystate.h -> pycore_state.h * warnings.h -> pycore_warnings.h * PCbuild project, Makefile.pre.in, Modules/Setup: add the Include/internal/ directory to the search paths of header files. * Update includes. For example, replace #include "internal/mem.h" with #include "pycore_mem.h".
2018-10-31bpo-35081: Move Py_BUILD_CORE code to internal/mem.h (GH-10249)Victor Stinner-0/+1
* Add #include "internal/mem.h" to C files using _PyMem_SetDefaultAllocator(). * Include/internal/mem.h now requires Py_BUILD_CORE to be defined.
2018-10-30bpo-33237: Improve AttributeError message for partially initialized module. ↵Serhiy Storchaka-21/+9
(GH-6398)
2018-10-29bpo-33331: Clean modules in the reversed order in PyImport_Cleanup(). (GH-6565)Serhiy Storchaka-3/+4
Modules imported last are now cleared first at interpreter shutdown. A newly imported module is moved to the end of sys.modules, behind modules on which it depends.
2018-09-12closes bpo-34646: Remove PyAPI_* macros from declarations. (GH-9218)Benjamin Peterson-1/+1
2018-08-03bpo-34301: Add _PyInterpreterState_Get() helper function (GH-8592)Victor Stinner-8/+8
sys_setcheckinterval() now uses a local variable to parse arguments, before writing into interp->check_interval.