summaryrefslogtreecommitdiff
path: root/Python/_warnings.c
AgeCommit message (Collapse)AuthorLines
2023-06-11[3.11] gh-105375: Improve PyErr_WarnExplicit() error handling (GH-105610) ↵Miss Islington (bot)-12/+16
(#105660) Bail on first error to prevent exceptions from possibly being overwritten. (cherry picked from commit 567d6ae8e77579173510fc948ac06b2ababf3d40) Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2022-06-20gh-93937, C API: Move PyFrame_GetBack() to Python.h (#93938) (#94000)Victor Stinner-1/+0
Move the follow functions and type from frameobject.h to pyframe.h, so the standard <Python.h> provide frame getter functions: * PyFrame_Check() * PyFrame_GetBack() * PyFrame_GetBuiltins() * PyFrame_GetGenerator() * PyFrame_GetGlobals() * PyFrame_GetLasti() * PyFrame_GetLocals() * PyFrame_Type Remove #include "frameobject.h" from many C files. It's no longer needed. (cherry picked from commit 27b989403356ccdd47545a93aeab8434e9c69f21)
2022-03-31bpo-47164: Add _PyCFunction_CAST() macro (GH-32192)Victor Stinner-3/+3
Use the macro in C files of the Python/ directory.
2022-02-22bpo-46765: Replace Locally Cached Strings with Statically Initialized ↵Eric Snow-21/+2
Objects (gh-31366) https://bugs.python.org/issue46765
2022-02-14bpo-46541: Discover the global strings. (gh-31346)Eric Snow-2/+2
Instead of manually enumerating the global strings in generate_global_objects.py, we extrapolate the list from usage of _Py_ID() and _Py_STR() in the source files. This is partly inspired by gh-31261. https://bugs.python.org/issue46541
2022-02-08bpo-46541: Replace core use of _Py_IDENTIFIER() with statically initialized ↵Eric Snow-113/+150
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
2021-07-26bpo-44590: Lazily allocate frame objects (GH-27077)Mark Shannon-4/+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.
2021-07-05bpo-43950: Print columns in tracebacks (PEP 657) (GH-26958)Ammar Askar-1/+1
The traceback.c and traceback.py mechanisms now utilize the newly added code.co_positions and PyCode_Addr2Location to print carets on the specific expressions involved in a traceback. Co-authored-by: Pablo Galindo <Pablogsal@gmail.com> Co-authored-by: Ammar Askar <ammar@ammaraskar.com> Co-authored-by: Batuhan Taskaya <batuhanosmantaskaya@gmail.com>
2021-05-21bpo-44032: Move data stack to thread from FrameObject. (GH-26076)Mark Shannon-1/+2
* Remove 'zombie' frames. We won't need them once we are allocating fixed-size frames. * Add co_nlocalplus field to code object to avoid recomputing size of locals + frees + cells. * Move locals, cells and freevars out of frame object into separate memory buffer. * Use per-threadstate allocated memory chunks for local variables. * Move globals and builtins from frame object to per-thread stack. * Move (slow) locals frame object to per-thread stack. * Move internal frame functions to internal header.
2021-02-19bpo-43268: Pass interp rather than tstate to internal functions (GH-24580)Victor Stinner-2/+2
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.
2020-11-19bpo-1635741: Port _warnings to the multi-phase init (GH-23379)Victor Stinner-40/+30
Port the _warnings extension module to the multi-phase initialization API (PEP 489).
2020-11-18bpo-40998: Fix a refleak in create_filter() (GH-23365)Victor Stinner-3/+5
2020-11-12bpo-42260: Initialize time and warnings earlier at startup (GH-23249)Victor Stinner-23/+7
* Call _PyTime_Init() and _PyWarnings_InitState() earlier during the Python initialization. * Inline _PyImportHooks_Init() into _PySys_InitCore(). * The _warnings initialization function no longer call _PyWarnings_InitState() to prevent resetting filters_version to 0. * _PyWarnings_InitState() now returns an int and no longer clear the state in case of error (it's done anyway at Python exit). * Rework init_importlib(), fix refleaks on errors.
2020-11-04bpo-1635741: Fix ref leak in _PyWarnings_Init() error path (GH-23151)Victor Stinner-8/+3
Replace PyModule_AddObject() with PyModule_AddObjectRef() in the _warnings module to fix a reference leak on error. Use also PyModule_AddObjectRef() in importdl.c.
2020-11-02bpo-26789: Fix logging.FileHandler._open() at exit (GH-23053)Victor Stinner-1/+1
The logging.FileHandler class now keeps a reference to the builtin open() function to be able to open or reopen the file during Python finalization. Fix errors like: Exception ignored in: (...) Traceback (most recent call last): (...) File ".../logging/__init__.py", line 1463, in error File ".../logging/__init__.py", line 1577, in _log File ".../logging/__init__.py", line 1587, in handle File ".../logging/__init__.py", line 1649, in callHandlers File ".../logging/__init__.py", line 948, in handle File ".../logging/__init__.py", line 1182, in emit File ".../logging/__init__.py", line 1171, in _open NameError: name 'open' is not defined
2020-10-27bpo-42161: Use _PyLong_GetZero() and _PyLong_GetOne() (GH-22995)Victor Stinner-2/+3
Use _PyLong_GetZero() and _PyLong_GetOne() in Objects/ and Python/ directories.
2020-06-10bpo-39465: Use _PyInterpreterState_GET() (GH-20788)Victor Stinner-6/+6
Replace _PyThreadState_GET() with _PyInterpreterState_GET() in: * get_small_int() * gcmodule.c: add also get_gc_state() function * _PyTrash_deposit_object() * _PyTrash_destroy_chain() * warnings_get_state() * Py_GetRecursionLimit() Cleanup listnode.c: add 'parser' variable.
2020-04-29bpo-40421: Add PyFrame_GetBack() function (GH-19765)Victor Stinner-6/+12
New PyFrame_GetBack() function: get the frame next outer frame. Replace frame->f_back with PyFrame_GetBack(frame) in most code but frameobject.c, ceval.c and genobject.c.
2020-04-29bpo-40429: PyFrame_GetCode() now returns a strong reference (GH-19773)Victor Stinner-1/+5
2020-04-29bpo-40429: PyFrame_GetCode() result cannot be NULL (GH-19772)Victor Stinner-4/+0
Add frame_nslots() to factorize duplicate code.
2020-04-28bpo-40421: Add PyFrame_GetCode() function (GH-19757)Victor Stinner-5/+13
PyFrame_GetCode(frame): return a borrowed reference to the frame code. Replace frame->f_code with PyFrame_GetCode(frame) in most code, except in frameobject.c, genobject.c and ceval.c. Also add PyFrame_GetLineNumber() to the limited C API.
2020-04-14bpo-40268: Remove a few pycore_pystate.h includes (GH-19510)Victor Stinner-1/+1
2020-04-14bpo-40268: Rename _PyInterpreterState_GET_UNSAFE() (GH-19509)Victor Stinner-2/+2
Rename _PyInterpreterState_GET_UNSAFE() to _PyInterpreterState_GET() for consistency with _PyThreadState_GET() and to have a shorter name (help to fit into 80 columns). Add also "assert(tstate != NULL);" to the function.
2020-04-14bpo-40268: Include explicitly pycore_interp.h (GH-19505)Victor Stinner-0/+1
pycore_pystate.h no longer includes pycore_interp.h: it's now included explicitly in files accessing PyInterpreterState.
2020-04-11bpo-39943: Add the const qualifier to pointers on non-mutable PyUnicode ↵Serhiy Storchaka-2/+2
data. (GH-19345)
2020-03-31bpo-32591: _PyErr_WarnUnawaitedCoroutine() sets source (GH-19247)Victor Stinner-3/+20
The _PyErr_WarnUnawaitedCoroutine() fallback now also sets the coroutine object as the source of the warning, as done by the Python implementation warnings._warn_unawaited_coroutine(). Moreover, don't truncate the coroutine name: Python supports arbitrary string length to format the message.
2020-03-14bpo-39585: Delete a pending comment in _warning.c (GH-18414)Hai Shi-1/+2
2020-03-03bpo-39831: Remove outdated comment. (GH-18764)Serhiy Storchaka-3/+1
2020-03-02bpo-39831: Fix a reference leak in PyErr_WarnEx(). (GH-18750)Serhiy Storchaka-2/+3
2020-03-02bpo-39796: Fix _warnings module initialization (GH-18739)Victor Stinner-13/+24
* Add _PyWarnings_InitState() which only initializes the _warnings module state (tstate->interp->warnings) without creating a module object * Py_InitializeFromConfig() now calls _PyWarnings_InitState() instead of _PyWarnings_Init() * Rename also private functions of _warnings.c to avoid confusion between the public C API and the private C API.
2020-02-11bpo-39245: Switch to public API for Vectorcall (GH-18460)Petr Viktorin-4/+4
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
2020-02-07bpo-39573: Use Py_TYPE() macro in Python and Include directories (GH-18391)Victor Stinner-2/+2
Replace direct access to PyObject.ob_type with Py_TYPE().
2020-01-30bpo-39487: Merge duplicated _Py_IDENTIFIER identifiers in C code (GH-18254)Hai Shi-3/+2
Moving repetitive `_Py_IDENTIFIER` instances to a global location helps identify them more easily in regards to sub-interpreter support.
2019-11-14bpo-38644: Add _PyObject_Call() (GH-17089)Victor Stinner-3/+5
* Add pycore_call.h internal header file. * Add _PyObject_Call(): PyObject_Call() with tstate * Add _PyObject_CallNoArgTstate(): _PyObject_CallNoArg() with tstate * Add _PyObject_FastCallDictTstate(): _PyObject_FastCallDict() with tstate * _PyObject_Call_Prepend() now takes tstate * Replace _PyObject_FastCall() calls with _PyObject_VectorcallTstate() calls
2019-10-08Fix typo in _warnings.warn_explicit() docstring (GH-16625)Hansraj Das-1/+1
2019-07-11bpo-37547: add _PyObject_CallMethodOneArg (GH-14685)Jeroen Demeyer-1/+1
2019-07-04bpo-37483: add _PyObject_CallOneArg() function (#14558)Jeroen Demeyer-4/+4
2019-05-10bpo-36737: Use the module state C-API for warnings. (gh-13159)Eric Snow-119/+198
2019-04-26bpo-36724: Add _PyWarnings_Fini() (#12963)Victor Stinner-16/+27
Py_FinalizeEx() now clears _PyRuntime.warnings variables and _PyRuntime.exitfuncs. Changes: * Add _PyWarnings_Fini(): called by Py_FinalizeEx() * call_ll_exitfuncs() now clears _PyRuntime.exitfuncs while iterating on it (on backward order).
2019-02-25bpo-35459: Use PyDict_GetItemWithError() instead of PyDict_GetItem(). (GH-11112)Serhiy Storchaka-5/+16
2018-12-11bpo-35454: Fix miscellaneous minor issues in error handling. (#11077)Serhiy Storchaka-1/+5
* bpo-35454: Fix miscellaneous minor issues in error handling. * Fix a null pointer dereference.
2018-11-27bpo-33012: Fix invalid function cast warnings with gcc 8. (GH-6749)Serhiy Storchaka-1/+1
Fix invalid function cast warnings with gcc 8 for method conventions different from METH_NOARGS, METH_O and METH_VARARGS excluding Argument Clinic generated code.
2018-11-12bpo-35081: Rename internal headers (GH-10275)Victor Stinner-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
2018-11-01bpo-35081: Add _PyThreadState_GET() internal macro (GH-10266)Victor Stinner-1/+1
If Py_BUILD_CORE is defined, the PyThreadState_GET() macro access _PyRuntime which comes from the internal pycore_state.h header. Public headers must not require internal headers. Move PyThreadState_GET() and _PyInterpreterState_GET_UNSAFE() from Include/pystate.h to Include/internal/pycore_state.h, and rename PyThreadState_GET() to _PyThreadState_GET() there. The PyThreadState_GET() macro of pystate.h is now redefined when pycore_state.h is included, to use the fast _PyThreadState_GET(). Changes: * Add _PyThreadState_GET() macro * Replace "PyThreadState_GET()->interp" with _PyInterpreterState_GET_UNSAFE() * Replace PyThreadState_GET() with _PyThreadState_GET() in internal C files (compiled with Py_BUILD_CORE defined), but keep PyThreadState_GET() in the public header files. * _testcapimodule.c: replace PyThreadState_GET() with PyThreadState_Get(); the module is not compiled with Py_BUILD_CORE defined. * pycore_state.h now requires Py_BUILD_CORE to be defined.
2018-11-01bpo-35081: Add pycore_ prefix to internal header files (GH-10263)Victor Stinner-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".
2018-09-12closes bpo-34646: Remove PyAPI_* macros from declarations. (GH-9218)Benjamin Peterson-1/+1
2018-08-03bpo-34301: Add _PyInterpreterState_Get() helper function (GH-8592)Victor Stinner-2/+2
sys_setcheckinterval() now uses a local variable to parse arguments, before writing into interp->check_interval.
2018-06-09bpo-33375: Fix GCC warning in Python/_warnings.c (GH-7556)Zackery Spytz-1/+0
_Py_IDENTIFIER(argv) is now unused.
2018-06-08bpo-33375: Get filename for warnings from frame.f_code.co_filename (GH-6622)Thomas Kluyver-66/+4
More consistent with how other parts of Python find the filename (e.g. tracebacks and pdb).
2018-05-15bpo-33509: Fix _warnings for module_globals=None (#6833)Victor Stinner-1/+8
Don't crash on warnings.warn_explicit() if module_globals is not a dict.