cpython/Modules/_sqlite
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
..
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
blob.c gh-92019: Make sqlite3.Blob indexing conform with the norm (#92020) 2022-04-30 09:01:37 -06:00
blob.h gh-69093: Support basic incremental I/O to blobs in sqlite3 (GH-30680) 2022-04-14 17:02:56 -07:00
connection.c [3.12] gh-108083: Don't ignore exceptions in sqlite3.Connection.__init__() and .close() (#108084) (#108141) 2023-08-20 01:07:41 +02:00
connection.h gh-83638: Add sqlite3.Connection.autocommit for PEP 249 compliant behaviour (#93823) 2022-11-12 23:44:41 +01:00
cursor.c [3.12] gh-117995: Don't raise DeprecationWarnings for indexed nameless params (GH-118001) (#118142) 2024-04-22 06:58:41 +00:00
cursor.h bpo-44092: Remove unused member reset from sqlite3.Cursor (GH-30377) 2022-01-03 15:47:16 -08:00
microprotocols.c gh-93829: In sqlite3, replace Py_BuildValue with faster APIs (#93830) 2022-06-15 10:42:49 +02:00
microprotocols.h bpo-42064: Convert sqlite3 global state to module state (GH-29073) 2021-10-27 13:12:21 +02:00
module.c gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205) 2023-05-05 21:11:27 +00:00
module.h gh-83638: Add sqlite3.Connection.autocommit for PEP 249 compliant behaviour (#93823) 2022-11-12 23:44:41 +01:00
prepare_protocol.c gh-94321: Document sqlite3.PrepareProtocol (#94620) 2022-07-08 00:33:17 +02:00
prepare_protocol.h Remove unused UNKNOWN macros from cursor.h and prepare_protocol.h (GH-27885) 2021-08-22 22:23:45 +09:00
row.c bpo-42064: Convert sqlite3 global state to module state (GH-29073) 2021-10-27 13:12:21 +02:00
row.h bpo-42064: Remove stale extern declarations in sqlite3 headers (GH-26840) 2021-06-23 21:06:53 +09:00
statement.c gh-88239: Use sqlite3_stmt_busy() to determine if statements are in use (#25984) 2022-06-27 09:58:56 +02:00
statement.h gh-88239: Use sqlite3_stmt_busy() to determine if statements are in use (#25984) 2022-06-27 09:58:56 +02:00
util.c gh-89022: Improve sqlite3 exceptions related to binding params and API misuse (#91572) 2022-05-04 07:16:01 -06:00
util.h gh-92206: Move pysqlite_step() to Modules/_sqlite/cursor.c (#92207) 2022-05-02 21:45:04 -06:00