root / qdict.c @ f4918804
History | View | Annotate | Download (8 kB)
1 | fb08dde0 | Luiz Capitulino | /*
|
---|---|---|---|
2 | fb08dde0 | Luiz Capitulino | * QDict data type.
|
3 | fb08dde0 | Luiz Capitulino | *
|
4 | fb08dde0 | Luiz Capitulino | * Copyright (C) 2009 Red Hat Inc.
|
5 | fb08dde0 | Luiz Capitulino | *
|
6 | fb08dde0 | Luiz Capitulino | * Authors:
|
7 | fb08dde0 | Luiz Capitulino | * Luiz Capitulino <lcapitulino@redhat.com>
|
8 | fb08dde0 | Luiz Capitulino | *
|
9 | fb08dde0 | Luiz Capitulino | * This work is licensed under the terms of the GNU GPL, version 2. See
|
10 | fb08dde0 | Luiz Capitulino | * the COPYING file in the top-level directory.
|
11 | fb08dde0 | Luiz Capitulino | */
|
12 | fb08dde0 | Luiz Capitulino | |
13 | fb08dde0 | Luiz Capitulino | #include "qint.h" |
14 | fb08dde0 | Luiz Capitulino | #include "qdict.h" |
15 | cd4dde36 | Luiz Capitulino | #include "qbool.h" |
16 | fb08dde0 | Luiz Capitulino | #include "qstring.h" |
17 | fb08dde0 | Luiz Capitulino | #include "qobject.h" |
18 | 72cf2d4f | Blue Swirl | #include "qemu-queue.h" |
19 | fb08dde0 | Luiz Capitulino | #include "qemu-common.h" |
20 | fb08dde0 | Luiz Capitulino | |
21 | aa43d9cc | Blue Swirl | static void qdict_destroy_obj(QObject *obj); |
22 | aa43d9cc | Blue Swirl | |
23 | aa43d9cc | Blue Swirl | static const QType qdict_type = { |
24 | aa43d9cc | Blue Swirl | .code = QTYPE_QDICT, |
25 | aa43d9cc | Blue Swirl | .destroy = qdict_destroy_obj, |
26 | aa43d9cc | Blue Swirl | }; |
27 | fb08dde0 | Luiz Capitulino | |
28 | fb08dde0 | Luiz Capitulino | /**
|
29 | fb08dde0 | Luiz Capitulino | * qdict_new(): Create a new QDict
|
30 | fb08dde0 | Luiz Capitulino | *
|
31 | fb08dde0 | Luiz Capitulino | * Return strong reference.
|
32 | fb08dde0 | Luiz Capitulino | */
|
33 | fb08dde0 | Luiz Capitulino | QDict *qdict_new(void)
|
34 | fb08dde0 | Luiz Capitulino | { |
35 | fb08dde0 | Luiz Capitulino | QDict *qdict; |
36 | fb08dde0 | Luiz Capitulino | |
37 | fb08dde0 | Luiz Capitulino | qdict = qemu_mallocz(sizeof(*qdict));
|
38 | fb08dde0 | Luiz Capitulino | QOBJECT_INIT(qdict, &qdict_type); |
39 | fb08dde0 | Luiz Capitulino | |
40 | fb08dde0 | Luiz Capitulino | return qdict;
|
41 | fb08dde0 | Luiz Capitulino | } |
42 | fb08dde0 | Luiz Capitulino | |
43 | fb08dde0 | Luiz Capitulino | /**
|
44 | fb08dde0 | Luiz Capitulino | * qobject_to_qdict(): Convert a QObject into a QDict
|
45 | fb08dde0 | Luiz Capitulino | */
|
46 | fb08dde0 | Luiz Capitulino | QDict *qobject_to_qdict(const QObject *obj)
|
47 | fb08dde0 | Luiz Capitulino | { |
48 | fb08dde0 | Luiz Capitulino | if (qobject_type(obj) != QTYPE_QDICT)
|
49 | fb08dde0 | Luiz Capitulino | return NULL; |
50 | fb08dde0 | Luiz Capitulino | |
51 | fb08dde0 | Luiz Capitulino | return container_of(obj, QDict, base);
|
52 | fb08dde0 | Luiz Capitulino | } |
53 | fb08dde0 | Luiz Capitulino | |
54 | fb08dde0 | Luiz Capitulino | /**
|
55 | fb08dde0 | Luiz Capitulino | * tdb_hash(): based on the hash agorithm from gdbm, via tdb
|
56 | fb08dde0 | Luiz Capitulino | * (from module-init-tools)
|
57 | fb08dde0 | Luiz Capitulino | */
|
58 | fb08dde0 | Luiz Capitulino | static unsigned int tdb_hash(const char *name) |
59 | fb08dde0 | Luiz Capitulino | { |
60 | fb08dde0 | Luiz Capitulino | unsigned value; /* Used to compute the hash value. */ |
61 | fb08dde0 | Luiz Capitulino | unsigned i; /* Used to cycle through random values. */ |
62 | fb08dde0 | Luiz Capitulino | |
63 | fb08dde0 | Luiz Capitulino | /* Set the initial value from the key size. */
|
64 | fb08dde0 | Luiz Capitulino | for (value = 0x238F13AF * strlen(name), i=0; name[i]; i++) |
65 | fb08dde0 | Luiz Capitulino | value = (value + (((const unsigned char *)name)[i] << (i*5 % 24))); |
66 | fb08dde0 | Luiz Capitulino | |
67 | fb08dde0 | Luiz Capitulino | return (1103515243 * value + 12345); |
68 | fb08dde0 | Luiz Capitulino | } |
69 | fb08dde0 | Luiz Capitulino | |
70 | fb08dde0 | Luiz Capitulino | /**
|
71 | fb08dde0 | Luiz Capitulino | * alloc_entry(): allocate a new QDictEntry
|
72 | fb08dde0 | Luiz Capitulino | */
|
73 | fb08dde0 | Luiz Capitulino | static QDictEntry *alloc_entry(const char *key, QObject *value) |
74 | fb08dde0 | Luiz Capitulino | { |
75 | fb08dde0 | Luiz Capitulino | QDictEntry *entry; |
76 | fb08dde0 | Luiz Capitulino | |
77 | fb08dde0 | Luiz Capitulino | entry = qemu_mallocz(sizeof(*entry));
|
78 | fb08dde0 | Luiz Capitulino | entry->key = qemu_strdup(key); |
79 | fb08dde0 | Luiz Capitulino | entry->value = value; |
80 | fb08dde0 | Luiz Capitulino | |
81 | fb08dde0 | Luiz Capitulino | return entry;
|
82 | fb08dde0 | Luiz Capitulino | } |
83 | fb08dde0 | Luiz Capitulino | |
84 | fb08dde0 | Luiz Capitulino | /**
|
85 | fb08dde0 | Luiz Capitulino | * qdict_find(): List lookup function
|
86 | fb08dde0 | Luiz Capitulino | */
|
87 | fb08dde0 | Luiz Capitulino | static QDictEntry *qdict_find(const QDict *qdict, |
88 | fb08dde0 | Luiz Capitulino | const char *key, unsigned int hash) |
89 | fb08dde0 | Luiz Capitulino | { |
90 | fb08dde0 | Luiz Capitulino | QDictEntry *entry; |
91 | fb08dde0 | Luiz Capitulino | |
92 | 72cf2d4f | Blue Swirl | QLIST_FOREACH(entry, &qdict->table[hash], next) |
93 | fb08dde0 | Luiz Capitulino | if (!strcmp(entry->key, key))
|
94 | fb08dde0 | Luiz Capitulino | return entry;
|
95 | fb08dde0 | Luiz Capitulino | |
96 | fb08dde0 | Luiz Capitulino | return NULL; |
97 | fb08dde0 | Luiz Capitulino | } |
98 | fb08dde0 | Luiz Capitulino | |
99 | fb08dde0 | Luiz Capitulino | /**
|
100 | fb08dde0 | Luiz Capitulino | * qdict_put_obj(): Put a new QObject into the dictionary
|
101 | fb08dde0 | Luiz Capitulino | *
|
102 | fb08dde0 | Luiz Capitulino | * Insert the pair 'key:value' into 'qdict', if 'key' already exists
|
103 | fb08dde0 | Luiz Capitulino | * its 'value' will be replaced.
|
104 | fb08dde0 | Luiz Capitulino | *
|
105 | fb08dde0 | Luiz Capitulino | * This is done by freeing the reference to the stored QObject and
|
106 | fb08dde0 | Luiz Capitulino | * storing the new one in the same entry.
|
107 | fb08dde0 | Luiz Capitulino | *
|
108 | fb08dde0 | Luiz Capitulino | * NOTE: ownership of 'value' is transferred to the QDict
|
109 | fb08dde0 | Luiz Capitulino | */
|
110 | fb08dde0 | Luiz Capitulino | void qdict_put_obj(QDict *qdict, const char *key, QObject *value) |
111 | fb08dde0 | Luiz Capitulino | { |
112 | fb08dde0 | Luiz Capitulino | unsigned int hash; |
113 | fb08dde0 | Luiz Capitulino | QDictEntry *entry; |
114 | fb08dde0 | Luiz Capitulino | |
115 | fb08dde0 | Luiz Capitulino | hash = tdb_hash(key) % QDICT_HASH_SIZE; |
116 | fb08dde0 | Luiz Capitulino | entry = qdict_find(qdict, key, hash); |
117 | fb08dde0 | Luiz Capitulino | if (entry) {
|
118 | fb08dde0 | Luiz Capitulino | /* replace key's value */
|
119 | fb08dde0 | Luiz Capitulino | qobject_decref(entry->value); |
120 | fb08dde0 | Luiz Capitulino | entry->value = value; |
121 | fb08dde0 | Luiz Capitulino | } else {
|
122 | fb08dde0 | Luiz Capitulino | /* allocate a new entry */
|
123 | fb08dde0 | Luiz Capitulino | entry = alloc_entry(key, value); |
124 | 72cf2d4f | Blue Swirl | QLIST_INSERT_HEAD(&qdict->table[hash], entry, next); |
125 | 29ec3156 | Luiz Capitulino | qdict->size++; |
126 | fb08dde0 | Luiz Capitulino | } |
127 | fb08dde0 | Luiz Capitulino | } |
128 | fb08dde0 | Luiz Capitulino | |
129 | fb08dde0 | Luiz Capitulino | /**
|
130 | fb08dde0 | Luiz Capitulino | * qdict_get(): Lookup for a given 'key'
|
131 | fb08dde0 | Luiz Capitulino | *
|
132 | fb08dde0 | Luiz Capitulino | * Return a weak reference to the QObject associated with 'key' if
|
133 | fb08dde0 | Luiz Capitulino | * 'key' is present in the dictionary, NULL otherwise.
|
134 | fb08dde0 | Luiz Capitulino | */
|
135 | fb08dde0 | Luiz Capitulino | QObject *qdict_get(const QDict *qdict, const char *key) |
136 | fb08dde0 | Luiz Capitulino | { |
137 | fb08dde0 | Luiz Capitulino | QDictEntry *entry; |
138 | fb08dde0 | Luiz Capitulino | |
139 | fb08dde0 | Luiz Capitulino | entry = qdict_find(qdict, key, tdb_hash(key) % QDICT_HASH_SIZE); |
140 | fb08dde0 | Luiz Capitulino | return (entry == NULL ? NULL : entry->value); |
141 | fb08dde0 | Luiz Capitulino | } |
142 | fb08dde0 | Luiz Capitulino | |
143 | fb08dde0 | Luiz Capitulino | /**
|
144 | fb08dde0 | Luiz Capitulino | * qdict_haskey(): Check if 'key' exists
|
145 | fb08dde0 | Luiz Capitulino | *
|
146 | fb08dde0 | Luiz Capitulino | * Return 1 if 'key' exists in the dict, 0 otherwise
|
147 | fb08dde0 | Luiz Capitulino | */
|
148 | fb08dde0 | Luiz Capitulino | int qdict_haskey(const QDict *qdict, const char *key) |
149 | fb08dde0 | Luiz Capitulino | { |
150 | fb08dde0 | Luiz Capitulino | unsigned int hash = tdb_hash(key) % QDICT_HASH_SIZE; |
151 | fb08dde0 | Luiz Capitulino | return (qdict_find(qdict, key, hash) == NULL ? 0 : 1); |
152 | fb08dde0 | Luiz Capitulino | } |
153 | fb08dde0 | Luiz Capitulino | |
154 | fb08dde0 | Luiz Capitulino | /**
|
155 | fb08dde0 | Luiz Capitulino | * qdict_size(): Return the size of the dictionary
|
156 | fb08dde0 | Luiz Capitulino | */
|
157 | fb08dde0 | Luiz Capitulino | size_t qdict_size(const QDict *qdict)
|
158 | fb08dde0 | Luiz Capitulino | { |
159 | fb08dde0 | Luiz Capitulino | return qdict->size;
|
160 | fb08dde0 | Luiz Capitulino | } |
161 | fb08dde0 | Luiz Capitulino | |
162 | fb08dde0 | Luiz Capitulino | /**
|
163 | fb08dde0 | Luiz Capitulino | * qdict_get_obj(): Get a QObject of a specific type
|
164 | fb08dde0 | Luiz Capitulino | */
|
165 | fb08dde0 | Luiz Capitulino | static QObject *qdict_get_obj(const QDict *qdict, const char *key, |
166 | fb08dde0 | Luiz Capitulino | qtype_code type) |
167 | fb08dde0 | Luiz Capitulino | { |
168 | fb08dde0 | Luiz Capitulino | QObject *obj; |
169 | fb08dde0 | Luiz Capitulino | |
170 | fb08dde0 | Luiz Capitulino | obj = qdict_get(qdict, key); |
171 | fb08dde0 | Luiz Capitulino | assert(obj != NULL);
|
172 | fb08dde0 | Luiz Capitulino | assert(qobject_type(obj) == type); |
173 | fb08dde0 | Luiz Capitulino | |
174 | fb08dde0 | Luiz Capitulino | return obj;
|
175 | fb08dde0 | Luiz Capitulino | } |
176 | fb08dde0 | Luiz Capitulino | |
177 | fb08dde0 | Luiz Capitulino | /**
|
178 | fb08dde0 | Luiz Capitulino | * qdict_get_int(): Get an integer mapped by 'key'
|
179 | fb08dde0 | Luiz Capitulino | *
|
180 | fb08dde0 | Luiz Capitulino | * This function assumes that 'key' exists and it stores a
|
181 | fb08dde0 | Luiz Capitulino | * QInt object.
|
182 | fb08dde0 | Luiz Capitulino | *
|
183 | fb08dde0 | Luiz Capitulino | * Return integer mapped by 'key'.
|
184 | fb08dde0 | Luiz Capitulino | */
|
185 | fb08dde0 | Luiz Capitulino | int64_t qdict_get_int(const QDict *qdict, const char *key) |
186 | fb08dde0 | Luiz Capitulino | { |
187 | fb08dde0 | Luiz Capitulino | QObject *obj = qdict_get_obj(qdict, key, QTYPE_QINT); |
188 | fb08dde0 | Luiz Capitulino | return qint_get_int(qobject_to_qint(obj));
|
189 | fb08dde0 | Luiz Capitulino | } |
190 | fb08dde0 | Luiz Capitulino | |
191 | fb08dde0 | Luiz Capitulino | /**
|
192 | cd4dde36 | Luiz Capitulino | * qdict_get_bool(): Get a bool mapped by 'key'
|
193 | cd4dde36 | Luiz Capitulino | *
|
194 | cd4dde36 | Luiz Capitulino | * This function assumes that 'key' exists and it stores a
|
195 | cd4dde36 | Luiz Capitulino | * QBool object.
|
196 | cd4dde36 | Luiz Capitulino | *
|
197 | cd4dde36 | Luiz Capitulino | * Return bool mapped by 'key'.
|
198 | cd4dde36 | Luiz Capitulino | */
|
199 | cd4dde36 | Luiz Capitulino | int qdict_get_bool(const QDict *qdict, const char *key) |
200 | cd4dde36 | Luiz Capitulino | { |
201 | cd4dde36 | Luiz Capitulino | QObject *obj = qdict_get_obj(qdict, key, QTYPE_QBOOL); |
202 | cd4dde36 | Luiz Capitulino | return qbool_get_int(qobject_to_qbool(obj));
|
203 | cd4dde36 | Luiz Capitulino | } |
204 | cd4dde36 | Luiz Capitulino | |
205 | cd4dde36 | Luiz Capitulino | /**
|
206 | f2e17508 | Luiz Capitulino | * qdict_get_qlist(): Get the QList mapped by 'key'
|
207 | f2e17508 | Luiz Capitulino | *
|
208 | f2e17508 | Luiz Capitulino | * This function assumes that 'key' exists and it stores a
|
209 | f2e17508 | Luiz Capitulino | * QList object.
|
210 | f2e17508 | Luiz Capitulino | *
|
211 | f2e17508 | Luiz Capitulino | * Return QList mapped by 'key'.
|
212 | f2e17508 | Luiz Capitulino | */
|
213 | f2e17508 | Luiz Capitulino | QList *qdict_get_qlist(const QDict *qdict, const char *key) |
214 | f2e17508 | Luiz Capitulino | { |
215 | f2e17508 | Luiz Capitulino | return qobject_to_qlist(qdict_get_obj(qdict, key, QTYPE_QLIST));
|
216 | f2e17508 | Luiz Capitulino | } |
217 | f2e17508 | Luiz Capitulino | |
218 | f2e17508 | Luiz Capitulino | /**
|
219 | fb08dde0 | Luiz Capitulino | * qdict_get_str(): Get a pointer to the stored string mapped
|
220 | fb08dde0 | Luiz Capitulino | * by 'key'
|
221 | fb08dde0 | Luiz Capitulino | *
|
222 | fb08dde0 | Luiz Capitulino | * This function assumes that 'key' exists and it stores a
|
223 | fb08dde0 | Luiz Capitulino | * QString object.
|
224 | fb08dde0 | Luiz Capitulino | *
|
225 | fb08dde0 | Luiz Capitulino | * Return pointer to the string mapped by 'key'.
|
226 | fb08dde0 | Luiz Capitulino | */
|
227 | fb08dde0 | Luiz Capitulino | const char *qdict_get_str(const QDict *qdict, const char *key) |
228 | fb08dde0 | Luiz Capitulino | { |
229 | fb08dde0 | Luiz Capitulino | QObject *obj = qdict_get_obj(qdict, key, QTYPE_QSTRING); |
230 | fb08dde0 | Luiz Capitulino | return qstring_get_str(qobject_to_qstring(obj));
|
231 | fb08dde0 | Luiz Capitulino | } |
232 | fb08dde0 | Luiz Capitulino | |
233 | fb08dde0 | Luiz Capitulino | /**
|
234 | fb08dde0 | Luiz Capitulino | * qdict_get_try_int(): Try to get integer mapped by 'key'
|
235 | fb08dde0 | Luiz Capitulino | *
|
236 | fb08dde0 | Luiz Capitulino | * Return integer mapped by 'key', if it is not present in
|
237 | fb08dde0 | Luiz Capitulino | * the dictionary or if the stored object is not of QInt type
|
238 | fb08dde0 | Luiz Capitulino | * 'err_value' will be returned.
|
239 | fb08dde0 | Luiz Capitulino | */
|
240 | fb08dde0 | Luiz Capitulino | int64_t qdict_get_try_int(const QDict *qdict, const char *key, |
241 | fb08dde0 | Luiz Capitulino | int64_t err_value) |
242 | fb08dde0 | Luiz Capitulino | { |
243 | fb08dde0 | Luiz Capitulino | QObject *obj; |
244 | fb08dde0 | Luiz Capitulino | |
245 | fb08dde0 | Luiz Capitulino | obj = qdict_get(qdict, key); |
246 | fb08dde0 | Luiz Capitulino | if (!obj || qobject_type(obj) != QTYPE_QINT)
|
247 | fb08dde0 | Luiz Capitulino | return err_value;
|
248 | fb08dde0 | Luiz Capitulino | |
249 | fb08dde0 | Luiz Capitulino | return qint_get_int(qobject_to_qint(obj));
|
250 | fb08dde0 | Luiz Capitulino | } |
251 | fb08dde0 | Luiz Capitulino | |
252 | fb08dde0 | Luiz Capitulino | /**
|
253 | fb08dde0 | Luiz Capitulino | * qdict_get_try_str(): Try to get a pointer to the stored string
|
254 | fb08dde0 | Luiz Capitulino | * mapped by 'key'
|
255 | fb08dde0 | Luiz Capitulino | *
|
256 | fb08dde0 | Luiz Capitulino | * Return a pointer to the string mapped by 'key', if it is not present
|
257 | fb08dde0 | Luiz Capitulino | * in the dictionary or if the stored object is not of QString type
|
258 | fb08dde0 | Luiz Capitulino | * NULL will be returned.
|
259 | fb08dde0 | Luiz Capitulino | */
|
260 | fb08dde0 | Luiz Capitulino | const char *qdict_get_try_str(const QDict *qdict, const char *key) |
261 | fb08dde0 | Luiz Capitulino | { |
262 | fb08dde0 | Luiz Capitulino | QObject *obj; |
263 | fb08dde0 | Luiz Capitulino | |
264 | fb08dde0 | Luiz Capitulino | obj = qdict_get(qdict, key); |
265 | fb08dde0 | Luiz Capitulino | if (!obj || qobject_type(obj) != QTYPE_QSTRING)
|
266 | fb08dde0 | Luiz Capitulino | return NULL; |
267 | fb08dde0 | Luiz Capitulino | |
268 | fb08dde0 | Luiz Capitulino | return qstring_get_str(qobject_to_qstring(obj));
|
269 | fb08dde0 | Luiz Capitulino | } |
270 | fb08dde0 | Luiz Capitulino | |
271 | fb08dde0 | Luiz Capitulino | /**
|
272 | 21f800d3 | Luiz Capitulino | * qdict_iter(): Iterate over all the dictionary's stored values.
|
273 | 21f800d3 | Luiz Capitulino | *
|
274 | 21f800d3 | Luiz Capitulino | * This function allows the user to provide an iterator, which will be
|
275 | 21f800d3 | Luiz Capitulino | * called for each stored value in the dictionary.
|
276 | 21f800d3 | Luiz Capitulino | */
|
277 | 21f800d3 | Luiz Capitulino | void qdict_iter(const QDict *qdict, |
278 | 21f800d3 | Luiz Capitulino | void (*iter)(const char *key, QObject *obj, void *opaque), |
279 | 21f800d3 | Luiz Capitulino | void *opaque)
|
280 | 21f800d3 | Luiz Capitulino | { |
281 | 21f800d3 | Luiz Capitulino | int i;
|
282 | 21f800d3 | Luiz Capitulino | QDictEntry *entry; |
283 | 21f800d3 | Luiz Capitulino | |
284 | 21f800d3 | Luiz Capitulino | for (i = 0; i < QDICT_HASH_SIZE; i++) { |
285 | 21f800d3 | Luiz Capitulino | QLIST_FOREACH(entry, &qdict->table[i], next) |
286 | 21f800d3 | Luiz Capitulino | iter(entry->key, entry->value, opaque); |
287 | 21f800d3 | Luiz Capitulino | } |
288 | 21f800d3 | Luiz Capitulino | } |
289 | 21f800d3 | Luiz Capitulino | |
290 | 21f800d3 | Luiz Capitulino | /**
|
291 | fb08dde0 | Luiz Capitulino | * qentry_destroy(): Free all the memory allocated by a QDictEntry
|
292 | fb08dde0 | Luiz Capitulino | */
|
293 | fb08dde0 | Luiz Capitulino | static void qentry_destroy(QDictEntry *e) |
294 | fb08dde0 | Luiz Capitulino | { |
295 | fb08dde0 | Luiz Capitulino | assert(e != NULL);
|
296 | fb08dde0 | Luiz Capitulino | assert(e->key != NULL);
|
297 | fb08dde0 | Luiz Capitulino | assert(e->value != NULL);
|
298 | fb08dde0 | Luiz Capitulino | |
299 | fb08dde0 | Luiz Capitulino | qobject_decref(e->value); |
300 | fb08dde0 | Luiz Capitulino | qemu_free(e->key); |
301 | fb08dde0 | Luiz Capitulino | qemu_free(e); |
302 | fb08dde0 | Luiz Capitulino | } |
303 | fb08dde0 | Luiz Capitulino | |
304 | fb08dde0 | Luiz Capitulino | /**
|
305 | fb08dde0 | Luiz Capitulino | * qdict_del(): Delete a 'key:value' pair from the dictionary
|
306 | fb08dde0 | Luiz Capitulino | *
|
307 | fb08dde0 | Luiz Capitulino | * This will destroy all data allocated by this entry.
|
308 | fb08dde0 | Luiz Capitulino | */
|
309 | fb08dde0 | Luiz Capitulino | void qdict_del(QDict *qdict, const char *key) |
310 | fb08dde0 | Luiz Capitulino | { |
311 | fb08dde0 | Luiz Capitulino | QDictEntry *entry; |
312 | fb08dde0 | Luiz Capitulino | |
313 | fb08dde0 | Luiz Capitulino | entry = qdict_find(qdict, key, tdb_hash(key) % QDICT_HASH_SIZE); |
314 | fb08dde0 | Luiz Capitulino | if (entry) {
|
315 | 72cf2d4f | Blue Swirl | QLIST_REMOVE(entry, next); |
316 | fb08dde0 | Luiz Capitulino | qentry_destroy(entry); |
317 | fb08dde0 | Luiz Capitulino | qdict->size--; |
318 | fb08dde0 | Luiz Capitulino | } |
319 | fb08dde0 | Luiz Capitulino | } |
320 | fb08dde0 | Luiz Capitulino | |
321 | fb08dde0 | Luiz Capitulino | /**
|
322 | fb08dde0 | Luiz Capitulino | * qdict_destroy_obj(): Free all the memory allocated by a QDict
|
323 | fb08dde0 | Luiz Capitulino | */
|
324 | fb08dde0 | Luiz Capitulino | static void qdict_destroy_obj(QObject *obj) |
325 | fb08dde0 | Luiz Capitulino | { |
326 | fb08dde0 | Luiz Capitulino | int i;
|
327 | fb08dde0 | Luiz Capitulino | QDict *qdict; |
328 | fb08dde0 | Luiz Capitulino | |
329 | fb08dde0 | Luiz Capitulino | assert(obj != NULL);
|
330 | fb08dde0 | Luiz Capitulino | qdict = qobject_to_qdict(obj); |
331 | fb08dde0 | Luiz Capitulino | |
332 | fb08dde0 | Luiz Capitulino | for (i = 0; i < QDICT_HASH_SIZE; i++) { |
333 | 72cf2d4f | Blue Swirl | QDictEntry *entry = QLIST_FIRST(&qdict->table[i]); |
334 | fb08dde0 | Luiz Capitulino | while (entry) {
|
335 | 72cf2d4f | Blue Swirl | QDictEntry *tmp = QLIST_NEXT(entry, next); |
336 | 72cf2d4f | Blue Swirl | QLIST_REMOVE(entry, next); |
337 | fb08dde0 | Luiz Capitulino | qentry_destroy(entry); |
338 | fb08dde0 | Luiz Capitulino | entry = tmp; |
339 | fb08dde0 | Luiz Capitulino | } |
340 | fb08dde0 | Luiz Capitulino | } |
341 | fb08dde0 | Luiz Capitulino | |
342 | fb08dde0 | Luiz Capitulino | qemu_free(qdict); |
343 | fb08dde0 | Luiz Capitulino | } |