1 #ifndef Py_INTERNAL_GLOBAL_STRINGS_H 2 #define Py_INTERNAL_GLOBAL_STRINGS_H 3 #ifdef __cplusplus 4 extern "C" { 5 #endif 6 7 #ifndef Py_BUILD_CORE 8 # error "this header requires Py_BUILD_CORE define" 9 #endif 10 11 // The data structure & init here are inspired by Tools/scripts/deepfreeze.py. 12 13 // All field names generated by ASCII_STR() have a common prefix, 14 // to help avoid collisions with keywords, etc. 15 16 #define STRUCT_FOR_ASCII_STR(LITERAL) \ 17 struct { \ 18 PyASCIIObject _ascii; \ 19 uint8_t _data[sizeof(LITERAL)]; \ 20 } 21 #define STRUCT_FOR_STR(NAME, LITERAL) \ 22 STRUCT_FOR_ASCII_STR(LITERAL) _ ## NAME; 23 #define STRUCT_FOR_ID(NAME) \ 24 STRUCT_FOR_ASCII_STR(#NAME) _ ## NAME; 25 26 // XXX Order by frequency of use? 27 28 /* The following is auto-generated by Tools/scripts/generate_global_objects.py. */ 29 struct _Py_global_strings { 30 struct { 31 STRUCT_FOR_STR(anon_dictcomp, "<dictcomp>") 32 STRUCT_FOR_STR(anon_genexpr, "<genexpr>") 33 STRUCT_FOR_STR(anon_lambda, "<lambda>") 34 STRUCT_FOR_STR(anon_listcomp, "<listcomp>") 35 STRUCT_FOR_STR(anon_module, "<module>") 36 STRUCT_FOR_STR(anon_setcomp, "<setcomp>") 37 STRUCT_FOR_STR(anon_string, "<string>") 38 STRUCT_FOR_STR(anon_unknown, "<unknown>") 39 STRUCT_FOR_STR(close_br, "}") 40 STRUCT_FOR_STR(comma_sep, ", ") 41 STRUCT_FOR_STR(dbl_close_br, "}}") 42 STRUCT_FOR_STR(dbl_open_br, "{{") 43 STRUCT_FOR_STR(dbl_percent, "%%") 44 STRUCT_FOR_STR(dot, ".") 45 STRUCT_FOR_STR(dot_locals, ".<locals>") 46 STRUCT_FOR_STR(empty, "") 47 STRUCT_FOR_STR(list_err, "list index out of range") 48 STRUCT_FOR_STR(newline, "\n") 49 STRUCT_FOR_STR(open_br, "{") 50 STRUCT_FOR_STR(percent, "%") 51 STRUCT_FOR_STR(utf_8, "utf-8") 52 } literals; 53 54 struct { 55 STRUCT_FOR_ID(False) 56 STRUCT_FOR_ID(Py_Repr) 57 STRUCT_FOR_ID(TextIOWrapper) 58 STRUCT_FOR_ID(True) 59 STRUCT_FOR_ID(WarningMessage) 60 STRUCT_FOR_ID(_) 61 STRUCT_FOR_ID(__IOBase_closed) 62 STRUCT_FOR_ID(__abc_tpflags__) 63 STRUCT_FOR_ID(__abs__) 64 STRUCT_FOR_ID(__abstractmethods__) 65 STRUCT_FOR_ID(__add__) 66 STRUCT_FOR_ID(__aenter__) 67 STRUCT_FOR_ID(__aexit__) 68 STRUCT_FOR_ID(__aiter__) 69 STRUCT_FOR_ID(__all__) 70 STRUCT_FOR_ID(__and__) 71 STRUCT_FOR_ID(__anext__) 72 STRUCT_FOR_ID(__annotations__) 73 STRUCT_FOR_ID(__args__) 74 STRUCT_FOR_ID(__await__) 75 STRUCT_FOR_ID(__bases__) 76 STRUCT_FOR_ID(__bool__) 77 STRUCT_FOR_ID(__build_class__) 78 STRUCT_FOR_ID(__builtins__) 79 STRUCT_FOR_ID(__bytes__) 80 STRUCT_FOR_ID(__call__) 81 STRUCT_FOR_ID(__cantrace__) 82 STRUCT_FOR_ID(__class__) 83 STRUCT_FOR_ID(__class_getitem__) 84 STRUCT_FOR_ID(__classcell__) 85 STRUCT_FOR_ID(__complex__) 86 STRUCT_FOR_ID(__contains__) 87 STRUCT_FOR_ID(__copy__) 88 STRUCT_FOR_ID(__del__) 89 STRUCT_FOR_ID(__delattr__) 90 STRUCT_FOR_ID(__delete__) 91 STRUCT_FOR_ID(__delitem__) 92 STRUCT_FOR_ID(__dict__) 93 STRUCT_FOR_ID(__dir__) 94 STRUCT_FOR_ID(__divmod__) 95 STRUCT_FOR_ID(__doc__) 96 STRUCT_FOR_ID(__enter__) 97 STRUCT_FOR_ID(__eq__) 98 STRUCT_FOR_ID(__exit__) 99 STRUCT_FOR_ID(__file__) 100 STRUCT_FOR_ID(__float__) 101 STRUCT_FOR_ID(__floordiv__) 102 STRUCT_FOR_ID(__format__) 103 STRUCT_FOR_ID(__fspath__) 104 STRUCT_FOR_ID(__ge__) 105 STRUCT_FOR_ID(__get__) 106 STRUCT_FOR_ID(__getattr__) 107 STRUCT_FOR_ID(__getattribute__) 108 STRUCT_FOR_ID(__getinitargs__) 109 STRUCT_FOR_ID(__getitem__) 110 STRUCT_FOR_ID(__getnewargs__) 111 STRUCT_FOR_ID(__getnewargs_ex__) 112 STRUCT_FOR_ID(__getstate__) 113 STRUCT_FOR_ID(__gt__) 114 STRUCT_FOR_ID(__hash__) 115 STRUCT_FOR_ID(__iadd__) 116 STRUCT_FOR_ID(__iand__) 117 STRUCT_FOR_ID(__ifloordiv__) 118 STRUCT_FOR_ID(__ilshift__) 119 STRUCT_FOR_ID(__imatmul__) 120 STRUCT_FOR_ID(__imod__) 121 STRUCT_FOR_ID(__import__) 122 STRUCT_FOR_ID(__imul__) 123 STRUCT_FOR_ID(__index__) 124 STRUCT_FOR_ID(__init__) 125 STRUCT_FOR_ID(__init_subclass__) 126 STRUCT_FOR_ID(__instancecheck__) 127 STRUCT_FOR_ID(__int__) 128 STRUCT_FOR_ID(__invert__) 129 STRUCT_FOR_ID(__ior__) 130 STRUCT_FOR_ID(__ipow__) 131 STRUCT_FOR_ID(__irshift__) 132 STRUCT_FOR_ID(__isabstractmethod__) 133 STRUCT_FOR_ID(__isub__) 134 STRUCT_FOR_ID(__iter__) 135 STRUCT_FOR_ID(__itruediv__) 136 STRUCT_FOR_ID(__ixor__) 137 STRUCT_FOR_ID(__le__) 138 STRUCT_FOR_ID(__len__) 139 STRUCT_FOR_ID(__length_hint__) 140 STRUCT_FOR_ID(__lltrace__) 141 STRUCT_FOR_ID(__loader__) 142 STRUCT_FOR_ID(__lshift__) 143 STRUCT_FOR_ID(__lt__) 144 STRUCT_FOR_ID(__main__) 145 STRUCT_FOR_ID(__matmul__) 146 STRUCT_FOR_ID(__missing__) 147 STRUCT_FOR_ID(__mod__) 148 STRUCT_FOR_ID(__module__) 149 STRUCT_FOR_ID(__mro_entries__) 150 STRUCT_FOR_ID(__mul__) 151 STRUCT_FOR_ID(__name__) 152 STRUCT_FOR_ID(__ne__) 153 STRUCT_FOR_ID(__neg__) 154 STRUCT_FOR_ID(__new__) 155 STRUCT_FOR_ID(__newobj__) 156 STRUCT_FOR_ID(__newobj_ex__) 157 STRUCT_FOR_ID(__next__) 158 STRUCT_FOR_ID(__notes__) 159 STRUCT_FOR_ID(__or__) 160 STRUCT_FOR_ID(__orig_class__) 161 STRUCT_FOR_ID(__origin__) 162 STRUCT_FOR_ID(__package__) 163 STRUCT_FOR_ID(__parameters__) 164 STRUCT_FOR_ID(__path__) 165 STRUCT_FOR_ID(__pos__) 166 STRUCT_FOR_ID(__pow__) 167 STRUCT_FOR_ID(__prepare__) 168 STRUCT_FOR_ID(__qualname__) 169 STRUCT_FOR_ID(__radd__) 170 STRUCT_FOR_ID(__rand__) 171 STRUCT_FOR_ID(__rdivmod__) 172 STRUCT_FOR_ID(__reduce__) 173 STRUCT_FOR_ID(__reduce_ex__) 174 STRUCT_FOR_ID(__repr__) 175 STRUCT_FOR_ID(__reversed__) 176 STRUCT_FOR_ID(__rfloordiv__) 177 STRUCT_FOR_ID(__rlshift__) 178 STRUCT_FOR_ID(__rmatmul__) 179 STRUCT_FOR_ID(__rmod__) 180 STRUCT_FOR_ID(__rmul__) 181 STRUCT_FOR_ID(__ror__) 182 STRUCT_FOR_ID(__round__) 183 STRUCT_FOR_ID(__rpow__) 184 STRUCT_FOR_ID(__rrshift__) 185 STRUCT_FOR_ID(__rshift__) 186 STRUCT_FOR_ID(__rsub__) 187 STRUCT_FOR_ID(__rtruediv__) 188 STRUCT_FOR_ID(__rxor__) 189 STRUCT_FOR_ID(__set__) 190 STRUCT_FOR_ID(__set_name__) 191 STRUCT_FOR_ID(__setattr__) 192 STRUCT_FOR_ID(__setitem__) 193 STRUCT_FOR_ID(__setstate__) 194 STRUCT_FOR_ID(__sizeof__) 195 STRUCT_FOR_ID(__slotnames__) 196 STRUCT_FOR_ID(__slots__) 197 STRUCT_FOR_ID(__spec__) 198 STRUCT_FOR_ID(__str__) 199 STRUCT_FOR_ID(__sub__) 200 STRUCT_FOR_ID(__subclasscheck__) 201 STRUCT_FOR_ID(__subclasshook__) 202 STRUCT_FOR_ID(__truediv__) 203 STRUCT_FOR_ID(__trunc__) 204 STRUCT_FOR_ID(__typing_is_unpacked_typevartuple__) 205 STRUCT_FOR_ID(__typing_prepare_subst__) 206 STRUCT_FOR_ID(__typing_subst__) 207 STRUCT_FOR_ID(__typing_unpacked_tuple_args__) 208 STRUCT_FOR_ID(__warningregistry__) 209 STRUCT_FOR_ID(__weakref__) 210 STRUCT_FOR_ID(__xor__) 211 STRUCT_FOR_ID(_abc_impl) 212 STRUCT_FOR_ID(_annotation) 213 STRUCT_FOR_ID(_blksize) 214 STRUCT_FOR_ID(_bootstrap) 215 STRUCT_FOR_ID(_dealloc_warn) 216 STRUCT_FOR_ID(_finalizing) 217 STRUCT_FOR_ID(_find_and_load) 218 STRUCT_FOR_ID(_fix_up_module) 219 STRUCT_FOR_ID(_get_sourcefile) 220 STRUCT_FOR_ID(_handle_fromlist) 221 STRUCT_FOR_ID(_initializing) 222 STRUCT_FOR_ID(_is_text_encoding) 223 STRUCT_FOR_ID(_lock_unlock_module) 224 STRUCT_FOR_ID(_showwarnmsg) 225 STRUCT_FOR_ID(_shutdown) 226 STRUCT_FOR_ID(_slotnames) 227 STRUCT_FOR_ID(_strptime_time) 228 STRUCT_FOR_ID(_uninitialized_submodules) 229 STRUCT_FOR_ID(_warn_unawaited_coroutine) 230 STRUCT_FOR_ID(_xoptions) 231 STRUCT_FOR_ID(add) 232 STRUCT_FOR_ID(append) 233 STRUCT_FOR_ID(big) 234 STRUCT_FOR_ID(buffer) 235 STRUCT_FOR_ID(builtins) 236 STRUCT_FOR_ID(c_call) 237 STRUCT_FOR_ID(c_exception) 238 STRUCT_FOR_ID(c_return) 239 STRUCT_FOR_ID(call) 240 STRUCT_FOR_ID(clear) 241 STRUCT_FOR_ID(close) 242 STRUCT_FOR_ID(closed) 243 STRUCT_FOR_ID(code) 244 STRUCT_FOR_ID(copy) 245 STRUCT_FOR_ID(copyreg) 246 STRUCT_FOR_ID(decode) 247 STRUCT_FOR_ID(default) 248 STRUCT_FOR_ID(defaultaction) 249 STRUCT_FOR_ID(dictcomp) 250 STRUCT_FOR_ID(difference_update) 251 STRUCT_FOR_ID(dispatch_table) 252 STRUCT_FOR_ID(displayhook) 253 STRUCT_FOR_ID(enable) 254 STRUCT_FOR_ID(encode) 255 STRUCT_FOR_ID(encoding) 256 STRUCT_FOR_ID(end_lineno) 257 STRUCT_FOR_ID(end_offset) 258 STRUCT_FOR_ID(errors) 259 STRUCT_FOR_ID(excepthook) 260 STRUCT_FOR_ID(exception) 261 STRUCT_FOR_ID(extend) 262 STRUCT_FOR_ID(filename) 263 STRUCT_FOR_ID(fileno) 264 STRUCT_FOR_ID(fillvalue) 265 STRUCT_FOR_ID(filters) 266 STRUCT_FOR_ID(find_class) 267 STRUCT_FOR_ID(flush) 268 STRUCT_FOR_ID(genexpr) 269 STRUCT_FOR_ID(get) 270 STRUCT_FOR_ID(get_source) 271 STRUCT_FOR_ID(getattr) 272 STRUCT_FOR_ID(getstate) 273 STRUCT_FOR_ID(ignore) 274 STRUCT_FOR_ID(importlib) 275 STRUCT_FOR_ID(inf) 276 STRUCT_FOR_ID(intersection) 277 STRUCT_FOR_ID(isatty) 278 STRUCT_FOR_ID(isinstance) 279 STRUCT_FOR_ID(items) 280 STRUCT_FOR_ID(iter) 281 STRUCT_FOR_ID(join) 282 STRUCT_FOR_ID(keys) 283 STRUCT_FOR_ID(lambda) 284 STRUCT_FOR_ID(last_traceback) 285 STRUCT_FOR_ID(last_type) 286 STRUCT_FOR_ID(last_value) 287 STRUCT_FOR_ID(latin1) 288 STRUCT_FOR_ID(len) 289 STRUCT_FOR_ID(line) 290 STRUCT_FOR_ID(lineno) 291 STRUCT_FOR_ID(listcomp) 292 STRUCT_FOR_ID(little) 293 STRUCT_FOR_ID(locale) 294 STRUCT_FOR_ID(match) 295 STRUCT_FOR_ID(metaclass) 296 STRUCT_FOR_ID(mode) 297 STRUCT_FOR_ID(modules) 298 STRUCT_FOR_ID(mro) 299 STRUCT_FOR_ID(msg) 300 STRUCT_FOR_ID(n_fields) 301 STRUCT_FOR_ID(n_sequence_fields) 302 STRUCT_FOR_ID(n_unnamed_fields) 303 STRUCT_FOR_ID(name) 304 STRUCT_FOR_ID(newlines) 305 STRUCT_FOR_ID(next) 306 STRUCT_FOR_ID(obj) 307 STRUCT_FOR_ID(offset) 308 STRUCT_FOR_ID(onceregistry) 309 STRUCT_FOR_ID(opcode) 310 STRUCT_FOR_ID(open) 311 STRUCT_FOR_ID(parent) 312 STRUCT_FOR_ID(partial) 313 STRUCT_FOR_ID(path) 314 STRUCT_FOR_ID(peek) 315 STRUCT_FOR_ID(persistent_id) 316 STRUCT_FOR_ID(persistent_load) 317 STRUCT_FOR_ID(print_file_and_line) 318 STRUCT_FOR_ID(ps1) 319 STRUCT_FOR_ID(ps2) 320 STRUCT_FOR_ID(raw) 321 STRUCT_FOR_ID(read) 322 STRUCT_FOR_ID(read1) 323 STRUCT_FOR_ID(readable) 324 STRUCT_FOR_ID(readall) 325 STRUCT_FOR_ID(readinto) 326 STRUCT_FOR_ID(readinto1) 327 STRUCT_FOR_ID(readline) 328 STRUCT_FOR_ID(reducer_override) 329 STRUCT_FOR_ID(reload) 330 STRUCT_FOR_ID(replace) 331 STRUCT_FOR_ID(reset) 332 STRUCT_FOR_ID(return) 333 STRUCT_FOR_ID(reversed) 334 STRUCT_FOR_ID(seek) 335 STRUCT_FOR_ID(seekable) 336 STRUCT_FOR_ID(send) 337 STRUCT_FOR_ID(setcomp) 338 STRUCT_FOR_ID(setstate) 339 STRUCT_FOR_ID(sort) 340 STRUCT_FOR_ID(stderr) 341 STRUCT_FOR_ID(stdin) 342 STRUCT_FOR_ID(stdout) 343 STRUCT_FOR_ID(strict) 344 STRUCT_FOR_ID(symmetric_difference_update) 345 STRUCT_FOR_ID(tell) 346 STRUCT_FOR_ID(text) 347 STRUCT_FOR_ID(threading) 348 STRUCT_FOR_ID(throw) 349 STRUCT_FOR_ID(top) 350 STRUCT_FOR_ID(truncate) 351 STRUCT_FOR_ID(unraisablehook) 352 STRUCT_FOR_ID(values) 353 STRUCT_FOR_ID(version) 354 STRUCT_FOR_ID(warnings) 355 STRUCT_FOR_ID(warnoptions) 356 STRUCT_FOR_ID(writable) 357 STRUCT_FOR_ID(write) 358 STRUCT_FOR_ID(zipimporter) 359 } identifiers; 360 struct { 361 PyASCIIObject _ascii; 362 uint8_t _data[2]; 363 } ascii[128]; 364 struct { 365 PyCompactUnicodeObject _latin1; 366 uint8_t _data[2]; 367 } latin1[128]; 368 }; 369 /* End auto-generated code */ 370 371 #undef ID 372 #undef STR 373 374 375 #define _Py_ID(NAME) \ 376 (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base)) 377 #define _Py_STR(NAME) \ 378 (_Py_SINGLETON(strings.literals._ ## NAME._ascii.ob_base)) 379 380 /* _Py_DECLARE_STR() should precede all uses of _Py_STR() in a function. 381 382 This is true even if the same string has already been declared 383 elsewhere, even in the same file. Mismatched duplicates are detected 384 by Tools/scripts/generate-global-objects.py. 385 386 Pairing _Py_DECLARE_STR() with every use of _Py_STR() makes sure the 387 string keeps working even if the declaration is removed somewhere 388 else. It also makes it clear what the actual string is at every 389 place it is being used. */ 390 #define _Py_DECLARE_STR(name, str) 391 392 #ifdef __cplusplus 393 } 394 #endif 395 #endif /* !Py_INTERNAL_GLOBAL_STRINGS_H */ 396