Lines Matching +full:1 +full:st
8 * 1. Redistributions of source code must retain the above copyright
52 #define ELFTC_STRING_TABLE_LENGTH(st) ((st)->st_len >> 1) argument
53 #define ELFTC_STRING_TABLE_CLEAR_COMPACTION_FLAG(st) do { \ argument
54 (st)->st_len &= ~ELFTC_STRING_TABLE_COMPACTION_FLAG; \
56 #define ELFTC_STRING_TABLE_SET_COMPACTION_FLAG(st) do { \ argument
57 (st)->st_len |= ELFTC_STRING_TABLE_COMPACTION_FLAG; \
59 #define ELFTC_STRING_TABLE_UPDATE_LENGTH(st, len) do { \ argument
60 (st)->st_len = \
61 ((st)->st_len & \
63 ((len) << 1); \
76 elftc_string_table_find_hash_entry(Elftc_String_Table *st, const char *string, in elftc_string_table_find_hash_entry() argument
83 hashindex = libelftc_hash_string(string) % st->st_nbuckets; in elftc_string_table_find_hash_entry()
88 SLIST_FOREACH(ste, &st->st_buckets[hashindex], ste_next) { in elftc_string_table_find_hash_entry()
89 s = st->st_string_pool + labs(ste->ste_idx); in elftc_string_table_find_hash_entry()
91 assert(s > st->st_string_pool && in elftc_string_table_find_hash_entry()
92 s < st->st_string_pool + st->st_string_pool_size); in elftc_string_table_find_hash_entry()
102 elftc_string_table_add_to_pool(Elftc_String_Table *st, const char *string) in elftc_string_table_add_to_pool() argument
107 len = strlen(string) + 1; /* length, including the trailing NUL */ in elftc_string_table_add_to_pool()
108 stlen = ELFTC_STRING_TABLE_LENGTH(st); in elftc_string_table_add_to_pool()
111 if (stlen + len >= st->st_string_pool_size) { in elftc_string_table_add_to_pool()
112 newsize = roundup(st->st_string_pool_size + in elftc_string_table_add_to_pool()
115 if ((newpool = realloc(st->st_string_pool, newsize)) == in elftc_string_table_add_to_pool()
118 st->st_string_pool = newpool; in elftc_string_table_add_to_pool()
119 st->st_string_pool_size = newsize; in elftc_string_table_add_to_pool()
122 memcpy(st->st_string_pool + stlen, string, len); in elftc_string_table_add_to_pool()
123 ELFTC_STRING_TABLE_UPDATE_LENGTH(st, stlen + len); in elftc_string_table_add_to_pool()
131 struct _Elftc_String_Table *st; in elftc_string_table_create() local
143 if ((st = malloc(tablesize)) == NULL) in elftc_string_table_create()
145 if ((st->st_string_pool = malloc(sizehint)) == NULL) { in elftc_string_table_create()
146 free(st); in elftc_string_table_create()
151 SLIST_INIT(&st->st_buckets[n]); in elftc_string_table_create()
153 st->st_len = 0; in elftc_string_table_create()
154 st->st_nbuckets = nbuckets; in elftc_string_table_create()
155 st->st_string_pool_size = sizehint; in elftc_string_table_create()
156 *st->st_string_pool = '\0'; in elftc_string_table_create()
157 ELFTC_STRING_TABLE_UPDATE_LENGTH(st, 1); in elftc_string_table_create()
159 return (st); in elftc_string_table_create()
163 elftc_string_table_destroy(Elftc_String_Table *st) in elftc_string_table_destroy() argument
168 for (n = 0; n < st->st_nbuckets; n++) in elftc_string_table_destroy()
169 SLIST_FOREACH_SAFE(s, &st->st_buckets[n], ste_next, t) in elftc_string_table_destroy()
171 free(st->st_string_pool); in elftc_string_table_destroy()
172 free(st); in elftc_string_table_destroy()
181 Elftc_String_Table *st; in elftc_string_table_from_section() local
197 if ((st = elftc_string_table_create(sizehint)) == NULL) in elftc_string_table_from_section()
216 for (s += 1; s < end; s += len) { in elftc_string_table_from_section()
217 if (elftc_string_table_insert(st, s) == 0) in elftc_string_table_from_section()
220 len = strlen(s) + 1; /* Include space for the trailing NUL. */ in elftc_string_table_from_section()
223 return (st); in elftc_string_table_from_section()
226 if (st) in elftc_string_table_from_section()
227 (void) elftc_string_table_destroy(st); in elftc_string_table_from_section()
233 elftc_string_table_image(Elftc_String_Table *st, size_t *size) in elftc_string_table_image() argument
246 if ((st->st_len & ELFTC_STRING_TABLE_COMPACTION_FLAG) == 0) { in elftc_string_table_image()
248 *size = ELFTC_STRING_TABLE_LENGTH(st); in elftc_string_table_image()
249 return (st->st_string_pool); in elftc_string_table_image()
255 assert(*st->st_string_pool == '\0'); in elftc_string_table_image()
257 newsize = 1; in elftc_string_table_image()
258 end = st->st_string_pool + ELFTC_STRING_TABLE_LENGTH(st); in elftc_string_table_image()
260 for (r = s = st->st_string_pool + 1; in elftc_string_table_image()
265 length = strlen(s) + 1; in elftc_string_table_image()
267 ste = elftc_string_table_find_hash_entry(st, s, in elftc_string_table_image()
269 head = &st->st_buckets[hashindex]; in elftc_string_table_image()
295 ELFTC_STRING_TABLE_CLEAR_COMPACTION_FLAG(st); in elftc_string_table_image()
296 ELFTC_STRING_TABLE_UPDATE_LENGTH(st, newsize); in elftc_string_table_image()
301 return (st->st_string_pool); in elftc_string_table_image()
305 elftc_string_table_insert(Elftc_String_Table *st, const char *string) in elftc_string_table_insert() argument
313 ste = elftc_string_table_find_hash_entry(st, string, &hashindex); in elftc_string_table_insert()
315 assert(hashindex >= 0 && hashindex < st->st_nbuckets); in elftc_string_table_insert()
320 if ((ste->ste_idx = elftc_string_table_add_to_pool(st, in elftc_string_table_insert()
326 SLIST_INSERT_HEAD(&st->st_buckets[hashindex], ste, ste_next); in elftc_string_table_insert()
337 elftc_string_table_lookup(Elftc_String_Table *st, const char *string) in elftc_string_table_lookup() argument
343 ste = elftc_string_table_find_hash_entry(st, string, &hashindex); in elftc_string_table_lookup()
345 assert(hashindex >= 0 && hashindex < st->st_nbuckets); in elftc_string_table_lookup()
354 elftc_string_table_remove(Elftc_String_Table *st, const char *string) in elftc_string_table_remove() argument
359 ste = elftc_string_table_find_hash_entry(st, string, NULL); in elftc_string_table_remove()
364 assert(idx > 0 && (size_t)idx < ELFTC_STRING_TABLE_LENGTH(st)); in elftc_string_table_remove()
368 ELFTC_STRING_TABLE_SET_COMPACTION_FLAG(st); in elftc_string_table_remove()
374 elftc_string_table_to_string(Elftc_String_Table *st, size_t offset) in elftc_string_table_to_string() argument
378 s = st->st_string_pool + offset; in elftc_string_table_to_string()
384 * - The end of the prior string at offset - 1. in elftc_string_table_to_string()
386 if (offset == 0 || offset >= ELFTC_STRING_TABLE_LENGTH(st) || in elftc_string_table_to_string()
387 *s == '\0' || *(s - 1) != '\0') { in elftc_string_table_to_string()