poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[COMMITTED] pvm, libpoke: avoid duplicating logic in pk_u?int_value


From: Jose E. Marchesi
Subject: [COMMITTED] pvm, libpoke: avoid duplicating logic in pk_u?int_value
Date: Sun, 26 Dec 2021 23:32:38 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

2021-12-26  Jose E. Marchesi  <jemarch@gnu.org>

        * libpoke/pvm-val.c (pvm_make_signed_integral): Return PK_NULL if
        an invalid `size' argument is provided.
        (pvm_make_unsigned_integral): Likewise.
        * libpoke/pvm.h: Document that these functions return PK_NULL in
        case an invalid size is provided.
        * libpoke/pk-val.c (pk_make_uint): Use pvm_make_unsigned_integral.
        (pk_make_int): Use pvm_make_signed_integral.
---
 ChangeLog         | 10 ++++++++++
 libpoke/pk-val.c  | 28 ++--------------------------
 libpoke/pvm-val.c |  6 ++++--
 libpoke/pvm.h     |  4 +++-
 4 files changed, 19 insertions(+), 29 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e8499133..66e193f1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2021-12-26  Jose E. Marchesi  <jemarch@gnu.org>
 
+       * libpoke/pvm-val.c (pvm_make_signed_integral): Return PK_NULL if
+       an invalid `size' argument is provided.
+       (pvm_make_unsigned_integral): Likewise.
+       * libpoke/pvm.h: Document that these functions return PK_NULL in
+       case an invalid size is provided.
+       * libpoke/pk-val.c (pk_make_uint): Use pvm_make_unsigned_integral.
+       (pk_make_int): Use pvm_make_signed_integral.
+
+2021-12-26  Jose E. Marchesi  <jemarch@gnu.org>
+
        * pickles/argp.pk (argp_parse): Remove dots after non-sentences in
        the default help summaries.
 
diff --git a/libpoke/pk-val.c b/libpoke/pk-val.c
index a173d679..7af41029 100644
--- a/libpoke/pk-val.c
+++ b/libpoke/pk-val.c
@@ -26,19 +26,7 @@
 pk_val
 pk_make_int (int64_t value, int size)
 {
-  pk_val new;
-
-  /* At the moment poke integers are limited to a maximum number of
-     bits.  */
-  if (size > 64)
-    return PK_NULL;
-
-  if (size <= 32)
-    new = pvm_make_int (value, size);
-  else
-    new = pvm_make_long (value, size);
-
-  return new;
+  return pvm_make_signed_integral (value, size);
 }
 
 int64_t
@@ -62,19 +50,7 @@ pk_int_size (pk_val val)
 pk_val
 pk_make_uint (uint64_t value, int size)
 {
-  pk_val new;
-
-  /* At the moment poke integers are limited to a maximum number of
-     bits.  */
-  if (size > 64)
-    return PK_NULL;
-
-  if (size <= 32)
-    new = pvm_make_uint (value, size);
-  else
-    new = pvm_make_ulong (value, size);
-
-  return new;
+  return pvm_make_unsigned_integral (value, size);
 }
 
 uint64_t
diff --git a/libpoke/pvm-val.c b/libpoke/pvm-val.c
index fe617ae3..53d922d5 100644
--- a/libpoke/pvm-val.c
+++ b/libpoke/pvm-val.c
@@ -88,7 +88,8 @@ pvm_make_ulong (uint64_t value, int size)
 pvm_val
 pvm_make_signed_integral (int64_t value, int size)
 {
-  assert (0 < size && size <= 64);
+  if (size > 64)
+    return PK_NULL;
 
   if (size <= 32)
     return PVM_MAKE_INT ((int32_t) value, size);
@@ -99,7 +100,8 @@ pvm_make_signed_integral (int64_t value, int size)
 pvm_val
 pvm_make_unsigned_integral (uint64_t value, int size)
 {
-  assert (0 < size && size <= 64);
+  if (size > 64)
+    return PK_NULL;
 
   if (size <= 32)
     return PVM_MAKE_UINT ((uint32_t) value, size);
diff --git a/libpoke/pvm.h b/libpoke/pvm.h
index 4c58696e..1c692c01 100644
--- a/libpoke/pvm.h
+++ b/libpoke/pvm.h
@@ -211,7 +211,9 @@ pvm_val pvm_make_long (int64_t value, int size);
 pvm_val pvm_make_ulong (uint64_t value, int size);
 
 /* Make signed and unsigned integral values.
-   SIZE is measured in bits and should be in the range 1 to 64.  */
+
+   SIZE is measured in bits and should be in the range 1 to 64.  If an
+   invalid size is provided these functions return PVM_NULL.  */
 
 pvm_val pvm_make_signed_integral (int64_t value, int size);
 
-- 
2.11.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]