mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00

This backports several PRs for gh-113993, making interned strings mortal so they can be garbage-collected when no longer needed. * Allow interned strings to be mortal, and fix related issues (GH-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 * Don't immortalize in PyUnicode_InternInPlace; keep immortalizing in other API (GH-121364) * Switch PyUnicode_InternInPlace to _PyUnicode_InternMortal, clarify docs * Document immortality in some functions that take `const char *` This is PyUnicode_InternFromString; PyDict_SetItemString, PyObject_SetAttrString; PyObject_DelAttrString; PyUnicode_InternFromString; and the PyModule_Add convenience functions. Always point out a non-immortalizing alternative. * Don't immortalize user-provided attr names in _ctypes * Immortalize names in code objects to avoid crash (GH-121903) * Intern latin-1 one-byte strings at startup (GH-122303) There are some 3.12-specific changes, mainly to allow statically allocated strings in deepfreeze. (In 3.13, deepfreeze switched to the general `_Py_ID`/`_Py_STR`.) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
37 lines
1.9 KiB
C
Generated
37 lines
1.9 KiB
C
Generated
// Auto-generated by Programs/freeze_test_frozenmain.py
|
|
unsigned char M_test_frozenmain[] = {
|
|
227,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,
|
|
0,0,0,0,0,243,162,0,0,0,151,0,100,0,100,1,
|
|
108,0,90,0,100,0,100,1,108,1,90,1,2,0,101,2,
|
|
100,2,171,1,0,0,0,0,0,0,1,0,2,0,101,2,
|
|
100,3,101,0,106,6,0,0,0,0,0,0,0,0,0,0,
|
|
0,0,0,0,0,0,0,0,171,2,0,0,0,0,0,0,
|
|
1,0,2,0,101,1,106,8,0,0,0,0,0,0,0,0,
|
|
0,0,0,0,0,0,0,0,0,0,171,0,0,0,0,0,
|
|
0,0,100,4,25,0,0,0,90,5,100,5,68,0,93,19,
|
|
0,0,90,6,2,0,101,2,100,6,101,6,155,0,100,7,
|
|
101,5,101,6,25,0,0,0,155,0,157,4,171,1,0,0,
|
|
0,0,0,0,1,0,140,21,4,0,121,1,41,8,233,0,
|
|
0,0,0,78,122,18,70,114,111,122,101,110,32,72,101,108,
|
|
108,111,32,87,111,114,108,100,122,8,115,121,115,46,97,114,
|
|
103,118,218,6,99,111,110,102,105,103,41,5,218,12,112,114,
|
|
111,103,114,97,109,95,110,97,109,101,218,10,101,120,101,99,
|
|
117,116,97,98,108,101,218,15,117,115,101,95,101,110,118,105,
|
|
114,111,110,109,101,110,116,218,17,99,111,110,102,105,103,117,
|
|
114,101,95,99,95,115,116,100,105,111,218,14,98,117,102,102,
|
|
101,114,101,100,95,115,116,100,105,111,122,7,99,111,110,102,
|
|
105,103,32,122,2,58,32,41,7,218,3,115,121,115,218,17,
|
|
95,116,101,115,116,105,110,116,101,114,110,97,108,99,97,112,
|
|
105,218,5,112,114,105,110,116,218,4,97,114,103,118,218,11,
|
|
103,101,116,95,99,111,110,102,105,103,115,114,3,0,0,0,
|
|
218,3,107,101,121,169,0,243,0,0,0,0,250,18,116,101,
|
|
115,116,95,102,114,111,122,101,110,109,97,105,110,46,112,121,
|
|
218,8,60,109,111,100,117,108,101,62,114,18,0,0,0,1,
|
|
0,0,0,115,97,0,0,0,240,3,1,1,1,243,8,0,
|
|
1,11,219,0,24,225,0,5,208,6,26,212,0,27,217,0,
|
|
5,128,106,144,35,151,40,145,40,212,0,27,216,9,38,208,
|
|
9,26,215,9,38,209,9,38,211,9,40,168,24,209,9,50,
|
|
128,6,243,2,6,12,2,128,67,241,14,0,5,10,136,71,
|
|
144,67,144,53,152,2,152,54,160,35,153,59,152,45,208,10,
|
|
40,213,4,41,241,15,6,12,2,114,16,0,0,0,
|
|
};
|