[pygobject] Fix PyLong <-> GPid conversion on 64bit Windows
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Fix PyLong <-> GPid conversion on 64bit Windows
- Date: Wed, 29 Mar 2017 11:04:51 +0000 (UTC)
commit d2a7e9a7b29e74fd97592fcc8462d718d0b7af17
Author: Christoph Reiter <creiter src gnome org>
Date: Mon Mar 27 14:47:22 2017 +0200
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
gi/pygspawn.c | 26 +++++++++++++++++++++-----
1 files changed, 21 insertions(+), 5 deletions(-)
---
diff --git a/gi/pygspawn.c b/gi/pygspawn.c
index 3806967..b7305eb 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",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]