use dynwind_begin and dynwind_end
authorBT Templeton <bt@hcoop.net>
Sun, 21 Jul 2013 20:48:22 +0000 (16:48 -0400)
committerRobin Templeton <robin@terpri.org>
Sat, 18 Apr 2015 22:49:11 +0000 (18:49 -0400)
This commit only changes uses of `SPECPDL_INDEX' and `unbind_to' that
could not be easily converted using Coccinelle.

15 files changed:
src/bytecode.c
src/callproc.c
src/charset.c
src/doc.c
src/fileio.c
src/keyboard.c
src/lread.c
src/menu.c
src/minibuf.c
src/nsfns.m
src/nsmenu.m
src/nsselect.m
src/print.c
src/process.c
src/sysdep.c

index cf71fd1..d46b453 100644 (file)
@@ -796,6 +796,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
        varbind:
          /* Specbind can signal and thus GC.  */
          BEFORE_POTENTIAL_GC ();
+          dynwind_begin ();
          specbind (vectorp[op], POP);
          AFTER_POTENTIAL_GC ();
          NEXT;
@@ -856,16 +857,13 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
          op -= Bunbind;
        dounbind:
          BEFORE_POTENTIAL_GC ();
-         unbind_to (SPECPDL_INDEX () - op, Qnil);
+          for (int i = 0; i < op; i++)
+            dynwind_end ();
          AFTER_POTENTIAL_GC ();
          NEXT;
 
        CASE (Bunbind_all):     /* Obsolete.  Never used.  */
-         /* To unbind back to the beginning of this frame.  Not used yet,
-            but will be needed for tail-recursion elimination.  */
-         BEFORE_POTENTIAL_GC ();
-         unbind_to (count, Qnil);
-         AFTER_POTENTIAL_GC ();
+          emacs_abort ();
          NEXT;
 
        CASE (Bgoto):
@@ -984,28 +982,31 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
          NEXT;
 
        CASE (Bsave_excursion):
+          dynwind_begin ();
          record_unwind_protect (save_excursion_restore,
                                 save_excursion_save ());
          NEXT;
 
        CASE (Bsave_current_buffer): /* Obsolete since ??.  */
        CASE (Bsave_current_buffer_1):
+          dynwind_begin ();
          record_unwind_current_buffer ();
          NEXT;
 
        CASE (Bsave_window_excursion): /* Obsolete since 24.1.  */
          {
-           ptrdiff_t count1 = SPECPDL_INDEX ();
+            dynwind_begin ();
            record_unwind_protect (restore_window_configuration,
                                   Fcurrent_window_configuration (Qnil));
            BEFORE_POTENTIAL_GC ();
            TOP = Fprogn (TOP);
-           unbind_to (count1, TOP);
+            dynwind_end ();
            AFTER_POTENTIAL_GC ();
            NEXT;
          }
 
        CASE (Bsave_restriction):
+          dynwind_begin ();
          record_unwind_protect (save_restriction_restore,
                                 save_restriction_save ());
          NEXT;
@@ -1067,6 +1068,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
        CASE (Bunwind_protect): /* FIXME: avoid closure for lexbind.  */
          {
            Lisp_Object handler = POP;
+            dynwind_begin ();
            /* Support for a function here is new in 24.4.  */
            record_unwind_protect (NILP (Ffunctionp (handler))
                                   ? unwind_body : bcall0,
@@ -1088,6 +1090,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
        CASE (Btemp_output_buffer_setup): /* Obsolete since 24.1.  */
          BEFORE_POTENTIAL_GC ();
          CHECK_STRING (TOP);
+          dynwind_begin ();
          temp_output_buffer_setup (SSDATA (TOP));
          AFTER_POTENTIAL_GC ();
          TOP = Vstandard_output;
@@ -1101,7 +1104,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
            temp_output_buffer_show (TOP);
            TOP = v1;
            /* pop binding of standard-output */
-           unbind_to (SPECPDL_INDEX () - 1, Qnil);
+            dynwind_end ();
            AFTER_POTENTIAL_GC ();
            NEXT;
          }
index 3647a1a..2f6030f 100644 (file)
@@ -283,7 +283,6 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int *filefd, Lisp_Object *temp
   int callproc_fd[CALLPROC_FDS];
   int status;
   ptrdiff_t i;
-  ptrdiff_t count = SPECPDL_INDEX ();
   USE_SAFE_ALLOCA;
 
   char **new_argv;
@@ -306,6 +305,8 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int *filefd, Lisp_Object *temp
   Lisp_Object coding_systems;
   bool discard_output;
 
+  dynwind_begin ();
+
   if (synch_process_pid)
     error ("call-process invoked recursively");
 
@@ -571,7 +572,7 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int *filefd, Lisp_Object *temp
   if (pid < 0)
     {
       child_errno = errno;
-      unbind_to (count, Qnil);
+      dynwind_end ();
       synchronize_system_messages_locale ();
       return
        code_convert_string_norecord (build_string (strerror (child_errno)),
@@ -626,7 +627,6 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int *filefd, Lisp_Object *temp
     bool volatile display_p_volatile = display_p;
     int volatile fd_error_volatile = fd_error;
     int *volatile filefd_volatile = filefd;
-    ptrdiff_t volatile count_volatile = count;
     char **volatile new_argv_volatile = new_argv;
     int volatile callproc_fd_volatile[CALLPROC_FDS];
     for (i = 0; i < CALLPROC_FDS; i++)
@@ -640,7 +640,6 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int *filefd, Lisp_Object *temp
     display_p = display_p_volatile;
     fd_error = fd_error_volatile;
     filefd = filefd_volatile;
-    count = count_volatile;
     new_argv = new_argv_volatile;
 
     for (i = 0; i < CALLPROC_FDS; i++)
@@ -707,7 +706,10 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int *filefd, Lisp_Object *temp
 #endif /* not MSDOS */
 
   if (INTEGERP (buffer))
-    return unbind_to (count, Qnil);
+    {
+      dynwind_end ();
+      return Qnil;
+    }
 
   if (BUFFERP (buffer))
     Fset_buffer (buffer);
@@ -806,8 +808,8 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int *filefd, Lisp_Object *temp
          else
            {                   /* We have to decode the input.  */
              Lisp_Object curbuf;
-             ptrdiff_t count1 = SPECPDL_INDEX ();
 
+              dynwind_begin ();
              XSETBUFFER (curbuf, current_buffer);
              /* FIXME: Call signal_after_change!  */
              prepare_to_modify_buffer (PT, PT, NULL);
@@ -819,7 +821,7 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int *filefd, Lisp_Object *temp
              specbind (Qinhibit_modification_hooks, Qt);
              decode_coding_c_string (&process_coding,
                                      (unsigned char *) buf, nread, curbuf);
-             unbind_to (count1, Qnil);
+              dynwind_end ();
              if (display_on_the_fly
                  && CODING_REQUIRE_DETECTION (&saved_coding)
                  && ! CODING_REQUIRE_DETECTION (&process_coding))
@@ -894,7 +896,7 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int *filefd, Lisp_Object *temp
   synch_process_pid = 0;
 
   SAFE_FREE ();
-  unbind_to (count, Qnil);
+  dynwind_end ();
 
   if (WIFSIGNALED (status))
     {
index 64d0152..e51ca5a 100644 (file)
@@ -494,16 +494,19 @@ load_charset_map_from_file (struct charset *charset, Lisp_Object mapfile,
 
   count = SPECPDL_INDEX ();
   record_unwind_protect_ptr (fclose_ptr_unwind, &fp);
-  specbind (Qfile_name_handler_alist, Qnil);
-  fd = openp (Vcharset_map_path, mapfile, suffixes, NULL, Qnil, false);
-  fp = fd < 0 ? 0 : fdopen (fd, "r");
-  if (!fp)
-    {
-      int open_errno = errno;
-      emacs_close (fd);
-      report_file_errno ("Loading charset map", mapfile, open_errno);
-    }
-  unbind_to (count + 1, Qnil);
+  {
+    ptrdiff_t count1 = SPECPDL_INDEX ();
+    specbind (Qfile_name_handler_alist, Qnil);
+    fd = openp (Vcharset_map_path, mapfile, suffixes, NULL, Qnil, false);
+    fp = fd < 0 ? 0 : fdopen (fd, "r");
+    if (!fp)
+      {
+        int open_errno = errno;
+        emacs_close (fd);
+        report_file_errno ("Loading charset map", mapfile, open_errno);
+      }
+    unbind_to (count1, Qnil);
+  }
 
   /* Use record, as `charset_map_entries' is large (larger than
      MAX_ALLOCA).  */
index ccf58ca..9f10f57 100644 (file)
--- a/src/doc.c
+++ b/src/doc.c
@@ -84,7 +84,6 @@ get_doc_string (Lisp_Object filepos, bool unibyte, bool definition)
   int offset;
   EMACS_INT position;
   Lisp_Object file, tem, pos;
-  ptrdiff_t count;
   USE_SAFE_ALLOCA;
 
   if (INTEGERP (filepos))
@@ -150,7 +149,7 @@ get_doc_string (Lisp_Object filepos, bool unibyte, bool definition)
                          file, build_string ("\"\n"));
        }
     }
-  count = SPECPDL_INDEX ();
+  dynwind_begin ();
   record_unwind_protect_int (close_file_unwind, fd);
 
   /* Seek only to beginning of disk block.  */
@@ -206,7 +205,7 @@ get_doc_string (Lisp_Object filepos, bool unibyte, bool definition)
        }
       p += nread;
     }
-  unbind_to (count, Qnil);
+  dynwind_end ();
   SAFE_FREE ();
 
   /* Sanity checking.  */
@@ -608,7 +607,7 @@ the same file name is found in the `doc-directory'.  */)
       report_file_errno ("Opening doc string file", build_string (name),
                         open_errno);
     }
-  count = SPECPDL_INDEX ();
+  dynwind_begin ();
   record_unwind_protect_int (close_file_unwind, fd);
   Vdoc_file_name = filename;
   filled = 0;
@@ -688,7 +687,8 @@ the same file name is found in the `doc-directory'.  */)
       filled -= end - buf;
       memmove (buf, end, filled);
     }
-  return unbind_to (count, Qnil);
+  dynwind_end ();
+  return Qnil;
 }
 \f
 DEFUN ("substitute-command-keys", Fsubstitute_command_keys,
index cc3b4eb..34b2497 100644 (file)
@@ -3437,7 +3437,6 @@ by calling `format-decode', which see.  */)
   ptrdiff_t how_much;
   off_t beg_offset, end_offset;
   int unprocessed;
-  ptrdiff_t count = SPECPDL_INDEX ();
   struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
   Lisp_Object handler, val, insval, orig_filename, old_undo;
   Lisp_Object p;
@@ -3457,7 +3456,8 @@ by calling `format-decode', which see.  */)
        && BEG == Z);
   Lisp_Object old_Vdeactivate_mark = Vdeactivate_mark;
   bool we_locked_file = 0;
-  ptrdiff_t fd_index;
+
+  dynwind_begin ();
 
   if (current_buffer->base_buffer && ! NILP (visit))
     error ("Cannot do file visiting in an indirect buffer");
@@ -3508,7 +3508,6 @@ by calling `format-decode', which see.  */)
       goto notfound;
     }
 
-  fd_index = SPECPDL_INDEX ();
   record_unwind_protect_ptr (close_file_ptr_unwind, &fd);
 
   /* Replacement should preserve point as it preserves markers.  */
@@ -3643,7 +3642,7 @@ by calling `format-decode', which see.  */)
                  Lisp_Object workbuf;
                  struct buffer *buf;
 
-                  ptrdiff_t count1 = SPECPDL_INDEX ();
+                  dynwind_begin ();
                  record_unwind_current_buffer ();
 
                  workbuf = Fget_buffer_create (build_string (" *code-converting-work*"));
@@ -3666,7 +3665,7 @@ by calling `format-decode', which see.  */)
                  coding_system = call2 (Vset_auto_coding_function,
                                         filename, make_number (nread));
 
-                  unbind_to (count1, Qnil);
+                  dynwind_end ();
 
                  /* Rewind the file for the actual read done later.  */
                  if (lseek (fd, 0, SEEK_SET) < 0)
@@ -3918,12 +3917,12 @@ by calling `format-decode', which see.  */)
       unsigned char *decoded;
       ptrdiff_t temp;
       ptrdiff_t this = 0;
-      ptrdiff_t this_count = SPECPDL_INDEX ();
       bool multibyte
        = ! NILP (BVAR (current_buffer, enable_multibyte_characters));
       Lisp_Object conversion_buffer;
       struct gcpro gcpro1;
 
+      dynwind_begin ();
       conversion_buffer = code_conversion_save (1, multibyte);
 
       /* First read the whole file, performing code conversion into
@@ -4002,7 +4001,7 @@ by calling `format-decode', which see.  */)
            }
          inserted = 0;
 
-         unbind_to (this_count, Qnil);
+          dynwind_end ();
          goto handled;
        }
 
@@ -4082,7 +4081,7 @@ by calling `format-decode', which see.  */)
       /* Set point before the inserted characters.  */
       SET_PT_BOTH (temp, same_at_start);
 
-      unbind_to (this_count, Qnil);
+      dynwind_end ();
 
       goto handled;
     }
@@ -4245,7 +4244,7 @@ by calling `format-decode', which see.  */)
             care of marker adjustment.  By this way, we can run Lisp
             program safely before decoding the inserted text.  */
          Lisp_Object unwind_data;
-         ptrdiff_t count1 = SPECPDL_INDEX ();
+          dynwind_begin ();
 
          unwind_data = Fcons (BVAR (current_buffer, enable_multibyte_characters),
                               Fcons (BVAR (current_buffer, undo_list),
@@ -4272,7 +4271,7 @@ by calling `format-decode', which see.  */)
              if (CONSP (coding_system))
                coding_system = XCAR (coding_system);
            }
-         unbind_to (count1, Qnil);
+          dynwind_end ();
          inserted = Z_BYTE - BEG_BYTE;
        }
 
@@ -4379,8 +4378,8 @@ by calling `format-decode', which see.  */)
   if (inserted > 0)
     {
       /* Don't run point motion or modification hooks when decoding.  */
-      ptrdiff_t count1 = SPECPDL_INDEX ();
       ptrdiff_t old_inserted = inserted;
+      dynwind_begin ();
       specbind (Qinhibit_point_motion_hooks, Qt);
       specbind (Qinhibit_modification_hooks, Qt);
 
@@ -4495,7 +4494,7 @@ by calling `format-decode', which see.  */)
           Otherwise start with an empty undo_list.  */
        bset_undo_list (current_buffer, EQ (old_undo, Qt) ? Qt : Qnil);
 
-      unbind_to (count1, Qnil);
+      dynwind_end ();
     }
 
   if (!NILP (visit)
@@ -4524,7 +4523,8 @@ by calling `format-decode', which see.  */)
   if (NILP (val))
     val = list2 (orig_filename, make_number (inserted));
 
-  RETURN_UNGCPRO (unbind_to (count, val));
+  dynwind_end ();
+  return val;
 }
 \f
 static Lisp_Object build_annotations (Lisp_Object, Lisp_Object);
@@ -4711,8 +4711,6 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename,
   const char *fn;
   struct stat st;
   struct timespec modtime;
-  ptrdiff_t count = SPECPDL_INDEX ();
-  ptrdiff_t count1 IF_LINT (= 0);
   Lisp_Object handler;
   Lisp_Object visit_file;
   Lisp_Object annotations;
@@ -4771,6 +4769,7 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename,
       return val;
     }
 
+  dynwind_begin ();
   record_unwind_protect (save_restriction_restore, save_restriction_save ());
 
   /* Special kludge to simplify auto-saving.  */
@@ -4856,7 +4855,7 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename,
          report_file_errno ("Opening output file", filename, open_errno);
        }
 
-      count1 = SPECPDL_INDEX ();
+      dynwind_begin ();
       record_unwind_protect_int_1 (close_file_unwind, desc, false);
     }
 
@@ -4933,7 +4932,7 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename,
       if (emacs_close (desc) < 0)
        ok = 0, save_errno = errno;
 
-      unbind_to (count1, Qnil);
+      dynwind_end ();
     }
 
   /* Some file systems have a bug where st_mtime is not updated
@@ -5007,7 +5006,7 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename,
        = XCDR (Vwrite_region_annotation_buffers);
     }
 
-  unbind_to (count, Qnil);
+  dynwind_end ();
 
   if (file_locked)
     unlock_file (lockname);
index 081a78f..d61960a 100644 (file)
@@ -1404,7 +1404,7 @@ command_loop_1 (void)
        {
          /* Bind inhibit-quit to t so that C-g gets read in
             rather than quitting back to the minibuffer.  */
-         ptrdiff_t count = SPECPDL_INDEX ();
+          dynwind_begin ();
          specbind (Qinhibit_quit, Qt);
 
          sit_for (Vminibuffer_message_timeout, 0, 2);
@@ -1413,7 +1413,7 @@ command_loop_1 (void)
          message1 (0);
          safe_run_hooks (Qecho_area_clear_hook);
 
-         unbind_to (count, Qnil);
+         dynwind_end ();
 
          /* If a C-g came in before, treat it as input now.  */
          if (!NILP (Vquit_flag))
@@ -1527,7 +1527,7 @@ command_loop_1 (void)
          /* Here for a command that isn't executed directly.  */
 
 #ifdef HAVE_WINDOW_SYSTEM
-            ptrdiff_t scount = SPECPDL_INDEX ();
+            dynwind_begin ();
 
             if (display_hourglass_p
                 && NILP (Vexecuting_kbd_macro))
@@ -1553,8 +1553,7 @@ command_loop_1 (void)
             hourglass cursor anyway.
             But don't cancel the hourglass within a macro
             just because a command in the macro finishes.  */
-         if (NILP (Vexecuting_kbd_macro))
-            unbind_to (scount, Qnil);
+            dynwind_end ();
 #endif
           }
       kset_last_prefix_arg (current_kboard, Vcurrent_prefix_arg);
@@ -3095,7 +3094,6 @@ read_char_1 (bool jump, volatile struct read_char_state *state)
       ptrdiff_t key_count;
       bool key_count_reset;
       struct gcpro gcpro1;
-      ptrdiff_t count = SPECPDL_INDEX ();
 
       /* Save the echo status.  */
       bool saved_immediate_echo = current_kboard->immediate_echo;
@@ -3103,6 +3101,8 @@ read_char_1 (bool jump, volatile struct read_char_state *state)
       Lisp_Object saved_echo_string = KVAR (current_kboard, echo_string);
       ptrdiff_t saved_echo_after_prompt = current_kboard->echo_after_prompt;
 
+      dynwind_begin ();
+
 #if 0
       if (before_command_restore_flag)
        {
@@ -3144,7 +3144,7 @@ read_char_1 (bool jump, volatile struct read_char_state *state)
       /* Call the input method.  */
       tem = call1 (Vinput_method_function, c);
 
-      unbind_to (count, tem);
+      dynwind_end ();
 
       /* Restore the saved echoing state
         and this_command_keys state.  */
@@ -3231,7 +3231,7 @@ read_char_1 (bool jump, volatile struct read_char_state *state)
   /* Process the help character specially if enabled.  */
   if (!NILP (Vhelp_form) && help_char_p (c))
     {
-      ptrdiff_t count = SPECPDL_INDEX ();
+      dynwind_begin ();
 
       help_form_saved_window_configs
        = Fcons (Fcurrent_window_configuration (Qnil),
@@ -3249,7 +3249,7 @@ read_char_1 (bool jump, volatile struct read_char_state *state)
        }
       while (BUFFERP (c));
       /* Remove the help from the frame.  */
-      unbind_to (count, Qnil);
+      dynwind_end ();
 
       redisplay ();
       if (EQ (c, make_number (040)))
@@ -8901,8 +8901,6 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
                   bool dont_downcase_last, bool can_return_switch_frame,
                   bool fix_current_buffer, bool prevent_redisplay)
 {
-  ptrdiff_t count = SPECPDL_INDEX ();
-
   /* How many keys there are in the current key sequence.  */
   int t;
 
@@ -8969,6 +8967,8 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
 
   struct gcpro gcpro1;
 
+  dynwind_begin ();
+
   GCPRO1 (fake_prefixed_keys);
   raw_keybuf_count = 0;
 
@@ -9200,7 +9200,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
             Just return -1.  */
          if (EQ (key, Qt))
            {
-             unbind_to (count, Qnil);
+              dynwind_end ();
              UNGCPRO;
              return -1;
            }
@@ -9759,7 +9759,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
     : Qnil;
 
   unread_switch_frame = delayed_switch_frame;
-  unbind_to (count, Qnil);
+  dynwind_end ();
 
   /* Don't downcase the last character if the caller says don't.
      Don't downcase it if the result is undefined, either.  */
index 908db29..033fa72 100644 (file)
@@ -1048,7 +1048,6 @@ Return t if the file exists and loads successfully.  */)
 {
   FILE *stream = NULL;
   int fd;
-  int fd_index;
   ptrdiff_t count = SPECPDL_INDEX ();
   struct gcpro gcpro1, gcpro2, gcpro3;
   Lisp_Object found, efound, hist_file_name;
@@ -1179,14 +1178,8 @@ Return t if the file exists and loads successfully.  */)
 #endif
     }
 
-  if (fd < 0)
-    {
-      /* Pacify older GCC with --enable-gcc-warnings.  */
-      IF_LINT (fd_index = 0);
-    }
-  else
+  if (fd >= 0)
     {
-      fd_index = SPECPDL_INDEX ();
       record_unwind_protect_ptr (close_file_ptr_unwind, &fd);
       record_unwind_protect_ptr (fclose_ptr_unwind, &stream);
     }
index 31f02f1..a6a9b55 100644 (file)
@@ -1160,6 +1160,7 @@ no quit occurs and `x-popup-menu' returns nil.  */)
   Lisp_Object x, y, window;
   int menuflags = 0;
   ptrdiff_t specpdl_count = SPECPDL_INDEX ();
+  ptrdiff_t specpdl_count2;
   struct gcpro gcpro1;
 
   if (NILP (position))
@@ -1406,6 +1407,8 @@ no quit occurs and `x-popup-menu' returns nil.  */)
     }
 #endif
 
+  specpdl_count2 = SPECPDL_INDEX ();
+
 #ifdef HAVE_NS                 /* FIXME: ns-specific, why? --Stef  */
   record_unwind_protect_void (discard_menu_items);
 #endif
@@ -1417,12 +1420,12 @@ no quit occurs and `x-popup-menu' returns nil.  */)
     selection = FRAME_TERMINAL (f)->menu_show_hook (f, xpos, ypos, menuflags,
                                                    title, &error_name);
 
-#ifdef HAVE_NS
-  unbind_to (specpdl_count, Qnil);
-#else
+#ifndef HAVE_NS
   discard_menu_items ();
 #endif
 
+  unbind_to (specpdl_count2, Qnil);
+
 #ifdef HAVE_NTGUI     /* FIXME: Is it really w32-specific?  --Stef  */
   if (FRAME_W32_P (f))
     FRAME_DISPLAY_INFO (f)->grabbed = 0;
index 4db3398..c53f91a 100644 (file)
@@ -1203,7 +1203,6 @@ is used to further constrain the set of candidates.  */)
               ? list_table : function_table));
   ptrdiff_t idx = 0, obsize = 0;
   int matchcount = 0;
-  ptrdiff_t bindcount = -1;
   Lisp_Object bucket, zero, end, tem;
   struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
 
@@ -1288,18 +1287,17 @@ is used to further constrain the set of candidates.  */)
 
          /* Ignore this element if it fails to match all the regexps.  */
          {
+            dynwind_begin ();
+            specbind (Qcase_fold_search,
+                      completion_ignore_case ? Qt : Qnil);
            for (regexps = Vcompletion_regexp_list; CONSP (regexps);
                 regexps = XCDR (regexps))
              {
-               if (bindcount < 0) {
-                 bindcount = SPECPDL_INDEX ();
-                 specbind (Qcase_fold_search,
-                           completion_ignore_case ? Qt : Qnil);
-               }
                tem = Fstring_match (XCAR (regexps), eltstring, zero);
                if (NILP (tem))
                  break;
              }
+            dynwind_end ();
            if (CONSP (regexps))
              continue;
          }
@@ -1313,11 +1311,6 @@ is used to further constrain the set of candidates.  */)
                tem = Fcommandp (elt, Qnil);
              else
                {
-                 if (bindcount >= 0)
-                   {
-                     unbind_to (bindcount, Qnil);
-                     bindcount = -1;
-                   }
                  GCPRO4 (tail, string, eltstring, bestmatch);
                  tem = (type == hash_table
                         ? call2 (predicate, elt,
@@ -1396,11 +1389,6 @@ is used to further constrain the set of candidates.  */)
        }
     }
 
-  if (bindcount >= 0) {
-    unbind_to (bindcount, Qnil);
-    bindcount = -1;
-  }
-
   if (NILP (bestmatch))
     return Qnil;               /* No completions found.  */
   /* If we are ignoring case, and there is no exact match,
@@ -1460,7 +1448,6 @@ with a space are ignored unless STRING itself starts with a space.  */)
     : VECTORP (collection) ? 2
     : NILP (collection) || (CONSP (collection) && !FUNCTIONP (collection));
   ptrdiff_t idx = 0, obsize = 0;
-  ptrdiff_t bindcount = -1;
   Lisp_Object bucket, tem, zero;
   struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
 
@@ -1551,18 +1538,17 @@ with a space are ignored unless STRING itself starts with a space.  */)
 
          /* Ignore this element if it fails to match all the regexps.  */
          {
+            dynwind_begin ();
+            specbind (Qcase_fold_search,
+                      completion_ignore_case ? Qt : Qnil);
            for (regexps = Vcompletion_regexp_list; CONSP (regexps);
                 regexps = XCDR (regexps))
              {
-               if (bindcount < 0) {
-                 bindcount = SPECPDL_INDEX ();
-                 specbind (Qcase_fold_search,
-                           completion_ignore_case ? Qt : Qnil);
-               }
                tem = Fstring_match (XCAR (regexps), eltstring, zero);
                if (NILP (tem))
                  break;
              }
+            dynwind_end ();
            if (CONSP (regexps))
              continue;
          }
@@ -1576,10 +1562,6 @@ with a space are ignored unless STRING itself starts with a space.  */)
                tem = Fcommandp (elt, Qnil);
              else
                {
-                 if (bindcount >= 0) {
-                   unbind_to (bindcount, Qnil);
-                   bindcount = -1;
-                 }
                  GCPRO4 (tail, eltstring, allmatches, string);
                  tem = type == 3
                    ? call2 (predicate, elt,
@@ -1594,11 +1576,6 @@ with a space are ignored unless STRING itself starts with a space.  */)
        }
     }
 
-  if (bindcount >= 0) {
-    unbind_to (bindcount, Qnil);
-    bindcount = -1;
-  }
-
   return Fnreverse (allmatches);
 }
 \f
index 5062903..a0fbcfd 100644 (file)
@@ -1068,7 +1068,6 @@ This function is an internal primitive--use `make-frame' instead.  */)
   int minibuffer_only = 0;
   long window_prompting = 0;
   int width, height;
-  ptrdiff_t count = specpdl_ptr - specpdl;
   struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
   Lisp_Object display;
   struct ns_display_info *dpyinfo = NULL;
@@ -1143,6 +1142,8 @@ This function is an internal primitive--use `make-frame' instead.  */)
 
   FRAME_DISPLAY_INFO (f) = dpyinfo;
 
+  dynwind_begin ();
+
   /* With FRAME_DISPLAY_INFO set up, this unwind-protect is safe.  */
   record_unwind_protect (unwind_create_frame, frame);
 
@@ -1360,7 +1361,8 @@ This function is an internal primitive--use `make-frame' instead.  */)
      and similar functions.  */
   Vwindow_list = Qnil;
 
-  return unbind_to (count, frame);
+  dynwind_end ();
+  return frame;
 }
 
 void
@@ -2724,11 +2726,11 @@ Text larger than the specified size is clipped.  */)
 {
   int root_x, root_y;
   struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
-  ptrdiff_t count = SPECPDL_INDEX ();
   struct frame *f;
   char *str;
   NSSize size;
 
+  dynwind_begin ();
   specbind (Qinhibit_redisplay, Qt);
 
   GCPRO4 (string, parms, frame, timeout);
@@ -2769,7 +2771,8 @@ Text larger than the specified size is clipped.  */)
   unblock_input ();
 
   UNGCPRO;
-  return unbind_to (count, Qnil);
+  dynwind_end ();
+  return Qnil;
 }
 
 
index 8b8362b..7600b60 100644 (file)
@@ -174,11 +174,12 @@ ns_update_menubar (struct frame *f, bool deep_p, EmacsMenu *submenu)
       int *submenu_n_panes;
       struct buffer *prev = current_buffer;
       Lisp_Object buffer;
-      ptrdiff_t specpdl_count = SPECPDL_INDEX ();
       int previous_menu_items_used = f->menu_bar_items_used;
       Lisp_Object *previous_items
        = alloca (previous_menu_items_used * sizeof *previous_items);
 
+      dynwind_begin ();
+
       /* lisp preliminaries */
       buffer = XWINDOW (FRAME_SELECTED_WINDOW (f))->contents;
       specbind (Qinhibit_quit, Qt);
@@ -258,7 +259,7 @@ ns_update_menubar (struct frame *f, bool deep_p, EmacsMenu *submenu)
           fprintf (stderr, "ERROR: did not find lisp menu for submenu '%s'.\n",
                   [[submenu title] UTF8String]);
          discard_menu_items ();
-         unbind_to (specpdl_count, Qnil);
+          dynwind_end ();
           [pool release];
           unblock_input ();
          return;
@@ -316,7 +317,7 @@ ns_update_menubar (struct frame *f, bool deep_p, EmacsMenu *submenu)
 
               free_menubar_widget_value_tree (first_wv);
               discard_menu_items ();
-              unbind_to (specpdl_count, Qnil);
+              dynwind_end ();
               [pool release];
               unblock_input ();
               return;
@@ -328,7 +329,7 @@ ns_update_menubar (struct frame *f, bool deep_p, EmacsMenu *submenu)
       f->menu_bar_items_used = menu_items_used;
 
       /* Calls restore_menu_items, etc., as they were outside */
-      unbind_to (specpdl_count, Qnil);
+      dynwind_end ();
 
       /* Parse stage 2a: now GC cannot happen during the lifetime of the
          widget_value, so it's safe to store data from a Lisp_String */
@@ -818,12 +819,13 @@ ns_menu_show (struct frame *f, int x, int y, int menuflags,
   EmacsMenu *pmenu;
   NSPoint p;
   Lisp_Object tem;
-  ptrdiff_t specpdl_count = SPECPDL_INDEX ();
   widget_value *wv, *first_wv = 0;
   bool keymaps = (menuflags & MENU_KEYMAPS);
 
   block_input ();
 
+  dynwind_begin ();
+
   p.x = x; p.y = y;
 
   /* now parse stage 2 as in ns_update_menubar */
@@ -999,7 +1001,7 @@ ns_menu_show (struct frame *f, int x, int y, int menuflags,
                                [NSString stringWithUTF8String: SSDATA (title)]];
   [pmenu fillWithWidgetValue: first_wv->contents];
   free_menubar_widget_value_tree (first_wv);
-  unbind_to (specpdl_count, Qnil);
+  dynwind_end ();
 
   popup_activated_flag = 1;
   tem = [pmenu runMenuAt: p forFrame: f keymaps: keymaps];
@@ -1459,16 +1461,16 @@ ns_popup_dialog (struct frame *f, Lisp_Object header, Lisp_Object contents)
                                            isQuestion: isQ];
 
   {
-    ptrdiff_t specpdl_count = SPECPDL_INDEX ();
     struct Popdown_data *unwind_data = xmalloc (sizeof (*unwind_data));
 
     unwind_data->pool = pool;
     unwind_data->dialog = dialog;
 
+    dynwind_begin ();
     record_unwind_protect_ptr (pop_down_menu, unwind_data);
     popup_activated_flag = 1;
     tem = [dialog runDialogAt: p];
-    unbind_to (specpdl_count, Qnil);  /* calls pop_down_menu */
+    dynwind_end ();
   }
 
   unblock_input ();
index 342199d..da1b955 100644 (file)
@@ -183,13 +183,12 @@ ns_get_local_selection (Lisp_Object selection_name,
 {
   Lisp_Object local_value;
   Lisp_Object handler_fn, value, check;
-  ptrdiff_t count;
 
   local_value = assq_no_quit (selection_name, Vselection_alist);
 
   if (NILP (local_value)) return Qnil;
 
-  count = specpdl_ptr - specpdl;
+  dynwind_begin ();
   specbind (Qinhibit_quit, Qt);
   CHECK_SYMBOL (target_type);
   handler_fn = Fcdr (Fassq (target_type, Vselection_converter_alist));
@@ -198,7 +197,7 @@ ns_get_local_selection (Lisp_Object selection_name,
                 XCAR (XCDR (local_value)));
   else
     value = Qnil;
-  unbind_to (count, Qnil);
+  dynwind_end ();
 
   check = value;
   if (CONSP (value) && SYMBOLP (XCAR (value)))
index 5ff3b5b..6ed0f51 100644 (file)
@@ -100,7 +100,7 @@ bool print_output_debug_flag EXTERNALLY_VISIBLE = 1;
    struct buffer *old = current_buffer;                                        \
    ptrdiff_t old_point = -1, start_point = -1;                         \
    ptrdiff_t old_point_byte = -1, start_point_byte = -1;               \
-   ptrdiff_t specpdl_count = SPECPDL_INDEX ();                         \
+   dynwind_begin ();                                                    \
    bool free_print_buffer = 0;                                         \
    bool multibyte                                                      \
      = !NILP (BVAR (current_buffer, enable_multibyte_characters));     \
@@ -185,7 +185,7 @@ bool print_output_debug_flag EXTERNALLY_VISIBLE = 1;
        xfree (print_buffer);                                           \
        print_buffer = 0;                                               \
      }                                                                 \
-   unbind_to (specpdl_count, Qnil);                                    \
+   dynwind_end ();                                                      \
    if (MARKERP (original))                                             \
      set_marker_both (original, Qnil, PT, PT_BYTE);                    \
    if (old_point >= 0)                                                 \
@@ -478,10 +478,10 @@ write_string_1 (const char *data, int size, Lisp_Object printcharfun)
 void
 temp_output_buffer_setup (const char *bufname)
 {
-  ptrdiff_t count = SPECPDL_INDEX ();
   register struct buffer *old = current_buffer;
   register Lisp_Object buf;
 
+  dynwind_begin ();
   record_unwind_current_buffer ();
 
   Fset_buffer (Fget_buffer_create (build_string (bufname)));
@@ -503,7 +503,7 @@ temp_output_buffer_setup (const char *bufname)
 
   Frun_hooks (1, &Qtemp_buffer_setup_hook);
 
-  unbind_to (count, Qnil);
+  dynwind_end ();
 
   specbind (Qstandard_output, buf);
 }
@@ -583,9 +583,9 @@ A printed representation of an object is text which describes that object.  */)
   bool prev_abort_on_gc;
   /* struct gcpro gcpro1, gcpro2; */
   Lisp_Object save_deactivate_mark;
-  ptrdiff_t count = SPECPDL_INDEX ();
   struct buffer *previous;
 
+  dynwind_begin ();
   specbind (Qinhibit_modification_hooks, Qt);
 
   {
@@ -619,7 +619,8 @@ A printed representation of an object is text which describes that object.  */)
   Vdeactivate_mark = save_deactivate_mark;
   /* UNGCPRO; */
 
-  return unbind_to (count, object);
+  dynwind_end ();
+  return object;
 }
 
 DEFUN ("princ", Fprinc, Sprinc, 1, 2, 0,
index 0b6321a..8182b28 100644 (file)
@@ -2842,8 +2842,6 @@ usage: (make-network-process &rest ARGS)  */)
   int xerrno = 0;
   int s = -1, outch, inch;
   struct gcpro gcpro1;
-  ptrdiff_t count = SPECPDL_INDEX ();
-  ptrdiff_t count1;
   Lisp_Object colon_address;  /* Either QClocal or QCremote.  */
   Lisp_Object tem;
   Lisp_Object name, buffer, host, service, address;
@@ -2857,6 +2855,8 @@ usage: (make-network-process &rest ARGS)  */)
   if (nargs == 0)
     return Qnil;
 
+  dynwind_begin ();
+
   /* Save arguments for process-contact and clone-process.  */
   contact = Flist (nargs, args);
   GCPRO1 (contact);
@@ -3122,7 +3122,7 @@ usage: (make-network-process &rest ARGS)  */)
  open_socket:
 
   /* Do this in case we never enter the for-loop below.  */
-  count1 = SPECPDL_INDEX ();
+  dynwind_begin ();
   s = -1;
 
   for (lres = res; lres; lres = lres->ai_next)
@@ -3269,7 +3269,8 @@ usage: (make-network-process &rest ARGS)  */)
 
       immediate_quit = 0;
 
-      unbind_to (count1, Qnil);
+      dynwind_end ();
+      dynwind_begin ();
       emacs_close (s);
       s = -1;
 
@@ -3338,7 +3339,11 @@ usage: (make-network-process &rest ARGS)  */)
         the normal blocking calls to open-network-stream handles this error
         better.  */
       if (is_non_blocking_client)
+        {
+          dynwind_end ();
+          dynwind_end ();
          return Qnil;
+        }
 
       report_file_errno ((is_server
                          ? "make server process failed"
@@ -3377,10 +3382,10 @@ usage: (make-network-process &rest ARGS)  */)
   p->infd  = inch;
   p->outfd = outch;
 
-  unbind_to (count1, Qnil);
+  dynwind_end ();
 
   /* Unwind bind_polling_period and request_sigio.  */
-  unbind_to (count, Qnil);
+  dynwind_end ();
 
   if (is_server && socktype != SOCK_DGRAM)
     pset_status (p, Qlisten);
index e440d14..acbd904 100644 (file)
@@ -3069,6 +3069,7 @@ system_process_attributes (Lisp_Object pid)
   if (fd >= 0)
     {
       ptrdiff_t readsize, nread_incr;
+      dynwind_begin ();
       record_unwind_protect_int (close_file_unwind, fd);
       nread = cmdline_size = 0;
 
@@ -3114,7 +3115,7 @@ system_process_attributes (Lisp_Object pid)
       cmd_str = make_unibyte_string (q, nread);
       decoded_cmd = code_convert_string_norecord (cmd_str,
                                                  Vlocale_coding_system, 0);
-      unbind_to (count, Qnil);
+      dynwind_end ();
       attrs = Fcons (Fcons (Qargs, decoded_cmd), attrs);
     }