[Tarantool-patches] [PATCH v5 30/52] sql: introduce mem_copy_bin()
Vladislav Shpilevoy
v.shpilevoy at tarantool.org
Tue Apr 13 02:36:15 MSK 2021
I appreciate the work you did here!
See 2 comments below.
> diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
> index 2622cdd82..e30795de5 100644
> --- a/src/box/sql/mem.c
> +++ b/src/box/sql/mem.c
> @@ -40,6 +40,19 @@
> #include "lua/utils.h"
> #include "lua/msgpack.h"
>
> +/*
> + * Make sure pMem->z points to a writable allocation of at least
> + * min(n,32) bytes.
> + *
> + * If the bPreserve argument is true, then copy of the content of
> + * pMem->z into the new allocation. pMem must be either a string or
> + * blob if bPreserve is true. If bPreserve is false, any prior content
> + * in pMem->z is discarded.
> + */
> +static int
> +sqlVdbeMemGrow(struct Mem *pMem, int n, int preserve);
> +
> +
1. Double empty line.
> bool
> mem_is_null(const struct Mem *mem)
> {
> @@ -477,6 +490,23 @@ mem_set_bin_allocated(struct Mem *mem, char *value, uint32_t size)
> set_bin_dynamic(mem, value, size, 0);
> }
>
> +int
> +mem_copy_bin(struct Mem *mem, const char *value, uint32_t size)
> +{
> + if ((mem->flags & (MEM_Agg | MEM_Frame)) != 0)
> + mem_clear(mem);
2. The same comment as for copy_str.
> + bool is_own_value = (mem->flags & (MEM_Str | 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