[erlang-bugs] bug in erl_interface

Serge Aleynikov <>
Mon Dec 16 18:17:43 CET 2013


You are correct that this doesn't lead to erroneous behavior as the same
integer can be encoded as SMALL_BIG and INTEGER_EXT, but it seems to me
that the current inconsistency between VM encoding and ei/erl_interface
should be normalized to follow the rules of "least astonishment". :-)


On Mon, Dec 16, 2013 at 11:39 AM, Björn-Egil Dahlberg <>wrote:

>  I don't stuff will break from this, so I wouldn't consider it a bug per
> se.
>
> For instance,
> 7> erlang:term_to_binary(1 bsl 29).
> <<131,98,32,0,0,0>>
>
> ok, but you could also define 1 bsl 29 = 536870912 as,
> <<131,110,4,0,0,0,0,32>> (SMALL_BIG)
> in the external format, so
>
> 9> erlang:binary_to_term(<<131,110,4,0,0,0,0,32>>).
> 536870912
>
> The "proper" way to encode should probably be as you describe though but I
> think it correct external format encoded from ei .. erl_interface legacy,
> what a bundle of joy =)
>
> // Björn-Egil
>
> On 2013-12-16 16:25, Serge Aleynikov wrote:
>
>  I believe there's a bug in the definition of ERL_MIN, ERL_MAX:
>
>  *grep -n -A1 ERL_MAX lib/erl_interface*/src/legacy/erl_eterm.h
> 28:#define ERL_MAX_COUNT     0xffffff
> 29:#define ERL_MAX ((1 << 27)-1)
> 30-#define ERL_MIN -(1 << 27)
>
>  The macros are used by lib/erl_interface/src/encode/encode_longlong.c:
>
>  *grep -n -B3 -A5 ERL_MAX lib/erl_interface/src/encode/encode_longlong.c *
> 63-         put8(s,ERL_SMALL_INTEGER_EXT);
> 64-         put8(s,(p & 0xff));
> 65-     }
> 66:    } else if ((p <= ERL_MAX) && (p >= ERL_MIN)) {
> 67-     /* FIXME: Non optimal, could use (p <= LONG_MAX) && (p >= LONG_MIN)
> 68-        and skip next case */
> 69-     if (!buf) s += 5;
> 70-     else {
> 71-         put8(s,ERL_INTEGER_EXT);
>
>  It seems to me that these definitions are obsolete as the VM encodes
> integers up to (1 << 31)-1 as ERL_INTEGER_EXT (98), and only above that as
> ERL_SMALL_BIG (110):
>
>  1> term_to_binary(1 bsl 31 - 1).
> <<131,98,127,255,255,255>>
> 2> term_to_binary(1 bsl 31).
> <<131,110,4,0,0,0,0,128>>
>
>  So the proper defines should be:
>
>  *lib/erl_interface*/src/legacy/erl_eterm.h:29:
>  #define ERL_MAX ((1 << *31*)-1)
> #define ERL_MIN -(1 << *31*)
>
>   Serge
>
>
>
> _______________________________________________
> erlang-bugs mailing ://erlang.org/mailman/listinfo/erlang-bugs
>
>
>
> _______________________________________________
> erlang-bugs mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-bugs
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20131216/8b1bd2e0/attachment-0001.html>


More information about the erlang-bugs mailing list