unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* [PATCH] Avoid 'frame-local-ref' errors when printing backtrace.
@ 2022-09-20  7:23 Andrew Whatson
  2022-09-21 10:50 ` Maxime Devos
  0 siblings, 1 reply; 8+ messages in thread
From: Andrew Whatson @ 2022-09-20  7:23 UTC (permalink / raw)
  To: guile-devel; +Cc: Andrew Whatson

Workaround for <https://bugs.gnu.org/57948>.

* module/system/vm/frame.scm (frame-call-representation): Treat a
binding as "unspecified" if its slot exceeds 'frame-num-locals'.
---
 module/system/vm/frame.scm | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/module/system/vm/frame.scm b/module/system/vm/frame.scm
index 3be73e29c..6b14fc62a 100644
--- a/module/system/vm/frame.scm
+++ b/module/system/vm/frame.scm
@@ -381,8 +381,16 @@
         (frame-local-ref frame i 'scm))
        ((find-slot i bindings)
         => (lambda (binding)
-             (let ((val (frame-local-ref frame (binding-slot binding)
-                                         (binding-representation binding))))
+             (let* ((slot (binding-slot binding))
+                    ;; HACK: Avoid out-of-range from frame-local-ref.
+                    ;; Some frames have bindings beyond nlocals.  That
+                    ;; is probably a bug somewhere else, but at least
+                    ;; this workaround allows them to be printed.
+                    (val (if (< slot nlocals)
+                             (frame-local-ref frame slot
+                                              (binding-representation binding))
+                             ;; else #<unspecified>
+                             )))
                ;; It could be that there's a value that isn't clobbered
                ;; by a call but that isn't live after a call either.  In
                ;; that case, if GC runs during the call, the value will
-- 
2.37.3




^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] Avoid 'frame-local-ref' errors when printing backtrace.
  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 13:58   ` Andrew Whatson
  0 siblings, 2 replies; 8+ messages in thread
From: Maxime Devos @ 2022-09-21 10:50 UTC (permalink / raw)
  To: Andrew Whatson, guile-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 1264 bytes --]



On 20-09-2022 09:23, Andrew Whatson wrote:
>           => (lambda (binding)
> -             (let ((val (frame-local-ref frame (binding-slot binding)
> -                                         (binding-representation binding))))
> +             (let* ((slot (binding-slot binding))
> +                    ;; HACK: Avoid out-of-range from frame-local-ref.
> +                    ;; Some frames have bindings beyond nlocals.  That
> +                    ;; is probably a bug somewhere else, but at least
> +                    ;; this workaround allows them to be printed.
> +                    (val (if (< slot nlocals)
> +                             (frame-local-ref frame slot
> +                                              (binding-representation binding))
> +                             ;; else #<unspecified > +                             )))

I propose to add a link to the bug report in the comments, for future 
reference.  Also, there is an interest in returning zero values in such 
cases: <https://www.mail-archive.com/bug-guile@gnu.org/msg07927.html> 
(that patch didn't work out, but the sentiment is still there).

As such, I recommend being explicit:

(if [...]
     [...]
     *unspecified*)

Greetings,
Maxime.

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 929 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] Avoid 'frame-local-ref' errors when printing backtrace.
  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-09-22 13:58   ` Andrew Whatson
  1 sibling, 2 replies; 8+ messages in thread
From: Andrew Whatson @ 2022-09-22 13:53 UTC (permalink / raw)
  To: guile-devel; +Cc: Andrew Whatson

Workaround for <https://bugs.gnu.org/57948>.

* module/system/vm/frame.scm (frame-call-representation): Treat a
binding as "unspecified" if its slot exceeds 'frame-num-locals'.
---
 module/system/vm/frame.scm | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/module/system/vm/frame.scm b/module/system/vm/frame.scm
index 3be73e29c..e36eb797c 100644
--- a/module/system/vm/frame.scm
+++ b/module/system/vm/frame.scm
@@ -381,8 +381,16 @@
         (frame-local-ref frame i 'scm))
        ((find-slot i bindings)
         => (lambda (binding)
-             (let ((val (frame-local-ref frame (binding-slot binding)
-                                         (binding-representation binding))))
+             (let* ((slot (binding-slot binding))
+                    ;; HACK: Avoid out-of-range from frame-local-ref.
+                    ;; Some frames have bindings beyond nlocals.  That
+                    ;; is probably a bug somewhere else, but at least
+                    ;; this workaround allows them to be printed.
+                    ;; See <https://bugs.gnu.org/57948>.
+                    (val (if (< slot nlocals)
+                             (frame-local-ref frame slot
+                                              (binding-representation binding))
+                             *unspecified*)))
                ;; It could be that there's a value that isn't clobbered
                ;; by a call but that isn't live after a call either.  In
                ;; that case, if GC runs during the call, the value will
-- 
2.37.3




^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] Avoid 'frame-local-ref' errors when printing backtrace.
  2022-09-21 10:50 ` Maxime Devos
  2022-09-22 13:53   ` Andrew Whatson
@ 2022-09-22 13:58   ` Andrew Whatson
  1 sibling, 0 replies; 8+ messages in thread
From: Andrew Whatson @ 2022-09-22 13:58 UTC (permalink / raw)
  To: Maxime Devos; +Cc: guile-devel

Maxime Devos <maximedevos@telenet.be> wrote:
>
> I propose to add a link to the bug report in the comments, for future
> reference.  Also, there is an interest in returning zero values in such
> cases: <https://www.mail-archive.com/bug-guile@gnu.org/msg07927.html>
> (that patch didn't work out, but the sentiment is still there).
>
> As such, I recommend being explicit:
>
> (if [...]
>      [...]
>      *unspecified*)

Done and done!  Thanks for the review :)



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Avoid 'frame-local-ref' errors when printing backtrace.
  2022-09-22 13:53   ` Andrew Whatson
@ 2022-09-22 15:10     ` Maxime Devos
  2022-10-12 20:34     ` Ludovic Courtès
  1 sibling, 0 replies; 8+ messages in thread
From: Maxime Devos @ 2022-09-22 15:10 UTC (permalink / raw)
  To: Andrew Whatson, guile-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 982 bytes --]



On 22-09-2022 15:53, Andrew Whatson wrote:
> -             (let ((val (frame-local-ref frame (binding-slot binding)
> -                                         (binding-representation binding))))
> +             (let* ((slot (binding-slot binding))
> +                    ;; HACK: Avoid out-of-range from frame-local-ref.
> +                    ;; Some frames have bindings beyond nlocals.  That
> +                    ;; is probably a bug somewhere else, but at least
> +                    ;; this workaround allows them to be printed.
> +                    ;; See<https://bugs.gnu.org/57948>.
> +                    (val (if (< slot nlocals)
> +                             (frame-local-ref frame slot
> +                                              (binding-representation binding))
> +*unspecified*)))

Looks reasonable from here, FWIW (I'm not familiar with (system vm frame)).

(Please keep in mind I do not have commit access.)

Greetings,
Maxime.

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 929 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Avoid 'frame-local-ref' errors when printing backtrace.
  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
  1 sibling, 1 reply; 8+ messages in thread
From: Ludovic Courtès @ 2022-10-12 20:34 UTC (permalink / raw)
  To: Andrew Whatson; +Cc: guile-devel, 57948

Hi Andrew,

Andrew Whatson <whatson@gmail.com> skribis:

> Workaround for <https://bugs.gnu.org/57948>.
>
> * module/system/vm/frame.scm (frame-call-representation): Treat a
> binding as "unspecified" if its slot exceeds 'frame-num-locals'.

Yay, great to see that fixed (or almost)!

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.

Could you send an updated patch?

Thanks,
Ludo’.

PS: BTW, it’ll be great to have more patches from you!  :-) To that end,
    please check out the new Guile copyright policy and let us know what
    option you’d like to choose:
    <https://lists.gnu.org/archive/html/guile-devel/2022-10/msg00008.html>.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Avoid 'frame-local-ref' errors when printing backtrace.
  2022-10-12 20:34     ` Ludovic Courtès
@ 2022-10-13  3:36       ` Andrew Whatson
  2022-10-13 13:09         ` Ludovic Courtès
  0 siblings, 1 reply; 8+ messages in thread
From: Andrew Whatson @ 2022-10-13  3:36 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guile-devel, 57948

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.
>
> Could you send an updated patch?

Ah yes, getting this covered in a test is on my list.  I had trouble
writing a reproducer previously, I think the bug might only occur in a
nested compilation context (top-level error compiling a dependency
module), but I'll have another go.

> PS: BTW, it’ll be great to have more patches from you!  :-) To that end,
>     please check out the new Guile copyright policy and let us know what
>     option you’d like to choose:
>     <https://lists.gnu.org/archive/html/guile-devel/2022-10/msg00008.html>.

I have already assigned copyright of my work on Guile to the FSF,
happy for that to remain.

That said, I'm glad to see this requirement being eased!

Cheers,
Andrew



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Avoid 'frame-local-ref' errors when printing backtrace.
  2022-10-13  3:36       ` Andrew Whatson
@ 2022-10-13 13:09         ` Ludovic Courtès
  0 siblings, 0 replies; 8+ messages in thread
From: Ludovic Courtès @ 2022-10-13 13:09 UTC (permalink / raw)
  To: Andrew Whatson; +Cc: guile-devel, 57948

Hi,

Andrew Whatson <whatson@gmail.com> skribis:

> 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.
>>
>> Could you send an updated patch?
>
> Ah yes, getting this covered in a test is on my list.  I had trouble
> writing a reproducer previously, I think the bug might only occur in a
> nested compilation context (top-level error compiling a dependency
> module), but I'll have another go.

Awesome.

>> PS: BTW, it’ll be great to have more patches from you!  :-) To that end,
>>     please check out the new Guile copyright policy and let us know what
>>     option you’d like to choose:
>>     <https://lists.gnu.org/archive/html/guile-devel/2022-10/msg00008.html>.
>
> I have already assigned copyright of my work on Guile to the FSF,
> happy for that to remain.

Oh sorry I had overlooked that, perfect!

Thanks,
Ludo’.



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-10-13 13:09 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2022-09-22 13:58   ` Andrew Whatson

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).