Skip to content

Commit d7b7c74

Browse files
committed
Issue #14993: Use standard "unsigned char" instead of a unsigned char bitfield
1 parent 05cab75 commit d7b7c74

3 files changed

Lines changed: 15 additions & 17 deletions

File tree

Include/unicodeobject.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -901,12 +901,10 @@ typedef struct {
901901
/* minimum length of the buffer when overallocation is enabled,
902902
see _PyUnicodeWriter_Init() */
903903
Py_ssize_t min_length;
904-
struct {
905-
unsigned char overallocate:1;
906-
/* If readonly is 1, buffer is a shared string (cannot be modified)
907-
and size is set to 0. */
908-
unsigned char readonly:1;
909-
} flags;
904+
unsigned char overallocate;
905+
/* If readonly is 1, buffer is a shared string (cannot be modified)
906+
and size is set to 0. */
907+
unsigned char readonly;
910908
} _PyUnicodeWriter ;
911909

912910
/* Initialize a Unicode writer.

Objects/stringlib/unicode_format.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ do_markup(SubString *input, PyObject *args, PyObject *kwargs,
898898

899899
if (field_present) {
900900
if (iter.str.start == iter.str.end)
901-
writer->flags.overallocate = 0;
901+
writer->overallocate = 0;
902902
if (!output_markup(&field_name, &format_spec,
903903
format_spec_needs_expanding, conversion, writer,
904904
args, kwargs, recursion_depth, auto_number))

Objects/unicodeobject.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12808,7 +12808,7 @@ _PyUnicodeWriter_Init(_PyUnicodeWriter *writer, Py_ssize_t min_length)
1280812808
writer->kind = 5; /* invalid kind */
1280912809
#endif
1281012810
writer->min_length = Py_MAX(min_length, 100);
12811-
writer->flags.overallocate = (min_length > 0);
12811+
writer->overallocate = (min_length > 0);
1281212812
}
1281312813

1281412814
int
@@ -12827,7 +12827,7 @@ _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer,
1282712827
newlen = writer->pos + length;
1282812828

1282912829
if (writer->buffer == NULL) {
12830-
if (writer->flags.overallocate) {
12830+
if (writer->overallocate) {
1283112831
/* overallocate 25% to limit the number of resize */
1283212832
if (newlen <= (PY_SSIZE_T_MAX - newlen / 4))
1283312833
newlen += newlen / 4;
@@ -12842,23 +12842,23 @@ _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer,
1284212842
}
1284312843

1284412844
if (newlen > writer->size) {
12845-
if (writer->flags.overallocate) {
12845+
if (writer->overallocate) {
1284612846
/* overallocate 25% to limit the number of resize */
1284712847
if (newlen <= (PY_SSIZE_T_MAX - newlen / 4))
1284812848
newlen += newlen / 4;
1284912849
if (newlen < writer->min_length)
1285012850
newlen = writer->min_length;
1285112851
}
1285212852

12853-
if (maxchar > writer->maxchar || writer->flags.readonly) {
12853+
if (maxchar > writer->maxchar || writer->readonly) {
1285412854
/* resize + widen */
1285512855
newbuffer = PyUnicode_New(newlen, maxchar);
1285612856
if (newbuffer == NULL)
1285712857
return -1;
1285812858
_PyUnicode_FastCopyCharacters(newbuffer, 0,
1285912859
writer->buffer, 0, writer->pos);
1286012860
Py_DECREF(writer->buffer);
12861-
writer->flags.readonly = 0;
12861+
writer->readonly = 0;
1286212862
}
1286312863
else {
1286412864
newbuffer = resize_compact(writer->buffer, newlen);
@@ -12869,7 +12869,7 @@ _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer,
1286912869
_PyUnicodeWriter_Update(writer);
1287012870
}
1287112871
else if (maxchar > writer->maxchar) {
12872-
assert(!writer->flags.readonly);
12872+
assert(!writer->readonly);
1287312873
newbuffer = PyUnicode_New(writer->size, maxchar);
1287412874
if (newbuffer == NULL)
1287512875
return -1;
@@ -12895,11 +12895,11 @@ _PyUnicodeWriter_WriteStr(_PyUnicodeWriter *writer, PyObject *str)
1289512895
return 0;
1289612896
maxchar = PyUnicode_MAX_CHAR_VALUE(str);
1289712897
if (maxchar > writer->maxchar || len > writer->size - writer->pos) {
12898-
if (writer->buffer == NULL && !writer->flags.overallocate) {
12898+
if (writer->buffer == NULL && !writer->overallocate) {
1289912899
Py_INCREF(str);
1290012900
writer->buffer = str;
1290112901
_PyUnicodeWriter_Update(writer);
12902-
writer->flags.readonly = 1;
12902+
writer->readonly = 1;
1290312903
writer->size = 0;
1290412904
writer->pos += len;
1290512905
return 0;
@@ -12921,7 +12921,7 @@ _PyUnicodeWriter_Finish(_PyUnicodeWriter *writer)
1292112921
Py_INCREF(unicode_empty);
1292212922
return unicode_empty;
1292312923
}
12924-
if (writer->flags.readonly) {
12924+
if (writer->readonly) {
1292512925
assert(PyUnicode_GET_LENGTH(writer->buffer) == writer->pos);
1292612926
return writer->buffer;
1292712927
}
@@ -13638,7 +13638,7 @@ PyUnicode_Format(PyObject *format, PyObject *args)
1363813638
goto onError;
1363913639
}
1364013640
if (fmtcnt == 0)
13641-
writer.flags.overallocate = 0;
13641+
writer.overallocate = 0;
1364213642

1364313643
if (c == '%') {
1364413644
if (_PyUnicodeWriter_Prepare(&writer, 1, '%') == -1)

0 commit comments

Comments
 (0)