mirror of
https://github.com/python/cpython.git
synced 2025-09-11 03:07:01 +00:00
gh-133968: Add PyUnicodeWriter_WriteASCII() function (#133973)
Replace most PyUnicodeWriter_WriteUTF8() calls with
PyUnicodeWriter_WriteASCII().
(cherry picked from commit f49a07b531
)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
parent
dba307a757
commit
3d69d18322
16 changed files with 98 additions and 31 deletions
6
Python/Python-ast.c
generated
6
Python/Python-ast.c
generated
|
@ -5796,7 +5796,7 @@ ast_repr_list(PyObject *list, int depth)
|
|||
|
||||
for (Py_ssize_t i = 0; i < Py_MIN(length, 2); i++) {
|
||||
if (i > 0) {
|
||||
if (PyUnicodeWriter_WriteUTF8(writer, ", ", 2) < 0) {
|
||||
if (PyUnicodeWriter_WriteASCII(writer, ", ", 2) < 0) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
@ -5820,7 +5820,7 @@ ast_repr_list(PyObject *list, int depth)
|
|||
}
|
||||
|
||||
if (i == 0 && length > 2) {
|
||||
if (PyUnicodeWriter_WriteUTF8(writer, ", ...", 5) < 0) {
|
||||
if (PyUnicodeWriter_WriteASCII(writer, ", ...", 5) < 0) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
@ -5924,7 +5924,7 @@ ast_repr_max_depth(AST_object *self, int depth)
|
|||
}
|
||||
|
||||
if (i > 0) {
|
||||
if (PyUnicodeWriter_WriteUTF8(writer, ", ", 2) < 0) {
|
||||
if (PyUnicodeWriter_WriteASCII(writer, ", ", 2) < 0) {
|
||||
Py_DECREF(name);
|
||||
Py_DECREF(value_repr);
|
||||
goto error;
|
||||
|
|
|
@ -979,7 +979,7 @@ contextvar_tp_repr(PyObject *op)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (PyUnicodeWriter_WriteUTF8(writer, "<ContextVar name=", 17) < 0) {
|
||||
if (PyUnicodeWriter_WriteASCII(writer, "<ContextVar name=", 17) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (PyUnicodeWriter_WriteRepr(writer, self->var_name) < 0) {
|
||||
|
@ -987,7 +987,7 @@ contextvar_tp_repr(PyObject *op)
|
|||
}
|
||||
|
||||
if (self->var_default != NULL) {
|
||||
if (PyUnicodeWriter_WriteUTF8(writer, " default=", 9) < 0) {
|
||||
if (PyUnicodeWriter_WriteASCII(writer, " default=", 9) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (PyUnicodeWriter_WriteRepr(writer, self->var_default) < 0) {
|
||||
|
@ -1182,15 +1182,15 @@ token_tp_repr(PyObject *op)
|
|||
if (writer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (PyUnicodeWriter_WriteUTF8(writer, "<Token", 6) < 0) {
|
||||
if (PyUnicodeWriter_WriteASCII(writer, "<Token", 6) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (self->tok_used) {
|
||||
if (PyUnicodeWriter_WriteUTF8(writer, " used", 5) < 0) {
|
||||
if (PyUnicodeWriter_WriteASCII(writer, " used", 5) < 0) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
if (PyUnicodeWriter_WriteUTF8(writer, " var=", 5) < 0) {
|
||||
if (PyUnicodeWriter_WriteASCII(writer, " var=", 5) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (PyUnicodeWriter_WriteRepr(writer, (PyObject *)self->tok_var) < 0) {
|
||||
|
|
|
@ -1176,7 +1176,7 @@ hamt_node_bitmap_dump(PyHamtNode_Bitmap *node,
|
|||
}
|
||||
|
||||
if (key_or_null == NULL) {
|
||||
if (PyUnicodeWriter_WriteUTF8(writer, "NULL:\n", -1) < 0) {
|
||||
if (PyUnicodeWriter_WriteASCII(writer, "NULL:\n", 6) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
@ -1194,7 +1194,7 @@ hamt_node_bitmap_dump(PyHamtNode_Bitmap *node,
|
|||
}
|
||||
}
|
||||
|
||||
if (PyUnicodeWriter_WriteUTF8(writer, "\n", 1) < 0) {
|
||||
if (PyUnicodeWriter_WriteASCII(writer, "\n", 1) < 0) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
@ -1915,7 +1915,7 @@ hamt_node_array_dump(PyHamtNode_Array *node,
|
|||
goto error;
|
||||
}
|
||||
|
||||
if (PyUnicodeWriter_WriteUTF8(writer, "\n", 1) < 0) {
|
||||
if (PyUnicodeWriter_WriteASCII(writer, "\n", 1) < 0) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue