[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 03/12] libpoke: Fix `muls` insn to use `pvm_alloc`
From: |
Mohammad-Reza Nabipoor |
Subject: |
[PATCH 03/12] libpoke: Fix `muls` insn to use `pvm_alloc` |
Date: |
Wed, 26 May 2021 02:51:06 +0430 |
2021-05-22 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
* libpoke/pvm.h (pvm_make_string_nodup): New function declaration.
* libpoke/pvm-val.c (pvm_make_string_nodup): New function definition.
* libpoke/pvm.jitter: Do not include `xalloc.h`.
(muls): Use `pvm_alloc` instead of `xmalloc`.
* etc/poke.rec (The `muls' instruction in pvm.jitter calls xmalloc):
Remove as done.
---
ChangeLog | 9 +++++++++
etc/poke.rec | 9 ---------
libpoke/pvm-val.c | 9 +++++++++
libpoke/pvm.h | 4 ++++
libpoke/pvm.jitter | 7 +++----
5 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index d62dd68c..15d858b0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2021-05-22 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
+
+ * libpoke/pvm.h (pvm_make_string_nodup): New function declaration.
+ * libpoke/pvm-val.c (pvm_make_string_nodup): New function definition.
+ * libpoke/pvm.jitter: Do not include `xalloc.h`.
+ (muls): Use `pvm_alloc` instead of `xmalloc`.
+ * etc/poke.rec (The `muls' instruction in pvm.jitter calls xmalloc):
+ Remove as done.
+
2021-05-22 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
* doc/learn-poke-in-y-minutes.pk (Struct Field Initializers): Update
diff --git a/etc/poke.rec b/etc/poke.rec
index 3e87f403..165772b2 100644
--- a/etc/poke.rec
+++ b/etc/poke.rec
@@ -1084,15 +1084,6 @@ Description:
+ Code in libpoke should not call `abort' nor `exit'.
Target: 1.1
-Summary: The `muls' instruction in pvm.jitter calls xmalloc
-Component: Compiler
-Kind: BUG
-BZ: 26894
-Priority: 3
-Description:
-+ libpoke code shouldn't abort, therefore xalloc shouldn't be used.
-Target: 1.1
-
Summary: Complete pvm_print_val for function types
Component: PVM
Kind: BUG
diff --git a/libpoke/pvm-val.c b/libpoke/pvm-val.c
index a13eecc7..217d6703 100644
--- a/libpoke/pvm-val.c
+++ b/libpoke/pvm-val.c
@@ -82,6 +82,15 @@ pvm_make_string (const char *str)
return PVM_BOX (box);
}
+pvm_val
+pvm_make_string_nodup (char *str)
+{
+ pvm_val_box box = pvm_make_box (PVM_VAL_TAG_STR);
+
+ PVM_VAL_BOX_STR (box) = str;
+ return PVM_BOX (box);
+}
+
pvm_val
pvm_make_array (pvm_val nelem, pvm_val type)
{
diff --git a/libpoke/pvm.h b/libpoke/pvm.h
index a07b043a..ad9e9939 100644
--- a/libpoke/pvm.h
+++ b/libpoke/pvm.h
@@ -214,6 +214,10 @@ pvm_val pvm_make_ulong (uint64_t value, int size);
pvm_val pvm_make_string (const char *value);
+/* Make a string PVM value without STRDUPing the VALUE. */
+
+pvm_val pvm_make_string_nodup (char *value);
+
/* Make an offset PVM value.
MAGNITUDE is a PVM integral value.
diff --git a/libpoke/pvm.jitter b/libpoke/pvm.jitter
index 1c3670b0..079d1c18 100644
--- a/libpoke/pvm.jitter
+++ b/libpoke/pvm.jitter
@@ -76,6 +76,7 @@ wrapped-functions
pvm_env_push_frame
pvm_env_toplevel
pvm_make_string
+ pvm_make_string_nodup
pvm_make_array
pvm_make_struct
pvm_make_offset
@@ -179,7 +180,6 @@ early-c
# include <assert.h>
# include <time.h>
# include <errno.h>
-# include "xalloc.h"
# include "timespec.h"
# include "intprops.h"
@@ -4213,14 +4213,13 @@ instruction muls ()
code
pvm_val str = JITTER_UNDER_TOP_STACK ();
size_t i, num = PVM_VAL_ULONG (JITTER_TOP_STACK ());
- char *res = xmalloc (strlen (PVM_VAL_STR (str)) * num + 1);
+ char *res = pvm_alloc (strlen (PVM_VAL_STR (str)) * num + 1);
*res = '\0';
for (i = 0; i < num; ++i)
strcat (res, PVM_VAL_STR (str));
- JITTER_PUSH_STACK (pvm_make_string (res));
- free (res);
+ JITTER_PUSH_STACK (pvm_make_string_nodup (res));
end
end
--
2.31.1