00228dd88d2b51e122b385272f5a3820a1e47a47
[platform/upstream/python-gobject.git] / gi / pyglib.h
1 /* -*- Mode: C; c-basic-offset: 4 -*-
2  * pyglib - Python bindings for GLib toolkit.
3  * Copyright (C) 1998-2003  James Henstridge
4  *               2004-2008  Johan Dahlin
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 #ifndef __PYGLIB_H__
21 #define __PYGLIB_H__
22
23 #include <Python.h>
24
25 #include <glib.h>
26
27 G_BEGIN_DECLS
28
29 typedef void (*PyGLibThreadsEnabledFunc) (void);
30 typedef void (*PyGLibThreadBlockFunc) (void);
31
32 #ifdef DISABLE_THREADING
33 #    define pyglib_gil_state_ensure()        PyGILState_LOCKED
34 #    define pyglib_gil_state_release(state)  state
35 #else
36 #    define pyglib_gil_state_ensure          PyGILState_Ensure
37 #    define pyglib_gil_state_release         PyGILState_Release
38 #endif
39
40 GOptionGroup * pyglib_option_group_transfer_group(PyObject *self);
41
42 /* Private: for gobject <-> glib interaction only. */
43 PyObject* _pyglib_generic_ptr_richcompare(void* a, void *b, int op);
44 PyObject* _pyglib_generic_long_richcompare(long a, long b, int op);
45
46
47 #define PYGLIB_REGISTER_TYPE(d, type, name)             \
48     if (!type.tp_alloc)                                 \
49         type.tp_alloc = PyType_GenericAlloc;            \
50     if (!type.tp_new)                                   \
51         type.tp_new = PyType_GenericNew;                \
52     if (PyType_Ready(&type))                            \
53         return;                                         \
54     PyDict_SetItemString(d, name, (PyObject *)&type);
55
56
57 G_END_DECLS
58
59 #endif /* __PYGLIB_H__ */
60