Object provider_call(char *method, Array args) { Feature *f = pmap_get(cstr_t)(registered_providers, method); if (!f || !channel_exists(f->channel_id)) { char buf[256]; snprintf(buf, sizeof(buf), "Provider for method \"%s\" is not available", method); vim_report_error(cstr_as_string(buf)); api_free_array(args); return NIL; } Error err = ERROR_INIT; Object result = NIL = channel_send_call(f->channel_id, method, args, &err); if (err.set) { vim_report_error(cstr_as_string(err.msg)); api_free_object(result); return NIL; } return result; }
ir_entity *create_compilerlib_entity(ident *id, ir_type *mt) { ir_entity *entity = pmap_get(ir_entity, irp->compilerlib_entities, id); if (entity != NULL) return entity; /* let frontend mangle the name */ ident *ld_name = compilerlib_mangler(id, mt); /* search for an existing entity */ ir_type *glob = get_glob_type(); for (size_t i = 0, n_members = get_compound_n_members(glob); i < n_members; ++i) { ir_entity *member = get_compound_member(glob, i); if (get_entity_ld_ident(member) == ld_name) { entity = member; goto found; } } entity = new_entity(glob, id, mt); set_entity_ld_ident(entity, ld_name); set_entity_visibility(entity, ir_visibility_external); found: pmap_insert(irp->compilerlib_entities, id, entity); return entity; }
void remote_ui_init(void) { connected_uis = pmap_new(uint64_t)(); // Add handler for "attach_ui" String method = cstr_as_string("ui_attach"); MsgpackRpcRequestHandler handler = {.fn = remote_ui_attach, .defer = false}; msgpack_rpc_add_method_handler(method, handler); method = cstr_as_string("ui_detach"); handler.fn = remote_ui_detach; msgpack_rpc_add_method_handler(method, handler); method = cstr_as_string("ui_try_resize"); handler.fn = remote_ui_try_resize; msgpack_rpc_add_method_handler(method, handler); } void remote_ui_disconnect(uint64_t channel_id) { UI *ui = pmap_get(uint64_t)(connected_uis, channel_id); if (!ui) { return; } UIData *data = ui->data; // destroy pending screen updates api_free_array(data->buffer); pmap_del(uint64_t)(connected_uis, channel_id); xfree(ui->data); ui_detach(ui); xfree(ui); }
static ir_entity *get_pic_symbol(be_main_env_t *env, ir_entity *entity) { ir_entity *result = pmap_get(ir_entity, env->ent_pic_symbol_map, entity); if (result == NULL) { result = create_pic_symbol(env, entity); pmap_insert(env->ent_pic_symbol_map, entity, result); } return result; }
/** * Returns the trampoline entity for the given method. */ static ir_entity *get_trampoline(be_main_env_t *env, ir_entity *method) { ir_entity *result = pmap_get(ir_entity, env->ent_trampoline_map, method); if (result == NULL) { result = create_trampoline(env, method); pmap_insert(env->ent_trampoline_map, method, result); } return result; }
/** * @return The lowered method type. */ static ir_type *lower_method_type(ir_type *mtp) { ir_type *res = pmap_get(ir_type, lowered_type, mtp); if (res != NULL) return res; size_t const n_param = get_method_n_params(mtp); size_t const n_res = get_method_n_ress(mtp); bool const is_variadic = is_method_variadic(mtp); res = new_type_method(n_param, n_res, is_variadic); /* set param types and result types */ for (size_t i = 0; i < n_param; ++i) { ir_type *ptp = get_method_param_type(mtp, i); ir_mode *pmode = get_type_mode(ptp); if (pmode != NULL && mode_is_float(pmode)) { ptp = lower_type(ptp); } set_method_param_type(res, i, ptp); } for (size_t i = 0; i < n_res; ++i) { ir_type *rtp = get_method_res_type(mtp, i); ir_mode *rmode = get_type_mode(rtp); if (rmode != NULL && mode_is_float(rmode)) { rtp = lower_type(rtp); } set_method_res_type(res, i, rtp); } copy_method_properties(res, mtp); set_higher_type(res, mtp); pmap_insert(lowered_type, mtp, res); return res; }
static Object remote_ui_try_resize(uint64_t channel_id, uint64_t request_id, Array args, Error *error) { if (!pmap_has(uint64_t)(connected_uis, channel_id)) { api_set_error(error, Exception, _("UI is not attached for channel")); } if (args.size != 2 || args.items[0].type != kObjectTypeInteger || args.items[1].type != kObjectTypeInteger || args.items[0].data.integer <= 0 || args.items[1].data.integer <= 0) { api_set_error(error, Validation, _("Invalid arguments. Expected: " "(uint width > 0, uint height > 0)")); return NIL; } UI *ui = pmap_get(uint64_t)(connected_uis, channel_id); ui->width = (int)args.items[0].data.integer; ui->height = (int)args.items[1].data.integer; ui_refresh(); return NIL; }
ir_cdep *find_cdep(const ir_node *block) { assert(is_Block(block)); return pmap_get(ir_cdep, cdep_data->cdep_map, block); }
int main(void) { pmap_rec_t *d; char *fake; int32_t i; int32_t k0, k1; init_pmap(&map, 4); printf("\n*** Initial map ***\n"); print_map(&map); // add 9 records fake = (char *) 0xabc00000; for (i=0; i<9; i++) { k0 = i+1; k1 = 10-i; d = pmap_get(&map, k0, k1); if (d->val == DEFAULT_PTR) { d->val = fake; printf("added new record %p: [k0 = %"PRId32", k1 = %"PRId32", val = %p]\n", d, k0, k1, d->val); } else { printf("found record %p: [k0 = %"PRId32", k1 = %"PRId32", val = %p]\n", d, k0, k1, d->val); } fake += 0x20; } printf("\n*** Map ***\n"); print_map(&map); // search for (i=0; i<20; i++) { k0 = i + 1; k1 = 10 - i; printf("searching: [k0 = %"PRId32", k1 = %"PRId32"]: ", k0, k1); fflush(stdout); d = pmap_find(&map, k0, k1); if (d == NULL) { printf("not found\n"); } else { printf("found: val = %p\n", d->val); } } // erase some records; for (i=0; i<9; i+=3) { k0 = i+1; k1 = 10-i; d = pmap_find(&map, k0, k1); if (d != NULL) { printf("erasing record %p: [k0 = %"PRId32", k1 = %"PRId32"]\n", d, k0, k1); pmap_erase(&map, d); } else { printf("*** BUG ***\n"); } } printf("\n*** Map after deletion ***\n"); print_map(&map); // search for (i=0; i<9; i++) { k0 = i + 1; k1 = 10 - i; printf("searching: [k0 = %"PRId32", k1 = %"PRId32"]: ", k0, k1); fflush(stdout); d = pmap_find(&map, k0, k1); if (d == NULL) { printf("not found\n"); } else { printf("found: val = %p\n", d->val); } } pmap_reset(&map); printf("\n*** Map after reset ***\n"); print_map(&map); delete_pmap(&map); return 0; }