[Tarantool-patches] [PATCH v3 9/9] lua, box, datetime: rename struct datetime_t
Safin Timur
tsafin at tarantool.org
Fri Aug 6 03:27:36 MSK 2021
This change dissolved in many patches.
On 02.08.2021 3:41, Timur Safin wrote:
> Renamed all references:
> - `struct datetime_t` -> `struct datetime`;
> - `struct datetime_interval_t` -> `struct datetime_interval`.
>
> Part of #5941
> ---
> src/box/tuple_compare.cc | 10 +++++-----
> src/lib/core/datetime.c | 25 ++++++++++++-------------
> src/lib/core/datetime.h | 29 ++++++++++++++---------------
> src/lib/mpstream/mpstream.c | 3 +--
> src/lib/mpstream/mpstream.h | 5 ++---
> src/lua/datetime.lua | 6 +++---
> src/lua/msgpack.c | 2 +-
> src/lua/msgpackffi.lua | 8 ++++----
> src/lua/serializer.c | 2 +-
> src/lua/serializer.h | 2 +-
> src/lua/utils.c | 10 +++++-----
> src/lua/utils.h | 4 ++--
> test/unit/datetime.c | 17 +++++++++--------
> 13 files changed, 60 insertions(+), 63 deletions(-)
>
> diff --git a/src/box/tuple_compare.cc b/src/box/tuple_compare.cc
> index f733b9f01..530417fcc 100644
> --- a/src/box/tuple_compare.cc
> +++ b/src/box/tuple_compare.cc
> @@ -397,8 +397,8 @@ mp_compare_uuid(const char *field_a, const char *field_b)
> static int
> mp_compare_datetime(const char *lhs, const char *rhs)
> {
> - datetime_t lhs_dt, rhs_dt;
> - datetime_t *ret;
> + datetime lhs_dt, rhs_dt;
> + datetime *ret;
> ret = mp_decode_datetime(&lhs, &lhs_dt);
> assert(ret != NULL);
> ret = mp_decode_datetime(&rhs, &rhs_dt);
> @@ -1648,7 +1648,7 @@ hint_uuid_raw(const char *data)
> }
>
> static inline hint_t
> -hint_datetime(struct datetime_t *date)
> +hint_datetime(struct datetime *date)
> {
> /*
> * Use at most HINT_VALUE_SECS_BITS from datetime
> @@ -1803,7 +1803,7 @@ field_hint_datetime(const char *field)
> int8_t ext_type;
> uint32_t len = mp_decode_extl(&field, &ext_type);
> assert(ext_type == MP_DATETIME);
> - struct datetime_t date;
> + struct datetime date;
> return hint_datetime(datetime_unpack(&field, len, &date));
> }
>
> @@ -1860,7 +1860,7 @@ field_hint_scalar(const char *field, struct coll *coll)
> return hint_uuid_raw(field);
> case MP_DATETIME:
> {
> - struct datetime_t date;
> + struct datetime date;
> return hint_datetime(datetime_unpack(&field, len, &date));
> }
> default:
> diff --git a/src/lib/core/datetime.c b/src/lib/core/datetime.c
> index 96e554bd2..03facb123 100755
> --- a/src/lib/core/datetime.c
> +++ b/src/lib/core/datetime.c
> @@ -84,7 +84,7 @@ mp_decode_Xint(const char **data)
> }
>
> static inline uint32_t
> -mp_sizeof_datetime_raw(const struct datetime_t *date)
> +mp_sizeof_datetime_raw(const struct datetime *date)
> {
> uint32_t sz = mp_sizeof_Xint(date->secs);
>
> @@ -98,13 +98,13 @@ mp_sizeof_datetime_raw(const struct datetime_t *date)
> }
>
> uint32_t
> -mp_sizeof_datetime(const struct datetime_t *date)
> +mp_sizeof_datetime(const struct datetime *date)
> {
> return mp_sizeof_ext(mp_sizeof_datetime_raw(date));
> }
>
> -struct datetime_t *
> -datetime_unpack(const char **data, uint32_t len, struct datetime_t *date)
> +struct datetime *
> +datetime_unpack(const char **data, uint32_t len, struct datetime *date)
> {
> const char * svp = *data;
>
> @@ -128,8 +128,8 @@ datetime_unpack(const char **data, uint32_t len, struct datetime_t *date)
> return date;
> }
>
> -struct datetime_t *
> -mp_decode_datetime(const char **data, struct datetime_t *date)
> +struct datetime *
> +mp_decode_datetime(const char **data, struct datetime *date)
> {
> if (mp_typeof(**data) != MP_EXT)
> return NULL;
> @@ -144,7 +144,7 @@ mp_decode_datetime(const char **data, struct datetime_t *date)
> }
>
> char *
> -datetime_pack(char *data, const struct datetime_t *date)
> +datetime_pack(char *data, const struct datetime *date)
> {
> data = mp_encode_Xint(data, date->secs);
> if (date->nsec != 0 || date->offset != 0)
> @@ -156,7 +156,7 @@ datetime_pack(char *data, const struct datetime_t *date)
> }
>
> char *
> -mp_encode_datetime(char *data, const struct datetime_t *date)
> +mp_encode_datetime(char *data, const struct datetime *date)
> {
> uint32_t len = mp_sizeof_datetime_raw(date);
>
> @@ -165,8 +165,7 @@ mp_encode_datetime(char *data, const struct datetime_t *date)
> return datetime_pack(data, date);
> }
>
> -int
> -datetime_to_string(const struct datetime_t * date, char *buf, uint32_t len)
> +int datetime_to_string(const struct datetime *date, char *buf, uint32_t len)
> {
> char * src = buf;
> int offset = date->offset;
> @@ -218,7 +217,7 @@ datetime_to_string(const struct datetime_t * date, char *buf, uint32_t len)
> int
> mp_snprint_datetime(char *buf, int size, const char **data, uint32_t len)
> {
> - struct datetime_t date = {0};
> + struct datetime date = {0};
>
> if (datetime_unpack(data, len, &date) == NULL)
> return -1;
> @@ -229,7 +228,7 @@ mp_snprint_datetime(char *buf, int size, const char **data, uint32_t len)
> int
> mp_fprint_datetime(FILE *file, const char **data, uint32_t len)
> {
> - struct datetime_t date;
> + struct datetime date;
>
> if (datetime_unpack(data, len, &date) == NULL)
> return -1;
> @@ -240,7 +239,7 @@ mp_fprint_datetime(FILE *file, const char **data, uint32_t len)
> return fprintf(file, "%s", buf);
> }
>
> -int datetime_compare(const struct datetime_t *lhs, const struct datetime_t *rhs)
> +int datetime_compare(const struct datetime *lhs, const struct datetime *rhs)
> {
> int result = COMPARE_RESULT(lhs->secs, rhs->secs);
> if (result != 0)
> diff --git a/src/lib/core/datetime.h b/src/lib/core/datetime.h
> index 2c9530ad7..540bd68d9 100644
> --- a/src/lib/core/datetime.h
> +++ b/src/lib/core/datetime.h
> @@ -50,7 +50,8 @@ extern "C"
> * Time is kept normalized to UTC, time-zone offset
> * is informative only.
> */
> -struct datetime_t {
> +struct datetime
> +{
> int64_t secs; /**< seconds since epoch */
> int32_t nsec; /**< nanoseconds if any */
> int32_t offset; /**< offset in minutes from UTC */
> @@ -59,42 +60,41 @@ struct datetime_t {
> /**
> * Date/time interval structure
> */
> -struct datetime_interval_t {
> +struct datetime_interval
> +{
> int64_t secs; /**< relative seconds delta */
> int32_t nsec; /**< nanoseconds delta */
> };
>
> -int
> -datetime_compare(const struct datetime_t * lhs,
> - const struct datetime_t * rhs);
> +int datetime_compare(const struct datetime *lhs,
> + const struct datetime *rhs);
>
> -
> -struct datetime_t *
> -datetime_unpack(const char **data, uint32_t len, struct datetime_t *date);
> +struct datetime *
> +datetime_unpack(const char **data, uint32_t len, struct datetime *date);
>
> /**
> * Pack datetime_t data to the MessagePack buffer.
> */
> char *
> -datetime_pack(char *data, const struct datetime_t *date);
> +datetime_pack(char *data, const struct datetime *date);
>
> /**
> * Calculate size of MessagePack buffer for datetime_t data.
> */
> uint32_t
> -mp_sizeof_datetime(const struct datetime_t *date);
> +mp_sizeof_datetime(const struct datetime *date);
>
> /**
> * Decode data from MessagePack buffer to datetime_t structure.
> */
> -struct datetime_t *
> -mp_decode_datetime(const char **data, struct datetime_t *date);
> +struct datetime *
> +mp_decode_datetime(const char **data, struct datetime *date);
>
> /**
> * Encode datetime_t structure to the MessagePack buffer.
> */
> char *
> -mp_encode_datetime(char *data, const struct datetime_t *date);
> +mp_encode_datetime(char *data, const struct datetime *date);
>
> /**
> * Convert datetime to string using default format
> @@ -102,8 +102,7 @@ mp_encode_datetime(char *data, const struct datetime_t *date);
> * @param buf output character buffer
> * @param len size ofoutput buffer
> */
> -int
> -datetime_to_string(const struct datetime_t * date, char *buf, uint32_t len);
> +int datetime_to_string(const struct datetime *date, char *buf, uint32_t len);
>
> int
> mp_snprint_datetime(char *buf, int size, const char **data, uint32_t len);
> diff --git a/src/lib/mpstream/mpstream.c b/src/lib/mpstream/mpstream.c
> index 1077e3b19..2af77c205 100644
> --- a/src/lib/mpstream/mpstream.c
> +++ b/src/lib/mpstream/mpstream.c
> @@ -209,8 +209,7 @@ mpstream_encode_uuid(struct mpstream *stream, const struct tt_uuid *uuid)
> mpstream_advance(stream, pos - data);
> }
>
> -void
> -mpstream_encode_datetime(struct mpstream *stream, const struct datetime_t *val)
> +void mpstream_encode_datetime(struct mpstream *stream, const struct datetime *val)
> {
> char *data = mpstream_reserve(stream, mp_sizeof_datetime(val));
> if (data == NULL)
> diff --git a/src/lib/mpstream/mpstream.h b/src/lib/mpstream/mpstream.h
> index 540e9a666..9e0ed6e72 100644
> --- a/src/lib/mpstream/mpstream.h
> +++ b/src/lib/mpstream/mpstream.h
> @@ -39,7 +39,7 @@ extern "C" {
> #endif /* defined(__cplusplus) */
>
> struct tt_uuid;
> -struct datetime_t;
> +struct datetime;
>
> /**
> * Ask the allocator to reserve at least size bytes. It can reserve
> @@ -146,8 +146,7 @@ mpstream_encode_decimal(struct mpstream *stream, const decimal_t *val);
> void
> mpstream_encode_uuid(struct mpstream *stream, const struct tt_uuid *uuid);
>
> -void
> -mpstream_encode_datetime(struct mpstream *stream, const struct datetime_t *dt);
> +void mpstream_encode_datetime(struct mpstream *stream, const struct datetime *dt);
>
> /** Copies n bytes from memory area src to stream. */
> void
> diff --git a/src/lua/datetime.lua b/src/lua/datetime.lua
> index dc88a9d9d..5cad4e02f 100644
> --- a/src/lua/datetime.lua
> +++ b/src/lua/datetime.lua
> @@ -80,7 +80,7 @@ ffi.cdef [[
> // datetime.c
>
> int
> - datetime_to_string(const struct datetime_t * date, char *buf, uint32_t len);
> + datetime_to_string(const struct datetime * date, char *buf, uint32_t len);
>
>
> // <asm-generic/posix_types.h>
> @@ -180,8 +180,8 @@ local NANOS_PER_SEC = 1000000000LL
> local DT_EPOCH_1970_OFFSET = 719163LL
>
>
> -local datetime_t = ffi.typeof('struct datetime_t')
> -local interval_t = ffi.typeof('struct datetime_interval_t')
> +local datetime_t = ffi.typeof('struct datetime')
> +local interval_t = ffi.typeof('struct datetime_interval')
> ffi.cdef [[
> struct t_interval_months {
> int m;
> diff --git a/src/lua/msgpack.c b/src/lua/msgpack.c
> index 0a4ba8129..9c1acc4dc 100644
> --- a/src/lua/msgpack.c
> +++ b/src/lua/msgpack.c
> @@ -339,7 +339,7 @@ luamp_decode(struct lua_State *L, struct luaL_serializer *cfg,
> }
> case MP_DATETIME:
> {
> - struct datetime_t * date = luaL_pushdatetime(L);
> + struct datetime *date = luaL_pushdatetime(L);
> date = datetime_unpack(data, len, date);
> if (date == NULL)
> goto ext_decode_err;
> diff --git a/src/lua/msgpackffi.lua b/src/lua/msgpackffi.lua
> index c47d77acb..fb5e7d644 100644
> --- a/src/lua/msgpackffi.lua
> +++ b/src/lua/msgpackffi.lua
> @@ -40,8 +40,8 @@ decimal_t *
> decimal_unpack(const char **data, uint32_t len, decimal_t *dec);
> struct tt_uuid *
> uuid_unpack(const char **data, uint32_t len, struct tt_uuid *uuid);
> -struct datetime_t *
> -datetime_unpack(const char **data, uint32_t len, struct datetime_t *date);
> +struct datetime *
> +datetime_unpack(const char **data, uint32_t len, struct datetime *date);
> ]])
>
> local strict_alignment = (jit.arch == 'arm')
> @@ -331,7 +331,7 @@ on_encode(ffi.typeof('float'), encode_float)
> on_encode(ffi.typeof('double'), encode_double)
> on_encode(ffi.typeof('decimal_t'), encode_decimal)
> on_encode(ffi.typeof('struct tt_uuid'), encode_uuid)
> -on_encode(ffi.typeof('struct datetime_t'), encode_datetime)
> +on_encode(ffi.typeof('struct datetime'), encode_datetime)
>
> --------------------------------------------------------------------------------
> -- Decoder
> @@ -527,7 +527,7 @@ local ext_decoder = {
> end,
> -- MP_DATETIME
> [4] = function(data, len)
> - local dt = ffi.new("struct datetime_t")
> + local dt = ffi.new("struct datetime")
> builtin.datetime_unpack(data, len, dt)
> return dt
> end,
> diff --git a/src/lua/serializer.c b/src/lua/serializer.c
> index c27e62c62..24f4a5ff9 100644
> --- a/src/lua/serializer.c
> +++ b/src/lua/serializer.c
> @@ -547,7 +547,7 @@ luaL_tofield(struct lua_State *L, struct luaL_serializer *cfg,
> field->ext_type = MP_ERROR;
> } else if (cd->ctypeid == CTID_DATETIME) {
> field->ext_type = MP_DATETIME;
> - field->dateval = (struct datetime_t*) cdata;
> + field->dateval = (struct datetime *)cdata;
> } else {
> field->ext_type = MP_UNKNOWN_EXTENSION;
> }
> diff --git a/src/lua/serializer.h b/src/lua/serializer.h
> index 52e51d279..e7a240e0a 100644
> --- a/src/lua/serializer.h
> +++ b/src/lua/serializer.h
> @@ -224,7 +224,7 @@ struct luaL_field {
> uint32_t size;
> decimal_t *decval;
> struct tt_uuid *uuidval;
> - struct datetime_t *dateval;
> + struct datetime *dateval;
> };
> enum mp_type type;
> /* subtypes of MP_EXT */
> diff --git a/src/lua/utils.c b/src/lua/utils.c
> index 685cab47b..9753016c9 100644
> --- a/src/lua/utils.c
> +++ b/src/lua/utils.c
> @@ -110,7 +110,7 @@ luaL_pushuuid(struct lua_State *L)
> return luaL_pushcdata(L, CTID_UUID);
> }
>
> -struct datetime_t *
> +struct datetime *
> luaL_pushdatetime(struct lua_State *L)
> {
> return luaL_pushcdata(L, CTID_DATETIME);
> @@ -720,22 +720,22 @@ tarantool_lua_utils_init(struct lua_State *L)
> CTID_UUID = luaL_ctypeid(L, "struct tt_uuid");
> assert(CTID_UUID != 0);
>
> - rc = luaL_cdef(L, "struct datetime_t {"
> + rc = luaL_cdef(L, "struct datetime {"
> "int64_t secs;"
> "int32_t nsec;"
> "int32_t offset;"
> "};");
> assert(rc == 0);
> (void) rc;
> - CTID_DATETIME = luaL_ctypeid(L, "struct datetime_t");
> + CTID_DATETIME = luaL_ctypeid(L, "struct datetime");
> assert(CTID_DATETIME != 0);
> - rc = luaL_cdef(L, "struct datetime_interval_t {"
> + rc = luaL_cdef(L, "struct datetime_interval {"
> "int64_t secs;"
> "int32_t nsec;"
> "};");
> assert(rc == 0);
> (void) rc;
> - CTID_INTERVAL = luaL_ctypeid(L, "struct datetime_interval_t");
> + CTID_INTERVAL = luaL_ctypeid(L, "struct datetime_interval");
> assert(CTID_INTERVAL != 0);
>
> lua_pushcfunction(L, luaT_newthread_wrapper);
> diff --git a/src/lua/utils.h b/src/lua/utils.h
> index bf56b1bb5..c27065a1c 100644
> --- a/src/lua/utils.h
> +++ b/src/lua/utils.h
> @@ -59,7 +59,7 @@ struct lua_State;
> struct ibuf;
> typedef struct ibuf box_ibuf_t;
> struct tt_uuid;
> -struct datetime_t;
> +struct datetime;
>
> /**
> * Single global lua_State shared by core and modules.
> @@ -84,7 +84,7 @@ luaL_pushuuid(struct lua_State *L);
> * @sa luaL_pushcdata
> * @return memory associated with this datetime_t data
> */
> -struct datetime_t *
> +struct datetime *
> luaL_pushdatetime(struct lua_State *L);
>
> /** \cond public */
> diff --git a/test/unit/datetime.c b/test/unit/datetime.c
> index 226b6fadb..e8a022542 100644
> --- a/test/unit/datetime.c
> +++ b/test/unit/datetime.c
> @@ -141,26 +141,27 @@ exit:
> #define SECS_PER_DAY 86400
> #define DT_EPOCH_1970_OFFSET 719163
>
> -
> -struct datetime_t {
> +struct datetime
> +{
> int64_t secs;
> int32_t nsec;
> int32_t offset;
> };
>
> static int
> -local_rd(const struct datetime_t * dt) {
> +local_rd(const struct datetime *dt)
> +{
> return (int)(dt->secs / SECS_PER_DAY) + DT_EPOCH_1970_OFFSET;
> }
>
> static int
> -local_dt(const struct datetime_t * dt) {
> +local_dt(const struct datetime *dt)
> +{
> return dt_from_rdn(local_rd(dt));
> }
>
> -
> -struct tm*
> -datetime_to_tm(struct datetime_t * dt)
> +struct tm *
> +datetime_to_tm(struct datetime *dt)
> {
> static struct tm tm;
>
> @@ -198,7 +199,7 @@ static void datetime_test(void)
> // check that stringized literal produces the same date
> // time fields
> static char buff[40];
> - struct datetime_t dt = {secs, nanosecs, ofs};
> + struct datetime dt = {secs, nanosecs, ofs};
> // datetime_to_tm returns time in GMT zone
> struct tm * p_tm = datetime_to_tm(&dt);
> size_t len = strftime(buff, sizeof buff, "%F %T%z", p_tm);
>
More information about the Tarantool-patches
mailing list