From fd46c899d931295b5db36f4ef77da7a31f96944c Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Sat, 25 Oct 2025 05:08:59 -0400 Subject: [PATCH 1/3] [mypyc] feat: make static literals immortal on Python3.14 --- mypyc/lib-rt/misc_ops.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/mypyc/lib-rt/misc_ops.c b/mypyc/lib-rt/misc_ops.c index ca09c347b4ff..34d1eb2b66d5 100644 --- a/mypyc/lib-rt/misc_ops.c +++ b/mypyc/lib-rt/misc_ops.c @@ -619,11 +619,17 @@ int CPyStatics_Initialize(PyObject **statics, PyObject **result = statics; // Start with some hard-coded values *result++ = Py_None; +#if !CPY_3_14_FEATURES Py_INCREF(Py_None); +#endif *result++ = Py_False; +#if !CPY_3_14_FEATURES Py_INCREF(Py_False); +#endif *result++ = Py_True; +#if !CPY_3_14_FEATURES Py_INCREF(Py_True); +#endif if (strings) { for (; **strings != '\0'; strings++) { size_t num; @@ -636,8 +642,11 @@ int CPyStatics_Initialize(PyObject **statics, if (obj == NULL) { return -1; } - PyUnicode_InternInPlace(&obj); + PyUnicode_InternInPlace(&obj); *result++ = obj; +#if CPY_3_14_FEATURES + CPy_SetImmortal(obj); +#endif data += len; } } @@ -655,6 +664,9 @@ int CPyStatics_Initialize(PyObject **statics, return -1; } *result++ = obj; +#if CPY_3_14_FEATURES + CPy_SetImmortal(obj); +#endif data += len; } } @@ -670,6 +682,9 @@ int CPyStatics_Initialize(PyObject **statics, if (obj == NULL) { return -1; } +#if CPY_3_14_FEATURES + CPy_SetImmortal(obj); +#endif data = end; data++; *result++ = obj; @@ -683,6 +698,9 @@ int CPyStatics_Initialize(PyObject **statics, if (obj == NULL) { return -1; } +#if CPY_3_14_FEATURES + CPy_SetImmortal(obj); +#endif *result++ = obj; } } @@ -695,6 +713,9 @@ int CPyStatics_Initialize(PyObject **statics, if (obj == NULL) { return -1; } +#if CPY_3_14_FEATURES + CPy_SetImmortal(obj); +#endif *result++ = obj; } } @@ -706,10 +727,17 @@ int CPyStatics_Initialize(PyObject **statics, if (obj == NULL) { return -1; } +#if CPY_3_14_FEATURES + CPy_SetImmortal(obj); +#endif int i; for (i = 0; i < num_items; i++) { PyObject *item = statics[*tuples++]; +#if CPY_3_14_FEATURES + CPy_SetImmortal(item); +#else Py_INCREF(item); +#endif PyTuple_SET_ITEM(obj, i, item); } *result++ = obj; @@ -723,9 +751,16 @@ int CPyStatics_Initialize(PyObject **statics, if (obj == NULL) { return -1; } +#if CPY_3_14_FEATURES + CPy_SetImmortal(obj); +#endif for (int i = 0; i < num_items; i++) { PyObject *item = statics[*frozensets++]; +#if CPY_3_14_FEATURES + CPy_SetImmortal(item); +#else Py_INCREF(item); +#endif if (PySet_Add(obj, item) == -1) { return -1; } From 20fcc0e872f66a64c537ae581b1e44c2dddcb0d5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 25 Oct 2025 09:10:59 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mypyc/lib-rt/misc_ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypyc/lib-rt/misc_ops.c b/mypyc/lib-rt/misc_ops.c index 34d1eb2b66d5..e9c11aa400d6 100644 --- a/mypyc/lib-rt/misc_ops.c +++ b/mypyc/lib-rt/misc_ops.c @@ -642,7 +642,7 @@ int CPyStatics_Initialize(PyObject **statics, if (obj == NULL) { return -1; } - PyUnicode_InternInPlace(&obj); + PyUnicode_InternInPlace(&obj); *result++ = obj; #if CPY_3_14_FEATURES CPy_SetImmortal(obj); From 8abe9aaaa21351a1d6aa96d5cdb33aebaf4cf6f9 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Sat, 25 Oct 2025 05:19:54 -0400 Subject: [PATCH 3/3] Update misc_ops.c --- mypyc/lib-rt/misc_ops.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mypyc/lib-rt/misc_ops.c b/mypyc/lib-rt/misc_ops.c index e9c11aa400d6..dfbdad106f9d 100644 --- a/mypyc/lib-rt/misc_ops.c +++ b/mypyc/lib-rt/misc_ops.c @@ -751,9 +751,9 @@ int CPyStatics_Initialize(PyObject **statics, if (obj == NULL) { return -1; } -#if CPY_3_14_FEATURES - CPy_SetImmortal(obj); -#endif +//#if CPY_3_14_FEATURES +// CPy_SetImmortal(obj); +//#endif for (int i = 0; i < num_items; i++) { PyObject *item = statics[*frozensets++]; #if CPY_3_14_FEATURES