|
6 | 6 | #define _GNU_SOURCE
|
7 | 7 | #include <inttypes.h>
|
8 | 8 | #include <stdio.h>
|
| 9 | +#include <stdlib.h> |
| 10 | +#include <string.h> |
9 | 11 | #include <zlib.h>
|
10 | 12 |
|
11 | 13 | #include "gendwarfksyms.h"
|
@@ -179,20 +181,41 @@ static int type_map_get(const char *name, struct type_expansion **res)
|
179 | 181 | return -1;
|
180 | 182 | }
|
181 | 183 |
|
| 184 | +static int cmp_expansion_name(const void *p1, const void *p2) |
| 185 | +{ |
| 186 | + struct type_expansion *const *e1 = p1; |
| 187 | + struct type_expansion *const *e2 = p2; |
| 188 | + |
| 189 | + return strcmp((*e1)->name, (*e2)->name); |
| 190 | +} |
| 191 | + |
182 | 192 | static void type_map_write(FILE *file)
|
183 | 193 | {
|
184 | 194 | struct type_expansion *e;
|
185 | 195 | struct hlist_node *tmp;
|
| 196 | + struct type_expansion **es; |
| 197 | + size_t count = 0; |
| 198 | + size_t i = 0; |
186 | 199 |
|
187 | 200 | if (!file)
|
188 | 201 | return;
|
189 | 202 |
|
190 |
| - hash_for_each_safe(type_map, e, tmp, hash) { |
191 |
| - checkp(fputs(e->name, file)); |
| 203 | + hash_for_each_safe(type_map, e, tmp, hash) |
| 204 | + ++count; |
| 205 | + es = xmalloc(count * sizeof(*es)); |
| 206 | + hash_for_each_safe(type_map, e, tmp, hash) |
| 207 | + es[i++] = e; |
| 208 | + |
| 209 | + qsort(es, count, sizeof(*es), cmp_expansion_name); |
| 210 | + |
| 211 | + for (i = 0; i < count; ++i) { |
| 212 | + checkp(fputs(es[i]->name, file)); |
192 | 213 | checkp(fputs(" ", file));
|
193 |
| - type_list_write(&e->expanded, file); |
| 214 | + type_list_write(&es[i]->expanded, file); |
194 | 215 | checkp(fputs("\n", file));
|
195 | 216 | }
|
| 217 | + |
| 218 | + free(es); |
196 | 219 | }
|
197 | 220 |
|
198 | 221 | static void type_map_free(void)
|
|
0 commit comments