1 /* -*- Mode: C; c-set-style: python; c-basic-offset: 4 -*-
2 * pyglib - Python bindings for GLib toolkit.
3 * Copyright (C) 1998-2003 James Henstridge
4 * 2004-2008 Johan Dahlin
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
27 #include "pyglib-private.h"
28 #include "pygoptioncontext.h"
29 #include "pygoptiongroup.h"
33 * pyg_option_group_transfer_group:
34 * @group: a GOptionGroup wrapper
36 * This is used to transfer the GOptionGroup to a GOptionContext. After this
37 * is called, the calle must handle the release of the GOptionGroup.
39 * When #NULL is returned, the GOptionGroup was already transfered.
41 * Returns: Either #NULL or the wrapped GOptionGroup.
44 pyglib_option_group_transfer_group(PyObject *obj)
46 PyGOptionGroup *self = (PyGOptionGroup*)obj;
48 if (self->is_in_context)
51 self->is_in_context = TRUE;
53 /* Here we increase the reference count of the PyGOptionGroup, because now
54 * the GOptionContext holds an reference to us (it is the userdata passed
55 * to g_option_group_new().
57 * The GOptionGroup is freed with the GOptionContext.
59 * We set it here because if we would do this in the init method we would
60 * hold two references and the PyGOptionGroup would never be freed.
68 /****** Private *****/
71 * _pyglib_destroy_notify:
72 * @user_data: a PyObject pointer.
74 * A function that can be used as a GDestroyNotify callback that will
75 * call Py_DECREF on the data.
78 _pyglib_destroy_notify(gpointer user_data)
80 PyObject *obj = (PyObject *)user_data;
81 PyGILState_STATE state;
83 state = pyglib_gil_state_ensure();
85 pyglib_gil_state_release(state);
89 _pyglib_handler_marshal(gpointer user_data)
91 PyObject *tuple, *ret;
93 PyGILState_STATE state;
95 g_return_val_if_fail(user_data != NULL, FALSE);
97 state = pyglib_gil_state_ensure();
99 tuple = (PyObject *)user_data;
100 ret = PyObject_CallObject(PyTuple_GetItem(tuple, 0),
101 PyTuple_GetItem(tuple, 1));
106 res = PyObject_IsTrue(ret);
110 pyglib_gil_state_release(state);
116 _pyglib_generic_ptr_richcompare(void* a, void *b, int op)
123 res = (a == b) ? Py_True : Py_False;
127 res = (a != b) ? Py_True : Py_False;
131 res = (a < b) ? Py_True : Py_False;
135 res = (a <= b) ? Py_True : Py_False;
139 res = (a > b) ? Py_True : Py_False;
143 res = (a >= b) ? Py_True : Py_False;
147 res = Py_NotImplemented;
156 _pyglib_generic_long_richcompare(long a, long b, int op)
163 res = (a == b) ? Py_True : Py_False;
168 res = (a != b) ? Py_True : Py_False;
174 res = (a < b) ? Py_True : Py_False;
179 res = (a <= b) ? Py_True : Py_False;
184 res = (a > b) ? Py_True : Py_False;
189 res = (a >= b) ? Py_True : Py_False;
194 res = Py_NotImplemented;