ph_variant_t *ph_var_object(uint32_t nelems) { ph_variant_t *var; ph_result_t res; var = ph_mem_alloc(mt.var); if (!var) { return NULL; } var->ref = 1; var->type = PH_VAR_OBJECT; res = ph_ht_init(&var->u.oval, nelems, &ph_ht_string_key_def, &var_val_def); if (res != PH_OK) { ph_mem_free(mt.var, var); return 0; } return var; }
static ph_dns_channel_t *create_chan(void) { ph_dns_channel_t *chan; struct ares_options opts; int res; pthread_mutexattr_t attr; chan = ph_mem_alloc(mt.chan); if (!chan) { return NULL; } pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&chan->chanlock, &attr); pthread_mutexattr_destroy(&attr); if (ph_ht_init(&chan->sock_map, 4, &sock_key, &ph_ht_ptr_val_def) != PH_OK) { ph_panic("failed to init sock map"); } memset(&opts, 0, sizeof(opts)); opts.sock_state_cb_data = chan; opts.sock_state_cb = sock_state_cb; opts.flags = ARES_FLAG_STAYOPEN; res = ares_init_options(&chan->chan, &opts, ARES_OPT_SOCK_STATE_CB|ARES_OPT_FLAGS); if (res != ARES_SUCCESS) { ph_panic("failed to ares_init_options: %s", ares_strerror(res)); } ares_set_socket_callback(chan->chan, sock_create_cb, chan); return chan; }
static void do_hook_init(void) { ph_memtype_register_block(sizeof(defs)/sizeof(defs[0]), defs, &mt.hookpoint); ph_ht_init(&hook_hash, 32, &ph_ht_string_key_def, &hookpoint_def); }
static void init_vprintf(void) { pthread_rwlock_init(&formatter_lock, NULL); ph_ht_init(&formatters, 4, &ph_ht_string_key_def, &val_def); atexit(fini_vprintf); }