Skip to content

Commit

Permalink
rm py2 C handling of disk_usage() on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Dec 19, 2024
1 parent 3bbfe69 commit 8d7bd96
Showing 1 changed file with 1 addition and 28 deletions.
29 changes: 1 addition & 28 deletions psutil/arch/windows/disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,33 +44,6 @@ PyObject *
psutil_disk_usage(PyObject *self, PyObject *args) {
BOOL retval;
ULARGE_INTEGER _, total, free;

#if PY_MAJOR_VERSION <= 2
char *path;

if (PyArg_ParseTuple(args, "u", &path)) {
Py_BEGIN_ALLOW_THREADS
retval = GetDiskFreeSpaceExW((LPCWSTR)path, &_, &total, &free);
Py_END_ALLOW_THREADS
goto return_;
}

// on Python 2 we also want to accept plain strings other
// than Unicode
PyErr_Clear(); // drop the argument parsing error
if (PyArg_ParseTuple(args, "s", &path)) {
Py_BEGIN_ALLOW_THREADS
retval = GetDiskFreeSpaceEx(path, &_, &total, &free);
Py_END_ALLOW_THREADS
goto return_;
}

return NULL;

return_:
if (retval == 0)
return PyErr_SetFromWindowsErrWithFilename(0, path);
#else
PyObject *py_path;
wchar_t *path;

Expand All @@ -91,7 +64,7 @@ psutil_disk_usage(PyObject *self, PyObject *args) {

if (retval == 0)
return PyErr_SetExcFromWindowsErrWithFilenameObject(PyExc_OSError, 0, py_path);
#endif

return Py_BuildValue("(LL)", total.QuadPart, free.QuadPart);
}

Expand Down

0 comments on commit 8d7bd96

Please sign in to comment.