cpython/Modules
Petr Viktorin 49f6beb56a
[3.12] gh-113993: Make interned strings mortal (GH-120520, GH-121364, GH-121903, GH-122303) (#123065)
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>
2024-09-27 13:28:48 -07:00
..
_blake2 gh-116116: Backport blake2 change to fix building with clang-cl on windows-i686 (GH-116117) 2024-03-04 17:22:46 +00:00
_ctypes [3.12] gh-113993: Make interned strings mortal (GH-120520, GH-121364, GH-121903, GH-122303) (#123065) 2024-09-27 13:28:48 -07:00
_decimal [3.12] gh-114563: C decimal falls back to pydecimal for unsupported format strings (GH-114879) (GH-115353) 2024-02-12 23:31:12 +02:00
_hacl [3.12] gh-99108: Refresh HACL*; update modules accordingly; fix namespacing (GH-117237) (GH-117243) 2024-03-26 01:43:24 +00:00
_io [3.12] gh-113993: Make interned strings mortal (GH-120520, GH-121364, GH-121903, GH-122303) (#123065) 2024-09-27 13:28:48 -07:00
_multiprocessing [3.12] gh-115886: Handle embedded null characters in shared memory name (GH-115887) (GH-115906) 2024-02-25 11:09:28 +00:00
_sqlite [3.12] gh-113993: Make interned strings mortal (GH-120520, GH-121364, GH-121903, GH-122303) (#123065) 2024-09-27 13:28:48 -07:00
_sre [3.12] gh-120155: Add assertion to sre.c match_getindex() (GH-120402) (#120410) 2024-06-12 13:57:45 +00:00
_ssl GH-103092: isolate _ssl (#104725) 2023-05-22 06:14:48 +05:30
_testcapi [3.12] gh-111495: Add tests for PyNumber C API (GH-111996) (#123376) 2024-09-06 00:51:26 +02:00
_xxtestfuzz [3.12] gh-121023: Improve _xxtestfuzz/README.rst (GH-121024) (#124141) 2024-09-16 20:29:02 +00:00
cjkcodecs [3.12] gh-115015: Argument Clinic: fix generated code for METH_METHOD methods without params (#115016) (#115067) 2024-02-06 11:20:16 +01:00
clinic [3.12] gh-113993: Make interned strings mortal (GH-120520, GH-121364, GH-121903, GH-122303) (#123065) 2024-09-27 13:28:48 -07:00
expat [3.12] gh-123678: Upgrade libexpat 2.6.3 (GH-123689) (GH-123708) 2024-09-04 20:19:33 +00:00
_abc.c gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205) 2023-05-05 21:11:27 +00:00
_asynciomodule.c [3.12] gh-112182: Replace StopIteration with RuntimeError for future (GH-113220) (GH-123033) 2024-08-15 15:34:53 +00:00
_bisectmodule.c gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205) 2023-05-05 21:11:27 +00:00
_bz2module.c gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205) 2023-05-05 21:11:27 +00:00
_codecsmodule.c gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205) 2023-05-05 21:11:27 +00:00
_collectionsmodule.c [3.12] gh-115243: Fix crash in deque.index() when the deque is concurrently modified (GH-115247) (GH-115465) 2024-02-14 17:17:58 +00:00
_contextvarsmodule.c gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205) 2023-05-05 21:11:27 +00:00
_cryptmodule.c gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205) 2023-05-05 21:11:27 +00:00
_csv.c [3.12] gh-113785: csv: fields starting with escapechar are not quoted (GH-122110) (GH-122259) 2024-08-09 16:04:29 +00:00
_curses_panel.c [3.12] gh-86493: Fix possible leaks in modules initialization: _curses_panel, _decimal, posix, xxsubtype (GH-106767) (#106849) 2023-07-18 10:03:59 +03:00
_cursesmodule.c [3.12] gh-107913: Fix possible losses of OSError error codes (GH-107930) (#108523) 2023-08-27 01:24:40 +02:00
_datetimemodule.c Revert "[3.12] gh-120713: Normalize year with century for datetime.strftime (GH-120820) (GH-121145)" (GH-122409) 2024-07-29 21:55:12 +03:00
_dbmmodule.c gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205) 2023-05-05 21:11:27 +00:00
_elementtree.c [3.12] gh-123213: Fixed xml.etree.ElementTree.Element.extend and assignment to no longer hide exceptions (GH-123214) (#123258) 2024-09-06 11:51:18 +03:00
_functoolsmodule.c gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205) 2023-05-05 21:11:27 +00:00
_gdbmmodule.c gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205) 2023-05-05 21:11:27 +00:00
_hashopenssl.c [3.12] gh-117233: Detect support for several hashes at hashlib build time (GH-117234) (#117767) 2024-04-11 18:36:31 +00:00
_heapqmodule.c gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205) 2023-05-05 21:11:27 +00:00
_json.c gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205) 2023-05-05 21:11:27 +00:00
_localemodule.c [3.12] gh-121905: Consistently use "floating-point" instead of "floating point" (GH-121907) (GH-122013) 2024-07-19 09:08:33 +00:00
_lsprof.c [3.12] gh-120289: Add external timer in traverse of _lsprof.Profiler (GH-121998) (#122001) 2024-07-19 04:05:08 +00:00
_lzmamodule.c [3.12] gh-104282: Fix null pointer dereference in lzma._decode_filter_properties (GH-104283) (GH-114181) 2024-01-17 13:31:33 +00:00
_math.h gh-101678: refactor the math module to use special functions from c11 (GH-101679) 2023-02-09 00:40:52 -08:00
_opcode.c gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205) 2023-05-05 21:11:27 +00:00
_operator.c [3.12] gh-113993: Make interned strings mortal (GH-120520, GH-121364, GH-121903, GH-122303) (#123065) 2024-09-27 13:28:48 -07:00
_pickle.c [3.12] gh-113993: Make interned strings mortal (GH-120520, GH-121364, GH-121903, GH-122303) (#123065) 2024-09-27 13:28:48 -07:00
_posixsubprocess.c [3.12] gh-113964: Don't prevent new threads until all non-daemon threads exit (GH-116677) (#117029) 2024-03-19 15:22:42 -04:00
_queuemodule.c [3.12] gh-104812: Run Pending Calls in any Thread (gh-104813) (gh-105752) 2023-06-14 00:50:08 +00:00
_randommodule.c gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205) 2023-05-05 21:11:27 +00:00
_scproxy.c gh-104180: Read SOCKS proxies from macOS System Configuration (#104181) 2023-05-09 10:24:29 +02:00
_ssl.c [3.12] gh-117310: Remove extra DECREF on "no ciphers" error path in _ssl._SSLContext constructor (GH-117309) (GH-117317) 2024-03-28 10:04:57 -07:00
_ssl.h GH-103092: isolate _ssl (#104725) 2023-05-22 06:14:48 +05:30
_ssl_data.h
_ssl_data_31.h [3.12] gh-103142: Upgrade binary builds and CI to OpenSSL 1.1.1u (GH-105174) (#105199) 2023-06-01 17:13:35 +00:00
_ssl_data_111.h [3.12] gh-103142: Upgrade binary builds and CI to OpenSSL 1.1.1u (GH-105174) (#105199) 2023-06-01 17:13:35 +00:00
_ssl_data_300.h [3.12] gh-103142: Upgrade binary builds and CI to OpenSSL 1.1.1u (GH-105174) (#105199) 2023-06-01 17:13:35 +00:00
_stat.c [3.12] gh-86493: Fix possible leaks in some modules initialization (GH-106768) (GH-106855) 2023-07-18 15:14:10 +03:00
_statisticsmodule.c gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205) 2023-05-05 21:11:27 +00:00
_struct.c [3.12] gh-124248: Fix crash in struct when processing 0p fields (GH-124251) (#124278) 2024-09-20 10:29:43 +00:00
_testbuffer.c [3.12] gh-114670: Fix _testbuffer module initialization (GH-114672) (#115272) 2024-02-11 10:53:00 +03:00
_testcapi_feature_macros.inc [3.12] gh-102304: doc: Add links to Stable ABI and Limited C API (#105345) (#105371) 2023-06-06 13:11:28 +00:00
_testcapimodule.c [3.12] gh-119585: Fix crash involving PyGILState_Release() and PyThreadState_Clear() (GH-119753) (#119861) 2024-05-31 15:42:09 +00:00
_testclinic.c [3.12] gh-118814: Fix the TypeVar constructor when name is passed by keyword (GH-122664) (GH-122807) 2024-08-08 09:49:50 +03:00
_testimportmultiple.c
_testinternalcapi.c [3.12] gh-119213: Be More Careful About _PyArg_Parser.kwtuple Across Interpreters (gh-119331) (gh-119425) 2024-05-22 22:26:58 +00:00
_testmultiphase.c gh-99113: Add a check for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104206) 2023-05-06 21:57:35 +00:00
_testsinglephase.c [3.12] gh-102251: Explicitly free state for test modules with state in test_import (GH-105085) (#105170) 2023-05-31 21:34:21 +00:00
_threadmodule.c [3.12] gh-113964: Don't prevent new threads until all non-daemon threads exit (GH-116677) (#117029) 2024-03-19 15:22:42 -04:00
_tkinter.c [3.12] gh-119614: Fix truncation of strings with embedded null characters in Tkinter (GH-120909) (GH-120939) 2024-06-24 09:39:56 +00:00
_tracemalloc.c GH-101520: Move tracemalloc functionality into core, leaving interface in Modules. (#104508) 2023-05-17 14:17:16 +01:00
_typingmodule.c gh-104549: Set __module__ on TypeAliasType (#104550) 2023-05-18 15:56:15 -07:00
_uuidmodule.c gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205) 2023-05-05 21:11:27 +00:00
_weakref.c gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205) 2023-05-05 21:11:27 +00:00
_winapi.c gh-100256: Skip inaccessible registry keys in the WinAPI mimetype implementation (GH-122047) 2024-08-07 19:39:51 +01:00
_xxinterpchannelsmodule.c [3.12] gh-76785: Use Pending Calls When Releasing Cross-Interpreter Data (gh-109556) (gh-112288) 2023-11-27 14:49:48 -07:00
_xxsubinterpretersmodule.c [3.12] gh-105716: Support Background Threads in Subinterpreters Consistently (gh-109921) (gh-110707) 2023-11-27 19:01:05 -07:00
_zoneinfo.c [3.12] gh-120155: Fix Coverity issue in zoneinfo load_data() (GH-120232) (#120311) 2024-06-10 10:12:25 +00:00
addrinfo.h gh-95174: WASI: skip missing sockets functions (GH-95179) 2022-07-27 08:19:23 +02:00
arraymodule.c [3.12] gh-121905: Consistently use "floating-point" instead of "floating point" (GH-121907) (GH-122013) 2024-07-19 09:08:33 +00:00
atexitmodule.c gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205) 2023-05-05 21:11:27 +00:00
audioop.c [3.12] gh-46968: Fix invalid reference to Sound eXchange (SoX) 12.17.7 license (#115094) 2024-02-06 18:59:23 +01:00
binascii.c [3.12] gh-118314: Fix padding edge case in binascii.a2b_base64 strict mode (GH-118320) (GH-118691) 2024-05-07 09:35:49 +00:00
cmathmodule.c [3.12] gh-86493: Fix possible leaks in some modules initialization (GH-106768) (GH-106855) 2023-07-18 15:14:10 +03:00
config.c.in Add tests for the C tokenizer and expose it as a private module (GH-27924) 2021-08-24 17:50:05 +01:00
errnomodule.c [3.12] gh-105375: Improve errnomodule error handling (#105590) (#105596) 2023-06-09 20:36:53 +00:00
faulthandler.c [3.12] gh-121905: Consistently use "floating-point" instead of "floating point" (GH-121907) (GH-122013) 2024-07-19 09:08:33 +00:00
fcntlmodule.c [3.12] Revert "[3.12] gh-69214: Fix fcntl.ioctl() request type (#119498) (#1… (#119905) 2024-06-01 17:08:07 +02:00
gc_weakref.txt Fix links to old SF bugs (#95648) 2022-08-04 18:12:35 +02:00
gcmodule.c [3.12] gh-116510: Fix crash during sub-interpreter shutdown (gh-124536) 2024-09-26 17:50:46 -07:00
getaddrinfo.c gh-74895: getaddrinfo no longer raises OverflowError (#2435) 2023-02-13 17:37:34 -08:00
getbuildinfo.c gh-81057: Move Globals in Core Code to _PyRuntimeState (gh-99496) 2022-11-15 09:45:11 -07:00
getnameinfo.c gh-95174: WASI: skip missing sockets functions (GH-95179) 2022-07-27 08:19:23 +02:00
getpath.c [3.12] gh-115136: Fix possible NULL deref in getpath_joinpath() (GH-115137) (GH-115157) 2024-02-08 11:18:38 +02:00
getpath.py gh-101543: Ensure Windows registry path is only used when stdlib can't be found (GH-101544) 2023-02-06 15:55:32 +00:00
getpath_noop.c bpo-45582: Port getpath[p].c to Python (GH-29041) 2021-12-03 00:08:42 +00:00
grpmodule.c [3.12] gh-104432: Use memcpy() to avoid misaligned loads (GH-104433) (#107355) 2023-07-27 13:52:39 -07:00
hashlib.h [3.12] gh-99108: Release the GIL around hashlib built-in computation (GH-104675) (#104776) 2023-05-23 11:24:02 +00:00
itertoolsmodule.c [3.12] gh-115874: Don't use module state in teedataobject tp_dealloc (GH-116204) (#116955) 2024-03-18 12:40:34 +00:00
ld_so_aix.in
main.c [3.12] gh-121957: Emit audit events for python -i and python -m asyncio (GH-122117) 2024-07-22 13:41:23 +02:00
makesetup gh-96269: static and shared ext need different deps (#96316) 2022-11-16 14:03:35 +01:00
makexp_aix
mathmodule.c [3.12] gh-123836: workaround fmod(x, y) bug on Windows (GH-124171) (#124186) 2024-09-17 21:44:52 +02:00
md5module.c [3.12] gh-99108: Refresh HACL*; update modules accordingly; fix namespacing (GH-117237) (GH-117243) 2024-03-26 01:43:24 +00:00
mmapmodule.c gh-81489: Use Unicode APIs for mmap tagname on Windows (GH-14133) 2024-01-11 23:13:02 +00:00
nismodule.c gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205) 2023-05-05 21:11:27 +00:00
ossaudiodev.c bpo-15999: Accept arbitrary values for boolean parameters. (#15609) 2022-12-03 11:52:21 -08:00
overlapped.c [3.12] gh-91227: Ignore ERROR_PORT_UNREACHABLE in proactor recvfrom() (GH-32011) (GH-117209) 2024-03-25 12:21:31 +02:00
posixmodule.c [3.12] gh-121905: Consistently use "floating-point" instead of "floating point" (GH-121907) (GH-122013) 2024-07-19 09:08:33 +00:00
posixmodule.h bpo-41498: Fix build on platforms without sigset_t (GH-29770) 2021-11-25 12:28:41 +01:00
pwdmodule.c [3.12] gh-116545: Fix error handling in mkpwent in pwdmodule (GH-116548) (#116593) 2024-03-11 11:55:09 +00:00
pyexpat.c [3.12] gh-115398: Expose Expat >=2.6.0 reparse deferral API (CVE-2023-52425) (GH-115623) (GH-116248) 2024-03-06 22:01:45 +00:00
readline.c [3.12] gh-112105: Make completer delims work on libedit (gh-112106) (gh-112487) 2023-11-28 06:42:54 +00:00
README
resource.c [3.12] gh-89886: Rely on HAVE_SYS_TIME_H (GH-105058) (#105192) 2023-06-01 12:08:37 +00:00
rotatingtree.c
rotatingtree.h
selectmodule.c [3.12] gh-121905: Consistently use "floating-point" instead of "floating point" (GH-121907) (GH-122013) 2024-07-19 09:08:33 +00:00
Setup [3.12] gh-99108: Refresh HACL* (GH-104808) (#104893) 2023-05-24 20:55:37 +00:00
Setup.bootstrap.in gh-103763: Implement PEP 695 (#103764) 2023-05-15 20:36:23 -07:00
Setup.stdlib.in [3.12] gh-117968: Add tests for the part of the PyRun family of the C API (GH-117982) (GH-118011) 2024-04-22 18:59:28 +00:00
sha1module.c [3.12] gh-99108: Refresh HACL*; update modules accordingly; fix namespacing (GH-117237) (GH-117243) 2024-03-26 01:43:24 +00:00
sha2module.c [3.12] gh-99108: Refresh HACL*; update modules accordingly; fix namespacing (GH-117237) (GH-117243) 2024-03-26 01:43:24 +00:00
sha3module.c [3.12] gh-99108: Refresh HACL*; update modules accordingly; fix namespacing (GH-117237) (GH-117243) 2024-03-26 01:43:24 +00:00
signalmodule.c [3.12] gh-121905: Consistently use "floating-point" instead of "floating point" (GH-121907) (GH-122013) 2024-07-19 09:08:33 +00:00
socketmodule.c [3.12] bpo-37013: Fix the error handling in socket.if_indextoname() (GH-13503) (GH-112597) 2023-12-25 20:55:08 +02:00
socketmodule.h gh-103092: Isolate socket module (#103094) 2023-04-09 06:33:52 +05:30
spwdmodule.c gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205) 2023-05-05 21:11:27 +00:00
symtablemodule.c [3.12] gh-110045: Update symtable module for PEP 695 (GH-110066) (#110070) 2023-09-29 08:10:22 +02:00
syslogmodule.c gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205) 2023-05-05 21:11:27 +00:00
termios.c [3.12] gh-114492: Initialize struct termios before calling tcgetattr() (GH-114495) (GH-114502) 2024-01-23 22:02:02 +00:00
timemodule.c [3.12] Revert "gh-123974: Fix time.get_clock_info() on NetBSD (GH-123975)" (GH-124115) (GH-124200) 2024-09-18 06:47:17 +00:00
tkappinit.c gh-103538: Remove unused TK_AQUA code (GH-103539) 2023-05-10 18:53:13 +00:00
tkinter.h gh-103532: Remove TKINTER_PROTECT_LOADTK code (GH-103535) 2023-04-14 09:04:16 -05:00
unicodedata.c gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205) 2023-05-05 21:11:27 +00:00
unicodedata_db.h closes gh-96734: Update to Unicode 15.0.0. (GH-96809) 2022-09-13 15:45:12 -07:00
unicodename_db.h closes gh-96734: Update to Unicode 15.0.0. (GH-96809) 2022-09-13 15:45:12 -07:00
winreparse.h
xxlimited.c [3.12] gh-110968: Py_MOD_PER_INTERPRETER_GIL_SUPPORTED was added to 3.12 (#111588) 2023-11-01 18:13:31 +01:00
xxlimited_35.c [3.12] gh-110968: Py_MOD_PER_INTERPRETER_GIL_SUPPORTED was added to 3.12 (#111588) 2023-11-01 18:13:31 +01:00
xxmodule.c gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205) 2023-05-05 21:11:27 +00:00
xxsubtype.c [3.12] gh-86493: Fix possible leaks in modules initialization: _curses_panel, _decimal, posix, xxsubtype (GH-106767) (#106849) 2023-07-18 10:03:59 +03:00
zlibmodule.c [3.12] gh-105967: Work around a macOS bug, limit zlib C library crc32 API calls to 1gig (GH-112615) (#112724) 2023-12-04 20:29:23 +00:00

Source files for standard library extension modules,
and former extension modules that are now builtin modules.