<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">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". :-)</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Dec 16, 2013 at 11:39 AM, Björn-Egil Dahlberg <span dir="ltr"><<a href="mailto:egil@erlang.org" target="_blank">egil@erlang.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
<div>I don't stuff will break from this, so
I wouldn't consider it a bug per se.<br>
<br>
For instance,<br>
7> erlang:term_to_binary(1 bsl 29). <br>
<<131,98,32,0,0,0>><br>
<br>
ok, but you could also define 1 bsl 29 = 536870912 as,<br>
<<131,110,4,0,0,0,0,32>> (SMALL_BIG)<br>
in the external format, so<br>
<br>
9> erlang:binary_to_term(<<131,110,4,0,0,0,0,32>>).<br>
536870912<br>
<br>
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 =)<br>
<br>
// Björn-Egil<br>
<br>
On 2013-12-16 16:25, Serge Aleynikov wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div class="gmail_default" style="font-family:arial,helvetica,sans-serif">I believe
there's a bug in the definition of ERL_MIN, ERL_MAX:</div>
<div class="gmail_default" style="font-family:arial,helvetica,sans-serif">
<br>
</div>
<div class="gmail_default">
<div class="gmail_default"><font face="courier new, monospace"><b>grep
-n -A1 ERL_MAX lib/erl_interface</b>/src/legacy/erl_eterm.h</font></div>
<div class="gmail_default"><font face="courier new, monospace">28:#define
ERL_MAX_COUNT 0xffffff</font></div>
<div class="gmail_default"><font face="courier new, monospace">29:#define
ERL_MAX ((1 << 27)-1)</font></div>
<div class="gmail_default"><font face="courier new, monospace">30-#define
ERL_MIN -(1 << 27)</font></div>
<div class="gmail_default"><font face="arial, helvetica,
sans-serif"><br>
</font></div>
<div class="gmail_default"><span style="font-family:arial,helvetica,sans-serif">The macros
are used by
lib/erl_interface/src/encode/encode_longlong.c:</span><font face="arial, helvetica, sans-serif"><br>
</font></div>
<div class="gmail_default"><span style="font-family:arial,helvetica,sans-serif"><br>
</span></div>
<div class="gmail_default">
<div class="gmail_default"><font face="courier new,
monospace"><b>grep -n -B3 -A5 ERL_MAX
lib/erl_interface/src/encode/encode_longlong.c </b></font></div>
<div class="gmail_default"><font face="courier new,
monospace">63- put8(s,ERL_SMALL_INTEGER_EXT);</font></div>
<div class="gmail_default"><font face="courier new,
monospace">64- put8(s,(p & 0xff));</font></div>
<div class="gmail_default"><font face="courier new,
monospace">65- }</font></div>
<div class="gmail_default"><font face="courier new,
monospace">66: } else if ((p <= ERL_MAX)
&& (p >= ERL_MIN)) {</font></div>
<div class="gmail_default"><font face="courier new,
monospace">67- /* FIXME: Non optimal, could use (p
<= LONG_MAX) && (p >= LONG_MIN)</font></div>
<div class="gmail_default"><font face="courier new,
monospace">68- and skip next case */</font></div>
<div class="gmail_default"><font face="courier new,
monospace">69- if (!buf) s += 5;</font></div>
<div class="gmail_default"><font face="courier new,
monospace">70- else {</font></div>
<div class="gmail_default"><font face="courier new,
monospace">71- put8(s,ERL_INTEGER_EXT);</font></div>
<div class="gmail_default"><font face="arial, helvetica,
sans-serif"><br>
</font></div>
</div>
<div class="gmail_default"><font face="arial, helvetica,
sans-serif">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):</font></div>
<div class="gmail_default"><font face="arial, helvetica,
sans-serif"><br>
</font></div>
<div class="gmail_default">
<div class="gmail_default"><font face="courier new,
monospace">1> term_to_binary(1 bsl 31 - 1).</font></div>
<div class="gmail_default"><font face="courier new,
monospace"><<131,98,127,255,255,255>></font></div>
<div class="gmail_default"><font face="courier new,
monospace">2> term_to_binary(1 bsl 31).</font></div>
<div class="gmail_default"><font face="courier new,
monospace"><<131,110,4,0,0,0,0,128>></font></div>
<div class="gmail_default"><br>
</div>
<div class="gmail_default">So the proper defines should be:</div>
<div class="gmail_default">
<br>
</div>
<div class="gmail_default"><b>lib/erl_interface</b><span style="font-family:'courier new',monospace">/src/legacy/erl_eterm.h:29:</span><br>
</div>
<div class="gmail_default">
<div class="gmail_default"><font face="courier new,
monospace">#define ERL_MAX ((1 << <b><u>31</u></b>)-1)</font></div>
<div class="gmail_default"><font face="courier new,
monospace">#define ERL_MIN -(1 << <b><u>31</u></b>)</font></div>
<div><font face="courier new, monospace"><br>
</font></div>
</div>
</div>
</div>
<div class="gmail_default">Serge</div>
<div class="gmail_default"><br>
</div>
</div>
<br>
<fieldset></fieldset>
<br>
<pre>_______________________________________________
erlang-bugs mailing list
<a href="mailto:erlang-bugs@erlang.org" target="_blank">erlang-bugs@erlang.org</a>
<a href="http://erlang.org/mailman/listinfo/erlang-bugs" target="_blank">http://erlang.org/mailman/listinfo/erlang-bugs</a>
</pre>
</blockquote>
<br>
</div>
<br>_______________________________________________<br>
erlang-bugs mailing list<br>
<a href="mailto:erlang-bugs@erlang.org">erlang-bugs@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-bugs" target="_blank">http://erlang.org/mailman/listinfo/erlang-bugs</a><br>
<br></blockquote></div><br></div>