]> git.eshelyaron.com Git - emacs.git/commitdiff
Simple wrapper for make_unibyte_string, adjust font_open_by_name.
authorDmitry Antipov <dmantipov@yandex.ru>
Fri, 20 Jul 2012 07:29:04 +0000 (11:29 +0400)
committerDmitry Antipov <dmantipov@yandex.ru>
Fri, 20 Jul 2012 07:29:04 +0000 (11:29 +0400)
* src/lisp.h (build_unibyte_string): New function.
* src/dosfns.c, src/fileio.c, src/fns.c, src/ftfont.c, src/process.c:
* src/sysdep.c, src/w32fns.c, src/xfns.c: Use it.
* src/font.c (font_open_by_name): Change 2nd and 3rd args to the only arg
of type Lisp_Object to avoid redundant calls to make_unibyte_string.
Adjust users accordingly.
* src/font.h (font_open_by_name): Adjust prototype.
* admin/coccinelle/unibyte_string.cocci: Semantic patch to convert from
make_unibyte_string to build_unibyte_string where appropriate.

15 files changed:
admin/ChangeLog
admin/coccinelle/unibyte_string.cocci [new file with mode: 0644]
src/ChangeLog
src/dosfns.c
src/fileio.c
src/fns.c
src/font.c
src/font.h
src/frame.c
src/ftfont.c
src/lisp.h
src/process.c
src/sysdep.c
src/w32fns.c
src/xfns.c

index 0d059714788a24732c6ea8381392ac1d7e22af25..b4c88c20ed125f91f5504074d9188b2bcd4d33b2 100644 (file)
@@ -1,3 +1,8 @@
+2012-07-20  Dmitry Antipov  <dmantipov@yandex.ru>
+
+       * coccinelle/unibyte_string.cocci: Semantic patch to convert from
+       make_unibyte_string to build_unibyte_string where appropriate.
+
 2012-07-17  Eli Zaretskii  <eliz@gnu.org>
 
        * CPP-DEFINES: Remove FILE_SYSTEM_CASE.
@@ -5,6 +10,7 @@
 2012-07-17  Chong Yidong  <cyd@gnu.org>
 
        * Version 24.1 released.
+
 2012-07-11  Paul Eggert  <eggert@cs.ucla.edu>
 
        Assume mkdir, perror, rename, rmdir, strerror.
diff --git a/admin/coccinelle/unibyte_string.cocci b/admin/coccinelle/unibyte_string.cocci
new file mode 100644 (file)
index 0000000..0ff8caf
--- /dev/null
@@ -0,0 +1,6 @@
+// make_unibyte_string (str, strlen (str)) -> build_unibyte_string (str)
+@@
+identifier I;
+@@
+- make_unibyte_string (I, strlen (I))
++ build_unibyte_string (I)
index 909fb03c4889b7261588f370bce5ec75db647de2..8242a35e9ec0584841267ed48fe697b0192cc76a 100644 (file)
@@ -1,3 +1,14 @@
+2012-07-20  Dmitry Antipov  <dmantipov@yandex.ru>
+
+       Simple wrapper for make_unibyte_string, adjust font_open_by_name.
+       * lisp.h (build_unibyte_string): New function.
+       * dosfns.c, fileio.c, fns.c, ftfont.c, process.c:
+       * sysdep.c, w32fns.c, xfns.c: Use it.
+       * font.c (font_open_by_name): Change 2nd and 3rd args to the only arg
+       of type Lisp_Object to avoid redundant calls to make_unibyte_string.
+       Adjust users accordingly.
+       * font.h (font_open_by_name): Adjust prototype.
+
 2012-07-20  Dmitry Antipov  <dmantipov@yandex.ru>
 
        Cleanup calls to Fgarbage_collect.
index ee28801e841c4595d5c9a51d4cf57ee5a6cbfcc1..6fd1b52e2523e00de5b3271dc97181bf5ce4c64e 100644 (file)
@@ -562,7 +562,7 @@ system_process_attributes (Lisp_Object pid)
        attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs);
       strcpy (cmd, basename (__crt0_argv[0]));
       /* Command name is encoded in locale-coding-system; decode it.  */
-      cmd_str = make_unibyte_string (cmd, strlen (cmd));
+      cmd_str = build_unibyte_string (cmd);
       decoded_cmd = code_convert_string_norecord (cmd_str,
                                                  Vlocale_coding_system, 0);
       attrs = Fcons (Fcons (Qcomm, decoded_cmd), attrs);
@@ -630,7 +630,7 @@ system_process_attributes (Lisp_Object pid)
        q[-1] = '\0';
 
       /* Command line is encoded in locale-coding-system; decode it.  */
-      cmd_str = make_unibyte_string (cmdline, strlen (cmdline));
+      cmd_str = build_unibyte_string (cmdline);
       decoded_cmd = code_convert_string_norecord (cmd_str,
                                                  Vlocale_coding_system, 0);
       xfree (cmdline);
index 185dd650438d9ac2454af1fc32ab30ff49c2059e..a13fe94e4168ffb8e611b82084e62ce7d1576599 100644 (file)
@@ -159,8 +159,7 @@ report_file_error (const char *string, Lisp_Object data)
 
   synchronize_system_messages_locale ();
   str = strerror (errorno);
-  errstring = code_convert_string_norecord (make_unibyte_string (str,
-                                                                strlen (str)),
+  errstring = code_convert_string_norecord (build_unibyte_string (str),
                                            Vlocale_coding_system, 0);
 
   while (1)
@@ -1658,7 +1657,7 @@ those `/' is discarded.  */)
               env variables twice should be acceptable. Note that
               decoding may cause a garbage collect.  */
            Lisp_Object orig, decoded;
-           orig = make_unibyte_string (o, strlen (o));
+           orig = build_unibyte_string (o);
            decoded = DECODE_FILE (orig);
            total += SBYTES (decoded);
            substituted = 1;
index da8889e70a7bddd8040dfe3f6d4b636993da6245..6e6b9332942fe004ddfd10a673b5564b5a63d2c1 100644 (file)
--- a/src/fns.c
+++ b/src/fns.c
@@ -2818,7 +2818,7 @@ The data read from the system are decoded using `locale-coding-system'.  */)
       for (i = 0; i < 7; i++)
        {
          str = nl_langinfo (days[i]);
-         val = make_unibyte_string (str, strlen (str));
+         val = build_unibyte_string (str);
          /* Fixme: Is this coding system necessarily right, even if
             it is consistent with CODESET?  If not, what to do?  */
          Faset (v, make_number (i),
@@ -2842,7 +2842,7 @@ The data read from the system are decoded using `locale-coding-system'.  */)
       for (i = 0; i < 12; i++)
        {
          str = nl_langinfo (months[i]);
-         val = make_unibyte_string (str, strlen (str));
+         val = build_unibyte_string (str);
          Faset (v, make_number (i),
                 code_convert_string_norecord (val, Vlocale_coding_system, 0));
        }
index 5b01a1f44d629e563d492e6dae1788e1875da8bc..2c0296aa8c5aa0f647f3d2892a3eb22c890f567b 100644 (file)
@@ -3350,13 +3350,13 @@ font_open_by_spec (FRAME_PTR f, Lisp_Object spec)
    found, return Qnil.  */
 
 Lisp_Object
-font_open_by_name (FRAME_PTR f, const char *name, ptrdiff_t len)
+font_open_by_name (FRAME_PTR f, Lisp_Object name)
 {
   Lisp_Object args[2];
   Lisp_Object spec, ret;
 
   args[0] = QCname;
-  args[1] = make_unibyte_string (name, len);
+  args[1] = name;
   spec = Ffont_spec (2, args);
   ret = font_open_by_spec (f, spec);
   /* Do not lose name originally put in.  */
@@ -4878,7 +4878,7 @@ If the named font is not yet loaded, return nil.  */)
 
       if (fontset >= 0)
        name = fontset_ascii (fontset);
-      font_object = font_open_by_name (f, SSDATA (name), SBYTES (name));
+      font_object = font_open_by_name (f, name);
     }
   else if (FONT_OBJECT_P (name))
     font_object = name;
index b4e994397dea9006754703f5c7f38920eb437c23..2e374571c6737c8e8f29fefed41fc3762d85a183 100644 (file)
@@ -771,7 +771,7 @@ extern void font_prepare_for_face (FRAME_PTR f, struct face *face);
 extern void font_done_for_face (FRAME_PTR f, struct face *face);
 
 extern Lisp_Object font_open_by_spec (FRAME_PTR f, Lisp_Object spec);
-extern Lisp_Object font_open_by_name (FRAME_PTR f, const char *name, ptrdiff_t len);
+extern Lisp_Object font_open_by_name (FRAME_PTR f, Lisp_Object name);
 
 extern Lisp_Object font_intern_prop (const char *str, ptrdiff_t len,
                                     int force_symbol);
index 9668ea4d8319418fa0783d91eba349b7a38157f5..bf2b180f2d39d6fe63f0971c30bbd2678ebd491b 100644 (file)
@@ -3167,16 +3167,14 @@ x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
       fontset = fs_query_fontset (arg, 0);
       if (fontset < 0)
        {
-         font_object = font_open_by_name (f, SSDATA (arg), SBYTES (arg));
+         font_object = font_open_by_name (f, arg);
          if (NILP (font_object))
            error ("Font `%s' is not defined", SSDATA (arg));
          arg = AREF (font_object, FONT_NAME_INDEX);
        }
       else if (fontset > 0)
        {
-         Lisp_Object ascii_font = fontset_ascii (fontset);
-
-         font_object = font_open_by_name (f, SSDATA (ascii_font), SBYTES (ascii_font));
+         font_object = font_open_by_name (f, fontset_ascii (fontset));
          if (NILP (font_object))
            error ("Font `%s' is not defined", SDATA (arg));
          arg = AREF (font_object, FONT_NAME_INDEX);
index 131a27f76e014a403ccda3f2615d975471268e2a..e16f967f5968a2188093e11c3ce0403f09361c65 100644 (file)
@@ -211,7 +211,7 @@ ftfont_pattern_entity (FcPattern *p, Lisp_Object extra)
     return Qnil;
 
   file = (char *) str;
-  key = Fcons (make_unibyte_string (file, strlen (file)), make_number (idx));
+  key = Fcons (build_unibyte_string (file), make_number (idx));
   cache = ftfont_lookup_cache (key, FTFONT_CACHE_FOR_ENTITY);
   entity = XCAR (cache);
   if (! NILP (entity))
index 471b8277b829bf0f8b4fb04879ae8fecdacf115a..2a598900146fd2de3b8e5119ffcf6ee80c203dac 100644 (file)
@@ -2609,6 +2609,15 @@ extern Lisp_Object make_string (const char *, ptrdiff_t);
 extern Lisp_Object make_formatted_string (char *, const char *, ...)
   ATTRIBUTE_FORMAT_PRINTF (2, 3);
 extern Lisp_Object make_unibyte_string (const char *, ptrdiff_t);
+
+/* Make unibyte string from C string when the length isn't known.  */
+
+static inline Lisp_Object
+build_unibyte_string (const char *str)
+{
+  return make_unibyte_string (str, strlen (str));
+}
+
 extern Lisp_Object make_multibyte_string (const char *, ptrdiff_t, ptrdiff_t);
 extern Lisp_Object make_event_array (int, Lisp_Object *);
 extern Lisp_Object make_uninit_string (EMACS_INT);
index ceb5c81d32b7410f913e98b9fce374e4d3e6aeed..1b66bef03a8403db57a55a507416fd0a107dcb53 100644 (file)
@@ -497,7 +497,7 @@ status_message (struct Lisp_Process *p)
        {
          int c1, c2;
 
-         string = make_unibyte_string (signame, strlen (signame));
+         string = build_unibyte_string (signame);
          if (! NILP (Vlocale_coding_system))
            string = (code_convert_string_norecord
                      (string, Vlocale_coding_system, 0));
index 7d0855b543c469a49240aa9fe6e50ddf32163d5f..6ce583b3d53abcbd5d91a5775bc332dc8673eb6a 100644 (file)
@@ -3092,7 +3092,7 @@ system_process_attributes (Lisp_Object pid)
 
       decoded_comm =
        (code_convert_string_norecord
-        (make_unibyte_string (args, strlen (args)),
+        (build_unibyte_string (args),
          Vlocale_coding_system, 0));
 
       attrs = Fcons (Fcons (Qargs, decoded_comm), attrs);
index dac83ab6ae1bef15c50c7fd1c181e6cd9514bb41..06938e3124bbc6a2884bd769c52d6b29373a9669 100644 (file)
@@ -4036,7 +4036,7 @@ x_default_font_parameter (struct frame *f, Lisp_Object parms)
 
       for (i = 0; names[i]; i++)
         {
-          font = font_open_by_name (f, names[i], strlen (names[i]));
+          font = font_open_by_name (f, build_unibyte_string (names[i]));
           if (! NILP (font))
             break;
         }
@@ -6197,8 +6197,7 @@ an integer representing a ShowWindow flag:
   if (!NILP (Vlocale_coding_system))
     {
       Lisp_Object decoded =
-       code_convert_string_norecord (make_unibyte_string (errstr,
-                                                          strlen (errstr)),
+       code_convert_string_norecord (build_unibyte_string (errstr),
                                      Vlocale_coding_system, 0);
       errstr = SSDATA (decoded);
     }
index a0229919aa0628914d3005dbc644d56d1ac6ee3c..e431651d93ac11ab2f49812ae4ebbf3f71fa00d9 100644 (file)
@@ -2956,7 +2956,7 @@ x_default_font_parameter (struct frame *f, Lisp_Object parms)
          read yet.  */
       const char *system_font = xsettings_get_system_font ();
       if (system_font)
-       font = font_open_by_name (f, system_font, strlen (system_font));
+       font = font_open_by_name (f, build_unibyte_string (system_font));
     }
 
   if (NILP (font))
@@ -2986,7 +2986,7 @@ x_default_font_parameter (struct frame *f, Lisp_Object parms)
 
       for (i = 0; names[i]; i++)
        {
-         font = font_open_by_name (f, names[i], strlen (names[i]));
+         font = font_open_by_name (f, build_unibyte_string (names[i]));
          if (! NILP (font))
            break;
        }