diff options
author | Christoph Reiter <creiter@src.gnome.org> | 2017-03-27 14:47:22 +0200 |
---|---|---|
committer | Christoph Reiter <creiter@src.gnome.org> | 2017-03-29 13:02:31 +0200 |
commit | d2a7e9a7b29e74fd97592fcc8462d718d0b7af17 (patch) | |
tree | 7fbe81793b84946d6efdf62ea2ade2c7485b86e4 | |
parent | cfeeaaf69f6d6f777e5f3a17493ff9dcc2bda900 (diff) | |
download | pygobject-d2a7e9a7b29e74fd97592fcc8462d718d0b7af17.tar.gz |
Fix PyLong <-> GPid conversion on 64bit Windows
GPid on Windows is a pointer and not int, and pointers don't fit long
on 64bit so use PyLong_AsVoidPtr/PyLong_FromVoidPtr there instead.
https://bugzilla.gnome.org/show_bug.cgi?id=780591
-rw-r--r-- | gi/pygspawn.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/gi/pygspawn.c b/gi/pygspawn.c index 3806967a..b7305eb5 100644 --- a/gi/pygspawn.c +++ b/gi/pygspawn.c @@ -34,10 +34,20 @@ struct _PyGChildSetupData { PYGLIB_DEFINE_TYPE("gi._glib.Pid", PyGPid_Type, PYGLIB_PyLongObject) +static GPid +pyg_pid_get_pid (PyObject *self) +{ +#ifdef G_OS_WIN32 + return (GPid)PyLong_AsVoidPtr (self); +#else + return (GPid)PYGLIB_PyLong_AsLong (self); +#endif +} + static PyObject * pyg_pid_close(PyObject *self, PyObject *args, PyObject *kwargs) { - g_spawn_close_pid(PYGLIB_PyLong_AsLong(self)); + g_spawn_close_pid(pyg_pid_get_pid (self)); Py_INCREF(Py_None); return Py_None; } @@ -50,7 +60,7 @@ static PyMethodDef pyg_pid_methods[] = { static void pyg_pid_free(PyObject *gpid) { - g_spawn_close_pid((GPid) PYGLIB_PyLong_AsLong(gpid)); + g_spawn_close_pid(pyg_pid_get_pid (gpid)); PYGLIB_PyLong_Type.tp_free((void *) gpid); } @@ -64,8 +74,14 @@ pyg_pid_tp_init(PyObject *self, PyObject *args, PyObject *kwargs) PyObject * pyg_pid_new(GPid pid) { - return PyObject_CallMethod((PyObject*)&PyGPid_Type, "__new__", "Oi", - &PyGPid_Type, pid); + PyObject *long_val; +#ifdef G_OS_WIN32 + long_val = PyLong_FromVoidPtr (pid); +#else + long_val = PYGLIB_PyLong_FromLong (pid); +#endif + return PyObject_CallMethod((PyObject*)&PyGPid_Type, "__new__", "ON", + &PyGPid_Type, long_val); } static void @@ -106,7 +122,7 @@ pyglib_spawn_async(PyObject *object, PyObject *args, PyObject *kwargs) gint *standard_input, *standard_output, *standard_error; struct _PyGChildSetupData *callback_data = NULL; GError *error = NULL; - GPid child_pid = -1; + GPid child_pid = 0; Py_ssize_t len, i; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|OsiOOOOO:gi._glib.spawn_async", |