Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-117431: Adapt str.find and friends to use the METH_FASTCALL calling convention#117468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
20 commits
Select commitHold shift + click to select a range
c038634
Draft: adapt str.{start,end}swith to Argument Clinic
erlend-aaslandApr 2, 2024
a9d3172
Revert unneeded and malformed change
erlend-aaslandApr 2, 2024
2ce5be6
Loosen error message tests
erlend-aaslandApr 2, 2024
6c95a0d
NEWS
erlend-aaslandApr 2, 2024
0ee5a28
Adapt str.count
erlend-aaslandApr 2, 2024
ec4c400
Adapt str.find
erlend-aaslandApr 2, 2024
6f05fe6
fixup! Adapt str.find
erlend-aaslandApr 2, 2024
4c46570
Adapt str.index
erlend-aaslandApr 2, 2024
df08da8
Adapt str.rfind
erlend-aaslandApr 2, 2024
9f26ea8
Adapt str.rindex
erlend-aaslandApr 2, 2024
1970887
Fixup docstrings
erlend-aaslandApr 2, 2024
571976d
Adapt NEWS
erlend-aaslandApr 2, 2024
154fe70
Address review: also mention str.count in the NEWS entry
erlend-aaslandApr 2, 2024
8fe04ae
Fixup endswith signature
erlend-aaslandApr 2, 2024
7b02515
Merge branch 'perf/starwith' into perf/str.find-and-friends
erlend-aaslandApr 2, 2024
c2ce49e
Address Jelle's review: clarify default values in param docstrings
erlend-aaslandApr 2, 2024
cae4c7e
Merge branch 'perf/starwith' into perf/str.find-and-friends
erlend-aaslandApr 2, 2024
d776fcd
Pull in main
erlend-aaslandApr 3, 2024
e7a55a8
any_find_slice() can return -2 on error
erlend-aaslandApr 3, 2024
ad10cb0
Pull in main
erlend-aaslandApr 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Adapt str.rindex
  • Loading branch information
@erlend-aasland
erlend-aasland committedApr 2, 2024
commit9f26ea83663a9b5b51c53b40bd7f8276c595b802
2 changes: 1 addition & 1 deletionLib/test/string_tests.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1509,7 +1509,7 @@ def test_find_etc_raise_correct_error_messages(self):
x, None, None, None)
self.assertRaisesRegex(TypeError, r'^index\b', s.index,
x, None, None, None)
self.assertRaisesRegex(TypeError, r'^rindex\(', s.rindex,
self.assertRaisesRegex(TypeError, r'^rindex\b', s.rindex,
x, None, None, None)
self.assertRaisesRegex(TypeError, r'^count\b', s.count,
x, None, None, None)
Expand Down
58 changes: 57 additions & 1 deletionObjects/clinic/unicodeobject.c.h
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

61 changes: 15 additions & 46 deletionsObjects/unicodeobject.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11062,24 +11062,6 @@ PyUnicode_AppendAndDel(PyObject **pleft, PyObject *right)
Py_XDECREF(right);
}

/*
Wraps asciilib_parse_args_finds() and additionally ensures that the
first argument is a unicode object.
*/

static inline int
parse_args_finds_unicode(const char * function_name, PyObject *args,
PyObject **substring,
Py_ssize_t *start, Py_ssize_t *end)
{
if (asciilib_parse_args_finds(function_name, args, substring, start, end)) {
if (ensure_unicode(*substring) < 0)
return 0;
return 1;
}
return 0;
}

/*[clinic input]
@text_signature "($self, sub[, start[, end]], /)"
str.count as unicode_count -> Py_ssize_t
Expand DownExpand Up@@ -12438,38 +12420,25 @@ unicode_rfind_impl(PyObject *str, PyObject *substr, Py_ssize_t start,
return any_find_slice(str, substr, start, end, -1);
}

PyDoc_STRVAR(rindex__doc__,
"S.rindex(sub[, start[, end]]) -> int\n\
\n\
Return the highest index in S where substring sub is found,\n\
such that sub is contained within S[start:end]. Optional\n\
arguments start and end are interpreted as in slice notation.\n\
\n\
Raises ValueError when the substring is not found.");

static PyObject *
unicode_rindex(PyObject *self, PyObject *args)
{
/* initialize variables to prevent gcc warning */
PyObject *substring = NULL;
Py_ssize_t start = 0;
Py_ssize_t end = 0;
Py_ssize_t result;

if (!parse_args_finds_unicode("rindex", args, &substring, &start, &end))
return NULL;
/*[clinic input]
str.rindex as unicode_rindex = str.count

result = any_find_slice(self, substring, start, end, -1);
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].

if (result == -2)
return NULL;
Optional arguments start and end are interpreted as in slice notation.
Raises ValueError when the substring is not found.
[clinic start generated code]*/

if (result < 0) {
static Py_ssize_t
unicode_rindex_impl(PyObject *str, PyObject *substr, Py_ssize_t start,
Py_ssize_t end)
/*[clinic end generated code: output=5f3aef124c867fe1 input=35943dead6c1ea9d]*/
{
Py_ssize_t result = any_find_slice(str, substr, start, end, -1);
if (result == -1) {
PyErr_SetString(PyExc_ValueError, "substring not found");
return NULL;
}

return PyLong_FromSsize_t(result);
return result;
}

/*[clinic input]
Expand DownExpand Up@@ -13509,7 +13478,7 @@ static PyMethodDef unicode_methods[] = {
UNICODE_LOWER_METHODDEF
UNICODE_LSTRIP_METHODDEF
UNICODE_RFIND_METHODDEF
{"rindex", (PyCFunction) unicode_rindex, METH_VARARGS, rindex__doc__},
UNICODE_RINDEX_METHODDEF
UNICODE_RJUST_METHODDEF
UNICODE_RSTRIP_METHODDEF
UNICODE_RPARTITION_METHODDEF
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp