Victor Stinner
0cdad1e2bc
Issue #25349 : Add fast path for b'%c' % int
Optimize also %% formater.
10 years ago
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.
10 years ago
Victor Stinner
ce179bf6ba
Add _PyBytesWriter_WriteBytes() to factorize the code
10 years ago
Victor Stinner
ad7715891e
_PyBytesWriter: simplify code to avoid "prealloc" parameters
Substract preallocate bytes from min_size before calling
_PyBytesWriter_Prepare().
10 years ago
Victor Stinner
53926a1ce2
_PyBytesWriter: rename size attribute to min_size
10 years ago
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 (%)
10 years ago
Victor Stinner
b3653a3458
Issue #25318 : cleanup code _PyBytesWriter
Rename "stack buffer" to "small buffer".
Add also an assertion in _PyBytesWriter_GetPos().
10 years ago
Victor Stinner
b13b97d3b8
Issue #25318 : Fix compilation error
Replace "#if Py_DEBUG" with "#ifdef Py_DEBUG".
10 years ago
Victor Stinner
0016507c16
Issue #25318 : Move _PyBytesWriter to bytesobject.c
Declare also the private API in bytesobject.h.
10 years ago
Serhiy Storchaka
d92d4efe3d
Issue #23573 : Restored optimization of bytes.rfind() and bytearray.rfind()
for single-byte argument on Linux.
11 years ago
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.
11 years ago
Serhiy Storchaka
8b2e8b6cce
Specify default values of semantic booleans in Argument Clinic generated signatures as booleans.
11 years ago
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.
11 years ago
Christian Heimes
4e25913f9f
Remove local dead code. In both blocks dir is always greater 0.
11 years ago
Larry Hastings
89964c48d1
Issue #23944 : Argument Clinic now wraps long impl prototypes at column 78.
11 years ago
Serhiy Storchaka
1009bf18b3
Issue #23501 : Argumen Clinic now generates code into separate files by default.
11 years ago
Serhiy Storchaka
41525e31a5
Issue #23466 : Raised OverflowError if %c argument is out of range.
11 years ago
Serhiy Storchaka
2c7b5a9d0d
Issue #23466 : %c, %o, %x, and %X in bytes formatting now raise TypeError on
non-integer input.
11 years ago
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.
11 years ago
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).
11 years ago
Serhiy Storchaka
1dd49824df
Issue #23681 : The -b option now affects comparisons of bytes with int.
11 years ago
Ethan Furman
62e977f1b6
Close issue23467: add %r compatibility to bytes and bytearray
11 years ago
Antoine Pitrou
a654510150
Issue #23629 : Fix the default __sizeof__ implementation for variable-sized objects.
11 years ago
Serhiy Storchaka
26861b0b29
Issue #23450 : Fixed possible integer overflows.
11 years ago
Serhiy Storchaka
ea5ce5a15e
Issue #23383 : Cleaned up bytes formatting.
11 years ago
Serhiy Storchaka
83848704f5
Issue #22896 : Fixed using _getbuffer() in recently added _PyBytes_Format().
11 years ago
Serhiy Storchaka
4fdb68491e
Issue #22896 : Avoid to use PyObject_AsCharBuffer(), PyObject_AsReadBuffer()
and PyObject_AsWriteBuffer().
11 years ago
Victor Stinner
5474d0ba19
Issue #20284 : Fix a compilation warning on Windows
Explicitly cast the long to char.
11 years ago
Benjamin Peterson
a8efc9601d
ensure ilen is initialized when it is assigned to len
11 years ago
Ethan Furman
b95b56150f
Issue20284: Implement PEP461
11 years ago
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.
11 years ago
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.
11 years ago
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.)
11 years ago
Benjamin Peterson
d48bc9468f
these variables ought to be Py_ssize_t
11 years ago
Benjamin Peterson
42ff105539
fix overflow checking in PyBytes_Repr ( closes #22519 )
11 years ago
Serhiy Storchaka
20b39b27d9
Removed redundant casts to `char *`.
Corresponding functions now accept `const char *` (issue #1772673 ).
11 years ago
Serhiy Storchaka
d8a1447c99
Issue #22215 : Now ValueError is raised instead of TypeError when str or bytes
argument contains not permitted null character or byte.
12 years ago
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.
12 years ago
Victor Stinner
88d146b7b9
Optimize PyBytes_FromObject(): only overallocate when size=0 to not get the
empty string singleton
12 years ago
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.
12 years ago
Martin v. Löwis
0efea322a9
Rerun AC, silence pointer conversion warnings.
12 years ago
Martin v. Löwis
7252a6e81e
Issue #20179 : Apply Argument Clinic to bytes and bytearray.
Patch by Tal Einat.
12 years ago
Zachary Ware
bca9694ac1
Issue #21442 : Fix MSVC compiler warning introduced by issue21377.
12 years ago
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).
12 years ago
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.
12 years ago
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.
12 years ago
Victor Stinner
c9362cf86a
Issue #19969 : PyBytes_FromFormatV() now raises an OverflowError if "%c"
argument is not in range [0; 255].
12 years ago
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.
12 years ago
Christian Heimes
985ecdcfc2
ssue #19183 : Implement PEP 456 'secure and interchangeable hash algorithm'.
Python now uses SipHash24 on all major platforms.
12 years ago
Ezio Melotti
745d54d2fa
#17806 : Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
12 years ago