summaryrefslogtreecommitdiffstats
path: root/Objects/exceptions.c
Commit message (Collapse)AuthorAgeFilesLines
* gh-94673: Properly Initialize and Finalize Static Builtin Types for Each ↵Eric Snow2023-05-021-6/+2
| | | | | Interpreter (gh-104072) Until now, we haven't been initializing nor finalizing the per-interpreter state properly.
* gh-94673: Ensure Builtin Static Types are Readied Properly (gh-103940)Eric Snow2023-04-271-4/+0
| | | There were cases where we do unnecessary work for builtin static types. This also simplifies some work necessary for a per-interpreter GIL.
* gh-103590: do not wrap a single exception raised from a try-except* (#103665)Irit Katriel2023-04-271-1/+6
|
* gh-102406: replace exception chaining by PEP-678 notes in codecs (#102407)Irit Katriel2023-03-211-110/+0
|
* gh-102594: PyErr_SetObject adds note to exception raised on normalization ↵Irit Katriel2023-03-161-0/+15
| | | | error (#102675)
* gh-102192: Replace PyErr_Fetch/Restore etc by more efficient alternatives ↵Irit Katriel2023-03-081-26/+13
| | | | (in Objects/) (#102218)
* gh-90110: Fix the c-analyzer Tool (#102483)Eric Snow2023-03-071-9/+4
| | | | | | | Some incompatible changes had gone in, and the "ignore" lists weren't properly undated. This change fixes that. It's necessary prior to enabling test_check_c_globals, which I hope to do soon. Note that this does include moving last_resort_memory_error to PyInterpreterState. https://github.com/python/cpython/issues/90110
* GH-101578: Normalize the current exception (GH-101607)Mark Shannon2023-02-081-12/+63
| | | | | | | | | | * Make sure that the current exception is always normalized. * Remove redundant type and traceback fields for the current exception. * Add new API functions: PyErr_GetRaisedException, PyErr_SetRaisedException * Add new API functions: PyException_GetArgs, PyException_SetArgs
* gh-99553: fix bug where an ExceptionGroup subclass can wrap a BaseException ↵Irit Katriel2022-11-181-1/+13
| | | | (GH-99572)
* gh-99300: Use Py_NewRef() in Objects/ directory (#99335)Victor Stinner2022-11-101-83/+37
| | | | Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and Py_XNewRef() in C files of the Objects/ directory.
* gh-99181: fix except* on unhashable exceptions (GH-99192)Irit Katriel2022-11-081-17/+26
|
* gh-91058: Add error suggestions to 'import from' import errors (#98305)Pablo Galindo Salgado2022-10-251-4/+16
|
* gh-97591: In `Exception.__setstate__()` acquire strong references before ↵Ofey Chan2022-10-021-1/+7
| | | | calling `tp_hash` slot (#97700)
* gh-96005: Handle WASI ENOTCAPABLE in getpath (GH-96006)Christian Heimes2022-08-161-0/+5
| | | | | | - On WASI `ENOTCAPABLE` is now mapped to `PermissionError`. - The `errno` modules exposes the new error number. - `getpath.py` now ignores `PermissionError` when it cannot open landmark files `pybuilddir.txt` and `pyenv.cfg`.
* gh-95369: add missing decref in error case of exception group's split (GH-95370)Irit Katriel2022-07-281-0/+1
|
* gh-95324: Emit a warning if an object doesn't call PyObject_GC_UnTrack ↵Pablo Galindo Salgado2022-07-271-2/+3
| | | | during deallocation in debug mode (#95325)
* gh-94673: Add _PyStaticType_InitBuiltin() (#95152)Eric Snow2022-07-251-2/+1
| | | | | | | | | | | | This is the first of several precursors to storing tp_subclasses (and tp_weaklist) on the interpreter state for static builtin types. We do the following: * add `_PyStaticType_InitBuiltin()` * add `_Py_TPFLAGS_STATIC_BUILTIN` * set it on all static builtin types in `_PyStaticType_InitBuiltin()` * shuffle some code around to be able to use _PyStaticType_InitBuiltin() * rename `_PyStructSequence_InitType()` to `_PyStructSequence_InitBuiltinWithFlags()` * add `_PyStructSequence_InitBuiltin()`.
* gh-94673: [c-analyzer] Add a Script to Identify Static Types (#94989)Eric Snow2022-07-191-11/+3
| | | issue: https://github.com/python/cpython/issues/94673
* GH-93207: Remove HAVE_STDARG_PROTOTYPES configure check for stdarg.h (#93215)Kumar Aditya2022-05-271-4/+0
|
* Use static inline function Py_EnterRecursiveCall() (#91988)Victor Stinner2022-05-041-5/+6
| | | | | | | | | | | | | | | | Currently, calling Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() may use a function call or a static inline function call, depending if the internal pycore_ceval.h header file is included or not. Use a different name for the static inline function to ensure that the static inline function is always used in Python internals for best performance. Similar approach than PyThreadState_GET() (function call) and _PyThreadState_GET() (static inline function). * Rename _Py_EnterRecursiveCall() to _Py_EnterRecursiveCallTstate() * Rename _Py_LeaveRecursiveCall() to _Py_LeaveRecursiveCallTstate() * pycore_ceval.h: Rename Py_EnterRecursiveCall() to _Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() and _Py_LeaveRecursiveCall()
* gh-89770: Implement PEP-678 - Exception notes (GH-31317)Irit Katriel2022-04-161-43/+80
|
* bpo-46775: OSError should call winerror_to_errno unconditionally on Windows ↵Dong-hee Na2022-03-301-8/+1
| | | | (GH-32179)
* bpo-46857: Fix refleak in OSError INIT_ALIAS() (GH-31594)Victor Stinner2022-02-261-6/+4
| | | _Py_GetRefTotal() no longer decrements _PySet_Dummy refcount.
* bpo-46729: add number of sub-exceptions in str() of BaseExceptionGroup ↵Irit Katriel2022-02-221-1/+6
| | | | (GH-31294)
* bpo-46541: Replace core use of _Py_IDENTIFIER() with statically initialized ↵Eric Snow2022-02-081-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-40170: PyType_SUPPORTS_WEAKREFS() becomes a regular function (GH-30938)Victor Stinner2022-01-271-1/+1
| | | | | | | | Convert the PyType_SUPPORTS_WEAKREFS() macro to a regular function. It no longer access the PyTypeObject.tp_weaklistoffset member directly. Add _PyType_SUPPORTS_WEAKREFS() static inline functions, used internally by Python for best performance.
* bpo-46431: improve error message on invalid calls to ↵Irit Katriel2022-01-241-1/+4
| | | | BaseExceptionGroup.__new__ (GH-30854)
* bpo-46417: Clear Unicode static types at exit (GH-30806)Victor Stinner2022-01-221-6/+0
| | | | | | | | | | | Add _PyUnicode_FiniTypes() function, called by finalize_interp_types(). It clears these static types: * EncodingMapType * PyFieldNameIter_Type * PyFormatterIter_Type _PyStaticType_Dealloc() now does nothing if tp_subclasses is not NULL.
* bpo-46417: Py_Finalize() clears static exceptioins (GH-30805)Victor Stinner2022-01-221-1/+26
| | | | | | The Py_Finalize() function now clears exceptions implemented as static types. Add _PyExc_FiniTypes() function, called by _PyExc_Fini().
* bpo-46417: Factorize _PyExc_InitTypes() code (GH-30804)Victor Stinner2022-01-221-170/+132
| | | | | | | | Add 'static_exceptions' list to factorize code between _PyExc_InitTypes() and _PyBuiltins_AddExceptions(). _PyExc_InitTypes() does nothing if it's not the main interpreter. Sort exceptions in Lib/test/exception_hierarchy.txt.
* bpo-46417: Use _PyType_CAST() in Objects directory (GH-30764)Victor Stinner2022-01-211-2/+1
|
* bpo-46219, 46221: simplify except* implementation following exc_info ↵Irit Katriel2022-01-021-2/+118
| | | | changes. Move helpers to exceptions.c. Do not assume that exception groups are truthy. (GH-30289)
* bpo-46107: ExceptionGroup.subgroup()/split() should copy __note__ to the ↵Irit Katriel2021-12-211-0/+5
| | | | parts (GH-30159)
* bpo-45292: [PEP-654] add except* (GH-29581)Irit Katriel2021-12-141-23/+135
|
* bpo-46008: Make runtime-global object/type lifecycle functions and state ↵Eric Snow2021-12-091-15/+29
| | | | | | | | | | | | 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-45947: Place dict and values pointer at fixed (negative) offset just ↵Mark Shannon2021-12-071-4/+1
| | | | | | | | | | | | | | | | | | | before GC header. (GH-29879) * Place __dict__ immediately before GC header for plain Python objects. * Fix up lazy dict creation logic to use managed dict pointers. * Manage values pointer, placing them directly before managed dict pointers. * Convert hint-based load/store attr specialization target managed dict classes. * Specialize LOAD_METHOD for managed dict objects. * Remove unsafe _PyObject_GC_Calloc function. * Remove unsafe _PyObject_GC_Malloc() function. * Add comment explaning use of Py_TPFLAGS_MANAGED_DICT.
* bpo-45607: Make it possible to enrich exception displays via setting their ↵Irit Katriel2021-12-031-0/+31
| | | | __note__ field (GH-29880)
* bpo-45292: [PEP 654] add the ExceptionGroup and BaseExceptionGroup classes ↵Irit Katriel2021-10-221-1/+527
| | | | (GH-28569)
* Fix typos in the Objects directory (GH-28766)Christian Clauss2021-10-061-1/+1
|
* bpo-44348: BaseException deallocator uses trashcan (GH-28190)Victor Stinner2021-09-071-1/+6
| | | | | | | | | | The deallocator function of the BaseException type now uses the trashcan mecanism to prevent stack overflow. For example, when a RecursionError instance is raised, it can be linked to another RecursionError through the __context__ attribute or the __traceback__ attribute, and then a chain of exceptions is created. When the chain is destroyed, nested deallocator function calls can crash with a stack overflow if the chain is too long compared to the available stack memory.
* bpo-44854: Remove trailing whitespaces (GH-27689)Serhiy Storchaka2021-08-091-1/+1
|
* bpo-34013: Move the Python 2 hints from the exception constructor to the ↵Pablo Galindo Salgado2021-07-271-201/+0
| | | | parser (GH-27392)
* bpo-44029: Remove Py_UNICODE APIs (GH-25881)Inada Naoki2021-05-071-19/+0
| | | | | | | | | | | | Remove deprecated `Py_UNICODE` APIs: `PyUnicode_Encode`, `PyUnicode_EncodeUTF7`, `PyUnicode_EncodeUTF8`, `PyUnicode_EncodeUTF16`, `PyUnicode_EncodeUTF32`, `PyUnicode_EncodeLatin1`, `PyUnicode_EncodeMBCS`, `PyUnicode_EncodeDecimal`, `PyUnicode_EncodeRawUnicodeEscape`, `PyUnicode_EncodeCharmap`, `PyUnicode_EncodeUnicodeEscape`, `PyUnicode_TransformDecimalToASCII`, `PyUnicode_TranslateCharmap`, `PyUnicodeEncodeError_Create`, `PyUnicodeTranslateError_Create`. See :pep:`393` and :pep:`624` for reference.
* bpo-43914: Highlight invalid ranges in SyntaxErrors (#25525)Pablo Galindo2021-04-231-17/+28
| | | | | | | | | | | | | | | | | 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-38530: Properly extend UnboundLocalError from NameError (GH-25444)Pablo Galindo2021-04-161-1/+2
|
* bpo-38530: Offer suggestions on NameError (GH-25397)Pablo Galindo2021-04-141-2/+63
| | | | | | | | | | | When printing NameError raised by the interpreter, PyErr_Display will offer suggestions of simmilar variable names in the function that the exception was raised from: >>> schwarzschild_black_hole = None >>> schwarschild_black_hole Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'schwarschild_black_hole' is not defined. Did you mean: schwarzschild_black_hole?
* bpo-38530: Offer suggestions on AttributeError (#16856)Pablo Galindo2021-04-141-2/+69
| | | | | | | | | When printing AttributeError, PyErr_Display will offer suggestions of similar attribute names in the object that the exception was raised from: >>> collections.namedtoplo Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: module 'collections' has no attribute 'namedtoplo'. Did you mean: namedtuple?
* bpo-43510: Implement PEP 597 opt-in EncodingWarning. (GH-19481)Inada Naoki2021-03-291-0/+9
| | | | | | | | | | | See [PEP 597](https://www.python.org/dev/peps/pep-0597/). * Add `-X warn_default_encoding` and `PYTHONWARNDEFAULTENCODING`. * Add EncodingWarning * Add io.text_encoding() * open(), TextIOWrapper() emits EncodingWarning when encoding is omitted and warn_default_encoding is enabled. * _pyio.TextIOWrapper() uses UTF-8 as fallback default encoding used when failed to import locale module. (used during building Python) * bz2, configparser, gzip, lzma, pathlib, tempfile modules use io.text_encoding(). * What's new entry
* bpo-43268: Pass interp rather than tstate to internal functions (GH-24580)Victor Stinner2021-02-191-4/+4
| | | | | | | | | | | | | | | Pass the current interpreter (interp) rather than the current Python thread state (tstate) to internal functions which only use the interpreter. Modified functions: * _PyXXX_Fini() and _PyXXX_ClearFreeList() functions * _PyEval_SignalAsyncExc(), make_pending_calls() * _PySys_GetObject(), sys_set_object(), sys_set_object_id(), sys_set_object_str() * should_audit(), set_flags_from_config(), make_flags() * _PyAtExit_Call() * init_stdio_encoding() * etc.
* bpo-40170: Always define PyExceptionClass_Name() as a function (GH-24553)Erlend Egeberg Aasland2021-02-171-2/+0
| | | Remove macro variant of PyExceptionClass_Name().