use dynwind_begin and dynwind_end
[bpt/emacs.git] / src / charset.c
index af3a6cd..97d6346 100644 (file)
@@ -1,6 +1,6 @@
 /* Basic character set support.
 
 /* Basic character set support.
 
-Copyright (C) 2001-2013 Free Software Foundation, Inc.
+Copyright (C) 2001-2014 Free Software Foundation, Inc.
 
 Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
   2005, 2006, 2007, 2008, 2009, 2010, 2011
 
 Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
   2005, 2006, 2007, 2008, 2009, 2010, 2011
@@ -389,12 +389,12 @@ load_charset_map (struct charset *charset, struct charset_map_entries *entries,
        {
          if (ascii_compatible_p)
            {
        {
          if (ascii_compatible_p)
            {
-             if (! ASCII_BYTE_P (from_c))
+             if (! ASCII_CHAR_P (from_c))
                {
                  if (from_c < nonascii_min_char)
                    nonascii_min_char = from_c;
                }
                {
                  if (from_c < nonascii_min_char)
                    nonascii_min_char = from_c;
                }
-             else if (! ASCII_BYTE_P (to_c))
+             else if (! ASCII_CHAR_P (to_c))
                {
                  nonascii_min_char = 0x80;
                }
                {
                  nonascii_min_char = 0x80;
                }
@@ -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;
   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;
   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"));
 
 
   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));
 
   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)
        {
 
       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;
          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);
       n_entries++;
     }
   fclose (fp);
-  clear_unwind_protect (count);
+  fp = NULL;
 
   load_charset_map (charset, head, n_entries, control_flag);
 
   load_charset_map (charset, head, n_entries, control_flag);
-  unbind_to (count, Qnil);
+  dynwind_end ();
 }
 
 static void
 }
 
 static void
@@ -914,7 +916,7 @@ usage: (define-charset-internal ...)  */)
 
   if (! charset.code_linear_p)
     {
 
   if (! charset.code_linear_p)
     {
-      charset.code_space_mask = xzalloc (256);
+      charset.code_space_mask = xzalloc_atomic (256);
       for (i = 0; i < 4; i++)
        for (j = charset.code_space[i * 4]; j <= charset.code_space[i * 4 + 1];
             j++)
       for (i = 0; i < 4; i++)
        for (j = charset.code_space[i * 4]; j <= charset.code_space[i * 4 + 1];
             j++)
@@ -1522,7 +1524,7 @@ find_charsets_in_text (const unsigned char *ptr, ptrdiff_t nchars,
 
            if (!NILP (table))
              c = translate_char (table, c);
 
            if (!NILP (table))
              c = translate_char (table, c);
-           if (ASCII_BYTE_P (c))
+           if (ASCII_CHAR_P (c))
              ASET (charsets, charset_ascii, Qt);
            else
              ASET (charsets, charset_eight_bit, Qt);
              ASET (charsets, charset_ascii, Qt);
            else
              ASET (charsets, charset_eight_bit, Qt);
@@ -2305,9 +2307,11 @@ init_charset (void)
          obscure problem (eg bug#6401), so better abort.  */
       fprintf (stderr, "Error: charsets directory not found:\n\
 %s\n\
          obscure problem (eg bug#6401), so better abort.  */
       fprintf (stderr, "Error: charsets directory not found:\n\
 %s\n\
-Emacs will not function correctly without the character map files.\n\
+Emacs will not function correctly without the character map files.\n%s\
 Please check your installation!\n",
 Please check your installation!\n",
-                   SDATA (tempdir));
+               SDATA (tempdir),
+               egetenv("EMACSDATA") ? "The EMACSDATA environment \
+variable is set, maybe it has the wrong value?\n" : "");
       exit (1);
     }
 
       exit (1);
     }
 
@@ -2351,6 +2355,8 @@ static struct charset charset_table_init[180];
 void
 syms_of_charset (void)
 {
 void
 syms_of_charset (void)
 {
+#include "charset.x"
+
   DEFSYM (Qcharsetp, "charsetp");
 
   DEFSYM (Qascii, "ascii");
   DEFSYM (Qcharsetp, "charsetp");
 
   DEFSYM (Qascii, "ascii");
@@ -2384,33 +2390,9 @@ syms_of_charset (void)
   }
 
   charset_table = charset_table_init;
   }
 
   charset_table = charset_table_init;
-  charset_table_size = sizeof charset_table_init / sizeof *charset_table_init;
+  charset_table_size = ARRAYELTS (charset_table_init);
   charset_table_used = 0;
 
   charset_table_used = 0;
 
-  defsubr (&Scharsetp);
-  defsubr (&Smap_charset_chars);
-  defsubr (&Sdefine_charset_internal);
-  defsubr (&Sdefine_charset_alias);
-  defsubr (&Scharset_plist);
-  defsubr (&Sset_charset_plist);
-  defsubr (&Sunify_charset);
-  defsubr (&Sget_unused_iso_final_char);
-  defsubr (&Sdeclare_equiv_charset);
-  defsubr (&Sfind_charset_region);
-  defsubr (&Sfind_charset_string);
-  defsubr (&Sdecode_char);
-  defsubr (&Sencode_char);
-  defsubr (&Ssplit_char);
-  defsubr (&Smake_char);
-  defsubr (&Schar_charset);
-  defsubr (&Scharset_after);
-  defsubr (&Siso_charset);
-  defsubr (&Sclear_charset_maps);
-  defsubr (&Scharset_priority_list);
-  defsubr (&Sset_charset_priority);
-  defsubr (&Scharset_id_internal);
-  defsubr (&Ssort_charsets);
-
   DEFVAR_LISP ("charset-map-path", Vcharset_map_path,
               doc: /* List of directories to search for charset map files.  */);
   Vcharset_map_path = Qnil;
   DEFVAR_LISP ("charset-map-path", Vcharset_map_path,
               doc: /* List of directories to search for charset map files.  */);
   Vcharset_map_path = Qnil;