Commit graph

95 commits

Author SHA1 Message Date
Eric Snow 93c92f7d1d bpo-31404: Revert "remove modules from Py_InterpreterState (#1638)" (#3565)
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-13 23:46:04 -07:00
Oren Milman 9d984fd2b0 bpo-31416: Fix assertion failures in case of a bad warnings.filters or warnings.defaultaction. (#3496)
Patch by Oren Milman.
2017-09-12 00:18:09 +03:00
Oren Milman 252033d50e bpo-31411: Prevent raising a SystemError in case warnings.onceregistry is not a dictionary. (#3485) 2017-09-11 09:28:39 +03:00
Eric Snow 2ebc5ce42a bpo-30860: Consolidate stateful runtime globals. (#3397)
* 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-07 23:51:28 -06:00
Eric Snow 05351c1bd8 Revert "bpo-30860: Consolidate stateful runtime globals." (#3379)
Windows buildbots started failing due to include-related errors.
2017-09-05 21:43:08 -07:00
Eric Snow 76d5abc868 bpo-30860: Consolidate stateful runtime globals. (#2594)
* 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-05 18:26:16 -07:00
Eric Snow 86b7afdfee bpo-28411: Remove "modules" field from Py_InterpreterState. (#1638)
sys.modules is the one true source.
2017-09-04 17:54:09 -06:00
Serhiy Storchaka ba85d69a3e bpo-29878: Add global instances of int for 0 and 1. (#852) 2017-03-30 09:09:41 +03:00
Victor Stinner 22f18750a5 Issue #20185: Convert _warnings.warn() to Argument Clinic
Fix warn_explicit(): interpret source=None as source=NULL.
2016-12-09 18:08:18 +01:00
Victor Stinner 55ba38a480 Use _PyObject_CallMethodIdObjArgs()
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-09 16:09:30 +01:00
Victor Stinner 7bfb42d5b7 Issue #28858: Remove _PyObject_CallArg1() macro
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-05 17:04:32 +01:00
Victor Stinner de4ae3d486 Backed out changeset b9c9691c72c5
Issue #28858: The change b9c9691c72c5 introduced a regression. It seems like
_PyObject_CallArg1() uses more stack memory than
PyObject_CallFunctionObjArgs().
2016-12-04 22:59:09 +01:00
Victor Stinner 4778eab1f2 Replace PyObject_CallFunction() with fastcall
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-01 14:51:04 +01:00
Victor Stinner 27580c1fb5 Replace PyObject_CallFunctionObjArgs() with fastcall
* 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-12-01 14:43:22 +01:00
Serhiy Storchaka 3b73ea1278 Issue #28701: Replace PyUnicode_CompareWithASCIIString with _PyUnicode_EqualToASCIIString.
The latter function is more readable, faster and doesn't raise exceptions.
2016-11-16 10:19:20 +02:00
Serhiy Storchaka f4934ea77d Issue #28701: Replace PyUnicode_CompareWithASCIIString with _PyUnicode_EqualToASCIIString.
The latter function is more readable, faster and doesn't raise exceptions.
2016-11-16 10:17:58 +02:00
Serhiy Storchaka f01e408c16 Issue #26200: Added Py_SETREF and replaced Py_XSETREF with Py_SETREF
in places where Py_DECREF was used.
2016-04-10 18:12:01 +03:00
Serhiy Storchaka 57a01d3a0e Issue #26200: Added Py_SETREF and replaced Py_XSETREF with Py_SETREF
in places where Py_DECREF was used.
2016-04-10 18:05:40 +03:00
Serhiy Storchaka ec39756960 Issue #22570: Renamed Py_SETREF to Py_XSETREF. 2016-04-06 09:50:03 +03:00
Serhiy Storchaka 48842714b9 Issue #22570: Renamed Py_SETREF to Py_XSETREF. 2016-04-06 09:45:48 +03:00
Victor Stinner 023654fa68 get_warnings_attr(): Fix coverity warning
Don't check if the dict key exists before getting the key. Instead get the key
and handle error.
2016-03-23 17:48:22 +01:00
Victor Stinner e98445a4de _warnings.warn_explicit(): try to import warnings
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-23 00:54:48 +01:00
Victor Stinner e19558af1b Add a source parameter to warnings.warn()
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-23 00:28:08 +01:00
Victor Stinner 914cde89d4 On ResourceWarning, log traceback where the object was allocated
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-19 01:03:51 +01:00
Victor Stinner 1231a4615f Add _showwarnmsg() and _formatwarnmsg() to warnings
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.
2016-03-19 00:47:17 +01:00
Serhiy Storchaka ef1585eb9a Issue #25923: Added more const qualifiers to signatures of static and private functions. 2015-12-25 20:01:53 +02:00
Serhiy Storchaka 5a57ade58e Issue #20440: Massive replacing unsafe attribute setting code with special
macro Py_SETREF.
2015-12-24 10:35:59 +02:00
Larry Hastings 714e49371b Issue #24305: Prevent import subsystem stack frames from being counted
by the warnings.warn(stacklevel=) parameter.
2015-09-06 00:39:37 -07:00
Benjamin Peterson 63a6a6fd41 merge 3.4 (#24096) 2015-05-03 11:29:58 -04:00
Benjamin Peterson 8c59816b70 merge 3.3 (#24096) 2015-05-03 11:28:46 -04:00
Benjamin Peterson deff2b76ec be more robust against the filters list changing under us (closes #24096) 2015-05-03 11:23:37 -04:00
Brett Cannon f299abdafa Issue #23731: Implement PEP 488.
The concept of .pyo files no longer exists. Now .pyc files have an
optional `opt-` tag which specifies if any extra optimizations beyond
the peepholer were applied.
2015-04-13 14:21:02 -04:00
Antoine Pitrou 87538e7bc4 Issue #4180: The warnings registries are now reset when the filters are modified. 2014-09-18 02:42:05 +02:00
Antoine Pitrou cb0a006fd1 Issue #4180: The warnings registries are now reset when the filters are modified. 2014-09-18 02:40:46 +02:00
Berker Peksag d8089e0d04 Issue #16382: Improve exception message of warnings.warn() for bad category.
Initial patch by Phil Elson.
2014-07-11 19:50:25 +03:00
Victor Stinner bd303c165b Issue #19512, #19515: remove shared identifiers, move identifiers where they
are used.

Move also _Py_IDENTIFIER() defintions to the top in modified files to remove
identifiers duplicated in the same file.
2013-11-07 23:07:29 +01:00
Victor Stinner 090543736f Issue #19512: add some common identifiers to only create common strings once,
instead of creating temporary Unicode string objects

Add also more identifiers in pythonrun.c to avoid temporary Unicode string
objets for the interactive interpreter.
2013-11-06 22:41:44 +01:00
Victor Stinner dcdd05b0b4 Close #19442: warn_explicit() does nothing when called late during Python shutdown
After more tests, I now think that it is the safest option.
2013-11-01 00:55:30 +01:00
Victor Stinner ae233eab5c Issue #19437: Fix show_warning() of _warnings, stop at the first error to not
call a Python function with an exception set
2013-10-31 14:51:38 +01:00
Victor Stinner 3cd04aa1b2 Issue #19437: Fix get_filter() from _warnings, don't call PyObject_IsSubclass()
with an exception set
2013-10-31 14:46:00 +01:00
Victor Stinner 856f45f09c Issue #19442: Fix warnings emitted during Python shutdown
Warnings may be emitted during Python shutdown, like "unclosed file XXX".
During shutdown, globals()['__main__'] may be None.
2013-10-30 00:04:59 +01:00
Victor Stinner a4c704b260 Issue #19424: Fix the warnings module to accept filename containing surrogate
characters.
2013-10-29 23:43:41 +01:00
Victor Stinner ce5f4fba11 Issue #19421: fix a check in warnings.warn() to be able to use it during Python
finalization.

sys.argv is set to None during Python finalization: add PyList_Check() to avoid
a crash in PyList_Size().
2013-10-28 18:47:22 +01:00
Victor Stinner 14e461d5b9 Close #11619: The parser and the import machinery do not encode Unicode
filenames anymore on Windows.
2013-08-26 22:28:21 +02:00
Victor Stinner 78e2c985ac Issue #18408: Fix show_warning(), clear also the exception raised by
_Py_DisplaySourceLine()

For example, _PyGC_DumpShutdownStats() calls PyErr_WarnExplicitFormat() while
the import machinery does not work anymore, _Py_DisplaySourceLine() fails when
trying to import the io module.
2013-07-16 01:54:37 +02:00
Antoine Pitrou 070cb3c9be Issue #1545463: At shutdown, defer finalization of codec modules so that stderr remains usable.
(should fix Windows buildbot failures on test_gc)
2013-05-08 13:23:25 +02:00
Antoine Pitrou aa5c5c60f1 Finally fix all test_capi refleaks 2012-01-18 21:45:15 +01:00
Benjamin Peterson 21e0da228d remove some usage of Py_UNICODE_TOUPPER/LOWER 2012-01-11 21:00:42 -05:00
Florent Xicluna 720682efd1 Merge 3.2 2011-12-09 23:42:29 +01:00
Florent Xicluna 5126df602c Remove obsolete py3k comment. 2011-12-09 23:41:21 +01:00