From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 9E75B6EC56; Thu, 15 Jul 2021 11:22:53 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 9E75B6EC56 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1626337373; bh=UNI0bO9ma2xnkEqJ7HiK/DSkOPlEO7+OtrL9OcBZsVA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=fmTVKyDmiA2lHLQfG+0UYEqDjFVvTAuBdFu+w6rl1DcvcI4pNhw8A5UMj+CHpWL3R LWnP+26vCeGlfNHcy5RSxPLWZ8zszQE+9I+GZ6lTifnRqpEv1QCsYOQws4DIMbYs23 KBUVRNjluStYdr8gRgQsPLhK0iMngYaem6aIhFfA= Received: from smtp57.i.mail.ru (smtp57.i.mail.ru [217.69.128.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 92F896F3C3 for ; Thu, 15 Jul 2021 11:18:58 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 92F896F3C3 Received: by smtp57.i.mail.ru with esmtpa (envelope-from ) id 1m3wa9-00070N-CD; Thu, 15 Jul 2021 11:18:57 +0300 To: v.shpilevoy@tarantool.org Date: Thu, 15 Jul 2021 11:18:14 +0300 Message-Id: X-Mailer: git-send-email 2.29.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD941C43E597735A9C30288BCF456A452ECBCD3030350682103182A05F538085040CCCF3B9BE425901E438BA3DF5FF9481CAA26E4A007FBD8E81709240D0605C5B8 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE79145AB6E9E75F07EEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637A005C90FB6EB35FF8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8C4A4EFEB5C0DB27F955F4F10F9F3A478117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BF1175FABE1C0F9B6A471835C12D1D977C4224003CC836476EB9C4185024447017B076A6E789B0E975F5C1EE8F4F765FCB918EA994890DB543AA81AA40904B5D9CF19DD082D7633A078D18283394535A93AA81AA40904B5D98AA50765F79006372BC0189147983080D81D268191BDAD3D698AB9A7B718F8C4D1B931868CE1C5781A620F70A64A45A98AA50765F79006372E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89F83C798A30B85E16B262FEC7FBD7D1F5BB5C8C57E37DE458BEDA766A37F9254B7 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CE68746B1F2AB10C62DE690B63ABE9B07120F9A73945C52D89C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF3033054805BDE987699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34F38194B2C99DC1286391551CCD53ABE6422A984E619DF2476B3C185E5E6FF41A6598F22AEF0920F91D7E09C32AA3244C22CFD73CFB8CCB6C1082F71EEE2DE01F725D5B54B2FE457583B48618A63566E0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXjnYxxC9kpVbyZqo8ci0UXQ X-Mailru-Sender: B5B6A6EBBD94DAD8DA84A184D75F19DB2E7B7B20C3E75D0F458D73B47994BF24638536D5762F0A4A1EC9E4A2C82A33BC8C24925A86E657CE0C70AEE3C9A96FBAB3D7EE8ED63280BE112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: [Tarantool-patches] [RFC PATCH 08/13] box, lua: renamed t_datetime_tz structure to datetime_t X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Timur Safin via Tarantool-patches Reply-To: Timur Safin Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" --- src/box/tuple_compare.cc | 4 ++-- src/lib/core/datetime.h | 22 +++++++++++----------- src/lib/core/mp_datetime.c | 24 ++++++++++++------------ src/lib/mpstream/mpstream.c | 2 +- src/lib/mpstream/mpstream.h | 4 ++-- src/lua/datetime.c | 6 +++--- src/lua/datetime.h | 2 +- src/lua/datetime.lua | 2 +- src/lua/msgpack.c | 2 +- src/lua/msgpackffi.lua | 6 +++--- src/lua/serializer.c | 2 +- src/lua/serializer.h | 2 +- src/lua/utils.c | 1 - test/unit/datetime.c | 21 ++++++++++----------- 14 files changed, 49 insertions(+), 51 deletions(-) diff --git a/src/box/tuple_compare.cc b/src/box/tuple_compare.cc index 39c9dd6e9..28814428c 100644 --- a/src/box/tuple_compare.cc +++ b/src/box/tuple_compare.cc @@ -401,8 +401,8 @@ mp_compare_uuid(const char *field_a, const char *field_b) static int mp_compare_datetime(const char *lhs, const char *rhs) { - t_datetime_tz lhs_dt, rhs_dt; - t_datetime_tz *ret; + datetime_t lhs_dt, rhs_dt; + datetime_t *ret; ret = mp_decode_datetime(&lhs, &lhs_dt); assert(ret != NULL); ret = mp_decode_datetime(&rhs, &rhs_dt); diff --git a/src/lib/core/datetime.h b/src/lib/core/datetime.h index bd23f33a3..b289b0486 100644 --- a/src/lib/core/datetime.h +++ b/src/lib/core/datetime.h @@ -47,7 +47,7 @@ extern "C" { /** * datetime structure consisting of: */ -struct t_datetime_tz { +struct datetime_t { int secs; ///< seconds since epoch int nsec; ///< nanoseconds if any int offset; ///< offset in minutes from GMT @@ -62,27 +62,27 @@ struct t_datetime_duration { }; int -datetime_compare(const struct t_datetime_tz * lhs, - const struct t_datetime_tz * rhs); +datetime_compare(const struct datetime_t * lhs, + const struct datetime_t * rhs); -struct t_datetime_tz * -datetime_unpack(const char **data, uint32_t len, struct t_datetime_tz *date); +struct datetime_t * +datetime_unpack(const char **data, uint32_t len, struct datetime_t *date); char * -datetime_pack(char *data, const struct t_datetime_tz *date); +datetime_pack(char *data, const struct datetime_t *date); uint32_t -mp_sizeof_datetime(const struct t_datetime_tz *date); +mp_sizeof_datetime(const struct datetime_t *date); -struct t_datetime_tz * -mp_decode_datetime(const char **data, struct t_datetime_tz *date); +struct datetime_t * +mp_decode_datetime(const char **data, struct datetime_t *date); char * -mp_encode_datetime(char *data, const struct t_datetime_tz *date); +mp_encode_datetime(char *data, const struct datetime_t *date); int -datetime_to_string(const struct t_datetime_tz * date, char *buf, uint32_t len); +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); diff --git a/src/lib/core/mp_datetime.c b/src/lib/core/mp_datetime.c index 2cf3fd79b..ad18f00c8 100644 --- a/src/lib/core/mp_datetime.c +++ b/src/lib/core/mp_datetime.c @@ -63,7 +63,7 @@ mp_decode_Xint(const char **data) } uint32_t -mp_sizeof_datetime(const struct t_datetime_tz *date) +mp_sizeof_datetime(const struct datetime_t *date) { uint32_t sz = mp_sizeof_Xint(date->secs); @@ -77,8 +77,8 @@ mp_sizeof_datetime(const struct t_datetime_tz *date) return sz; } -struct t_datetime_tz * -datetime_unpack(const char **data, uint32_t len, struct t_datetime_tz *date) +struct datetime_t * +datetime_unpack(const char **data, uint32_t len, struct datetime_t *date) { const char * svp = *data; @@ -102,8 +102,8 @@ datetime_unpack(const char **data, uint32_t len, struct t_datetime_tz *date) return date; } -struct t_datetime_tz * -mp_decode_datetime(const char **data, struct t_datetime_tz *date) +struct datetime_t * +mp_decode_datetime(const char **data, struct datetime_t *date) { if (mp_typeof(**data) != MP_EXT) return NULL; @@ -118,7 +118,7 @@ mp_decode_datetime(const char **data, struct t_datetime_tz *date) } char * -datetime_pack(char *data, const struct t_datetime_tz *date) +datetime_pack(char *data, const struct datetime_t *date) { data = mp_encode_Xint(data, date->secs); if (date->nsec != 0 || date->offset != 0) @@ -130,7 +130,7 @@ datetime_pack(char *data, const struct t_datetime_tz *date) } char * -mp_encode_datetime(char *data, const struct t_datetime_tz *date) +mp_encode_datetime(char *data, const struct datetime_t *date) { uint32_t len = mp_sizeof_datetime(date); @@ -140,7 +140,7 @@ mp_encode_datetime(char *data, const struct t_datetime_tz *date) } int -datetime_to_string(const struct t_datetime_tz * date, char *buf, uint32_t len) +datetime_to_string(const struct datetime_t * date, char *buf, uint32_t len) { char * src = buf; int offset = date->offset; @@ -191,7 +191,7 @@ datetime_to_string(const struct t_datetime_tz * date, char *buf, uint32_t len) int mp_snprint_datetime(char *buf, int size, const char **data, uint32_t len) { - struct t_datetime_tz date = {0}; + struct datetime_t date = {0}; if (datetime_unpack(data, len, &date) == NULL) return -1; @@ -202,7 +202,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 t_datetime_tz date; + struct datetime_t date; if (datetime_unpack(data, len, &date) == NULL) return -1; @@ -220,8 +220,8 @@ adjusted_secs(int secs, int offset) } int -datetime_compare(const struct t_datetime_tz * lhs, - const struct t_datetime_tz * rhs) +datetime_compare(const struct datetime_t * lhs, + const struct datetime_t * rhs) { int result = COMPARE_RESULT(adjusted_secs(lhs->secs, lhs->offset), adjusted_secs(rhs->secs, rhs->offset)); diff --git a/src/lib/mpstream/mpstream.c b/src/lib/mpstream/mpstream.c index 8c92b4049..1077e3b19 100644 --- a/src/lib/mpstream/mpstream.c +++ b/src/lib/mpstream/mpstream.c @@ -210,7 +210,7 @@ mpstream_encode_uuid(struct mpstream *stream, const struct tt_uuid *uuid) } void -mpstream_encode_datetime(struct mpstream *stream, const struct t_datetime_tz *val) +mpstream_encode_datetime(struct mpstream *stream, const struct datetime_t *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 39e8fd956..540e9a666 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 t_datetime_tz; +struct datetime_t; /** * Ask the allocator to reserve at least size bytes. It can reserve @@ -147,7 +147,7 @@ void mpstream_encode_uuid(struct mpstream *stream, const struct tt_uuid *uuid); void -mpstream_encode_datetime(struct mpstream *stream, const struct t_datetime_tz *dt); +mpstream_encode_datetime(struct mpstream *stream, const struct datetime_t *dt); /** Copies n bytes from memory area src to stream. */ void diff --git a/src/lua/datetime.c b/src/lua/datetime.c index 215cb89fb..a4f9915e0 100644 --- a/src/lua/datetime.c +++ b/src/lua/datetime.c @@ -39,7 +39,7 @@ uint32_t CTID_DATETIME_TZ = 0; uint32_t CTID_DURATION = 0; -struct t_datetime_tz * +struct datetime_t * luaL_pushdatetime(struct lua_State *L) { return luaL_pushcdata(L, CTID_DATETIME_TZ); @@ -48,14 +48,14 @@ luaL_pushdatetime(struct lua_State *L) void tarantool_lua_datetime_init(struct lua_State *L) { - int rc = luaL_cdef(L, "struct t_datetime_tz {" + int rc = luaL_cdef(L, "struct datetime_t {" "int secs;" "int nsec;" "int offset;" "};"); assert(rc == 0); (void) rc; - CTID_DATETIME_TZ = luaL_ctypeid(L, "struct t_datetime_tz"); + CTID_DATETIME_TZ = luaL_ctypeid(L, "struct datetime_t"); assert(CTID_DATETIME_TZ != 0); diff --git a/src/lua/datetime.h b/src/lua/datetime.h index 38ba53561..cee96ca06 100644 --- a/src/lua/datetime.h +++ b/src/lua/datetime.h @@ -42,7 +42,7 @@ extern uint32_t CTID_DURATION; struct lua_State; -struct t_datetime_tz* +struct datetime_t* luaL_pushdatetime(struct lua_State *L); void diff --git a/src/lua/datetime.lua b/src/lua/datetime.lua index efd953de9..086c97697 100644 --- a/src/lua/datetime.lua +++ b/src/lua/datetime.lua @@ -150,7 +150,7 @@ local NANOS_PER_SEC = 1000000000LL local DT_EPOCH_1970_OFFSET = 719163LL -local datetime_t = ffi.typeof('struct t_datetime_tz') +local datetime_t = ffi.typeof('struct datetime_t') local duration_t = ffi.typeof('struct t_datetime_duration') local function duration_new() diff --git a/src/lua/msgpack.c b/src/lua/msgpack.c index dd2c41056..0a4ba8129 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 t_datetime_tz * date = luaL_pushdatetime(L); + struct datetime_t * 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 2613cf216..271be857a 100644 --- a/src/lua/msgpackffi.lua +++ b/src/lua/msgpackffi.lua @@ -36,8 +36,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 t_datetime_tz * -datetime_unpack(const char **data, uint32_t len, struct t_datetime_tz *date); +struct datetime_t * +datetime_unpack(const char **data, uint32_t len, struct datetime_t *date); ]]) local strict_alignment = (jit.arch == 'arm') @@ -517,7 +517,7 @@ local ext_decoder = { end, -- MP_DATETIME [4] = function(data, len) - local dt = ffi.new("struct t_datetime_tz") + local dt = ffi.new("struct datetime_t") builtin.datetime_unpack(data, len, dt) return dt end, diff --git a/src/lua/serializer.c b/src/lua/serializer.c index 55120a725..160d6fe7e 100644 --- a/src/lua/serializer.c +++ b/src/lua/serializer.c @@ -543,7 +543,7 @@ luaL_tofield(struct lua_State *L, struct luaL_serializer *cfg, field->uuidval = (struct tt_uuid *) cdata; } else if (cd->ctypeid == CTID_DATETIME_TZ) { field->ext_type = MP_DATETIME; - field->dateval = (struct t_datetime_tz *) cdata; + field->dateval = (struct datetime_t *) cdata; } else if (cd->ctypeid == CTID_CONST_STRUCT_ERROR_REF && opts != NULL && opts->error_marshaling_enabled) { diff --git a/src/lua/serializer.h b/src/lua/serializer.h index ec62c723f..52e51d279 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 t_datetime_tz *dateval; + struct datetime_t *dateval; }; enum mp_type type; /* subtypes of MP_EXT */ diff --git a/src/lua/utils.c b/src/lua/utils.c index 34cec0eed..5ec0ce135 100644 --- a/src/lua/utils.c +++ b/src/lua/utils.c @@ -232,7 +232,6 @@ luaL_setcdatagc(struct lua_State *L, int idx) lua_pop(L, 1); } - /** * A helper to register a single type metatable. */ diff --git a/test/unit/datetime.c b/test/unit/datetime.c index f74ac139d..7e0229758 100644 --- a/test/unit/datetime.c +++ b/test/unit/datetime.c @@ -129,36 +129,35 @@ parse_datetime(const char *str, size_t len, int64_t *sp, int64_t *np, // avoid introducing external datetime.h dependency // - just copy paste it for today #define SECS_PER_DAY 86400 -#define NANOS_PER_SEC 1000000000 #define DT_EPOCH_1970_OFFSET 719163 -struct t_datetime_tz { - int64_t sec; +struct datetime_t { + int64_t secs; int64_t nsec; int64_t offset; }; static int -local_rd(const struct t_datetime_tz * dt) { - return (int)(dt->sec / SECS_PER_DAY) + DT_EPOCH_1970_OFFSET; +local_rd(const struct datetime_t * dt) { + return (int)(dt->secs / SECS_PER_DAY) + DT_EPOCH_1970_OFFSET; } static int -local_dt(const struct t_datetime_tz * dt) { +local_dt(const struct datetime_t * dt) { return dt_from_rdn(local_rd(dt)); } struct tm* -datetime_to_tm(struct t_datetime_tz * dt) +datetime_to_tm(struct datetime_t * dt) { static struct tm tm; memset(&tm, 0, sizeof(tm)); dt_to_struct_tm(local_dt(dt), &tm); - int seconds_of_day = dt->sec % 86400; + int seconds_of_day = dt->secs % 86400; tm.tm_hour = (seconds_of_day / 3600) % 24; tm.tm_min = (seconds_of_day / 60) % 60; tm.tm_sec = seconds_of_day % 60; @@ -189,14 +188,14 @@ static void datetime_test(void) // check that stringized literal produces the same date // time fields static char buff[40]; - struct t_datetime_tz dt = {secs, nanosecs, ofs}; + struct datetime_t 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); ok(len > 0, "strftime"); - rc = parse_datetime(buff, len, &dt.sec, &dt.nsec, &dt.offset); + rc = parse_datetime(buff, len, &dt.secs, &dt.nsec, &dt.offset); is(rc, 0, "correct parse_datetime return value for '%s'", buff); - is(secs, dt.sec, + is(secs, dt.secs, "reversible seconds via strftime for '%s", buff); } } -- 2.29.2