Kaydet (Commit) fb9ea8c5 authored tarafından Victor Stinner's avatar Victor Stinner

Don't check for the maximum character when copying from unicodeobject.c

 * Create copy_characters() function which doesn't check for the maximum
   character in release mode
 * _PyUnicode_CheckConsistency() is no more static to be able to use it
   in _PyUnicode_FormatAdvanced() (in formatter_unicode.c)
 * _PyUnicode_CheckConsistency() checks the string hash
üst 05d11895
...@@ -2030,6 +2030,13 @@ PyAPI_FUNC(Py_UNICODE*) PyUnicode_AsUnicodeCopy( ...@@ -2030,6 +2030,13 @@ PyAPI_FUNC(Py_UNICODE*) PyUnicode_AsUnicodeCopy(
); );
#endif /* Py_LIMITED_API */ #endif /* Py_LIMITED_API */
#if defined(Py_DEBUG) && !defined(Py_LIMITED_API)
/* FIXME: use PyObject* type for op */
PyAPI_FUNC(int) _PyUnicode_CheckConsistency(
void *op,
int check_content);
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
This diff is collapsed.
...@@ -1284,33 +1284,31 @@ _PyUnicode_FormatAdvanced(PyObject *obj, ...@@ -1284,33 +1284,31 @@ _PyUnicode_FormatAdvanced(PyObject *obj,
Py_ssize_t start, Py_ssize_t end) Py_ssize_t start, Py_ssize_t end)
{ {
InternalFormatSpec format; InternalFormatSpec format;
PyObject *result = NULL; PyObject *result;
/* check for the special case of zero length format spec, make /* check for the special case of zero length format spec, make
it equivalent to str(obj) */ it equivalent to str(obj) */
if (start == end) { if (start == end)
result = PyObject_Str(obj); return PyObject_Str(obj);
goto done;
}
/* parse the format_spec */ /* parse the format_spec */
if (!parse_internal_render_format_spec(format_spec, start, end, if (!parse_internal_render_format_spec(format_spec, start, end,
&format, 's', '<')) &format, 's', '<'))
goto done; return NULL;
/* type conversion? */ /* type conversion? */
switch (format.type) { switch (format.type) {
case 's': case 's':
/* no type conversion needed, already a string. do the formatting */ /* no type conversion needed, already a string. do the formatting */
result = format_string_internal(obj, &format); result = format_string_internal(obj, &format);
if (result != NULL)
assert(_PyUnicode_CheckConsistency(result, 1));
break; break;
default: default:
/* unknown */ /* unknown */
unknown_presentation_type(format.type, obj->ob_type->tp_name); unknown_presentation_type(format.type, obj->ob_type->tp_name);
goto done; result = NULL;
} }
done:
return result; return result;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment