static void test_strpool(void *p) { struct StrPool *pool; struct PStr *s; pool = strpool_create(NULL); tt_assert(pool); strpool_free(pool); pool = strpool_create(NULL); tt_assert(pool); int_check(strpool_total(pool), 0); s = strpool_get(pool, "foo", -1); str_check(s->str, "foo"); int_check(s->refcnt, 1); int_check(s->len, 3); int_check(strpool_total(pool), 1); tt_assert(s == strpool_get(pool, "fooTAIL", 3)); int_check(s->refcnt, 2); int_check(strpool_total(pool), 1); strpool_incref(s); int_check(s->refcnt, 3); strpool_decref(s); int_check(s->refcnt, 2); strpool_decref(s); int_check(s->refcnt, 1); int_check(strpool_total(pool), 1); strpool_decref(s); int_check(strpool_total(pool), 0); strpool_free(pool); /* free strc with strings */ pool = strpool_create(NULL); tt_assert(pool); s = strpool_get(pool, "foo", -1); s = strpool_get(pool, "bar", 3); int_check(strpool_total(pool), 2); strpool_free(pool); end:; }
/*{{{ ProfTab * proftab_create(BIT32 version, etc. */ ProfTab *proftab_create (ProfTabContents contents, void *alloc_fn (size_t size, void *user_data), void free_fn (void *block, size_t size, void *user_data), void *user_data) { ProfTab *table = (ProfTab *) alloc_fn (sizeof (ProfTab), user_data); table->alloc_fn = alloc_fn; table->free_fn = free_fn; table->user_data = user_data; table->contents = contents; table->count_table_size = 0; table->strpool = strpool_create (PROFTAB_INITIAL_STRPOOL_SIZE, PROFTAB_STRPOOL_SIZE_INCREMENT, alloc_fn, free_fn, user_data); table->entry_list_head = NULL; table->entry_list_tail = NULL; if (cgraph_profiling || sampling_profiling) { int i; RoutineInfoEntry **hash_table; table->rout_hash_table = memalloc (ROUTINE_INFO_HASH_TABLE_SIZE * sizeof (table->rout_hash_table)); hash_table = table->rout_hash_table; for (i = 0; i < ROUTINE_INFO_HASH_TABLE_SIZE; i++) hash_table[i] = NULL; } else table->rout_hash_table = NULL; return table; }