From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp37.i.mail.ru (smtp37.i.mail.ru [94.100.177.97]) (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 5DD47469710 for ; Thu, 28 May 2020 02:32:32 +0300 (MSK) From: Vladislav Shpilevoy Date: Thu, 28 May 2020 01:32:19 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v2 01/10] small: sanitized rlist and new region API List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org, alyapunov@tarantool.org, korablev@tarantool.org, tsafin@tarantool.org Rlist used a hack to implement offsetof() leading to crash under undefined behaviour clang sanitizer. It was fixed in this update. Additionally, region_alloc_object() is changed to return the used size and a new macro region_alloc_array() is added. This small API change is supposed to simplify switching lots of region allocations to aligned versions in scope of #4609. Part of #4609 --- src/box/txn.c | 17 +++++++++-------- src/box/vy_write_iterator.c | 7 +++++-- src/lib/small | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/box/txn.c b/src/box/txn.c index 488aa4bdd..b81693c0a 100644 --- a/src/box/txn.c +++ b/src/box/txn.c @@ -54,11 +54,11 @@ static int txn_add_redo(struct txn *txn, struct txn_stmt *stmt, struct request *request) { /* Create a redo log row. */ + int size; struct xrow_header *row; - row = region_alloc_object(&txn->region, struct xrow_header); + row = region_alloc_object(&txn->region, struct xrow_header, &size); if (row == NULL) { - diag_set(OutOfMemory, sizeof(*row), - "region", "struct xrow_header"); + diag_set(OutOfMemory, size, "region_alloc_object", "row"); return -1; } if (request->header != NULL) { @@ -91,11 +91,11 @@ txn_add_redo(struct txn *txn, struct txn_stmt *stmt, struct request *request) static struct txn_stmt * txn_stmt_new(struct region *region) { + int size; struct txn_stmt *stmt; - stmt = region_alloc_object(region, struct txn_stmt); + stmt = region_alloc_object(region, struct txn_stmt, &size); if (stmt == NULL) { - diag_set(OutOfMemory, sizeof(*stmt), - "region", "struct txn_stmt"); + diag_set(OutOfMemory, size, "region_alloc_object", "stmt"); return NULL; } @@ -178,9 +178,10 @@ txn_new(void) region_create(®ion, &cord()->slabc); /* Place txn structure on the region. */ - struct txn *txn = region_alloc_object(®ion, struct txn); + int size; + struct txn *txn = region_alloc_object(®ion, struct txn, &size); if (txn == NULL) { - diag_set(OutOfMemory, sizeof(*txn), "region", "struct txn"); + diag_set(OutOfMemory, size, "region_alloc_object", "txn"); return NULL; } assert(region_used(®ion) == sizeof(*txn)); diff --git a/src/box/vy_write_iterator.c b/src/box/vy_write_iterator.c index 01962faa3..78a52ae5c 100644 --- a/src/box/vy_write_iterator.c +++ b/src/box/vy_write_iterator.c @@ -102,9 +102,12 @@ static inline struct vy_write_history * vy_write_history_new(struct vy_entry entry, struct vy_write_history *next) { struct vy_write_history *h; - h = region_alloc_object(&fiber()->gc, struct vy_write_history); - if (h == NULL) + int size; + h = region_alloc_object(&fiber()->gc, struct vy_write_history, &size); + if (h == NULL) { + diag_set(OutOfMemory, size, "region_alloc_object", "h"); return NULL; + } h->entry = entry; assert(next == NULL || (next->entry.stmt != NULL && vy_stmt_lsn(next->entry.stmt) > vy_stmt_lsn(entry.stmt))); diff --git a/src/lib/small b/src/lib/small index 118b53334..fc75e99f5 160000 --- a/src/lib/small +++ b/src/lib/small @@ -1 +1 @@ -Subproject commit 118b53334ad785ebe0534758832841dc2786fdc4 +Subproject commit fc75e99f5b2a695c9f52db78198ea7ada7ef6a82 -- 2.21.1 (Apple Git-122.3)