Victor Stinner
71dc3d878a
Issue #25349 , #26249 : Fix memleak in formatfloat()
2016-04-26 12:35:13 +02:00
Victor Stinner
e914d41312
Issue #26766 : Fix _PyBytesWriter_Finish()
...
Return a bytearray object when bytearray is requested and when the small buffer
is used.
Fix also test_bytes: bytearray%args must return a bytearray type.
2016-04-15 17:52:27 +02:00
Serhiy Storchaka
c9a59e6e4f
Issue #26764 : Fixed SystemError in bytes.__rmod__.
2016-04-15 14:11:10 +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
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
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
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
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
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
Serhiy Storchaka
413fdcea21
Issue #24821 : Refactor STRINGLIB(fastsearch_memchr_1char) and split it on
...
STRINGLIB(find_char) and STRINGLIB(rfind_char) that can be used independedly
without special preconditions.
2015-11-14 15:42:17 +02:00
Victor Stinner
c3d2bc19e4
Use _PyBytesWriter in _PyBytes_FromIterator()
2015-10-14 14:15:49 +02:00
Victor Stinner
c5c3ba4bec
Add _PyBytesWriter_Resize() function
...
This function gives a control to the buffer size without using min_size.
2015-10-14 13:56:47 +02:00
Victor Stinner
3c50ce39bf
Factorize _PyBytes_FromList() and _PyBytes_FromTuple() code using a C macro
2015-10-14 13:50:40 +02:00
Victor Stinner
f2eafa323b
Split PyBytes_FromObject() into subfunctions
2015-10-14 13:44:29 +02:00
Victor Stinner
2ec8063cc9
Modify _PyBytes_DecodeEscapeRecode() to use _PyBytesAPI
...
* Don't overallocate by 400% when recode is needed: only overallocate on demand
using _PyBytesWriter.
* Use _PyLong_DigitValue to convert hexadecimal digit to int
* Create _PyBytes_DecodeEscapeRecode() subfunction
2015-10-14 13:32:13 +02:00
Victor Stinner
f6358a7e4c
_PyBytesWriter_Alloc(): only use 10 bytes of the small buffer in debug mode to
...
enhance code to detect buffer under- and overflow.
2015-10-14 12:02:39 +02:00
Victor Stinner
2bf8993db9
Optimize bytes.fromhex() and bytearray.fromhex()
...
Issue #25401 : Optimize bytes.fromhex() and bytearray.fromhex(): they are now
between 2x and 3.5x faster. Changes:
* Use a fast-path working on a char* string for ASCII string
* Use a slow-path for non-ASCII string
* Replace slow hex_digit_to_int() function with a O(1) lookup in
_PyLong_DigitValue precomputed table
* Use _PyBytesWriter API to handle the buffer
* Add unit tests to check the error position in error messages
2015-10-14 11:25:33 +02:00
Victor Stinner
772b2b09f2
Optimize bytearray % args
...
Issue #25399 : Don't create temporary bytes objects: modify _PyBytes_Format() to
create work directly on bytearray objects.
* Rename _PyBytes_Format() to _PyBytes_FormatEx() just in case if something
outside CPython uses it
* _PyBytes_FormatEx() now uses (char*, Py_ssize_t) for the input string, so
bytearray_format() doesn't need tot create a temporary input bytes object
* Add use_bytearray parameter to _PyBytes_FormatEx() which is passed to
_PyBytesWriter, to create a bytearray buffer instead of a bytes buffer
Most formatting operations are now between 2.5 and 5 times faster.
2015-10-14 09:56:53 +02:00
Victor Stinner
661aaccf9d
Add use_bytearray attribute to _PyBytesWriter
...
Issue #25399 : Add a new use_bytearray attribute to _PyBytesWriter to use a
bytearray buffer, instead of using a bytes object.
2015-10-14 09:41:48 +02:00
Victor Stinner
03dab786b2
Rewrite PyBytes_FromFormatV() using _PyBytesWriter API
...
* Add much more unit tests on PyBytes_FromFormatV()
* Remove the first loop to compute the length of the output string
* Use _PyBytesWriter to handle the bytes buffer, use overallocation
* Cleanup the code to make simpler and easier to review
2015-10-14 00:21:35 +02:00
Victor Stinner
e9aa5950bb
Fix compilation error in _PyBytesWriter_WriteBytes() on Windows
2015-10-12 13:57:47 +02:00
Victor Stinner
6c2cdae9e6
Writer APIs: use empty string singletons
...
Modify _PyBytesWriter_Finish() and _PyUnicodeWriter_Finish() to return the
empty bytes/Unicode string if the string is empty.
2015-10-12 13:29:43 +02:00
Victor Stinner
c29e29bed1
Relax _PyBytesWriter API
...
Don't require _PyBytesWriter pointer to be a "char *". Same change for
_PyBytesWriter_WriteBytes() parameter.
For example, binascii uses "unsigned char*".
2015-10-12 13:12:54 +02:00
Victor Stinner
0cdad1e2bc
Issue #25349 : Add fast path for b'%c' % int
...
Optimize also %% formater.
2015-10-09 22:50:36 +02:00
Victor Stinner
be75b8cf23
Issue #25349 : Optimize bytes % int
...
Optimize bytes.__mod__(args) for integere formats: %d (%i, %u), %o, %x and %X.
_PyBytesWriter is now used to format directly the integer into the writer
buffer, instead of using a temporary bytes object.
Formatting is between 30% and 50% faster on a microbenchmark.
2015-10-09 22:43:24 +02:00
Victor Stinner
ce179bf6ba
Add _PyBytesWriter_WriteBytes() to factorize the code
2015-10-09 12:57:22 +02:00
Victor Stinner
ad7715891e
_PyBytesWriter: simplify code to avoid "prealloc" parameters
...
Substract preallocate bytes from min_size before calling
_PyBytesWriter_Prepare().
2015-10-09 12:38:53 +02:00
Victor Stinner
53926a1ce2
_PyBytesWriter: rename size attribute to min_size
2015-10-09 12:37:03 +02:00
Victor Stinner
fa7762ec06
Issue #25349 : Optimize bytes % args using the new private _PyBytesWriter API
...
* Thanks to the _PyBytesWriter API, output smaller than 512 bytes are allocated
on the stack and so avoid calling _PyBytes_Resize(). Because of that, change
the default buffer size to fmtcnt instead of fmtcnt+100.
* Rely on _PyBytesWriter algorithm to overallocate the buffer instead of using
a custom code. For example, _PyBytesWriter uses a different overallocation
factor (25% or 50%) depending on the platform to get best performances.
* Disable overallocation for the last write.
* Replace C loops to fill characters with memset()
* Add also many comments to _PyBytes_Format()
* Remove unused FORMATBUFLEN constant
* Avoid the creation of a temporary bytes object when formatting a floating
point number (when no custom formatting option is used)
* Fix also reference leaks on error handling
* Use Py_MEMCPY() to copy bytes between two formatters (%)
2015-10-09 11:48:06 +02:00
Victor Stinner
b3653a3458
Issue #25318 : cleanup code _PyBytesWriter
...
Rename "stack buffer" to "small buffer".
Add also an assertion in _PyBytesWriter_GetPos().
2015-10-09 03:38:24 +02:00
Victor Stinner
b13b97d3b8
Issue #25318 : Fix compilation error
...
Replace "#if Py_DEBUG" with "#ifdef Py_DEBUG".
2015-10-09 02:52:16 +02:00
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
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
Serhiy Storchaka
ac5569b1fa
Issue #24115 : Update uses of PyObject_IsTrue(), PyObject_Not(),
...
PyObject_IsInstance(), PyObject_RichCompareBool() and _PyDict_Contains()
to check for and handle errors correctly.
2015-05-30 17:48:19 +03:00
Serhiy Storchaka
fa494fd883
Issue #24115 : Update uses of PyObject_IsTrue(), PyObject_Not(),
...
PyObject_IsInstance(), PyObject_RichCompareBool() and _PyDict_Contains()
to check for and handle errors correctly.
2015-05-30 17:45:22 +03:00
Serhiy Storchaka
8b2e8b6cce
Specify default values of semantic booleans in Argument Clinic generated signatures as booleans.
2015-05-30 11:30:39 +03:00
Gregory P. Smith
8cb6569fe1
Implements issue #9951 : Adds a hex() method to bytes, bytearray, & memoryview.
...
Also updates a few internal implementations of the same thing to use the
new built-in code.
Contributed by Arnon Yaari.
2015-04-25 23:22:26 +00:00
Christian Heimes
4e25913f9f
Remove local dead code. In both blocks dir is always greater 0.
2015-04-18 05:54:02 +02:00
Larry Hastings
89964c48d1
Issue #23944 : Argument Clinic now wraps long impl prototypes at column 78.
2015-04-14 18:07:59 -04:00
Serhiy Storchaka
1009bf18b3
Issue #23501 : Argumen Clinic now generates code into separate files by default.
2015-04-03 23:53:51 +03:00
Serhiy Storchaka
41525e31a5
Issue #23466 : Raised OverflowError if %c argument is out of range.
2015-04-03 20:53:46 +03:00
Serhiy Storchaka
2c7b5a9d0d
Issue #23466 : %c, %o, %x, and %X in bytes formatting now raise TypeError on
...
non-integer input.
2015-03-30 09:19:08 +03:00
Victor Stinner
dabbfe7b30
Issue #23573 : Fix bytes.rfind() and bytearray.rfind() on Windows
...
Windows has no memrchr() function.
This change is only a workaround, the optimization must be reenabled on other
platforms.
2015-03-25 03:16:32 +01:00
Serhiy Storchaka
d9d769fcdd
Issue #23573 : Increased performance of string search operations (str.find,
...
str.index, str.count, the in operator, str.split, str.partition) with
arguments of different kinds (UCS1, UCS2, UCS4).
2015-03-24 21:55:47 +02:00
Serhiy Storchaka
1dd49824df
Issue #23681 : The -b option now affects comparisons of bytes with int.
2015-03-20 16:54:57 +02:00
Ethan Furman
62e977f1b6
Close issue23467: add %r compatibility to bytes and bytearray
2015-03-11 08:17:00 -07:00
Antoine Pitrou
63afdaa110
Issue #23629 : Fix the default __sizeof__ implementation for variable-sized objects.
2015-03-10 22:35:24 +01:00
Antoine Pitrou
a654510150
Issue #23629 : Fix the default __sizeof__ implementation for variable-sized objects.
2015-03-10 22:32:00 +01:00
Serhiy Storchaka
26861b0b29
Issue #23450 : Fixed possible integer overflows.
2015-02-16 20:52:17 +02:00
Serhiy Storchaka
ea5ce5a15e
Issue #23383 : Cleaned up bytes formatting.
2015-02-10 23:23:12 +02:00
Serhiy Storchaka
83848704f5
Issue #22896 : Fixed using _getbuffer() in recently added _PyBytes_Format().
2015-02-03 01:49:18 +02:00
Serhiy Storchaka
3dd3e26680
Issue #22896 : Avoid to use PyObject_AsCharBuffer(), PyObject_AsReadBuffer()
...
and PyObject_AsWriteBuffer().
2015-02-03 01:25:42 +02:00
Serhiy Storchaka
4fdb68491e
Issue #22896 : Avoid to use PyObject_AsCharBuffer(), PyObject_AsReadBuffer()
...
and PyObject_AsWriteBuffer().
2015-02-03 01:21:08 +02:00
Victor Stinner
5474d0ba19
Issue #20284 : Fix a compilation warning on Windows
...
Explicitly cast the long to char.
2015-01-26 16:43:36 +01:00
Benjamin Peterson
a8efc9601d
ensure ilen is initialized when it is assigned to len
2015-01-26 09:23:41 -05:00
Ethan Furman
b95b56150f
Issue20284: Implement PEP461
2015-01-23 20:05:18 -08:00
Serhiy Storchaka
83cf99d733
Issue #20335 : bytes constructor now raises TypeError when encoding or errors
...
is specified with non-string argument. Based on patch by Renaud Blanch.
2014-12-02 09:24:06 +02:00
Serhiy Storchaka
0b2cacb42a
Issue #20335 : bytes constructor now raises TypeError when encoding or errors
...
is specified with non-string argument. Based on patch by Renaud Blanch.
2014-12-02 09:26:14 +02:00
Larry Hastings
dfbeb160de
Issue #22615 : Argument Clinic now supports the "type" argument for the
...
int converter. This permits using the int converter with enums and
typedefs.
2014-10-13 10:39:41 +01:00
R David Murray
861470c836
#16518 : Bring error messages in harmony with docs ("bytes-like object")
...
Some time ago we changed the docs to consistently use the term 'bytes-like
object' in all the contexts where bytes, bytearray, memoryview, etc are used.
This patch (by Ezio Melotti) completes that work by changing the error
messages that previously reported that certain types did "not support the
buffer interface" to instead say that a bytes-like object is required. (The
glossary entry for bytes-like object references the discussion of the buffer
protocol in the docs.)
2014-10-05 11:47:01 -04:00
Benjamin Peterson
cdfb7691dd
merge 3.4
2014-09-29 19:12:44 -04:00
Benjamin Peterson
c2cfa8ddd8
merge 3.3
2014-09-29 19:12:37 -04:00
Benjamin Peterson
d48bc9468f
these variables ought to be Py_ssize_t
2014-09-29 19:12:26 -04:00
Benjamin Peterson
36a24f3f43
merge 3.4 ( #22519 )
2014-09-29 19:11:05 -04:00
Benjamin Peterson
18f836fb65
merge 3.3 ( closes #22519 )
2014-09-29 19:09:49 -04:00
Benjamin Peterson
42ff105539
fix overflow checking in PyBytes_Repr ( closes #22519 )
2014-09-29 19:01:18 -04:00
Serhiy Storchaka
20b39b27d9
Removed redundant casts to `char *`.
...
Corresponding functions now accept `const char *` (issue #1772673 ).
2014-09-28 11:27:24 +03:00
Serhiy Storchaka
d8a1447c99
Issue #22215 : Now ValueError is raised instead of TypeError when str or bytes
...
argument contains not permitted null character or byte.
2014-09-06 20:07:17 +03:00
Victor Stinner
049e509a9f
Issue #22207 : Fix "comparison between signed and unsigned integers" warning in
...
test checking for integer overflow on Py_ssize_t type: cast explicitly to
size_t.
2014-08-17 22:20:00 +02:00
Victor Stinner
88d146b7b9
Optimize PyBytes_FromObject(): only overallocate when size=0 to not get the
...
empty string singleton
2014-08-17 21:12:18 +02:00
Terry Jan Reedy
ffff1440d1
Issue #22077 : Improve index error messages for bytearrays, bytes, lists, and
...
tuples by adding 'or slices'. Added ', not <typename' for bytearrays.
Original patch by Claudiu Popa.
2014-08-02 01:30:37 -04:00
Martin v. Löwis
0efea322a9
Rerun AC, silence pointer conversion warnings.
2014-07-27 17:29:17 +02:00
Martin v. Löwis
7252a6e81e
Issue #20179 : Apply Argument Clinic to bytes and bytearray.
...
Patch by Tal Einat.
2014-07-27 16:25:09 +02:00
Zachary Ware
bca9694ac1
Issue #21442 : Fix MSVC compiler warning introduced by issue21377.
2014-05-06 11:42:37 -05:00
Victor Stinner
db067af12a
Issue #21233 : Add new C functions: PyMem_RawCalloc(), PyMem_Calloc(),
...
PyObject_Calloc(), _PyObject_GC_Calloc(). bytes(int) and bytearray(int) are now
using ``calloc()`` instead of ``malloc()`` for large objects which is faster
and use less memory (until the bytearray buffer is filled with data).
2014-05-02 22:31:14 +02:00
Antoine Pitrou
161d695fb0
Issue #21377 : PyBytes_Concat() now tries to concatenate in-place when the first argument has a reference count of 1.
...
Patch by Nikolaus Rath.
2014-05-01 14:36:20 +02:00
Kristján Valur Jónsson
25dded041f
Make the various iterators' "setstate" sliently and consistently clip the
...
index. This avoids the possibility of setting an iterator to an invalid
state.
2014-03-05 13:47:57 +00:00
Kristján Valur Jónsson
c5cc5011ac
Make the various iterators' "setstate" sliently and consistently clip the
...
index. This avoids the possibility of setting an iterator to an invalid
state.
2014-03-05 15:23:07 +00:00
Victor Stinner
507ac3a591
(Merge 3.3) Issue #19969 : PyBytes_FromFormatV() now raises an OverflowError if
...
"%c" argument is not in range [0; 255].
2013-12-13 12:15:31 +01:00
Victor Stinner
c9362cf86a
Issue #19969 : PyBytes_FromFormatV() now raises an OverflowError if "%c"
...
argument is not in range [0; 255].
2013-12-13 12:14:44 +01:00
Christian Heimes
d3afe781b1
Silence expression result unused warnings with clang.
...
The PyObject_INIT() macros returns obj:
../cpython/Objects/methodobject.c:32:23: warning: expression result unused [-Wunused-value]
PyObject_INIT(op, &PyCFunction_Type);
^~
../cpython/Include/objimpl.h:139:69: note: expanded from macro 'PyObject_INIT'
( Py_TYPE(op) = (typeobj), _Py_NewReference((PyObject *)(op)), (op) )
^
1 warning generated.
2013-12-04 09:27:47 +01:00
Christian Heimes
985ecdcfc2
ssue #19183 : Implement PEP 456 'secure and interchangeable hash algorithm'.
...
Python now uses SipHash24 on all major platforms.
2013-11-20 11:46:18 +01:00
Ezio Melotti
745d54d2fa
#17806 : Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
2013-11-16 19:10:57 +02:00
Victor Stinner
fd9e44db37
Issue #16286 : optimize PyUnicode_RichCompare() for identical strings (same
...
pointer) for any operator, not only Py_EQ and Py_NE.
Code of bytes_richcompare() and PyUnicode_RichCompare() is now closer.
2013-11-04 11:23:05 +01:00
Victor Stinner
c8bc5377ac
Issue #16286 : write a new subfunction bytes_compare_eq()
...
* cleanup bytes_richcompare()
* PyUnicode_RichCompare(): replace a test with a XOR
2013-11-04 11:08:10 +01:00
Victor Stinner
986e224d5a
Issue #18408 : Fix error handling in PyBytes_FromObject()
...
_PyBytes_Resize(&new) sets new to NULL on error, don't call Py_DECREF() with NULL.
2013-10-29 03:14:22 +01:00
Serhiy Storchaka
c679227e31
Issue #1772673 : The type of `char*` arguments now changed to `const char*`.
2013-10-19 21:03:34 +03:00
Antoine Pitrou
9ed5f27266
Issue #18722 : Remove uses of the "register" keyword in C code.
2013-08-13 20:18:52 +02:00
Serhiy Storchaka
b8cbba5877
Issue #12983 : Bytes literals with invalid \x escape now raise a SyntaxError
...
and a full traceback including line number.
2013-02-10 17:43:25 +02:00
Serhiy Storchaka
801d955f04
Issue #12983 : Bytes literals with invalid \x escape now raise a SyntaxError
...
and a full traceback including line number.
2013-02-10 17:42:01 +02:00