diff --git a/src/box/key_def.c b/src/box/key_def.c index 441cad1e0b6eaa926bc774764a0c2e186e4a08dc..f2e6c65f2e9a1bd9323c84e8e7ac27229c7ef267 100644 --- a/src/box/key_def.c +++ b/src/box/key_def.c @@ -325,7 +325,7 @@ key_def_new(const struct key_part_def *parts, uint32_t part_count, return NULL; } -int +void key_def_dump_parts(const struct key_def *def, struct key_part_def *parts, struct region *region) { @@ -339,12 +339,7 @@ key_def_dump_parts(const struct key_def *def, struct key_part_def *parts, part_def->nullable_action = part->nullable_action; part_def->coll_id = part->coll_id; if (part->path != NULL) { - char *path = region_alloc(region, part->path_len + 1); - if (path == NULL) { - diag_set(OutOfMemory, part->path_len + 1, - "region", "part_def->path"); - return -1; - } + char *path = xregion_alloc(region, part->path_len + 1); memcpy(path, part->path, part->path_len); path[part->path_len] = '\0'; part_def->path = path; @@ -352,7 +347,6 @@ key_def_dump_parts(const struct key_def *def, struct key_part_def *parts, part_def->path = NULL; } } - return 0; } /* {{{ Module API helpers */ @@ -1146,16 +1140,10 @@ key_def_find_pk_in_cmp_def(const struct key_def *cmp_def, size_t region_svp = region_used(region); /* First, dump primary key parts as is. */ - size_t size; - struct key_part_def *parts = - region_alloc_array(region, typeof(parts[0]), pk_def->part_count, - &size); - if (parts == NULL) { - diag_set(OutOfMemory, size, "region_alloc_array", "parts"); - goto out; - } - if (key_def_dump_parts(pk_def, parts, region) != 0) - goto out; + struct key_part_def *parts = xregion_alloc_array( + region, typeof(parts[0]), pk_def->part_count); + key_def_dump_parts(pk_def, parts, region); + /* * Second, update field numbers to match the primary key * parts in a secondary key. @@ -1170,7 +1158,6 @@ key_def_find_pk_in_cmp_def(const struct key_def *cmp_def, /* Finally, allocate the new key definition. */ extracted_def = key_def_new(parts, pk_def->part_count, false); -out: region_truncate(region, region_svp); return extracted_def; } diff --git a/src/box/key_def.h b/src/box/key_def.h index eb570be7e16fcc77565d64fb1a99c30f1f464de4..03f71796626ef46d80856c4de4d1134e0947112e 100644 --- a/src/box/key_def.h +++ b/src/box/key_def.h @@ -660,9 +660,8 @@ key_def_new(const struct key_part_def *parts, uint32_t part_count, /** * Dump part definitions of the given key def. * The region is used for allocating JSON paths, if any. - * Return -1 on memory allocation error, 0 on success. */ -int +void key_def_dump_parts(const struct key_def *def, struct key_part_def *parts, struct region *region); diff --git a/src/box/vy_log.c b/src/box/vy_log.c index f12f60233f2d271d24ca76e53c77cda209518e6b..a48503f4669002638cf9a23545cb451ac27b60d4 100644 --- a/src/box/vy_log.c +++ b/src/box/vy_log.c @@ -735,16 +735,10 @@ vy_log_record_dup(struct region *pool, const struct vy_log_record *src) memcpy((char *)dst->end, src->end, size); } if (src->key_def != NULL) { - dst->key_parts = - region_alloc_array(pool, typeof(dst->key_parts[0]), - src->key_def->part_count, &size); - if (dst->key_parts == NULL) { - diag_set(OutOfMemory, size, "region_alloc_array", - "def->key_parts"); - goto err; - } - if (key_def_dump_parts(src->key_def, dst->key_parts, pool) != 0) - goto err; + dst->key_parts = xregion_alloc_array( + pool, typeof(dst->key_parts[0]), + src->key_def->part_count); + key_def_dump_parts(src->key_def, dst->key_parts, pool); dst->key_part_count = src->key_def->part_count; dst->key_def = NULL; }