Tarantool development patches archive
 help / color / mirror / Atom feed
From: Alexander Turenko <alexander.turenko@tarantool.org>
To: Maria Khaydich <maria.khaydich@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH] Msgpackffi considers msgpack.cfg options now
Date: Wed, 18 Dec 2019 02:26:35 +0300	[thread overview]
Message-ID: <20191217232635.hln5hjeeqbq2iquz@tkn_work_nb> (raw)
In-Reply-To: <1575061766.543705524@f389.i.mail.ru>

Sorry again for the late reply.

> > I think we also should implement encode_sparse_* options to
> > be compatible with msgpack module.
>
> Could you please explain how do you propose to implement them? It
> seems to me the purpose of those configs is to handle excessively
> sparse arrays as maps (as stated in src/lua/utils.h). Which does not
> seem relevant to lua module where the only container type is table.
> What do I miss here? 

It is about encoding, not decoding: encode a Lua table with numeric keys
as MP_ARRAY, MP_MAP or give an error. It seems that nothing prevent us
from implementing this logic on Lua.

> Subject: [PATCH 1/2] Msgpackffi considers msgpack.cfg options now
> Msgpack.cfg options changes did not affect msgpackffi serializer state.
> This patch fixes it for options encode_load_metatables, decode_ and
> encode_invalid_numbers, encode_use_tostring and encode_invalid_as_nil.
> Closes #4499
> ---
> Issue:
> https://github.com/tarantool/tarantool/issues/4499
> Branch:
> https://github.com/tarantool/tarantool/compare/eljashm/gh-4499-msgpackffi-ignores-msgpack.cfg-options

> @@ -261,6 +263,19 @@ local function encode_r(buf, obj, level)
>          else
>              error("Invalid __serialize value")
>          end
> +    elseif type(obj) == math.huge or type(obj) == -math.huge or 
> +        type(obj) == math.nan then
> +        if msgpack.cfg.encode_invalid_numbers then
> +            if obj == math.huge then
> +                obj = 1/0
> +            elseif obj == -math.huge then
> +                obj = -1/0
> +            else
> +                obj = 0/0
> +            end
> +        else
> +            encode_nil(buf)
> +        end

I would save 1/0, -1/0, 0/0 as module local variables for readability,
like as it is done in test_double().

I also found that math.huge is 1/0 (inf) and there is no math.nan (it
just nil).

> @@ -562,6 +589,15 @@ decode_r = function(data)
>      elseif c >= 0xe0 then
>          return tonumber(ffi.cast('signed char',c)) -- negfixint
>      elseif c == 0xc0 then
> +        if msgpack.cfg.decode_invalid_numbers then
> +            if c == 0/0 then
> +                return math.nan
> +            elseif c == 1/0 then
> +                return math.huge
> +            elseif c == -1/0 then
> +                return -math.huge
> +            end
> +        end

Same as above.

> @@ -628,6 +664,8 @@ return {
>      on_encode = on_encode;
>      decode_unchecked = decode_unchecked;
>      decode = decode_unchecked; -- just for tests
> +    cfg = msgpack.cfg;
> +    new = msgpack.new; -- for serializer tests to work properly

So they'll test msgpack, not msgpackffi.

  reply	other threads:[~2019-12-17 23:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-07 10:36 Maria
2019-11-11 23:21 ` Alexander Turenko
2019-11-29 21:09   ` Maria Khaydich
2019-12-17 23:26     ` Alexander Turenko [this message]
2020-01-24 17:37       ` [Tarantool-patches] [PATCH] lua: msgpackffi " Maria Khaydich
2020-01-25 15:01         ` 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=20191217232635.hln5hjeeqbq2iquz@tkn_work_nb \
    --to=alexander.turenko@tarantool.org \
    --cc=maria.khaydich@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH] Msgpackffi considers msgpack.cfg options now' \
    /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