]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-103906: Remove immortal refcounting in compile/marshal.c (gh-103922)
authorDong-hee Na <donghee.na@python.org>
Mon, 5 Jun 2023 13:38:36 +0000 (22:38 +0900)
committerGitHub <noreply@github.com>
Mon, 5 Jun 2023 13:38:36 +0000 (22:38 +0900)
Objects/sliceobject.c
Python/compile.c
Python/marshal.c

index e6776ac92b669ce405635f0cb7c0857dbbe640a5..5a33977f06442181848d711c55c3363661af6ae7 100644 (file)
@@ -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
index d52c2b0802b5460f5a9042e6f550d2928ea7f369..32431728422765266296f9e254c9eeceb2427e63 100644 (file)
@@ -900,10 +900,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 objects, 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);
@@ -6355,7 +6355,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,
index 6439503d2c687967ba70170957edf50014f282b4..352976b1d69f04f4ba04a6e2190b9d7211c9d879 100644 (file)
@@ -1019,7 +1019,7 @@ r_object(RFILE *p)
         break;
 
     case TYPE_NONE:
-        retval = Py_NewRef(Py_None);
+        retval = Py_None;
         break;
 
     case TYPE_STOPITER:
@@ -1027,15 +1027,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: