Stackdb
Stackdb is a stackable, multi-target and -level source debugger and memory forensics library.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
glib_wrapper.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013, 2014 The University of Utah
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #ifndef _UTIL_GLIB_H
20 #define _UTIL_GLIB_H
21 
22 #include <glib.h>
23 
24 /*
25  * A little cast to quickly use any numeric type (for sizeof(type) <=
26  * sizeof(uintptr_t), anyway) as a GHashTable gpointer key.
27  */
28 #define VGINTKEY gpointer)(uintptr_t
29 
34 #define v_g_list_foreach(glhead,glcur,elm) \
35  for ((glcur) = (glhead), \
36  (elm) = (glcur) ? (typeof(elm))(glcur)->data : NULL; \
37  (glcur) != NULL; \
38  (glcur) = g_list_next(glcur), \
39  (elm) = (glcur) ? (typeof(elm))(glcur)->data : NULL)
40 
46 #define v_g_list_foreach_safe(glhead,glcur,glnext,elm) \
47  for ((glcur) = (glhead), \
48  (glnext) = (glcur) ? g_list_next(glcur) : NULL, \
49  (elm) = (glcur) ? (typeof(elm))(glcur)->data : NULL; \
50  (glcur) != NULL; \
51  (glcur) = (glnext), \
52  (glnext) = (glnext) ? g_list_next(glnext) : NULL, \
53  (elm) = (glcur) ? (typeof(elm))(glcur)->data : NULL)
54 
55 #define v_g_list_foreach_remove(glhead,glcur,glnext) \
56  do { \
57  (glhead) = g_list_remove_link(glhead,glcur); \
58  } while (0)
59 
60 #define v_g_slist_foreach(gslhead,gslcur,elm) \
61  for ((gslcur) = (gslhead), \
62  (elm) = (gslcur) ? (typeof(elm))(gslcur)->data : NULL; \
63  (gslcur) != NULL; \
64  (gslcur) = g_slist_next(gslcur), \
65  (elm) = (gslcur) ? (typeof(elm))(gslcur)->data : NULL)
66 #define v_g_slist_foreach_dual(gslhead1,gslhead2,gslcur1,gslcur2,elm1,elm2) \
67  for ((gslcur1) = (gslhead1),(gslcur2) = (gslhead2), \
68  (elm1) = (gslcur1) ? (typeof(elm1))(gslcur1)->data : NULL, \
69  (elm2) = (gslcur2) ? (typeof(elm2))(gslcur2)->data : NULL; \
70  (gslcur1) != NULL && (gslcur2) != NULL; \
71  (gslcur1) = g_slist_next(gslcur1),(gslcur2) = g_slist_next(gslcur2), \
72  (elm1) = (gslcur1) ? (typeof(elm1))(gslcur1)->data : NULL, \
73  (elm2) = (gslcur2) ? (typeof(elm2))(gslcur2)->data : NULL)
74 #define v_g_slist_steal(gslcur) (gslcur)->data = NULL
75 
76 static inline GSList *g_hash_table_get_keys_slist(GHashTable *t) {
77  GSList *retval = NULL;
78  GHashTableIter iter;
79  gpointer k;
80 
81  if (!t)
82  return NULL;
83 
84  g_hash_table_iter_init(&iter,t);
85  while (g_hash_table_iter_next(&iter,&k,NULL)) {
86  retval = g_slist_prepend(retval,k);
87  }
88 
89  return retval;
90 }
91 
92 static inline GSList *g_hash_table_get_values_slist(GHashTable *t) {
93  GSList *retval = NULL;
94  GHashTableIter iter;
95  gpointer v;
96 
97  if (!t)
98  return NULL;
99 
100  g_hash_table_iter_init(&iter,t);
101  while (g_hash_table_iter_next(&iter,NULL,&v)) {
102  retval = g_slist_prepend(retval,v);
103  }
104 
105  return retval;
106 }
107 
108 /*
109 #define vg_slist_foreach_safe(gslhead,gslcur,data,gslprev) \
110  for ((gslcur) = (gslhead), \
111  (gslprev) = NULL, \
112  (data) = (gslcur) ? (typeof(data))(gslcur)->data : NULL; \
113  (gslcur) != NULL; \
114  gslprev = gslcur, (gslcur) = g_slist_next(gslcur))
115 
116 #define vg_slist_foreach_i(gslhead,gslcur,data,lpc) \
117  for ((lpc) = 0, \
118  (gslcur) = (gslhead), \
119  (data) = (gslcur) ? (typeof(data))(gslcur)->data : NULL; \
120  (gslcur) != NULL; \
121  ++(lpc), (gslcur) = g_slist_next(gslcur))
122 
123 #define vg_slist_foreach_delete(gslhead,gslcur,gslprev) \
124  do { \
125  GSList *next = (gslcur) ? g_slist_next(gslcur) : NULL; \
126  if (
127  while (0);
128  for ((lpc) = 0, \
129  (gslcur) = (gslhead), \
130  (data) = (gslcur) ? (typeof(data))gslhead->data : NULL; \
131  gslhead->len - lpc > 0; \
132  ++lpc, gslcur = g_slist_next(gslcur))
133 */
134 
135 #endif /* _UTIL_GLIB_H */
struct target * t
Definition: dumptarget.c:48