File 2831-erts-Remove-creation-0-as-wildcard.patch of Package erlang

From 82b98b430d61678876a53088bc253bb14d09bc9f Mon Sep 17 00:00:00 2001
From: Sverker Eriksson <sverker@erlang.org>
Date: Tue, 26 Oct 2021 20:22:38 +0200
Subject: [PATCH 1/8] erts: Remove creation 0 as wildcard

---
 erts/doc/src/erl_ext_dist.xml                 |  6 ++----
 erts/emulator/beam/erl_monitor_link.c         |  3 +--
 erts/emulator/beam/erl_node_container_utils.h |  2 +-
 erts/emulator/beam/erl_vm.h                   |  2 --
 erts/emulator/beam/external.c                 | 18 ++----------------
 erts/emulator/test/list_bif_SUITE.erl         | 19 -------------------
 6 files changed, 6 insertions(+), 44 deletions(-)

diff --git a/erts/doc/src/erl_ext_dist.xml b/erts/doc/src/erl_ext_dist.xml
index 43c5407847..b2e2c6316a 100644
--- a/erts/doc/src/erl_ext_dist.xml
+++ b/erts/doc/src/erl_ext_dist.xml
@@ -755,10 +755,8 @@
 	  <item><p>A 32-bit big endian unsigned integer. All identifiers
 	    originating from the same node incarnation must have identical <c>Creation</c>
 	    values. This makes it possible to separate identifiers from old
-	    (crashed) nodes from a new one. The value zero should be avoided for
-	    normal operations as it is used as a wild card for debug purpose
-	    (like a pid returned by <seemfa marker="erts:erlang#list_to_pid/1">
-	    erlang:list_to_pid/1</seemfa>).</p>
+	    (crashed) nodes from a new one. The value zero is reserved and
+            must be avoided for normal operations.</p>
 	  </item>
 	</taglist>
 	<p><c>NEW_PID_EXT</c> was introduced in OTP 19, but only to be decoded
diff --git a/erts/emulator/beam/erl_monitor_link.c b/erts/emulator/beam/erl_monitor_link.c
index bb683428d7..c8e8a1b31a 100644
--- a/erts/emulator/beam/erl_monitor_link.c
+++ b/erts/emulator/beam/erl_monitor_link.c
@@ -197,8 +197,7 @@ ml_cmp_keys(Eterm key1, Eterm key2)
                 if (n1->sysname != n2->sysname)
                     return n1->sysname < n2->sysname ? -1 : 1;
                 ASSERT(n1->creation != n2->creation);
-                if (n1->creation != 0 && n2->creation != 0)
-                    return n1->creation < n2->creation ? -1 : 1;
+                return n1->creation < n2->creation ? -1 : 1;
             }
 
             ndw1 = external_thing_data_words(et1);
diff --git a/erts/emulator/beam/erl_node_container_utils.h b/erts/emulator/beam/erl_node_container_utils.h
index f86b5ea9d3..edabdfef61 100644
--- a/erts/emulator/beam/erl_node_container_utils.h
+++ b/erts/emulator/beam/erl_node_container_utils.h
@@ -106,7 +106,7 @@
  */
 #define dist_entry_channel_no(x)				\
   ((x) == erts_this_dist_entry					\
-   ? ((Uint) 0)							\
+   ? ((Uint) ERST_INTERNAL_CHANNEL_NO)							\
    : (ASSERT(is_atom((x)->sysname)),			        \
       (Uint) atom_val((x)->sysname)))
 #define internal_channel_no(x) ((Uint) ERST_INTERNAL_CHANNEL_NO)
diff --git a/erts/emulator/beam/erl_vm.h b/erts/emulator/beam/erl_vm.h
index 7c2fe55796..d55d01d5ed 100644
--- a/erts/emulator/beam/erl_vm.h
+++ b/erts/emulator/beam/erl_vm.h
@@ -259,8 +259,6 @@ extern int H_MAX_FLAGS;         /* maximum heap flags  */
 extern int erts_atom_table_size;/* Atom table size */
 extern int erts_pd_initial_size;/* Initial Process dictionary table size */
 
-#define ORIG_CREATION 0
-
 /* macros for extracting bytes from uint16's */
 
 #define hi_byte(a) ((a) >> 8) 
diff --git a/erts/emulator/beam/external.c b/erts/emulator/beam/external.c
index d0d5d66ea0..ca73664522 100644
--- a/erts/emulator/beam/external.c
+++ b/erts/emulator/beam/external.c
@@ -66,19 +66,6 @@
 #define ERTS_MAX_TINY_CREATION (3)
 #define is_tiny_creation(Cre) ((unsigned)(Cre) <= ERTS_MAX_TINY_CREATION)
 
-/*
- *   When 0 is used as creation, the real creation
- *   is unknown. Creation 0 on data will be changed to current
- *   creation of the node which it belongs to when it enters
- *   that node.
- *       This typically happens when a remote pid is created with
- *   list_to_pid/1 and then sent to the remote node. This behavior
- *   has the undesirable effect that a pid can be passed between nodes,
- *   and as a result of that not being equal to itself (the pid that
- *   comes back isn't equal to the original pid).
- *
- */
-
 #undef ERTS_DEBUG_USE_DIST_SEP
 #ifdef DEBUG
 #  if 0
@@ -2946,9 +2933,8 @@ static ERTS_INLINE int dec_is_this_node(Eterm sysname, Uint32 creation)
 {
     return (sysname == INTERNAL_LOCAL_SYSNAME
             ||
-            (sysname == erts_this_node->sysname
-             && (creation == erts_this_node->creation
-                 || creation == ORIG_CREATION)));
+            (sysname == erts_this_node->sysname &&
+             creation == erts_this_node->creation));
 }
 
 
diff --git a/erts/emulator/test/list_bif_SUITE.erl b/erts/emulator/test/list_bif_SUITE.erl
index b398e22707..9f8ef4449b 100644
--- a/erts/emulator/test/list_bif_SUITE.erl
+++ b/erts/emulator/test/list_bif_SUITE.erl
@@ -175,25 +175,6 @@ t_list_to_ext_pidportref(Config) when is_list(Config) ->
     true = rpc:call(Node, erlang, '=:=', [Ref, Ref2]),
     true = rpc:call(Node, erlang, '==',  [Ref, Ref2]),
 
-    %% Make sure no ugly comparison with 0-creation as wildcard is done.
-    Pid0 = make_0_creation(Pid),
-    Port0 = make_0_creation(Port),
-    Ref0 = make_0_creation(Ref),
-    false = (Pid =:= Pid0),
-    false = (Port =:= Port0),
-    false = (Ref =:= Ref0),
-    false = (Pid == Pid0),
-    false = (Port == Port0),
-    false = (Ref == Ref0),
-
-    %% Check 0-creations are converted to local node creations
-    %% when sent to matching node name.
-    true = rpc:call(Node, erlang, '=:=', [Pid, Pid0]),
-    true = rpc:call(Node, erlang, '==',  [Pid, Pid0]),
-    true = rpc:call(Node, erlang, '=:=', [Port, Port0]),
-    true = rpc:call(Node, erlang, '==',  [Port, Port0]),
-    true = rpc:call(Node, erlang, '=:=', [Ref, Ref0]),
-    true = rpc:call(Node, erlang, '==',  [Ref, Ref0]),
 
     slave:stop(Node),
     ok.
-- 
2.31.1

openSUSE Build Service is sponsored by