poke-devel
[Top][All Lists]
Advanced

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

[COMMITTED] pkl,pickles: raise E_constraint when array boundaries types


From: Jose E. Marchesi
Subject: [COMMITTED] pkl,pickles: raise E_constraint when array boundaries types are not satified
Date: Mon, 11 Apr 2022 00:17:50 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)


Up to now the array mappers and constructors were raising the
E_map_bounds exception when the boundaries of an array type weren't
satisfied (like for example byte[3#b]).

The name of that exception was confusing (constructing doens't involve
mapping) and the extra exception was causing problems with unions.

While fixing that later problem I realized that it is not worth it to
differenciate this case from the more general problem of a constraint
violation: the constraint implicitly defined by the boundary in the
array type.

Therefore this patch.

2022-04-11  Jose E. Marchesi  <jemarch@gnu.org>

        * libpoke/pkl-gen.pks (array_mapper): Raise PVM_E_CONSTRAINT
        instead of PVM_E_MAP_BOUNDS in case of array bound failure.
        (array_constructor): Likewise.
        * libpoke/libpoke.h (PK_EC_MAP_BOUNDS): Remove.
        * libpoke/pkl-rt.pk (E_map_bounds): Likewise.
        * libpoke/pvm.h (PVM_E_MAP_BOUNDS): Likewise.
        (PVM_E_MAP_BOUNDS_NAME): Likewise.
        (PVM_E_MAP_BOUNDS_ESTATUS): Likewise.
        * pickles/diff.pk: Adapt accordingly.
        * testsuite/poke.pkl/scons-union-12.pk: New test.
        * testsuite/poke.pkl/scons-union-13.pk: Likewise.
        * testsuite/poke.pkl/scons-union-14.pk: Likewise.
        * testsuite/poke.map/maps-unions-14.pk: Likewise.
        * testsuite/poke.map/maps-unions-15.pk: Likewise.
        * testsuite/poke.map/maps-unions-16.pk: Likewise.
        * testsuite/Makefile.am (EXTRA_DIST): Add new tests.
---
 ChangeLog                            | 19 +++++++++++++++++++
 libpoke/libpoke.h                    |  1 -
 libpoke/pkl-gen.pks                  |  8 ++++----
 libpoke/pkl-rt.pk                    |  3 ---
 libpoke/pvm.h                        |  5 -----
 pickles/Makefile.am                  |  3 ++-
 pickles/diff.pk                      | 14 +++++++-------
 testsuite/Makefile.am                |  6 ++++++
 testsuite/poke.map/maps-unions-14.pk | 11 +++++++++++
 testsuite/poke.map/maps-unions-15.pk | 11 +++++++++++
 testsuite/poke.map/maps-unions-16.pk |  8 ++++++++
 testsuite/poke.pkl/scons-union-12.pk |  9 +++++++++
 testsuite/poke.pkl/scons-union-13.pk |  9 +++++++++
 testsuite/poke.pkl/scons-union-14.pk |  6 ++++++
 14 files changed, 92 insertions(+), 21 deletions(-)
 create mode 100644 testsuite/poke.map/maps-unions-14.pk
 create mode 100644 testsuite/poke.map/maps-unions-15.pk
 create mode 100644 testsuite/poke.map/maps-unions-16.pk
 create mode 100644 testsuite/poke.pkl/scons-union-12.pk
 create mode 100644 testsuite/poke.pkl/scons-union-13.pk
 create mode 100644 testsuite/poke.pkl/scons-union-14.pk

diff --git a/ChangeLog b/ChangeLog
index 6537a71b..61f5b7e1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2022-04-11  Jose E. Marchesi  <jemarch@gnu.org>
+
+       * libpoke/pkl-gen.pks (array_mapper): Raise PVM_E_CONSTRAINT
+       instead of PVM_E_MAP_BOUNDS in case of array bound failure.
+       (array_constructor): Likewise.
+       * libpoke/libpoke.h (PK_EC_MAP_BOUNDS): Remove.
+       * libpoke/pkl-rt.pk (E_map_bounds): Likewise.
+       * libpoke/pvm.h (PVM_E_MAP_BOUNDS): Likewise.
+       (PVM_E_MAP_BOUNDS_NAME): Likewise.
+       (PVM_E_MAP_BOUNDS_ESTATUS): Likewise.
+       * pickles/diff.pk: Adapt accordingly.
+       * testsuite/poke.pkl/scons-union-12.pk: New test.
+       * testsuite/poke.pkl/scons-union-13.pk: Likewise.
+       * testsuite/poke.pkl/scons-union-14.pk: Likewise.
+       * testsuite/poke.map/maps-unions-14.pk: Likewise.
+       * testsuite/poke.map/maps-unions-15.pk: Likewise.
+       * testsuite/poke.map/maps-unions-16.pk: Likewise.
+       * testsuite/Makefile.am (EXTRA_DIST): Add new tests.
+
 2022-04-10  Jose E. Marchesi  <jemarch@gnu.org>
 
        * pickles/openpgp.pk (PGP_MPI): The `len' field is big endian.
diff --git a/libpoke/libpoke.h b/libpoke/libpoke.h
index cbee119b..918325ed 100644
--- a/libpoke/libpoke.h
+++ b/libpoke/libpoke.h
@@ -49,7 +49,6 @@ typedef uint64_t pk_val;
 #define PK_EC_NO_IOS        2
 #define PK_EC_NO_RETURN     3
 #define PK_EC_OUT_OF_BOUNDS 4
-#define PK_EC_MAP_BOUNDS    5
 #define PK_EC_EOF           6
 #define PK_EC_MAP           7
 #define PK_EC_CONV          8
diff --git a/libpoke/pkl-gen.pks b/libpoke/pkl-gen.pks
index d0e110a9..11930901 100644
--- a/libpoke/pkl-gen.pks
+++ b/libpoke/pkl-gen.pks
@@ -42,12 +42,12 @@
 ;;;
 ;;; Otherwise, if EBOUND is not null, then perform a map bounded by the
 ;;; given number of elements.  If EOF is encountered before the given
-;;; amount of elements are read, then raise PVM_E_MAP_BOUNDS.
+;;; amount of elements are read, then raise PVM_E_CONSTRAINT.
 ;;;
 ;;; Otherwise, if SBOUND is not null, then perform a map bounded by the
 ;;; given size (a bit-offset), i.e. read array elements from IO until
 ;;; the total size of the array is exactly SBOUND.  If SBOUND is exceeded,
-;;; then raise PVM_E_MAP_BOUNDS.
+;;; then raise PVM_E_CONSTRAINT.
 ;;;
 ;;; Only one of EBOUND or SBOUND simultanously are supported.
 ;;; Note that OFF should be of type offset<uint<64>,*>.
@@ -235,7 +235,7 @@
         popf 1
         return
 .bounds_fail:
-        push PVM_E_MAP_BOUNDS
+        push PVM_E_CONSTRAINT
         raise
         .end
 
@@ -426,7 +426,7 @@
         popf 1
         return
 .bounds_fail:
-        push PVM_E_MAP_BOUNDS
+        push PVM_E_CONSTRAINT
         raise
         .end
 
diff --git a/libpoke/pkl-rt.pk b/libpoke/pkl-rt.pk
index c6b3209c..db64f17b 100644
--- a/libpoke/pkl-rt.pk
+++ b/libpoke/pkl-rt.pk
@@ -156,7 +156,6 @@ immutable var EC_div_by_zero   = 1;
 immutable var EC_no_ios        = 2;
 immutable var EC_no_return     = 3;
 immutable var EC_out_of_bounds = 4;
-immutable var EC_map_bounds    = 5;
 immutable var EC_eof           = 6;
 immutable var EC_map           = 7;
 immutable var EC_conv          = 8;
@@ -183,8 +182,6 @@ immutable var E_no_return
   = Exception {code = EC_no_return, name = "no return", exit_status = 1};
 immutable var E_out_of_bounds
   = Exception {code = EC_out_of_bounds, name = "out of bounds", exit_status = 
1};
-immutable var E_map_bounds
-  = Exception {code = EC_map_bounds, name = "out of map bounds", exit_status = 
1};
 immutable var E_eof
   = Exception {code = EC_eof, name = "EOF", exit_status = 0 };
 immutable var E_map
diff --git a/libpoke/pvm.h b/libpoke/pvm.h
index 2ce9af5f..bfe73c93 100644
--- a/libpoke/pvm.h
+++ b/libpoke/pvm.h
@@ -498,7 +498,6 @@ enum pvm_exit_code
   E(NO_IOS)                  \
   E(NO_RETURN)               \
   E(OUT_OF_BOUNDS)           \
-  E(MAP_BOUNDS)              \
   E(EOF)                     \
   E(MAP)                     \
   E(CONV)                    \
@@ -533,10 +532,6 @@ enum pvm_exit_code
 #define PVM_E_OUT_OF_BOUNDS_NAME "out of bounds"
 #define PVM_E_OUT_OF_BOUNDS_ESTATUS 1
 
-#define PVM_E_MAP_BOUNDS    5
-#define PVM_E_MAP_BOUNDS_NAME "out of map bounds"
-#define PVM_E_MAP_BOUNDS_ESTATUS 1
-
 #define PVM_E_EOF           6
 #define PVM_E_EOF_NAME "EOF"
 #define PVM_E_EOF_ESTATUS 1
diff --git a/pickles/Makefile.am b/pickles/Makefile.am
index 6115fdf0..d9407802 100644
--- a/pickles/Makefile.am
+++ b/pickles/Makefile.am
@@ -4,4 +4,5 @@ dist_pickles_DATA = elf-common.pk elf-64.pk elf-32.pk elf.pk 
ctf.pk ctf-dump.pk
                     color.pk rgb24.pk id3v1.pk ios.pk diff.pk pk-table.pk \
                     dwarf.pk dwarf-common.pk dwarf-frame.pk dwarf-pubnames.pk \
                     dwarf-types.pk time.pk argp.pk pktest.pk mbr.pk ustar.pk \
-                    mcr.pk dwarf-expr.pk dwarf-info.pk id3v2.pk jffs2.pk 
asn1-ber.pk
+                    mcr.pk dwarf-expr.pk dwarf-info.pk id3v2.pk jffs2.pk 
asn1-ber.pk \
+                    openpgp.pk
diff --git a/pickles/diff.pk b/pickles/diff.pk
index bfec73a8..9e40976c 100644
--- a/pickles/diff.pk
+++ b/pickles/diff.pk
@@ -169,7 +169,7 @@ type Diff_Thunk =
    This function raises E_map if any of the values to compare are not
    mapped.
 
-   This function raises E_map_bounds if the size of either A or B is
+   This function raises E_constraint if the size of either A or B is
    not a multiple of bytes.  Note however that the constituent data
    structures are not required to be a whole number of bytes.  */
 
@@ -246,13 +246,13 @@ fun diff_structured = (any a, any b,
     {
       if (val'elem (idx) ?! E_inval)
       {
-        /* Note that recursing into the element may result in E_map_bounds
+        /* Note that recursing into the element may result in E_constraint
            in case a non-byte element is found.  In that case, try to
            emit the thunk anyway.  */
         if (elem_simple_p (val, idx)
             || ! { sdiff_addrem (what, val'elem (idx),
                                  prefix + format_ename (val'ename (idx)),
-                                 0); } ?! E_map_bounds)
+                                 0); } ?! E_constraint)
           thunk.addrem :what what :off val'eoffset (idx) :siz val'esize (idx)
                        :bytes get_elem_bytes (val, idx)
                        :name prefix + format_ename (val'ename (idx))
@@ -286,12 +286,12 @@ fun diff_structured = (any a, any b,
 
           /* If the element is simple, add a change to the current
              thunk; otherwise recurse to handle its elements.  Note that
-             recursing into the element may result in E_map_bounds in case a
+             recursing into the element may result in E_constraint in case a
              non-byte element is found.  In that case, try to emit the
              thunk anyway.  */
           if (elem_simple_p (a, idx)
               || ! { sdiff_change (a'elem (idx), b'elem (idx),
-                                   a_full_name, b_full_name); } ?! 
E_map_bounds)
+                                   a_full_name, b_full_name); } ?! 
E_constraint)
           {
             var a_bytes = get_elem_bytes (a, idx);
             var b_bytes = get_elem_bytes (b, idx);
@@ -323,7 +323,7 @@ fun diff_structured = (any a, any b,
 
   try
   {
-    if (! { sdiff_change (a, b, prefix_a, prefix_b); } ?! E_map_bounds)
+    if (! { sdiff_change (a, b, prefix_a, prefix_b); } ?! E_constraint)
     {
       var a_bytes = byte[a'size] @ a'ios : a'offset;
       var b_bytes = byte[b'size] @ b'ios : b'offset;
@@ -337,7 +337,7 @@ fun diff_structured = (any a, any b,
                      :bvalue format_value (b);
     }
   }
-  catch if E_map_bounds
+  catch if E_constraint
   {
     raise Exception { code = EC_inval,
                       name = "invalid argument",
diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
index 3bfd3d4e..e24f6702 100644
--- a/testsuite/Makefile.am
+++ b/testsuite/Makefile.am
@@ -519,6 +519,9 @@ EXTRA_DIST = \
   poke.map/maps-unions-11.pk \
   poke.map/maps-unions-12.pk \
   poke.map/maps-unions-13.pk \
+  poke.map/maps-unions-14.pk \
+  poke.map/maps-unions-15.pk \
+  poke.map/maps-unions-16.pk \
   poke.map/maps-unions-method-1.pk \
   poke.map/maps-unions-method-2.pk \
   poke.map/maps-unions-method-3.pk \
@@ -1974,6 +1977,9 @@ EXTRA_DIST = \
   poke.pkl/scons-union-9.pk \
   poke.pkl/scons-union-10.pk \
   poke.pkl/scons-union-11.pk \
+  poke.pkl/scons-union-12.pk \
+  poke.pkl/scons-union-13.pk \
+  poke.pkl/scons-union-14.pk \
   poke.pkl/scons-union-diag-1.pk \
   poke.pkl/scons-union-method-1.pk \
   poke.pkl/scons-union-method-2.pk \
diff --git a/testsuite/poke.map/maps-unions-14.pk 
b/testsuite/poke.map/maps-unions-14.pk
new file mode 100644
index 00000000..057a491a
--- /dev/null
+++ b/testsuite/poke.map/maps-unions-14.pk
@@ -0,0 +1,11 @@
+/* { dg-do run } */
+/* { dg-data {c*} {0x00 0x00 0x00 0x01} } */
+
+type Foo = struct { byte[3#b] bad; };
+
+var tag = 2;
+type Bar = union { Foo foo : tag == 0; int bar : tag == 2; };
+
+/* { dg-command {.set endian big} } */
+/* { dg-command { Bar @ 0#B } } */
+/* { dg-output "Bar \{bar=1\}" } */
diff --git a/testsuite/poke.map/maps-unions-15.pk 
b/testsuite/poke.map/maps-unions-15.pk
new file mode 100644
index 00000000..2158eb12
--- /dev/null
+++ b/testsuite/poke.map/maps-unions-15.pk
@@ -0,0 +1,11 @@
+/* { dg-do run } */
+/* { dg-data {c*} {0x00 0x00 0x00 0x01} } */
+
+type Foo = struct { byte[3#b] bad; };
+
+var tag = 3;
+type Bar = union { Foo foo : tag == 0; int bar : tag == 2; };
+
+/* { dg-command {.set endian big} } */
+/* { dg-command { try Bar @ 0#B; catch if E_constraint { print "caught\n"; } } 
} */
+/* { dg-output "caught" } */
diff --git a/testsuite/poke.map/maps-unions-16.pk 
b/testsuite/poke.map/maps-unions-16.pk
new file mode 100644
index 00000000..0ca4ecfc
--- /dev/null
+++ b/testsuite/poke.map/maps-unions-16.pk
@@ -0,0 +1,8 @@
+/* { dg-do run } */
+/* { dg-data {c*} {0x00 0x00 0x00 0x01} } */
+
+type Foo = struct { byte[3#b] bad; };
+
+/* { dg-command {.set endian big} } */
+/* { dg-command { try Foo @ 0#B; catch if E_constraint { print "caught\n"; } } 
} */
+/* { dg-output "caught" } */
diff --git a/testsuite/poke.pkl/scons-union-12.pk 
b/testsuite/poke.pkl/scons-union-12.pk
new file mode 100644
index 00000000..ffabdb30
--- /dev/null
+++ b/testsuite/poke.pkl/scons-union-12.pk
@@ -0,0 +1,9 @@
+/* { dg-do run } */
+
+type Foo = struct { byte[3#b] bad; };
+
+var tag = 2;
+type Bar = union { Foo foo : tag == 0; int bar : tag == 2; };
+
+/* { dg-command { Bar {} } } */
+/* { dg-output "Bar \{bar=0\}" } */
diff --git a/testsuite/poke.pkl/scons-union-13.pk 
b/testsuite/poke.pkl/scons-union-13.pk
new file mode 100644
index 00000000..afc29323
--- /dev/null
+++ b/testsuite/poke.pkl/scons-union-13.pk
@@ -0,0 +1,9 @@
+/* { dg-do run } */
+
+type Foo = struct { byte[3#b] bad; };
+
+var tag = 3;
+type Bar = union { Foo foo : tag == 0; int bar : tag == 2; };
+
+/* { dg-command { try Bar {}; catch if E_constraint { print "caught\n"; } } } 
*/
+/* { dg-output "caught" } */
diff --git a/testsuite/poke.pkl/scons-union-14.pk 
b/testsuite/poke.pkl/scons-union-14.pk
new file mode 100644
index 00000000..24ff17f0
--- /dev/null
+++ b/testsuite/poke.pkl/scons-union-14.pk
@@ -0,0 +1,6 @@
+/* { dg-do run } */
+
+type Foo = struct { byte[3#b] bad; };
+
+/* { dg-command { try Foo {}; catch if E_constraint { print "caught\n"; } } } 
*/
+/* { dg-output "caught" } */
-- 
2.11.0




reply via email to

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