From: Dmitry Antipov Date: Fri, 20 Jul 2012 07:29:04 +0000 (+0400) Subject: Simple wrapper for make_unibyte_string, adjust font_open_by_name. X-Git-Tag: emacs-24.2.90~1124 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d7ea76b4f34c4e2c43bf0b1deeedde354ca540f7;p=emacs.git Simple wrapper for make_unibyte_string, adjust font_open_by_name. * 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. --- diff --git a/admin/ChangeLog b/admin/ChangeLog index 0d059714788..b4c88c20ed1 100644 --- a/admin/ChangeLog +++ b/admin/ChangeLog @@ -1,3 +1,8 @@ +2012-07-20 Dmitry Antipov + + * coccinelle/unibyte_string.cocci: Semantic patch to convert from + make_unibyte_string to build_unibyte_string where appropriate. + 2012-07-17 Eli Zaretskii * CPP-DEFINES: Remove FILE_SYSTEM_CASE. @@ -5,6 +10,7 @@ 2012-07-17 Chong Yidong * Version 24.1 released. + 2012-07-11 Paul Eggert Assume mkdir, perror, rename, rmdir, strerror. diff --git a/admin/coccinelle/unibyte_string.cocci b/admin/coccinelle/unibyte_string.cocci new file mode 100644 index 00000000000..0ff8cafa15d --- /dev/null +++ b/admin/coccinelle/unibyte_string.cocci @@ -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) diff --git a/src/ChangeLog b/src/ChangeLog index 909fb03c488..8242a35e9ec 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,14 @@ +2012-07-20 Dmitry Antipov + + 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 Cleanup calls to Fgarbage_collect. diff --git a/src/dosfns.c b/src/dosfns.c index ee28801e841..6fd1b52e252 100644 --- a/src/dosfns.c +++ b/src/dosfns.c @@ -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); diff --git a/src/fileio.c b/src/fileio.c index 185dd650438..a13fe94e416 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -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; diff --git a/src/fns.c b/src/fns.c index da8889e70a7..6e6b9332942 100644 --- 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)); } diff --git a/src/font.c b/src/font.c index 5b01a1f44d6..2c0296aa8c5 100644 --- a/src/font.c +++ b/src/font.c @@ -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; diff --git a/src/font.h b/src/font.h index b4e994397de..2e374571c67 100644 --- a/src/font.h +++ b/src/font.h @@ -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); diff --git a/src/frame.c b/src/frame.c index 9668ea4d831..bf2b180f2d3 100644 --- a/src/frame.c +++ b/src/frame.c @@ -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); diff --git a/src/ftfont.c b/src/ftfont.c index 131a27f76e0..e16f967f596 100644 --- a/src/ftfont.c +++ b/src/ftfont.c @@ -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)) diff --git a/src/lisp.h b/src/lisp.h index 471b8277b82..2a598900146 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -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); diff --git a/src/process.c b/src/process.c index ceb5c81d32b..1b66bef03a8 100644 --- a/src/process.c +++ b/src/process.c @@ -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)); diff --git a/src/sysdep.c b/src/sysdep.c index 7d0855b543c..6ce583b3d53 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -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); diff --git a/src/w32fns.c b/src/w32fns.c index dac83ab6ae1..06938e3124b 100644 --- a/src/w32fns.c +++ b/src/w32fns.c @@ -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); } diff --git a/src/xfns.c b/src/xfns.c index a0229919aa0..e431651d93a 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -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; }