From 8cdd24ddd7d07a1cc6dda42a202bb66b756c5f63 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Thu, 27 Apr 2023 22:28:24 +0900 Subject: [PATCH 1/4] gh-103906: Remove immortal refcounting in compile.c --- Python/compile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Python/compile.c b/Python/compile.c index a0ad3687f586d8..0dc85e11cebf6a 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -892,10 +892,10 @@ static PyObject* merge_consts_recursive(PyObject *const_cache, PyObject *o) { assert(PyDict_CheckExact(const_cache)); - // None and Ellipsis are singleton, and key is the singleton. + // None and Ellipsis are immortal object, and key is the singleton. // No need to merge object and key. if (o == Py_None || o == Py_Ellipsis) { - return Py_NewRef(o); + return o; } PyObject *key = _PyCode_ConstantKey(o); From 6d0dd681f9ecb18ffec79e1db4a3e4ab3c6d7974 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Thu, 27 Apr 2023 22:32:56 +0900 Subject: [PATCH 2/4] Remove refcounting for Py_None --- Python/compile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/compile.c b/Python/compile.c index 0dc85e11cebf6a..22a30253e029b4 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -5706,7 +5706,7 @@ compiler_error(struct compiler *c, location loc, } PyObject *loc_obj = PyErr_ProgramTextObject(c->c_filename, loc.lineno); if (loc_obj == NULL) { - loc_obj = Py_NewRef(Py_None); + loc_obj = Py_None; } PyObject *args = Py_BuildValue("O(OiiOii)", msg, c->c_filename, loc.lineno, loc.col_offset + 1, loc_obj, From 57d9b5fac61647b2630be8dea26424e9c8ae0761 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Thu, 27 Apr 2023 23:10:53 +0900 Subject: [PATCH 3/4] Update Python/compile.c Co-authored-by: Jelle Zijlstra --- Python/compile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/compile.c b/Python/compile.c index 22a30253e029b4..2dfa06eaac810a 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -892,7 +892,7 @@ static PyObject* merge_consts_recursive(PyObject *const_cache, PyObject *o) { assert(PyDict_CheckExact(const_cache)); - // None and Ellipsis are immortal object, and key is the singleton. + // None and Ellipsis are immortal objects, and key is the singleton. // No need to merge object and key. if (o == Py_None || o == Py_Ellipsis) { return o; From 414eae5a050d0d84a85403f4458de02490765739 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Thu, 27 Apr 2023 23:15:36 +0900 Subject: [PATCH 4/4] Remove more cases --- Objects/sliceobject.c | 2 +- Python/marshal.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c index e6776ac92b669c..5a33977f064421 100644 --- a/Objects/sliceobject.c +++ b/Objects/sliceobject.c @@ -26,7 +26,7 @@ ellipsis_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) PyErr_SetString(PyExc_TypeError, "EllipsisType takes no arguments"); return NULL; } - return Py_NewRef(Py_Ellipsis); + return Py_Ellipsis; } static void diff --git a/Python/marshal.c b/Python/marshal.c index 2966139cec9ae9..7f5d5d71529300 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -1015,7 +1015,7 @@ r_object(RFILE *p) break; case TYPE_NONE: - retval = Py_NewRef(Py_None); + retval = Py_None; break; case TYPE_STOPITER: @@ -1023,15 +1023,15 @@ r_object(RFILE *p) break; case TYPE_ELLIPSIS: - retval = Py_NewRef(Py_Ellipsis); + retval = Py_Ellipsis; break; case TYPE_FALSE: - retval = Py_NewRef(Py_False); + retval = Py_False; break; case TYPE_TRUE: - retval = Py_NewRef(Py_True); + retval = Py_True; break; case TYPE_INT: