summaryrefslogtreecommitdiffstats
path: root/Python/import.c
Commit message (Collapse)AuthorAgeFilesLines
* bpo-39882: Py_FatalError() logs the function name (GH-18819)Victor Stinner2020-03-061-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.
* bpo-39245: Switch to public API for Vectorcall (GH-18460)Petr Viktorin2020-02-111-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
* bpo-38076 Clear the interpreter state only after clearing module globals ↵Eddie Elizondo2020-02-041-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
* bpo-39487: Merge duplicated _Py_IDENTIFIER identifiers in C code (GH-18254)Hai Shi2020-01-301-4/+3
| | | Moving repetitive `_Py_IDENTIFIER` instances to a global location helps identify them more easily in regards to sub-interpreter support.
* bpo-38960: DTrace build fix for FreeBSD. (GH-17451)David Carlier2020-01-281-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.
* bpo-38858: new_interpreter() reuses pycore_init_builtins() (GH-17351)Victor Stinner2019-11-221-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.
* bpo-38858: _PyImport_FixupExtensionObject() handles subinterpreters (GH-17350)Victor Stinner2019-11-221-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.
* bpo-36854: gcmodule.c gets its state from tstate (GH-17285)Victor Stinner2019-11-201-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
* bpo-38353: Cleanup includes in the internal C API (GH-16548)Victor Stinner2019-10-021-0/+1
| | | | Use forward declaration of types to avoid includes in the internal C API. Add also comment to justify other includes.
* bpo-35943: Prevent PyImport_GetModule() from returning a ↵Joannah Nanjekye2019-09-111-23/+46
| | | | partially-initialized module (GH-15057)
* bpo-37409: fix relative import with no parent (#14956)Ben Lewis2019-09-111-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.
* bpo-37444: Update differing exception between builtins and importlib (GH-14869)Ngalim Siregar2019-08-031-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
* Fix typos in comments, docs and test names (#15018)Min ho Kim2019-07-301-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.
* bpo-37547: add _PyObject_CallMethodOneArg (GH-14685)Jeroen Demeyer2019-07-111-7/+5
|
* bpo-37337: Add _PyObject_CallMethodNoArgs() (GH-14267)Jeroen Demeyer2019-07-081-1/+1
|
* bpo-37483: add _PyObject_CallOneArg() function (#14558)Jeroen Demeyer2019-07-041-1/+1
|
* bpo-36710: Use tstate in pylifecycle.c (GH-14249)Victor Stinner2019-06-191-4/+5
| | | | In pylifecycle.c: pass tstate argument, rather than interp argument, to functions.
* bpo-36710: Remove PyImport_Cleanup() function (GH-14221)Victor Stinner2019-06-191-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.".
* bpo-36710: Add tstate parameter in import.c (GH-14218)Victor Stinner2019-06-191-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.
* Revert "bpo-36818: Add PyInterpreterState.runtime field. (gh-13129)" (GH-13795)Victor Stinner2019-06-041-2/+1
| | | This reverts commit 396e0a8d9dc65453cb9d53500d0a620602656cfe.
* bpo-36818: Add PyInterpreterState.runtime field. (gh-13129)Eric Snow2019-06-011-1/+2
| | | https://bugs.python.org/issue36818
* bpo-20602: Do not clear sys.flags and sys.float_info during shutdown (GH-8096)Zackery Spytz2019-05-301-2/+0
| | | There is no need to clear these immutable objects during shutdown.
* bpo-36763: Implement the PEP 587 (GH-13592)Victor Stinner2019-05-271-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()
* bpo-36842: Implement PEP 578 (GH-12613)Steve Dower2019-05-231-0/+11
| | | Adds sys.audit, sys.addaudithook, io.open_code, and associated C APIs.
* bpo-36900: import.c uses PyInterpreterState.core_config (GH-13278)Victor Stinner2019-05-131-26/+45
| | | | Move _PyImportZip_Init() to the internal C API and add an 'interp' parameter.
* bpo-24048: Save the live exception during import.c's remove_module() (GH-13005)Zackery Spytz2019-05-081-3/+7
| | | Save the live exception during the course of remove_module().
* bpo-36763: Make _PyCoreConfig.check_hash_pycs_mode public (GH-13052)Victor Stinner2019-05-021-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*".
* bpo-36710: Add runtime parameter in gcmodule.c (GH-12958)Victor Stinner2019-04-261-1/+1
| | | | Add 'state' or 'runtime' parameter to functions in gcmodule.c to avoid to rely directly on the global variable _PyRuntime.
* bpo-36370: Check for PyErr_Occurred() after PyImport_GetModule() (GH-12504)Stefan Krah2019-03-251-5/+14
|
* bpo-36362: Avoid unused variables when HAVE_DYNAMIC_LOADING is not defined ↵Stéphane Wirtel2019-03-191-2/+3
| | | | | (GH-12430) https://bugs.python.org/issue36362
* bpo-35459: Use PyDict_GetItemWithError() instead of PyDict_GetItem(). (GH-11112)Serhiy Storchaka2019-02-251-14/+29
|
* bpo-35470: Fix a reference counting bug in ↵Zackery Spytz2019-01-101-1/+0
| | | | _PyImport_FindExtensionObjectEx(). (GH-11128)
* bpo-35454: Fix miscellaneous minor issues in error handling. (#11077)Serhiy Storchaka2018-12-111-2/+2
| | | | | | * bpo-35454: Fix miscellaneous minor issues in error handling. * Fix a null pointer dereference.
* bpo-35177, Python-ast.h: Fix "Yield" compiler warning (GH-10664)Victor Stinner2018-11-221-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
* bpo-35081: Rename internal headers (GH-10275)Victor Stinner2018-11-121-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
* bpo-35177: Add dependencies between header files (GH-10361)Victor Stinner2018-11-111-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
* bpo-35133: Fix mistakes when concatenate string literals on different lines. ↵Serhiy Storchaka2018-11-051-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.
* bpo-35081: And pycore_lifecycle.h and pycore_pathconfig.h (GH-10273)Victor Stinner2018-11-011-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.
* bpo-35081: Add pycore_ prefix to internal header files (GH-10263)Victor Stinner2018-10-311-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".
* bpo-35081: Move Py_BUILD_CORE code to internal/mem.h (GH-10249)Victor Stinner2018-10-311-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.
* bpo-33237: Improve AttributeError message for partially initialized module. ↵Serhiy Storchaka2018-10-301-21/+9
| | | | (GH-6398)
* bpo-33331: Clean modules in the reversed order in PyImport_Cleanup(). (GH-6565)Serhiy Storchaka2018-10-291-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.
* closes bpo-34646: Remove PyAPI_* macros from declarations. (GH-9218)Benjamin Peterson2018-09-121-1/+1
|
* bpo-34301: Add _PyInterpreterState_Get() helper function (GH-8592)Victor Stinner2018-08-031-8/+8
| | | | sys_setcheckinterval() now uses a local variable to parse arguments, before writing into interp->check_interval.
* bpo-31650: Remove _Py_CheckHashBasedPycsMode global config var (GH-8608)Victor Stinner2018-08-011-2/+2
| | | | | | | | bpo-31650, bpo-34170: Replace _Py_CheckHashBasedPycsMode with _PyCoreConfig._check_hash_pycs_mode. Modify PyInit__imp() and zipimport to get the parameter from the current interpreter core configuration. Remove Include/internal/import.h file.
* bpo-34170: Add Python/coreconfig.c for _PyCoreConfig (GH-8607)Victor Stinner2018-08-011-2/+0
| | | | | | | * Add Include/coreconfig.h * Move config_*() and _PyCoreConfig_*() functions from Modules/main.c to a new Python/coreconfig.c file. * Inline _Py_ReadHashSeed() into config_init_hash_seed() * Move global configuration variables to coreconfig.c
* bpo-33443 Fix typo in Python/import.c (GH-6722)ukwksk2018-05-141-5/+5
|
* bpo-33330: Write exceptions occurred in PyImport_Cleanup() to stderr. (GH-6606)Serhiy Storchaka2018-04-291-16/+20
| | | | They where silenced before.
* bpo-33330: Improve error handling in PyImport_Cleanup(). (GH-6564)Serhiy Storchaka2018-04-251-9/+24
|
* bpo-32946: Speed up "from ... import ..." from non-packages. (GH-5873)Serhiy Storchaka2018-03-111-4/+15
|