summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/Objects/stringlib
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/tools/python3/Objects/stringlib')
-rw-r--r--contrib/tools/python3/Objects/stringlib/README.txt2
-rw-r--r--contrib/tools/python3/Objects/stringlib/clinic/transmogrify.h.h11
-rw-r--r--contrib/tools/python3/Objects/stringlib/codecs.h3
-rw-r--r--contrib/tools/python3/Objects/stringlib/fastsearch.h12
-rw-r--r--contrib/tools/python3/Objects/stringlib/find.h47
-rw-r--r--contrib/tools/python3/Objects/stringlib/unicode_format.h15
6 files changed, 16 insertions, 74 deletions
diff --git a/contrib/tools/python3/Objects/stringlib/README.txt b/contrib/tools/python3/Objects/stringlib/README.txt
index e1e329290ac..26f3d02b0ef 100644
--- a/contrib/tools/python3/Objects/stringlib/README.txt
+++ b/contrib/tools/python3/Objects/stringlib/README.txt
@@ -9,7 +9,7 @@ the following defines used by the different modules:
STRINGLIB_CHAR
- the type used to hold a character (char or Py_UNICODE)
+ the type used to hold a character (char, Py_UCS1, Py_UCS2 or Py_UCS4)
STRINGLIB_GET_EMPTY()
diff --git a/contrib/tools/python3/Objects/stringlib/clinic/transmogrify.h.h b/contrib/tools/python3/Objects/stringlib/clinic/transmogrify.h.h
index 49388cf043c..3a985ab5c7a 100644
--- a/contrib/tools/python3/Objects/stringlib/clinic/transmogrify.h.h
+++ b/contrib/tools/python3/Objects/stringlib/clinic/transmogrify.h.h
@@ -3,10 +3,11 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
+#include "pycore_abstract.h" // _PyNumber_Index()
+#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
PyDoc_STRVAR(stringlib_expandtabs__doc__,
"expandtabs($self, /, tabsize=8)\n"
@@ -62,7 +63,7 @@ stringlib_expandtabs(PyObject *self, PyObject *const *args, Py_ssize_t nargs, Py
if (!noptargs) {
goto skip_optional_pos;
}
- tabsize = _PyLong_AsInt(args[0]);
+ tabsize = PyLong_AsInt(args[0]);
if (tabsize == -1 && PyErr_Occurred()) {
goto exit;
}
@@ -278,4 +279,4 @@ stringlib_zfill(PyObject *self, PyObject *arg)
exit:
return return_value;
}
-/*[clinic end generated code: output=d44a269805f6739e input=a9049054013a1b77]*/
+/*[clinic end generated code: output=b409bdf9ab68d5a6 input=a9049054013a1b77]*/
diff --git a/contrib/tools/python3/Objects/stringlib/codecs.h b/contrib/tools/python3/Objects/stringlib/codecs.h
index 958cc861478..f98e71c3fc6 100644
--- a/contrib/tools/python3/Objects/stringlib/codecs.h
+++ b/contrib/tools/python3/Objects/stringlib/codecs.h
@@ -408,9 +408,6 @@ STRINGLIB(utf8_encoder)(_PyBytesWriter *writer,
}
else {
/* rep is unicode */
- if (PyUnicode_READY(rep) < 0)
- goto error;
-
if (!PyUnicode_IS_ASCII(rep)) {
raise_encode_exception(&exc, "utf-8", unicode,
startpos, endpos,
diff --git a/contrib/tools/python3/Objects/stringlib/fastsearch.h b/contrib/tools/python3/Objects/stringlib/fastsearch.h
index 257b7bd6788..76ddbf720f2 100644
--- a/contrib/tools/python3/Objects/stringlib/fastsearch.h
+++ b/contrib/tools/python3/Objects/stringlib/fastsearch.h
@@ -69,8 +69,8 @@ STRINGLIB(find_char)(const STRINGLIB_CHAR* s, Py_ssize_t n, STRINGLIB_CHAR ch)
and UCS4 representations. */
if (needle != 0) {
do {
- void *candidate = memchr(p, needle,
- (e - p) * sizeof(STRINGLIB_CHAR));
+ const void *candidate = memchr(p, needle,
+ (e - p) * sizeof(STRINGLIB_CHAR));
if (candidate == NULL)
return -1;
s1 = p;
@@ -588,7 +588,7 @@ STRINGLIB(default_find)(const STRINGLIB_CHAR* s, Py_ssize_t n,
continue;
}
/* miss: check if next character is part of pattern */
- if (!STRINGLIB_BLOOM(mask, ss[i+1])) {
+ if (i + 1 <= w && !STRINGLIB_BLOOM(mask, ss[i+1])) {
i = i + m;
}
else {
@@ -597,7 +597,7 @@ STRINGLIB(default_find)(const STRINGLIB_CHAR* s, Py_ssize_t n,
}
else {
/* skip: check if next character is part of pattern */
- if (!STRINGLIB_BLOOM(mask, ss[i+1])) {
+ if (i + 1 <= w && !STRINGLIB_BLOOM(mask, ss[i+1])) {
i = i + m;
}
}
@@ -661,7 +661,7 @@ STRINGLIB(adaptive_find)(const STRINGLIB_CHAR* s, Py_ssize_t n,
}
}
/* miss: check if next character is part of pattern */
- if (!STRINGLIB_BLOOM(mask, ss[i+1])) {
+ if (i + 1 <= w && !STRINGLIB_BLOOM(mask, ss[i+1])) {
i = i + m;
}
else {
@@ -670,7 +670,7 @@ STRINGLIB(adaptive_find)(const STRINGLIB_CHAR* s, Py_ssize_t n,
}
else {
/* skip: check if next character is part of pattern */
- if (!STRINGLIB_BLOOM(mask, ss[i+1])) {
+ if (i + 1 <= w && !STRINGLIB_BLOOM(mask, ss[i+1])) {
i = i + m;
}
}
diff --git a/contrib/tools/python3/Objects/stringlib/find.h b/contrib/tools/python3/Objects/stringlib/find.h
index 509b9297396..c385718a5b2 100644
--- a/contrib/tools/python3/Objects/stringlib/find.h
+++ b/contrib/tools/python3/Objects/stringlib/find.h
@@ -70,50 +70,3 @@ STRINGLIB(contains_obj)(PyObject* str, PyObject* sub)
}
#endif /* STRINGLIB_WANT_CONTAINS_OBJ */
-
-/*
-This function is a helper for the "find" family (find, rfind, index,
-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.
-*/
-
-#define FORMAT_BUFFER_SIZE 50
-
-Py_LOCAL_INLINE(int)
-STRINGLIB(parse_args_finds)(const char * function_name, PyObject *args,
- PyObject **subobj,
- Py_ssize_t *start, Py_ssize_t *end)
-{
- PyObject *tmp_subobj;
- Py_ssize_t tmp_start = 0;
- Py_ssize_t tmp_end = PY_SSIZE_T_MAX;
- PyObject *obj_start=Py_None, *obj_end=Py_None;
- char format[FORMAT_BUFFER_SIZE] = "O|OO:";
- size_t len = strlen(format);
-
- strncpy(format + len, function_name, FORMAT_BUFFER_SIZE - len - 1);
- format[FORMAT_BUFFER_SIZE - 1] = '\0';
-
- if (!PyArg_ParseTuple(args, format, &tmp_subobj, &obj_start, &obj_end))
- return 0;
-
- /* To support None in "start" and "end" arguments, meaning
- the same as if they were not passed.
- */
- if (obj_start != Py_None)
- if (!_PyEval_SliceIndex(obj_start, &tmp_start))
- return 0;
- if (obj_end != Py_None)
- if (!_PyEval_SliceIndex(obj_end, &tmp_end))
- return 0;
-
- *start = tmp_start;
- *end = tmp_end;
- *subobj = tmp_subobj;
- return 1;
-}
-
-#undef FORMAT_BUFFER_SIZE
diff --git a/contrib/tools/python3/Objects/stringlib/unicode_format.h b/contrib/tools/python3/Objects/stringlib/unicode_format.h
index ccd7c77c0a0..91c71ab5736 100644
--- a/contrib/tools/python3/Objects/stringlib/unicode_format.h
+++ b/contrib/tools/python3/Objects/stringlib/unicode_format.h
@@ -2,6 +2,7 @@
unicode_format.h -- implementation of str.format().
*/
+#include "pycore_complexobject.h" // _PyComplex_FormatAdvancedWriter()
#include "pycore_floatobject.h" // _PyFloat_FormatAdvancedWriter()
/************************************************************************/
@@ -820,7 +821,7 @@ output_markup(SubString *field_name, SubString *format_spec,
if (conversion != '\0') {
tmp = do_conversion(fieldobj, conversion);
- if (tmp == NULL || PyUnicode_READY(tmp) == -1)
+ if (tmp == NULL)
goto done;
/* do the assignment, transferring ownership: fieldobj = tmp */
@@ -832,7 +833,7 @@ output_markup(SubString *field_name, SubString *format_spec,
if (format_spec_needs_expanding) {
tmp = build_string(format_spec, args, kwargs, recursion_depth-1,
auto_number);
- if (tmp == NULL || PyUnicode_READY(tmp) == -1)
+ if (tmp == NULL)
goto done;
/* note that in the case we're expanding the format string,
@@ -948,10 +949,6 @@ do_string_format(PyObject *self, PyObject *args, PyObject *kwargs)
int recursion_depth = 2;
AutoNumber auto_number;
-
- if (PyUnicode_READY(self) == -1)
- return NULL;
-
AutoNumber_Init(&auto_number);
SubString_init(&input, self, 0, PyUnicode_GET_LENGTH(self));
return build_string(&input, args, kwargs, recursion_depth, &auto_number);
@@ -1110,9 +1107,6 @@ formatter_parser(PyObject *ignored, PyObject *self)
return NULL;
}
- if (PyUnicode_READY(self) == -1)
- return NULL;
-
it = PyObject_New(formatteriterobject, &PyFormatterIter_Type);
if (it == NULL)
return NULL;
@@ -1252,9 +1246,6 @@ formatter_field_name_split(PyObject *ignored, PyObject *self)
return NULL;
}
- if (PyUnicode_READY(self) == -1)
- return NULL;
-
it = PyObject_New(fieldnameiterobject, &PyFieldNameIter_Type);
if (it == NULL)
return NULL;