From: Gregory Heytings <gregory@heytings.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Istvan Marko <mi-ebugs@kismala.com>, Eli Zaretskii <eliz@gnu.org>,
61504@debbugs.gnu.org
Subject: bug#61504: 29.0.60; executing byte-code from previous build causes SIGSEGV crash
Date: Tue, 14 Feb 2023 16:00:35 +0000 [thread overview]
Message-ID: <0f053182b0be67f5117f@heytings.org> (raw)
In-Reply-To: <jwvo7pw46nk.fsf-monnier+emacs@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 953 bytes --]
>
> Looks right to me.
>
Many thanks for your review!
>> @@ -940,10 +940,9 @@ #define DEFINE(name, value) [name] = &&insn_ ## name,
>> }
>>
>> CASE (Bsave_restriction):
>> - record_unwind_protect (save_restriction_restore,
>> - save_restriction_save ());
>> - record_unwind_protect (narrowing_locks_restore,
>> - narrowing_locks_save ());
>> + record_unwind_protect (save_restriction_and_narrowing_locks_restore,
>> + Fcons (save_restriction_save (),
>> + narrowing_locks_save ()));
>> NEXT;
>
> Shouldn't the value returned by `save_restriction_save` include the
> narrowing locks already?
>
> IOW rather than changing this `bytecode.c` code, the locks handling
> should be "hidden" inside `save_restriction_restore` and
> `save_restriction_save`, don't you think?
>
You mean, the attached patch? That's probably even better, indeed.
(Again it passes make and make check, with and without native
compilation.)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Improve-backward-compatibility-of-save-restriction.patch --]
[-- Type: text/x-diff; name=Improve-backward-compatibility-of-save-restriction.patch, Size: 5535 bytes --]
From 79c5581d34da4baecf5514c1d0d25cfbcc33f05d Mon Sep 17 00:00:00 2001
From: Gregory Heytings <gregory@heytings.org>
Date: Tue, 14 Feb 2023 15:59:16 +0000
Subject: [PATCH] Improve backward compatibility of save-restriction
* src/editfns.c (save_restriction_save_1): Renamed from
'save_restrictions_save'.
(save_restriction_restore_1): Renamed from
'save_restriction_restore'.
(save_restriction_restore): New function, combining
'save_restriction_save_1' and 'narrowing_locks_save'.
(save_restriction_save): New function, combining
'save_restriction_restore_1' and 'narrowing_locks_restore'.
(Fsave_restriction): Restore the previous code.
(narrowing_locks_save, narrowing_locks_restore): Make them static.
* src/lisp.h: Remove two functions that are not externally visible
anymore.
* src/comp.c (helper_save_restriction): Restore the previous code.
* src/bytecode.c (exec_byte_code): Restore the previous code.
* lisp/emacs-lisp/bytecomp.el (byte-compile-save-restriction):
Decrement unbinding count.
---
lisp/emacs-lisp/bytecomp.el | 2 +-
src/bytecode.c | 2 --
src/comp.c | 2 --
src/editfns.c | 26 +++++++++++++++++++-------
src/lisp.h | 2 --
5 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index c6cda6b588a..5df1205869c 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -4900,7 +4900,7 @@ byte-compile-save-excursion
(defun byte-compile-save-restriction (form)
(byte-compile-out 'byte-save-restriction 0)
(byte-compile-body-do-effect (cdr form))
- (byte-compile-out 'byte-unbind 2))
+ (byte-compile-out 'byte-unbind 1))
(defun byte-compile-save-current-buffer (form)
(byte-compile-out 'byte-save-current-buffer 0)
diff --git a/src/bytecode.c b/src/bytecode.c
index 8e214560f30..124348e5b35 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -942,8 +942,6 @@ #define DEFINE(name, value) [name] = &&insn_ ## name,
CASE (Bsave_restriction):
record_unwind_protect (save_restriction_restore,
save_restriction_save ());
- record_unwind_protect (narrowing_locks_restore,
- narrowing_locks_save ());
NEXT;
CASE (Bcatch): /* Obsolete since 25. */
diff --git a/src/comp.c b/src/comp.c
index 0e2dfd3913b..10cf7962ba1 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -5063,8 +5063,6 @@ helper_save_restriction (void)
{
record_unwind_protect (save_restriction_restore,
save_restriction_save ());
- record_unwind_protect (narrowing_locks_restore,
- narrowing_locks_save ());
}
static bool
diff --git a/src/editfns.c b/src/editfns.c
index ce133785e0b..1534f78ace7 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -2794,7 +2794,7 @@ reset_outermost_narrowings (void)
/* Helper functions to save and restore the narrowing locks of the
current buffer in Fsave_restriction. */
-Lisp_Object
+static Lisp_Object
narrowing_locks_save (void)
{
Lisp_Object buf = Fcurrent_buffer ();
@@ -2804,7 +2804,7 @@ narrowing_locks_save (void)
return Fcons (buf, Fcopy_sequence (locks));
}
-void
+static void
narrowing_locks_restore (Lisp_Object buf_and_saved_locks)
{
Lisp_Object buf = XCAR (buf_and_saved_locks);
@@ -2975,8 +2975,8 @@ DEFUN ("internal--unlock-narrowing", Finternal__unlock_narrowing,
return Qnil;
}
-Lisp_Object
-save_restriction_save (void)
+static Lisp_Object
+save_restriction_save_1 (void)
{
if (BEGV == BEG && ZV == Z)
/* The common case that the buffer isn't narrowed.
@@ -2999,8 +2999,8 @@ save_restriction_save (void)
}
}
-void
-save_restriction_restore (Lisp_Object data)
+static void
+save_restriction_restore_1 (Lisp_Object data)
{
struct buffer *cur = NULL;
struct buffer *buf = (CONSP (data)
@@ -3068,6 +3068,19 @@ save_restriction_restore (Lisp_Object data)
set_buffer_internal (cur);
}
+Lisp_Object
+save_restriction_save (void)
+{
+ return Fcons (save_restriction_save_1 (), narrowing_locks_save ());
+}
+
+void
+save_restriction_restore (Lisp_Object data)
+{
+ save_restriction_restore_1 (XCAR (data));
+ narrowing_locks_restore (XCDR (data));
+}
+
DEFUN ("save-restriction", Fsave_restriction, Ssave_restriction, 0, UNEVALLED, 0,
doc: /* Execute BODY, saving and restoring current buffer's restrictions.
The buffer's restrictions make parts of the beginning and end invisible.
@@ -3092,7 +3105,6 @@ DEFUN ("save-restriction", Fsave_restriction, Ssave_restriction, 0, UNEVALLED, 0
specpdl_ref count = SPECPDL_INDEX ();
record_unwind_protect (save_restriction_restore, save_restriction_save ());
- record_unwind_protect (narrowing_locks_restore, narrowing_locks_save ());
val = Fprogn (body);
return unbind_to (count, val);
}
diff --git a/src/lisp.h b/src/lisp.h
index 93197d38176..1276285e2f2 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4684,8 +4684,6 @@ XMODULE_FUNCTION (Lisp_Object o)
extern void save_excursion_restore (Lisp_Object, Lisp_Object);
extern Lisp_Object save_restriction_save (void);
extern void save_restriction_restore (Lisp_Object);
-extern Lisp_Object narrowing_locks_save (void);
-extern void narrowing_locks_restore (Lisp_Object);
extern Lisp_Object make_buffer_string (ptrdiff_t, ptrdiff_t, bool);
extern Lisp_Object make_buffer_string_both (ptrdiff_t, ptrdiff_t, ptrdiff_t,
ptrdiff_t, bool);
--
2.39.0
next prev parent reply other threads:[~2023-02-14 16:00 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-14 6:33 bug#61504: 29.0.60; executing byte-code from previous build causes SIGSEGV crash Istvan Marko
2023-02-14 9:29 ` Gregory Heytings
2023-02-14 13:29 ` Eli Zaretskii
2023-02-14 16:50 ` Mattias Engdegård
2023-02-14 17:00 ` Gregory Heytings
2023-02-14 17:16 ` Eli Zaretskii
2023-02-14 20:44 ` Gregory Heytings
2023-02-14 17:21 ` Mattias Engdegård
2023-02-14 20:46 ` Gregory Heytings
2023-02-14 20:32 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-14 20:47 ` Gregory Heytings
2023-02-14 15:22 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-14 16:00 ` Gregory Heytings [this message]
2023-02-14 16:47 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-14 16:51 ` Gregory Heytings
2023-02-14 17:36 ` Istvan Marko
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0f053182b0be67f5117f@heytings.org \
--to=gregory@heytings.org \
--cc=61504@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=mi-ebugs@kismala.com \
--cc=monnier@iro.umontreal.ca \
/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.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.