use dynwind_begin and dynwind_end
[bpt/emacs.git] / src / charset.c
index ad37778..97d6346 100644 (file)
@@ -484,7 +484,7 @@ load_charset_map_from_file (struct charset *charset, Lisp_Object mapfile,
   unsigned min_code = CHARSET_MIN_CODE (charset);
   unsigned max_code = CHARSET_MAX_CODE (charset);
   int fd;
-  FILE *fp;
+  FILE *fp = NULL;
   Lisp_Object suffixes;
   struct charset_map_entries *head, *entries;
   int n_entries;
@@ -492,23 +492,25 @@ load_charset_map_from_file (struct charset *charset, Lisp_Object mapfile,
 
   suffixes = list2 (build_string (".map"), build_string (".TXT"));
 
-  count = SPECPDL_INDEX ();
-  record_unwind_protect_nothing ();
-  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);
-    }
-  set_unwind_protect_ptr (count, fclose_unwind, fp);
-  unbind_to (count + 1, Qnil);
+  dynwind_begin ();
+  record_unwind_protect_ptr (fclose_ptr_unwind, &fp);
+  {
+    dynwind_begin ();
+    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);
+      }
+    dynwind_end ();
+  }
 
-  /* Use record_xmalloc, as `charset_map_entries' is
-     large (larger than MAX_ALLOCA).  */
-  head = record_xmalloc (sizeof *head);
+  /* Use record, as `charset_map_entries' is large (larger than
+     MAX_ALLOCA).  */
+  head = xmalloc (sizeof *head);
   entries = head;
   memset (entries, 0, sizeof (struct charset_map_entries));
 
@@ -539,7 +541,7 @@ load_charset_map_from_file (struct charset *charset, Lisp_Object mapfile,
 
       if (n_entries == 0x10000)
        {
-         entries->next = record_xmalloc (sizeof *entries->next);
+         entries->next = xmalloc (sizeof *entries->next);
          entries = entries->next;
          memset (entries, 0, sizeof (struct charset_map_entries));
          n_entries = 0;
@@ -551,10 +553,10 @@ load_charset_map_from_file (struct charset *charset, Lisp_Object mapfile,
       n_entries++;
     }
   fclose (fp);
-  clear_unwind_protect (count);
+  fp = NULL;
 
   load_charset_map (charset, head, n_entries, control_flag);
-  unbind_to (count, Qnil);
+  dynwind_end ();
 }
 
 static void