Commit Graph

5531 Commits

Author SHA1 Message Date
Serhiy Storchaka 131b8f8eee Issue #26718: super.__init__ no longer leaks memory if called multiple times.
NOTE: A direct call of super.__init__ is not endorsed!
2016-04-13 15:28:53 +03:00
Serhiy Storchaka 3d7497608b Issue #26718: super.__init__ no longer leaks memory if called multiple times.
NOTE: A direct call of super.__init__ is not endorsed!
2016-04-13 15:27:33 +03:00
Serhiy Storchaka 59865e7fe1 Issue #26200: Restored more safe usages of Py_SETREF. 2016-04-11 09:57:37 +03: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 03f17f8671 Issue #17339: Improved TypeError message in bytes constructor. 2016-04-10 14:44:59 +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
Serhiy Storchaka ab479c49d3 Issue #26494: Fixed crash on iterating exhausting iterators.
Affected classes are generic sequence iterators, iterators of str, bytes,
bytearray, list, tuple, set, frozenset, dict, OrderedDict, corresponding
views and os.scandir() iterator.
2016-03-30 20:41:15 +03:00
Serhiy Storchaka fbb1c5ee06 Issue #26494: Fixed crash on iterating exhausting iterators.
Affected classes are generic sequence iterators, iterators of str, bytes,
bytearray, list, tuple, set, frozenset, dict, OrderedDict, corresponding
views and os.scandir() iterator.
2016-03-30 20:40:02 +03:00
Raymond Hettinger 3625af5f21 Moved misplaced functions to the section for C API functions. 2016-03-27 01:15:07 -07:00
Raymond Hettinger 2c257ab0f8 Responsibility for argument checking belongs in set.__init__() rather than set.__new__().
See dict.__new__() and list.__new__() for comparison.  Neither of those examine or touch
args or kwds.  That work is done in the __init__() methods.
2016-03-26 04:10:11 -07:00
Raymond Hettinger b72e21b9ab Speed-up construction of empty sets by approx 12-14%. 2016-03-25 02:29:59 -07:00
Victor Stinner f963c13597 longobject.c: fix compilation warning on Windows 64-bit
We know that Py_SIZE(b) is -1 or 1 an so fits into the sdigit type.
2016-03-23 18:36:54 +01:00
Victor Stinner 0aed3a4ebc _PyMem_DebugFree(): fix compiler warning on Windows
Don't return a void value.
2016-03-23 11:30:43 +01:00
Victor Stinner fac395681f Optimize bytes.replace(b'', b'.')
Issue #26574: Optimize bytes.replace(b'', b'.') and
bytearray.replace(b'', b'.'): up to 80% faster. Patch written by Josh Snider.
2016-03-21 10:38:58 +01:00
Victor Stinner ad524375af Fail if PyMem_Malloc() is called without holding the GIL
Issue #26563: Debug hooks on Python memory allocators now raise a fatal error
if functions of the PyMem_Malloc() family are called without holding the GIL.
2016-03-16 12:12:53 +01:00
Victor Stinner ffcf1a54d3 Oops, revert unwanted change used to create an example
Issue #26564.
2016-03-15 22:49:40 +01:00
Victor Stinner 0611c26a58 On memory error, dump the memory block traceback
Issue #26564: _PyObject_DebugDumpAddress() now dumps the traceback where a
memory block was allocated on memory block. Use the tracemalloc module to get
the traceback.
2016-03-15 22:22:13 +01:00
Victor Stinner c4aec3628b Check the GIL in PyObject_Malloc()
Issue #26558: The debug hook of PyObject_Malloc() now checks that the GIL is
held when the function is called.
2016-03-14 22:26:53 +01:00
Victor Stinner 34be807ca4 Add PYTHONMALLOC env var
Issue #26516:

* Add PYTHONMALLOC environment variable to set the Python memory
  allocators and/or install debug hooks.
* PyMem_SetupDebugHooks() can now also be used on Python compiled in release
  mode.
* The PYTHONMALLOCSTATS environment variable can now also be used on Python
  compiled in release mode. It now has no effect if set to an empty string.
* In debug mode, debug hooks are now also installed on Python memory allocators
  when Python is configured without pymalloc.
2016-03-14 12:04:26 +01:00
Benjamin Peterson 0f04bc7959 merge 3.5 (closes #26478) 2016-03-03 22:10:52 -08:00
Benjamin Peterson cfc2a1fc70 merge 3.4 (closes #26478) 2016-03-03 22:08:01 -08:00
Benjamin Peterson f11b25b081 properly use the ObjArgs variant of CallMethod in dictview binary operations (closes #26478) 2016-03-03 22:05:36 -08:00
Yury Selivanov d2dc15b26b Merge 3.5 (issue #25888) 2016-03-02 11:31:06 -05:00
Yury Selivanov c724bae51c coroutines: Error when awaiting on coroutine that's being awaited
Issue #25888
2016-03-02 11:30:46 -05:00
Victor Stinner f2192855dd Merge 3.5 2016-03-01 22:07:53 +01:00
Victor Stinner 337986740f Issue #26464: Fix unicode_fast_translate() again
Initialize i variable if the string is non-ASCII.
2016-03-01 21:59:58 +01:00
Victor Stinner 3d9d77a3dc Merge 3.5 2016-03-01 21:30:50 +01:00
Victor Stinner 6c9aa8f2bf Fix str.translate()
Issue #26464: Fix str.translate() when string is ASCII and first replacements
removes character, but next replacement uses a non-ASCII character or a string
longer than 1 character. Regression introduced in Python 3.5.0.
2016-03-01 21:30:30 +01:00
Yury Selivanov 3e48b38dff Merge 3.5 (issue #25887) 2016-02-13 18:00:31 -05:00
Yury Selivanov 77c96813ab Issue #25887: Raise a RuntimeError when a coroutine is awaited more than once. 2016-02-13 17:59:05 -05:00
Yury Selivanov e0b23095ee Issues #26289 and #26315: Optimize floor/modulo div for single-digit longs
Microbenchmarks show 2-2.5x improvement.  Built-in 'divmod' function
is now also ~10% faster.

-m timeit -s "x=22331" "x//2;x//-3;x//4;x//5;x//-6;x//7;x//8;x//-99;x//100;"
with patch: 0.321          without patch: 0.633

-m timeit -s "x=22331" "x%2;x%3;x%-4;x%5;x%6;x%-7;x%8;x%99;x%-100;"
with patch: 0.224          without patch: 0.66

Big thanks to Serhiy Storchaka, Mark Dickinson and Victor Stinner for
thorow code reviews and algorithms improvements.
2016-02-11 10:26:27 -05:00
Martin Panter 7e3a91a5fc Issue #26136: Upgrade the generator_stop warning to DeprecationWarning
Patch by Anish Shah.
2016-02-10 04:40:48 +00:00
Serhiy Storchaka d2962f145a Issue #25949: __dict__ for an OrderedDict instance is now created only when
needed.
2016-02-08 16:39:05 +02:00
Yury Selivanov a0fcaca4e1 Issue #26288: Fix comment 2016-02-06 12:21:33 -05:00
Yury Selivanov 186c30b7ae Issue #26288: Optimize PyLong_AsDouble. 2016-02-05 19:40:01 -05:00
Raymond Hettinger f50215412c Add early-out for the common case where kwds is NULL (gives 1.1% speedup). 2016-02-04 02:46:16 -08:00
Raymond Hettinger ce5179fcba Issue #23601: Use small object allocator for dict key objects 2016-01-31 08:56:21 -08:00
Victor Stinner 5b96f17b1c Merge 3.5 2016-01-27 17:01:13 +01:00
Victor Stinner 5bc03a6d4d Fix resize_compact()
Issue #26217: resize_compact() must set wstr_length to 0 after freeing the wstr
string. Otherwise, an assertion fails in _PyUnicode_CheckConsistency().
2016-01-27 16:56:53 +01:00
Raymond Hettinger 0dceb91866 Tests versus zero are more compact than tests versus -1. 2016-01-25 10:33:30 -08:00
Victor Stinner 3cdd5fb970 code_richcompare() now uses the constants types
Issue #25843: When compiling code, don't merge constants if they are equal but
have a different types. For example, "f1, f2 = lambda: 1, lambda: 1.0" is now
correctly compiled to two different functions: f1() returns 1 (int) and f2()
returns 1.0 (int), even if 1 and 1.0 are equal.

Add a new _PyCode_ConstantKey() private function.
2016-01-22 12:33:12 +01:00
Victor Stinner efb2413ce8 code_richcompare() now uses the constants types
Issue #25843: When compiling code, don't merge constants if they are equal but
have a different types. For example, "f1, f2 = lambda: 1, lambda: 1.0" is now
correctly compiled to two different functions: f1() returns 1 (int) and f2()
returns 1.0 (int), even if 1 and 1.0 are equal.

Add a new _PyCode_ConstantKey() private function.
2016-01-22 12:33:12 +01:00
Victor Stinner 9f78939552 Issue #26107: Fix typo in Objects/lnotab_notes.txt
Double parenthesis
2016-01-21 18:12:29 +01:00
Victor Stinner f3914eb16d co_lnotab supports negative line number delta
Issue #26107: The format of the co_lnotab attribute of code objects changes to
support negative line number delta.

Changes:

* assemble_lnotab(): if line number delta is less than -128 or greater than
  127, emit multiple (offset_delta, lineno_delta) in co_lnotab
* update functions decoding co_lnotab to use signed 8-bit integers

  - dis.findlinestarts()
  - PyCode_Addr2Line()
  - _PyCode_CheckLineNumber()
  - frame_setlineno()

* update lnotab_notes.txt
* increase importlib MAGIC_NUMBER to 3361
* document the change in What's New in Python 3.6
* cleanup also PyCode_Optimize() to use better variable names
2016-01-20 12:16:21 +01:00
Victor Stinner b56837a033 Merge 3.5
Issue #26154: Add a new private _PyThreadState_UncheckedGet() function.
2016-01-20 11:19:46 +01:00
Victor Stinner bfd316e750 Add _PyThreadState_UncheckedGet()
Issue #26154: Add a new private _PyThreadState_UncheckedGet() function which
gets the current thread state, but don't call Py_FatalError() if it is NULL.

Python 3.5.1 removed the _PyThreadState_Current symbol from the Python C API to
no more expose complex and private atomic types. Atomic types depends on the
compiler or can even depend on compiler options. The new function
_PyThreadState_UncheckedGet() allows to get the variable value without having
to care of the exact implementation of atomic types.

Changes:

* Replace direct usage of the _PyThreadState_Current variable with a call to
  _PyThreadState_UncheckedGet().
* In pystate.c, replace direct usage of the _PyThreadState_Current variable
  with the PyThreadState_GET() macro for readability.
* Document also PyThreadState_Get() in pystate.h
2016-01-20 11:12:38 +01:00
Serhiy Storchaka 4918b47c64 Issue #25935: Garbage collector now breaks reference loops with OrderedDict. 2016-01-19 14:48:42 +02:00
Serhiy Storchaka d205d0145c Issue #25935: Garbage collector now breaks reference loops with OrderedDict. 2016-01-19 14:46:25 +02:00
Benjamin Peterson 2c028492d4 merge 3.5 (#25731) 2016-01-18 21:18:35 -08:00
Benjamin Peterson 9ad11544bf set tp_new from the class in the hierarchy that actually owns the descriptor (closes #25731)
Debugging by Eryk Sun.
2016-01-18 21:11:18 -08:00
doko@ubuntu.com 3b63dc3aa9 - merge 3.5 2016-01-14 14:05:21 +01:00
doko@ubuntu.com 17210f50d2 dictobject.c(dict_sizeof): Make it static again. 2016-01-14 14:04:59 +01:00
Barry Warsaw 3d220cc4d7 As per further discussion, re-enable the typeobject.c guard for picklability.
upstreams such as Cython will have to adjust.
2016-01-11 15:51:27 -05:00
Barry Warsaw 09880c89e9 Comment out some tests that won't pass now that we've reverted the
picklability regression.  Also, as per further discussion, remove the
regressing code.
2016-01-11 15:14:53 -05:00
Barry Warsaw ec71f1779f Issue #22995: [UPDATE] Comment out the one of the pickleability tests in
_PyObject_GetState() due to regressions observed in Cython-based projects.
2016-01-11 13:49:40 -05:00
Barry Warsaw 885e1939be Issue #22995: [UPDATE] Comment out the one of the pickleability tests in
_PyObject_GetState() due to regressions observed in Cython-based projects.
2016-01-11 13:24:02 -05:00
Serhiy Storchaka 576f132b98 Issue #20440: Cleaning up the code by using Py_SETREF. 2016-01-05 21:27:54 +02:00
Benjamin Peterson 3e47a1337c merge 3.5 2016-01-01 11:56:35 -06:00
Benjamin Peterson 4e3dd51396 merge 3.4 2016-01-01 11:56:16 -06:00
Benjamin Peterson 630329e4ea merge 3.3 2016-01-01 11:55:47 -06:00
Benjamin Peterson 0e617e22f0 remove some copyright notices supserseded by the toplevel ones 2016-01-01 11:53:47 -06:00
Serhiy Storchaka 288cb25f1a Issue #25961: Disallowed null characters in the type name.
Simplified testing for null characters in __name__ setter.
2015-12-30 21:41:53 +02:00
Serhiy Storchaka 42bf8fc901 Issue #25961: Disallowed null characters in the type name.
Simplified testing for null characters in __name__ setter.
2015-12-30 21:40:49 +02:00
Serhiy Storchaka 4e6aad1f7a Clean up float.as_integer_ratio(). 2015-12-29 22:55:48 +02:00
Serhiy Storchaka 0d250bc119 Issue #25971: Optimized creating Fractions from floats by 2 times and from
Decimals by 3 times.
Unified error messages in float.as_integer_ratio(), Decimal.as_integer_ratio(),
and Fraction constructors.
2015-12-29 22:34:23 +02:00
Serhiy Storchaka 1ed017ae92 Issue #20440: Cleaning up the code by using Py_SETREF and Py_CLEAR.
Old code is correct, but with Py_SETREF and Py_CLEAR it can be cleaner.
This patch doesn't fix bugs and hence there is no need to backport it.
2015-12-27 15:51:32 +02:00
Serhiy Storchaka 726fc139a5 Issue #20440: More use of Py_SETREF.
This patch is manually crafted and contains changes that couldn't be handled
automatically.
2015-12-27 15:44:33 +02:00
Serhiy Storchaka 191321d11b Issue #20440: More use of Py_SETREF.
This patch is manually crafted and contains changes that couldn't be handled
automatically.
2015-12-27 15:41:34 +02:00
Serhiy Storchaka bdb908ea54 Issue #20440: Applied yet one patch for using Py_SETREF.
The patch is automatically generated, it replaces the code that uses Py_CLEAR.
2015-12-27 12:38:28 +02:00
Serhiy Storchaka 4a1e70fc31 Issue #20440: Applied yet one patch for using Py_SETREF.
The patch is automatically generated, it replaces the code that uses Py_CLEAR.
2015-12-27 12:36:18 +02:00
Serhiy Storchaka f9253c96fd Issue #22995: Instances of extension types with a state that aren't
subclasses of list or dict and haven't implemented any pickle-related
methods (__reduce__, __reduce_ex__, __getnewargs__, __getnewargs_ex__,
or __getstate__), can no longer be pickled.  Including memoryview.
2015-12-25 21:05:35 +02:00
Serhiy Storchaka f81be8aa3f Issue #22995: Instances of extension types with a state that aren't
subclasses of list or dict and haven't implemented any pickle-related
methods (__reduce__, __reduce_ex__, __getnewargs__, __getnewargs_ex__,
or __getstate__), can no longer be pickled.  Including memoryview.
2015-12-25 21:04:29 +02: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 2d06e84455 Issue #25923: Added the const qualifier to static constant arrays. 2015-12-25 19:53:18 +02:00
Serhiy Storchaka f006940351 Issue #20440: Massive replacing unsafe attribute setting code with special
macro Py_SETREF.
2015-12-24 10:39:57 +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
Serhiy Storchaka 3987e26e75 Issue #25914: Fixed and simplified OrderedDict.__sizeof__. 2015-12-22 08:22:05 +02:00
Serhiy Storchaka 0ce7a3a34c Issue #25914: Fixed and simplified OrderedDict.__sizeof__. 2015-12-22 08:16:18 +02:00
Serhiy Storchaka 3182db356c Issue #25766: Special method __bytes__() now works in str subclasses. 2015-12-20 16:37:21 +02:00
Serhiy Storchaka 5aac3ed799 Issue #25766: Special method __bytes__() now works in str subclasses. 2015-12-20 16:36:34 +02:00
Serhiy Storchaka a9406e77fa Issue #25421: __sizeof__ methods of builtin types now use dynamic basic size.
This allows sys.getsize() to work correctly with their subclasses with
__slots__ defined.
2015-12-19 20:07:11 +02:00
Serhiy Storchaka 5c4064e8bd Issue #25421: __sizeof__ methods of builtin types now use dynamic basic size.
This allows sys.getsize() to work correctly with their subclasses with
__slots__ defined.
2015-12-19 20:05:25 +02:00
Serhiy Storchaka 42bb126f0a Issue #25899: Converted Objects/listsort.txt to UTF-8.
Original patch by Chris Angelico.
2015-12-18 13:23:33 +02:00
Serhiy Storchaka 9b3a2eec1c Issues #25890, #25891, #25892: Removed unused variables in Windows code.
Reported by Alexander Riccio.
2015-12-18 10:03:13 +02:00
Raymond Hettinger e4495877dd Minor tweek. Counting down rather than up reduces register pressure. 2015-12-15 00:42:30 -08:00
Raymond Hettinger 86d322f020 Undo inadvertent line swap 2015-12-13 19:27:17 -08:00
Raymond Hettinger 5088f6005f Hoist constant expressions (so->table and so->mask) out of the inner-loop. 2015-12-13 18:45:01 -08:00
Serhiy Storchaka 7c088a9b5c Issue #25709: Fixed problem with in-place string concatenation and utf-8 cache. 2015-12-03 01:05:52 +02:00
Serhiy Storchaka 6648bf5661 Issue #25709: Fixed problem with in-place string concatenation and utf-8 cache. 2015-12-03 01:04:37 +02:00
Serhiy Storchaka 7aa690860e Issue #25709: Fixed problem with in-place string concatenation and utf-8 cache. 2015-12-03 01:02:03 +02:00
Serhiy Storchaka 6a50e79130 Issue #24097: Fixed crash in object.__reduce__() if slot name is freed inside
__getattr__.  Original patch by Antoine Pitrou.
2015-11-25 18:35:15 +02:00
Serhiy Storchaka 670d78abc5 Issue #24097: Fixed crash in object.__reduce__() if slot name is freed inside
__getattr__.  Original patch by Antoine Pitrou.
2015-11-25 18:34:19 +02:00
Serhiy Storchaka d28bb624d1 Issue #24097: Fixed crash in object.__reduce__() if slot name is freed inside
__getattr__.  Original patch by Antoine Pitrou.
2015-11-25 18:33:29 +02:00
Serhiy Storchaka bb6e4a0b31 Issue #24731: Fixed crash on converting objects with special methods
__bytes__, __trunc__, and __float__ returning instances of subclasses of
bytes, int, and float to subclasses of bytes, int, and float correspondingly.
2015-11-25 15:53:19 +02:00
Serhiy Storchaka f9afda57ad Issue #24731: Fixed crash on converting objects with special methods
__bytes__, __trunc__, and __float__ returning instances of subclasses of
bytes, int, and float to subclasses of bytes, int, and float correspondingly.
2015-11-25 15:52:04 +02:00
Serhiy Storchaka 15095800a3 Issue #24731: Fixed crash on converting objects with special methods
__bytes__, __trunc__, and __float__ returning instances of subclasses of
bytes, int, and float to subclasses of bytes, int, and float correspondingly.
2015-11-25 15:47:01 +02:00
Victor Stinner b4efc963d6 Issue #25557: Refactor _PyDict_LoadGlobal()
Don't fallback to PyDict_GetItemWithError() if the hash is unknown: compute the
hash instead. Add also comments to explain the optimization a little bit.
2015-11-20 09:24:02 +01:00
Raymond Hettinger 66f6238fca Add assertion to verify the pre-condition in the comments. 2015-11-17 20:58:43 -08:00