summaryrefslogtreecommitdiff
path: root/Python/_warnings.c
AgeCommit message (Collapse)AuthorLines
2018-12-10bpo-35454: Fix miscellaneous minor issues in error handling. (GH-11077)Miss Islington (bot)-1/+5
* bpo-35454: Fix miscellaneous minor issues in error handling. * Fix a null pointer dereference. (cherry picked from commit 8905fcc85a6fc3ac394bc89b0bbf40897e9497a6) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2018-05-15bpo-33509: Fix _warnings for module_globals=None (GH-6833)Miss Islington (bot)-1/+8
Don't crash on warnings.warn_explicit() if module_globals is not a dict. (cherry picked from commit b056562860c227bad2e0ba7cd3130e115c007768) Co-authored-by: Victor Stinner <vstinner@redhat.com>
2018-01-26bpo-32591: fix abort in _PyErr_WarnUnawaitedCoroutine during shutdown (#5337)Nathaniel J. Smith-0/+7
When an unawaited coroutine is collected very late in shutdown -- like, during the final GC at the end of PyImport_Cleanup -- then it was triggering an interpreter abort, because we'd try to look up the "warnings" module and not only was it missing (we were prepared for that), but the entire module system was missing (which we were not prepared for). I've tried to fix this at the source, by making the utility function get_warnings_attr robust against this in general. Note that it already has the convention that it can return NULL without setting an error, which is how it signals that the attribute it was asked to fetch is missing, and that all callers already check for NULL returns. There's a similar check for being late in shutdown at the top of warn_explicit, which might be unnecessary after this fix, but I'm not sure so I'm going to leave it.
2018-01-25 bpo-32571: Avoid raising unneeded AttributeError and silencing it in C code ↵Serhiy Storchaka-8/+2
(GH-5222) Add two new private APIs: _PyObject_LookupAttr() and _PyObject_LookupAttrId()
2018-01-21bpo-32591: Fix PyExc_WarnFormat call (follow-up commit) (#5263)Yury Selivanov-5/+4
The previous version was correct in terms of behaviour, but checking the return value of PyErr_WarnFormat allows to avoid calling PyErr_Occurred and silences the coverity alarm.
2018-01-21bpo-32591: Add native coroutine origin tracking (#5250)Nathaniel J. Smith-0/+47
* Add coro.cr_origin and sys.set_coroutine_origin_tracking_depth * Use coroutine origin information in the unawaited coroutine warning * Stop using set_coroutine_wrapper in asyncio debug mode * In BaseEventLoop.set_debug, enable debugging in the correct thread
2018-01-08bpo-31975 (PEP 565): Show DeprecationWarning in __main__ (GH-4458)Nick Coghlan-7/+33
- primary change is to add a new default filter entry for 'default::DeprecationWarning:__main__' - secondary change is an internal one to cope with plain strings in the warning module's internal filter list (this avoids the need to create a compiled regex object early on during interpreter startup) - assorted documentation updates, including many more examples of configuring the warnings settings - additional tests to ensure that both the pure Python and the C accelerated warnings modules have the expected default configuration
2017-12-19bpo-32030: Fix compiler warnings (#4921)Victor Stinner-13/+4
Fix compiler warnings in Py_FinalizeEx(): only define variables if they are needed, add #ifdef. Other cleanup changes: * _PyWarnings_InitWithConfig() is no more needed: call _PyWarnings_Init() instead. * Inline pymain_init_main_interpreter() in its caller. This subfunction is no more justifed.
2017-12-12bpo-32230: Set sys.warnoptions with -X dev (#4820)Victor Stinner-51/+22
Rather than supporting dev mode directly in the warnings module, this instead adjusts the initialisation code to add an extra 'default' entry to sys.warnoptions when dev mode is enabled. This ensures that dev mode behaves *exactly* as if `-Wdefault` had been passed on the command line, including in the way it interacts with `sys.warnoptions`, and with other command line flags like `-bb`. Fix also bpo-20361: have -b & -bb options take precedence over any other warnings options. Patch written by Nick Coghlan, with minor modifications of Victor Stinner.
2017-11-27bpo-27535: Fix memory leak with warnings ignore (#4489)Victor Stinner-4/+9
The warnings module doesn't leak memory anymore in the hidden warnings registry for the "ignore" action of warnings filters. The warn_explicit() function doesn't add the warning key to the registry anymore for the "ignore" action.
2017-11-27bpo-32089: Use default action for ResourceWarning (#4584)Victor Stinner-3/+2
In development and debug mode, use the "default" action, rather than the "always" action, for ResourceWarning in the default warnings filters.
2017-11-23bpo-27535: Cleanup create_filter() (#4516)Victor Stinner-38/+18
create_filter() now expects the action as a _Py_Identifier which avoids string comparison, and more important, to avoid handling the "unknown action" annoying case.
2017-11-23bpo-32030: Add _PyMainInterpreterConfig.pythonhome (#4513)Victor Stinner-6/+14
* Py_Main() now reads the PYTHONHOME environment variable * Add _Py_GetPythonHomeWithConfig() private function * Add _PyWarnings_InitWithConfig() * init_filters() doesn't get the current core configuration from the current interpreter or Python thread anymore. Pass explicitly the configuration to _PyWarnings_InitWithConfig(). * _Py_InitializeCore() now fails on _PyWarnings_InitWithConfig() failure. * Pass configuration as constant
2017-11-22bpo-27535: Optimize warnings.warn() (#4508)Victor Stinner-42/+33
* Optimize warnings.filterwarnings(). Replace re.compile('') with None to avoid the cost of calling a regex.match() method, whereas it always matchs. * Optimize get_warnings_attr(): replace PyObject_GetAttrString() with _PyObject_GetAttrId(). Cleanup also create_filter(): * Use _Py_IDENTIFIER() to allow to cleanup strings at Python finalization * Replace Py_FatalError() with a regular exceptions
2017-11-20bpo-32089: Fix warnings filters in dev mode (#4482)Victor Stinner-10/+27
The developer mode (-X dev) now creates all default warnings filters to order filters in the correct order to always show ResourceWarning and make BytesWarning depend on the -b option. Write a functional test to make sure that ResourceWarning is logged twice at the same location in the developer mode. Add a new 'dev_mode' field to _PyCoreConfig.
2017-11-20bpo-32088: Display Deprecation in debug mode (#4474)Victor Stinner-0/+7
When Python is build is debug mode (Py_DEBUG), DeprecationWarning, PendingDeprecationWarning and ImportWarning warnings are now displayed by default. test_venv: run "-m pip" and "-m ensurepip._uninstall" with -W ignore::DeprecationWarning since pip code is not part of Python.
2017-11-11bpo-31572: Don't silence unexpected errors in the _warnings module. (#3731)Serhiy Storchaka-68/+89
Get rid of _PyObject_HasAttrId() and PyDict_GetItemString(). Silence only expected AttributeError, KeyError and ImportError when get an attribute, look up in a dict or import a module.
2017-11-05Fix miscellaneous typos (#4275)luzpaz-1/+1
2017-09-29bpo-31285: Remove splitlines identifier from Python/_warnings.c (#3803)Oren Milman-3/+0
(forgot to remove it in #3219)
2017-09-24bpo-31566: Fix an assertion failure in _warnings.warn() in case of a bad ↵Oren Milman-3/+4
__name__ global. (#3717)
2017-09-24bpo-31285: Fix an assertion failure and a SystemError in ↵Oren Milman-3/+1
warnings.warn_explicit. (#3219)
2017-09-15bpo-28411: Support other mappings in PyInterpreterState.modules. (#3593)Eric Snow-6/+1
The concrete PyDict_* API is used to interact with PyInterpreterState.modules in a number of places. This isn't compatible with all dict subclasses, nor with other Mapping implementations. This patch switches the concrete API usage to the corresponding abstract API calls. We also add a PyImport_GetModule() function (and some other helpers) to reduce a bunch of code duplication.
2017-09-13bpo-31404: Revert "remove modules from Py_InterpreterState (#1638)" (#3565)Eric Snow-1/+4
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.
2017-09-12bpo-31416: Fix assertion failures in case of a bad warnings.filters or ↵Oren Milman-3/+16
warnings.defaultaction. (#3496) Patch by Oren Milman.
2017-09-11bpo-31411: Prevent raising a SystemError in case warnings.onceregistry is ↵Oren Milman-1/+7
not a dictionary. (#3485)
2017-09-07bpo-30860: Consolidate stateful runtime globals. (#3397)Eric Snow-41/+39
* 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).
2017-09-05Revert "bpo-30860: Consolidate stateful runtime globals." (#3379)Eric Snow-38/+41
Windows buildbots started failing due to include-related errors.
2017-09-05bpo-30860: Consolidate stateful runtime globals. (#2594)Eric Snow-41/+38
* 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).
2017-09-04bpo-28411: Remove "modules" field from Py_InterpreterState. (#1638)Eric Snow-4/+1
sys.modules is the one true source.
2017-03-30bpo-29878: Add global instances of int for 0 and 1. (#852)Serhiy Storchaka-15/+4
2016-12-09Issue #20185: Convert _warnings.warn() to Argument ClinicVictor Stinner-16/+21
Fix warn_explicit(): interpret source=None as source=NULL.
2016-12-09Use _PyObject_CallMethodIdObjArgs()Victor Stinner-1/+1
Issue #28915: Replace _PyObject_CallMethodId() with _PyObject_CallMethodIdObjArgs() in various modules when the format string was only made of "O" formats, PyObject* arguments. _PyObject_CallMethodIdObjArgs() avoids the creation of a temporary tuple and doesn't have to parse a format string.
2016-12-05Issue #28858: Remove _PyObject_CallArg1() macroVictor Stinner-1/+1
Replace _PyObject_CallArg1(func, arg) with PyObject_CallFunctionObjArgs(func, arg, NULL) Using the _PyObject_CallArg1() macro increases the usage of the C stack, which was unexpected and unwanted. PyObject_CallFunctionObjArgs() doesn't have this issue.
2016-12-04Backed out changeset b9c9691c72c5Victor Stinner-1/+1
Issue #28858: The change b9c9691c72c5 introduced a regression. It seems like _PyObject_CallArg1() uses more stack memory than PyObject_CallFunctionObjArgs().
2016-12-01Replace PyObject_CallFunction() with fastcallVictor Stinner-1/+1
Replace PyObject_CallFunction(func, "O", arg) and PyObject_CallFunction(func, "O", arg, NULL) with _PyObject_CallArg1(func, arg) Replace PyObject_CallFunction(func, NULL) with _PyObject_CallNoArg(func) _PyObject_CallNoArg() and _PyObject_CallArg1() are simpler and don't allocate memory on the C stack.
2016-12-01Replace PyObject_CallFunctionObjArgs() with fastcallVictor Stinner-1/+1
* PyObject_CallFunctionObjArgs(func, NULL) => _PyObject_CallNoArg(func) * PyObject_CallFunctionObjArgs(func, arg, NULL) => _PyObject_CallArg1(func, arg) PyObject_CallFunctionObjArgs() allocates 40 bytes on the C stack and requires extra work to "parse" C arguments to build a C array of PyObject*. _PyObject_CallNoArg() and _PyObject_CallArg1() are simpler and don't allocate memory on the C stack. This change is part of the fastcall project. The change on listsort() is related to the issue #23507.
2016-11-16Issue #28701: Replace PyUnicode_CompareWithASCIIString with ↵Serhiy Storchaka-7/+7
_PyUnicode_EqualToASCIIString. The latter function is more readable, faster and doesn't raise exceptions.
2016-11-16Issue #28701: Replace PyUnicode_CompareWithASCIIString with ↵Serhiy Storchaka-7/+7
_PyUnicode_EqualToASCIIString. The latter function is more readable, faster and doesn't raise exceptions.
2016-04-10Issue #26200: Added Py_SETREF and replaced Py_XSETREF with Py_SETREFSerhiy Storchaka-1/+1
in places where Py_DECREF was used.
2016-04-10Issue #26200: Added Py_SETREF and replaced Py_XSETREF with Py_SETREFSerhiy Storchaka-1/+1
in places where Py_DECREF was used.
2016-04-06Issue #22570: Renamed Py_SETREF to Py_XSETREF.Serhiy Storchaka-1/+1
2016-04-06Issue #22570: Renamed Py_SETREF to Py_XSETREF.Serhiy Storchaka-1/+1
2016-03-23get_warnings_attr(): Fix coverity warningVictor Stinner-4/+3
Don't check if the dict key exists before getting the key. Instead get the key and handle error.
2016-03-23_warnings.warn_explicit(): try to import warningsVictor Stinner-14/+36
Issue #26592: _warnings.warn_explicit() now tries to import the warnings module (Python implementation) if the source parameter is set to be able to log the traceback where the source was allocated.
2016-03-23Add a source parameter to warnings.warn()Victor Stinner-5/+6
Issue #26604: * Add a new optional source parameter to _warnings.warn() and warnings.warn() * Modify asyncore, asyncio and _pyio modules to set the source parameter when logging a ResourceWarning warning
2016-03-19On ResourceWarning, log traceback where the object was allocatedVictor Stinner-29/+62
Issue #26567: * Add a new function PyErr_ResourceWarning() function to pass the destroyed object * Add a source attribute to warnings.WarningMessage * Add warnings._showwarnmsg() which uses tracemalloc to get the traceback where source object was allocated.
2016-03-19Add _showwarnmsg() and _formatwarnmsg() to warningsVictor Stinner-25/+53
Issue #26568: add new _showwarnmsg() and _formatwarnmsg() functions to the warnings module. The C function warn_explicit() now calls warnings._showwarnmsg() with a warnings.WarningMessage as parameter, instead of calling warnings.showwarning() with multiple parameters. _showwarnmsg() calls warnings.showwarning() if warnings.showwarning() was replaced. Same for _formatwarnmsg(): call warnings.formatwarning() if it was replaced.
2015-12-25Issue #25923: Added more const qualifiers to signatures of static and ↵Serhiy Storchaka-1/+1
private functions.
2015-12-24Issue #20440: Massive replacing unsafe attribute setting code with specialSerhiy Storchaka-2/+1
macro Py_SETREF.
2015-09-06Issue #24305: Prevent import subsystem stack frames from being countedLarry Hastings-2/+70
by the warnings.warn(stacklevel=) parameter.