mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Release the GIL when calling getlongpathname as it does I/O
This commit is contained in:
parent
a13dd062f3
commit
9be75ea01d
@ -773,13 +773,18 @@ get_long_path_name(PyObject *self, PyObject *args) {
|
||||
DWORD current_size = 4096;
|
||||
wchar_raii buf((wchar_t*)PyMem_Malloc(current_size * sizeof(wchar_t)));
|
||||
if (!buf) return PyErr_NoMemory();
|
||||
DWORD needed_size = GetLongPathNameW(path.ptr(), buf.ptr(), current_size);
|
||||
DWORD needed_size;
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
needed_size = GetLongPathNameW(path.ptr(), buf.ptr(), current_size);
|
||||
Py_END_ALLOW_THREADS
|
||||
if (needed_size >= current_size - 32) {
|
||||
current_size = needed_size + 32;
|
||||
PyMem_Free(buf.ptr());
|
||||
buf.set_ptr((wchar_t*)PyMem_Malloc(current_size * sizeof(wchar_t)));
|
||||
if (!buf) return PyErr_NoMemory();
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
needed_size = GetLongPathNameW(path.ptr(), buf.ptr(), current_size);
|
||||
Py_END_ALLOW_THREADS
|
||||
}
|
||||
if (!needed_size) return PyErr_SetExcFromWindowsErrWithFilenameObject(PyExc_OSError, 0, PyTuple_GET_ITEM(args, 0));
|
||||
if (needed_size >= current_size - 2) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user