dp_rsp_t dp_rsp_create(dp_mgr_t dp, const char * name) { size_t nameLen; dp_rsp_t r; if (dp == NULL || name == NULL) return NULL; nameLen = strlen(name); r = (dp_rsp_t)mem_alloc(dp->m_alloc, sizeof(struct dp_rsp) + nameLen + 1); if (r == NULL) return NULL; r->m_dp = dp; r->m_name = (char*)(r + 1); r->m_name_len = nameLen; r->m_bindings = NULL; r->m_processor = NULL; r->m_type = NULL; r->m_context = NULL; cpe_hash_entry_init(&r->m_hh); memcpy((char*)r->m_name, name, nameLen + 1); if (cpe_hash_table_insert_unique(&dp->m_rsps, r) != 0) { mem_free(dp->m_alloc, r); return NULL; } return r; }
static dr_metalib_source_t dr_metalib_source_create( dr_metalib_builder_t builder, const char * name, size_t capacity, dr_metalib_source_type_t type, dr_metalib_source_format_t format, dr_metalib_source_from_t from) { char * buf; dr_metalib_source_t source; size_t name_len; assert(builder); name_len = strlen(name) + 1; buf = mem_alloc(builder->m_alloc, name_len + sizeof(struct dr_metalib_source) + capacity); if (buf == NULL) return NULL; memcpy(buf, name, name_len); source = (dr_metalib_source_t)(buf + name_len); source->m_builder = builder; source->m_name = buf; source->m_type = type; source->m_format = format; source->m_from = from; source->m_state = dr_metalib_source_state_not_analize; source->m_capacity = capacity; TAILQ_INIT(&source->m_includes); TAILQ_INIT(&source->m_include_by); TAILQ_INIT(&source->m_elements); cpe_hash_entry_init(&source->m_hh); if (cpe_hash_table_insert_unique(&builder->m_sources, source) != 0) { mem_free(builder->m_alloc, buf); return NULL; } TAILQ_INSERT_TAIL(&builder->m_sources_in_order, source, m_next); return source; }