File 0844-Implement-a-separate-test-for-stack-direction-for-th.patch of Package erlang

From 38251bbb5c266b5fa27814b558fa7339792b5ce5 Mon Sep 17 00:00:00 2001
From: Sergei Golovan <sgolovan@gmail.com>
Date: Tue, 24 Sep 2019 09:35:03 +0300
Subject: [PATCH 1/4] Implement a separate test for stack direction for the re
 module

Fix the bug with failure to build from the source on HP PA-RISC
architecture where stack grows upwards. See
https://bugs.erlang.org/browse/ERL-1043 for details.
---
 erts/emulator/beam/erl_bif_re.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/erts/emulator/beam/erl_bif_re.c b/erts/emulator/beam/erl_bif_re.c
index b3bf1c7ee3..f5ccd86b42 100644
--- a/erts/emulator/beam/erl_bif_re.c
+++ b/erts/emulator/beam/erl_bif_re.c
@@ -90,6 +90,16 @@ stack_guard_upwards(void)
     return erts_check_above_limit(&c, limit - ERTS_PCRE_STACK_MARGIN);
 }
 
+static ERTS_NOINLINE
+int stack_grows_downwards(char *prev_c)
+{
+    char c;
+    if (&c < prev_c)
+        return 1;
+    else
+        return 0;
+}
+
 void erts_init_bif_re(void)
 {
     char c;
@@ -97,7 +107,7 @@ void erts_init_bif_re(void)
     erts_pcre_free = &erts_erts_pcre_free;
     erts_pcre_stack_malloc = &erts_erts_pcre_stack_malloc;
     erts_pcre_stack_free = &erts_erts_pcre_stack_free;
-    if ((char *) erts_ptr_id(&c) > ERTS_STACK_LIMIT)
+    if (stack_grows_downwards(&c))
         erts_pcre_stack_guard = stack_guard_downwards;
     else
         erts_pcre_stack_guard = stack_guard_upwards;
-- 
2.16.4

openSUSE Build Service is sponsored by