File 0986-erts-Add-etp-string-to-atom.patch of Package erlang

From 71c90aa8e05b21a34e5fac8b76eae76fc44fcb87 Mon Sep 17 00:00:00 2001
From: Sverker Eriksson <sverker@erlang.org>
Date: Wed, 9 Sep 2020 19:05:49 +0200
Subject: [PATCH 1/4] erts: Add etp-string-to-atom

---
 erts/etc/unix/etp-commands.in | 61 +++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/erts/etc/unix/etp-commands.in b/erts/etc/unix/etp-commands.in
index 9ed887c3d4..019c814952 100644
--- a/erts/etc/unix/etp-commands.in
+++ b/erts/etc/unix/etp-commands.in
@@ -646,6 +646,67 @@ define etp-atom-1
 end
 
 
+define etp-string-to-atom
+# Args: (char*) null-terminated
+#
+# Non-reentrant
+
+  set $etp_i = 0
+  set $etp_h = ((UWord)0)
+  while (($arg0)[$etp_i]) != 0
+    set $etp_c = (unsigned char)(($arg0)[$etp_i])
+
+    if $etp_c & 0x80
+      printf "Non ASCII atoms not implemented\n"
+      loop_break
+    end
+
+    set $etp_h = ($etp_h << 4) + $etp_c
+    set $etp_g = $etp_h & 0xf0000000
+    if $etp_g != 0
+      set $etp_h ^= ($etp_g >> 24)
+      set $etp_h ^= $etp_g
+    end
+    set $etp_i++
+  end
+
+  # hash_get_slot
+  set $etp_h ^= $etp_h >> erts_atom_table.htable.shift
+  if $etp_arch64
+    set $etp_h = (11400714819323198485UL * $etp_h) >> erts_atom_table.htable.shift
+  else
+    set $etp_h = (2654435769UL * $etp_h) >> erts_atom_table.htable.shift
+  end
+  set $etp_p = (Atom*)erts_atom_table.htable.bucket[$etp_h]
+
+  # search hash bucket list
+  while $etp_p
+    set $etp_i = 0
+    while $etp_i < $etp_p->len && ($arg0)[$etp_i]
+      if $etp_p->name[$etp_i] != ($arg0)[$etp_i]
+	loop_break
+      end
+      set $etp_i++
+    end
+    if $etp_i == $etp_p->len && ($arg0)[$etp_i] == 0
+      loop_break
+    end
+    set $etp_p = (Atom*)$etp_p->slot.bucket.next
+  end
+  if $etp_p
+    print ($etp_p->slot.index << 6) | (2 << 2) | 3
+  else
+    printf "Can't find atom\n"
+  end
+end
+
+document etp-string-to-atom
+%----------------------------------------
+% etp-string-to-atom (char*)
+%
+% Ex: etp-string-to-atom "erlang"
+%----------------------------------------
+end
 
 define etp-char-1
 # Args: int char, int quote_char
-- 
2.26.2

openSUSE Build Service is sponsored by