summaryrefslogtreecommitdiffstats
path: root/Python/errors.c
Commit message (Collapse)AuthorAgeFilesLines
* bpo-46541: Replace core use of _Py_IDENTIFIER() with statically initialized ↵Eric Snow2022-02-081-34/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* bpo-46417: _curses uses PyStructSequence_NewType() (GH-30736)Victor Stinner2022-01-211-0/+1
| | | | | | | | The _curses module now creates its ncurses_version type as a heap type using PyStructSequence_NewType(), rather than using a static type. * Move _PyStructSequence_FiniType() definition to pycore_structseq.h. * test.pythoninfo: log curses.ncurses_version.
* bpo-46417: Finalize structseq types at exit (GH-30645)Victor Stinner2022-01-211-0/+11
| | | | | | | | | | | | | | | | | | Add _PyStructSequence_FiniType() and _PyStaticType_Dealloc() functions to finalize a structseq static type in Py_Finalize(). Currrently, these functions do nothing if Python is built in release mode. Clear static types: * AsyncGenHooksType: sys.set_asyncgen_hooks() * FlagsType: sys.flags * FloatInfoType: sys.float_info * Hash_InfoType: sys.hash_info * Int_InfoType: sys.int_info * ThreadInfoType: sys.thread_info * UnraisableHookArgsType: sys.unraisablehook * VersionInfoType: sys.version * WindowsVersionType: sys.getwindowsversion()
* bpo-45711: Remove type and traceback from exc_info (GH-30122)Irit Katriel2021-12-171-17/+1
| | | | | | | | * Do not PUSH/POP traceback or type to the stack as part of exc_info * Remove exc_traceback and exc_type from _PyErr_StackItem * Add to what's new, because this change breaks things like Cython
* bpo-46008: Make runtime-global object/type lifecycle functions and state ↵Eric Snow2021-12-091-1/+5
| | | | | | | | | | | | consistent. (gh-29998) This change is strictly renames and moving code around. It helps in the following ways: * ensures type-related init functions focus strictly on one of the three aspects (state, objects, types) * passes in PyInterpreterState * to all those functions, simplifying work on moving types/objects/state to the interpreter * consistent naming conventions help make what's going on more clear * keeping API related to a type in the corresponding header file makes it more obvious where to look for it https://bugs.python.org/issue46008
* bpo-45711: Remove unnecessary normalization of exc_info (GH-29922)Irit Katriel2021-12-081-20/+0
|
* bpo-45711: Change exc_info related APIs to derive type and traceback from ↵Irit Katriel2021-11-301-26/+48
| | | | the exception instance (GH-29780)
* bpo-45711: use exc_value instead of exc_type to determine if exc_info is ↵Irit Katriel2021-11-251-21/+75
| | | | valid. Add more assertions. (GH-29627)
* bpo-45848: Allow the parser to get error lines from encoded files (GH-29646)Pablo Galindo Salgado2021-11-201-4/+14
|
* bpo-45434: pyport.h no longer includes <stdlib.h> (GH-28914)Victor Stinner2021-10-131-3/+4
| | | | | Include <stdlib.h> explicitly in C files. Python.h includes <wchar.h>.
* bpo-45439: Move _PyObject_CallNoArgs() to pycore_call.h (GH-28895)Victor Stinner2021-10-121-5/+6
| | | | | | | * Move _PyObject_CallNoArgs() to pycore_call.h (internal C API). * _ssl, _sqlite and _testcapi extensions now call the public PyObject_CallNoArgs() function, rather than _PyObject_CallNoArgs(). * _lsprof extension is now built with Py_BUILD_CORE_MODULE macro defined to get access to internal _PyObject_CallNoArgs().
* bpo-45439: Rename _PyObject_CallNoArg() to _PyObject_CallNoArgs() (GH-28891)Victor Stinner2021-10-111-1/+1
| | | | | Fix typo in the private _PyObject_CallNoArg() function name: rename it to _PyObject_CallNoArgs() to be consistent with the public function PyObject_CallNoArgs().
* bpo-41031: Match C and Python code formatting of unprintable exceptions and ↵Irit Katriel2021-09-051-1/+3
| | | | exceptions in the __main__ module. (GH-28139)
* bpo-45083: Include the exception class qualname when formatting an exception ↵Irit Katriel2021-09-031-17/+16
| | | | | (GH-28119) Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
* bpo-25782: avoid hang in PyErr_SetObject when current exception has a cycle ↵Irit Katriel2021-08-101-1/+15
| | | | | in its context chain (GH-27626) Co-authored-by: Dennis Sweeney 36520290+sweeneyde@users.noreply.github.com
* closes bpo-39091: Fix segfault when Exception constructor returns ↵Noah2021-08-031-4/+16
| | | | | non-exception for gen.throw. (#17658) Co-authored-by: Benjamin Peterson <benjamin@python.org>
* bpo-44590: Lazily allocate frame objects (GH-27077)Mark Shannon2021-07-261-1/+2
| | | | | | | | | | | | | | * Convert "specials" array to InterpreterFrame struct, adding f_lasti, f_state and other non-debug FrameObject fields to it. * Refactor, calls pushing the call to the interpreter upward toward _PyEval_Vector. * Compute f_back when on thread stack, only filling in value when frame object outlives stack invocation. * Move ownership of InterpreterFrame in generator from frame object to generator object. * Do not create frame objects for Python calls. * Do not create frame objects for generators.
* bpo-44094: Remove deprecated PyErr_ APIs. (GH-26011)Inada Naoki2021-05-131-36/+0
| | | These APIs are deprecated since Python 3.3. They are not documented too.
* bpo-43914: Highlight invalid ranges in SyntaxErrors (#25525)Pablo Galindo2021-04-231-2/+42
| | | | | | | | | | | | | | | | | To improve the user experience understanding what part of the error messages associated with SyntaxErrors is wrong, we can highlight the whole error range and not only place the caret at the first character. In this way: >>> foo(x, z for z in range(10), t, w) File "<stdin>", line 1 foo(x, z for z in range(10), t, w) ^ SyntaxError: Generator expression must be parenthesized becomes >>> foo(x, z for z in range(10), t, w) File "<stdin>", line 1 foo(x, z for z in range(10), t, w) ^^^^^^^^^^^^^^^^^^^^ SyntaxError: Generator expression must be parenthesized
* bpo-43687: Py_Initialize() creates singletons earlier (GH-25147)Victor Stinner2021-04-021-1/+1
| | | | | Reorganize pycore_interp_init() to initialize singletons before the the first PyType_Ready() call. Fix an issue when Python is configured using --without-doc-strings.
* bpo-32381: Rewrite PyErr_ProgramText() (GH-23700)Victor Stinner2020-12-081-5/+10
| | | PyErr_ProgramText() now calls PyErr_ProgramTextObject().
* bpo-42599: Remove useless PyModule_GetWarningsModule() (GH-23691)Hai Shi2020-12-081-3/+0
| | | | Removed PyModule_GetWarningsModule() which is useless due to the _warnings module was converted to a builtin module in 2.6.
* bpo-42500: Fix recursion in or after except (GH-23568)Mark Shannon2020-12-021-0/+3
| | | * Use counter, rather boolean state when handling soft overflows.
* bpo-42152: Use PyDict_Contains and PyDict_SetDefault if appropriate. (GH-22986)Serhiy Storchaka2020-10-261-4/+5
| | | | | | | If PyDict_GetItemWithError is only used to check whether the key is in dict, it is better to use PyDict_Contains instead. And if it is used in combination with PyDict_SetItem, PyDict_SetDefault can replace the combination.
* bpo-41991: Remove _PyObject_HasAttrId (GH-22629)Serhiy Storchaka2020-10-101-2/+17
| | | It can silence arbitrary exceptions.
* bpo-40985: Show correct SyntaxError text when last line has a LINECONT ↵Lysandros Nikolaou2020-06-161-4/+8
| | | | | | | | (GH-20888) When a file ends with a line that contains a line continuation character the text of the emitted SyntaxError is empty, contrary to the old parser, where the error text contained the text of the last line.
* Remove redundant var in PyErr_NewException() (GH-20850)Hai Shi2020-06-131-2/+0
|
* bpo-40826: Add _Py_EnsureTstateNotNULL() macro (GH-20571)Victor Stinner2020-06-011-1/+1
| | | | Add _Py_EnsureTstateNotNULL(tstate) macro: call Py_FatalError() if tstate is NULL, the error message contains the current function name.
* bpo-40696: Fix a hang that can arise after gen.throw() (GH-20287)Chris Jerdonek2020-05-221-9/+53
| | | | | | | | This updates _PyErr_ChainStackItem() to use _PyErr_SetObject() instead of _PyErr_ChainExceptions(). This prevents a hang in certain circumstances because _PyErr_SetObject() performs checks to prevent cycles in the exception context chain while _PyErr_ChainExceptions() doesn't.
* bpo-31033: Improve the traceback for cancelled asyncio tasks (GH-19951)Chris Jerdonek2020-05-181-0/+14
| | | | | When an asyncio.Task is cancelled, the exception traceback now starts with where the task was first interrupted. Previously, the traceback only had "depth one."
* bpo-29587: _PyErr_ChainExceptions() checks exception (GH-19902)Victor Stinner2020-05-051-1/+11
| | | | | | | | | | | | | | | | | | | _PyErr_ChainExceptions() now ensures that the first parameter is an exception type, as done by _PyErr_SetObject(). * The following function now check PyExceptionInstance_Check() in an assertion using a new _PyBaseExceptionObject_cast() helper function: * PyException_GetTraceback(), PyException_SetTraceback() * PyException_GetCause(), PyException_SetCause() * PyException_GetContext(), PyException_SetContext() * PyExceptionClass_Name() now checks PyExceptionClass_Check() with an assertion. * Remove XXX comment and add gi_exc_state variable to _gen_throw(). * Remove comment from test_generators
* bpo-40429: PyThreadState_GetFrame() returns a strong ref (GH-19781)Victor Stinner2020-04-291-1/+1
| | | | The PyThreadState_GetFrame() function now returns a strong reference to the frame.
* bpo-40268: Remove a few pycore_pystate.h includes (GH-19510)Victor Stinner2020-04-141-1/+1
|
* bpo-38644: Use _PySys_Audit(): pass tstate explicitly (GH-19183)Victor Stinner2020-03-271-1/+2
| | | Add the dependency to tstate more explicit.
* bpo-39573: Use Py_IS_TYPE() macro to check for types (GH-18809)Andy Lester2020-03-061-1/+1
| | | Co-authored-by: Victor Stinner <vstinner@python.org>
* bpo-39573: Finish converting to new Py_IS_TYPE() macro (GH-18601)Andy Lester2020-03-041-1/+1
|
* closes bpo-39630: Update pointers to string literals to be const char *. ↵Andy Lester2020-02-141-1/+1
| | | | (GH-18510)
* bpo-39245: Switch to public API for Vectorcall (GH-18460)Petr Viktorin2020-02-111-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-39487: Merge duplicated _Py_IDENTIFIER identifiers in C code (GH-18254)Hai Shi2020-01-301-3/+1
| | | Moving repetitive `_Py_IDENTIFIER` instances to a global location helps identify them more easily in regards to sub-interpreter support.
* bpo-39164: Fix compiler warning in PyErr_GetExcInfo() (GH-18010)Victor Stinner2020-01-151-1/+1
| | | The function has no return value.
* bpo-39164: Add private _PyErr_GetExcInfo() function (GH-17752)Julien Danjou2020-01-131-4/+10
| | | | | | This adds a new function named _PyErr_GetExcInfo() that is a variation of the original PyErr_GetExcInfo() taking a PyThreadState as its first argument. That function allows to retrieve the exceptions information of any Python thread -- not only the current one.
* bpo-38920: Add audit hooks for when sys.excepthook and sys.unraisable hooks ↵Steve Dower2019-11-281-30/+40
| | | | | are invoked (GH-17392) Also fixes some potential segfaults in unraisable hook handling.
* bpo-38733: PyErr_Occurred() caller must hold the GIL (GH-17080)Victor Stinner2019-11-071-0/+3
| | | | | | | | | | | bpo-3605, bpo-38733: Optimize _PyErr_Occurred(): remove "tstate == NULL" test. Py_FatalError() no longer calls PyErr_Occurred() if called without holding the GIL. So PyErr_Occurred() no longer has to support tstate==NULL case. _Py_CheckFunctionResult(): use directly _PyErr_Occurred() to avoid explicit "!= NULL" test.
* bpo-38644: Pass tstate to _Py_CheckFunctionResult() (GH-17050)Victor Stinner2019-11-051-0/+15
| | | | | * Add tstate parameter to _Py_CheckFunctionResult() * Add _PyErr_FormatFromCauseTstate() * Replace PyErr_XXX(...) with _PyErr_XXX(state, ...)
* bpo-37337: Add _PyObject_CallMethodNoArgs() (GH-14267)Jeroen Demeyer2019-07-081-1/+1
|
* bpo-37483: add _PyObject_CallOneArg() function (#14558)Jeroen Demeyer2019-07-041-3/+2
|
* bpo-36710: Pass explicitly tstate in sysmodule.c (GH-14060)Victor Stinner2019-06-131-2/+8
| | | | | | | | * Replace global var Py_VerboseFlag with interp->config.verbose. * Add _PyErr_NoMemory(tstate) function. * Add tstate parameter to _PyEval_SetCoroutineOriginTrackingDepth() and move the function to the internal API. * Replace _PySys_InitMain(runtime, interp) with _PySys_InitMain(runtime, tstate).
* bpo-36829: sys.excepthook and sys.unraisablehook flush (GH-13620)Victor Stinner2019-05-281-0/+9
| | | | | | | 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-36763: Implement the PEP 587 (GH-13592)Victor Stinner2019-05-271-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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-36829: Add _PyErr_WriteUnraisableMsg() (GH-13488)Victor Stinner2019-05-271-13/+71
| | | | | * sys.unraisablehook: add 'err_msg' field to UnraisableHookArgs. * Use _PyErr_WriteUnraisableMsg() in _ctypes _DictRemover_call() and gc delete_garbage().