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 "pygoptioncontext.h"
28 #include "pygoptiongroup.h"
32 * pyg_option_group_transfer_group:
33 * @group: a GOptionGroup wrapper
35 * This is used to transfer the GOptionGroup to a GOptionContext. After this
36 * is called, the calle must handle the release of the GOptionGroup.
38 * When #NULL is returned, the GOptionGroup was already transfered.
40 * Returns: Either #NULL or the wrapped GOptionGroup.
43 pyglib_option_group_transfer_group(PyObject
*obj
)
45 PyGOptionGroup
*self
= (PyGOptionGroup
*)obj
;
47 if (self
->is_in_context
)
50 self
->is_in_context
= TRUE
;
52 /* Here we increase the reference count of the PyGOptionGroup, because now
53 * the GOptionContext holds an reference to us (it is the userdata passed
54 * to g_option_group_new().
56 * The GOptionGroup is freed with the GOptionContext.
58 * We set it here because if we would do this in the init method we would
59 * hold two references and the PyGOptionGroup would never be freed.
67 /****** Private *****/
70 * _pyglib_destroy_notify:
71 * @user_data: a PyObject pointer.
73 * A function that can be used as a GDestroyNotify callback that will
74 * call Py_DECREF on the data.
77 _pyglib_destroy_notify(gpointer user_data
)
79 PyObject
*obj
= (PyObject
*)user_data
;
80 PyGILState_STATE state
;
82 state
= PyGILState_Ensure();
84 PyGILState_Release(state
);
88 _pyglib_handler_marshal(gpointer user_data
)
90 PyObject
*tuple
, *ret
;
92 PyGILState_STATE state
;
94 g_return_val_if_fail(user_data
!= NULL
, FALSE
);
96 state
= PyGILState_Ensure();
98 tuple
= (PyObject
*)user_data
;
99 ret
= PyObject_CallObject(PyTuple_GetItem(tuple
, 0),
100 PyTuple_GetItem(tuple
, 1));
105 res
= PyObject_IsTrue(ret
);
109 PyGILState_Release(state
);
115 _pyglib_generic_ptr_richcompare(void* a
, void *b
, int op
)
122 res
= (a
== b
) ? Py_True
: Py_False
;
126 res
= (a
!= b
) ? Py_True
: Py_False
;
130 res
= (a
< b
) ? Py_True
: Py_False
;
134 res
= (a
<= b
) ? Py_True
: Py_False
;
138 res
= (a
> b
) ? Py_True
: Py_False
;
142 res
= (a
>= b
) ? Py_True
: Py_False
;
146 res
= Py_NotImplemented
;
155 _pyglib_generic_long_richcompare(long a
, long b
, int op
)
162 res
= (a
== b
) ? Py_True
: Py_False
;
167 res
= (a
!= b
) ? Py_True
: Py_False
;
173 res
= (a
< b
) ? Py_True
: Py_False
;
178 res
= (a
<= b
) ? Py_True
: Py_False
;
183 res
= (a
> b
) ? Py_True
: Py_False
;
188 res
= (a
>= b
) ? Py_True
: Py_False
;
193 res
= Py_NotImplemented
;