From 897dfe950d05b80802f1385a85d5a3665ebfbac4 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 14 Nov 2022 16:27:03 +0100 Subject: [PATCH 1/2] gh-99300: Use Py_NewRef() in PC/ directory Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and Py_XNewRef() in test C files of the PC/ directory. --- PC/_msi.c | 3 +-- PC/winreg.c | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/PC/_msi.c b/PC/_msi.c index 01f7fea7d2b6db..b104e3c6ef548c 100644 --- a/PC/_msi.c +++ b/PC/_msi.c @@ -701,8 +701,7 @@ _msi_SummaryInformation_GetProperty_impl(msiobj *self, int field) result = PyBytes_FromStringAndSize(sval, ssize); break; case VT_EMPTY: - Py_INCREF(Py_None); - result = Py_None; + result = Py_NewRef(Py_None); break; default: PyErr_Format(PyExc_NotImplementedError, "result of type %d", type); diff --git a/PC/winreg.c b/PC/winreg.c index 6ae0d8169cc56b..9f7b756227b444 100644 --- a/PC/winreg.c +++ b/PC/winreg.c @@ -308,8 +308,7 @@ static PyHKEYObject * winreg_HKEYType___enter___impl(PyHKEYObject *self) /*[clinic end generated code: output=52c34986dab28990 input=c40fab1f0690a8e2]*/ { - Py_XINCREF(self); - return self; + return Py_XNewRef(self); } @@ -784,8 +783,7 @@ Reg2Py(BYTE *retDataBuf, DWORD retDataSize, DWORD typ) support it natively, we should handle the bits. */ default: if (retDataSize == 0) { - Py_INCREF(Py_None); - obData = Py_None; + obData = Py_NewRef(Py_None); } else obData = PyBytes_FromStringAndSize( From 4e2a5a0343fad1a771663d1516519f4743c63fd8 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 14 Nov 2022 18:05:33 +0100 Subject: [PATCH 2/2] Fix compiler warning: add cast --- PC/winreg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PC/winreg.c b/PC/winreg.c index 9f7b756227b444..df34e8cf5a77a9 100644 --- a/PC/winreg.c +++ b/PC/winreg.c @@ -308,7 +308,7 @@ static PyHKEYObject * winreg_HKEYType___enter___impl(PyHKEYObject *self) /*[clinic end generated code: output=52c34986dab28990 input=c40fab1f0690a8e2]*/ { - return Py_XNewRef(self); + return (PyHKEYObject*)Py_XNewRef(self); }