From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp56.i.mail.ru (smtp56.i.mail.ru [217.69.128.36]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 19ADB4765E4 for ; Tue, 29 Dec 2020 14:03:40 +0300 (MSK) From: mechanik20051988 Date: Tue, 29 Dec 2020 14:03:30 +0300 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 2/4] memtx: changed some memtx files from .c to .cc List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: v.shpilevoy@tarantool.org, alyapunov@tarantool.org Cc: mechanik20051988 , tarantool-patches@dev.tarantool.org From: mechanik20051988 --- src/box/CMakeLists.txt | 4 +-- src/box/field_map.h | 8 +++++ src/box/{memtx_engine.c => memtx_engine.cc} | 38 ++++++++++++--------- src/box/{memtx_space.c => memtx_space.cc} | 15 ++++---- 4 files changed, 40 insertions(+), 25 deletions(-) rename src/box/{memtx_engine.c => memtx_engine.cc} (97%) rename src/box/{memtx_space.c => memtx_space.cc} (98%) diff --git a/src/box/CMakeLists.txt b/src/box/CMakeLists.txt index 19203f770..d2af89d05 100644 --- a/src/box/CMakeLists.txt +++ b/src/box/CMakeLists.txt @@ -127,8 +127,8 @@ add_library(box STATIC memtx_bitset.c memtx_tx.c engine.c - memtx_engine.c - memtx_space.c + memtx_engine.cc + memtx_space.cc sysview.c blackhole.c service_engine.c diff --git a/src/box/field_map.h b/src/box/field_map.h index d8ef726a1..5087d25e5 100644 --- a/src/box/field_map.h +++ b/src/box/field_map.h @@ -35,6 +35,10 @@ #include #include "bit/bit.h" +#if defined(__cplusplus) +extern "C" { +#endif /* defined(__cplusplus) */ + struct region; struct field_map_builder_slot; @@ -257,4 +261,8 @@ field_map_build_size(struct field_map_builder *builder) void field_map_build(struct field_map_builder *builder, char *buffer); +#if defined(__cplusplus) +} /* extern "C" */ +#endif /* defined(__plusplus) */ + #endif /* TARANTOOL_BOX_FIELD_MAP_H_INCLUDED */ diff --git a/src/box/memtx_engine.c b/src/box/memtx_engine.cc similarity index 97% rename from src/box/memtx_engine.c rename to src/box/memtx_engine.cc index f79f14b4f..520a221dd 100644 --- a/src/box/memtx_engine.c +++ b/src/box/memtx_engine.cc @@ -552,7 +552,7 @@ struct checkpoint { static struct checkpoint * checkpoint_new(const char *snap_dirname, uint64_t snap_io_rate_limit) { - struct checkpoint *ckpt = malloc(sizeof(*ckpt)); + struct checkpoint *ckpt = (struct checkpoint *)malloc(sizeof(*ckpt)); if (ckpt == NULL) { diag_set(OutOfMemory, sizeof(*ckpt), "malloc", "struct checkpoint"); @@ -621,7 +621,7 @@ checkpoint_add_space(struct space *sp, void *data) if (!pk) return 0; struct checkpoint *ckpt = (struct checkpoint *)data; - struct checkpoint_entry *entry = malloc(sizeof(*entry)); + struct checkpoint_entry *entry = (struct checkpoint_entry *)malloc(sizeof(*entry)); if (entry == NULL) { diag_set(OutOfMemory, sizeof(*entry), "malloc", "struct checkpoint_entry"); @@ -851,7 +851,7 @@ struct memtx_join_ctx { static int memtx_join_add_space(struct space *space, void *arg) { - struct memtx_join_ctx *ctx = arg; + struct memtx_join_ctx *ctx = (struct memtx_join_ctx *)arg; if (!space_is_memtx(space)) return 0; if (space_is_temporary(space)) @@ -861,7 +861,7 @@ memtx_join_add_space(struct space *space, void *arg) struct index *pk = space_index(space, 0); if (pk == NULL) return 0; - struct memtx_join_entry *entry = malloc(sizeof(*entry)); + struct memtx_join_entry *entry = (struct memtx_join_entry *)malloc(sizeof(*entry)); if (entry == NULL) { diag_set(OutOfMemory, sizeof(*entry), "malloc", "struct memtx_join_entry"); @@ -881,7 +881,7 @@ static int memtx_engine_prepare_join(struct engine *engine, void **arg) { (void)engine; - struct memtx_join_ctx *ctx = malloc(sizeof(*ctx)); + struct memtx_join_ctx *ctx = (struct memtx_join_ctx *)malloc(sizeof(*ctx)); if (ctx == NULL) { diag_set(OutOfMemory, sizeof(*ctx), "malloc", "struct memtx_join_ctx"); @@ -919,7 +919,7 @@ memtx_join_send_tuple(struct xstream *stream, uint32_t space_id, static int memtx_join_f(va_list ap) { - struct memtx_join_ctx *ctx = va_arg(ap, struct memtx_join_ctx *); + struct memtx_join_ctx *ctx = (struct memtx_join_ctx *)va_arg(ap, struct memtx_join_ctx *); struct memtx_join_entry *entry; rlist_foreach_entry(entry, &ctx->entries, in_ctx) { struct snapshot_iterator *it = entry->iterator; @@ -941,7 +941,7 @@ static int memtx_engine_join(struct engine *engine, void *arg, struct xstream *stream) { (void)engine; - struct memtx_join_ctx *ctx = arg; + struct memtx_join_ctx *ctx = (struct memtx_join_ctx *)arg; ctx->stream = stream; /* * Memtx snapshot iterators are safe to use from another @@ -962,7 +962,7 @@ static void memtx_engine_complete_join(struct engine *engine, void *arg) { (void)engine; - struct memtx_join_ctx *ctx = arg; + struct memtx_join_ctx *ctx = (struct memtx_join_ctx *)arg; struct memtx_join_entry *entry, *next; rlist_foreach_entry_safe(entry, &ctx->entries, in_ctx, next) { entry->iterator->free(entry->iterator); @@ -1066,7 +1066,8 @@ memtx_engine_new(const char *snap_dirname, bool force_recovery, uint64_t tuple_arena_max_size, uint32_t objsize_min, bool dontdump, float alloc_factor) { - struct memtx_engine *memtx = calloc(1, sizeof(*memtx)); + int64_t snap_signature; + struct memtx_engine *memtx = (struct memtx_engine *)calloc(1, sizeof(*memtx)); if (memtx == NULL) { diag_set(OutOfMemory, sizeof(*memtx), "malloc", "struct memtx_engine"); @@ -1090,7 +1091,7 @@ memtx_engine_new(const char *snap_dirname, bool force_recovery, * So if the local directory isn't empty, read the snapshot * signature right now to initialize the instance UUID. */ - int64_t snap_signature = xdir_last_vclock(&memtx->snap_dir, NULL); + snap_signature = xdir_last_vclock(&memtx->snap_dir, NULL); if (snap_signature >= 0) { struct xlog_cursor cursor; if (xdir_open_cursor(&memtx->snap_dir, @@ -1220,15 +1221,19 @@ memtx_tuple_new(struct tuple_format *format, const char *data, const char *end) struct region *region = &fiber()->gc; size_t region_svp = region_used(region); struct field_map_builder builder; + uint32_t field_map_size, data_offset; + size_t tuple_len, total; + char *raw; + if (tuple_field_map_create(format, data, true, &builder) != 0) goto end; - uint32_t field_map_size = field_map_build_size(&builder); + field_map_size = field_map_build_size(&builder); /* * Data offset is calculated from the begin of the struct * tuple base, not from memtx_tuple, because the struct * tuple is not the first field of the memtx_tuple. */ - uint32_t data_offset = sizeof(struct tuple) + field_map_size; + data_offset = sizeof(struct tuple) + field_map_size; if (data_offset > INT16_MAX) { /** tuple->data_offset is 15 bits */ diag_set(ClientError, ER_TUPLE_METADATA_IS_TOO_BIG, @@ -1236,8 +1241,8 @@ memtx_tuple_new(struct tuple_format *format, const char *data, const char *end) goto end; } - size_t tuple_len = end - data; - size_t total = sizeof(struct memtx_tuple) + field_map_size + tuple_len; + tuple_len = end - data; + total = sizeof(struct memtx_tuple) + field_map_size + tuple_len; ERROR_INJECT(ERRINJ_TUPLE_ALLOC, { diag_set(OutOfMemory, total, "slab allocator", "memtx_tuple"); @@ -1250,7 +1255,8 @@ memtx_tuple_new(struct tuple_format *format, const char *data, const char *end) } struct memtx_tuple *memtx_tuple; - while ((memtx_tuple = smalloc(&memtx->alloc, total)) == NULL) { + while ((memtx_tuple = (struct memtx_tuple *) + smalloc(&memtx->alloc, total)) == NULL) { bool stop; memtx_engine_run_gc(memtx, &stop); if (stop) @@ -1269,7 +1275,7 @@ memtx_tuple_new(struct tuple_format *format, const char *data, const char *end) tuple_format_ref(format); tuple->data_offset = data_offset; tuple->is_dirty = false; - char *raw = (char *) tuple + tuple->data_offset; + raw = (char *) tuple + tuple->data_offset; field_map_build(&builder, raw - field_map_size); memcpy(raw, data, tuple_len); say_debug("%s(%zu) = %p", __func__, tuple_len, memtx_tuple); diff --git a/src/box/memtx_space.c b/src/box/memtx_space.cc similarity index 98% rename from src/box/memtx_space.c rename to src/box/memtx_space.cc index 73b4c450e..e46e4eaeb 100644 --- a/src/box/memtx_space.c +++ b/src/box/memtx_space.cc @@ -861,8 +861,8 @@ struct memtx_ddl_state { static int memtx_check_on_replace(struct trigger *trigger, void *event) { - struct txn *txn = event; - struct memtx_ddl_state *state = trigger->data; + struct txn *txn = (struct txn *)event; + struct memtx_ddl_state *state = (struct memtx_ddl_state *)trigger->data; struct txn_stmt *stmt = txn_current_stmt(txn); /* Nothing to check on DELETE. */ @@ -985,8 +985,8 @@ memtx_init_ephemeral_space(struct space *space) static int memtx_build_on_replace(struct trigger *trigger, void *event) { - struct txn *txn = event; - struct memtx_ddl_state *state = trigger->data; + struct txn *txn = (struct txn *)event; + struct memtx_ddl_state *state = (struct memtx_ddl_state *)trigger->data; struct txn_stmt *stmt = txn_current_stmt(txn); struct tuple *cmp_tuple = stmt->new_tuple != NULL ? stmt->new_tuple : @@ -1006,12 +1006,12 @@ memtx_build_on_replace(struct trigger *trigger, void *event) return 0; } - struct tuple *delete = NULL; + struct tuple *unused = nullptr; enum dup_replace_mode mode = state->index->def->opts.is_unique ? DUP_INSERT : DUP_REPLACE_OR_INSERT; state->rc = index_replace(state->index, stmt->old_tuple, - stmt->new_tuple, mode, &delete); + stmt->new_tuple, mode, &unused); if (state->rc != 0) { diag_move(diag_get(), &state->diag); return 0; @@ -1193,7 +1193,8 @@ struct space * memtx_space_new(struct memtx_engine *memtx, struct space_def *def, struct rlist *key_list) { - struct memtx_space *memtx_space = malloc(sizeof(*memtx_space)); + struct memtx_space *memtx_space = + (struct memtx_space *)malloc(sizeof(*memtx_space)); if (memtx_space == NULL) { diag_set(OutOfMemory, sizeof(*memtx_space), "malloc", "struct memtx_space"); -- 2.20.1