pidgin 2.14.14dev
glibcompat.h
Go to the documentation of this file.
1
6/* purple
7 *
8 * Purple is the legal property of its developers, whose names are too numerous
9 * to list here. Please refer to the COPYRIGHT file distributed with this
10 * source distribution.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
25 */
26
27#ifndef PURPLE_GLIBCOMPAT_H
28#define PURPLE_GLIBCOMPAT_H
29
30#include <string.h>
31
32#include <glib.h>
33
34#if !GLIB_CHECK_VERSION(2,28,0)
35static inline void
36g_list_free_full(GList *l, GDestroyNotify free_func) {
37 GList *ll = NULL;
38
39 for(ll = l; ll != NULL; ll = ll->next) {
40 free_func(ll->data);
41 }
42
43 g_list_free(l);
44}
45
46static inline void
47g_slist_free_full(GSList *l, GDestroyNotify free_func) {
48 GSList *ll = NULL;
49
50 for(ll = l; ll != NULL; ll = ll->next) {
51 free_func(ll->data);
52 }
53
54 g_slist_free(l);
55}
56#endif /* !GLIB_CHECK_VERSION(2,23,0) */
57
58#if !GLIB_CHECK_VERSION(2,32,0)
59# define G_GNUC_BEGIN_IGNORE_DEPRECATIONS
60# define G_GNUC_END_IGNORE_DEPRECATIONS
61
62static inline void
63g_queue_free_full(GQueue *queue, GDestroyNotify free_func) {
64 GList *l = NULL;
65
66 for(l = queue->head; l != NULL; l = l->next) {
67 free_func(l->data);
68 }
69
70 g_queue_free(queue);
71}
72
73static inline gboolean
74g_hash_table_contains(GHashTable *hash_table, gconstpointer key) {
75 return g_hash_table_lookup_extended(hash_table, key, NULL, NULL);
76}
77
78#endif /* !GLIB_CHECK_VERSION(2,32,0) */
79
80#ifdef __clang__
81
82#undef G_GNUC_BEGIN_IGNORE_DEPRECATIONS
83#define G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
84 _Pragma ("clang diagnostic push") \
85 _Pragma ("clang diagnostic ignored \"-Wdeprecated-declarations\"")
86
87#undef G_GNUC_END_IGNORE_DEPRECATIONS
88#define G_GNUC_END_IGNORE_DEPRECATIONS \
89 _Pragma ("clang diagnostic pop")
90
91#endif /* __clang__ */
92
93/* Backport the static inline version of g_memdup2 if we don't have g_memdup2.
94 * see https://mail.gnome.org/archives/desktop-devel-list/2021-February/msg00000.html
95 * for more information.
96 */
97#if !GLIB_CHECK_VERSION(2, 67, 3)
98static inline gpointer
99g_memdup2(gconstpointer mem, gsize byte_size) {
100 gpointer new_mem = NULL;
101
102 if(mem && byte_size != 0) {
103 new_mem = g_malloc (byte_size);
104 memcpy (new_mem, mem, byte_size);
105 }
106
107 return new_mem;
108}
109#endif /* !GLIB_CHECK_VERSION(2, 67, 3) */
110
111#endif /* PURPLE_GLIBCOMPAT_H */
112