Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e4e021b

Browse files
committed
Release the interpreter lock for calls that may block: _locking(),
_getch(), _getche(). Fix bogus error return when open_osfhandle() doesn't have the right argument list.
1 parent 00d9306 commit e4e021b

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

PC/msvcrtmodule.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,15 @@ static PyObject *msvcrt_locking(PyObject *self, PyObject *args)
3939
int fd;
4040
int mode;
4141
long nbytes;
42+
int err;
4243

4344
if (!PyArg_ParseTuple(args, "iil:locking", &fd, &mode, &nbytes))
4445
return NULL;
4546

46-
if (_locking(fd, mode, nbytes) != 0)
47+
Py_BEGIN_ALLOW_THREADS
48+
err = _locking(fd, mode, nbytes);
49+
Py_END_ALLOW_THREADS
50+
if (err != 0)
4751
return PyErr_SetFromErrno(PyExc_IOError);
4852

4953
Py_INCREF(Py_None);
@@ -73,7 +77,7 @@ static PyObject *msvcrt_open_osfhandle(PyObject *self, PyObject *args)
7377
int fd;
7478

7579
if (!PyArg_ParseTuple(args, "li:open_osfhandle", &handle, &flags))
76-
return PyErr_SetFromErrno(PyExc_IOError);
80+
return NULL;
7781

7882
fd = _open_osfhandle(handle, flags);
7983
if (fd == -1)
@@ -120,7 +124,9 @@ static PyObject *msvcrt_getch(PyObject *self, PyObject *args)
120124
if (!PyArg_ParseTuple(args, ":getch"))
121125
return NULL;
122126

127+
Py_BEGIN_ALLOW_THREADS
123128
ch = _getch();
129+
Py_END_ALLOW_THREADS
124130
s[0] = ch;
125131
return PyString_FromStringAndSize(s, 1);
126132
}
@@ -133,7 +139,9 @@ static PyObject *msvcrt_getche(PyObject *self, PyObject *args)
133139
if (!PyArg_ParseTuple(args, ":getche"))
134140
return NULL;
135141

142+
Py_BEGIN_ALLOW_THREADS
136143
ch = _getche();
144+
Py_END_ALLOW_THREADS
137145
s[0] = ch;
138146
return PyString_FromStringAndSize(s, 1);
139147
}

0 commit comments

Comments
 (0)