Commit 70bfeae
[3.13] pythongh-113993: Allow interned strings to be mortal, and fix related issues (pythonGH-120520)
* Add an InternalDocs file describing how interning should work and how to use it.
* Add internal functions to *explicitly* request what kind of interning is done:
- `_PyUnicode_InternMortal`
- `_PyUnicode_InternImmortal`
- `_PyUnicode_InternStatic`
* Switch uses of `PyUnicode_InternInPlace` to those.
* Disallow using `_Py_SetImmortal` on strings directly.
You should use `_PyUnicode_InternImmortal` instead:
- Strings should be interned before immortalization, otherwise you're possibly
interning a immortalizing copy.
- `_Py_SetImmortal` doesn't handle the `SSTATE_INTERNED_MORTAL` to
`SSTATE_INTERNED_IMMORTAL` update, and those flags can't be changed in
backports, as they are now part of public API and version-specific ABI.
* Add private `_only_immortal` argument for `sys.getunicodeinternedsize`, used in refleak test machinery.
* Make sure the statically allocated string singletons are unique. This means these sets are now disjoint:
- `_Py_ID`
- `_Py_STR` (including the empty string)
- one-character latin-1 singletons
Now, when you intern a singleton, that exact singleton will be interned.
* Add a `_Py_LATIN1_CHR` macro, use it instead of `_Py_ID`/`_Py_STR` for one-character latin-1 singletons everywhere (including Clinic).
* Intern `_Py_STR` singletons at startup.
* For free-threaded builds, intern `_Py_LATIN1_CHR` singletons at startup.
* Beef up the tests. Cover internal details (marked with `@cpython_only`).
* Add lots of assertions
Co-Authored-By: Eric Snow <[email protected]>1 parent 732c005 commit 70bfeae
File tree
42 files changed
+2456
-1136
lines changed- Include/internal
- InternalDocs
- Lib/test
- libregrtest
- Misc/NEWS.d/next/Core and Builtins
- Modules
- _io
- _sqlite/clinic
- clinic
- Objects
- Parser
- Python
- clinic
- Tools
- build
- clinic/libclinic
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
42 files changed
+2456
-1136
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | 40 | | |
42 | 41 | | |
43 | 42 | | |
44 | 43 | | |
45 | | - | |
46 | 44 | | |
47 | 45 | | |
48 | 46 | | |
49 | 47 | | |
50 | 48 | | |
51 | 49 | | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | 50 | | |
56 | 51 | | |
57 | 52 | | |
| |||
66 | 61 | | |
67 | 62 | | |
68 | 63 | | |
69 | | - | |
70 | 64 | | |
71 | 65 | | |
72 | 66 | | |
| |||
260 | 254 | | |
261 | 255 | | |
262 | 256 | | |
| 257 | + | |
263 | 258 | | |
264 | 259 | | |
265 | 260 | | |
| |||
272 | 267 | | |
273 | 268 | | |
274 | 269 | | |
275 | | - | |
276 | 270 | | |
277 | 271 | | |
278 | 272 | | |
| |||
296 | 290 | | |
297 | 291 | | |
298 | 292 | | |
299 | | - | |
300 | 293 | | |
301 | 294 | | |
302 | 295 | | |
| |||
314 | 307 | | |
315 | 308 | | |
316 | 309 | | |
317 | | - | |
318 | 310 | | |
319 | 311 | | |
320 | 312 | | |
| |||
370 | 362 | | |
371 | 363 | | |
372 | 364 | | |
373 | | - | |
374 | 365 | | |
375 | 366 | | |
376 | 367 | | |
| |||
399 | 390 | | |
400 | 391 | | |
401 | 392 | | |
402 | | - | |
403 | 393 | | |
404 | 394 | | |
405 | 395 | | |
| |||
423 | 413 | | |
424 | 414 | | |
425 | 415 | | |
426 | | - | |
427 | 416 | | |
428 | 417 | | |
429 | 418 | | |
| |||
456 | 445 | | |
457 | 446 | | |
458 | 447 | | |
459 | | - | |
460 | 448 | | |
461 | 449 | | |
462 | 450 | | |
| |||
470 | 458 | | |
471 | 459 | | |
472 | 460 | | |
473 | | - | |
474 | 461 | | |
475 | 462 | | |
476 | 463 | | |
| |||
581 | 568 | | |
582 | 569 | | |
583 | 570 | | |
584 | | - | |
585 | 571 | | |
586 | 572 | | |
587 | 573 | | |
| |||
627 | 613 | | |
628 | 614 | | |
629 | 615 | | |
630 | | - | |
631 | 616 | | |
632 | 617 | | |
633 | 618 | | |
| |||
655 | 640 | | |
656 | 641 | | |
657 | 642 | | |
658 | | - | |
659 | 643 | | |
660 | 644 | | |
661 | 645 | | |
| |||
679 | 663 | | |
680 | 664 | | |
681 | 665 | | |
682 | | - | |
683 | 666 | | |
684 | 667 | | |
685 | 668 | | |
| |||
786 | 769 | | |
787 | 770 | | |
788 | 771 | | |
789 | | - | |
790 | 772 | | |
791 | 773 | | |
792 | 774 | | |
| |||
809 | 791 | | |
810 | 792 | | |
811 | 793 | | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
812 | 798 | | |
813 | 799 | | |
814 | 800 | | |
| |||
0 commit comments