summaryrefslogtreecommitdiff
path: root/Python/import.c
AgeCommit message (Collapse)AuthorLines
2018-12-10bpo-35454: Fix miscellaneous minor issues in error handling. (GH-11077)Miss Islington (bot)-2/+2
* bpo-35454: Fix miscellaneous minor issues in error handling. * Fix a null pointer dereference. (cherry picked from commit 8905fcc85a6fc3ac394bc89b0bbf40897e9497a6) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2018-11-05bpo-35133: Fix mistakes when concatenate string literals on different lines. ↵Miss Islington (bot)-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. (cherry picked from commit 34fd4c20198dea6ab2fe8dc6d32d744d9bde868d) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2018-04-25bpo-33330: Improve error handling in PyImport_Cleanup(). (GH-6564)Miss Islington (bot)-9/+24
(cherry picked from commit e9d9494d6b2a5e0c2d48d22c7f0d5e95504b4f7e) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2018-01-29rename _imp initialization function to follow conventions (#5432)Benjamin Peterson-2/+1
When the C imp module became _imp in 6f44d66bc491bad5b8d897a68da68e009e27829d, the initialization function should have been renamed from PyInit_imp to PyInit__imp.
2017-12-15fix up signedness in PyImport_ExtendInittab (#4831)Benjamin Peterson-5/+3
As a result of 92a3c6f493ad411e4cf0acdf305ef4876aa90669, the compiler complains: Python/import.c:2311:21: warning: comparison of integers of different signs: 'long' and 'unsigned long' [-Wsign-compare] if ((i + n + 1) <= PY_SSIZE_T_MAX / sizeof(struct _inittab)) { ~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This overflow is extremely unlikely to happen, but let's avoid undefined behavior anyway.
2017-12-12import.c: Fix a GCC warning (#4822)Victor Stinner-1/+1
Fix the warning: Python/import.c: warning: comparison between signed and unsigned integer expressions if ((i + n + 1) <= PY_SSIZE_T_MAX / sizeof(struct _inittab)) {
2017-12-09fix my byte-swapping implementation (#4772)Benjamin Peterson-10/+10
2017-12-09closes bpo-31650: PEP 552 (Deterministic pycs) implementation (#4575)Benjamin Peterson-0/+42
Python now supports checking bytecode cache up-to-dateness with a hash of the source contents rather than volatile source metadata. See the PEP for details. While a fairly straightforward idea, quite a lot of code had to be modified due to the pervasiveness of pyc implementation details in the codebase. Changes in this commit include: - The core changes to importlib to understand how to read, validate, and regenerate hash-based pycs. - Support for generating hash-based pycs in py_compile and compileall. - Modifications to our siphash implementation to support passing a custom key. We then expose it to importlib through _imp. - Updates to all places in the interpreter, standard library, and tests that manually generate or parse pyc files to grok the new format. - Support in the interpreter command line code for long options like --check-hash-based-pycs. - Tests and documentation for all of the above.
2017-12-07Fix missing DECREF of mod. (#4749)Neil Schemenauer-0/+1
2017-12-06bpo-32030: Add _PyImport_Fini2() (#4737)Victor Stinner-11/+41
PyImport_ExtendInittab() now uses PyMem_RawRealloc() rather than PyMem_Realloc(). PyImport_ExtendInittab() can be called before Py_Initialize() whereas only the PyMem_Raw allocator is supposed to be used before Py_Initialize(). Add _PyImport_Fini2() to release the memory allocated by PyImport_ExtendInittab() at exit. PyImport_ExtendInittab() now forces the usage of the default raw allocator, to be able to release memory in _PyImport_Fini2(). Don't export these functions anymore to be C API, only to Py_BUILD_CORE: * _PyExc_Fini() * _PyImport_Fini() * _PyGC_DumpShutdownStats() * _PyGC_Fini() * _PyType_Fini() * _Py_HashRandomization_Fini()
2017-12-06bpo-32030: pass interp to _PyImport_Init() (#4736)Victor Stinner-9/+1
Remove also the initstr variable, unused since the commit e69f0df45b709c25ac80617c41bbae16f56870fb pushed in 2012: "bpo-13959: Re-implement imp.find_module() in Lib/imp.py"
2017-12-03Refactor PyImport_ImportModuleLevelObject(). (#4680)Neil Schemenauer-50/+57
Add import_find_and_load() helper function. The addition of the importtime option has made PyImport_ImportModuleLevelObject() large and so using a helper seems worthwhile. It also makes it clearer that abs_name is the only argument needed by _find_and_load().
2017-11-20bpo-32030: Add more options to _PyCoreConfig (#4485)Victor Stinner-4/+3
Py_Main() now handles two more -X options: * -X showrefcount: new _PyCoreConfig.show_ref_count field * -X showalloccount: new _PyCoreConfig.show_alloc_count field
2017-11-15bpo-32030: Enhance Py_Main() (#4412)Victor Stinner-25/+6
Parse more env vars in Py_Main(): * Add more options to _PyCoreConfig: * faulthandler * tracemalloc * importtime * Move code to parse environment variables from _Py_InitializeCore() to Py_Main(). This change fixes a regression from Python 3.6: PYTHONUNBUFFERED is now read before calling pymain_init_stdio(). * _PyFaulthandler_Init() and _PyTraceMalloc_Init() now take an argument to decide if the module has to be enabled at startup. * tracemalloc_start() is now responsible to check the maximum number of frames. Other changes: * Cleanup Py_Main(): * Rename some pymain_xxx() subfunctions * Add pymain_run_python() subfunction * Cleanup Py_NewInterpreter() * _PyInterpreterState_Enable() now reports failure * init_hash_secret() now considers pyurandom() failure as an "user error": don't fail with abort(). * pymain_optlist_append() and pymain_strdup() now sets err on memory allocation failure.
2017-11-15bpo-32030: Split Py_Main() into subfunctions (#4399)Victor Stinner-13/+20
* Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
2017-11-07bpo-31415: Improve error handling and caching of the importtime option. (#4138)Serhiy Storchaka-13/+20
2017-11-02bpo-31415: Support PYTHONPROFILEIMPORTTIME envvar equivalent to -X ↵Barry Warsaw-4/+11
importtime (#4240) Support PYTHONPROFILEIMPORTTIME envvar equivalent to -X importtime
2017-10-16bpo-31773: _PyTime_GetPerfCounter() uses _PyTime_t (GH-3983)Victor Stinner-6/+6
* Rewrite win_perf_counter() to only use integers internally. * Add _PyTime_MulDiv() which compute "ticks * mul / div" in two parts (int part and remaining) to prevent integer overflow. * Clock frequency is checked at initialization for integer overflow. * Enhance also pymonotonic() to reduce the precision loss on macOS (mach_absolute_time() clock).
2017-10-12bpo-31773: time.perf_counter() uses again double (GH-3964)Victor Stinner-6/+6
time.clock() and time.perf_counter() now use again C double internally. Remove also _PyTime_GetWinPerfCounterWithInfo(): use _PyTime_GetPerfCounterDoubleWithInfo() instead on Windows.
2017-10-10bpo-31415: Add _PyTime_GetPerfCounter() and use it for -X importtime (#3936)Victor Stinner-2/+2
* Add _PyTime_GetPerfCounter() * Use _PyTime_GetPerfCounter() for -X importtime
2017-10-03bpo-31415: Add `-X importtime` option (GH-3490)INADA Naoki-0/+42
It shows show import time of each module. It's useful for optimizing startup time. Typical usage: python -X importtime -c 'import requests'
2017-09-29bpo-31574: importlib dtrace (#3749)Christian Heimes-0/+10
Importlib was instrumented with two dtrace probes to profile import timing. Signed-off-by: Christian Heimes <christian@python.org>
2017-09-15bpo-28411: Support other mappings in PyInterpreterState.modules. (#3593)Eric Snow-43/+121
The concrete PyDict_* API is used to interact with PyInterpreterState.modules in a number of places. This isn't compatible with all dict subclasses, nor with other Mapping implementations. This patch switches the concrete API usage to the corresponding abstract API calls. We also add a PyImport_GetModule() function (and some other helpers) to reduce a bunch of code duplication.
2017-09-14bpo-28411: Isolate PyInterpreterState.modules (#3575)Eric Snow-14/+45
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.
2017-09-13bpo-31404: Revert "remove modules from Py_InterpreterState (#1638)" (#3565)Eric Snow-168/+37
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.
2017-09-07bpo-30860: Consolidate stateful runtime globals. (#3397)Eric Snow-0/+1
* group the (stateful) runtime globals into various topical structs * consolidate the topical structs under a single top-level _PyRuntimeState struct * add a check-c-globals.py script that helps identify runtime globals Other globals are excluded (see globals.txt and check-c-globals.py).
2017-09-07bpo-31370: Remove support for threads-less builds (#3385)Antoine Pitrou-14/+0
* Remove Setup.config * Always define WITH_THREAD for compatibility.
2017-09-04bpo-28411: Remove "modules" field from Py_InterpreterState. (#1638)Eric Snow-37/+168
sys.modules is the one true source.
2017-07-12bpo-30876: Relative import from unloaded package now reimports the package ↵Serhiy Storchaka-7/+0
(#2639) instead of failing with SystemError. Relative import from non-package now fails with ImportError rather than SystemError.
2017-07-10bpo-30891: Fix importlib _find_and_load() race condition (#2646)Victor Stinner-4/+0
* Rewrite importlib _get_module_lock(): it is now responsible to hold the imp lock directly. * _find_and_load() now holds the module lock to check if name is in sys.modules to prevent a race condition
2017-07-06bpo-30814: Fixed a race condition when import a submodule from a package. ↵Serhiy Storchaka-16/+1
(#2580)
2017-06-15bpo-30626: Fix error handling in PyImport_Import(). (#2103)Serhiy Storchaka-2/+6
In rare circumstances PyImport_Import() could return NULL without raising an error.
2017-05-28Doc nits for bpo-16500 (#1841)Antoine Pitrou-1/+1
* Doc nits for bpo-16500 * Fix more references
2017-03-23bpo-6532: Make the thread id an unsigned integer. (#781)Serhiy Storchaka-10/+11
* bpo-6532: Make the thread id an unsigned integer. From C API side the type of results of PyThread_start_new_thread() and PyThread_get_thread_ident(), the id parameter of PyThreadState_SetAsyncExc(), and the thread_id field of PyThreadState changed from "long" to "unsigned long". * Restore a check in thread_get_ident().
2017-03-08Use Py_RETURN_FALSE/Py_RETURN_TRUE rather than ↵Serhiy Storchaka-1/+1
PyBool_FromLong(0)/PyBool_FromLong(1). (#567)
2017-02-04Removed redundant Argument Clinic directives.Serhiy Storchaka-5/+0
2017-01-23Issue #28999: Use Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE whereverSerhiy Storchaka-6/+3
possible. Patch is writen with Coccinelle.
2016-12-09Use _PyObject_CallMethodIdObjArgs()Victor Stinner-1/+1
Issue #28915: Replace _PyObject_CallMethodId() with _PyObject_CallMethodIdObjArgs() in various modules when the format string was only made of "O" formats, PyObject* arguments. _PyObject_CallMethodIdObjArgs() avoids the creation of a temporary tuple and doesn't have to parse a format string.
2016-12-04Backed out changeset b9c9691c72c5Victor Stinner-1/+1
Issue #28858: The change b9c9691c72c5 introduced a regression. It seems like _PyObject_CallArg1() uses more stack memory than PyObject_CallFunctionObjArgs().
2016-12-01Replace PyObject_CallFunctionObjArgs() with fastcallVictor Stinner-1/+1
* PyObject_CallFunctionObjArgs(func, NULL) => _PyObject_CallNoArg(func) * PyObject_CallFunctionObjArgs(func, arg, NULL) => _PyObject_CallArg1(func, arg) PyObject_CallFunctionObjArgs() allocates 40 bytes on the C stack and requires extra work to "parse" C arguments to build a C array of PyObject*. _PyObject_CallNoArg() and _PyObject_CallArg1() are simpler and don't allocate memory on the C stack. This change is part of the fastcall project. The change on listsort() is related to the issue #23507.
2016-11-20Added the const qualifier to char* variables that refer to readonly internalSerhiy Storchaka-1/+1
UTF-8 represenatation of Unicode objects.
2016-11-16Issue #28701: Replace PyUnicode_CompareWithASCIIString with ↵Serhiy Storchaka-13/+7
_PyUnicode_EqualToASCIIString. The latter function is more readable, faster and doesn't raise exceptions.
2016-11-16Issue #28701: Replace PyUnicode_CompareWithASCIIString with ↵Serhiy Storchaka-13/+7
_PyUnicode_EqualToASCIIString. The latter function is more readable, faster and doesn't raise exceptions.
2016-09-09Fix potential NULL pointer dereference in _imp_create_builtinChristian Heimes-0/+4
PyModule_GetDef() can return NULL. Let's check the return value properly like in the other five cases. CID 1299590
2016-09-07[backport to 3.5] - issue26896 - Disambiguate uses of "importer" with "finder".Senthil Kumaran-3/+4
2016-08-31Issue #27909: Fix INCREF for possible NULL valueRaymond Hettinger-1/+1
2016-09-07Issue #27911: Remove some unnecessary error checks in import.c.Brett Cannon-6/+2
Thanks to Xiang Zhang for the patch.
2016-09-07Issue #15767: Use ModuleNotFoundError.Eric Snow-1/+2
2016-08-31MergeRaymond Hettinger-1/+1
2016-08-02Issue #22557: Now importing already imported modules is up to 2.5 times faster.Serhiy Storchaka-218/+177