summaryrefslogtreecommitdiffstats
path: root/Python/pythonrun.c
Commit message (Collapse)AuthorAgeFilesLines
* bpo-43660: Fix crash when displaying exceptions with custom values for ↵Miss Islington (bot)2021-03-291-1/+2
| | | | | | | sys.stderr (GH-25075) (cherry picked from commit 09b90a037d18f5d4acdf1b14082e57bda78e85d3) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
* bpo-32381: Fix PyRun_SimpleFileExFlags() encoding (GH-23642) (GH-23692) ↵Victor Stinner2020-12-081-92/+132
| | | | | | | | | | | | | | | (GH-23696) Fix encoding name when running a ".pyc" file on Windows: PyRun_SimpleFileExFlags() now uses the correct encoding to decode the filename. * Add pyrun_file() subfunction. * Add pyrun_simple_file() subfunction. * PyRun_SimpleFileExFlags() now calls _Py_fopen_obj() rather than _Py_fopen(). (cherry picked from commit b6d98c10fff6f320f8fdf595c3f9a05d8be4e31d) (cherry picked from commit f0e42ae03c41ec32fcb3064772f46ff7f2c5ff3b)
* [3.8] bpo-35975: Only use cf_feature_version if PyCF_ONLY_AST in cf_flags ↵Guido van Rossum2020-06-281-1/+1
| | | | (#21023)
* bpo-38920: Add audit hooks for when sys.excepthook and sys.unraisablehook ↵Steve Dower2019-11-281-0/+8
| | | | | are invoked (GH-17392) Also fixes some potential segfaults in unraisable hook handling.
* closes bpo-37633: Reëxport some function compatibility wrappers for macros ↵Miss Islington (bot)2019-11-051-16/+16
| | | | | | | in ``pythonrun.h``. (GH-17056) (cherry picked from commit 62161ce989d7d4fe2b0e6899a54da20feeddc798) Co-authored-by: Benjamin Peterson <benjamin@python.org>
* bpo-37467: Fix PyErr_Display() for bytes filename (GH-14504)Miss Islington (bot)2019-07-011-1/+1
| | | | | | | | | | | | | | | | | Fix sys.excepthook() and PyErr_Display() if a filename is a bytes string. For example, for a SyntaxError exception where the filename attribute is a bytes string. Cleanup also test_sys: * Sort imports. * Rename numruns global var to INTERN_NUMRUNS. * Add DisplayHookTest and ExceptHookTest test case classes. * Don't save/restore sys.stdout and sys.displayhook using setUp()/tearDown(): do it in each test method. * Test error case (call hook with no argument) after the success case. (cherry picked from commit f9b7457bd7f438263e0d2dd1f70589ad56a2585e) Co-authored-by: Victor Stinner <vstinner@redhat.com>
* bpo-37253: Add _PyCompilerFlags_INIT macro (GH-14018)Miss Islington (bot)2019-06-131-13/+4
| | | | | | | | Add a new _PyCompilerFlags_INIT macro to initialize PyCompilerFlags variables, rather than initializing cf_flags and cf_feature_version explicitly in each variable. (cherry picked from commit 37d66d7d4bc7dbac9809d69966a774ebb32563be) Co-authored-by: Victor Stinner <vstinner@redhat.com>
* bpo-37001: Makes symtable.symtable have parity with compile for input (#13483)Dino Viehland2019-05-281-4/+60
| | | | | | | * Makes symtable.symtable have parity for accepted datatypes for source code as compile() * Add NEWS blurb
* bpo-36829: sys.excepthook and sys.unraisablehook flush (GH-13620)Victor Stinner2019-05-281-0/+10
| | | | | | | sys.excepthook() and sys.unraisablehook() now explicitly flush the file (usually sys.stderr). If file.flush() fails, sys.excepthook() silently ignores the error, whereas sys.unraisablehook() logs the new exception.
* bpo-1230540: Add threading.excepthook() (GH-13515)Victor Stinner2019-05-271-14/+24
| | | | | | | | | | | | | | | | | | | Add a new threading.excepthook() function which handles uncaught Thread.run() exception. It can be overridden to control how uncaught exceptions are handled. threading.ExceptHookArgs is not documented on purpose: it should not be used directly. * threading.excepthook() and threading.ExceptHookArgs. * Add _PyErr_Display(): similar to PyErr_Display(), but accept a 'file' parameter. * Add _thread._excepthook(): C implementation of the exception hook calling _PyErr_Display(). * Add _thread._ExceptHookArgs: structseq type. * Add threading._invoke_excepthook_wrapper() which handles the gory details to ensure that everything remains alive during Python shutdown. * Add unit tests.
* bpo-36763: Implement the PEP 587 (GH-13592)Victor Stinner2019-05-271-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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-36710: Add tstate parameter in ceval.c (GH-13547)Victor Stinner2019-05-241-20/+41
| | | | | | | | | | | | | | | | * Fix a possible reference leak in _PyErr_Print() if exception is NULL. * PyErr_BadInternalCall(): replace PyErr_Format() with _PyErr_SetString(). * Add pycore_pyerrors.h header file. * New functions: * _PyErr_Clear() * _PyErr_Fetch() * _PyErr_Print() * _PyErr_Restore() * _PyErr_SetObject() * _PyErr_SetString() * Add 'tstate' parameter to _PyEval_AddPendingCall().
* bpo-36842: Implement PEP 578 (GH-12613)Steve Dower2019-05-231-0/+6
| | | Adds sys.audit, sys.addaudithook, io.open_code, and associated C APIs.
* bpo-36763: _Py_RunMain() doesn't call Py_Exit() anymore (GH-13390)Victor Stinner2019-05-171-16/+36
| | | | | | | | | Py_Main() and _Py_RunMain() now return the exitcode rather than calling Py_Exit(exitcode) when calling PyErr_Print() if the current exception type is SystemExit. * Add _Py_HandleSystemExit(). * Add pymain_exit_err_print(). * Add pymain_exit_print().
* bpo-36763: Add _Py_InitializeMain() (GH-13362)Victor Stinner2019-05-161-0/+9
| | | | | | | | | * Add a private _Py_InitializeMain() function. * Add again _PyCoreConfig._init_main. * _Py_InitializeFromConfig() now uses _init_main to decide if _Py_InitializeMainInterpreter() should be called. * _PyCoreConfig: rename _frozen to pathconfig_warnings, its value is now the opposite of Py_FrozenFlag. * Add an unit test for _init_main=0 and _Py_InitializeMain().
* bpo-36900: Replace global conf vars with config (GH-13299)Victor Stinner2019-05-141-1/+3
| | | | | | Replace global configuration variables with core_config read from the current interpreter. Cleanup dynload_hpux.c.
* bpo-35975: Support parsing earlier minor versions of Python 3 (GH-12086)Guido van Rossum2019-03-071-0/+6
| | | | | | | This adds a `feature_version` flag to `ast.parse()` (documented) and `compile()` (hidden) that allow tweaking the parser to support older versions of the grammar. In particular if `feature_version` is 5 or 6, the hacks for the `async` and `await` keyword from PEP 492 are reinstated. (For 7 or higher, these are unconditionally treated as keywords, but they are still special tokens rather than `NAME` tokens that the parser driver recognizes.) https://bugs.python.org/issue35975
* Re-init _Py_UnhandledKeyboardInterrupt before run. (GH-11963)Gregory P. Smith2019-02-211-0/+11
| | | | | | | | | | Explicitly reinitialize this every eval *just in case* someone is calling into an embedded Python where they don't care about an uncaught KeyboardInterrupt exception (why didn't they leave `config.install_signal_handlers` set to `0`?!?) but then later call `Py_Main()` itself (which *checks* this flag and dies with a signal after its interpreter exits). We don't want a previous embedded interpreter's uncaught exception to trigger an unexplained signal exit from a future `Py_Main()` based one.
* bpo-1054041: Exit properly after an uncaught ^C. (#11862)Gregory P. Smith2019-02-161-2/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * bpo-1054041: Exit properly by a signal after a ^C. An uncaught KeyboardInterrupt exception means the user pressed ^C and our code did not handle it. Programs that install SIGINT handlers are supposed to reraise the SIGINT signal to the SIG_DFL handler in order to exit in a manner that their calling process can detect that they died due to a Ctrl-C. https://www.cons.org/cracauer/sigint.html After this change on POSIX systems while true; do python -c 'import time; time.sleep(23)'; done can be stopped via a simple Ctrl-C instead of the shell infinitely restarting a new python process. What to do on Windows, or if anything needs to be done there has not yet been determined. That belongs in its own PR. TODO(gpshead): A unittest for this behavior is still needed. * Do the unhandled ^C check after pymain_free. * Return STATUS_CONTROL_C_EXIT on Windows. * Fix ifdef around unistd.h include. * 📜🤖 Added by blurb_it. * Add STATUS_CTRL_C_EXIT to the os module on Windows * Add unittests. * Don't send CTRL_C_EVENT in the Windows test. It was causing CI systems to bail out of the entire test suite. See https://dev.azure.com/Python/cpython/_build/results?buildId=37980 for example. * Correct posix test (fail on macOS?) check. * STATUS_CONTROL_C_EXIT must be unsigned. * Improve the error message. * test typo :) * Skip if the bash version is too old. ...and rename the windows test to reflect what it does. * min bash version is 4.4, detect no bash. * restore a blank line i didn't mean to delete. * PyErr_Occurred() before the Py_DECREF(co); * Don't add os.STATUS_CONTROL_C_EXIT as a constant. * Update the Windows test comment. * Refactor common logic into a run_eval_code_obj fn.
* bpo-35766: Merge typed_ast back into CPython (GH-11645)Guido van Rossum2019-01-311-0/+2
|
* bpo-30167: Remove __cached__ from __main__ when removing __file__ (GH-7415)INADA Naoki2018-11-291-2/+8
|
* 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-1/+1
| | | | | | | | | | | | | | 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-35081: Add pycore_ prefix to internal header files (GH-10263)Victor Stinner2018-10-311-1/+1
| | | | | | | | | | | | | | | | | | | | * 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-34653: Removed unused function PyParser_SimpleParseStringFilename. (GH-9260)Eric V. Smith2018-09-131-6/+0
| | | | | | This function was not in any .h file and was not used by Python, so removing it is safe. https://bugs.python.org/issue34653
* closes bpo-34646: Remove PyAPI_* macros from declarations. (GH-9218)Benjamin Peterson2018-09-121-16/+16
|
* bpo-34301: Add _PyInterpreterState_Get() helper function (GH-8592)Victor Stinner2018-08-031-6/+2
| | | | sys_setcheckinterval() now uses a local variable to parse arguments, before writing into interp->check_interval.
* bpo-34084: Fix setting an error message for the "Barry as BDFL" easter egg. ↵Serhiy Storchaka2018-07-231-0/+4
| | | | (GH-8262)
* bpo-34080: Fix a memory leak in the compiler. (GH-8222)Serhiy Storchaka2018-07-111-1/+1
|
* bpo-24596: Decref module in PyRun_SimpleFileExFlags() on SystemExit (GH-7918)Zackery Spytz2018-07-031-1/+2
| | | | PyErr_Print() will not return when the exception is a SystemExit, so decref the __main__ module object in that case.
* bpo-33451: Close pyc files before calling PyEval_EvalCode() (GH-7884)Zackery Spytz2018-06-241-6/+9
| | | Directly executed pyc files were being kept open longer than necessary.
* bpo-33818: PyExceptionClass_Name() will now return "const char *". (GH-7581)Serhiy Storchaka2018-06-151-2/+2
|
* closes bpo-31650: PEP 552 (Deterministic pycs) implementation (#4575)Benjamin Peterson2017-12-091-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | 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.
* bpo-32030: Add more options to _PyCoreConfig (#4485)Victor Stinner2017-11-211-1/+5
| | | | | | Py_Main() now handles two more -X options: * -X showrefcount: new _PyCoreConfig.show_ref_count field * -X showalloccount: new _PyCoreConfig.show_alloc_count field
* bpo-30696: Fix the REPL looping endlessly when no memory (GH-4160)xdegaye2017-11-121-18/+42
|
* Add the const qualifier to "char *" variables that refer to literal strings. ↵Serhiy Storchaka2017-11-111-1/+1
| | | | (#4370)
* bpo-30817: Fix PyErr_PrintEx() when no memory (#2526)xdegaye2017-10-231-3/+9
|
* bpo-28603: Fix formatting tracebacks for unhashable exceptions (#4014)Zane Bitter2017-10-171-3/+18
|
* bpo-30860: Fix a refleak. (#3567)Eric Snow2017-09-141-1/+4
| | | | | Resolves bpo-31420. (This was accidentally reverted when in #3565.)
* bpo-31404: Revert "remove modules from Py_InterpreterState (#1638)" (#3565)Eric Snow2017-09-141-4/+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-30860: Fix a refleak. (#3506)Eric Snow2017-09-121-1/+4
| | | | | | | | | | | | | | * Drop warnoptions from PyInterpreterState. * Drop xoptions from PyInterpreterState. * Don't set warnoptions and _xoptions again. * Decref after adding to sys.__dict__. * Drop an unused macro. * Check sys.xoptions *before* we delete it.
* bpo-30860: Consolidate stateful runtime globals. (#3397)Eric Snow2017-09-081-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).
* bpo-22257: Private C-API for main interpreter initialization (PEP 432). (#1729)Eric Snow2017-05-241-2/+8
| | | (patch by Nick Coghlan)
* bpo-29556: Remove unused #include <langinfo.h> (#98)Yen Chi Hsuan2017-02-151-4/+0
| | | | | | bltinmodule.c: Added in b744ba1 and no longer necessary since d64e8a7 posixmodule.c: Added in d1cd4d4 and no longer necessary since efb00c0 pythonrun.c: Added in 73d538b and no longer necessary since d600951 sysmodule.c: Added in 5467d4c and no longer necessary since a2c17c5
* Issue #25677: Merge SyntaxError caret positioning from 3.6Martin Panter2016-12-191-1/+1
|\
| * Issue #25677: Merge SyntaxError caret positioning from 3.5Martin Panter2016-12-191-1/+1
| |\
| | * Issue #25677: Correct syntax error caret for indented blocks.Martin Panter2016-12-111-1/+1
| | | | | | | | | | | | Based on patch by Michael Layzell.
* | | Added the const qualifier to char* variables that refer to readonly internalSerhiy Storchaka2016-11-201-3/+3
|/ / | | | | | | UTF-8 represenatation of Unicode objects.
* | Replaced outdated macros _PyUnicode_AsString and _PyUnicode_AsStringAndSizeSerhiy Storchaka2016-11-201-4/+4
| | | | | | | | with PyUnicode_AsUTF8 and PyUnicode_AsUTF8AndSize.