Subject: [bug#54165] [PATCH v2 2/2] gnu: guile-bytestructures: add patch. (Closes: #54165)

From: Felix Lechner <[email-masked]>
Date: Fri, 7 Jun 2024 06:44:56 -0700

Adds the patch from a pull request recently submitted upstream. [1] The
maintainer has not responded yet, so there could be further updates as time
goes on.

With this commit, nyacc 1.08.1 builds successfully..

[1] https://github.com/TaylanUB/scheme-bytestructures/pull/48

Change-Id: I8cd248e6e33efd36f54ca3b31c17badf54a863c5
---
 gnu/packages/guile.scm                        |  3 +-
 .../guile-bytestructures-fix-54165.patch      | 92 +++++++++++++++++++
 2 files changed, 94 insertions(+), 1 deletion(-)
 create mode 100644 gnu/packages/patches/guile-bytestructures-fix-54165.patch

diff --git a/gnu/packages/guile.scm b/gnu/packages/guile.scm
index 0bbd4a12ad..f7ef0dceff 100644
--- a/gnu/packages/guile.scm
+++ b/gnu/packages/guile.scm
@@ -796,7 +796,8 @@ (define-public guile-bytestructures
               (file-name (git-file-name name version))
               (sha256
                (base32
-                "1gnh3p2042cch1nkapl0p4pv20q7qs8cxvvbp7a5h1dwqbrkdyss"))))
+                "1gnh3p2042cch1nkapl0p4pv20q7qs8cxvvbp7a5h1dwqbrkdyss"))
+              (patches (search-patches "guile-bytestructures-fix-54165.patch"))))
     (build-system gnu-build-system)
     (arguments
      `(#:make-flags '("GUILE_AUTO_COMPILE=0")     ;to prevent guild warnings
diff --git a/gnu/packages/patches/guile-bytestructures-fix-54165.patch b/gnu/packages/patches/guile-bytestructures-fix-54165.patch
new file mode 100644
index 0000000000..b91ca36df4
--- /dev/null
+++ b/gnu/packages/patches/guile-bytestructures-fix-54165.patch
@@ -0,0 +1,92 @@
+From 5082cdd2529f13286509a525a28f9d9917456fc1 Mon Sep 17 00:00:00 2001
+From: Felix Lechner <[email-masked]>
+Date: Fri, 7 Jun 2024 04:51:17 -0700
+Subject: [PATCH] Fix alignment in unpacked structs containing unions. (Closes:
+ #47)
+
+The 2.0.1 release suffered from a test failure [1] that caused some
+distributions to disable the test [2] but the underlying cause had yet
+to be identified.
+
+Based on a preliminary review of the code, the author of this commit
+believes there was a surplus line in the code [3] which is deleted
+here.  This is the proposed evidence: The line shadowed the
+'alignment' variable in line immediately above it. [4] Then, the same
+expression was used two lines down below. [5] In combination, the line
+being removed here seems to have been left over from editing under
+time pressure. It may also have been added inadvertently.
+
+On GNU Guix, this commit fixes the 'ref1' test for aligned struct
+bytestructures containing union members, which was referenced via
+"run-tests.body.scm:194: FAIL ref1" in Ludo's original report. [6] The
+test output can be found at the bottom of this message.
+
+This commit closes Github issue #47. [7]
+
+[1] https://issues.guix.gnu.org/54165#1
+[2] https://github.com/alpinelinux/aports/commit/2d8604645ca38552343c61fbc65728a2881e6ddd
+[3] https://github.com/TaylanUB/scheme-bytestructures/blob/a6d5d25b26c0c5ef1f5fa38e2472fbf6a32cdf89/bytestructures/body/struct.scm#L110
+[4] https://github.com/TaylanUB/scheme-bytestructures/blob/a6d5d25b26c0c5ef1f5fa38e2472fbf6a32cdf89/bytestructures/body/struct.scm#L109
+[5] https://github.com/TaylanUB/scheme-bytestructures/blob/a6d5d25b26c0c5ef1f5fa38e2472fbf6a32cdf89/bytestructures/body/struct.scm#L112
+[6] https://github.com/TaylanUB/scheme-bytestructures/blob/a6d5d25b26c0c5ef1f5fa38e2472fbf6a32cdf89/run-tests.body.scm#L194
+[7] https://github.com/TaylanUB/scheme-bytestructures/issues/47
+
+* * *
+
+Group begin: aligned
+Test begin:
+  test-name: "ref1"
+  source-file: "run-tests.body.scm"
+  source-line: 194
+  source-form: (test-eqv "ref1" 321 (bytestructure-ref bs (quote a)))
+Test end:
+  result-kind: pass
+  actual-value: 321
+  expected-value: 321
+Test begin:
+  test-name: "ref2"
+  source-file: "run-tests.body.scm"
+  source-line: 196
+  source-form: (test-eqv "ref2" 456 (bytestructure-ref bs (quote b)))
+Test end:
+  result-kind: pass
+  actual-value: 456
+  expected-value: 456
+Test begin:
+  test-name: "set1"
+  source-file: "run-tests.body.scm"
+  source-line: 197
+  source-form: (test-eqv "set1" 789 (begin (bytestructure-set! bs (quote a) 789) (bytestructure-ref bs (quote a))))
+Test end:
+  result-kind: pass
+  actual-value: 789
+  expected-value: 789
+Test begin:
+  test-name: "set2"
+  source-file: "run-tests.body.scm"
+  source-line: 199
+  source-form: (test-eqv "set2" 987 (begin (bytestructure-set! bs (quote b) 987) (bytestructure-ref bs (quote b))))
+Test end:
+  result-kind: pass
+  actual-value: 987
+  expected-value: 987
+Group end: aligned
+---
+ bytestructures/body/struct.scm | 1 -
+ 1 file changed, 1 deletion(-)
+
+diff --git a/bytestructures/body/struct.scm b/bytestructures/body/struct.scm
+index 07797b5..0113a17 100644
+--- a/bytestructures/body/struct.scm
++++ b/bytestructures/body/struct.scm
+@@ -107,7 +107,6 @@
+     (let ((descriptor (cadr field-spec)))
+       (bytestructure-descriptor-size descriptor)))
+   (let* ((alignment (apply max (map field-spec-alignment field-specs)))
+-         (alignment (pack-alignment pack alignment))
+          (size (apply max (map field-spec-size field-specs)))
+          (position (align position size (pack-alignment pack alignment))))
+     (let loop ((field-specs field-specs)
+-- 
+2.41.0
+
-- 
2.41.0