From: Dmitry Antipov Date: Fri, 9 Aug 2013 12:25:34 +0000 (+0400) Subject: Use xstrdup and build_unibyte_string where applicable. X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~1686^2~347 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=309f24d1ec07646fb1a090ee10fe456e79aea097;p=emacs.git Use xstrdup and build_unibyte_string where applicable. * alloc.c (xstrdup): Tiny cleanup. Add eassert. * xfns.c (x_window): * xrdb.c (x_get_customization_string): * xterm.c (xim_initialize): * w32fns.c (w32_window): Use xstrdup. (w32_display_monitor_attributes_list): * emacs.c (init_cmdargs): * keyboard.c (PUSH_C_STR): * nsfont.m (nsfont_open): * sysdep.c (system_process_attributes): * w32.c (system_process_attributes): * xdisp.c (message1, message1_nolog): Use build_unibyte_string. --- diff --git a/src/ChangeLog b/src/ChangeLog index aa424d2ec06..bd8aae80d5d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,19 @@ +2013-08-09 Dmitry Antipov + + Use xstrdup and build_unibyte_string where applicable. + * alloc.c (xstrdup): Tiny cleanup. Add eassert. + * xfns.c (x_window): + * xrdb.c (x_get_customization_string): + * xterm.c (xim_initialize): + * w32fns.c (w32_window): Use xstrdup. + (w32_display_monitor_attributes_list): + * emacs.c (init_cmdargs): + * keyboard.c (PUSH_C_STR): + * nsfont.m (nsfont_open): + * sysdep.c (system_process_attributes): + * w32.c (system_process_attributes): + * xdisp.c (message1, message1_nolog): Use build_unibyte_string. + 2013-08-09 Eli Zaretskii * w32.c (PEXCEPTION_POINTERS, PEXCEPTION_RECORD, PCONTEXT): Define diff --git a/src/alloc.c b/src/alloc.c index c8141d22f95..19418bd6686 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -796,10 +796,8 @@ xpalloc (void *pa, ptrdiff_t *nitems, ptrdiff_t nitems_incr_min, char * xstrdup (const char *s) { - size_t len = strlen (s) + 1; - char *p = xmalloc (len); - memcpy (p, s, len); - return p; + eassert (s); + return strcpy (xmalloc (strlen (s) + 1), s); } /* Like putenv, but (1) use the equivalent of xmalloc and (2) the diff --git a/src/emacs.c b/src/emacs.c index cf3a3c68932..23aef6a2b65 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -517,8 +517,7 @@ init_cmdargs (int argc, char **argv, int skip_args) They are decoded in the function command-line after we know locale-coding-system. */ Vcommand_line_args - = Fcons (make_unibyte_string (argv[i], strlen (argv[i])), - Vcommand_line_args); + = Fcons (build_unibyte_string (argv[i]), Vcommand_line_args); } unbind_to (count, Qnil); diff --git a/src/keyboard.c b/src/keyboard.c index c026b16e689..3afdce42ca2 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -8431,7 +8431,7 @@ read_char_minibuf_menu_prompt (int commandflag, return Qnil; #define PUSH_C_STR(str, listvar) \ - listvar = Fcons (make_unibyte_string (str, strlen (str)), listvar) + listvar = Fcons (build_unibyte_string (str), listvar) /* Prompt string always starts with map's prompt, and a space. */ prompt_strings = Fcons (name, prompt_strings); diff --git a/src/nsfont.m b/src/nsfont.m index ad169d7ddae..235150e3aef 100644 --- a/src/nsfont.m +++ b/src/nsfont.m @@ -920,8 +920,7 @@ nsfont_open (struct frame *f, Lisp_Object font_entity, int pixel_size) font->underline_thickness = lrint (font_info->underwidth); font->props[FONT_NAME_INDEX] = Ffont_xlfd_name (font_object, Qnil); - font->props[FONT_FULLNAME_INDEX] = - make_unibyte_string (font_info->name, strlen (font_info->name)); + font->props[FONT_FULLNAME_INDEX] = build_unibyte_string (font_info->name); } unblock_input (); diff --git a/src/sysdep.c b/src/sysdep.c index 11a6f4a76ce..201ba9d104d 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -3243,13 +3243,11 @@ system_process_attributes (Lisp_Object pid) attrs); decoded_cmd = (code_convert_string_norecord - (make_unibyte_string (pinfo.pr_fname, - strlen (pinfo.pr_fname)), + (build_unibyte_string (pinfo.pr_fname), Vlocale_coding_system, 0)); attrs = Fcons (Fcons (Qcomm, decoded_cmd), attrs); decoded_cmd = (code_convert_string_norecord - (make_unibyte_string (pinfo.pr_psargs, - strlen (pinfo.pr_psargs)), + (build_unibyte_string (pinfo.pr_psargs), Vlocale_coding_system, 0)); attrs = Fcons (Fcons (Qargs, decoded_cmd), attrs); } @@ -3319,9 +3317,9 @@ system_process_attributes (Lisp_Object pid) if (gr) attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs); - decoded_comm = code_convert_string_norecord - (make_unibyte_string (proc.ki_comm, strlen (proc.ki_comm)), - Vlocale_coding_system, 0); + decoded_comm = (code_convert_string_norecord + (build_unibyte_string (proc.ki_comm), + Vlocale_coding_system, 0)); attrs = Fcons (Fcons (Qcomm, decoded_comm), attrs); { diff --git a/src/w32.c b/src/w32.c index 9b87cfc8faa..21dbf49ed7c 100644 --- a/src/w32.c +++ b/src/w32.c @@ -5769,8 +5769,8 @@ system_process_attributes (Lisp_Object pid) { /* Decode the command name from locale-specific encoding. */ - cmd_str = make_unibyte_string (pe.szExeFile, - strlen (pe.szExeFile)); + cmd_str = build_unibyte_string (pe.szExeFile); + decoded_cmd = code_convert_string_norecord (cmd_str, Vlocale_coding_system, 0); diff --git a/src/w32fns.c b/src/w32fns.c index dff35de0973..c43b7d4adf3 100644 --- a/src/w32fns.c +++ b/src/w32fns.c @@ -4124,12 +4124,7 @@ w32_window (struct frame *f, long window_prompting, int minibuffer_only) for the window manager, so GC relocation won't bother it. Elsewhere we specify the window name for the window manager. */ - - { - char *str = SSDATA (Vx_resource_name); - f->namebuf = xmalloc (strlen (str) + 1); - strcpy (f->namebuf, str); - } + f->namebuf = xstrdup (SSDATA (Vx_resource_name)); my_create_window (f); @@ -4992,8 +4987,8 @@ w32_display_monitor_attributes_list (void) attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)), attributes); - name = DECODE_SYSTEM (make_unibyte_string (mi.szDevice, - strlen (mi.szDevice))); + name = DECODE_SYSTEM (build_unibyte_string (mi.szDevice)); + attributes = Fcons (Fcons (Qname, name), attributes); attributes = Fcons (Fcons (Qmm_size, list2i (width_mm, height_mm)), diff --git a/src/xdisp.c b/src/xdisp.c index ab625b9d6ec..aee24e27d52 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -9789,7 +9789,7 @@ message3_nolog (Lisp_Object m) void message1 (const char *m) { - message3 (m ? make_unibyte_string (m, strlen (m)) : Qnil); + message3 (m ? build_unibyte_string (m) : Qnil); } @@ -9798,7 +9798,7 @@ message1 (const char *m) void message1_nolog (const char *m) { - message3_nolog (m ? make_unibyte_string (m, strlen (m)) : Qnil); + message3_nolog (m ? build_unibyte_string (m) : Qnil); } /* Display a message M which contains a single %s diff --git a/src/xfns.c b/src/xfns.c index a1e9e916aba..92a7964eb75 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -2313,12 +2313,7 @@ x_window (struct frame *f, long window_prompting, int minibuffer_only) for the window manager, so GC relocation won't bother it. Elsewhere we specify the window name for the window manager. */ - - { - char *str = SSDATA (Vx_resource_name); - f->namebuf = xmalloc (strlen (str) + 1); - strcpy (f->namebuf, str); - } + f->namebuf = xstrdup (SSDATA (Vx_resource_name)); ac = 0; XtSetArg (al[ac], XtNallowShellResize, 1); ac++; diff --git a/src/xrdb.c b/src/xrdb.c index 7c9cd53fa8c..6ef5c3bcb41 100644 --- a/src/xrdb.c +++ b/src/xrdb.c @@ -75,18 +75,9 @@ x_get_customization_string (XrmDatabase db, const char *name, sprintf (full_class, "%s.%s", class, "Customization"); result = x_get_string_resource (db, full_name, full_class); - - if (result) - { - char *copy = xmalloc (strlen (result) + 1); - strcpy (copy, result); - return copy; - } - else - return 0; + return result ? xstrdup (result) : NULL; } - /* Expand all the Xt-style %-escapes in STRING, whose length is given by STRING_LEN. Here are the escapes we're supposed to recognize: diff --git a/src/xterm.c b/src/xterm.c index 6391154961f..db5ca1a1fbb 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -8081,13 +8081,10 @@ xim_initialize (struct x_display_info *dpyinfo, char *resource_name) { #ifdef HAVE_X11R6_XIM struct xim_inst_t *xim_inst = xmalloc (sizeof *xim_inst); - ptrdiff_t len; dpyinfo->xim_callback_data = xim_inst; xim_inst->dpyinfo = dpyinfo; - len = strlen (resource_name); - xim_inst->resource_name = xmalloc (len + 1); - memcpy (xim_inst->resource_name, resource_name, len + 1); + xim_inst->resource_name = xstrdup (resource_name); XRegisterIMInstantiateCallback (dpyinfo->display, dpyinfo->xrdb, resource_name, emacs_class, xim_instantiate_callback,