[Tarantool-patches] FW: [PATCH v1 09/10] sql: refactor vdbeaux.c

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Sun Feb 28 20:35:43 MSK 2021


> : @@ -1402,41 +1408,26 @@ sqlVdbeList(Vdbe * p)
> :  		mem_set_i64(pMem, pOp->p3);
> :  		pMem++;
> : 
> : -		if (sqlVdbeMemClearAndResize(pMem, 256)) {
> : -			assert(p->db->mallocFailed);
> : -			return -1;
> : -		}
> : -		pMem->flags = MEM_Str | MEM_Term;
> : -		zP4 = displayP4(pOp, pMem->z, pMem->szMalloc);
> : -
> : -		if (zP4 != pMem->z) {
> : -			pMem->n = 0;
> : -			sqlVdbeMemSetStr(pMem, zP4, -1, 1, 0);
> : -		} else {
> : -			assert(pMem->z != 0);
> : -			pMem->n = sqlStrlen30(pMem->z);
> : -		}
> : +		size_t size = 256;
> : +		char *tmp_buf = (char *) static_alloc(size);
> : +		assert(tmp_buf != NULL);
> : +		zP4 = displayP4(pOp, tmp_buf, size);
> : +		mem_set_str(pMem, zP4, strlen(zP4), 0, true);
> :  		pMem++;
> 
> Please, please, not introduce any newer usage of static_alloc,
> it's very fragile and might work only inside of controlled context of 
> single module (i.e. swim). If used by multiple modules -
> results are unpredictable. Any other allocator is fine if used 
> by multiple fibers, but not static_alloc.

What exactly is the problem with static alloc here? Can you explain?
>From the text above I can only see one argument - 'fragile'. Which is
not a real argument.

Static alloc is faster than anything we have except allocation on
the stack. So I would prefer to use it when possible.


More information about the Tarantool-patches mailing list