Commit 9fd6334
[3.12] 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.
* Beef up the tests. Cover internal details (marked with `@cpython_only`).
* Add lots of assertions
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>1 parent 41090b7 commit 9fd6334
41 files changed
Lines changed: 2298 additions & 1033 deletions
File tree
- Include/internal
- InternalDocs
- Lib/test
- libregrtest
- Misc/NEWS.d/next/Core and Builtins
- Modules
- _io
- _sqlite/clinic
- clinic
- Objects
- PC/clinic
- Parser
- Python
- clinic
- Tools
- build
- clinic
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Some 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 | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | 39 | | |
41 | 40 | | |
42 | 41 | | |
43 | 42 | | |
44 | | - | |
45 | 43 | | |
46 | 44 | | |
47 | 45 | | |
48 | 46 | | |
49 | 47 | | |
50 | 48 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | 49 | | |
55 | 50 | | |
56 | 51 | | |
| |||
66 | 61 | | |
67 | 62 | | |
68 | 63 | | |
69 | | - | |
70 | 64 | | |
71 | 65 | | |
72 | 66 | | |
| |||
255 | 249 | | |
256 | 250 | | |
257 | 251 | | |
| 252 | + | |
258 | 253 | | |
259 | 254 | | |
260 | 255 | | |
| |||
266 | 261 | | |
267 | 262 | | |
268 | 263 | | |
269 | | - | |
270 | 264 | | |
271 | 265 | | |
272 | 266 | | |
| |||
286 | 280 | | |
287 | 281 | | |
288 | 282 | | |
289 | | - | |
290 | 283 | | |
291 | 284 | | |
292 | 285 | | |
| |||
304 | 297 | | |
305 | 298 | | |
306 | 299 | | |
307 | | - | |
308 | 300 | | |
309 | 301 | | |
310 | 302 | | |
| |||
357 | 349 | | |
358 | 350 | | |
359 | 351 | | |
360 | | - | |
361 | 352 | | |
362 | 353 | | |
363 | 354 | | |
| |||
385 | 376 | | |
386 | 377 | | |
387 | 378 | | |
388 | | - | |
389 | 379 | | |
390 | 380 | | |
391 | 381 | | |
| |||
546 | 536 | | |
547 | 537 | | |
548 | 538 | | |
549 | | - | |
550 | 539 | | |
551 | 540 | | |
552 | 541 | | |
| |||
591 | 580 | | |
592 | 581 | | |
593 | 582 | | |
594 | | - | |
595 | 583 | | |
596 | 584 | | |
597 | 585 | | |
| |||
619 | 607 | | |
620 | 608 | | |
621 | 609 | | |
622 | | - | |
623 | 610 | | |
624 | 611 | | |
625 | 612 | | |
| |||
643 | 630 | | |
644 | 631 | | |
645 | 632 | | |
646 | | - | |
647 | 633 | | |
648 | 634 | | |
649 | 635 | | |
| |||
746 | 732 | | |
747 | 733 | | |
748 | 734 | | |
749 | | - | |
750 | 735 | | |
751 | 736 | | |
752 | 737 | | |
| |||
769 | 754 | | |
770 | 755 | | |
771 | 756 | | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
772 | 761 | | |
773 | 762 | | |
774 | 763 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments