int pat_put(const char *path) { int i; grn_obj buf; grn_pat *pat = grn_pat_create(&ctx, path, key_size, value_size, GRN_OBJ_PERSISTENT|GRN_OBJ_KEY_VAR_SIZE); if (!pat) { return -1; } GRN_TEXT_INIT(&buf, 0); for (i = 0; i < nloops; i++) { int key = GENKEY(i); GRN_BULK_REWIND(&buf); grn_text_itoh(&ctx, &buf, key, key_size); { void *value; grn_id rid = grn_pat_add(&ctx, pat, GRN_BULK_HEAD(&buf), key_size, &value, NULL); if (!rid) { fprintf(stderr, "table_lookup failed"); } else { memcpy(value, GRN_BULK_HEAD(&buf), value_size); } } } grn_obj_close(&ctx, &buf); grn_pat_close(&ctx, pat); return 0; }
static grn_rc grn_ctx_impl_init(grn_ctx *ctx) { grn_io_mapinfo mi; if (!(ctx->impl = grn_io_anon_map(ctx, &mi, IMPL_SIZE))) { return ctx->rc; } grn_alloc_init_ctx_impl(ctx); ctx->impl->encoding = ctx->encoding; ctx->impl->lifoseg = -1; ctx->impl->currseg = -1; CRITICAL_SECTION_INIT(ctx->impl->lock); if (!(ctx->impl->values = grn_array_create(ctx, NULL, sizeof(grn_db_obj *), GRN_ARRAY_TINY))) { CRITICAL_SECTION_FIN(ctx->impl->lock); grn_io_anon_unmap(ctx, &mi, IMPL_SIZE); ctx->impl = NULL; return ctx->rc; } if (!(ctx->impl->temporary_columns = grn_pat_create(ctx, NULL, GRN_TABLE_MAX_KEY_SIZE, sizeof(grn_obj *), 0))) { grn_array_close(ctx, ctx->impl->values); CRITICAL_SECTION_FIN(ctx->impl->lock); grn_io_anon_unmap(ctx, &mi, IMPL_SIZE); ctx->impl = NULL; return ctx->rc; } if (!(ctx->impl->ios = grn_hash_create(ctx, NULL, GRN_TABLE_MAX_KEY_SIZE, sizeof(grn_io *), GRN_OBJ_KEY_VAR_SIZE|GRN_HASH_TINY))) { grn_array_close(ctx, ctx->impl->values); grn_pat_close(ctx, ctx->impl->temporary_columns); CRITICAL_SECTION_FIN(ctx->impl->lock); grn_io_anon_unmap(ctx, &mi, IMPL_SIZE); ctx->impl = NULL; return ctx->rc; } ctx->impl->db = NULL; ctx->impl->expr_vars = grn_hash_create(ctx, NULL, sizeof(grn_id), sizeof(grn_obj *), 0); ctx->impl->stack_curr = 0; ctx->impl->curr_expr = NULL; ctx->impl->qe_next = NULL; GRN_TEXT_INIT(&ctx->impl->current_request_id, 0); ctx->impl->current_request_timer_id = NULL; ctx->impl->parser = NULL; GRN_TEXT_INIT(&ctx->impl->output.names, GRN_OBJ_VECTOR); GRN_UINT32_INIT(&ctx->impl->output.levels, GRN_OBJ_VECTOR); if (ctx == &grn_gctx) { ctx->impl->command_version = GRN_COMMAND_VERSION_STABLE; } else { ctx->impl->command_version = grn_get_default_command_version(); } if (ctx == &grn_gctx) { ctx->impl->match_escalation_threshold = GRN_DEFAULT_MATCH_ESCALATION_THRESHOLD; } else { ctx->impl->match_escalation_threshold = grn_get_default_match_escalation_threshold(); } ctx->impl->finalizer = NULL; ctx->impl->com = NULL; ctx->impl->output.buf = grn_obj_open(ctx, GRN_BULK, 0, GRN_DB_TEXT); ctx->impl->output.func = NULL; ctx->impl->output.data.ptr = NULL; #ifdef GRN_WITH_MESSAGE_PACK msgpack_packer_init(&ctx->impl->output.msgpacker, ctx, grn_msgpack_buffer_write); #endif ctx->impl->tv.tv_sec = 0; ctx->impl->tv.tv_nsec = 0; ctx->impl->edge = NULL; grn_loader_init(&ctx->impl->loader); ctx->impl->plugin_path = NULL; GRN_TEXT_INIT(&ctx->impl->query_log_buf, 0); ctx->impl->previous_errbuf[0] = '\0'; ctx->impl->n_same_error_messages = 0; grn_ctx_impl_mrb_init(ctx); return ctx->rc; }