Navigation Menu

Skip to content

Commit

Permalink
grn_obj_cast: return GRN_INVALID_ARGUMENT for not found record
Browse files Browse the repository at this point in the history
It's not a problem but it may be backward incompatible...
How to test it...?
  • Loading branch information
kou committed Apr 22, 2015
1 parent f69eddc commit 394825f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
12 changes: 10 additions & 2 deletions lib/db.c
Expand Up @@ -5243,7 +5243,11 @@ grn_obj_is_persistent(grn_ctx *ctx, grn_obj *obj)
if (GRN_BULK_VSIZE(p_key)) {\
id = addp ? grn_table_add_by_key(ctx, table, p_key, NULL)\
: grn_table_get_by_key(ctx, table, p_key);\
if (id) { GRN_RECORD_SET(ctx, dest, id); }\
if (id) {\
GRN_RECORD_SET(ctx, dest, id);\
} else {\
rc = GRN_INVALID_ARGUMENT;\
}\
} else {\
GRN_RECORD_SET(ctx, dest, GRN_ID_NIL);\
}\
Expand All @@ -5253,7 +5257,11 @@ grn_obj_is_persistent(grn_ctx *ctx, grn_obj *obj)
GRN_UINT32_INIT(&record_id, 0);\
grn_obj_cast(ctx, src, &record_id, GRN_TRUE);\
id = GRN_UINT32_VALUE(&record_id);\
if (id) { GRN_RECORD_SET(ctx, dest, id); }\
if (id) {\
GRN_RECORD_SET(ctx, dest, id);\
} else {\
rc = GRN_INVALID_ARGUMENT;\
}\
}\
} else {\
rc = GRN_FUNCTION_NOT_IMPLEMENTED;\
Expand Down
3 changes: 1 addition & 2 deletions lib/expr.c
Expand Up @@ -728,8 +728,7 @@ grn_expr_append_obj_resolve_const(grn_ctx *ctx,
grn_obj dest;

GRN_OBJ_INIT(&dest, GRN_BULK, 0, to_domain);
if (!grn_obj_cast(ctx, obj, &dest, GRN_FALSE) &&
GRN_BULK_VSIZE(&dest) > 0) {
if (!grn_obj_cast(ctx, obj, &dest, GRN_FALSE)) {
grn_obj_reinit(ctx, obj, to_domain, 0);
grn_bulk_write(ctx, obj, GRN_BULK_HEAD(&dest), GRN_BULK_VSIZE(&dest));
}
Expand Down
8 changes: 5 additions & 3 deletions test/unit/core/test-cast-table.c
Expand Up @@ -122,13 +122,14 @@ cut_teardown(void)
}

static void
cast_text(const gchar *text)
cast_text(grn_rc expected_rc, const gchar *text)
{
grn_obj_reinit(&context, &src, GRN_DB_TEXT, 0);
if (text) {
GRN_TEXT_PUTS(&context, &src, text);
}
grn_test_assert(grn_obj_cast(&context, &src, &dest, GRN_FALSE));
grn_test_assert_equal_rc(expected_rc,
grn_obj_cast(&context, &src, &dest, GRN_FALSE));
}

void
Expand All @@ -154,11 +155,12 @@ test_text_to_table(gconstpointer data)
gsize expected_size;

grn_obj_reinit(&context, &dest, users, 0);
cast_text(gcut_data_get_string(data, "text"));
expected_size = gcut_data_get_size(data, "expected-size");
if (expected_size == 0) {
cast_text(GRN_INVALID_ARGUMENT, gcut_data_get_string(data, "text"));
cut_assert_equal_uint(0, GRN_BULK_VSIZE(&dest));
} else {
cast_text(GRN_SUCCESS, gcut_data_get_string(data, "text"));
grn_test_assert_equal_record_id(&context,
grn_ctx_at(&context, users),
gcut_data_get_uint(data, "expected"),
Expand Down

0 comments on commit 394825f

Please sign in to comment.