Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-46881: Statically allocate and initialize the latin1 characters. #31616

Merged
merged 8 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Include/internal/pycore_global_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,14 @@ struct _Py_global_strings {
STRUCT_FOR_ID(write)
STRUCT_FOR_ID(zipimporter)
} identifiers;
struct {
PyASCIIObject _ascii;
uint8_t _data[2];
} ascii[128];
struct {
PyCompactUnicodeObject _latin1;
uint8_t _data[2];
} latin1[128];
};
/* End auto-generated code */

Expand Down
294 changes: 281 additions & 13 deletions Include/internal/pycore_runtime_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,34 @@ extern "C" {
_PyBytes_SIMPLE_INIT(CH, 1) \
}

#define _PyASCIIObject_INIT(LITERAL) \
#define _PyUnicode_ASCII_BASE_INIT(LITERAL, ASCII) \
{ \
._ascii = { \
.ob_base = _PyObject_IMMORTAL_INIT(&PyUnicode_Type), \
.length = sizeof(LITERAL) - 1, \
.hash = -1, \
.state = { \
.kind = 1, \
.compact = 1, \
.ascii = 1, \
.ready = 1, \
}, \
.ob_base = _PyObject_IMMORTAL_INIT(&PyUnicode_Type), \
.length = sizeof(LITERAL) - 1, \
.hash = -1, \
.state = { \
.kind = 1, \
.compact = 1, \
.ascii = ASCII, \
.ready = 1, \
}, \
._data = LITERAL, \
}
#define _PyASCIIObject_INIT(LITERAL) \
{ \
._ascii = _PyUnicode_ASCII_BASE_INIT(LITERAL, 1), \
._data = LITERAL \
}
#define INIT_STR(NAME, LITERAL) \
._ ## NAME = _PyASCIIObject_INIT(LITERAL)
#define INIT_ID(NAME) \
._ ## NAME = _PyASCIIObject_INIT(#NAME)

#define _PyUnicode_LATIN1_INIT(LITERAL) \
{ \
._latin1 = { \
._base = _PyUnicode_ASCII_BASE_INIT(LITERAL, 0), \
}, \
._data = LITERAL, \
}

/* The following is auto-generated by Tools/scripts/generate_global_objects.py. */
#define _Py_global_objects_INIT { \
Expand Down Expand Up @@ -963,6 +971,266 @@ extern "C" {
INIT_ID(write), \
INIT_ID(zipimporter), \
}, \
.ascii = { \
_PyASCIIObject_INIT("\x00"), \
_PyASCIIObject_INIT("\x01"), \
_PyASCIIObject_INIT("\x02"), \
_PyASCIIObject_INIT("\x03"), \
_PyASCIIObject_INIT("\x04"), \
_PyASCIIObject_INIT("\x05"), \
_PyASCIIObject_INIT("\x06"), \
_PyASCIIObject_INIT("\x07"), \
_PyASCIIObject_INIT("\x08"), \
_PyASCIIObject_INIT("\x09"), \
_PyASCIIObject_INIT("\x0a"), \
_PyASCIIObject_INIT("\x0b"), \
_PyASCIIObject_INIT("\x0c"), \
_PyASCIIObject_INIT("\x0d"), \
_PyASCIIObject_INIT("\x0e"), \
_PyASCIIObject_INIT("\x0f"), \
_PyASCIIObject_INIT("\x10"), \
_PyASCIIObject_INIT("\x11"), \
_PyASCIIObject_INIT("\x12"), \
_PyASCIIObject_INIT("\x13"), \
_PyASCIIObject_INIT("\x14"), \
_PyASCIIObject_INIT("\x15"), \
_PyASCIIObject_INIT("\x16"), \
_PyASCIIObject_INIT("\x17"), \
_PyASCIIObject_INIT("\x18"), \
_PyASCIIObject_INIT("\x19"), \
_PyASCIIObject_INIT("\x1a"), \
_PyASCIIObject_INIT("\x1b"), \
_PyASCIIObject_INIT("\x1c"), \
_PyASCIIObject_INIT("\x1d"), \
_PyASCIIObject_INIT("\x1e"), \
_PyASCIIObject_INIT("\x1f"), \
_PyASCIIObject_INIT("\x20"), \
_PyASCIIObject_INIT("\x21"), \
_PyASCIIObject_INIT("\x22"), \
_PyASCIIObject_INIT("\x23"), \
_PyASCIIObject_INIT("\x24"), \
_PyASCIIObject_INIT("\x25"), \
_PyASCIIObject_INIT("\x26"), \
_PyASCIIObject_INIT("\x27"), \
_PyASCIIObject_INIT("\x28"), \
_PyASCIIObject_INIT("\x29"), \
_PyASCIIObject_INIT("\x2a"), \
_PyASCIIObject_INIT("\x2b"), \
_PyASCIIObject_INIT("\x2c"), \
_PyASCIIObject_INIT("\x2d"), \
_PyASCIIObject_INIT("\x2e"), \
_PyASCIIObject_INIT("\x2f"), \
_PyASCIIObject_INIT("\x30"), \
_PyASCIIObject_INIT("\x31"), \
_PyASCIIObject_INIT("\x32"), \
_PyASCIIObject_INIT("\x33"), \
_PyASCIIObject_INIT("\x34"), \
_PyASCIIObject_INIT("\x35"), \
_PyASCIIObject_INIT("\x36"), \
_PyASCIIObject_INIT("\x37"), \
_PyASCIIObject_INIT("\x38"), \
_PyASCIIObject_INIT("\x39"), \
_PyASCIIObject_INIT("\x3a"), \
_PyASCIIObject_INIT("\x3b"), \
_PyASCIIObject_INIT("\x3c"), \
_PyASCIIObject_INIT("\x3d"), \
_PyASCIIObject_INIT("\x3e"), \
_PyASCIIObject_INIT("\x3f"), \
_PyASCIIObject_INIT("\x40"), \
_PyASCIIObject_INIT("\x41"), \
_PyASCIIObject_INIT("\x42"), \
_PyASCIIObject_INIT("\x43"), \
_PyASCIIObject_INIT("\x44"), \
_PyASCIIObject_INIT("\x45"), \
_PyASCIIObject_INIT("\x46"), \
_PyASCIIObject_INIT("\x47"), \
_PyASCIIObject_INIT("\x48"), \
_PyASCIIObject_INIT("\x49"), \
_PyASCIIObject_INIT("\x4a"), \
_PyASCIIObject_INIT("\x4b"), \
_PyASCIIObject_INIT("\x4c"), \
_PyASCIIObject_INIT("\x4d"), \
_PyASCIIObject_INIT("\x4e"), \
_PyASCIIObject_INIT("\x4f"), \
_PyASCIIObject_INIT("\x50"), \
_PyASCIIObject_INIT("\x51"), \
_PyASCIIObject_INIT("\x52"), \
_PyASCIIObject_INIT("\x53"), \
_PyASCIIObject_INIT("\x54"), \
_PyASCIIObject_INIT("\x55"), \
_PyASCIIObject_INIT("\x56"), \
_PyASCIIObject_INIT("\x57"), \
_PyASCIIObject_INIT("\x58"), \
_PyASCIIObject_INIT("\x59"), \
_PyASCIIObject_INIT("\x5a"), \
_PyASCIIObject_INIT("\x5b"), \
_PyASCIIObject_INIT("\x5c"), \
_PyASCIIObject_INIT("\x5d"), \
_PyASCIIObject_INIT("\x5e"), \
_PyASCIIObject_INIT("\x5f"), \
_PyASCIIObject_INIT("\x60"), \
_PyASCIIObject_INIT("\x61"), \
_PyASCIIObject_INIT("\x62"), \
_PyASCIIObject_INIT("\x63"), \
_PyASCIIObject_INIT("\x64"), \
_PyASCIIObject_INIT("\x65"), \
_PyASCIIObject_INIT("\x66"), \
_PyASCIIObject_INIT("\x67"), \
_PyASCIIObject_INIT("\x68"), \
_PyASCIIObject_INIT("\x69"), \
_PyASCIIObject_INIT("\x6a"), \
_PyASCIIObject_INIT("\x6b"), \
_PyASCIIObject_INIT("\x6c"), \
_PyASCIIObject_INIT("\x6d"), \
_PyASCIIObject_INIT("\x6e"), \
_PyASCIIObject_INIT("\x6f"), \
_PyASCIIObject_INIT("\x70"), \
_PyASCIIObject_INIT("\x71"), \
_PyASCIIObject_INIT("\x72"), \
_PyASCIIObject_INIT("\x73"), \
_PyASCIIObject_INIT("\x74"), \
_PyASCIIObject_INIT("\x75"), \
_PyASCIIObject_INIT("\x76"), \
_PyASCIIObject_INIT("\x77"), \
_PyASCIIObject_INIT("\x78"), \
_PyASCIIObject_INIT("\x79"), \
_PyASCIIObject_INIT("\x7a"), \
_PyASCIIObject_INIT("\x7b"), \
_PyASCIIObject_INIT("\x7c"), \
_PyASCIIObject_INIT("\x7d"), \
_PyASCIIObject_INIT("\x7e"), \
_PyASCIIObject_INIT("\x7f"), \
}, \
.latin1 = { \
_PyUnicode_LATIN1_INIT("\x80"), \
_PyUnicode_LATIN1_INIT("\x81"), \
_PyUnicode_LATIN1_INIT("\x82"), \
_PyUnicode_LATIN1_INIT("\x83"), \
_PyUnicode_LATIN1_INIT("\x84"), \
_PyUnicode_LATIN1_INIT("\x85"), \
_PyUnicode_LATIN1_INIT("\x86"), \
_PyUnicode_LATIN1_INIT("\x87"), \
_PyUnicode_LATIN1_INIT("\x88"), \
_PyUnicode_LATIN1_INIT("\x89"), \
_PyUnicode_LATIN1_INIT("\x8a"), \
_PyUnicode_LATIN1_INIT("\x8b"), \
_PyUnicode_LATIN1_INIT("\x8c"), \
_PyUnicode_LATIN1_INIT("\x8d"), \
_PyUnicode_LATIN1_INIT("\x8e"), \
_PyUnicode_LATIN1_INIT("\x8f"), \
_PyUnicode_LATIN1_INIT("\x90"), \
_PyUnicode_LATIN1_INIT("\x91"), \
_PyUnicode_LATIN1_INIT("\x92"), \
_PyUnicode_LATIN1_INIT("\x93"), \
_PyUnicode_LATIN1_INIT("\x94"), \
_PyUnicode_LATIN1_INIT("\x95"), \
_PyUnicode_LATIN1_INIT("\x96"), \
_PyUnicode_LATIN1_INIT("\x97"), \
_PyUnicode_LATIN1_INIT("\x98"), \
_PyUnicode_LATIN1_INIT("\x99"), \
_PyUnicode_LATIN1_INIT("\x9a"), \
_PyUnicode_LATIN1_INIT("\x9b"), \
_PyUnicode_LATIN1_INIT("\x9c"), \
_PyUnicode_LATIN1_INIT("\x9d"), \
_PyUnicode_LATIN1_INIT("\x9e"), \
_PyUnicode_LATIN1_INIT("\x9f"), \
_PyUnicode_LATIN1_INIT("\xa0"), \
_PyUnicode_LATIN1_INIT("\xa1"), \
_PyUnicode_LATIN1_INIT("\xa2"), \
_PyUnicode_LATIN1_INIT("\xa3"), \
_PyUnicode_LATIN1_INIT("\xa4"), \
_PyUnicode_LATIN1_INIT("\xa5"), \
_PyUnicode_LATIN1_INIT("\xa6"), \
_PyUnicode_LATIN1_INIT("\xa7"), \
_PyUnicode_LATIN1_INIT("\xa8"), \
_PyUnicode_LATIN1_INIT("\xa9"), \
_PyUnicode_LATIN1_INIT("\xaa"), \
_PyUnicode_LATIN1_INIT("\xab"), \
_PyUnicode_LATIN1_INIT("\xac"), \
_PyUnicode_LATIN1_INIT("\xad"), \
_PyUnicode_LATIN1_INIT("\xae"), \
_PyUnicode_LATIN1_INIT("\xaf"), \
_PyUnicode_LATIN1_INIT("\xb0"), \
_PyUnicode_LATIN1_INIT("\xb1"), \
_PyUnicode_LATIN1_INIT("\xb2"), \
_PyUnicode_LATIN1_INIT("\xb3"), \
_PyUnicode_LATIN1_INIT("\xb4"), \
_PyUnicode_LATIN1_INIT("\xb5"), \
_PyUnicode_LATIN1_INIT("\xb6"), \
_PyUnicode_LATIN1_INIT("\xb7"), \
_PyUnicode_LATIN1_INIT("\xb8"), \
_PyUnicode_LATIN1_INIT("\xb9"), \
_PyUnicode_LATIN1_INIT("\xba"), \
_PyUnicode_LATIN1_INIT("\xbb"), \
_PyUnicode_LATIN1_INIT("\xbc"), \
_PyUnicode_LATIN1_INIT("\xbd"), \
_PyUnicode_LATIN1_INIT("\xbe"), \
_PyUnicode_LATIN1_INIT("\xbf"), \
_PyUnicode_LATIN1_INIT("\xc0"), \
_PyUnicode_LATIN1_INIT("\xc1"), \
_PyUnicode_LATIN1_INIT("\xc2"), \
_PyUnicode_LATIN1_INIT("\xc3"), \
_PyUnicode_LATIN1_INIT("\xc4"), \
_PyUnicode_LATIN1_INIT("\xc5"), \
_PyUnicode_LATIN1_INIT("\xc6"), \
_PyUnicode_LATIN1_INIT("\xc7"), \
_PyUnicode_LATIN1_INIT("\xc8"), \
_PyUnicode_LATIN1_INIT("\xc9"), \
_PyUnicode_LATIN1_INIT("\xca"), \
_PyUnicode_LATIN1_INIT("\xcb"), \
_PyUnicode_LATIN1_INIT("\xcc"), \
_PyUnicode_LATIN1_INIT("\xcd"), \
_PyUnicode_LATIN1_INIT("\xce"), \
_PyUnicode_LATIN1_INIT("\xcf"), \
_PyUnicode_LATIN1_INIT("\xd0"), \
_PyUnicode_LATIN1_INIT("\xd1"), \
_PyUnicode_LATIN1_INIT("\xd2"), \
_PyUnicode_LATIN1_INIT("\xd3"), \
_PyUnicode_LATIN1_INIT("\xd4"), \
_PyUnicode_LATIN1_INIT("\xd5"), \
_PyUnicode_LATIN1_INIT("\xd6"), \
_PyUnicode_LATIN1_INIT("\xd7"), \
_PyUnicode_LATIN1_INIT("\xd8"), \
_PyUnicode_LATIN1_INIT("\xd9"), \
_PyUnicode_LATIN1_INIT("\xda"), \
_PyUnicode_LATIN1_INIT("\xdb"), \
_PyUnicode_LATIN1_INIT("\xdc"), \
_PyUnicode_LATIN1_INIT("\xdd"), \
_PyUnicode_LATIN1_INIT("\xde"), \
_PyUnicode_LATIN1_INIT("\xdf"), \
_PyUnicode_LATIN1_INIT("\xe0"), \
_PyUnicode_LATIN1_INIT("\xe1"), \
_PyUnicode_LATIN1_INIT("\xe2"), \
_PyUnicode_LATIN1_INIT("\xe3"), \
_PyUnicode_LATIN1_INIT("\xe4"), \
_PyUnicode_LATIN1_INIT("\xe5"), \
_PyUnicode_LATIN1_INIT("\xe6"), \
_PyUnicode_LATIN1_INIT("\xe7"), \
_PyUnicode_LATIN1_INIT("\xe8"), \
_PyUnicode_LATIN1_INIT("\xe9"), \
_PyUnicode_LATIN1_INIT("\xea"), \
_PyUnicode_LATIN1_INIT("\xeb"), \
_PyUnicode_LATIN1_INIT("\xec"), \
_PyUnicode_LATIN1_INIT("\xed"), \
_PyUnicode_LATIN1_INIT("\xee"), \
_PyUnicode_LATIN1_INIT("\xef"), \
_PyUnicode_LATIN1_INIT("\xf0"), \
_PyUnicode_LATIN1_INIT("\xf1"), \
_PyUnicode_LATIN1_INIT("\xf2"), \
_PyUnicode_LATIN1_INIT("\xf3"), \
_PyUnicode_LATIN1_INIT("\xf4"), \
_PyUnicode_LATIN1_INIT("\xf5"), \
_PyUnicode_LATIN1_INIT("\xf6"), \
_PyUnicode_LATIN1_INIT("\xf7"), \
_PyUnicode_LATIN1_INIT("\xf8"), \
_PyUnicode_LATIN1_INIT("\xf9"), \
_PyUnicode_LATIN1_INIT("\xfa"), \
_PyUnicode_LATIN1_INIT("\xfb"), \
_PyUnicode_LATIN1_INIT("\xfc"), \
_PyUnicode_LATIN1_INIT("\xfd"), \
_PyUnicode_LATIN1_INIT("\xfe"), \
_PyUnicode_LATIN1_INIT("\xff"), \
}, \
}, \
\
.tuple_empty = { \
Expand Down
3 changes: 0 additions & 3 deletions Include/internal/pycore_unicodeobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ struct _Py_unicode_ids {
};

struct _Py_unicode_state {
/* Single character Unicode strings in the Latin-1 range are being
shared as well. */
PyObject *latin1[256];
struct _Py_unicode_fs_codec fs_codec;

// Unicode identifiers (_Py_Identifier): see _PyUnicode_FromId()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Statically allocate and initialize the latin1 characters.
Loading