unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Andrew Whatson <whatson@gmail.com>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: guile-devel@gnu.org, 57948@debbugs.gnu.org
Subject: Re: [PATCH] Avoid 'frame-local-ref' errors when printing backtrace.
Date: Wed, 11 Jan 2023 15:24:15 +1000	[thread overview]
Message-ID: <CAPE069deSOMm8ZoDRd_opj46Rn_0UX3T0uhRUw0xL71QPQsWWg@mail.gmail.com> (raw)
In-Reply-To: <87czawvl0v.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 281 bytes --]

Ludovic Courtès <ludo@gnu.org> wrote:
>
> It would be great if you could add a simple test case though, so that
> the bug doesn’t eventually come back to haunt us.

I've finally tracked this one down, a patch with a unit test for this
bug is attached.

Cheers,
Andrew

[-- Attachment #2: test-frame-local-ref-error.patch --]
[-- Type: text/x-patch, Size: 2111 bytes --]

commit 164bdce6acf53796cb96ef1930a89c6caf84bc39
Author: Andrew Whatson <whatson@gmail.com>
Date:   Wed Jan 11 14:04:32 2023 +1000

    Test for 'frame-local-ref' errors when printing backtrace.
    
    This test reproduces the error from <https://bugs.gnu.org/56493>, and
    passes with the workaround which was merged in commit
    c7fa78fc751eb336bcfafbb5ac59c460ee2c5d7a.
    
    * test-suite/tests/eval.test ("avoid frame-local-ref out of range"): New
    test.

diff --git a/test-suite/tests/eval.test b/test-suite/tests/eval.test
index 9d20812f2..316153385 100644
--- a/test-suite/tests/eval.test
+++ b/test-suite/tests/eval.test
@@ -22,6 +22,7 @@
   :use-module ((system vm vm) :select (call-with-stack-overflow-handler))
   :use-module ((system vm frame) :select (frame-call-representation))
   :use-module (ice-9 documentation)
+  :use-module (ice-9 exceptions)
   :use-module (ice-9 local-eval))
 
 
@@ -387,7 +388,27 @@
       (and (eq? (car (frame-call-representation (car frames)))
                 'make-stack)
            (eq? (car (frame-call-representation (car (last-pair frames))))
-                'with-exception-handler)))))
+                'with-exception-handler))))
+
+  (pass-if "avoid frame-local-ref out of range"
+    (with-exception-handler
+        (lambda (ex)
+          ;; If frame-call-representation fails, we'll catch that
+          ;; instead of the expected "Wrong type to apply" error.
+          (string-prefix? "Wrong type to apply" (exception-message ex)))
+      (lambda ()
+        (with-exception-handler
+            (lambda (ex)
+              (let* ((stack (make-stack #t))
+                     (frames (stack->frames stack)))
+                (for-each frame-call-representation frames))
+              (raise-exception ex))
+          (lambda ()
+            ;; This throws a "Wrong type to apply" error, creating a
+            ;; frame with an incorrect number of local slots as
+            ;; described in bug <https://bugs.gnu.org/56493>.
+            (primitive-eval '(define foo (#t))))))
+      #:unwind? #t)))
 
 ;;;
 ;;; letrec init evaluation

  parent reply	other threads:[~2023-01-11  5:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-20  7:23 [PATCH] Avoid 'frame-local-ref' errors when printing backtrace Andrew Whatson
2022-09-21 10:50 ` Maxime Devos
2022-09-22 13:53   ` Andrew Whatson
2022-09-22 15:10     ` Maxime Devos
2022-10-12 20:34     ` Ludovic Courtès
2022-10-13  3:36       ` Andrew Whatson
2022-10-13 13:09         ` Ludovic Courtès
2023-01-11  5:24       ` Andrew Whatson [this message]
2023-01-11 23:03         ` Ludovic Courtès
2023-01-12  2:09           ` Andrew Whatson
2022-11-29 18:06     ` lloda
2022-09-22 13:58   ` Andrew Whatson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPE069deSOMm8ZoDRd_opj46Rn_0UX3T0uhRUw0xL71QPQsWWg@mail.gmail.com \
    --to=whatson@gmail.com \
    --cc=57948@debbugs.gnu.org \
    --cc=guile-devel@gnu.org \
    --cc=ludo@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).