summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-01-24 10:57:42 -0800
committerGiampaolo Rodola <g.rodola@gmail.com>2020-01-24 10:57:42 -0800
commitcbbd95abdfdd0befbf665144e4edffa02dd86219 (patch)
tree0290bc4ba49e29cc3db8a3ce0973b92400485a4b
parente49a9919ec043b476833feb592286b2c14533e82 (diff)
downloadpsutil-cbbd95abdfdd0befbf665144e4edffa02dd86219.tar.gz
convert win
-rw-r--r--psutil/_psutil_common.c2
-rw-r--r--psutil/_psutil_common.h11
-rw-r--r--psutil/_psutil_posix.c4
-rw-r--r--psutil/_psutil_windows.c56
4 files changed, 32 insertions, 41 deletions
diff --git a/psutil/_psutil_common.c b/psutil/_psutil_common.c
index e433f797..5dfa723f 100644
--- a/psutil/_psutil_common.c
+++ b/psutil/_psutil_common.c
@@ -170,9 +170,11 @@ Py_PidConverter(PyObject *arg, void *addr) {
if ((sizeof(pid_t) == sizeof(int)) || (sizeof(pid_t) == sizeof(long))) {
*((pid_t *)addr) = PyLong_AsLong(arg);
}
+#ifndef PSUTIL_WINDOWS
else if (sizeof(pid_t) == sizeof(long long)) {
*((pid_t *)addr) = PyLong_AsLongLong(arg);
}
+#endif
else {
PyErr_SetString(PyExc_ValueError, "can't get size of pid_t");
}
diff --git a/psutil/_psutil_common.h b/psutil/_psutil_common.h
index a99b6337..7eb0e8bd 100644
--- a/psutil/_psutil_common.h
+++ b/psutil/_psutil_common.h
@@ -22,17 +22,6 @@ static const int PSUTIL_CONN_NONE = 128;
#if PY_MAJOR_VERSION < 3
PyObject* PyUnicode_DecodeFSDefault(char *s);
PyObject* PyUnicode_DecodeFSDefaultAndSize(char *s, Py_ssize_t size);
-#endif
-
-// Python 2 compatibility for PyArg_ParseTuple pid arg type handling.
-#if PY_MAJOR_VERSION == 2
- // XXX: not bullet proof (long long case is missing).
- #if PSUTIL_SIZEOF_PID_T == 4
- #define _Py_PARSE_PID "i"
- #else
- #define _Py_PARSE_PID "l"
- #endif
-
PyObject *PyLong_FromPid(pid_t pid);
#endif
diff --git a/psutil/_psutil_posix.c b/psutil/_psutil_posix.c
index f4ecbd93..792264de 100644
--- a/psutil/_psutil_posix.c
+++ b/psutil/_psutil_posix.c
@@ -135,7 +135,7 @@ psutil_posix_getpriority(PyObject *self, PyObject *args) {
int priority;
errno = 0;
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid))
+ if (! PyArg_ParseTuple(args, "O&", Py_PidConverter, &pid))
return NULL;
#ifdef PSUTIL_OSX
@@ -158,7 +158,7 @@ psutil_posix_setpriority(PyObject *self, PyObject *args) {
int priority;
int retval;
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID "i", &pid, &priority))
+ if (! PyArg_ParseTuple(args, "O&i", Py_PidConverter, &pid, &priority))
return NULL;
#ifdef PSUTIL_OSX
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c
index 94508134..1dee658c 100644
--- a/psutil/_psutil_windows.c
+++ b/psutil/_psutil_windows.c
@@ -114,7 +114,7 @@ psutil_pid_exists(PyObject *self, PyObject *args) {
pid_t pid;
int status;
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid))
+ if (! PyArg_ParseTuple(args, "O&", Py_PidConverter, &pid))
return NULL;
status = psutil_pid_is_running(pid);
@@ -171,7 +171,7 @@ psutil_proc_kill(PyObject *self, PyObject *args) {
HANDLE hProcess;
pid_t pid;
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid))
+ if (! PyArg_ParseTuple(args, "O&", Py_PidConverter, &pid))
return NULL;
if (pid == 0)
return AccessDenied("automatically set for PID 0");
@@ -215,7 +215,7 @@ psutil_proc_wait(PyObject *self, PyObject *args) {
pid_t pid;
long timeout;
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID "l", &pid, &timeout))
+ if (! PyArg_ParseTuple(args,"O&l", Py_PidConverter, &pid, &timeout))
return NULL;
if (pid == 0)
return AccessDenied("automatically set for PID 0");
@@ -285,7 +285,7 @@ psutil_proc_cpu_times(PyObject *self, PyObject *args) {
HANDLE hProcess;
FILETIME ftCreate, ftExit, ftKernel, ftUser;
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid))
+ if (! PyArg_ParseTuple(args, "O&", Py_PidConverter, &pid))
return NULL;
hProcess = psutil_handle_from_pid(pid, PROCESS_QUERY_LIMITED_INFORMATION);
@@ -337,7 +337,7 @@ psutil_proc_create_time(PyObject *self, PyObject *args) {
HANDLE hProcess;
FILETIME ftCreate, ftExit, ftKernel, ftUser;
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid))
+ if (! PyArg_ParseTuple(args, "O&", Py_PidConverter, &pid))
return NULL;
// special case for PIDs 0 and 4, return system boot time
@@ -403,8 +403,8 @@ psutil_proc_cmdline(PyObject *self, PyObject *args, PyObject *kwdict) {
PyObject *py_usepeb = Py_True;
static char *keywords[] = {"pid", "use_peb", NULL};
- if (!PyArg_ParseTupleAndKeywords(args, kwdict, _Py_PARSE_PID "|O",
- keywords, &pid, &py_usepeb)) {
+ if (!PyArg_ParseTupleAndKeywords(args, kwdict, "O&|O", keywords,
+ Py_PidConverter, &pid, &py_usepeb)) {
return NULL;
}
if ((pid == 0) || (pid == 4))
@@ -429,7 +429,7 @@ psutil_proc_environ(PyObject *self, PyObject *args) {
pid_t pid;
int pid_return;
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid))
+ if (! PyArg_ParseTuple(args, "O&", Py_PidConverter, &pid))
return NULL;
if ((pid == 0) || (pid == 4))
return Py_BuildValue("s", "");
@@ -454,7 +454,7 @@ psutil_proc_exe(PyObject *self, PyObject *args) {
wchar_t exe[MAX_PATH];
unsigned int size = sizeof(exe);
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid))
+ if (! PyArg_ParseTuple(args, "O&", Py_PidConverter, &pid))
return NULL;
hProcess = psutil_handle_from_pid(pid, PROCESS_QUERY_LIMITED_INFORMATION);
@@ -489,7 +489,7 @@ psutil_proc_name(PyObject *self, PyObject *args) {
PROCESSENTRY32W pentry;
HANDLE hSnapShot;
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid))
+ if (! PyArg_ParseTuple(args, "O&", Py_PidConverter, &pid))
return NULL;
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, pid);
if (hSnapShot == INVALID_HANDLE_VALUE)
@@ -525,7 +525,7 @@ psutil_proc_memory_info(PyObject *self, PyObject *args) {
pid_t pid;
PROCESS_MEMORY_COUNTERS_EX cnt;
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid))
+ if (! PyArg_ParseTuple(args, "O&", Py_PidConverter, &pid))
return NULL;
hProcess = psutil_handle_from_pid(pid, PROCESS_QUERY_LIMITED_INFORMATION);
@@ -641,7 +641,7 @@ psutil_proc_memory_uss(PyObject *self, PyObject *args) {
PMEMORY_WORKING_SET_INFORMATION wsInfo;
ULONG_PTR i;
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid))
+ if (! PyArg_ParseTuple(args, "O&", Py_PidConverter, &pid))
return NULL;
hProcess = psutil_handle_from_pid(pid, PROCESS_QUERY_INFORMATION);
if (hProcess == NULL)
@@ -709,7 +709,7 @@ psutil_proc_cwd(PyObject *self, PyObject *args) {
pid_t pid;
int pid_return;
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid))
+ if (! PyArg_ParseTuple(args, "O&", Py_PidConverter, &pid))
return NULL;
pid_return = psutil_pid_is_running(pid);
@@ -732,7 +732,7 @@ psutil_proc_suspend_or_resume(PyObject *self, PyObject *args) {
HANDLE hProcess;
PyObject* suspend;
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID "O", &pid, &suspend))
+ if (! PyArg_ParseTuple(args, "O&O", Py_PidConverter, &pid, &suspend))
return NULL;
hProcess = psutil_handle_from_pid(pid, PROCESS_SUSPEND_RESUME);
@@ -768,7 +768,7 @@ psutil_proc_threads(PyObject *self, PyObject *args) {
if (py_retlist == NULL)
return NULL;
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid))
+ if (! PyArg_ParseTuple(args, "O&", Py_PidConverter, &pid))
goto error;
if (pid == 0) {
// raise AD instead of returning 0 as procexp is able to
@@ -866,7 +866,7 @@ psutil_proc_open_files(PyObject *self, PyObject *args) {
DWORD access = PROCESS_DUP_HANDLE | PROCESS_QUERY_INFORMATION;
PyObject *py_retlist;
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid))
+ if (! PyArg_ParseTuple(args, "O&", Py_PidConverter, &pid))
return NULL;
processHandle = psutil_handle_from_pid(pid, access);
@@ -898,7 +898,7 @@ psutil_proc_username(PyObject *self, PyObject *args) {
PyObject *py_domain = NULL;
PyObject *py_tuple = NULL;
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid))
+ if (! PyArg_ParseTuple(args, "O&", Py_PidConverter, &pid))
return NULL;
processHandle = psutil_handle_from_pid(
@@ -1015,7 +1015,7 @@ psutil_proc_priority_get(PyObject *self, PyObject *args) {
DWORD priority;
HANDLE hProcess;
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid))
+ if (! PyArg_ParseTuple(args, "O&", Py_PidConverter, &pid))
return NULL;
hProcess = psutil_handle_from_pid(pid, PROCESS_QUERY_LIMITED_INFORMATION);
@@ -1044,7 +1044,7 @@ psutil_proc_priority_set(PyObject *self, PyObject *args) {
HANDLE hProcess;
DWORD access = PROCESS_QUERY_INFORMATION | PROCESS_SET_INFORMATION;
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID "i", &pid, &priority))
+ if (! PyArg_ParseTuple(args, "O&i", Py_PidConverter, &pid, &priority))
return NULL;
hProcess = psutil_handle_from_pid(pid, access);
if (hProcess == NULL)
@@ -1072,7 +1072,7 @@ psutil_proc_io_priority_get(PyObject *self, PyObject *args) {
DWORD IoPriority;
NTSTATUS status;
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid))
+ if (! PyArg_ParseTuple(args, "O&", Py_PidConverter, &pid))
return NULL;
hProcess = psutil_handle_from_pid(pid, PROCESS_QUERY_LIMITED_INFORMATION);
@@ -1105,7 +1105,7 @@ psutil_proc_io_priority_set(PyObject *self, PyObject *args) {
NTSTATUS status;
DWORD access = PROCESS_QUERY_INFORMATION | PROCESS_SET_INFORMATION;
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID "i", &pid, &prio))
+ if (! PyArg_ParseTuple(args, "O&i", Py_PidConverter, &pid, &prio))
return NULL;
hProcess = psutil_handle_from_pid(pid, access);
@@ -1135,7 +1135,7 @@ psutil_proc_io_counters(PyObject *self, PyObject *args) {
HANDLE hProcess;
IO_COUNTERS IoCounters;
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid))
+ if (! PyArg_ParseTuple(args, "O&", Py_PidConverter, &pid))
return NULL;
hProcess = psutil_handle_from_pid(pid, PROCESS_QUERY_LIMITED_INFORMATION);
if (NULL == hProcess)
@@ -1168,7 +1168,7 @@ psutil_proc_cpu_affinity_get(PyObject *self, PyObject *args) {
DWORD_PTR proc_mask;
DWORD_PTR system_mask;
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid))
+ if (! PyArg_ParseTuple(args, "O&", Py_PidConverter, &pid))
return NULL;
hProcess = psutil_handle_from_pid(pid, PROCESS_QUERY_LIMITED_INFORMATION);
if (hProcess == NULL) {
@@ -1200,9 +1200,9 @@ psutil_proc_cpu_affinity_set(PyObject *self, PyObject *args) {
DWORD_PTR mask;
#ifdef _WIN64
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID "K", &pid, &mask))
+ if (! PyArg_ParseTuple(args, "O&K", Py_PidConverter, &pid, &mask))
#else
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID "k", &pid, &mask))
+ if (! PyArg_ParseTuple(args, "O&k", Py_PidConverter, &pid, &mask))
#endif
{
return NULL;
@@ -1232,7 +1232,7 @@ psutil_proc_is_suspended(PyObject *self, PyObject *args) {
PSYSTEM_PROCESS_INFORMATION process;
PVOID buffer;
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid))
+ if (! PyArg_ParseTuple(args, "O&", Py_PidConverter, &pid))
return NULL;
if (! psutil_get_proc_info(pid, &process, &buffer))
return NULL;
@@ -1391,7 +1391,7 @@ psutil_proc_num_handles(PyObject *self, PyObject *args) {
HANDLE hProcess;
DWORD handleCount;
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid))
+ if (! PyArg_ParseTuple(args, "O&", Py_PidConverter, &pid))
return NULL;
hProcess = psutil_handle_from_pid(pid, PROCESS_QUERY_LIMITED_INFORMATION);
if (NULL == hProcess)
@@ -1449,7 +1449,7 @@ psutil_proc_memory_maps(PyObject *self, PyObject *args) {
if (py_retlist == NULL)
return NULL;
- if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid))
+ if (! PyArg_ParseTuple(args, "O&", Py_PidConverter, &pid))
goto error;
hProcess = psutil_handle_from_pid(pid, access);
if (NULL == hProcess)