emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r117942: Fix local_cons etc. to not exhaust the stac


From: Paul Eggert
Subject: [Emacs-diffs] trunk r117942: Fix local_cons etc. to not exhaust the stack when in a loop.
Date: Thu, 25 Sep 2014 02:01:21 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 117942
revision-id: address@hidden
parent: address@hidden
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Wed 2014-09-24 19:01:14 -0700
message:
  Fix local_cons etc. to not exhaust the stack when in a loop.
  
  Problem reported in:
  http://lists.gnu.org/archive/html/emacs-devel/2014-09/msg00696.html
  * buffer.c (Fother_buffer, other_buffer_safely, init_buffer):
  * charset.c (load_charset_map_from_file, Ffind_charset_region)
  (Ffind_charset_string):
  * chartab.c (uniprop_encode_value_numeric, uniprop_table):
  * data.c (wrong_range):
  * editfns.c (Fpropertize, format2):
  * emacs.c (init_cmdargs, decode_env_path):
  * fileio.c (auto_save_error):
  * fns.c (Fyes_or_no_p):
  * font.c (font_style_to_value, font_parse_xlfd)
  (font_parse_family_registry, font_delete_unmatched)
  (font_add_log):
  * fontset.c (Fset_fontset_font):
  * frame.c (x_get_arg):
  * keyboard.c (echo_dash, safe_run_hooks_error, parse_menu_item)
  (read_char_minibuf_menu_prompt):
  * keymap.c (silly_event_symbol_error, describe_vector):
  * lread.c (load_warn_old_style_backquotes):
  * menu.c (single_menu_item):
  * minibuf.c (Fread_buffer):
  * process.c (status_message, Fformat_network_address)
  (server_accept_connection):
  * textprop.c (copy_text_properties):
  * xdisp.c (Fcurrent_bidi_paragraph_direction):
  * xfns.c (x_default_scroll_bar_color_parameter):
  * xfont.c (xfont_open):
  * xselect.c (x_clipboard_manager_error_1):
  * xterm.c (x_term_init):
  Put USE_LOCAL_ALLOCA at the start of the function.
  * fns.c (maybe_resize_hash_table): Use build_string instead of
  build_local_string, since we'd otherwise need a conditional
  USE_LOCAL_ALLOCA here, but this is just debugging output and is
  not worth the bother of optimization.
  * font.c (font_delete_unmatched): Remove by-hand code that
  observed MAX_ALLOCA limit, since it's now done automatically.
  * keymap.c (Fsingle_key_description): Put USE_SAFE_ALLOCA at top,
  since build_local_string needs its sa_alloc.
  * lisp.h (lisp_word_count): New function.
  (SAFE_ALLOCA_LISP): Use it.
  (USE_LOCAL_ALLOCA): New macro.
  (local_cons, make_local_vector, make_local_string):
  Observe the MAX_ALLOCA limit.
  (LISP_STRING_OVERHEAD): New constant.
  (make_local_string): Use it.
modified:
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/buffer.c                   buffer.c-20091113204419-o5vbwnq5f7feedwu-264
  src/charset.c                  charset.c-20091113204419-o5vbwnq5f7feedwu-1075
  src/chartab.c                  chartab.c-20091113204419-o5vbwnq5f7feedwu-8539
  src/data.c                     data.c-20091113204419-o5vbwnq5f7feedwu-251
  src/editfns.c                  editfns.c-20091113204419-o5vbwnq5f7feedwu-255
  src/emacs.c                    emacs.c-20091113204419-o5vbwnq5f7feedwu-241
  src/fileio.c                   fileio.c-20091113204419-o5vbwnq5f7feedwu-210
  src/fns.c                      fns.c-20091113204419-o5vbwnq5f7feedwu-203
  src/font.c                     font.c-20091113204419-o5vbwnq5f7feedwu-8540
  src/fontset.c                  fontset.c-20091113204419-o5vbwnq5f7feedwu-1079
  src/frame.c                    frame.c-20091113204419-o5vbwnq5f7feedwu-243
  src/keyboard.c                 keyboard.c-20091113204419-o5vbwnq5f7feedwu-449
  src/keymap.c                   keymap.c-20091113204419-o5vbwnq5f7feedwu-219
  src/lisp.h                     lisp.h-20091113204419-o5vbwnq5f7feedwu-253
  src/lread.c                    lread.c-20091113204419-o5vbwnq5f7feedwu-266
  src/menu.c                     menu.c-20091113204419-o5vbwnq5f7feedwu-8676
  src/minibuf.c                  minibuf.c-20091113204419-o5vbwnq5f7feedwu-242
  src/process.c                  process.c-20091113204419-o5vbwnq5f7feedwu-462
  src/textprop.c                 textprop.c-20091113204419-o5vbwnq5f7feedwu-512
  src/xdisp.c                    xdisp.c-20091113204419-o5vbwnq5f7feedwu-240
  src/xfns.c                     xfns.c-20091113204419-o5vbwnq5f7feedwu-274
  src/xfont.c                    xfont.c-20091113204419-o5vbwnq5f7feedwu-8547
  src/xselect.c                  xselect.c-20091113204419-o5vbwnq5f7feedwu-543
  src/xterm.c                    xterm.c-20091113204419-o5vbwnq5f7feedwu-244
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2014-09-24 20:54:25 +0000
+++ b/src/ChangeLog     2014-09-25 02:01:14 +0000
@@ -1,3 +1,53 @@
+2014-09-25  Paul Eggert  <address@hidden>
+
+       Fix local_cons etc. to not exhaust the stack when in a loop.
+       Problem reported in:
+       http://lists.gnu.org/archive/html/emacs-devel/2014-09/msg00696.html
+       * buffer.c (Fother_buffer, other_buffer_safely, init_buffer):
+       * charset.c (load_charset_map_from_file, Ffind_charset_region)
+       (Ffind_charset_string):
+       * chartab.c (uniprop_encode_value_numeric, uniprop_table):
+       * data.c (wrong_range):
+       * editfns.c (Fpropertize, format2):
+       * emacs.c (init_cmdargs, decode_env_path):
+       * fileio.c (auto_save_error):
+       * fns.c (Fyes_or_no_p):
+       * font.c (font_style_to_value, font_parse_xlfd)
+       (font_parse_family_registry, font_delete_unmatched)
+       (font_add_log):
+       * fontset.c (Fset_fontset_font):
+       * frame.c (x_get_arg):
+       * keyboard.c (echo_dash, safe_run_hooks_error, parse_menu_item)
+       (read_char_minibuf_menu_prompt):
+       * keymap.c (silly_event_symbol_error, describe_vector):
+       * lread.c (load_warn_old_style_backquotes):
+       * menu.c (single_menu_item):
+       * minibuf.c (Fread_buffer):
+       * process.c (status_message, Fformat_network_address)
+       (server_accept_connection):
+       * textprop.c (copy_text_properties):
+       * xdisp.c (Fcurrent_bidi_paragraph_direction):
+       * xfns.c (x_default_scroll_bar_color_parameter):
+       * xfont.c (xfont_open):
+       * xselect.c (x_clipboard_manager_error_1):
+       * xterm.c (x_term_init):
+       Put USE_LOCAL_ALLOCA at the start of the function.
+       * fns.c (maybe_resize_hash_table): Use build_string instead of
+       build_local_string, since we'd otherwise need a conditional
+       USE_LOCAL_ALLOCA here, but this is just debugging output and is
+       not worth the bother of optimization.
+       * font.c (font_delete_unmatched): Remove by-hand code that
+       observed MAX_ALLOCA limit, since it's now done automatically.
+       * keymap.c (Fsingle_key_description): Put USE_SAFE_ALLOCA at top,
+       since build_local_string needs its sa_alloc.
+       * lisp.h (lisp_word_count): New function.
+       (SAFE_ALLOCA_LISP): Use it.
+       (USE_LOCAL_ALLOCA): New macro.
+       (local_cons, make_local_vector, make_local_string):
+       Observe the MAX_ALLOCA limit.
+       (LISP_STRING_OVERHEAD): New constant.
+       (make_local_string): Use it.
+
 2014-09-24  Paul Eggert  <address@hidden>
 
        Default to stack objects on non-GNU/Linux, non-DOS_NT platforms.

=== modified file 'src/buffer.c'
--- a/src/buffer.c      2014-09-17 15:34:37 +0000
+++ b/src/buffer.c      2014-09-25 02:01:14 +0000
@@ -1509,8 +1509,9 @@
 The buffer is found by scanning the selected or specified frame's buffer
 list first, followed by the list of all buffers.  If no other buffer
 exists, return the buffer `*scratch*' (creating it if necessary).  */)
-  (register Lisp_Object buffer, Lisp_Object visible_ok, Lisp_Object frame)
+  (Lisp_Object buffer, Lisp_Object visible_ok, Lisp_Object frame)
 {
+  USE_LOCAL_ALLOCA;
   struct frame *f = decode_any_frame (frame);
   Lisp_Object tail = f->buffer_list, pred = f->buffer_predicate;
   Lisp_Object buf, notsogood = Qnil;
@@ -1569,6 +1570,7 @@
 Lisp_Object
 other_buffer_safely (Lisp_Object buffer)
 {
+  USE_LOCAL_ALLOCA;
   Lisp_Object tail, buf;
 
   FOR_EACH_LIVE_BUFFER (tail, buf)
@@ -5238,6 +5240,7 @@
 void
 init_buffer (int initialized)
 {
+  USE_LOCAL_ALLOCA;
   char *pwd;
   Lisp_Object temp;
   ptrdiff_t len;

=== modified file 'src/charset.c'
--- a/src/charset.c     2014-09-16 08:20:08 +0000
+++ b/src/charset.c     2014-09-25 02:01:14 +0000
@@ -481,6 +481,7 @@
 load_charset_map_from_file (struct charset *charset, Lisp_Object mapfile,
                            int control_flag)
 {
+  USE_LOCAL_ALLOCA;
   unsigned min_code = CHARSET_MIN_CODE (charset);
   unsigned max_code = CHARSET_MAX_CODE (charset);
   int fd;
@@ -1550,6 +1551,7 @@
 only `ascii', `eight-bit-control', and `eight-bit-graphic'.  */)
   (Lisp_Object beg, Lisp_Object end, Lisp_Object table)
 {
+  USE_LOCAL_ALLOCA;
   Lisp_Object charsets;
   ptrdiff_t from, from_byte, to, stop, stop_byte;
   int i;
@@ -1601,6 +1603,7 @@
 only `ascii', `eight-bit-control', and `eight-bit-graphic'. */)
   (Lisp_Object str, Lisp_Object table)
 {
+  USE_LOCAL_ALLOCA;
   Lisp_Object charsets;
   int i;
   Lisp_Object val;

=== modified file 'src/chartab.c'
--- a/src/chartab.c     2014-09-24 11:11:14 +0000
+++ b/src/chartab.c     2014-09-25 02:01:14 +0000
@@ -1249,6 +1249,7 @@
 static Lisp_Object
 uniprop_encode_value_numeric (Lisp_Object table, Lisp_Object value)
 {
+  USE_LOCAL_ALLOCA;
   Lisp_Object *value_table = XVECTOR (XCHAR_TABLE 
(table)->extras[4])->contents;
   int i, size = ASIZE (XCHAR_TABLE (table)->extras[4]);
 
@@ -1292,6 +1293,7 @@
 Lisp_Object
 uniprop_table (Lisp_Object prop)
 {
+  USE_LOCAL_ALLOCA;
   Lisp_Object val, table, result;
 
   val = Fassq (prop, Vchar_code_property_alist);

=== modified file 'src/data.c'
--- a/src/data.c        2014-09-22 19:20:45 +0000
+++ b/src/data.c        2014-09-25 02:01:14 +0000
@@ -1004,6 +1004,7 @@
 static void
 wrong_range (Lisp_Object min, Lisp_Object max, Lisp_Object wrong)
 {
+  USE_LOCAL_ALLOCA;
   xsignal2 (Qerror, Fconcat (4, ((Lisp_Object [])
     { build_local_string ("Value should be from "),
       Fnumber_to_string (min),

=== modified file 'src/editfns.c'
--- a/src/editfns.c     2014-09-18 11:34:24 +0000
+++ b/src/editfns.c     2014-09-25 02:01:14 +0000
@@ -3531,6 +3531,7 @@
 usage: (propertize STRING &rest PROPERTIES)  */)
   (ptrdiff_t nargs, Lisp_Object *args)
 {
+  USE_LOCAL_ALLOCA;
   Lisp_Object properties, string;
   struct gcpro gcpro1, gcpro2;
   ptrdiff_t i;
@@ -4362,6 +4363,7 @@
 Lisp_Object
 format2 (const char *string1, Lisp_Object arg0, Lisp_Object arg1)
 {
+  USE_LOCAL_ALLOCA;
   return Fformat (3, ((Lisp_Object [])
     { build_local_string (string1), arg0, arg1 }));
 }

=== modified file 'src/emacs.c'
--- a/src/emacs.c       2014-09-16 08:20:08 +0000
+++ b/src/emacs.c       2014-09-25 02:01:14 +0000
@@ -396,7 +396,8 @@
 static void
 init_cmdargs (int argc, char **argv, int skip_args, char *original_pwd)
 {
-  register int i;
+  USE_LOCAL_ALLOCA;
+  int i;
   Lisp_Object name, dir, handler;
   ptrdiff_t count = SPECPDL_INDEX ();
   Lisp_Object raw_name;
@@ -2208,6 +2209,7 @@
 Lisp_Object
 decode_env_path (const char *evarname, const char *defalt, bool empty)
 {
+  USE_LOCAL_ALLOCA;
   const char *path, *p;
   Lisp_Object lpath, element, tem;
   /* Default is to use "." for empty path elements.

=== modified file 'src/fileio.c'
--- a/src/fileio.c      2014-09-22 19:20:45 +0000
+++ b/src/fileio.c      2014-09-25 02:01:14 +0000
@@ -5411,6 +5411,7 @@
 static Lisp_Object
 auto_save_error (Lisp_Object error_val)
 {
+  USE_LOCAL_ALLOCA;
   Lisp_Object msg;
   int i;
   struct gcpro gcpro1;

=== modified file 'src/fns.c'
--- a/src/fns.c 2014-09-17 18:27:36 +0000
+++ b/src/fns.c 2014-09-25 02:01:14 +0000
@@ -2706,7 +2706,8 @@
 if `last-nonmenu-event' is nil, and `use-dialog-box' is non-nil.  */)
   (Lisp_Object prompt)
 {
-  register Lisp_Object ans;
+  USE_LOCAL_ALLOCA;
+  Lisp_Object ans;
   struct gcpro gcpro1;
 
   CHECK_STRING (prompt);
@@ -3996,7 +3997,7 @@
       if (HASH_TABLE_P (Vpurify_flag)
          && XHASH_TABLE (Vpurify_flag) == h)
        Fmessage (2, ((Lisp_Object [])
-         { build_local_string ("Growing hash table to: %d"),
+         { build_string ("Growing hash table to: %d"),
            make_number (new_size) }));
 #endif
 

=== modified file 'src/font.c'
--- a/src/font.c        2014-09-24 11:11:14 +0000
+++ b/src/font.c        2014-09-25 02:01:14 +0000
@@ -357,6 +357,7 @@
 font_style_to_value (enum font_property_index prop, Lisp_Object val,
                      bool noerror)
 {
+  USE_LOCAL_ALLOCA;
   Lisp_Object table = AREF (font_style_table, prop - FONT_WEIGHT_INDEX);
   int len;
 
@@ -1049,6 +1050,7 @@
 int
 font_parse_xlfd (char *name, ptrdiff_t len, Lisp_Object font)
 {
+  USE_LOCAL_ALLOCA;
   int i, j, n;
   char *f[XLFD_LAST_INDEX + 1];
   Lisp_Object val;
@@ -1758,6 +1760,7 @@
 void
 font_parse_family_registry (Lisp_Object family, Lisp_Object registry, 
Lisp_Object font_spec)
 {
+  USE_LOCAL_ALLOCA;
   ptrdiff_t len;
   char *p0, *p1;
 
@@ -2683,11 +2686,10 @@
 static Lisp_Object
 font_delete_unmatched (Lisp_Object vec, Lisp_Object spec, int size)
 {
+  USE_LOCAL_ALLOCA;
   Lisp_Object entity, val;
   enum font_property_index prop;
-  /* If USE_STACK_LISP_OBJECTS, MAX is used to avoid unbounded alloca.  */
-  ptrdiff_t i, max
-    = (USE_STACK_LISP_OBJECTS ? MAX_ALLOCA / sizeof (struct Lisp_Cons) : 0);
+  ptrdiff_t i;
 
   for (val = Qnil, i = ASIZE (vec) - 1; i >= 0; i--)
     {
@@ -2715,7 +2717,7 @@
        }
       if (NILP (spec))
        {
-         val = --max > 0 ? local_cons (entity, val) : Fcons (entity, val);
+         val = local_cons (entity, val);
          continue;
        }
       for (prop = FONT_WEIGHT_INDEX; prop < FONT_SIZE_INDEX; prop++)
@@ -2746,7 +2748,7 @@
                   AREF (entity, FONT_AVGWIDTH_INDEX)))
        prop = FONT_SPEC_MAX;
       if (prop < FONT_SPEC_MAX)
-       val = --max > 0 ? local_cons (entity, val) : Fcons (entity, val);
+       val = local_cons (entity, val);
     }
   return (Fvconcat (1, &val));
 }
@@ -5004,6 +5006,7 @@
 void
 font_add_log (const char *action, Lisp_Object arg, Lisp_Object result)
 {
+  USE_LOCAL_ALLOCA;
   Lisp_Object val;
   int i;
 

=== modified file 'src/fontset.c'
--- a/src/fontset.c     2014-09-18 11:34:24 +0000
+++ b/src/fontset.c     2014-09-25 02:01:14 +0000
@@ -1420,6 +1420,7 @@
 appended.  By default, FONT-SPEC overrides the previous settings.  */)
   (Lisp_Object name, Lisp_Object target, Lisp_Object font_spec, Lisp_Object 
frame, Lisp_Object add)
 {
+  USE_LOCAL_ALLOCA;
   Lisp_Object fontset;
   Lisp_Object font_def, registry, family;
   Lisp_Object range_list;

=== modified file 'src/frame.c'
--- a/src/frame.c       2014-09-23 17:03:48 +0000
+++ b/src/frame.c       2014-09-25 02:01:14 +0000
@@ -4137,7 +4137,8 @@
 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
           const char *attribute, const char *class, enum resource_types type)
 {
-  register Lisp_Object tem;
+  USE_LOCAL_ALLOCA;
+  Lisp_Object tem;
 
   tem = Fassq (param, alist);
 

=== modified file 'src/keyboard.c'
--- a/src/keyboard.c    2014-09-24 20:30:28 +0000
+++ b/src/keyboard.c    2014-09-25 02:01:14 +0000
@@ -597,6 +597,8 @@
 static void
 echo_dash (void)
 {
+  USE_LOCAL_ALLOCA;
+
   /* Do nothing if not echoing at all.  */
   if (NILP (KVAR (current_kboard, echo_string)))
     return;
@@ -1894,6 +1896,7 @@
 static Lisp_Object
 safe_run_hooks_error (Lisp_Object error, ptrdiff_t nargs, Lisp_Object *args)
 {
+  USE_LOCAL_ALLOCA;
   Lisp_Object hook, fun;
 
   eassert (nargs == 2);
@@ -7700,6 +7703,7 @@
 bool
 parse_menu_item (Lisp_Object item, int inmenubar)
 {
+  USE_LOCAL_ALLOCA;
   Lisp_Object def, tem, item_string, start;
   Lisp_Object filter;
   Lisp_Object keyhint;
@@ -8523,7 +8527,8 @@
 read_char_minibuf_menu_prompt (int commandflag,
                               Lisp_Object map)
 {
-  register Lisp_Object name;
+  USE_LOCAL_ALLOCA;
+  Lisp_Object name;
   ptrdiff_t nlength;
   /* FIXME: Use the minibuffer's frame width.  */
   ptrdiff_t width = FRAME_COLS (SELECTED_FRAME ()) - 4;

=== modified file 'src/keymap.c'
--- a/src/keymap.c      2014-09-24 11:11:14 +0000
+++ b/src/keymap.c      2014-09-25 02:01:14 +0000
@@ -1308,6 +1308,7 @@
 static void
 silly_event_symbol_error (Lisp_Object c)
 {
+  USE_LOCAL_ALLOCA;
   Lisp_Object parsed, base, name, assoc;
   int modifiers;
 
@@ -2235,6 +2236,8 @@
 around function keys and event symbols.  */)
   (Lisp_Object key, Lisp_Object no_angles)
 {
+  USE_SAFE_ALLOCA;
+
   if (CONSP (key) && lucid_event_type_list_p (key))
     key = Fevent_convert_list (key);
 
@@ -2258,7 +2261,6 @@
       if (NILP (no_angles))
        {
          Lisp_Object result;
-         USE_SAFE_ALLOCA;
          char *buffer = SAFE_ALLOCA (sizeof "<>"
                                      + SBYTES (SYMBOL_NAME (key)));
          esprintf (buffer, "<%s>", SDATA (SYMBOL_NAME (key)));
@@ -3416,6 +3418,7 @@
                 bool partial, Lisp_Object shadow, Lisp_Object entire_map,
                 bool keymap_p, bool mention_shadow)
 {
+  USE_LOCAL_ALLOCA;
   Lisp_Object definition;
   Lisp_Object tem2;
   Lisp_Object elt_prefix = Qnil;

=== modified file 'src/lisp.h'
--- a/src/lisp.h        2014-09-24 20:54:25 +0000
+++ b/src/lisp.h        2014-09-25 02:01:14 +0000
@@ -4562,11 +4562,27 @@
   } while (false)
 
 
+/* Return floor (NBYTES / WORD_SIZE).  */
+
+INLINE ptrdiff_t
+lisp_word_count (ptrdiff_t nbytes)
+{
+  if (-1 >> 1 == -1)
+    switch (word_size)
+      {
+      case 2: return nbytes >> 1;
+      case 4: return nbytes >> 2;
+      case 8: return nbytes >> 3;
+      case 16: return nbytes >> 4;
+      }
+  return nbytes / word_size - (nbytes % word_size < 0);
+}
+
 /* SAFE_ALLOCA_LISP allocates an array of Lisp_Objects.  */
 
 #define SAFE_ALLOCA_LISP(buf, nelt)                           \
   do {                                                        \
-    if ((nelt) <= sa_avail / word_size)                               \
+    if ((nelt) <= lisp_word_count (sa_avail))                 \
       (buf) = AVAIL_ALLOCA ((nelt) * word_size);              \
     else if ((nelt) <= min (PTRDIFF_MAX, SIZE_MAX) / word_size) \
       {                                                               \
@@ -4635,17 +4651,27 @@
 # define USE_LOCAL_ALLOCATORS
 #endif
 
+/* Any function that uses a local allocator should start with either
+   'USE_SAFE_ALLOCA; or 'USE_LOCAL_ALLOCA;' (but not both).  */
+#ifdef USE_LOCAL_ALLOCATORS
+# define USE_LOCAL_ALLOCA ptrdiff_t sa_avail = MAX_ALLOCA
+#else
+# define USE_LOCAL_ALLOCA
+#endif
+
 #ifdef USE_LOCAL_ALLOCATORS
 
 /* Return a function-scoped cons whose car is X and cdr is Y.  */
 
 # define local_cons(x, y)                                              \
-    ({                                                                 \
-       struct Lisp_Cons *c_ = alloca (sizeof (struct Lisp_Cons));      \
-       c_->car = (x);                                                  \
-       c_->u.cdr = (y);                                                        
\
-       make_lisp_ptr (c_, Lisp_Cons);                                  \
-    })
+    (sizeof (struct Lisp_Cons) <= sa_avail                             \
+     ? ({                                                              \
+         struct Lisp_Cons *c_ = AVAIL_ALLOCA (sizeof (struct Lisp_Cons)); \
+         c_->car = (x);                                                \
+         c_->u.cdr = (y);                                              \
+         make_lisp_ptr (c_, Lisp_Cons);                                \
+       })                                                              \
+     : Fcons (x, y))
 
 # define local_list1(a) local_cons (a, Qnil)
 # define local_list2(a, b) local_cons (a, local_list1 (b))
@@ -4658,33 +4684,33 @@
 # define make_local_vector(size, init)                                 \
     ({                                                                 \
        ptrdiff_t size_ = size;                                         \
-       Lisp_Object init_ = init;                                       \
        Lisp_Object vec_;                                               \
-       if (size_ <= (MAX_ALLOCA - header_size) / word_size)            \
+       if (size_ <= lisp_word_count (sa_avail - header_size))          \
         {                                                              \
-          void *ptr_ = alloca (size_ * word_size + header_size);       \
-          vec_ = local_vector_init (ptr_, size_, init_);               \
+          void *ptr_ = AVAIL_ALLOCA (size_ * word_size + header_size); \
+          vec_ = local_vector_init (ptr_, size_, init);                \
         }                                                              \
        else                                                            \
-        vec_ = Fmake_vector (make_number (size_), init_);              \
+        vec_ = Fmake_vector (make_number (size_), init);               \
        vec_;                                                           \
     })
 
+enum { LISP_STRING_OVERHEAD = sizeof (struct Lisp_String) + 1 };
+
 /* Return a function-scoped string with contents DATA and length NBYTES.  */
 
 # define make_local_string(data, nbytes)                               \
     ({                                                                 \
-       char const *data_ = data;                                       \
        ptrdiff_t nbytes_ = nbytes;                                     \
        Lisp_Object string_;                                            \
-       if (nbytes_ <= MAX_ALLOCA - sizeof (struct Lisp_String) - 1)    \
+       if (nbytes_ <= sa_avail - LISP_STRING_OVERHEAD)                 \
         {                                                              \
-          struct Lisp_String *ptr_                                     \
-            = alloca (sizeof (struct Lisp_String) + 1 + nbytes_);      \
-          string_ = local_string_init (ptr_, data_, nbytes_);          \
+          struct Lisp_String *ptr_ = AVAIL_ALLOCA (LISP_STRING_OVERHEAD \
+                                                   + nbytes_);         \
+          string_ = local_string_init (ptr_, data, nbytes_);           \
         }                                                              \
        else                                                            \
-        string_ = make_string (data_, nbytes_);                        \
+        string_ = make_string (data, nbytes_);                         \
        string_;                                                                
\
     })
 

=== modified file 'src/lread.c'
--- a/src/lread.c       2014-09-22 06:06:19 +0000
+++ b/src/lread.c       2014-09-25 02:01:14 +0000
@@ -968,6 +968,7 @@
 static void
 load_warn_old_style_backquotes (Lisp_Object file)
 {
+  USE_LOCAL_ALLOCA;
   if (!NILP (Vold_style_backquotes))
     Fmessage (2, ((Lisp_Object [])
       { build_local_string ("Loading `%s': old-style backquotes detected!"),
@@ -3638,6 +3639,7 @@
 static Lisp_Object
 read_list (bool flag, Lisp_Object readcharfun)
 {
+  USE_LOCAL_ALLOCA;
   Lisp_Object val, tail;
   Lisp_Object elt, tem;
   struct gcpro gcpro1, gcpro2;

=== modified file 'src/menu.c'
--- a/src/menu.c        2014-09-15 14:53:23 +0000
+++ b/src/menu.c        2014-09-25 02:01:14 +0000
@@ -324,6 +324,7 @@
 static void
 single_menu_item (Lisp_Object key, Lisp_Object item, Lisp_Object dummy, void 
*skp_v)
 {
+  USE_LOCAL_ALLOCA;
   Lisp_Object map, item_string, enabled;
   struct gcpro gcpro1, gcpro2;
   bool res;

=== modified file 'src/minibuf.c'
--- a/src/minibuf.c     2014-09-15 14:53:23 +0000
+++ b/src/minibuf.c     2014-09-25 02:01:14 +0000
@@ -1123,6 +1123,7 @@
 function, instead of the usual behavior.  */)
   (Lisp_Object prompt, Lisp_Object def, Lisp_Object require_match)
 {
+  USE_LOCAL_ALLOCA;
   Lisp_Object result;
   char *s;
   ptrdiff_t len;

=== modified file 'src/process.c'
--- a/src/process.c     2014-09-23 17:03:48 +0000
+++ b/src/process.c     2014-09-25 02:01:14 +0000
@@ -592,6 +592,7 @@
 static Lisp_Object
 status_message (struct Lisp_Process *p)
 {
+  USE_LOCAL_ALLOCA;
   Lisp_Object status = p->status;
   Lisp_Object symbol;
   int code;
@@ -1290,6 +1291,8 @@
 Returns nil if format of ADDRESS is invalid.  */)
   (Lisp_Object address, Lisp_Object omit_port)
 {
+  USE_LOCAL_ALLOCA;
+
   if (NILP (address))
     return Qnil;
 
@@ -4003,6 +4006,7 @@
 static void
 server_accept_connection (Lisp_Object server, int channel)
 {
+  USE_LOCAL_ALLOCA;
   Lisp_Object proc, caller, name, buffer;
   Lisp_Object contact, host, service;
   struct Lisp_Process *ps= XPROCESS (server);

=== modified file 'src/textprop.c'
--- a/src/textprop.c    2014-09-15 14:53:23 +0000
+++ b/src/textprop.c    2014-09-25 02:01:14 +0000
@@ -1913,6 +1913,7 @@
 copy_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object src,
                      Lisp_Object pos, Lisp_Object dest, Lisp_Object prop)
 {
+  USE_LOCAL_ALLOCA;
   INTERVAL i;
   Lisp_Object res;
   Lisp_Object stuff;

=== modified file 'src/xdisp.c'
--- a/src/xdisp.c       2014-09-23 16:07:23 +0000
+++ b/src/xdisp.c       2014-09-25 02:01:14 +0000
@@ -20892,6 +20892,7 @@
 See also `bidi-paragraph-direction'.  */)
   (Lisp_Object buffer)
 {
+  USE_LOCAL_ALLOCA;
   struct buffer *buf = current_buffer;
   struct buffer *old = buf;
 

=== modified file 'src/xfns.c'
--- a/src/xfns.c        2014-09-24 04:12:37 +0000
+++ b/src/xfns.c        2014-09-25 02:01:14 +0000
@@ -1561,6 +1561,7 @@
                                      const char *xprop, const char *xclass,
                                      int foreground_p)
 {
+  USE_LOCAL_ALLOCA;
   struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
   Lisp_Object tem;
 
@@ -4272,6 +4273,7 @@
 void
 select_visual (struct x_display_info *dpyinfo)
 {
+  USE_LOCAL_ALLOCA;
   Display *dpy = dpyinfo->display;
   Screen *screen = dpyinfo->screen;
 

=== modified file 'src/xfont.c'
--- a/src/xfont.c       2014-09-23 17:03:48 +0000
+++ b/src/xfont.c       2014-09-25 02:01:14 +0000
@@ -677,6 +677,7 @@
 static Lisp_Object
 xfont_open (struct frame *f, Lisp_Object entity, int pixel_size)
 {
+  USE_LOCAL_ALLOCA;
   Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
   Display *display = dpyinfo->display;
   char name[512];

=== modified file 'src/xselect.c'
--- a/src/xselect.c     2014-09-16 08:20:08 +0000
+++ b/src/xselect.c     2014-09-25 02:01:14 +0000
@@ -2159,6 +2159,7 @@
 static Lisp_Object
 x_clipboard_manager_error_1 (Lisp_Object err)
 {
+  USE_LOCAL_ALLOCA;
   Fmessage (2, ((Lisp_Object [])
     { build_local_string ("X clipboard manager error: %s\n\
 If the problem persists, set `x-select-enable-clipboard-manager' to nil."),
@@ -2212,6 +2213,7 @@
 x_clipboard_manager_save_all (void)
 {
   /* Loop through all X displays, saving owned clipboards.  */
+  USE_LOCAL_ALLOCA;
   struct x_display_info *dpyinfo;
   Lisp_Object local_selection, local_frame;
 

=== modified file 'src/xterm.c'
--- a/src/xterm.c       2014-09-24 07:17:51 +0000
+++ b/src/xterm.c       2014-09-25 02:01:14 +0000
@@ -10692,6 +10692,7 @@
 struct x_display_info *
 x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
 {
+  USE_LOCAL_ALLOCA;
   Display *dpy;
   struct terminal *terminal;
   struct x_display_info *dpyinfo;


reply via email to

[Prev in Thread] Current Thread [Next in Thread]