Skip to content

Commit

Permalink
#fix 1046: reset user SetErrorMode instead of resetting it to sysstem…
Browse files Browse the repository at this point in the history
… default
  • Loading branch information
giampaolo committed May 2, 2017
1 parent 721dfe2 commit 4c07213
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
None
- OpenBSD: connections('unix'): laddr and raddr are now set to "" instead of
None
- 1046_: [Windows] disk_partitions() on Windows overrides user's SetErrorMode.

*2017-04-10*

Expand Down
7 changes: 4 additions & 3 deletions psutil/_psutil_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -2447,6 +2447,7 @@ psutil_disk_partitions(PyObject *self, PyObject *args) {
int all;
int type;
int ret;
unsigned int old_mode = 0;
char opts[20];
LPTSTR fs_type[MAX_PATH + 1] = { 0 };
DWORD pflags = 0;
Expand All @@ -2460,7 +2461,7 @@ psutil_disk_partitions(PyObject *self, PyObject *args) {

// avoid to visualize a message box in case something goes wrong
// see https://github.com/giampaolo/psutil/issues/264
SetErrorMode(SEM_FAILCRITICALERRORS);
old_mode = SetErrorMode(SEM_FAILCRITICALERRORS);

if (! PyArg_ParseTuple(args, "O", &py_all))
goto error;
Expand Down Expand Up @@ -2541,11 +2542,11 @@ psutil_disk_partitions(PyObject *self, PyObject *args) {
drive_letter = strchr(drive_letter, 0) + 1;
}

SetErrorMode(0);
SetErrorMode(old_mode);
return py_retlist;

error:
SetErrorMode(0);
SetErrorMode(old_mode);
Py_XDECREF(py_tuple);
Py_DECREF(py_retlist);
return NULL;
Expand Down

0 comments on commit 4c07213

Please sign in to comment.