From: Jesus Cea Date: Wed, 20 Apr 2011 15:42:50 +0000 (+0200) Subject: MERGE: startswith and endswith don't accept None as slice index. Patch by Torsten... X-Git-Tag: v3.2.1b1~99 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6159ee3cf59b3fd8fcf9818c0a8071362d1ad7c2;p=python MERGE: startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828) --- 6159ee3cf59b3fd8fcf9818c0a8071362d1ad7c2 diff --cc Misc/NEWS index fe6ba0194b,663846f702..36f34e66f3 --- a/Misc/NEWS +++ b/Misc/NEWS @@@ -39,23 -25,35 +39,26 @@@ Core and Builtin - Issue #11450: Don't truncate hg version info in Py_GetBuildInfo() when there are many tags (e.g. when using mq). Patch by Nadeem Vawda. -- Issue #10451: memoryview objects could allow to mutate a readable buffer. - Initial patch by Ross Lagerwall. - -- Issue #10892: Don't segfault when trying to delete __abstractmethods__ from a - class. +- Issue #11246: Fix PyUnicode_FromFormat("%V") to decode the byte string from + UTF-8 (with replace error handler) instead of ISO-8859-1 (in strict mode). + Patch written by Ray Allen. -- Issue #8020: Avoid a crash where the small objects allocator would read - non-Python managed memory while it is being modified by another thread. - Patch by Matt Bandy. +- Issue #11286: Raise a ValueError from calling PyMemoryView_FromBuffer with + a buffer struct having a NULL data pointer. -- Issue #8278: On Windows and with a NTFS filesystem, os.stat() and os.utime() - can now handle dates after 2038. +- Issue #11272: On Windows, input() strips '\r' (and not only '\n'), and + sys.stdin uses universal newline (replace '\r\n' by '\n'). + - issue #11828: startswith and endswith don't accept None as slice index. + Patch by Torsten Becker. + -- Issue #4236: PyModule_Create2 now checks the import machinery directly - rather than the Py_IsInitialized flag, avoiding a Fatal Python - error in certain circumstances when an import is done in __del__. - -- Issue #10596: Fix float.__mod__ to have the same behaviour as - float.__divmod__ with respect to signed zeros. -4.0 % 4.0 should be - 0.0, not -0.0. +- Issue #10830: Fix PyUnicode_FromFormatV("%c") for non-BMP characters on + narrow build. -- Issue #5587: add a repr to dict_proxy objects. Patch by David Stanek and - Daniel Urban. +- Check for NULL result in PyType_FromSpec. -- Issue #11506: Trying to assign to a bytes literal should result in a - SyntaxError. +- Issue #11386: bytearray.pop() now throws IndexError when the bytearray is + empty, instead of OverflowError. Library ------- diff --cc Objects/stringlib/find.h index f915296cae,4407d717d2..ce615dcb8a --- a/Objects/stringlib/find.h +++ b/Objects/stringlib/find.h @@@ -91,14 -100,12 +91,12 @@@ stringlib_contains_obj(PyObject* str, P ) != -1; } -#endif /* STRINGLIB_STR */ +#endif /* STRINGLIB_WANT_CONTAINS_OBJ */ - #if STRINGLIB_IS_UNICODE - /* This function is a helper for the "find" family (find, rfind, index, - rindex) of unicodeobject.c file, because they all have the same - behaviour for the arguments. + rindex) and for count, startswith and endswith, because they all have + the same behaviour for the arguments. It does not touch the variables received until it knows everything is ok. @@@ -141,6 -147,45 +138,38 @@@ stringlib_parse_args_finds(const char return 1; } + #undef FORMAT_BUFFER_SIZE + -#ifdef FROM_UNICODE ++#if STRINGLIB_IS_UNICODE + + /* + Wraps stringlib_parse_args_finds() and additionally ensures that the + first argument is a unicode object. + + Note that we receive a pointer to the pointer of the substring object, + so when we create that object in this function we don't DECREF it, + because it continues living in the caller functions (those functions, + after finishing using the substring, must DECREF it). + */ + + Py_LOCAL_INLINE(int) + stringlib_parse_args_finds_unicode(const char * function_name, PyObject *args, + PyUnicodeObject **substring, + Py_ssize_t *start, Py_ssize_t *end) + { + PyObject *tmp_substring; + + if(stringlib_parse_args_finds(function_name, args, &tmp_substring, + start, end)) { + tmp_substring = PyUnicode_FromObject(tmp_substring); + if (!tmp_substring) + return 0; + *substring = (PyUnicodeObject *)tmp_substring; + return 1; + } + return 0; + } + -#endif /* FROM_UNICODE */ +#endif /* STRINGLIB_IS_UNICODE */ #endif /* STRINGLIB_FIND_H */ - -/* -Local variables: -c-basic-offset: 4 -indent-tabs-mode: nil -End: -*/ diff --cc Objects/unicodeobject.c index cbda72532d,877640d995..ddf6f2e20d --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@@ -7442,20 -7150,15 +7442,15 @@@ unicode_count(PyUnicodeObject *self, Py Py_ssize_t end = PY_SSIZE_T_MAX; PyObject *result; - if (!PyArg_ParseTuple(args, "O|O&O&:count", &substring, - _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end)) - return NULL; - - substring = (PyUnicodeObject *)PyUnicode_FromObject( - (PyObject *)substring); - if (substring == NULL) + if (!stringlib_parse_args_finds_unicode("count", args, &substring, + &start, &end)) return NULL; - FIX_START_END(self); - + ADJUST_INDICES(start, end, self->length); result = PyLong_FromSsize_t( stringlib_count(self->str + start, end - start, - substring->str, substring->length) + substring->str, substring->length, + PY_SSIZE_T_MAX) ); Py_DECREF(substring);