LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File 0122-Make-0-bsl-BigNumber-consistently-succeed.patch of Package erlang (Project home:Ledest:erlang:20)

From 8c0569d2b5c26545cb7abd9063a1abda7ebd13e9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Thu, 10 Aug 2017 11:46:48 +0200
Subject: [PATCH] Make '0 bsl BigNumber' consistently succeed

'0 bsl 134217728' would fail with a system limit exception on a 32-bit
BEAM machine, but not on a 64-bit BEAM machine. Smaller values
on the right would always work.

Make erlang:bsl(0, BigNumber) always return 0 to make for consistency.
(The previous commit accidentally did that change for
'0 bsl BigNumber'.)
---
 erts/emulator/beam/erl_arith.c   | 6 +++++-
 erts/emulator/test/big_SUITE.erl | 7 +++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/erts/emulator/beam/erl_arith.c b/erts/emulator/beam/erl_arith.c
index 861532f24..f2a3e411e 100644
--- a/erts/emulator/beam/erl_arith.c
+++ b/erts/emulator/beam/erl_arith.c
@@ -276,8 +276,12 @@ shift(Process* p, Eterm arg1, Eterm arg2, int right)
 		goto do_bsl;
 	    } else if (is_small(arg1) || is_big(arg1)) {
 		/*
-		 * N bsl PositiveBigNum is too large to represent.
+		 * N bsl PositiveBigNum is too large to represent,
+                 * unless N is 0.
 		 */
+                if (arg1 == make_small(0)) {
+                    BIF_RET(arg1);
+                }
 		BIF_ERROR(p, SYSTEM_LIMIT);
 	    }
 	     /* Fall through if the left argument is not an integer. */
diff --git a/erts/emulator/test/big_SUITE.erl b/erts/emulator/test/big_SUITE.erl
index c30876021..5939d024a 100644
--- a/erts/emulator/test/big_SUITE.erl
+++ b/erts/emulator/test/big_SUITE.erl
@@ -339,6 +339,13 @@ system_limit(Config) when is_list(Config) ->
     {'EXIT',{system_limit,_}} = (catch apply(erlang, id('bsl'), [Maxbig,2])),
     {'EXIT',{system_limit,_}} = (catch id(1) bsl (1 bsl 45)),
     {'EXIT',{system_limit,_}} = (catch id(1) bsl (1 bsl 69)),
+
+    %% There should be no system_limit exception when shifting a zero.
+    0 = id(0) bsl (1 bsl 128),
+    0 = id(0) bsr -(1 bsl 128),
+    Erlang = id(erlang),
+    0 = Erlang:'bsl'(id(0), 1 bsl 128),
+    0 = Erlang:'bsr'(id(0), -(1 bsl 128)),
     ok.
 
 maxbig() ->
-- 
2.14.1