Issue #24115: Update uses of PyObject_IsTrue(), PyObject_Not(),
PyObject_IsInstance(), PyObject_RichCompareBool() and _PyDict_Contains()
to check for and handle errors correctly.
diff --git a/Modules/_json.c b/Modules/_json.c
index c913409..3349b0c 100644
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -874,6 +874,9 @@
     int strict = PyObject_IsTrue(s->strict);
     Py_ssize_t next_idx;
 
+    if (strict < 0)
+        return NULL;
+
     pairs = PyList_New(0);
     if (pairs == NULL)
         return NULL;
@@ -997,6 +1000,9 @@
     int strict = PyObject_IsTrue(s->strict);
     Py_ssize_t next_idx;
 
+    if (strict < 0)
+        return NULL;
+
     pairs = PyList_New(0);
     if (pairs == NULL)
         return NULL;
@@ -1466,6 +1472,7 @@
     Returns a new PyObject representation of the term.
     */
     PyObject *res;
+    int strict;
     char *str = PyString_AS_STRING(pystr);
     Py_ssize_t length = PyString_GET_SIZE(pystr);
     if (idx < 0) {
@@ -1479,10 +1486,11 @@
     switch (str[idx]) {
         case '"':
             /* string */
+            strict = PyObject_IsTrue(s->strict);
+            if (strict < 0)
+                return NULL;
             return scanstring_str(pystr, idx + 1,
-                PyString_AS_STRING(s->encoding),
-                PyObject_IsTrue(s->strict),
-                next_idx_ptr);
+                PyString_AS_STRING(s->encoding), strict, next_idx_ptr);
         case '{':
             /* object */
             if (Py_EnterRecursiveCall(" while decoding a JSON object "
@@ -1557,6 +1565,7 @@
     Returns a new PyObject representation of the term.
     */
     PyObject *res;
+    int strict;
     Py_UNICODE *str = PyUnicode_AS_UNICODE(pystr);
     Py_ssize_t length = PyUnicode_GET_SIZE(pystr);
     if (idx < 0) {
@@ -1570,9 +1579,10 @@
     switch (str[idx]) {
         case '"':
             /* string */
-            return scanstring_unicode(pystr, idx + 1,
-                PyObject_IsTrue(s->strict),
-                next_idx_ptr);
+            strict = PyObject_IsTrue(s->strict);
+            if (strict < 0)
+                return NULL;
+            return scanstring_unicode(pystr, idx + 1, strict, next_idx_ptr);
         case '{':
             /* object */
             if (Py_EnterRecursiveCall(" while decoding a JSON object "
@@ -1825,14 +1835,19 @@
 
     PyEncoderObject *s;
     PyObject *markers, *defaultfn, *encoder, *indent, *key_separator;
-    PyObject *item_separator, *sort_keys, *skipkeys, *allow_nan;
+    PyObject *item_separator, *sort_keys, *skipkeys, *allow_nan_obj;
+    int allow_nan;
 
     assert(PyEncoder_Check(self));
     s = (PyEncoderObject *)self;
 
     if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOOOOOOOO:make_encoder", kwlist,
         &markers, &defaultfn, &encoder, &indent, &key_separator, &item_separator,
-        &sort_keys, &skipkeys, &allow_nan))
+        &sort_keys, &skipkeys, &allow_nan_obj))
+        return -1;
+
+    allow_nan = PyObject_IsTrue(allow_nan_obj);
+    if (allow_nan < 0)
         return -1;
 
     s->markers = markers;
@@ -1844,7 +1859,7 @@
     s->sort_keys = sort_keys;
     s->skipkeys = skipkeys;
     s->fast_encode = (PyCFunction_Check(s->encoder) && PyCFunction_GetFunction(s->encoder) == (PyCFunction)py_encode_basestring_ascii);
-    s->allow_nan = PyObject_IsTrue(allow_nan);
+    s->allow_nan = allow_nan;
 
     Py_INCREF(s->markers);
     Py_INCREF(s->defaultfn);
@@ -2110,6 +2125,8 @@
     if (it == NULL)
         goto bail;
     skipkeys = PyObject_IsTrue(s->skipkeys);
+    if (skipkeys < 0)
+        goto bail;
     idx = 0;
     while ((key = PyIter_Next(it)) != NULL) {
         PyObject *encoded;
diff --git a/Modules/threadmodule.c b/Modules/threadmodule.c
index efc5d7f..82eff00 100644
--- a/Modules/threadmodule.c
+++ b/Modules/threadmodule.c
@@ -333,12 +333,18 @@
         "_localdummy_destroyed", (PyCFunction) _localdummy_destroyed, METH_O
     };
 
-    if (type->tp_init == PyBaseObject_Type.tp_init
-        && ((args && PyObject_IsTrue(args))
-        || (kw && PyObject_IsTrue(kw)))) {
-        PyErr_SetString(PyExc_TypeError,
-                  "Initialization arguments are not supported");
-        return NULL;
+    if (type->tp_init == PyBaseObject_Type.tp_init) {
+        int rc = 0;
+        if (args != NULL)
+            rc = PyObject_IsTrue(args);
+        if (rc == 0 && kw != NULL)
+            rc = PyObject_IsTrue(kw);
+        if (rc != 0) {
+            if (rc > 0)
+                PyErr_SetString(PyExc_TypeError,
+                          "Initialization arguments are not supported");
+            return NULL;
+        }
     }
 
     self = (localobject *)type->tp_alloc(type, 0);