From: Timur Safin via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: v.shpilevoy@tarantool.org, olegrok@tarantool.org Cc: tarantool-patches@dev.tarantool.org Subject: [Tarantool-patches] [PATCH v3 9/9] lua, box, datetime: rename struct datetime_t Date: Mon, 2 Aug 2021 03:41:05 +0300 [thread overview] Message-ID: <c70ac075b28f84b52ade49eb089d0d2a8cdfeb62.1627864075.git.tsafin@tarantool.org> (raw) In-Reply-To: <cover.1627864075.git.tsafin@tarantool.org> 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); -- 2.29.2
next prev parent reply other threads:[~2021-08-02 0:46 UTC|newest] Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-08-02 0:40 [Tarantool-patches] [PATCH v3 0/9] Initial datetime support Timur Safin via Tarantool-patches 2021-08-02 0:40 ` [Tarantool-patches] [PATCH v3 1/9] build: add Christian Hansen c-dt to the build Timur Safin via Tarantool-patches 2021-08-04 23:58 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-05 8:55 ` Safin Timur via Tarantool-patches 2021-08-08 14:34 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-02 0:40 ` [Tarantool-patches] [PATCH v3 2/9] lua: built-in module datetime Timur Safin via Tarantool-patches 2021-08-04 23:58 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-06 0:23 ` Safin Timur via Tarantool-patches 2021-08-06 1:30 ` Oleg Babin via Tarantool-patches 2021-08-06 13:00 ` Safin Timur via Tarantool-patches 2021-08-06 17:24 ` Safin Timur via Tarantool-patches 2021-08-08 11:26 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-08 16:35 ` Safin Timur via Tarantool-patches 2021-08-10 12:20 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-10 12:21 ` Igor Munkin via Tarantool-patches 2021-08-12 20:47 ` Safin Timur via Tarantool-patches 2021-08-15 20:52 ` Safin Timur via Tarantool-patches 2021-08-06 0:26 ` Safin Timur via Tarantool-patches 2021-08-08 14:34 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-08 16:47 ` Safin Timur via Tarantool-patches 2021-08-02 0:40 ` [Tarantool-patches] [PATCH v3 3/9] lua, datetime: datetime tests Timur Safin via Tarantool-patches 2021-08-06 0:25 ` Safin Timur via Tarantool-patches 2021-08-02 0:41 ` [Tarantool-patches] [PATCH v3 4/9] lua, datetime: display datetime Timur Safin via Tarantool-patches 2021-08-02 0:41 ` [Tarantool-patches] [PATCH v3 5/9] box, datetime: messagepack support for datetime Timur Safin via Tarantool-patches 2021-08-03 13:38 ` Timur Safin via Tarantool-patches 2021-08-02 0:41 ` [Tarantool-patches] [PATCH v3 6/9] box, datetime: datetime comparison for indices Timur Safin via Tarantool-patches 2021-08-03 12:02 ` Serge Petrenko via Tarantool-patches 2021-08-03 12:59 ` Timur Safin via Tarantool-patches 2021-08-04 10:12 ` Timur Safin via Tarantool-patches 2021-08-02 0:41 ` [Tarantool-patches] [PATCH v3 7/9] lua, datetime: time intervals support Timur Safin via Tarantool-patches 2021-08-02 0:41 ` [Tarantool-patches] [PATCH v3 8/9] datetime: changelog for datetime module Timur Safin via Tarantool-patches 2021-08-02 0:41 ` Timur Safin via Tarantool-patches [this message] 2021-08-06 0:27 ` [Tarantool-patches] [PATCH v3 9/9] lua, box, datetime: rename struct datetime_t Safin Timur via Tarantool-patches 2021-08-03 21:23 ` [Tarantool-patches] [PATCH v3 1/2] datetime: update tests for macosx Timur Safin via Tarantool-patches 2021-08-06 0:28 ` Safin Timur via Tarantool-patches 2021-08-03 21:23 ` [Tarantool-patches] [PATCH v3 2/2] lua, datetime: introduce ctime, strftime wrappers Timur Safin via Tarantool-patches 2021-08-06 0:30 ` Safin Timur via Tarantool-patches 2021-08-03 21:26 ` [Tarantool-patches] [PATCH v3 0/9] Initial datetime support Timur Safin via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=c70ac075b28f84b52ade49eb089d0d2a8cdfeb62.1627864075.git.tsafin@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=olegrok@tarantool.org \ --cc=tsafin@tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v3 9/9] lua, box, datetime: rename struct datetime_t' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox