summaryrefslogtreecommitdiffstats
path: root/Objects/bytesobject.c
Commit message (Collapse)AuthorAgeFilesLines
* bpo-39939: Add str.removeprefix and str.removesuffix (GH-18939)sweeneyde2020-04-221-0/+77
| | | | | Added str.removeprefix and str.removesuffix methods and corresponding bytes, bytearray, and collections.UserString methods to remove affixes from a string if present. See PEP 616 for a full description.
* bpo-40268: Remove unused pycore_pymem.h includes (GH-19531)Victor Stinner2020-04-151-2/+2
|
* bpo-40268: Add _PyInterpreterState_GetConfig() (GH-19492)Victor Stinner2020-04-131-5/+2
| | | | | | | | Don't access PyInterpreterState.config member directly anymore, but use new functions: * _PyInterpreterState_GetConfig() * _PyInterpreterState_SetConfig() * _Py_GetConfig()
* bpo-39943: Add the const qualifier to pointers on non-mutable PyBytes data. ↵Serhiy Storchaka2020-04-121-7/+8
| | | | (GH-19472)
* bpo-39943: Add the const qualifier to pointers on non-mutable PyUnicode ↵Serhiy Storchaka2020-04-111-4/+6
| | | | data. (GH-19345)
* bpo-40170: Add _PyIndex_Check() internal function (GH-19426)Victor Stinner2020-04-081-2/+3
| | | | | | | | | Add _PyIndex_Check() function to the internal C API: fast inlined verson of PyIndex_Check(). Add Include/internal/pycore_abstract.h header file. Replace PyIndex_Check() with _PyIndex_Check() in C files of Objects and Python subdirectories.
* bpo-35081: Move bytes_methods.h to the internal C API (GH-18492)Victor Stinner2020-02-121-1/+1
| | | | | Move the bytes_methods.h header file to the internal C API as pycore_bytes_methods.h: it only contains private symbols (prefixed by "_Py"), except of the PyDoc_STRVAR_shared() macro.
* bpo-39245: Switch to public API for Vectorcall (GH-18460)Petr Viktorin2020-02-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The bulk of this patch was generated automatically with: for name in \ PyObject_Vectorcall \ Py_TPFLAGS_HAVE_VECTORCALL \ PyObject_VectorcallMethod \ PyVectorcall_Function \ PyObject_CallOneArg \ PyObject_CallMethodNoArgs \ PyObject_CallMethodOneArg \ ; do echo $name git grep -lwz _$name | xargs -0 sed -i "s/\b_$name\b/$name/g" done old=_PyObject_FastCallDict new=PyObject_VectorcallDict git grep -lwz $old | xargs -0 sed -i "s/\b$old\b/$new/g" and then cleaned up: - Revert changes to in docs & news - Revert changes to backcompat defines in headers - Nudge misaligned comments
* bpo-39573: Use Py_SET_SIZE() function (GH-18402)Victor Stinner2020-02-071-1/+1
| | | | Replace direct acccess to PyVarObject.ob_size with usage of the Py_SET_SIZE() function.
* bpo-39573: Use Py_TYPE() macro in Objects directory (GH-18392)Victor Stinner2020-02-071-1/+1
| | | Replace direct access to PyObject.ob_type with Py_TYPE().
* bpo-39542: Simplify _Py_NewReference() (GH-18332)Victor Stinner2020-02-031-1/+5
| | | | | | | | | * Remove _Py_INC_REFTOTAL and _Py_DEC_REFTOTAL macros: modify directly _Py_RefTotal. * _Py_ForgetReference() is no longer defined if the Py_TRACE_REFS macro is not defined. * Remove _Py_NewReference() implementation from object.c: unify the two implementations in object.h inline function. * Fix Py_TRACE_REFS build: _Py_INC_TPALLOCS() macro has been removed.
* bpo-39489: Remove COUNT_ALLOCS special build (GH-18259)Victor Stinner2020-02-031-16/+0
| | | | | | | | | | | Remove: * COUNT_ALLOCS macro * sys.getcounts() function * SHOW_ALLOC_COUNT code in listobject.c * SHOW_TRACK_COUNT code in tupleobject.c * PyConfig.show_alloc_count field * -X showalloccount command line option * @test.support.requires_type_collecting decorator
* bpo-39487: Merge duplicated _Py_IDENTIFIER identifiers in C code (GH-18254)Hai Shi2020-01-301-2/+2
| | | Moving repetitive `_Py_IDENTIFIER` instances to a global location helps identify them more easily in regards to sub-interpreter support.
* bpo-36389: Fix _PyBytesWriter in release mode (GH-16624)Victor Stinner2019-10-071-11/+10
| | | | Fix _PyBytesWriter API when Python is built in release mode with assertions.
* bpo-36389: _PyObject_CheckConsistency() available in release mode (GH-16612)Victor Stinner2019-10-071-7/+8
| | | | | | | | | | | | | | | | | | | | | bpo-36389, bpo-38376: The _PyObject_CheckConsistency() function is now also available in release mode. For example, it can be used to debug a crash in the visit_decref() function of the GC. Modify the following functions to also work in release mode: * _PyDict_CheckConsistency() * _PyObject_CheckConsistency() * _PyType_CheckConsistency() * _PyUnicode_CheckConsistency() Other changes: * _PyMem_IsPtrFreed(ptr) now also returns 1 if ptr is NULL (equals to 0). * _PyBytesWriter_CheckConsistency() now returns 1 and is only used with assert(). * Reorder _PyObject_Dump() to write safe fields first, and only attempt to render repr() at the end.
* bpo-37206: Unrepresentable default values no longer represented as None. ↵Serhiy Storchaka2019-09-141-1/+1
| | | | | | | (GH-13933) In ArgumentClinic, value "NULL" should now be used only for unrepresentable default values (like in the optional third parameter of getattr). "None" should be used if None is accepted as argument and passing None has the same effect as not passing the argument at all.
* Cut disused recode_encoding logic in _PyBytes_DecodeEscape. (GH-16013)Greg Price2019-09-121-58/+5
| | | | | | | | | | | | | | | | | | | | | All call sites pass NULL for `recode_encoding`, so this path is completely untested. That's been true since before Python 3.0. It adds significant complexity to this logic, so it's best to take it out. All call sites now have a literal NULL, and that's been true since commit 768921cf3 eliminated a conditional (`foo ? bar : NULL`) at the call site in Python/ast.c where we're parsing a bytes literal. But even before then, that condition `foo` had been a constant since unadorned string literals started meaning Unicode, in commit 572dbf8f1 aka v3.0a1~1035 . The `unicode` parameter is already unused, so mark it as unused too. The code that acted on it was also taken out before Python 3.0, in commit 8d30cc014 aka v3.0a1~1031 . The function (PyBytes_DecodeEscape) is exposed in the API, but it's never been documented.
* Remove unneeded assignment in PyBytes_Concat() (GH-15274)Sergey Fedoseev2019-09-101-1/+0
| | | The `wb.len = -1` assignment is unneeded since its introduction in 161d695fb0455ce52530d4f43a9eac4c738f64bb as `PyObject_GetBuffer` always fills it in.
* Cut tricky `goto` that isn't needed, in _PyBytes_DecodeEscape. (GH-15825)Greg Price2019-09-101-3/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is the sort of `goto` that requires the reader to stare hard at the code to unpick what it's doing. On doing so, the answer is... not very much! * It jumps from the bottom of the loop to almost the top; the effect is to bypass the loop condition `s < end` and also the `if`-condition `*s != '\\'`, acting as if both are true. * We've just decremented `s`, after incrementing it in the `switch` condition. So it has the same value as when `s == end` failed. Before that was another increment... and before that we had `s < end`. So `s < end` true, then increment, then `s == end` false... that means `s < end` is still true. * Also this means `s` points to the same character as it did for the `switch` condition. And there was a `case '\\'`, which we didn't hit -- so `*s != '\\'` is also true. * That means this has no effect on the behavior! The most it might do is an optimization -- we get to skip those two checks, because (as just proven above) we know they're true. * But gosh, this is the *invalid escape sequence* path. This does not seem like the kind of code path that calls for extreme optimization tricks. So, take the `goto` and the label out. Perhaps the compiler will notice the exact same facts we showed above, and generate identical code. Or perhaps it won't! That'll be OK. But then, crucially, if some future edit to this loop causes the reasoning above to *stop* holding true... the compiler will adjust this jump accordingly. One of us fallible humans might not.
* Make PyXXX_Fini() functions private (GH-15531)Victor Stinner2019-08-261-1/+1
| | | | | For example, rename PyTuple_Fini() to _PyTuple_Fini(). These functions are only declared in the internal C API.
* bpo-37483: add _PyObject_CallOneArg() function (#14558)Jeroen Demeyer2019-07-041-2/+1
|
* bpo-36974: tp_print -> tp_vectorcall_offset and tp_reserved -> tp_as_async ↵Jeroen Demeyer2019-05-311-4/+4
| | | | | | | | | (GH-13464) Automatically replace tp_print -> tp_vectorcall_offset tp_compare -> tp_as_async tp_reserved -> tp_as_async
* bpo-22385: Support output separators in hex methods. (#13578)Gregory P. Smith2019-05-291-8/+26
| | | | | | | | | | | | | | | | | | * bpo-22385: Support output separators in hex methods. Also in binascii.hexlify aka b2a_hex. The underlying implementation behind all hex generation in CPython uses the same pystrhex.c implementation. This adds support to bytes, bytearray, and memoryview objects. The binascii module functions exist rather than being slated for deprecation because they return bytes rather than requiring an intermediate step through a str object. This change was inspired by MicroPython which supports sep in its binascii implementation (and does not yet support the .hex methods). https://bugs.python.org/issue22385
* remove unnecessary tp_dealloc (GH-13647)Inada Naoki2019-05-291-9/+1
|
* bpo-36763: Implement the PEP 587 (GH-13592)Victor Stinner2019-05-271-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add a whole new documentation page: "Python Initialization Configuration" * PyWideStringList_Append() return type is now PyStatus, instead of int * PyInterpreterState_New() now calls PyConfig_Clear() if PyConfig_InitPythonConfig() fails. * Rename files: * Python/coreconfig.c => Python/initconfig.c * Include/cpython/coreconfig.h => Include/cpython/initconfig.h * Include/internal/: pycore_coreconfig.h => pycore_initconfig.h * Rename structures * _PyCoreConfig => PyConfig * _PyPreConfig => PyPreConfig * _PyInitError => PyStatus * _PyWstrList => PyWideStringList * Rename PyConfig fields: * use_module_search_paths => module_search_paths_set * module_search_path_env => pythonpath_env * Rename PyStatus field: _func => func * PyInterpreterState: rename core_config field to config * Rename macros and functions: * _PyCoreConfig_SetArgv() => PyConfig_SetBytesArgv() * _PyCoreConfig_SetWideArgv() => PyConfig_SetArgv() * _PyCoreConfig_DecodeLocale() => PyConfig_SetBytesString() * _PyInitError_Failed() => PyStatus_Exception() * _Py_INIT_ERROR_TYPE_xxx enums => _PyStatus_TYPE_xxx * _Py_UnixMain() => Py_BytesMain() * _Py_ExitInitError() => Py_ExitStatusException() * _Py_PreInitializeFromArgs() => Py_PreInitializeFromBytesArgs() * _Py_PreInitializeFromWideArgs() => Py_PreInitializeFromArgs() * _Py_PreInitialize() => Py_PreInitialize() * _Py_RunMain() => Py_RunMain() * _Py_InitializeFromConfig() => Py_InitializeFromConfig() * _Py_INIT_XXX() => _PyStatus_XXX() * _Py_INIT_FAILED() => _PyStatus_EXCEPTION() * Rename 'err' PyStatus variables to 'status' * Convert RUN_CODE() macro to config_run_code() static inline function * Remove functions: * _Py_InitializeFromArgs() * _Py_InitializeFromWideArgs() * _PyInterpreterState_GetCoreConfig()
* Fix couple of dead code paths (GH-7418)David Carlier2019-05-171-2/+0
|
* bpo-36946: Fix possible signed integer overflow when handling slices. (GH-13375)Zackery Spytz2019-05-171-1/+2
| | | | | | | The final addition (cur += step) may overflow, so use size_t for "cur". "cur" is always positive (even for negative steps), so it is safe to use size_t here. Co-Authored-By: Martin Panter <vadmium+py@gmail.com>
* bpo-36900: Replace global conf vars with config (GH-13299)Victor Stinner2019-05-141-2/+4
| | | | | | Replace global configuration variables with core_config read from the current interpreter. Cleanup dynload_hpux.c.
* bpo-36254: Fix invalid uses of %d in format strings in C. (GH-12264)Serhiy Storchaka2019-03-131-1/+1
|
* bpo-35552: Fix reading past the end in PyUnicode_FromFormat() and ↵Serhiy Storchaka2019-01-121-3/+9
| | | | | | PyBytes_FromFormat(). (GH-11276) Format characters "%s" and "%V" in PyUnicode_FromFormat() and "%s" in PyBytes_FromFormat() no longer read memory past the limit if precision is specified.
* bpo-33817: Fix _PyBytes_Resize() for empty bytes object. (GH-11516)Serhiy Storchaka2019-01-121-0/+13
| | | | Add also tests for PyUnicode_FromFormat() and PyBytes_FromFormat() with empty result.
* bpo-35444: Unify and optimize the helper for getting a builtin object. ↵Serhiy Storchaka2018-12-111-2/+3
| | | | | | | | (GH-11047) This speeds up pickling of some iterators. This fixes also error handling in pickling methods when fail to look up builtin "getattr".
* bpo-35059: PyObject_INIT() casts to PyObject* (GH-10674)Victor Stinner2018-11-231-3/+3
| | | | | | PyObject_INIT() and PyObject_INIT_VAR() now cast their first argument to PyObject*, as done in Python 3.7. Revert partially commit b4435e20a92af474f117b78b98ddc6f515363af5.
* bpo-35081: Add Include/internal/pycore_object.h (GH-10640)Victor Stinner2018-11-211-0/+1
| | | | Move _PyObject_GC_TRACK() and _PyObject_GC_UNTRACK() from Include/objimpl.h to Include/internal/pycore_object.h.
* bpo-35081: Rename internal headers (GH-10275)Victor Stinner2018-11-121-2/+2
| | | | | | | | | | | | | | Rename Include/internal/ headers: * pycore_hash.h -> pycore_pyhash.h * pycore_lifecycle.h -> pycore_pylifecycle.h * pycore_mem.h -> pycore_pymem.h * pycore_state.h -> pycore_pystate.h Add missing headers to Makefile.pre.in and PCbuild: * pycore_condvar.h. * pycore_hamt.h * pycore_pyhash.h
* bpo-35081: Add pycore_ prefix to internal header files (GH-10263)Victor Stinner2018-10-311-2/+2
| | | | | | | | | | | | | | | | | | | | * Rename Include/internal/ header files: * pyatomic.h -> pycore_atomic.h * ceval.h -> pycore_ceval.h * condvar.h -> pycore_condvar.h * context.h -> pycore_context.h * pygetopt.h -> pycore_getopt.h * gil.h -> pycore_gil.h * hamt.h -> pycore_hamt.h * hash.h -> pycore_hash.h * mem.h -> pycore_mem.h * pystate.h -> pycore_state.h * warnings.h -> pycore_warnings.h * PCbuild project, Makefile.pre.in, Modules/Setup: add the Include/internal/ directory to the search paths of header files. * Update includes. For example, replace #include "internal/mem.h" with #include "pycore_mem.h".
* bpo-35064 prefix smelly symbols that appear with COUNT_ALLOCS with _Py_ ↵Pablo Galindo2018-10-281-5/+5
| | | | | | | (GH-10152) Configuring python with ./configure --with-pydebug CFLAGS="-D COUNT_ALLOCS -O0" makes "make smelly" fail as some symbols were being exported without the "Py_" or "_Py" prefixes.
* bpo-35059: Convert PyObject_INIT() to function (GH-10077)Victor Stinner2018-10-261-3/+3
| | | | | * Convert PyObject_INIT() and PyObject_INIT_VAR() macros to static inline functions. * Fix usage of these functions: cast to PyObject* or PyVarObject*.
* bpo-34984: Improve error messages for bytes and bytearray constructors. ↵Serhiy Storchaka2018-10-211-2/+3
| | | | (GH-9874)
* bpo-34973: Fix crash in bytes constructor. (GH-9841)Serhiy Storchaka2018-10-211-35/+69
| | | Constructing bytes from mutating list could cause a crash.
* bpo-34974: Do not replace unexpected errors in bytes() and bytearray(). ↵Serhiy Storchaka2018-10-141-1/+4
| | | | | | | (GH-9852) bytes and bytearray constructors converted unexpected exceptions (e.g. MemoryError and KeyboardInterrupt) to TypeError.
* bpo-34879: Fix a possible null pointer dereference in bytesobject.c (GH-9683)Zackery Spytz2018-10-031-1/+1
| | | | | formatfloat() was not checking if PyBytes_FromStringAndSize() failed, which could lead to a null pointer dereference in _PyBytes_FormatEx().
* bpo-34436: Fix check that disables overallocation for the last fmt specifier ↵Alexey Izbyshev2018-08-231-3/+3
| | | | | (GH-8826) Reported by Svace static analyzer.
* bpo-34170: Add _PyCoreConfig.bytes_warning (GH-8447)Victor Stinner2018-07-241-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Add more fields to _PyCoreConfig: * _check_hash_pycs_mode * bytes_warning * debug * inspect * interactive * legacy_windows_fs_encoding * legacy_windows_stdio * optimization_level * quiet * unbuffered_stdio * user_site_directory * verbose * write_bytecode Changes: * Remove pymain_get_global_config() and pymain_set_global_config() which became useless. These functions have been replaced by _PyCoreConfig_GetGlobalConfig() and _PyCoreConfig_SetGlobalConfig(). * sys.flags.dont_write_bytecode value is now restricted to 1 even if -B option is specified multiple times on the command line. * PyThreadState_Clear() now uses the config from the current interpreter rather than using global Py_VerboseFlag
* bpo-20180: complete AC conversion of Objects/stringlib/transmogrify.h (GH-8039)Tal Einat2018-07-061-7/+5
| | | | * converted bytes methods: expandtabs, ljust, rjust, center, zfill * updated char_convertor to properly set the C default value
* bpo-33012: Fix invalid function cast warnings with gcc 8 for METH_NOARGS. ↵Siddhesh Poyarekar2018-04-291-17/+17
| | | | | | | | | (GH-6030) METH_NOARGS functions need only a single argument but they are cast into a PyCFunction, which takes two arguments. This triggers an invalid function cast warning in gcc8 due to the argument mismatch. Fix this by adding a dummy unused argument.
* bpo-32677: Add .isascii() to str, bytes and bytearray (GH-5342)INADA Naoki2018-01-271-0/+2
|
* bpo-23699: Use a macro to reduce boilerplate code in rich comparison ↵stratakis2017-11-021-20/+7
| | | | functions (GH-793)
* bpo-20047: Make bytearray methods partition() and rpartition() rejecting (#4158)Serhiy Storchaka2017-10-281-2/+2
| | | separators that are not bytes-like objects.
* bpo-31825: Fixed OverflowError in the 'unicode-escape' codec (#4058)Serhiy Storchaka2017-10-201-1/+1
| | | | and in codecs.escape_decode() when decode an escaped non-ascii byte.