https://github.com/python/cpython/commit/f6ba0499c4c0bbc21a48869161d0b37aae035743
commit: f6ba0499c4c0bbc21a48869161d0b37aae035743
branch: 3.14
author: Stan Ulbrych <[email protected]>
committer: StanFromIreland <[email protected]>
date: 2026-10-26T19:49:48Z
summary:

[3.14] Fix ignored error returns in `sys` initialization, `_ctypes` and 
`_interpchannels` (GH-160614) (#160712)

(cherry picked from commit 65057c56b9043d68c687042aef7a4cc4f344076d)

files:
M Modules/_ctypes/_ctypes.c
M Modules/_interpchannelsmodule.c
M Python/pylifecycle.c

diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index ac0ffb00e785c31..cf298b0fb49182c 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -2497,22 +2497,30 @@ PyCSimpleType_init(PyObject *self, PyObject *args, 
PyObject *kwds)
         }
         assert(sw_info);
 #ifdef WORDS_BIGENDIAN
-        PyObject_SetAttrString(self, "__ctype_le__", swapped);
-        PyObject_SetAttrString(self, "__ctype_be__", self);
-        PyObject_SetAttrString(swapped, "__ctype_be__", self);
-        PyObject_SetAttrString(swapped, "__ctype_le__", swapped);
+        if (PyObject_SetAttrString(self, "__ctype_le__", swapped) < 0 ||
+            PyObject_SetAttrString(self, "__ctype_be__", self) < 0 ||
+            PyObject_SetAttrString(swapped, "__ctype_be__", self) < 0 ||
+            PyObject_SetAttrString(swapped, "__ctype_le__", swapped) < 0)
+       {
+            Py_DECREF(swapped);
+            return -1;
+        }
         /* We are creating the type for the OTHER endian */
         sw_info->format = _ctypes_alloc_format_string("<", stginfo->format+1);
 #else
-        PyObject_SetAttrString(self, "__ctype_be__", swapped);
-        PyObject_SetAttrString(self, "__ctype_le__", self);
-        PyObject_SetAttrString(swapped, "__ctype_le__", self);
-        PyObject_SetAttrString(swapped, "__ctype_be__", swapped);
+        if (PyObject_SetAttrString(self, "__ctype_be__", swapped) < 0 ||
+            PyObject_SetAttrString(self, "__ctype_le__", self) < 0 ||
+            PyObject_SetAttrString(swapped, "__ctype_le__", self) < 0 ||
+            PyObject_SetAttrString(swapped, "__ctype_be__", swapped) < 0)
+        {
+            Py_DECREF(swapped);
+            return -1;
+        }
         /* We are creating the type for the OTHER endian */
         sw_info->format = _ctypes_alloc_format_string(">", stginfo->format+1);
 #endif
         Py_DECREF(swapped);
-        if (PyErr_Occurred()) {
+        if (sw_info->format == NULL) {
             return -1;
         }
     };
diff --git a/Modules/_interpchannelsmodule.c b/Modules/_interpchannelsmodule.c
index 351509d57de16e9..6516d4592f5eef9 100644
--- a/Modules/_interpchannelsmodule.c
+++ b/Modules/_interpchannelsmodule.c
@@ -2638,7 +2638,7 @@ _channelid_shared(PyThreadState *tstate, PyObject *obj, 
_PyXIData_t *data)
     if (st == NULL) {
         return -1;
     }
-    if (!PyObject_IsInstance(obj, (PyObject *)st->ChannelIDType)) {
+    if (!PyObject_TypeCheck(obj, st->ChannelIDType)) {
         PyErr_Format(PyExc_TypeError,
                      "'_id' attribute must be an %N object, not %T",
                      st->ChannelIDType, obj);
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index fe55ec7cafffec7..83d5f43f8991e3b 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -2835,8 +2835,14 @@ init_sys_streams(PyThreadState *tstate)
                        config->stdio_errors);
     if (std == NULL)
         goto error;
-    PySys_SetObject("__stdin__", std);
-    _PySys_SetAttr(&_Py_ID(stdin), std);
+    if (PySys_SetObject("__stdin__", std) < 0) {
+        Py_DECREF(std);
+        goto error;
+    }
+    if (_PySys_SetAttr(&_Py_ID(stdin), std) < 0) {
+        Py_DECREF(std);
+        goto error;
+    }
     Py_DECREF(std);
 
     /* Set sys.stdout */
@@ -2846,8 +2852,14 @@ init_sys_streams(PyThreadState *tstate)
                        config->stdio_errors);
     if (std == NULL)
         goto error;
-    PySys_SetObject("__stdout__", std);
-    _PySys_SetAttr(&_Py_ID(stdout), std);
+    if (PySys_SetObject("__stdout__", std) < 0) {
+        Py_DECREF(std);
+        goto error;
+    }
+    if (_PySys_SetAttr(&_Py_ID(stdout), std) < 0) {
+        Py_DECREF(std);
+        goto error;
+    }
     Py_DECREF(std);
 
 #if 1 /* Disable this if you have trouble debugging bootstrap stuff */

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to