use dynwind_begin and dynwind_end
[bpt/emacs.git] / src / minibuf.c
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