From: Paul Eggert <eggert@cs.ucla.edu>
To: Pip Cet <pipcet@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: [Emacs-diffs] master d02c2f7 4/4: Speed up maybe_gc when GC is inhibited
Date: Sun, 21 Jul 2019 12:33:40 -0700 [thread overview]
Message-ID: <6c1975e5-eab1-d4b6-8903-dfa3c405f734@cs.ucla.edu> (raw)
In-Reply-To: <CAOqdjBesVq=Pz7S-7UE-NaC0X46Pg7H1OCiFryY4nzNBZZ4ByA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 122 bytes --]
Pip Cet wrote:
> This looks unsafe to me.
Right you are, of course; thanks for checking that. I installed the attached.
[-- Attachment #2: 0001-Fix-lifetime-error-in-previous-patch.patch --]
[-- Type: text/x-patch, Size: 5103 bytes --]
From 5d4dd552c29279b8a9e6ed269a2dc3afc36f73b9 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sun, 21 Jul 2019 12:31:51 -0700
Subject: [PATCH] Fix lifetime error in previous patch
Problem reported by Pip Cet in:
https://lists.gnu.org/r/emacs-devel/2019-07/msg00520.html
* src/alloc.c (inhibit_garbage_collection): Use new function.
(allow_garbage_collection): Accept intmax_t, not pointer.
* src/eval.c (default_toplevel_binding, do_one_unbind)
(backtrace_eval_unrewind, Fbacktrace__locals, mark_specpdl):
Support SPECPDL_UNWIND_INTMAX.
(record_unwind_protect_excursion): New function.
* src/lisp.h (enum specbind_tag): New constant SPECPDL_UNWIND_INTMAX.
(union specbinding): New member unwind_intmax.
---
src/alloc.c | 8 +++-----
src/eval.c | 16 ++++++++++++++++
src/lisp.h | 7 +++++++
3 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/src/alloc.c b/src/alloc.c
index 50015808e5..aa9200f2eb 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -5505,10 +5505,9 @@ staticpro (Lisp_Object const *varaddress)
consing_until_gc to speed up maybe_gc when GC is inhibited. */
static void
-allow_garbage_collection (void *ptr)
+allow_garbage_collection (intmax_t consing)
{
- object_ct *p = ptr;
- consing_until_gc = *p;
+ consing_until_gc = consing;
garbage_collection_inhibited--;
}
@@ -5516,8 +5515,7 @@ ptrdiff_t
inhibit_garbage_collection (void)
{
ptrdiff_t count = SPECPDL_INDEX ();
- object_ct consing = consing_until_gc;
- record_unwind_protect_ptr (allow_garbage_collection, &consing);
+ record_unwind_protect_intmax (allow_garbage_collection, consing_until_gc);
garbage_collection_inhibited++;
consing_until_gc = OBJECT_CT_MAX;
return count;
diff --git a/src/eval.c b/src/eval.c
index 02a6c3555a..b890aa6f7f 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -674,6 +674,7 @@ default_toplevel_binding (Lisp_Object symbol)
case SPECPDL_UNWIND_ARRAY:
case SPECPDL_UNWIND_PTR:
case SPECPDL_UNWIND_INT:
+ case SPECPDL_UNWIND_INTMAX:
case SPECPDL_UNWIND_EXCURSION:
case SPECPDL_UNWIND_VOID:
case SPECPDL_BACKTRACE:
@@ -3394,6 +3395,15 @@ record_unwind_protect_int (void (*function) (int), int arg)
grow_specpdl ();
}
+void
+record_unwind_protect_intmax (void (*function) (intmax_t), intmax_t arg)
+{
+ specpdl_ptr->unwind_intmax.kind = SPECPDL_UNWIND_INTMAX;
+ specpdl_ptr->unwind_intmax.func = function;
+ specpdl_ptr->unwind_intmax.arg = arg;
+ grow_specpdl ();
+}
+
void
record_unwind_protect_excursion (void)
{
@@ -3448,6 +3458,9 @@ do_one_unbind (union specbinding *this_binding, bool unwinding,
case SPECPDL_UNWIND_INT:
this_binding->unwind_int.func (this_binding->unwind_int.arg);
break;
+ case SPECPDL_UNWIND_INTMAX:
+ this_binding->unwind_intmax.func (this_binding->unwind_intmax.arg);
+ break;
case SPECPDL_UNWIND_VOID:
this_binding->unwind_void.func ();
break;
@@ -3784,6 +3797,7 @@ backtrace_eval_unrewind (int distance)
case SPECPDL_UNWIND_ARRAY:
case SPECPDL_UNWIND_PTR:
case SPECPDL_UNWIND_INT:
+ case SPECPDL_UNWIND_INTMAX:
case SPECPDL_UNWIND_VOID:
case SPECPDL_BACKTRACE:
break;
@@ -3917,6 +3931,7 @@ NFRAMES and BASE specify the activation frame to use, as in `backtrace-frame'.
case SPECPDL_UNWIND_ARRAY:
case SPECPDL_UNWIND_PTR:
case SPECPDL_UNWIND_INT:
+ case SPECPDL_UNWIND_INTMAX:
case SPECPDL_UNWIND_EXCURSION:
case SPECPDL_UNWIND_VOID:
case SPECPDL_BACKTRACE:
@@ -3979,6 +3994,7 @@ mark_specpdl (union specbinding *first, union specbinding *ptr)
case SPECPDL_UNWIND_PTR:
case SPECPDL_UNWIND_INT:
+ case SPECPDL_UNWIND_INTMAX:
case SPECPDL_UNWIND_VOID:
break;
diff --git a/src/lisp.h b/src/lisp.h
index 6d101fed90..9d37629bc4 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -3156,6 +3156,7 @@ enum specbind_tag {
Its elements are potential Lisp_Objects. */
SPECPDL_UNWIND_PTR, /* Likewise, on void *. */
SPECPDL_UNWIND_INT, /* Likewise, on int. */
+ SPECPDL_UNWIND_INTMAX, /* Likewise, on intmax_t. */
SPECPDL_UNWIND_EXCURSION, /* Likewise, on an execursion. */
SPECPDL_UNWIND_VOID, /* Likewise, with no arg. */
SPECPDL_BACKTRACE, /* An element of the backtrace. */
@@ -3191,6 +3192,11 @@ union specbinding
void (*func) (int);
int arg;
} unwind_int;
+ struct {
+ ENUM_BF (specbind_tag) kind : CHAR_BIT;
+ void (*func) (intmax_t);
+ intmax_t arg;
+ } unwind_intmax;
struct {
ENUM_BF (specbind_tag) kind : CHAR_BIT;
Lisp_Object marker, window;
@@ -4118,6 +4124,7 @@ extern void record_unwind_protect (void (*) (Lisp_Object), Lisp_Object);
extern void record_unwind_protect_array (Lisp_Object *, ptrdiff_t);
extern void record_unwind_protect_ptr (void (*) (void *), void *);
extern void record_unwind_protect_int (void (*) (int), int);
+extern void record_unwind_protect_intmax (void (*) (intmax_t), intmax_t);
extern void record_unwind_protect_void (void (*) (void));
extern void record_unwind_protect_excursion (void);
extern void record_unwind_protect_nothing (void);
--
2.17.1
next prev parent reply other threads:[~2019-07-21 19:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20190721182418.6344.52048@vcs0.savannah.gnu.org>
[not found] ` <20190721182420.CA41920BE2@vcs0.savannah.gnu.org>
2019-07-21 18:58 ` master d02c2f7 4/4: Speed up maybe_gc when GC is inhibited Pip Cet
2019-07-21 19:33 ` Paul Eggert [this message]
[not found] ` <20190721182420.57AA720BE2@vcs0.savannah.gnu.org>
2019-07-22 13:36 ` [Emacs-diffs] master cf28594 2/4: Improve doc for hash tables Stefan Monnier
2019-07-23 4:33 ` Paul Eggert
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/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6c1975e5-eab1-d4b6-8903-dfa3c405f734@cs.ucla.edu \
--to=eggert@cs.ucla.edu \
--cc=emacs-devel@gnu.org \
--cc=pipcet@gmail.com \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).