Commit d7b7c747 authored by Victor Stinner's avatar Victor Stinner

Issue #14993: Use standard "unsigned char" instead of a unsigned char bitfield

parent 05cab75d
...@@ -901,12 +901,10 @@ typedef struct { ...@@ -901,12 +901,10 @@ typedef struct {
/* minimum length of the buffer when overallocation is enabled, /* minimum length of the buffer when overallocation is enabled,
see _PyUnicodeWriter_Init() */ see _PyUnicodeWriter_Init() */
Py_ssize_t min_length; Py_ssize_t min_length;
struct { unsigned char overallocate;
unsigned char overallocate:1; /* If readonly is 1, buffer is a shared string (cannot be modified)
/* If readonly is 1, buffer is a shared string (cannot be modified) and size is set to 0. */
and size is set to 0. */ unsigned char readonly;
unsigned char readonly:1;
} flags;
} _PyUnicodeWriter ; } _PyUnicodeWriter ;
/* Initialize a Unicode writer. /* Initialize a Unicode writer.
......
...@@ -898,7 +898,7 @@ do_markup(SubString *input, PyObject *args, PyObject *kwargs, ...@@ -898,7 +898,7 @@ do_markup(SubString *input, PyObject *args, PyObject *kwargs,
if (field_present) { if (field_present) {
if (iter.str.start == iter.str.end) if (iter.str.start == iter.str.end)
writer->flags.overallocate = 0; writer->overallocate = 0;
if (!output_markup(&field_name, &format_spec, if (!output_markup(&field_name, &format_spec,
format_spec_needs_expanding, conversion, writer, format_spec_needs_expanding, conversion, writer,
args, kwargs, recursion_depth, auto_number)) args, kwargs, recursion_depth, auto_number))
......
...@@ -12808,7 +12808,7 @@ _PyUnicodeWriter_Init(_PyUnicodeWriter *writer, Py_ssize_t min_length) ...@@ -12808,7 +12808,7 @@ _PyUnicodeWriter_Init(_PyUnicodeWriter *writer, Py_ssize_t min_length)
writer->kind = 5; /* invalid kind */ writer->kind = 5; /* invalid kind */
#endif #endif
writer->min_length = Py_MAX(min_length, 100); writer->min_length = Py_MAX(min_length, 100);
writer->flags.overallocate = (min_length > 0); writer->overallocate = (min_length > 0);
} }
int int
...@@ -12827,7 +12827,7 @@ _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer, ...@@ -12827,7 +12827,7 @@ _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer,
newlen = writer->pos + length; newlen = writer->pos + length;
if (writer->buffer == NULL) { if (writer->buffer == NULL) {
if (writer->flags.overallocate) { if (writer->overallocate) {
/* overallocate 25% to limit the number of resize */ /* overallocate 25% to limit the number of resize */
if (newlen <= (PY_SSIZE_T_MAX - newlen / 4)) if (newlen <= (PY_SSIZE_T_MAX - newlen / 4))
newlen += newlen / 4; newlen += newlen / 4;
...@@ -12842,7 +12842,7 @@ _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer, ...@@ -12842,7 +12842,7 @@ _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer,
} }
if (newlen > writer->size) { if (newlen > writer->size) {
if (writer->flags.overallocate) { if (writer->overallocate) {
/* overallocate 25% to limit the number of resize */ /* overallocate 25% to limit the number of resize */
if (newlen <= (PY_SSIZE_T_MAX - newlen / 4)) if (newlen <= (PY_SSIZE_T_MAX - newlen / 4))
newlen += newlen / 4; newlen += newlen / 4;
...@@ -12850,7 +12850,7 @@ _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer, ...@@ -12850,7 +12850,7 @@ _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer,
newlen = writer->min_length; newlen = writer->min_length;
} }
if (maxchar > writer->maxchar || writer->flags.readonly) { if (maxchar > writer->maxchar || writer->readonly) {
/* resize + widen */ /* resize + widen */
newbuffer = PyUnicode_New(newlen, maxchar); newbuffer = PyUnicode_New(newlen, maxchar);
if (newbuffer == NULL) if (newbuffer == NULL)
...@@ -12858,7 +12858,7 @@ _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer, ...@@ -12858,7 +12858,7 @@ _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer,
_PyUnicode_FastCopyCharacters(newbuffer, 0, _PyUnicode_FastCopyCharacters(newbuffer, 0,
writer->buffer, 0, writer->pos); writer->buffer, 0, writer->pos);
Py_DECREF(writer->buffer); Py_DECREF(writer->buffer);
writer->flags.readonly = 0; writer->readonly = 0;
} }
else { else {
newbuffer = resize_compact(writer->buffer, newlen); newbuffer = resize_compact(writer->buffer, newlen);
...@@ -12869,7 +12869,7 @@ _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer, ...@@ -12869,7 +12869,7 @@ _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer,
_PyUnicodeWriter_Update(writer); _PyUnicodeWriter_Update(writer);
} }
else if (maxchar > writer->maxchar) { else if (maxchar > writer->maxchar) {
assert(!writer->flags.readonly); assert(!writer->readonly);
newbuffer = PyUnicode_New(writer->size, maxchar); newbuffer = PyUnicode_New(writer->size, maxchar);
if (newbuffer == NULL) if (newbuffer == NULL)
return -1; return -1;
...@@ -12895,11 +12895,11 @@ _PyUnicodeWriter_WriteStr(_PyUnicodeWriter *writer, PyObject *str) ...@@ -12895,11 +12895,11 @@ _PyUnicodeWriter_WriteStr(_PyUnicodeWriter *writer, PyObject *str)
return 0; return 0;
maxchar = PyUnicode_MAX_CHAR_VALUE(str); maxchar = PyUnicode_MAX_CHAR_VALUE(str);
if (maxchar > writer->maxchar || len > writer->size - writer->pos) { if (maxchar > writer->maxchar || len > writer->size - writer->pos) {
if (writer->buffer == NULL && !writer->flags.overallocate) { if (writer->buffer == NULL && !writer->overallocate) {
Py_INCREF(str); Py_INCREF(str);
writer->buffer = str; writer->buffer = str;
_PyUnicodeWriter_Update(writer); _PyUnicodeWriter_Update(writer);
writer->flags.readonly = 1; writer->readonly = 1;
writer->size = 0; writer->size = 0;
writer->pos += len; writer->pos += len;
return 0; return 0;
...@@ -12921,7 +12921,7 @@ _PyUnicodeWriter_Finish(_PyUnicodeWriter *writer) ...@@ -12921,7 +12921,7 @@ _PyUnicodeWriter_Finish(_PyUnicodeWriter *writer)
Py_INCREF(unicode_empty); Py_INCREF(unicode_empty);
return unicode_empty; return unicode_empty;
} }
if (writer->flags.readonly) { if (writer->readonly) {
assert(PyUnicode_GET_LENGTH(writer->buffer) == writer->pos); assert(PyUnicode_GET_LENGTH(writer->buffer) == writer->pos);
return writer->buffer; return writer->buffer;
} }
...@@ -13638,7 +13638,7 @@ PyUnicode_Format(PyObject *format, PyObject *args) ...@@ -13638,7 +13638,7 @@ PyUnicode_Format(PyObject *format, PyObject *args)
goto onError; goto onError;
} }
if (fmtcnt == 0) if (fmtcnt == 0)
writer.flags.overallocate = 0; writer.overallocate = 0;
if (c == '%') { if (c == '%') {
if (_PyUnicodeWriter_Prepare(&writer, 1, '%') == -1) if (_PyUnicodeWriter_Prepare(&writer, 1, '%') == -1)
......
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