diff options
| author | Giampaolo Rodola <g.rodola@gmail.com> | 2017-11-24 14:07:06 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-11-24 14:07:06 +0100 |
| commit | 34fb3666859bda349afdc9b4397b0b7a715f08de (patch) | |
| tree | 74ff50536fd2275efc945b4329482acc938d45e1 /psutil/_psutil_common.c | |
| parent | 71c4f5683460e110693c976b21b06ab4034ae8a3 (diff) | |
| download | psutil-34fb3666859bda349afdc9b4397b0b7a715f08de.tar.gz | |
Arguments for NoSuchProcess and AccessDenied for the C ext (#1180)
* change NoSuchProcess and AccessDenied C exceptions signatures
* fix arg call on win
Diffstat (limited to 'psutil/_psutil_common.c')
| -rw-r--r-- | psutil/_psutil_common.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/psutil/_psutil_common.c b/psutil/_psutil_common.c index e9fce85e..908dbf14 100644 --- a/psutil/_psutil_common.c +++ b/psutil/_psutil_common.c @@ -37,12 +37,13 @@ PyUnicode_DecodeFSDefaultAndSize(char *s, Py_ssize_t size) { /* * Set OSError(errno=ESRCH, strerror="No such process") Python exception. + * If msg != "" the exception message will change in accordance. */ PyObject * -NoSuchProcess(void) { +NoSuchProcess(char *msg) { PyObject *exc; - char *msg = strerror(ESRCH); - exc = PyObject_CallFunction(PyExc_OSError, "(is)", ESRCH, msg); + exc = PyObject_CallFunction( + PyExc_OSError, "(is)", ESRCH, strlen(msg) ? msg : strerror(ESRCH)); PyErr_SetObject(PyExc_OSError, exc); Py_XDECREF(exc); return NULL; @@ -51,12 +52,13 @@ NoSuchProcess(void) { /* * Set OSError(errno=EACCES, strerror="Permission denied") Python exception. + * If msg != "" the exception message will change in accordance. */ PyObject * -AccessDenied(void) { +AccessDenied(char *msg) { PyObject *exc; - char *msg = strerror(EACCES); - exc = PyObject_CallFunction(PyExc_OSError, "(is)", EACCES, msg); + exc = PyObject_CallFunction( + PyExc_OSError, "(is)", EACCES, strlen(msg) ? msg : strerror(EACCES)); PyErr_SetObject(PyExc_OSError, exc); Py_XDECREF(exc); return NULL; |
