Issue #23524: Finish removing _PyVerify_fd from sources
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index 12e5156..54cfb7f 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -117,18 +117,13 @@
         int fd = self->fd;
         self->fd = -1;
         /* fd is accessible and someone else may have closed it */
-        if (_PyVerify_fd(fd)) {
-            Py_BEGIN_ALLOW_THREADS
-            _Py_BEGIN_SUPPRESS_IPH
-            err = close(fd);
-            if (err < 0)
-                save_errno = errno;
-            _Py_END_SUPPRESS_IPH
-            Py_END_ALLOW_THREADS
-        } else {
+        Py_BEGIN_ALLOW_THREADS
+        _Py_BEGIN_SUPPRESS_IPH
+        err = close(fd);
+        if (err < 0)
             save_errno = errno;
-            err = -1;
-        }
+        _Py_END_SUPPRESS_IPH
+        Py_END_ALLOW_THREADS
     }
     if (err < 0) {
         errno = save_errno;
@@ -700,8 +695,6 @@
 
     if (self->fd < 0)
         return err_closed();
-    if (!_PyVerify_fd(self->fd))
-        return PyErr_SetFromErrno(PyExc_IOError);
 
     _Py_BEGIN_SUPPRESS_IPH
 #ifdef MS_WINDOWS
@@ -914,18 +907,15 @@
             return NULL;
     }
 
-    if (_PyVerify_fd(fd)) {
-        Py_BEGIN_ALLOW_THREADS
-        _Py_BEGIN_SUPPRESS_IPH
+    Py_BEGIN_ALLOW_THREADS
+    _Py_BEGIN_SUPPRESS_IPH
 #ifdef MS_WINDOWS
-        res = _lseeki64(fd, pos, whence);
+    res = _lseeki64(fd, pos, whence);
 #else
-        res = lseek(fd, pos, whence);
+    res = lseek(fd, pos, whence);
 #endif
-        _Py_END_SUPPRESS_IPH
-        Py_END_ALLOW_THREADS
-    } else
-        res = -1;
+    _Py_END_SUPPRESS_IPH
+    Py_END_ALLOW_THREADS
     if (res < 0)
         return PyErr_SetFromErrno(PyExc_IOError);
 
@@ -1116,10 +1106,7 @@
         return err_closed();
     Py_BEGIN_ALLOW_THREADS
     _Py_BEGIN_SUPPRESS_IPH
-    if (_PyVerify_fd(self->fd))
-        res = isatty(self->fd);
-    else
-        res = 0;
+    res = isatty(self->fd);
     _Py_END_SUPPRESS_IPH
     Py_END_ALLOW_THREADS
     return PyBool_FromLong(res);
diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c
index c2d3000..1c1e4fb 100644
--- a/Modules/faulthandler.c
+++ b/Modules/faulthandler.c
@@ -159,7 +159,7 @@
         fd = _PyLong_AsInt(file);
         if (fd == -1 && PyErr_Occurred())
             return -1;
-        if (fd < 0 || !_PyVerify_fd(fd)) {
+        if (fd < 0) {
             PyErr_SetString(PyExc_ValueError,
                             "file is not a valid file descripter");
             return -1;
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index b0015a5..73c37d0 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -1326,10 +1326,6 @@
      */
     if (fileno != -1 && fileno != 0) {
         /* Ensure that fileno is within the CRT's valid range */
-        if (!_PyVerify_fd(fileno)) {
-            PyErr_SetFromErrno(PyExc_OSError);
-            return NULL;
-        }
         _Py_BEGIN_SUPPRESS_IPH
         fh = (HANDLE)_get_osfhandle(fileno);
         _Py_END_SUPPRESS_IPH
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 4f5ec99..957a5f2 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -1178,34 +1178,6 @@
 #endif
 }
 
-
-#if defined _MSC_VER && _MSC_VER >= 1400 && _MSC_VER < 1900
-/* Legacy implementation of _PyVerify_fd_dup2 while transitioning to
- * MSVC 14.0. This should eventually be removed. (issue23524)
- */
-#define IOINFO_L2E 5
-#define IOINFO_ARRAYS 64
-#define IOINFO_ARRAY_ELTS   (1 << IOINFO_L2E)
-#define _NHANDLE_           (IOINFO_ARRAYS * IOINFO_ARRAY_ELTS)
-#define _NO_CONSOLE_FILENO (intptr_t)-2
-
-/* the special case of checking dup2.  The target fd must be in a sensible range */
-static int
-_PyVerify_fd_dup2(int fd1, int fd2)
-{
-    if (!_PyVerify_fd(fd1))
-        return 0;
-    if (fd2 == _NO_CONSOLE_FILENO)
-        return 0;
-    if ((unsigned)fd2 < _NHANDLE_)
-        return 1;
-    else
-        return 0;
-}
-#else
-#define _PyVerify_fd_dup2(fd1, fd2) (_PyVerify_fd(fd1) && (fd2) >= 0)
-#endif
-
 #ifdef MS_WINDOWS
 
 static int
@@ -1409,9 +1381,6 @@
     int res;
     int async_err = 0;
 
-    if (!_PyVerify_fd(fd))
-        return posix_error();
-
     do {
         Py_BEGIN_ALLOW_THREADS
         _Py_BEGIN_SUPPRESS_IPH
@@ -7549,8 +7518,6 @@
 /*[clinic end generated code: output=2fe4e93602822c14 input=2bc42451ca5c3223]*/
 {
     int res;
-    if (!_PyVerify_fd(fd))
-        return posix_error();
     /* We do not want to retry upon EINTR: see http://lwn.net/Articles/576478/
      * and http://linux.derkeiler.com/Mailing-Lists/Kernel/2005-09/3000.html
      * for more details.
@@ -7583,9 +7550,8 @@
     int i;
     Py_BEGIN_ALLOW_THREADS
     _Py_BEGIN_SUPPRESS_IPH
-    for (i = fd_low; i < fd_high; i++)
-        if (_PyVerify_fd(i))
-            close(i);
+    for (i = max(fd_low, 0); i < fd_high; i++)
+        close(i);
     _Py_END_SUPPRESS_IPH
     Py_END_ALLOW_THREADS
     Py_RETURN_NONE;
@@ -7629,7 +7595,7 @@
     int dup3_works = -1;
 #endif
 
-    if (!_PyVerify_fd_dup2(fd, fd2))
+    if (fd < 0 || fd2 < 0)
         return posix_error();
 
     /* dup2() can fail with EINTR if the target FD is already open, because it
@@ -7753,10 +7719,6 @@
 {
     Py_off_t result;
 
-    if (!_PyVerify_fd(fd)) {
-        posix_error();
-        return -1;
-    }
 #ifdef SEEK_SET
     /* Turn 0, 1, 2 into SEEK_{SET,CUR,END} */
     switch (how) {
@@ -7769,10 +7731,6 @@
     if (PyErr_Occurred())
         return -1;
 
-    if (!_PyVerify_fd(fd)) {
-        posix_error();
-        return -1;
-    }
     Py_BEGIN_ALLOW_THREADS
     _Py_BEGIN_SUPPRESS_IPH
 #ifdef MS_WINDOWS
@@ -7980,10 +7938,6 @@
     buffer = PyBytes_FromStringAndSize((char *)NULL, length);
     if (buffer == NULL)
         return NULL;
-    if (!_PyVerify_fd(fd)) {
-        Py_DECREF(buffer);
-        return posix_error();
-    }
 
     do {
         Py_BEGIN_ALLOW_THREADS
@@ -8226,8 +8180,6 @@
 /*[clinic end generated code: output=6a48c8b4e644ca00 input=08ce94aa1eaf7b5e]*/
 {
     int return_value;
-    if (!_PyVerify_fd(fd))
-        return 0;
     _Py_BEGIN_SUPPRESS_IPH
     return_value = isatty(fd);
     _Py_END_SUPPRESS_IPH
@@ -8419,11 +8371,6 @@
     Py_ssize_t size;
     int async_err = 0;
 
-    if (!_PyVerify_fd(fd)) {
-        posix_error();
-        return -1;
-    }
-
     do {
         Py_BEGIN_ALLOW_THREADS
         _Py_BEGIN_SUPPRESS_IPH
@@ -8606,9 +8553,6 @@
     int result;
     int async_err = 0;
 
-    if (!_PyVerify_fd(fd))
-        return posix_error();
-
     do {
         Py_BEGIN_ALLOW_THREADS
         _Py_BEGIN_SUPPRESS_IPH
@@ -10979,11 +10923,6 @@
 /*[clinic end generated code: output=0445e20e149aa5b8 input=89ac008dc9ab6b95]*/
 {
     int return_value;
-    if (!_PyVerify_fd(fd)) {
-        posix_error();
-        return -1;
-    }
-
     _Py_BEGIN_SUPPRESS_IPH
     return_value = _Py_get_inheritable(fd);
     _Py_END_SUPPRESS_IPH
@@ -11005,8 +10944,6 @@
 /*[clinic end generated code: output=f1b1918a2f3c38c2 input=9ceaead87a1e2402]*/
 {
     int result;
-    if (!_PyVerify_fd(fd))
-        return posix_error();
 
     _Py_BEGIN_SUPPRESS_IPH
     result = _Py_set_inheritable(fd, inheritable, NULL);
@@ -11080,9 +11017,6 @@
     if (!PyArg_ParseTuple(args, "i:get_blocking", &fd))
         return NULL;
 
-    if (!_PyVerify_fd(fd))
-        return posix_error();
-
     _Py_BEGIN_SUPPRESS_IPH
     blocking = _Py_get_blocking(fd);
     _Py_END_SUPPRESS_IPH
@@ -11106,9 +11040,6 @@
     if (!PyArg_ParseTuple(args, "ii:set_blocking", &fd, &blocking))
         return NULL;
 
-    if (!_PyVerify_fd(fd))
-        return posix_error();
-
     _Py_BEGIN_SUPPRESS_IPH
     result = _Py_set_blocking(fd, blocking);
     _Py_END_SUPPRESS_IPH
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c
index e078091..7eef0b5 100644
--- a/Modules/signalmodule.c
+++ b/Modules/signalmodule.c
@@ -579,7 +579,7 @@
             }
 
             fd = (int)sockfd;
-            if ((SOCKET_T)fd != sockfd || !_PyVerify_fd(fd)) {
+            if ((SOCKET_T)fd != sockfd) {
                 PyErr_SetString(PyExc_ValueError, "invalid fd");
                 return NULL;
             }
@@ -609,11 +609,6 @@
     if (fd != -1) {
         int blocking;
 
-        if (!_PyVerify_fd(fd)) {
-            PyErr_SetString(PyExc_ValueError, "invalid fd");
-            return NULL;
-        }
-
         if (_Py_fstat(fd, &status) != 0)
             return NULL;