Commit Graph

5358 Commits

Author SHA1 Message Date
Victor Stinner 0016507c16 Issue #25318: Move _PyBytesWriter to bytesobject.c
Declare also the private API in bytesobject.h.
2015-10-09 01:53:21 +02:00
Victor Stinner e7bf86cd7d Optimize backslashreplace error handler
Issue #25318: Optimize backslashreplace and xmlcharrefreplace error handlers in
UTF-8 encoder. Optimize also backslashreplace error handler for ASCII and
Latin1 encoders.

Use the new _PyBytesWriter API to optimize these error handlers for the
encoders. It avoids to create an exception and call the slow implementation of
the error handler.
2015-10-09 01:39:28 +02:00
Victor Stinner fdfbf78114 Issue #25318: Add _PyBytesWriter API
Add a new private API to optimize Unicode encoders. It uses a small buffer
allocated on the stack and supports overallocation.

Use _PyBytesWriter API for UCS1 (ASCII and Latin1) and UTF-8 encoders. Enable
overallocation for the UTF-8 encoder with error handlers.

unicode_encode_ucs1(): initialize collend to collstart+1 to not check the
current character twice, we already know that it is not ASCII.
2015-10-09 00:33:49 +02:00
Martin Panter 585a6acfef Merge typo fixes from 3.5 2015-10-07 11:13:55 +00:00
Martin Panter ec1aa5c2a1 More typos in 3.5 documentation and comments 2015-10-07 11:03:53 +00:00
Martin Panter 3f930dcd87 Merge typo fixes from 3.4 into 3.5 2015-10-07 11:01:47 +00:00
Martin Panter 9955a373a8 Various minor typos in documentation and comments 2015-10-07 10:26:23 +00:00
Benjamin Peterson cdae2cb88a merge 3.5 (closes #24806) 2015-10-06 19:42:46 -07:00
Benjamin Peterson 59dc696821 merge 3.4 (#24806) 2015-10-06 19:42:02 -07:00
Benjamin Peterson bd6c41a185 prevent unacceptable bases from becoming bases through multiple inheritance (#24806) 2015-10-06 19:36:54 -07:00
Victor Stinner 74e8fac3c8 Issue #25301: Fix compatibility with ISO C90 2015-10-05 13:49:26 +02:00
Victor Stinner 1d65d9192d Issue #25301: The UTF-8 decoder is now up to 15 times as fast for error
handlers: ``ignore``, ``replace`` and ``surrogateescape``.
2015-10-05 13:43:50 +02:00
Victor Stinner eb36fdaad8 Fix _PyUnicodeWriter_PrepareKind()
Initialize kind to 0 (PyUnicode_WCHAR_KIND) to ensure that
_PyUnicodeWriter_PrepareKind() handles correctly read-only buffer: copy the
buffer.
2015-10-03 01:55:51 +02:00
Serhiy Storchaka 29e68edbf4 Issue #24848: Fixed bugs in UTF-7 decoding of misformed data:
1. Non-ASCII bytes were accepted after shift sequence.
2. A low surrogate could be emitted in case of error in high surrogate.
3. In some circumstances the '\xfd' character was produced instead of the
replacement character '\ufffd' (due to a bug in _PyUnicodeWriter).
2015-10-02 13:14:03 +03:00
Serhiy Storchaka 58c8f2bb6d Issue #24848: Fixed bugs in UTF-7 decoding of misformed data:
1. Non-ASCII bytes were accepted after shift sequence.
2. A low surrogate could be emitted in case of error in high surrogate.
3. In some circumstances the '\xfd' character was produced instead of the
replacement character '\ufffd' (due to a bug in _PyUnicodeWriter).
2015-10-02 13:13:14 +03:00
Serhiy Storchaka 28b21e50c8 Issue #24848: Fixed bugs in UTF-7 decoding of misformed data:
1. Non-ASCII bytes were accepted after shift sequence.
2. A low surrogate could be emitted in case of error in high surrogate.
2015-10-02 13:07:28 +03:00
Serhiy Storchaka 5dbe245ef2 Issue #24483: C implementation of functools.lru_cache() now calculates key's
hash only once.
2015-10-02 12:47:59 +03:00
Serhiy Storchaka b9d98d532c Issue #24483: C implementation of functools.lru_cache() now calculates key's
hash only once.
2015-10-02 12:47:11 +03:00
Victor Stinner 3222da26fe Make _PyUnicode_TranslateCharmap() symbol private
unicodeobject.h exposes PyUnicode_TranslateCharmap() and PyUnicode_Translate().
2015-10-01 22:07:32 +02:00
Victor Stinner 01ada3996b Issue #25267: The UTF-8 encoder is now up to 75 times as fast for error
handlers: ``ignore``, ``replace``, ``surrogateescape``, ``surrogatepass``.
Patch co-written with Serhiy Storchaka.
2015-10-01 21:54:51 +02:00
Victor Stinner d69dd8bd5e (Merge 3.5) Issue #25182: Fix compilation on Windows 2015-09-30 15:03:50 +02:00
Victor Stinner ae86da9b20 (Merge 3.4) Issue #25182: Fix compilation on Windows 2015-09-30 15:03:31 +02:00
Victor Stinner 89719e1daf Issue #25182: Fix compilation on Windows
Restore also errno value before calling PyErr_SetFromErrno().
2015-09-30 15:01:34 +02:00
Serhiy Storchaka 85c386dee4 Issue #25182: The stdprinter (used as sys.stderr before the io module is
imported at startup) now uses the backslashreplace error handler.
2015-09-30 15:51:01 +03:00
Serhiy Storchaka 008fc77e1e Issue #25182: The stdprinter (used as sys.stderr before the io module is
imported at startup) now uses the backslashreplace error handler.
2015-09-30 15:50:32 +03:00
Serhiy Storchaka a59018c7ab Issue #25182: The stdprinter (used as sys.stderr before the io module is
imported at startup) now uses the backslashreplace error handler.
2015-09-30 15:46:53 +03:00
Victor Stinner c3713e9706 Optimize ascii/latin1+surrogateescape encoders
Issue #25227: Optimize ASCII and latin1 encoders with the ``surrogateescape``
error handler: the encoders are now up to 3 times as fast.

Initial patch written by Serhiy Storchaka.
2015-09-29 12:32:13 +02:00
Victor Stinner 0030cd52da Issue #25227: Cleanup unicode_encode_ucs1() error handler
* Change limit type from unsigned int to Py_UCS4, to use the same type than the
  "ch" variable (an Unicode character).
* Reuse ch variable for _Py_ERROR_XMLCHARREFREPLACE
* Add some newlines for readability
2015-09-24 14:45:00 +02:00
Victor Stinner 54385b206d Issue #24870: revert unwanted change
Sorry, I pushed the patch on the UTF-8 decoder by mistake :-(
2015-09-22 10:46:52 +02:00
Victor Stinner 5ebae87628 Issue #25207, #14626: Fix my commit.
It doesn't work to use #define XXX defined(YYY)" and then "#ifdef XXX"
to check YYY.
2015-09-22 01:29:33 +02:00
Victor Stinner 6174474bea _PyUnicodeWriter_PrepareInternal(): make the assertion more strict 2015-09-22 01:01:17 +02:00
Victor Stinner ca9381ea01 Issue #24870: Add _PyUnicodeWriter_PrepareKind() macro
Add a macro which ensures that the writer has at least the requested kind.
2015-09-22 00:58:32 +02:00
Victor Stinner 5014920cb7 Issue #24870: Reuse the new _Py_error_handler enum
Factorize code with the new get_error_handler() function.

Add some empty lines for readability.
2015-09-22 00:26:54 +02:00
Victor Stinner f96418de05 Issue #24870: Optimize the ASCII decoder for error handlers: surrogateescape,
ignore and replace. Initial patch written by Naoki Inada.

The decoder is now up to 60 times as fast for these error handlers.

Add also unit tests for the ASCII decoder.
2015-09-21 23:06:27 +02:00
Victor Stinner 026977717e Merge 3.5 2015-09-19 13:39:16 +02:00
Victor Stinner 5783fd2c58 Issue #24999: In longobject.c, use two shifts instead of ">> 2*PyLong_SHIFT" to
avoid undefined behaviour when LONG_MAX type is smaller than 60 bits.

This change should fix a warning with the ICC compiler.
2015-09-19 13:39:03 +02:00
Victor Stinner 058258652a Merge 3.5 (pytime, odict) 2015-09-18 13:55:15 +02:00
Victor Stinner 4a0d1e7c36 odictobject.c: fix compiler warning
PyObject_Length() returns a P_ssize_t, not an int. Use a Py_ssize_t to avoid
overflow.
2015-09-18 13:44:11 +02:00
Serhiy Storchaka 56f6e76c68 Issue #15989: Fixed some scarcely probable integer overflows.
It is very unlikely that they can occur in real code for now.
2015-09-06 21:25:30 +03:00
Guido van Rossum ba5f59089a Issue #24912: Prevent __class__ assignment to immutable built-in objects. (Merge 3.5 -> 3.6) 2015-09-05 15:20:57 -07:00
Guido van Rossum 37fdcbc4c3 Issue #24912: Prevent __class__ assignment to immutable built-in objects. (Merge 3.5.0 -> 3.5) 2015-09-05 15:20:08 -07:00
Guido van Rossum 7d293ee97d Issue #24912: Prevent __class__ assignment to immutable built-in objects. 2015-09-04 20:54:07 -07:00
Victor Stinner fa9dfd4f82 Merge 3.5 (odict) 2015-09-03 17:50:30 +02:00
Victor Stinner ca30b02abe Issue #24992: Fix error handling and a race condition (related to garbage
collection) in collections.OrderedDict constructor.

Patch reviewed by Serhiy Storchaka.
2015-09-03 17:50:04 +02:00
Victor Stinner 99bb14bf0c type_call() now detect bugs in type new and init
* Call _Py_CheckFunctionResult() to check for bugs in type
  constructors (tp_new)
* Add assertions to ensure an exception was raised if tp_init failed
  or that no exception was raised if tp_init succeed

Refactor also the function to have less indentation.
2015-09-03 12:16:49 +02:00
Eric V. Smith ab2aa6dc91 Fixed an incorrect comment. 2015-08-26 14:10:32 -04:00
Stefan Krah 5f35725fb8 Merge #15944. 2015-08-08 13:38:59 +02:00
Stefan Krah 0c51595a78 Issue #15944: memoryview: Allow arbitrary formats when casting to bytes.
Original patch by Martin Panter.
2015-08-08 13:38:10 +02:00
Eric Snow 5060bc51ca Merge from 3.5 (issue #24667). 2015-08-07 17:47:35 -06:00
Eric Snow 8c7f9558eb Issue #24667: Resize odict in all cases that the underlying dict resizes. 2015-08-07 17:45:12 -06:00
Eric V. Smith 577d2069da Fix typo in comment. 2015-08-07 18:50:24 -04:00
Raymond Hettinger 4148195c45 Move the active entry multiplication to later in the hash calculation 2015-08-07 00:43:39 -07:00
Raymond Hettinger b501a27ad8 Restore frozenset hash caching removed in cf707dd190a9 2015-08-06 22:15:22 -07:00
Zachary Ware 070bd62cfa Closes #21279: Merge with 3.5 2015-08-06 00:05:13 -05:00
Zachary Ware d987a81d29 Issue #21279: Merge with 3.4 2015-08-06 00:04:23 -05:00
Zachary Ware 79b98df023 Issue #21279: Flesh out str.translate docs
Initial patch by Kinga Farkas, Martin Panter, and John Posner.
2015-08-05 23:54:15 -05:00
Raymond Hettinger a286a51ae1 Fix comment typo 2015-08-01 11:07:11 -07:00
Raymond Hettinger 36c0500990 Tweak the comments 2015-08-01 10:57:42 -07:00
Raymond Hettinger fbffdef47d Issue #24762: Speed-up frozenset_hash() and greatly beef-up the comments. 2015-08-01 09:53:00 -07:00
Raymond Hettinger daffc916aa Issue #24681: Move the most likely test first in set_add_entry(). 2015-07-31 07:58:56 -07:00
Raymond Hettinger 70559b5c20 Issue #24681: Move the store of so->table to the code block where it is used. 2015-07-23 07:42:23 -04:00
Serhiy Storchaka c8fe04484e Issue #23573: Restored optimization of bytes.rfind() and bytearray.rfind()
for single-byte argument on Linux.
2015-07-20 22:58:29 +03:00
Serhiy Storchaka d92d4efe3d Issue #23573: Restored optimization of bytes.rfind() and bytearray.rfind()
for single-byte argument on Linux.
2015-07-20 22:58:02 +03:00
Raymond Hettinger ff9e18a863 Issue #24583: Consolidate previous set object updates into a single function
with a single entry point, named exit points at the bottom, more self-evident
refcount adjustments, and a comment describing why the pre-increment was
necessary at all.
2015-07-20 07:34:05 -04:00
Raymond Hettinger 482c05cbb5 Issue #24583: Fix refcount leak. 2015-07-20 01:23:32 -04:00
Raymond Hettinger 061091a7c5 Issue #24583: Fix crash when set is mutated while being updated. 2015-07-15 23:54:02 -07:00
Raymond Hettinger d702044bcd merge 2015-07-15 23:52:29 -07:00
Raymond Hettinger a3626bc5bd Issue #24583: Fix crash when set is mutated while being updated. 2015-07-15 23:50:14 -07:00
Raymond Hettinger 5d2385ff6f Neaten-up a little bit. 2015-07-08 11:52:27 -07:00
Raymond Hettinger 9632a7d735 Issue 24581: Revert c9782a9ac031 pending a stronger test for mutation during iteration. 2015-07-07 15:29:24 -07:00
Raymond Hettinger 11ce8e6c37 Minor bit of factoring-out common code. 2015-07-06 19:08:49 -07:00
Raymond Hettinger 3dbc11cadd Tighten-up code in the set iterator to use an entry pointer rather than indexing. 2015-07-06 19:03:01 -07:00
Raymond Hettinger ef6bd7d963 Tighten-up code in set_next() to use an entry pointer rather than indexing. 2015-07-06 08:43:37 -07:00
Raymond Hettinger b48d6a63ff Bring related functions add/contains/discard together in the code. 2015-07-05 16:27:44 -07:00
Raymond Hettinger 73799b181e Change add/contains/discard calls to pass the key and hash instead of an entry struct. 2015-07-05 16:06:10 -07:00
Raymond Hettinger dc28d5a198 Clean-up call patterns for add/contains/discard to better match the caller's needs. 2015-07-05 10:03:20 -07:00
Benjamin Peterson 191a8f0a34 merge heads 2015-07-04 22:53:45 -05:00
Benjamin Peterson d34c246baf merge 3.5 (#24407) 2015-07-04 19:59:50 -05:00
Benjamin Peterson e54d5321cc merge 3.4 (#24407) 2015-07-04 19:59:24 -05:00
Benjamin Peterson 2a48a6eb33 merge 3.3 (#24407) 2015-07-04 19:58:11 -05:00
Benjamin Peterson a82f77fb00 protect against mutation of the dict during insertion (closes #24407) 2015-07-04 19:55:16 -05:00
Raymond Hettinger ac2ef65c32 Make the unicode equality test an external function rather than in-lining it.
The real benefit of the unicode specialized function comes from
bypassing the overhead of PyObject_RichCompareBool() and not
from being in-lined (especially since there was almost no shared
data between the caller and callee).  Also, the in-lining was
having a negative effect on code generation for the callee.
2015-07-04 16:04:44 -07:00
Raymond Hettinger e186c7674c Make sure the dummy percentage calculation won't overflow. 2015-07-04 11:28:35 -07:00
Raymond Hettinger c2480dc0c4 Minor cleanup. 2015-07-04 08:46:31 -07:00
Raymond Hettinger b322326f48 Minor nit: Make the style of checking error return values more consistent. 2015-07-03 23:37:16 -07:00
Raymond Hettinger 4897300276 Minor factoring: move redundant resize scaling logic into the resize function. 2015-07-03 20:00:03 -07:00
Raymond Hettinger 3c1f52e829 Call set_lookkey() directly to avoid unnecessary memory spills and reloads. 2015-07-03 18:31:09 -07:00
Raymond Hettinger 15f0869609 Move insertion resize logic into set_insert_key().
Simplifies the code a little bit and does the resize check
only when a new key is added (giving a small speed up in
the case where the key already exists).

Fixes possible bug in set_merge() where the set_insert_key()
call relies on a big resize at the start to make enough room
for the keys but is vulnerable to a comparision callback that
could cause the table to shrink in the middle of the merge.

Also, changed the resize threshold from two-thirds of the
mask+1 to just two-thirds.  The plus one offset gave no
real benefit (afterall, the two-thirds mark is just a
heuristic and isn't a precise cut-off).
2015-07-03 17:21:17 -07:00
Yury Selivanov bb215e2300 Merge 3.5 (Issue #19235) 2015-07-03 01:10:11 -04:00
Yury Selivanov f488fb422a Issue #19235: Add new RecursionError exception. Patch by Georg Brandl. 2015-07-03 01:04:23 -04:00
Yury Selivanov d6d0b5b1fa Merge 3.5 (Issue #24450) 2015-07-03 00:24:14 -04:00
Yury Selivanov e13f8f3cab Issue #24450: Add gi_yieldfrom to generators; cr_await to coroutines.
Patch by Benno Leslie and Yury Selivanov.
2015-07-03 00:23:30 -04:00
Serhiy Storchaka 81da944d61 Issue #24467: Fixed possible buffer over-read in bytearray. The bytearray
object now always allocates place for trailing null byte and it's buffer now
is always null-terminated.
2015-06-29 21:18:55 +03:00
Serhiy Storchaka bc9e75ed02 Issue #24467: Fixed possible buffer over-read in bytearray. The bytearray
object now always allocates place for trailing null byte and it's buffer now
is always null-terminated.
2015-06-29 21:18:01 +03:00
Serhiy Storchaka 7b6e3b91f5 Issue #24467: Fixed possible buffer over-read in bytearray. The bytearray
object now always allocates place for trailing null byte and it's buffer now
is always null-terminated.
2015-06-29 21:14:06 +03:00
Raymond Hettinger 2eff9e9441 Minor refactoring. Move reference count logic into function that adds entry. 2015-06-27 22:03:35 -07:00
Benjamin Peterson b5048d3938 merge 3.5 2015-06-27 15:46:31 -05:00
Benjamin Peterson 4801383c29 upgrade to Unicode 8.0.0 2015-06-27 15:45:56 -05:00
Raymond Hettinger 91672617d5 Minor tweeak to tighten the inner-loop. 2015-06-26 02:50:21 -07:00
Yury Selivanov b257b7993c Merge 3.5 (issue #24439) 2015-06-24 11:04:39 -04:00