summaryrefslogtreecommitdiffstats
path: root/Objects/exceptions.c
Commit message (Collapse)AuthorAgeFilesLines
* [3.13] gh-119521: Rename IncompleteInputError to _IncompleteInputError and ↵Miss Islington (bot)2024-06-241-8/+12
| | | | | | | | | | | | | remove from public API/ABI (GH-119680, GH-120955) (GH-120944) - gh-119521: Rename IncompleteInputError to _IncompleteInputError and remove from public API/ABI (GH-119680) (cherry picked from commit ce1064e4c9bcfd673323ad690e60f86e1ab907bb) - gh-119521: Use `PyAPI_DATA`, not `extern`, for `_PyExc_IncompleteInputError` (GH-120955) (cherry picked from commit ac61d58db0753a3b37de21dbc6e86b38f2a93f1b) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com> Co-authored-by: Petr Viktorin <encukou@gmail.com>
* [3.13] gh-117398: Use Per-Interpreter State for the _datetime Static Types ↵Miss Islington (bot)2024-06-031-1/+1
| | | | | | | | | | | (gh-120009) We make use of the same mechanism that we use for the static builtin types. This required a few tweaks. This change is the final piece needed to make _datetime support multiple interpreters. I've updated the module slot accordingly. (cherry picked from commit 105f22ea46ac16866e6df18ebae2a8ba422b7f45, AKA gh-119929) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
* gh-114570: Add PythonFinalizationError exception (#115352)Victor Stinner2024-02-141-0/+5
| | | | | | | | | | | | | | | | | Add PythonFinalizationError exception. This exception derived from RuntimeError is raised when an operation is blocked during the Python finalization. The following functions now raise PythonFinalizationError, instead of RuntimeError: * _thread.start_new_thread() * subprocess.Popen * os.fork() * os.fork1() * os.forkpty() Morever, _winapi.Overlapped finalizer now logs an unraisable PythonFinalizationError, instead of an unraisable RuntimeError.
* gh-89240: Enable multiprocessing on Windows to use large process pools ↵Steve Dower2024-02-131-4/+3
| | | | | | | (GH-107873) We add _winapi.BatchedWaitForMultipleObjects to wait for larger numbers of handles. This is an internal module, hence undocumented, and should be used with caution. Check the docstring for info before using BatchedWaitForMultipleObjects.
* gh-113744: Add a new IncompleteInputError exception to improve incomplete ↵Pablo Galindo Salgado2024-01-301-0/+6
| | | | | input detection in the codeop module (#113745) Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
* gh-111666: Speed up `BaseExceptionGroup.{derive,split,subgroup}` (#111667)Nikita Sobolev2023-11-041-20/+6
|
* gh-109894: Fix initialization of static `MemoryError` in subinterpreter ↵Radislav Chugunov2023-10-231-4/+0
| | | | | | | | | | | | (gh-110911) Fixes #109894 * set `interp.static_objects.last_resort_memory_error.args` to empty tuple to avoid crash on `PyErr_Display()` call * allow `_PyExc_InitGlobalObjects()` to be called on subinterpreter init --------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
* gh-110964: Remove private _PyArg functions (#110966)Victor Stinner2023-10-171-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Move the following private functions and structures to pycore_modsupport.h internal C API: * _PyArg_BadArgument() * _PyArg_CheckPositional() * _PyArg_NoKeywords() * _PyArg_NoPositional() * _PyArg_ParseStack() * _PyArg_ParseStackAndKeywords() * _PyArg_Parser structure * _PyArg_UnpackKeywords() * _PyArg_UnpackKeywordsWithVararg() * _PyArg_UnpackStack() * _Py_ANY_VARARGS() Changes: * Python/getargs.h now includes pycore_modsupport.h to export functions. * clinic.py now adds pycore_modsupport.h when one of these functions is used. * Add pycore_modsupport.h includes when a C extension uses one of these functions. * Define Py_BUILD_CORE_MODULE in C extensions which now include directly or indirectly (via code generated by Argument Clinic) pycore_modsupport.h: * _csv * _curses_panel * _dbm * _gdbm * _multiprocessing.posixshmem * _sqlite.row * _statistics * grp * resource * syslog * _testcapi: bad_get() no longer uses METH_FASTCALL calling convention but METH_VARARGS. Replace _PyArg_UnpackStack() with PyArg_ParseTuple(). * _testcapi: add PYTESTCAPI_NEED_INTERNAL_API macro which is defined by _testcapi sub-modules which need the internal C API (pycore_modsupport.h): exceptions.c, float.c, vectorcall.c, watchers.c. * Remove Include/cpython/modsupport.h header file. Include/modsupport.h no longer includes the removed header file. * Fix mypy clinic.py
* gh-106869: Use new PyMemberDef constant names (#106871)Victor Stinner2023-07-251-31/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Remove '#include "structmember.h"'. * If needed, add <stddef.h> to get offsetof() function. * Update Parser/asdl_c.py to regenerate Python/Python-ast.c. * Replace: * T_SHORT => Py_T_SHORT * T_INT => Py_T_INT * T_LONG => Py_T_LONG * T_FLOAT => Py_T_FLOAT * T_DOUBLE => Py_T_DOUBLE * T_STRING => Py_T_STRING * T_OBJECT => _Py_T_OBJECT * T_CHAR => Py_T_CHAR * T_BYTE => Py_T_BYTE * T_UBYTE => Py_T_UBYTE * T_USHORT => Py_T_USHORT * T_UINT => Py_T_UINT * T_ULONG => Py_T_ULONG * T_STRING_INPLACE => Py_T_STRING_INPLACE * T_BOOL => Py_T_BOOL * T_OBJECT_EX => Py_T_OBJECT_EX * T_LONGLONG => Py_T_LONGLONG * T_ULONGLONG => Py_T_ULONGLONG * T_PYSSIZET => Py_T_PYSSIZET * T_NONE => _Py_T_NONE * READONLY => Py_READONLY * PY_AUDIT_READ => Py_AUDIT_READ * READ_RESTRICTED => Py_AUDIT_READ * PY_WRITE_RESTRICTED => _Py_WRITE_RESTRICTED * RESTRICTED => (READ_RESTRICTED | _Py_WRITE_RESTRICTED)
* gh-106521: Remove _PyObject_LookupAttr() function (GH-106642)Serhiy Storchaka2023-07-121-2/+2
|
* gh-104922: remove PY_SSIZE_T_CLEAN (#106315)Inada Naoki2023-07-021-1/+0
|
* fix typos (#106247)Inada Naoki2023-06-301-1/+1
| | | Most typos are in comments, but two typos are in docstring.
* gh-106084: Remove _PyObject_RealIsInstance() function (#106106)Victor Stinner2023-06-261-0/+1
| | | | | | | | | | | | | | | Remove the following functions from the public C API: * _PyObject_RealIsInstance() * _PyObject_RealIsSubclass() * _Py_add_one_to_index_F() * _Py_add_one_to_index_C() Move _PyObject_RealIsInstance() and _PyObject_RealIsSubclass() to the internal C API (pycore_abstract.h) and no longer export their symbols (in libpython). Make _Py_add_one_to_index_F() and _Py_add_one_to_index_C() functions static: no longer export them.
* gh-105730: support more callables in ExceptionGroup.split() and subgroup() ↵Irit Katriel2023-06-231-3/+3
| | | | (#106035)
* gh-106033: Get rid of new occurrences of PyDict_GetItem and PyObject_HasAttr ↵Serhiy Storchaka2023-06-231-16/+15
| | | | | | | | (GH-106034) These functions are broken by design because they discard any exceptions raised inside, including MemoryError and KeyboardInterrupt. They should not be used in new code.
* gh-92536: Remove PyUnicode_READY() calls (#105210)Victor Stinner2023-06-011-2/+0
| | | | Since Python 3.12, PyUnicode_READY() does nothing and always returns 0.
* gh-105071: add PyUnstable_Exc_PrepReraiseStar to expose except* ↵Irit Katriel2023-05-301-0/+39
| | | | implementation in the unstable API (#105072)
* gh-104454: Fix refleak in AttributeError_reduce (#104455)Charles Machalow2023-05-131-1/+3
| | | | | * Fix the reference leak introduced by https://github.com/python/cpython/issues/103333 Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
* gh-103333: Pickle the keyword attributes of AttributeError (#103352)Charles Machalow2023-05-121-1/+43
| | | | | | * Pickle the `name` and `args` attributes of AttributeError when present. Co-authored-by: Gregory P. Smith <greg@krypto.org> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
* 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
|