bpo-28261: Fixed err msgs where PyArg_ParseTuple is used to parse normal tuples. (#3119)

diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index fe39567..010658e 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -3262,7 +3262,9 @@
         /* Here ftuple is a borrowed reference */
         return NULL;
 
-    if (!PyArg_ParseTuple(ftuple, "O&O", _get_name, &name, &dll)) {
+    if (!PyArg_ParseTuple(ftuple, "O&O;illegal func_spec argument",
+                          _get_name, &name, &dll))
+    {
         Py_DECREF(ftuple);
         return NULL;
     }
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index b5d368a..57b66d6 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -562,8 +562,15 @@
     PyObject *buffer;
     unsigned long long flag;
 
-    if (!PyArg_ParseTuple(state, "OK", &buffer, &flag))
+    if (!PyTuple_Check(state)) {
+        PyErr_SetString(PyExc_TypeError, "state argument must be a tuple");
         return NULL;
+    }
+    if (!PyArg_ParseTuple(state, "OK;setstate(): illegal state argument",
+                          &buffer, &flag))
+    {
+        return NULL;
+    }
 
     self->pendingcr = (int) (flag & 1);
     flag >>= 1;
diff --git a/Modules/audioop.c b/Modules/audioop.c
index dcd7788..80c8a2a 100644
--- a/Modules/audioop.c
+++ b/Modules/audioop.c
@@ -1293,7 +1293,7 @@
     char *cp, *ncp;
     Py_ssize_t len;
     int chan, d, *prev_i, *cur_i, cur_o;
-    PyObject *samps, *str, *rv = NULL;
+    PyObject *samps, *str, *rv = NULL, *channel;
     int bytes_per_frame;
 
     if (!audioop_check_size(width))
@@ -1354,8 +1354,12 @@
             prev_i[chan] = cur_i[chan] = 0;
     }
     else {
+        if (!PyTuple_Check(state)) {
+            PyErr_SetString(PyExc_TypeError, "state must be a tuple or None");
+            goto exit;
+        }
         if (!PyArg_ParseTuple(state,
-                        "iO!;audioop.ratecv: illegal state argument",
+                        "iO!;ratecv(): illegal state argument",
                         &d, &PyTuple_Type, &samps))
             goto exit;
         if (PyTuple_Size(samps) != nchannels) {
@@ -1364,10 +1368,18 @@
             goto exit;
         }
         for (chan = 0; chan < nchannels; chan++) {
-            if (!PyArg_ParseTuple(PyTuple_GetItem(samps, chan),
-                                  "ii:ratecv", &prev_i[chan],
-                                               &cur_i[chan]))
+            channel = PyTuple_GetItem(samps, chan);
+            if (!PyTuple_Check(channel)) {
+                PyErr_SetString(PyExc_TypeError,
+                                "ratecv(): illegal state argument");
                 goto exit;
+            }
+            if (!PyArg_ParseTuple(channel,
+                                  "ii;ratecv(): illegal state argument",
+                                  &prev_i[chan], &cur_i[chan]))
+            {
+                goto exit;
+            }
         }
     }
 
@@ -1638,7 +1650,9 @@
         PyErr_SetString(PyExc_TypeError, "state must be a tuple or None");
         return NULL;
     }
-    else if (!PyArg_ParseTuple(state, "ii", &valpred, &index)) {
+    else if (!PyArg_ParseTuple(state, "ii;lin2adpcm(): illegal state argument",
+                               &valpred, &index))
+    {
         return NULL;
     }
     else if (valpred >= 0x8000 || valpred < -0x8000 ||
@@ -1766,7 +1780,9 @@
         PyErr_SetString(PyExc_TypeError, "state must be a tuple or None");
         return NULL;
     }
-    else if (!PyArg_ParseTuple(state, "ii", &valpred, &index)) {
+    else if (!PyArg_ParseTuple(state, "ii;adpcm2lin(): illegal state argument",
+                               &valpred, &index))
+    {
         return NULL;
     }
     else if (valpred >= 0x8000 || valpred < -0x8000 ||
diff --git a/Modules/overlapped.c b/Modules/overlapped.c
index 4390e9a..6099d46 100644
--- a/Modules/overlapped.c
+++ b/Modules/overlapped.c
@@ -990,7 +990,9 @@
         ((SOCKADDR_IN*)Address)->sin_port = htons(Port);
         return Length;
     }
-    else if (PyArg_ParseTuple(obj, "uHkk", &Host, &Port, &FlowInfo, &ScopeId))
+    else if (PyArg_ParseTuple(obj,
+                              "uHkk;ConnectEx(): illegal address_as_bytes "
+                              "argument", &Host, &Port, &FlowInfo, &ScopeId))
     {
         PyErr_Clear();
         Address->sa_family = AF_INET6;
@@ -1024,8 +1026,11 @@
     BOOL ret;
     DWORD err;
 
-    if (!PyArg_ParseTuple(args, F_HANDLE "O", &ConnectSocket, &AddressObj))
+    if (!PyArg_ParseTuple(args, F_HANDLE "O!:ConnectEx",
+                          &ConnectSocket, &PyTuple_Type, &AddressObj))
+    {
         return NULL;
+    }
 
     if (self->type != TYPE_NONE) {
         PyErr_SetString(PyExc_ValueError, "operation already attempted");
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index e18dd32..bf8d19f 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -5972,12 +5972,14 @@
                         "getnameinfo() argument 1 must be a tuple");
         return NULL;
     }
-    if (!PyArg_ParseTuple(sa, "si|II",
+    if (!PyArg_ParseTuple(sa, "si|II;getnameinfo(): illegal sockaddr argument",
                           &hostp, &port, &flowinfo, &scope_id))
+    {
         return NULL;
+    }
     if (flowinfo > 0xfffff) {
         PyErr_SetString(PyExc_OverflowError,
-                        "getsockaddrarg: flowinfo must be 0-1048575.");
+                        "getnameinfo(): flowinfo must be 0-1048575.");
         return NULL;
     }
     PyOS_snprintf(pbuf, sizeof(pbuf), "%d", port);
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index 15c467b..36a95bb 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -415,7 +415,7 @@
  * an exception and return 0 on error.
  */
 static int
-gettmarg(PyObject *args, struct tm *p)
+gettmarg(PyObject *args, struct tm *p, const char *format)
 {
     int y;
 
@@ -427,7 +427,7 @@
         return 0;
     }
 
-    if (!PyArg_ParseTuple(args, "iiiiiiiii",
+    if (!PyArg_ParseTuple(args, format,
                           &y, &p->tm_mon, &p->tm_mday,
                           &p->tm_hour, &p->tm_min, &p->tm_sec,
                           &p->tm_wday, &p->tm_yday, &p->tm_isdst))
@@ -586,8 +586,12 @@
         if (_PyTime_localtime(tt, &buf) != 0)
             return NULL;
     }
-    else if (!gettmarg(tup, &buf) || !checktm(&buf))
+    else if (!gettmarg(tup, &buf,
+                       "iiiiiiiii;strftime(): illegal time tuple argument") ||
+             !checktm(&buf))
+    {
         return NULL;
+    }
 
 #if defined(_MSC_VER) || defined(sun) || defined(_AIX)
     if (buf.tm_year + 1900 < 1 || 9999 < buf.tm_year + 1900) {
@@ -776,9 +780,13 @@
         time_t tt = time(NULL);
         if (_PyTime_localtime(tt, &buf) != 0)
             return NULL;
-
-    } else if (!gettmarg(tup, &buf) || !checktm(&buf))
+    }
+    else if (!gettmarg(tup, &buf,
+                       "iiiiiiiii;asctime(): illegal time tuple argument") ||
+             !checktm(&buf))
+    {
         return NULL;
+    }
     return _asctime(&buf);
 }
 
@@ -814,8 +822,11 @@
 {
     struct tm buf;
     time_t tt;
-    if (!gettmarg(tup, &buf))
+    if (!gettmarg(tup, &buf,
+                  "iiiiiiiii;mktime(): illegal time tuple argument"))
+    {
         return NULL;
+    }
 #ifdef _AIX
     /* year < 1902 or year > 2037 */
     if (buf.tm_year < 2 || buf.tm_year > 137) {