[Tarantool-patches] [PATCH v4 31/53] sql: introduce mem_copy_binary()

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Tue Mar 30 02:05:32 MSK 2021


Thanks for the patch!

On 23.03.2021 10:36, Mergen Imeev via Tarantool-patches wrote:
> This patch introduces mem_copy_binary() function. Function
> mem_copy_binary() clears MEM, allocates enough memory and copies given
> binary to allocated memory.
> 
> Part of #5818
> ---
>  src/box/sql/mem.c      | 14 ++++++++++++++
>  src/box/sql/mem.h      |  3 +++
>  src/box/sql/vdbe.c     |  7 ++-----
>  src/box/sql/vdbeapi.c  |  4 ++--
>  src/box/sql/vdbesort.c |  6 +-----
>  5 files changed, 22 insertions(+), 12 deletions(-)
> 
> diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
> index 5ee49cdca..99beec9ad 100644
> --- a/src/box/sql/mem.c
> +++ b/src/box/sql/mem.c
> @@ -465,6 +465,20 @@ mem_set_allocated_binary(struct Mem *mem, char *value, uint32_t size)
>  	mem_set_dyn_bin(mem, value, size, 0);
>  }
>  
> +int
> +mem_copy_binary(struct Mem *mem, const char *value, uint32_t size)
> +{

What if mem is not a binary now? What if it is a frame? Why don't you clear it?

> +	bool is_own_value = (mem->flags & MEM_Blob) != 0 && mem->z == value;
> +	if (sqlVdbeMemGrow(mem, size, is_own_value) != 0)
> +		return -1;
> +	if (!is_own_value)
> +		memcpy(mem->z, value, size);
> +	mem->n = size;
> +	mem->flags = MEM_Blob;
> +	mem->field_type = FIELD_TYPE_VARBINARY;
> +	return 0;
> +}


More information about the Tarantool-patches mailing list