* 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 Dmitry Antipov <dmantipov@yandex.ru>
+
+ 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 <eliz@gnu.org>
* w32.c (PEXCEPTION_POINTERS, PEXCEPTION_RECORD, PCONTEXT): Define
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
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);
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);
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 ();
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);
}
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);
{
{
/* 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);
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);
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)),
void
message1 (const char *m)
{
- message3 (m ? make_unibyte_string (m, strlen (m)) : Qnil);
+ message3 (m ? build_unibyte_string (m) : Qnil);
}
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
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++;
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:
{
#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,