void test_fix_size_set_value_increment(void) { gint32 count = 29; gint32 increment_count = 5; gint32 retrieved_count; grn_obj *record_value; grn_obj *retrieved_record_value; record_value = grn_obj_open(context, GRN_BULK, 0, GRN_DB_INT32); grn_bulk_write(context, record_value, (const char *)&count, sizeof(count)); grn_test_assert(grn_obj_set_value(context, count_column, groonga_bookmark_id, record_value, GRN_OBJ_SET)); grn_obj_close(context, record_value); record_value = grn_obj_open(context, GRN_BULK, 0, GRN_DB_INT32); grn_bulk_write(context, record_value, (const char *)&increment_count, sizeof(increment_count)); grn_test_assert(grn_obj_set_value(context, count_column, groonga_bookmark_id, record_value, GRN_OBJ_INCR)); grn_obj_close(context, record_value); retrieved_record_value = grn_obj_get_value(context, count_column, groonga_bookmark_id, NULL); memcpy(&retrieved_count, GRN_BULK_HEAD(retrieved_record_value), GRN_BULK_VSIZE(retrieved_record_value)); cut_assert_equal_int(count + increment_count, retrieved_count); grn_obj_close(context, retrieved_record_value); }
int table_put_allocate(void) { int i; grn_obj *buf; grn_obj *key_type = grn_ctx_at(&ctx, GRN_DB_SHORT_TEXT); grn_obj *table = grn_table_create(&ctx, "<t1>", 4, NULL, GRN_OBJ_TABLE_HASH_KEY|GRN_OBJ_PERSISTENT, key_type, value_type); if (!table) { return -1; } for (i = 0; i < nloops; i++) { int key = GENKEY(i); buf = grn_obj_open(&ctx, GRN_BULK, 0, 0); grn_text_itoh(&ctx, buf, key, key_size); { grn_id rid = grn_table_add(&ctx, table, GRN_BULK_HEAD(buf), key_size, NULL); if (!rid) { fprintf(stderr, "table_lookup failed"); } else { grn_obj *value_buf; value_buf = grn_obj_open(&ctx, GRN_BULK, 0, 0); grn_text_itoh(&ctx, value_buf, key, key_size); if (grn_obj_set_value(&ctx, table, rid, value_buf, GRN_OBJ_SET)) { fprintf(stderr, "grn_obj_set_value failed"); } grn_obj_close(&ctx, value_buf); } } grn_obj_close(&ctx, buf); } return 0; }
grn_obj * rb_grn_vector_from_ruby_object (VALUE object, grn_ctx *context, grn_obj *vector) { VALUE *values; grn_obj value; int i, n; if (vector) GRN_OBJ_INIT(vector, GRN_VECTOR, 0, GRN_ID_NIL); else vector = grn_obj_open(context, GRN_VECTOR, 0, 0); if (NIL_P(object)) return vector; GRN_VOID_INIT(&value); n = RARRAY_LEN(object); values = RARRAY_PTR(object); for (i = 0; i < n; i++) { grn_obj *_value = &value; RVAL2GRNOBJ(values[i], context, &_value); grn_vector_add_element(context, vector, GRN_BULK_HEAD(&value), GRN_BULK_VSIZE(&value), 0, value.header.domain); } GRN_OBJ_FIN(context, &value); return vector; }
void rb_grn_variable_size_column_bind (RbGrnVariableSizeColumn *rb_column, grn_ctx *context, grn_obj *column) { RbGrnObject *rb_grn_object; int column_type; unsigned char value_type; rb_grn_object = RB_GRN_OBJECT(rb_column); rb_grn_column_bind(RB_GRN_COLUMN(rb_column), context, column); rb_column->element_value = NULL; column_type = (column->header.flags & GRN_OBJ_COLUMN_TYPE_MASK); if (column_type != GRN_OBJ_COLUMN_VECTOR) { return; } switch (rb_grn_object->range->header.type) { case GRN_TABLE_HASH_KEY: case GRN_TABLE_PAT_KEY: case GRN_TABLE_DAT_KEY: case GRN_TABLE_NO_KEY: value_type = GRN_UVECTOR; break; default: value_type = GRN_VECTOR; break; } if (column->header.flags & GRN_OBJ_WITH_WEIGHT) { rb_column->element_value = grn_obj_open(context, value_type, 0, rb_grn_object->range_id); } }
grn_obj * rb_grn_value_from_ruby_object (VALUE object, grn_ctx *context, grn_obj *value, grn_id type_id, grn_obj *type) { grn_bool string_p, table_type_p; string_p = rb_type(object) == T_STRING; table_type_p = (GRN_TABLE_HASH_KEY <= type->header.type && type->header.type <= GRN_TABLE_NO_KEY); if (!string_p) { return RVAL2GRNBULK_WITH_TYPE(object, context, value, type_id, type); } if (table_type_p && RSTRING_LEN(object) == 0) { if (value) { if (value->header.domain != type_id) { grn_obj_reinit(context, value, type_id, 0); } } else { value = grn_obj_open(context, GRN_BULK, 0, type_id); rb_grn_context_check(context, object); } GRN_RECORD_SET(context, value, GRN_ID_NIL); return value; } return RVAL2GRNBULK(object, context, value); }
void test_array_set_data(void) { grn_obj *table; grn_id record_id; gchar value[] = "sample value"; grn_obj *record_value; grn_obj *retrieved_record_value; const gchar *dupped_retrieved_record_value; const gchar *value_type_name = "value_type"; grn_obj *value_type; value_type = grn_type_create(context, value_type_name, strlen(value_type_name), 0, sizeof(value)); table = grn_table_create(context, NULL, 0, NULL, GRN_OBJ_TABLE_NO_KEY, NULL, value_type); record_id = grn_table_add(context, table, NULL, 0, NULL); record_value = grn_obj_open(context, GRN_BULK, 0, GRN_DB_TEXT); grn_bulk_write(context, record_value, value, sizeof(value)); grn_test_assert(grn_obj_set_value(context, table, record_id, record_value, GRN_OBJ_SET)); grn_obj_unlink(context, record_value); retrieved_record_value = grn_obj_get_value(context, table, record_id, NULL); dupped_retrieved_record_value = cut_take_strdup(GRN_BULK_HEAD(retrieved_record_value)); grn_obj_unlink(context, retrieved_record_value); cut_assert_equal_string(value, dupped_retrieved_record_value); }
void rb_grn_index_column_bind (RbGrnIndexColumn *rb_grn_index_column, grn_ctx *context, grn_obj *column) { RbGrnObject *rb_grn_object; rb_grn_column_bind(RB_GRN_COLUMN(rb_grn_index_column), context, column); rb_grn_object = RB_GRN_OBJECT(rb_grn_index_column); rb_grn_index_column->old_value = grn_obj_open(context, GRN_BULK, 0, rb_grn_object->range_id); rb_grn_index_column->id_query = grn_obj_open(context, GRN_BULK, 0, rb_grn_object->domain_id); rb_grn_index_column->string_query = grn_obj_open(context, GRN_BULK, GRN_OBJ_DO_SHALLOW_COPY, GRN_DB_SHORT_TEXT); }
static grn_obj * text_geo_point_open(double latitude, double longitude) { grn_obj *point; point = grn_obj_open(context, GRN_BULK, 0, GRN_DB_SHORT_TEXT); GRN_TEXT_PUTS(context, point, cut_take_printf("%f,%f", latitude, longitude)); return point; }
static void grn_ctx_impl_init(grn_ctx *ctx) { if (!(ctx->impl = GRN_MALLOC(sizeof(struct _grn_ctx_impl)))) { return; } if (!(ctx->impl->segs = grn_io_anon_map(ctx, &ctx->impl->mi, sizeof(grn_io_mapinfo) * N_SEGMENTS))) { GRN_FREE(ctx->impl); ctx->impl = NULL; return; } #ifdef USE_DYNAMIC_MALLOC_CHANGE grn_ctx_impl_init_malloc(ctx); #endif if (!(ctx->impl->values = grn_array_create(ctx, NULL, sizeof(grn_tmp_db_obj), GRN_ARRAY_TINY))) { grn_io_anon_unmap(ctx, &ctx->impl->mi, sizeof(grn_io_mapinfo) * N_SEGMENTS); GRN_FREE(ctx->impl); ctx->impl = NULL; return; } ctx->impl->encoding = ctx->encoding; ctx->impl->lifoseg = -1; ctx->impl->currseg = -1; ctx->impl->db = NULL; ctx->impl->qe = grn_hash_create(ctx, NULL, sizeof(grn_id), sizeof(void *), 0); ctx->impl->stack_curr = 0; ctx->impl->phs = NIL; ctx->impl->code = NIL; ctx->impl->dump = NIL; ctx->impl->op = GRN_OP_T0LVL; ctx->impl->args = NIL; ctx->impl->envir = NIL; ctx->impl->value = NIL; ctx->impl->ncells = 0; ctx->impl->n_entries = 0; ctx->impl->seqno = 0; ctx->impl->lseqno = 0; ctx->impl->nbinds = 0; ctx->impl->nunbinds = 0; ctx->impl->feed_mode = grn_ql_atonce; ctx->impl->cur = NULL; ctx->impl->str_end = NULL; ctx->impl->batchmode = 0; ctx->impl->gc_verbose = 0; ctx->impl->inbuf = NULL; ctx->impl->co.mode = 0; ctx->impl->co.func = NULL; ctx->impl->objects = NULL; ctx->impl->symbols = NULL; ctx->impl->com = NULL; ctx->impl->outbuf = grn_obj_open(ctx, GRN_BULK, 0, 0); GRN_TEXT_INIT(&ctx->impl->subbuf, 0); }
void rb_grn_expression_bind (RbGrnExpression *rb_grn_expression, grn_ctx *context, grn_obj *expression) { RbGrnObject *rb_grn_object; rb_grn_object = RB_GRN_OBJECT(rb_grn_expression); rb_grn_expression->value = grn_obj_open(context, GRN_BULK, 0, rb_grn_object->range_id); }
void rb_grn_column_bind (RbGrnColumn *rb_column, grn_ctx *context, grn_obj *column) { RbGrnObject *rb_grn_object; rb_grn_object = RB_GRN_OBJECT(rb_column); rb_grn_named_object_bind(RB_GRN_NAMED_OBJECT(rb_column), context, column); rb_column->value = grn_obj_open(context, GRN_BULK, 0, rb_grn_object->range_id); }
void cut_setup(void) { remove_tmp_directory(); g_mkdir_with_parents(tmp_directory, 0700); context = g_new0(grn_ctx, 1); grn_ctx_init(context, 0); ja = grn_ja_create(context, NULL, 65536, 0); vector = grn_obj_open(context, GRN_BULK, GRN_OBJ_VECTOR, GRN_DB_VOID); }
static grn_obj * wgs84_geo_point_open(double latitude, double longitude) { grn_obj *point, *point_text; point_text = text_geo_point_open(latitude, longitude); point = grn_obj_open(context, GRN_BULK, 0, GRN_DB_WGS84_GEO_POINT); grn_obj_cast(context, point_text, point, GRN_FALSE); grn_obj_unlink(context, point_text); return point; }
static void bench_setup_points(gpointer user_data, const gchar *start_point_string, const gchar *end_point_string, grn_builtin_type wgs84_or_tgs) { BenchmarkData *data = user_data; grn_obj start_point_text, end_point_text; GRN_TEXT_INIT(&start_point_text, 0); GRN_TEXT_INIT(&end_point_text, 0); GRN_TEXT_SETS(data->context, &start_point_text, start_point_string); GRN_TEXT_SETS(data->context, &end_point_text, end_point_string); data->start_point = grn_obj_open(data->context, GRN_BULK, 0, wgs84_or_tgs); data->end_point = grn_obj_open(data->context, GRN_BULK, 0, wgs84_or_tgs); grn_obj_cast(data->context, &start_point_text, data->start_point, GRN_FALSE); grn_obj_cast(data->context, &end_point_text, data->end_point, GRN_FALSE); grn_ctx_push(data->context, data->start_point); grn_ctx_push(data->context, data->end_point); grn_obj_unlink(data->context, &start_point_text); grn_obj_unlink(data->context, &end_point_text); }
void rb_grn_table_key_support_bind (RbGrnTableKeySupport *rb_grn_table_key_support, grn_ctx *context, grn_obj *table_key_support) { RbGrnObject *rb_grn_object; RbGrnTable *rb_grn_table; rb_grn_object = RB_GRN_OBJECT(rb_grn_table_key_support); rb_grn_table = RB_GRN_TABLE(rb_grn_table_key_support); rb_grn_table_bind(rb_grn_table, context, table_key_support); rb_grn_table_key_support->key = grn_obj_open(context, GRN_BULK, 0, rb_grn_object->domain_id); }
void rb_grn_double_array_trie_bind (RbGrnDoubleArrayTrie *rb_grn_double_array_trie, grn_ctx *context, grn_obj *double_array_trie) { RbGrnObject *rb_grn_object; RbGrnTableKeySupport *rb_grn_table_key_support; rb_grn_object = RB_GRN_OBJECT(rb_grn_double_array_trie); rb_grn_table_key_support = RB_GRN_TABLE_KEY_SUPPORT(rb_grn_double_array_trie); rb_grn_table_key_support_bind(rb_grn_table_key_support, context, double_array_trie); rb_grn_double_array_trie->new_key = grn_obj_open(context, GRN_BULK, 0, rb_grn_object->domain_id); }
grn_obj * rb_grn_bulk_from_ruby_object_with_type (VALUE object, grn_ctx *context, grn_obj *bulk, grn_id type_id, grn_obj *type) { const char *string; unsigned int size; union { int8_t int8_value; uint8_t uint8_value; int16_t int16_value; uint16_t uint16_value; int32_t int32_value; uint32_t uint32_value; int64_t int64_value; uint64_t uint64_value; int64_t time_value; double double_value; grn_geo_point geo_point_value; grn_id record_id; } value; grn_id range; VALUE rb_type_object; grn_obj_flags flags = 0; grn_bool string_p, table_type_p; string_p = rb_type(object) == T_STRING; table_type_p = (GRN_TABLE_HASH_KEY <= type->header.type && type->header.type <= GRN_TABLE_NO_KEY); switch (type_id) { case GRN_DB_INT8: value.int8_value = NUM2SHORT(object); string = (const char *)&(value.int8_value); size = sizeof(value.int8_value); break; case GRN_DB_UINT8: value.uint8_value = NUM2USHORT(object); string = (const char *)&(value.uint8_value); size = sizeof(value.uint8_value); break; case GRN_DB_INT16: value.int16_value = NUM2SHORT(object); string = (const char *)&(value.int16_value); size = sizeof(value.int16_value); break; case GRN_DB_UINT16: value.uint16_value = NUM2USHORT(object); string = (const char *)&(value.uint16_value); size = sizeof(value.uint16_value); break; case GRN_DB_INT32: value.int32_value = NUM2INT(object); string = (const char *)&(value.int32_value); size = sizeof(value.int32_value); break; case GRN_DB_UINT32: value.uint32_value = NUM2UINT(object); string = (const char *)&(value.uint32_value); size = sizeof(value.uint32_value); break; case GRN_DB_INT64: value.int64_value = NUM2LL(object); string = (const char *)&(value.int64_value); size = sizeof(value.int64_value); break; case GRN_DB_UINT64: value.uint64_value = NUM2ULL(object); string = (const char *)&(value.uint64_value); size = sizeof(value.uint64_value); break; case GRN_DB_FLOAT: value.double_value = NUM2DBL(object); string = (const char *)&(value.double_value); size = sizeof(value.double_value); break; case GRN_DB_TIME: { VALUE rb_sec, rb_usec; int64_t sec; int32_t usec; if (string_p) { ID id_parse; CONST_ID(id_parse, "parse"); object = rb_funcall(rb_cTime, id_parse, 1, object); } switch (TYPE(object)) { case T_FIXNUM: case T_BIGNUM: sec = NUM2LL(object); usec = 0; break; case T_FLOAT: rb_sec = rb_funcall(object, rb_intern("to_i"), 0); rb_usec = rb_funcall(object, rb_intern("remainder"), 1, INT2NUM(1)); sec = NUM2LL(rb_sec); usec = (int32_t)(NUM2DBL(rb_usec) * 1000000); break; case T_NIL: sec = 0; usec = 0; break; default: sec = NUM2LL(rb_funcall(object, rb_intern("to_i"), 0)); usec = NUM2INT(rb_funcall(object, rb_intern("usec"), 0)); break; } value.time_value = GRN_TIME_PACK(sec, usec); string = (const char *)&(value.time_value); size = sizeof(value.time_value); break; } case GRN_DB_SHORT_TEXT: case GRN_DB_TEXT: case GRN_DB_LONG_TEXT: string = StringValuePtr(object); size = RSTRING_LEN(object); range = grn_obj_get_range(context, type); if (size > range) rb_raise(rb_eArgError, "string is too large: expected: %u <= %u", size, range); flags |= GRN_OBJ_DO_SHALLOW_COPY; break; case GRN_DB_TOKYO_GEO_POINT: case GRN_DB_WGS84_GEO_POINT: { VALUE rb_geo_point; VALUE rb_latitude, rb_longitude; if (type_id == GRN_DB_TOKYO_GEO_POINT) { rb_geo_point = rb_funcall(rb_cGrnTokyoGeoPoint, rb_intern("new"), 1, object); } else { rb_geo_point = rb_funcall(rb_cGrnWGS84GeoPoint, rb_intern("new"), 1, object); } rb_geo_point = rb_funcall(rb_geo_point, rb_intern("to_msec"), 0); rb_latitude = rb_funcall(rb_geo_point, rb_intern("latitude"), 0); rb_longitude = rb_funcall(rb_geo_point, rb_intern("longitude"), 0); value.geo_point_value.latitude = NUM2INT(rb_latitude); value.geo_point_value.longitude = NUM2INT(rb_longitude); string = (const char *)&(value.geo_point_value); size = sizeof(value.geo_point_value); break; } case GRN_DB_VOID: case GRN_DB_DELIMIT: case GRN_DB_UNIGRAM: case GRN_DB_BIGRAM: case GRN_DB_TRIGRAM: case GRN_DB_MECAB: rb_type_object = GRNOBJECT2RVAL(Qnil, context, type, GRN_FALSE); rb_raise(rb_eArgError, "unbulkable type: %s", rb_grn_inspect(rb_type_object)); break; default: if (table_type_p && (NIL_P(object) || (string_p && RSTRING_LEN(object) == 0))) { value.record_id = GRN_ID_NIL; string = (const char *)&(value.record_id); size = sizeof(value.record_id); if (bulk && bulk->header.domain != type_id) { grn_obj_reinit(context, bulk, type_id, 0); } } else { return RVAL2GRNBULK(object, context, bulk); } break; } if (!bulk) { bulk = grn_obj_open(context, GRN_BULK, flags, GRN_ID_NIL); rb_grn_context_check(context, object); } GRN_TEXT_SET(context, bulk, string, size); return bulk; }
grn_obj * rb_grn_bulk_from_ruby_object (VALUE object, grn_ctx *context, grn_obj *bulk) { if (bulk && bulk->header.domain == GRN_DB_TIME) return RVAL2GRNBULK_WITH_TYPE(object, context, bulk, bulk->header.domain, grn_ctx_at(context, bulk->header.domain)); if (!bulk) { bulk = grn_obj_open(context, GRN_BULK, 0, GRN_ID_NIL); rb_grn_context_check(context, object); } switch (TYPE(object)) { case T_NIL: grn_obj_reinit(context, bulk, GRN_DB_VOID, 0); break; case T_SYMBOL: object = rb_funcall(object, rb_intern("to_s"), 0); case T_STRING: grn_obj_reinit(context, bulk, GRN_DB_TEXT, 0); rb_grn_context_text_set(context, bulk, object); break; case T_FIXNUM: case T_BIGNUM: { int64_t int64_value; int64_value = NUM2LL(object); if (int64_value <= INT32_MAX) { grn_obj_reinit(context, bulk, GRN_DB_INT32, 0); GRN_INT32_SET(context, bulk, int64_value); } else { grn_obj_reinit(context, bulk, GRN_DB_INT64, 0); GRN_INT64_SET(context, bulk, int64_value); } break; } case T_FLOAT: grn_obj_reinit(context, bulk, GRN_DB_FLOAT, 0); GRN_FLOAT_SET(context, bulk, NUM2DBL(object)); break; case T_TRUE: grn_obj_reinit(context, bulk, GRN_DB_BOOL, 0); GRN_BOOL_SET(context, bulk, GRN_TRUE); break; case T_FALSE: grn_obj_reinit(context, bulk, GRN_DB_BOOL, 0); GRN_BOOL_SET(context, bulk, GRN_FALSE); break; default: if (RVAL2CBOOL(rb_obj_is_kind_of(object, rb_cTime))) { VALUE sec, usec; int64_t time_value; sec = rb_funcall(object, rb_intern("to_i"), 0); usec = rb_funcall(object, rb_intern("usec"), 0); time_value = GRN_TIME_PACK(NUM2LL(sec), NUM2LL(usec)); grn_obj_reinit(context, bulk, GRN_DB_TIME, 0); GRN_TIME_SET(context, bulk, time_value); } else if (RVAL2CBOOL(rb_obj_is_kind_of(object, rb_cGrnObject))) { grn_obj *grn_object; grn_id id_value; grn_object = RVAL2GRNOBJECT(object, &context); grn_obj_reinit(context, bulk, grn_object->header.domain, 0); id_value = grn_obj_id(context, grn_object); GRN_RECORD_SET(context, bulk, id_value); } else if (RVAL2CBOOL(rb_obj_is_kind_of(object, rb_cGrnRecord))) { grn_obj *table; grn_id id_value; table = RVAL2GRNOBJECT(rb_funcall(object, rb_intern("table"), 0), &context); id_value = NUM2UINT(rb_funcall(object, rb_intern("id"), 0)); grn_obj_reinit(context, bulk, grn_obj_id(context, table), 0); GRN_RECORD_SET(context, bulk, id_value); } else { rb_raise(rb_eTypeError, "bulked object should be one of " "[nil, true, false, String, Symbol, Integer, Float, Time, " "Groonga::Object, Groonga::Record]: %s", rb_grn_inspect(object)); } break; } return bulk; }
grn_obj * rb_grn_bulk_from_ruby_object_with_type (VALUE object, grn_ctx *context, grn_obj *bulk, grn_id type_id, grn_obj *type) { const char *string; unsigned int size; int32_t int32_value; uint32_t uint32_value; int64_t int64_value; uint64_t uint64_value; int64_t time_value; double double_value; grn_id record_id, range; VALUE rb_type_object; grn_obj_flags flags = 0; grn_bool string_p, table_type_p; string_p = rb_type(object) == T_STRING; table_type_p = (GRN_TABLE_HASH_KEY <= type->header.type && type->header.type <= GRN_TABLE_VIEW); if (string_p && !table_type_p) { return RVAL2GRNBULK(object, context, bulk); } switch (type_id) { case GRN_DB_INT32: int32_value = NUM2INT(object); string = (const char *)&int32_value; size = sizeof(int32_value); break; case GRN_DB_UINT32: uint32_value = NUM2UINT(object); string = (const char *)&uint32_value; size = sizeof(uint32_value); break; case GRN_DB_INT64: int64_value = NUM2LL(object); string = (const char *)&int64_value; size = sizeof(int64_value); break; case GRN_DB_UINT64: uint64_value = NUM2ULL(object); string = (const char *)&uint64_value; size = sizeof(uint64_value); break; case GRN_DB_FLOAT: double_value = NUM2DBL(object); string = (const char *)&double_value; size = sizeof(double_value); break; case GRN_DB_TIME: { VALUE rb_sec, rb_usec; int64_t sec; int32_t usec; switch (TYPE(object)) { case T_FIXNUM: case T_BIGNUM: sec = NUM2LL(object); usec = 0; break; case T_FLOAT: rb_sec = rb_funcall(object, rb_intern("to_i"), 0); rb_usec = rb_funcall(object, rb_intern("remainder"), 1, INT2NUM(1)); sec = NUM2LL(rb_sec); usec = (int32_t)(NUM2DBL(rb_usec) * 1000000); break; case T_NIL: sec = 0; usec = 0; break; default: sec = NUM2LL(rb_funcall(object, rb_intern("to_i"), 0)); usec = NUM2INT(rb_funcall(object, rb_intern("usec"), 0)); break; } time_value = GRN_TIME_PACK(sec, usec); } string = (const char *)&time_value; size = sizeof(time_value); break; case GRN_DB_SHORT_TEXT: case GRN_DB_TEXT: case GRN_DB_LONG_TEXT: string = StringValuePtr(object); size = RSTRING_LEN(object); range = grn_obj_get_range(context, type); if (size > range) rb_raise(rb_eArgError, "string is too large: expected: %u <= %u", size, range); flags |= GRN_OBJ_DO_SHALLOW_COPY; break; case GRN_DB_VOID: case GRN_DB_DELIMIT: case GRN_DB_UNIGRAM: case GRN_DB_BIGRAM: case GRN_DB_TRIGRAM: case GRN_DB_MECAB: rb_type_object = GRNOBJECT2RVAL(Qnil, context, type, GRN_FALSE); rb_raise(rb_eArgError, "unbulkable type: %s", rb_grn_inspect(rb_type_object)); break; default: if (table_type_p && (NIL_P(object) || (string_p && RSTRING_LEN(object) == 0))) { record_id = GRN_ID_NIL; string = (const char *)&record_id; size = sizeof(record_id); if (bulk && bulk->header.domain != type_id) { grn_obj_reinit(context, bulk, type_id, 0); } } else { return RVAL2GRNBULK(object, context, bulk); } break; } if (!bulk) { bulk = grn_obj_open(context, GRN_BULK, flags, GRN_ID_NIL); rb_grn_context_check(context, object); } GRN_TEXT_SET(context, bulk, string, size); return bulk; }
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; }