From: Serge Petrenko <sergepetrenko@tarantool.org> To: vdavydov.dev@gmail.com Cc: tarantool-patches@freelists.org, kostja@tarantool.org, Serge Petrenko <sergepetrenko@tarantool.org> Subject: [PATCH v2 1/8] lua: fix decimal comparison with nil Date: Thu, 8 Aug 2019 14:55:52 +0300 [thread overview] Message-ID: <af34745174a7b8094bb542ceac57d42e1600fbd6.1565263272.git.sergepetrenko@tarantool.org> (raw) In-Reply-To: <cover.1565263272.git.sergepetrenko@tarantool.org> Previously decimal comparison with nil failed with following error: `expected decimal, number or string as 2 argument`. Fix this. Follow-up #692 --- src/lua/decimal.c | 4 ++++ test/app/decimal.result | 26 ++++++++++++++++++++++++++ test/app/decimal.test.lua | 8 ++++++++ 3 files changed, 38 insertions(+) diff --git a/src/lua/decimal.c b/src/lua/decimal.c index 330f4c3f8..e480ec7be 100644 --- a/src/lua/decimal.c +++ b/src/lua/decimal.c @@ -69,6 +69,10 @@ ldecimal_##name(struct lua_State *L) { \ static int \ ldecimal_##name(struct lua_State *L) { \ assert(lua_gettop(L) == 2); \ + if (lua_isnil(L, 1) || lua_isnil(L, 2)) { \ + lua_pushboolean(L, false); \ + return 1; \ + } \ decimal_t *lhs = lua_todecimal(L, 1); \ decimal_t *rhs = lua_todecimal(L, 2); \ lua_pushboolean(L, decimal_compare(lhs, rhs) cmp 0); \ diff --git a/test/app/decimal.result b/test/app/decimal.result index b53f4e75d..633f3681a 100644 --- a/test/app/decimal.result +++ b/test/app/decimal.result @@ -223,6 +223,32 @@ b | - '0.1' | ... +-- check comparsion with nil +a == nil + | --- + | - false + | ... +a ~= nil + | --- + | - true + | ... +a > nil + | --- + | - false + | ... +a < nil + | --- + | - false + | ... +a >= nil + | --- + | - false + | ... +a <= nil + | --- + | - false + | ... + decimal.sqrt(a) | --- | - '3.1622776601683793319988935444327185337' diff --git a/test/app/decimal.test.lua b/test/app/decimal.test.lua index cee56d5e7..cb14dfb56 100644 --- a/test/app/decimal.test.lua +++ b/test/app/decimal.test.lua @@ -62,6 +62,14 @@ a ~= b a b +-- check comparsion with nil +a == nil +a ~= nil +a > nil +a < nil +a >= nil +a <= nil + decimal.sqrt(a) decimal.ln(a) decimal.log10(a) -- 2.20.1 (Apple Git-117)
next prev parent reply other threads:[~2019-08-08 11:55 UTC|newest] Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-08-08 11:55 [PATCH v2 0/8] Decimal indices Serge Petrenko 2019-08-08 11:55 ` Serge Petrenko [this message] 2019-08-12 21:16 ` [PATCH v2 1/8] lua: fix decimal comparison with nil Konstantin Osipov 2019-08-14 11:00 ` Vladimir Davydov 2019-08-14 22:17 ` Konstantin Osipov 2019-08-08 11:55 ` [PATCH v2 2/8] decimal: fix encoding numbers with positive exponent Serge Petrenko 2019-08-12 21:18 ` Konstantin Osipov 2019-08-13 9:00 ` [tarantool-patches] " Serge Petrenko 2019-08-14 22:21 ` Konstantin Osipov 2019-08-14 11:56 ` Vladimir Davydov 2019-08-08 11:55 ` [PATCH v2 3/8] lua/pickle: fix a typo Serge Petrenko 2019-08-12 21:18 ` Konstantin Osipov 2019-08-14 11:12 ` Vladimir Davydov 2019-08-14 11:15 ` Serge Petrenko 2019-08-08 11:55 ` [PATCH v2 4/8] lua: rework luaL_field types to support msgpack extensions Serge Petrenko 2019-08-12 21:23 ` Konstantin Osipov 2019-08-13 13:15 ` [tarantool-patches] " Serge Petrenko 2019-08-14 22:23 ` Konstantin Osipov 2019-08-15 8:27 ` Serge Petrenko 2019-08-16 8:06 ` Konstantin Osipov 2019-08-08 11:55 ` [PATCH v2 5/8] box: rework field_def and tuple_compare to work with mp_field_type instead of mp_type Serge Petrenko 2019-08-12 21:28 ` Konstantin Osipov 2019-08-08 11:55 ` [PATCH v2 6/8] decimal: allow to encode/decode decimals as MsgPack Serge Petrenko 2019-08-12 21:29 ` Konstantin Osipov 2019-08-12 21:34 ` Konstantin Osipov 2019-08-13 14:01 ` Serge Petrenko 2019-08-14 22:25 ` Konstantin Osipov 2019-08-08 11:55 ` [PATCH v2 7/8] decimal: add conversions to (u)int64_t Serge Petrenko 2019-08-12 21:39 ` Konstantin Osipov 2019-08-13 14:18 ` Serge Petrenko 2019-08-14 22:26 ` Konstantin Osipov 2019-08-14 22:29 ` Konstantin Osipov 2019-08-08 11:55 ` [PATCH v2 8/8] decimal: allow to index decimals Serge Petrenko 2019-08-08 13:42 ` Serge Petrenko 2019-08-12 21:41 ` Konstantin Osipov
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=af34745174a7b8094bb542ceac57d42e1600fbd6.1565263272.git.sergepetrenko@tarantool.org \ --to=sergepetrenko@tarantool.org \ --cc=kostja@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=vdavydov.dev@gmail.com \ --subject='Re: [PATCH v2 1/8] lua: fix decimal comparison with nil' \ /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