Imported Upstream version 3.7.3
[platform/upstream/python-gobject.git] / gi / _glib / 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, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19  * USA
20  */
21
22 #ifndef __PYGLIB_H__
23 #define __PYGLIB_H__
24
25 #include <Python.h>
26
27 #include <glib.h>
28
29 G_BEGIN_DECLS
30
31 typedef void (*PyGLibThreadsEnabledFunc) (void);
32 typedef void (*PyGLibThreadBlockFunc) (void);
33
34 void pyglib_init(void);
35 void pyglib_init_internal(PyObject *api);
36 PyGILState_STATE pyglib_gil_state_ensure(void);
37 void pyglib_gil_state_release(PyGILState_STATE state);
38 int pyglib_enable_threads(void);
39 gboolean pyglib_error_check(GError **error);
40 PyObject *pyglib_error_marshal (GError **error);
41 gboolean pyglib_gerror_exception_check(GError **error);
42 PyObject *pyglib_register_exception_for_domain(gchar *name,
43                                                gint error_domain);
44 gboolean pyglib_threads_enabled(void);
45 void pyglib_set_thread_block_funcs(PyGLibThreadBlockFunc block_threads_func,
46                                    PyGLibThreadBlockFunc unblock_threads_func);
47 void pyglib_block_threads(void);
48 void pyglib_unblock_threads(void);
49 PyObject * pyglib_option_context_new(GOptionContext *context);
50 PyObject * pyglib_option_group_new(GOptionGroup *group);
51 GOptionGroup * pyglib_option_group_transfer_group(PyObject *self);
52
53 /* Private: for gobject <-> glib interaction only. */
54 void _pyglib_notify_on_enabling_threads(PyGLibThreadsEnabledFunc callback);
55 PyObject* _pyglib_generic_ptr_richcompare(void* a, void *b, int op);
56 PyObject* _pyglib_generic_long_richcompare(long a, long b, int op);
57
58 #define pyglib_begin_allow_threads              \
59     G_STMT_START {                              \
60         PyThreadState *_save = NULL;            \
61         if (pyglib_threads_enabled())           \
62             _save = PyEval_SaveThread();
63
64 #define pyglib_end_allow_threads                \
65         if (pyglib_threads_enabled())           \
66             PyEval_RestoreThread(_save);        \
67     } G_STMT_END
68
69 #define PYGLIB_REGISTER_TYPE(d, type, name)             \
70     if (!type.tp_alloc)                                 \
71         type.tp_alloc = PyType_GenericAlloc;            \
72     if (!type.tp_new)                                   \
73         type.tp_new = PyType_GenericNew;                \
74     if (PyType_Ready(&type))                            \
75         return;                                         \
76     PyDict_SetItemString(d, name, (PyObject *)&type);
77
78
79 G_END_DECLS
80
81 #endif /* __PYGLIB_H__ */
82