* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
*/
#include <Python.h>
#include <glib.h>
#include "pyglib.h"
-
-#include "pygspawn.h"
-#include "pygi-error.h"
+#include "pyglib-private.h"
struct _PyGChildSetupData {
PyObject *func;
PyObject *data;
};
-PYGLIB_DEFINE_TYPE("gi._gi.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
-}
+PYGLIB_DEFINE_TYPE("gi._glib.Pid", PyGPid_Type, PYGLIB_PyLongObject)
static PyObject *
pyg_pid_close(PyObject *self, PyObject *args, PyObject *kwargs)
{
- g_spawn_close_pid(pyg_pid_get_pid (self));
+ g_spawn_close_pid(PYGLIB_PyLong_AsLong(self));
Py_INCREF(Py_None);
return Py_None;
}
static void
pyg_pid_free(PyObject *gpid)
{
- g_spawn_close_pid(pyg_pid_get_pid (gpid));
+ g_spawn_close_pid((GPid) PYGLIB_PyLong_AsLong(gpid));
PYGLIB_PyLong_Type.tp_free((void *) gpid);
}
static int
pyg_pid_tp_init(PyObject *self, PyObject *args, PyObject *kwargs)
{
- PyErr_SetString(PyExc_TypeError, "gi._gi.Pid cannot be manually instantiated");
+ PyErr_SetString(PyExc_TypeError, "gi._glib.Pid cannot be manually instantiated");
return -1;
}
PyObject *
pyg_pid_new(GPid pid)
{
- PyObject *long_val;
-#ifdef G_OS_WIN32
- long_val = PyLong_FromVoidPtr (pid);
+ PYGLIB_PyLongObject *pygpid;
+
+#if PY_VERSION_HEX >= 0x03000000
+ return PyObject_CallMethod((PyObject*)&PyGPid_Type, "__new__", "Oi",
+ &PyGPid_Type, pid);
#else
- long_val = PYGLIB_PyLong_FromLong (pid);
+ pygpid = PyObject_NEW(PyIntObject, &PyGPid_Type);
+ pygpid->ob_ival = pid;
#endif
- return PyObject_CallMethod((PyObject*)&PyGPid_Type, "__new__", "ON",
- &PyGPid_Type, long_val);
+ return (PyObject *) pygpid;
}
static void
PyGILState_STATE gil;
data = (struct _PyGChildSetupData *) user_data;
- gil = PyGILState_Ensure();
+ gil = pyglib_gil_state_ensure();
if (data->data)
retval = PyObject_CallFunction(data->func, "O", data->data);
else
Py_DECREF(data->func);
Py_XDECREF(data->data);
g_slice_free(struct _PyGChildSetupData, data);
- PyGILState_Release(gil);
+ pyglib_gil_state_release(gil);
}
PyObject *
gint *standard_input, *standard_output, *standard_error;
struct _PyGChildSetupData *callback_data = NULL;
GError *error = NULL;
- GPid child_pid = 0;
+ GPid child_pid = -1;
Py_ssize_t len, i;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|OsiOOOOO:gi._gi.spawn_async",
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|OsiOOOOO:gi._glib.spawn_async",
kwlist,
&pyargv, &pyenvp, &working_directory, &flags,
&func, &user_data,
/* parse argv */
if (!PySequence_Check(pyargv)) {
PyErr_SetString(PyExc_TypeError,
- "gi._gi.spawn_async: "
+ "gi._glib.spawn_async: "
"first argument must be a sequence of strings");
return NULL;
}
PyObject *tmp = PySequence_ITEM(pyargv, i);
if (tmp == NULL || !PYGLIB_PyUnicode_Check(tmp)) {
PyErr_SetString(PyExc_TypeError,
- "gi._gi.spawn_async: "
+ "gi._glib.spawn_async: "
"first argument must be a sequence of strings");
g_free(argv);
Py_XDECREF(tmp);
if (pyenvp) {
if (!PySequence_Check(pyenvp)) {
PyErr_SetString(PyExc_TypeError,
- "gi._gi.spawn_async: "
+ "gi._glib.spawn_async: "
"second argument must be a sequence of strings");
g_free(argv);
return NULL;
PyObject *tmp = PySequence_ITEM(pyenvp, i);
if (tmp == NULL || !PYGLIB_PyUnicode_Check(tmp)) {
PyErr_SetString(PyExc_TypeError,
- "gi._gi.spawn_async: "
+ "gi._glib.spawn_async: "
"second argument must be a sequence of strings");
g_free(envp);
Py_XDECREF(tmp);
Py_XDECREF(callback_data->data);
g_slice_free(struct _PyGChildSetupData, callback_data);
}
- pygi_error_check(&error);
+ pyglib_error_check(&error);
return NULL;
}
g_free(argv);
PyGPid_Type.tp_methods = pyg_pid_methods;
PyGPid_Type.tp_init = pyg_pid_tp_init;
PyGPid_Type.tp_free = (freefunc)pyg_pid_free;
- PyGPid_Type.tp_new = PYGLIB_PyLong_Type.tp_new;
PYGLIB_REGISTER_TYPE(d, PyGPid_Type, "Pid");
}