[Tarantool-patches] [PATCH v5 27/52] sql: introduce mem_set_str_*() functions

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Tue Apr 13 02:34:22 MSK 2021


Nice fixes!

See 2 comments below.

> diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
> index 6c08e772d..e0903e3b0 100644
> --- a/src/box/sql/vdbeapi.c
> +++ b/src/box/sql/vdbeapi.c
> @@ -125,6 +125,27 @@ setResultStrOrError(sql_context * pCtx,	/* Function context */
>  		    void (*xDel) (void *)	/* Destructor function */
>      )
>  {
> +	if (xDel == SQL_STATIC) {
> +		if (n < 0)
> +			mem_set_str0_static(pCtx->pOut, (char *)z);
> +		else
> +			mem_set_str_static(pCtx->pOut, (char *)z, n);
> +		return;
> +	}
> +	if (xDel == SQL_DYNAMIC) {
> +		if (n < 0)
> +			mem_set_str0_allocated(pCtx->pOut, (char *)z);
> +		else
> +			mem_set_str_allocated(pCtx->pOut, (char *)z, n);

1. I don't understand. You check for xDel == SQL_DYNAMIC and yet
you use 'allocated' suffix. Below you check for != TRANSIENT
instead of == DYNAMIC, and use 'dynamic'. Why? All looks messed
up. The same in the next hunk.

> +		return;
> +	}> diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
> index ae55e4c29..171cb8946 100644
> --- a/src/box/sql/vdbeaux.c
> +++ b/src/box/sql/vdbeaux.c
> @@ -1333,41 +1331,34 @@ sqlVdbeList(Vdbe * p)
>  		mem_set_int(pMem, pOp->p3, pOp->p3 < 0);
>  		pMem++;
>  
> -		if (sqlVdbeMemClearAndResize(pMem, 256)) {
> -			assert(p->db->mallocFailed);
> +		char *buf = sqlDbMallocRaw(sql_get(), 256);

2. I think you need some kind of mem_set_strlen(), or mem_grow()/mem_reserve(),
or something else to reserve the memory. To extend zMalloc. Otherwise you
can't reuse the memory which might already be in the mem object.


More information about the Tarantool-patches mailing list