[Tarantool-patches] [PATCH 3/5] decimal: rename decimal_to_string to decimal_str

Sergey Ostanevich sergos at tarantool.org
Thu Jul 29 14:41:46 MSK 2021


Hi! Thanks for the patch, just one comment re commit message.

LGTM

Sergos

> On 28 Jul 2021, at 00:24, Vladislav Shpilevoy <v.shpilevoy at tarantool.org> wrote:
> 
> To be consistent with tt_uuid_str() and tt_uuid_to_string().
> _str() returns a string. _to_string() copies it into an externally
> passed buffer.

Please, mention the decimal_to_string() function explicitly to ease the search later on.

> 
> Part of #6259
> ---
> src/box/lua/serialize_lua.c       | 2 +-
> src/lib/core/decimal.c            | 2 +-
> src/lib/core/decimal.h            | 2 +-
> src/lib/core/mp_decimal.c         | 4 ++--
> src/lua/decimal.c                 | 2 +-
> test/unit/decimal.c               | 4 ++--
> third_party/lua-cjson/lua_cjson.c | 2 +-
> third_party/lua-yaml/lyaml.cc     | 2 +-
> 8 files changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/src/box/lua/serialize_lua.c b/src/box/lua/serialize_lua.c
> index 7144305cf..1f791980f 100644
> --- a/src/box/lua/serialize_lua.c
> +++ b/src/box/lua/serialize_lua.c
> @@ -853,7 +853,7 @@ dump_node(struct lua_dumper *d, struct node *nd, int indent)
> 		switch (field->ext_type) {
> 		case MP_DECIMAL:
> 			nd->mask |= NODE_QUOTE;
> -			str = decimal_to_string(field->decval);
> +			str = decimal_str(field->decval);
> 			len = strlen(str);
> 			break;
> 		case MP_UUID:
> diff --git a/src/lib/core/decimal.c b/src/lib/core/decimal.c
> index 118c311d5..4befbda37 100644
> --- a/src/lib/core/decimal.c
> +++ b/src/lib/core/decimal.c
> @@ -165,7 +165,7 @@ decimal_from_uint64(decimal_t *dec, uint64_t num)
> }
> 
> const char *
> -decimal_to_string(const decimal_t *dec)
> +decimal_str(const decimal_t *dec)
> {
> 	char *buf = tt_static_buf();
> 	/* No errors are possible. */
> diff --git a/src/lib/core/decimal.h b/src/lib/core/decimal.h
> index 6f8762ed3..d2f2dfbdb 100644
> --- a/src/lib/core/decimal.h
> +++ b/src/lib/core/decimal.h
> @@ -126,7 +126,7 @@ decimal_from_uint64(decimal_t *dec, uint64_t num);
>  * the decimal representation.
>  */
> const char *
> -decimal_to_string(const decimal_t *dec);
> +decimal_str(const decimal_t *dec);
> 
> /**
>  * Convert a given decimal to int64_t
> diff --git a/src/lib/core/mp_decimal.c b/src/lib/core/mp_decimal.c
> index ffc2c5773..3610b8af5 100644
> --- a/src/lib/core/mp_decimal.c
> +++ b/src/lib/core/mp_decimal.c
> @@ -77,7 +77,7 @@ mp_snprint_decimal(char *buf, int size, const char **data, uint32_t len)
> 	decimal_t d;
> 	if (decimal_unpack(data, len, &d) == NULL)
> 		return -1;
> -	return snprintf(buf, size, "%s", decimal_to_string(&d));
> +	return snprintf(buf, size, "%s", decimal_str(&d));
> }
> 
> int
> @@ -86,5 +86,5 @@ mp_fprint_decimal(FILE *file, const char **data, uint32_t len)
> 	decimal_t d;
> 	if (decimal_unpack(data, len, &d) == NULL)
> 		return -1;
> -	return fprintf(file, "%s", decimal_to_string(&d));
> +	return fprintf(file, "%s", decimal_str(&d));
> }
> diff --git a/src/lua/decimal.c b/src/lua/decimal.c
> index 003680a48..e25b3ec18 100644
> --- a/src/lua/decimal.c
> +++ b/src/lua/decimal.c
> @@ -376,7 +376,7 @@ ldecimal_tostring(struct lua_State *L)
> 	if (lua_gettop(L) < 1)
> 		return luaL_error(L, "usage: decimal.tostring(decimal)");
> 	decimal_t *lhs = lua_checkdecimal(L, 1);
> -	lua_pushstring(L, decimal_to_string(lhs));
> +	lua_pushstring(L, decimal_str(lhs));
> 	return 1;
> }
> 
> diff --git a/test/unit/decimal.c b/test/unit/decimal.c
> index 32694b88a..756c68518 100644
> --- a/test/unit/decimal.c
> +++ b/test/unit/decimal.c
> @@ -107,7 +107,7 @@ char buf[32];
> 	is(b1, b2, "mp_decode(mp_encode("str") len");\
> 	is(decimal_compare(&dec, &d2), 0, "mp_decode(mp_encode("str")) value");\
> 	is(decimal_scale(&dec), decimal_scale(&d2), "mp_decode(mp_encode("str")) scale");\
> -	is(strcmp(decimal_to_string(&d2), str), 0, "str(mp_decode(mp_encode("str"))) == "str);\
> +	is(strcmp(decimal_str(&d2), str), 0, "str(mp_decode(mp_encode("str"))) == "str);\
> 	b2 = buf;\
> 	int8_t type;\
> 	uint32_t l2 = mp_decode_extl(&b2, &type);\
> @@ -131,7 +131,7 @@ char buf[32];
> 	is(decimal_compare(&dec, &d2), 0, "decimal_unpack(decimal_pack("str")) value");\
> 	is(decimal_scale(&dec), decimal_scale(&d2), "decimal_unpack(decimal_pack("str")) scale");\
> 	is(decimal_precision(&dec), decimal_precision(&d2), "decimal_unpack(decimal_pack("str")) precision");\
> -	is(strcmp(decimal_to_string(&d2), str), 0, "str(decimal_unpack(decimal_pack("str")) == "str);\
> +	is(strcmp(decimal_str(&d2), str), 0, "str(decimal_unpack(decimal_pack("str")) == "str);\
> })
> 
> #define test_toint(type, num, out_fmt) ({\
> diff --git a/third_party/lua-cjson/lua_cjson.c b/third_party/lua-cjson/lua_cjson.c
> index 5123b9a74..7a326075a 100644
> --- a/third_party/lua-cjson/lua_cjson.c
> +++ b/third_party/lua-cjson/lua_cjson.c
> @@ -420,7 +420,7 @@ static void json_append_data(lua_State *l, struct luaL_serializer *cfg,
>         switch (field.ext_type) {
>         case MP_DECIMAL:
>         {
> -            const char *str = decimal_to_string(field.decval);
> +            const char *str = decimal_str(field.decval);
>             return json_append_string(cfg, json, str, strlen(str));
>         }
>         case MP_UUID:
> diff --git a/third_party/lua-yaml/lyaml.cc b/third_party/lua-yaml/lyaml.cc
> index 5469e9f4f..2b67dcc6a 100644
> --- a/third_party/lua-yaml/lyaml.cc
> +++ b/third_party/lua-yaml/lyaml.cc
> @@ -700,7 +700,7 @@ static int dump_node(struct lua_yaml_dumper *dumper)
>    case MP_EXT:
>       switch (field.ext_type) {
>       case MP_DECIMAL:
> -         str = decimal_to_string(field.decval);
> +         str = decimal_str(field.decval);
>          len = strlen(str);
>          break;
>       case MP_UUID:
> -- 
> 2.24.3 (Apple Git-128)
> 



More information about the Tarantool-patches mailing list