Kouhei Sutou
null+****@clear*****
Wed Jul 18 17:01:24 JST 2018
Kouhei Sutou 2018-07-18 17:01:24 +0900 (Wed, 18 Jul 2018) New Revision: a86039aab316b9d682382f8a1e74ad96c1ece91e https://github.com/groonga/groonga/commit/a86039aab316b9d682382f8a1e74ad96c1ece91e Message: Clear option values on remove (for persistent) / close (for temporary) New API: grn_obj_clear_option_values() Modified files: include/groonga/obj.h lib/db.c lib/grn_db.h lib/grn_options.h lib/obj.c lib/options.c Modified: include/groonga/obj.h (+1 -0) =================================================================== --- include/groonga/obj.h 2018-07-18 16:30:15 +0900 (51dff63db) +++ include/groonga/obj.h 2018-07-18 17:01:24 +0900 (3e372e1e4) @@ -92,6 +92,7 @@ grn_obj_get_option_values(grn_ctx *ctx, int name_length, grn_option_revision revision, grn_obj *values); +GRN_API grn_rc grn_obj_clear_option_values(grn_ctx *ctx, grn_obj *obj); #ifdef __cplusplus } Modified: lib/db.c (+19 -5) =================================================================== --- lib/db.c 2018-07-18 16:30:15 +0900 (4f2d0c231) +++ lib/db.c 2018-07-18 17:01:24 +0900 (4fe288911) @@ -938,6 +938,15 @@ grn_db_get_option_values(grn_ctx *ctx, values); } +grn_rc +grn_db_clear_option_values(grn_ctx *ctx, + grn_obj *db, + grn_id id) +{ + grn_db *db_ = (grn_db *)db; + return grn_options_clear(ctx, db_->options, id); +} + static grn_obj * grn_type_open(grn_ctx *ctx, grn_obj_spec *spec) { @@ -10285,6 +10294,7 @@ _grn_obj_remove(grn_ctx *ctx, grn_obj *obj, grn_bool dependent) if (GRN_DB_OBJP(obj)) { id = DB_OBJ(obj)->id; db = DB_OBJ(obj)->db; + rc = grn_obj_clear_option_values(ctx, obj); } switch (obj->header.type) { case GRN_DB : @@ -11205,12 +11215,13 @@ grn_obj_close(grn_ctx *ctx, grn_obj *obj) grn_rc rc = GRN_INVALID_ARGUMENT; GRN_API_ENTER; if (obj) { - if (grn_obj_is_table(ctx, obj) && - (DB_OBJ(obj)->id & GRN_OBJ_TMP_OBJECT)) { - grn_table_close_columns(ctx, obj); - } if (GRN_DB_OBJP(obj)) { + grn_id id = DB_OBJ(obj)->id; grn_hook_entry entry; + + if (grn_obj_is_table(ctx, obj) && (id & GRN_OBJ_TMP_OBJECT)) { + grn_table_close_columns(ctx, obj); + } if (DB_OBJ(obj)->finalizer) { DB_OBJ(obj)->finalizer(ctx, 1, &obj, &DB_OBJ(obj)->user_data); } @@ -11220,7 +11231,10 @@ grn_obj_close(grn_ctx *ctx, grn_obj *obj) for (entry = 0; entry < N_HOOK_ENTRIES; entry++) { grn_hook_free(ctx, DB_OBJ(obj)->hooks[entry]); } - grn_obj_delete_by_id(ctx, DB_OBJ(obj)->db, DB_OBJ(obj)->id, GRN_FALSE); + if (id & GRN_OBJ_TMP_OBJECT) { + grn_obj_clear_option_values(ctx, obj); + } + grn_obj_delete_by_id(ctx, DB_OBJ(obj)->db, id, GRN_FALSE); } switch (obj->header.type) { case GRN_VECTOR : Modified: lib/grn_db.h (+3 -0) =================================================================== --- lib/grn_db.h 2018-07-18 16:30:15 +0900 (263cba455) +++ lib/grn_db.h 2018-07-18 17:01:24 +0900 (02acd9267) @@ -146,6 +146,9 @@ grn_db_get_option_values(grn_ctx *ctx, int name_length, grn_option_revision revision, grn_obj *values); +grn_rc grn_db_clear_option_values(grn_ctx *ctx, + grn_obj *db, + grn_id id); grn_rc _grn_table_delete_by_id(grn_ctx *ctx, grn_obj *table, grn_id id, grn_table_delete_optarg *optarg); Modified: lib/grn_options.h (+3 -0) =================================================================== --- lib/grn_options.h 2018-07-18 16:30:15 +0900 (2f2775993) +++ lib/grn_options.h 2018-07-18 17:01:24 +0900 (c9fa48547) @@ -53,6 +53,9 @@ grn_option_revision grn_options_get(grn_ctx *ctx, int name_length, grn_option_revision revision, grn_obj *values); +grn_rc grn_options_clear(grn_ctx *ctx, + grn_options *options, + grn_id id); #ifdef __cplusplus } Modified: lib/obj.c (+22 -0) =================================================================== --- lib/obj.c 2018-07-18 16:30:15 +0900 (ed8945637) +++ lib/obj.c 2018-07-18 17:01:24 +0900 (24b66dae6) @@ -785,3 +785,25 @@ grn_obj_get_option_values(grn_ctx *ctx, GRN_API_RETURN(returned_revision); } + +grn_rc +grn_obj_clear_option_values(grn_ctx *ctx, grn_obj *obj) +{ + grn_id id; + grn_rc rc; + + GRN_API_ENTER; + + id = grn_obj_id(ctx, obj); + if (id & GRN_OBJ_TMP_OBJECT) { + rc = grn_options_clear(ctx, + ctx->impl->temporary_options, + id & ~GRN_OBJ_TMP_OBJECT); + } else { + rc = grn_db_clear_option_values(ctx, + grn_ctx_db(ctx), + id); + } + + GRN_API_RETURN(rc); +} Modified: lib/options.c (+8 -0) =================================================================== --- lib/options.c 2018-07-18 16:30:15 +0900 (50db70685) +++ lib/options.c 2018-07-18 17:01:24 +0900 (2d6ec3bcb) @@ -375,3 +375,11 @@ grn_options_get(grn_ctx *ctx, return GRN_OPTION_REVISION_NONE; #endif /* GRN_WITH_MESSAGE_PACK */ } + +grn_rc +grn_options_clear(grn_ctx *ctx, + grn_options *options, + grn_id id) +{ + return grn_ja_put(ctx, options->values, id, NULL, 0, GRN_OBJ_SET, NULL); +} -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180718/b57cbc6f/attachment-0001.htm