1 /*
2 * glib-compat.h
3 *
4 * Copyright 2011 Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
5 *
6 * This file is a part of the Libfm library.
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #ifndef __GLIB_COMPAT_H__
24 #define __GLIB_COMPAT_H__
25 #include <glib.h>
26 #include <glib-object.h>
27
28 G_BEGIN_DECLS
29
30 /* GLib prior 2.24 have no such macro */
31 #ifndef G_DEFINE_INTERFACE
32 # define G_DEFINE_INTERFACE(TN, t_n, T_P) \
33 static void t_n##_default_init (TN##Interface *klass); \
34 GType t_n##_get_type (void) \
35 { \
36 static volatile gsize g_define_type_id__volatile = 0; \
37 if (g_once_init_enter (&g_define_type_id__volatile)) \
38 { \
39 GType g_define_type_id = \
40 g_type_register_static_simple (G_TYPE_INTERFACE, \
41 g_intern_static_string (#TN), \
42 sizeof (TN##Interface), \
43 (GClassInitFunc)t_n##_default_init, \
44 0, \
45 (GInstanceInitFunc)NULL, \
46 (GTypeFlags) 0); \
47 if (T_P) \
48 g_type_interface_add_prerequisite (g_define_type_id, T_P); \
49 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
50 } \
51 return g_define_type_id__volatile; \
52 } /* closes t_n##_get_type() */
53 #endif /* G_DEFINE_INTERFACE */
54
55 #if !GLIB_CHECK_VERSION(2, 28, 0)
56 gboolean
57 g_signal_accumulator_first_wins (GSignalInvocationHint *ihint,
58 GValue *return_accu,
59 const GValue *handler_return,
60 gpointer dummy);
61 #endif
62
63 #if !GLIB_CHECK_VERSION(2, 28, 0)
64
65 /* This API was added in glib 2.28 */
66
67 #define g_slist_free_full(slist, free_func) \
68 { \
69 g_slist_foreach(slist, (GFunc)free_func, NULL); \
70 g_slist_free(slist); \
71 }
72
73 #define g_list_free_full(list, free_func) \
74 { \
75 g_list_foreach(list, (GFunc)free_func, NULL); \
76 g_list_free(list); \
77 }
78
79 #endif
80
81 #if !GLIB_CHECK_VERSION(2, 34, 0)
82 /* This useful API was added in glib 2.34 */
g_slist_copy_deep(GSList * list,GCopyFunc func,gpointer user_data)83 static inline GSList *g_slist_copy_deep(GSList *list, GCopyFunc func, gpointer user_data)
84 {
85 GSList *new_list = g_slist_copy(list), *l;
86 for(l = new_list; l; l = l->next)
87 l->data = func(l->data, user_data);
88 return new_list;
89 }
90 #endif
91
92 G_END_DECLS
93
94 #endif
95