From e03262d3d6e6f946d7b6d98e7ea76b6c69c20eee Mon Sep 17 00:00:00 2001 From: Jade Abraham Date: Fri, 17 Jan 2025 12:50:11 -0800 Subject: [PATCH] incref none Signed-off-by: Jade Abraham --- tools/chapel-py/src/core-types-gen.cpp | 4 +++- tools/chapel-py/src/python-types.h | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/chapel-py/src/core-types-gen.cpp b/tools/chapel-py/src/core-types-gen.cpp index fa0c59623d50..dfb792e3f2b3 100644 --- a/tools/chapel-py/src/core-types-gen.cpp +++ b/tools/chapel-py/src/core-types-gen.cpp @@ -97,7 +97,9 @@ struct InvokeHelper { template static PyObject* invoke(ContextObject* contextObject, F&& fn) { fn(); - Py_RETURN_NONE; + // In python3.12, Py_None is immortal and this is not needed + Py_INCREF(Py_None); + return Py_None; } }; diff --git a/tools/chapel-py/src/python-types.h b/tools/chapel-py/src/python-types.h index 2a4d1f2815a9..f1e171d10709 100644 --- a/tools/chapel-py/src/python-types.h +++ b/tools/chapel-py/src/python-types.h @@ -135,7 +135,9 @@ PyObject* wrapOptional(ContextObject* context, const std::optional& opt) { if (opt) { return PythonReturnTypeInfo::wrap(context, *opt); } else { - Py_RETURN_NONE; + // In python3.12, Py_None is immortal and this is not needed + Py_INCREF(Py_None); + return Py_None; } } @@ -211,7 +213,9 @@ PyObject* wrapNilable(ContextObject* context, const Nilable& opt) { if (opt.value) { return PythonReturnTypeInfo::wrap(context, opt.value); } else { - Py_RETURN_NONE; + // In python3.12, Py_None is immortal and this is not needed + Py_INCREF(Py_None); + return Py_None; } }