* lisp.h (xlispstrdupa): New macro.
(xlispstrdup): New prototype.
* alloc.c (xlispstrdup): New function.
* callint.c (Fcall_interactively):
* fileio.c (Ffile_name_directory, Fexpand_file_name)
(Fsubstitute_in_file_name):
* frame.c (Fmake_terminal_frame): Use xlispstrdupa.
* image.c (x_create_bitmap_from_file):
* w32term.c (w32_term_init):
* xterm.c (x_term_init): Use xlispstrdup.
+2013-08-14 Dmitry Antipov <dmantipov@yandex.ru>
+
+ Utility function and macro to copy Lisp string to C string.
+ * lisp.h (xlispstrdupa): New macro.
+ (xlispstrdup): New prototype.
+ * alloc.c (xlispstrdup): New function.
+ * callint.c (Fcall_interactively):
+ * fileio.c (Ffile_name_directory, Fexpand_file_name)
+ (Fsubstitute_in_file_name):
+ * frame.c (Fmake_terminal_frame): Use xlispstrdupa.
+ * image.c (x_create_bitmap_from_file):
+ * w32term.c (w32_term_init):
+ * xterm.c (x_term_init): Use xlispstrdup.
+
2013-08-14 Lars Magne Ingebrigtsen <larsi@gnus.org>
* image.c (imagemagick_load_image): Make animated pictures work.
return memcpy (xmalloc (size), s, size);
}
+/* Like above, but duplicates Lisp string to C string. */
+
+char *
+xlispstrdup (Lisp_Object string)
+{
+ ptrdiff_t size = SBYTES (string) + 1;
+ return memcpy (xmalloc (size), SSDATA (string), size);
+}
+
/* Like putenv, but (1) use the equivalent of xmalloc and (2) the
argument is a const pointer. */
/* If SPECS is set to a string, use it as an interactive prompt. */
if (STRINGP (specs))
- {
- /* Make a copy of string so that if a GC relocates specs,
- `string' will still be valid. */
- string = alloca (SBYTES (specs) + 1);
- memcpy (string, SSDATA (specs), SBYTES (specs) + 1);
- }
+ /* Make a copy of string so that if a GC relocates specs,
+ `string' will still be valid. */
+ string = xlispstrdupa (specs);
else
{
Lisp_Object input;
}
#ifdef DOS_NT
- beg = alloca (SBYTES (filename) + 1);
- memcpy (beg, SSDATA (filename), SBYTES (filename) + 1);
+ beg = xlispstrdupa (filename);
#else
beg = SSDATA (filename);
#endif
#endif
/* Make a local copy of nm[] to protect it from GC in DECODE_FILE below. */
- nm = alloca (SBYTES (name) + 1);
- memcpy (nm, SSDATA (name), SBYTES (name) + 1);
+ nm = xlispstrdupa (name);
#ifdef DOS_NT
/* Note if special escape prefix is present, but remove for now. */
/* Always work on a copy of the string, in case GC happens during
decode of environment variables, causing the original Lisp_String
data to be relocated. */
- nm = alloca (SBYTES (filename) + 1);
- memcpy (nm, SDATA (filename), SBYTES (filename) + 1);
+ nm = xlispstrdupa (filename);
#ifdef DOS_NT
dostounix_filename (nm, multibyte);
? FRAME_TTY (XFRAME (selected_frame))->name
: NULL));
if (!NILP (tty))
- {
- name = alloca (SBYTES (tty) + 1);
- memcpy (name, SSDATA (tty), SBYTES (tty));
- name[SBYTES (tty)] = 0;
- }
+ name = xlispstrdupa (tty);
tty_type = get_future_frame_param
(Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
? FRAME_TTY (XFRAME (selected_frame))->type
: NULL));
if (!NILP (tty_type))
- {
- type = alloca (SBYTES (tty_type) + 1);
- memcpy (type, SSDATA (tty_type), SBYTES (tty_type));
- type[SBYTES (tty_type)] = 0;
- }
+ type = xlispstrdupa (tty_type);
t = init_tty (name, type, 0); /* Errors are not fatal. */
}
id = x_allocate_bitmap_record (f);
dpyinfo->bitmaps[id - 1].img = bitmap;
dpyinfo->bitmaps[id - 1].refcount = 1;
- dpyinfo->bitmaps[id - 1].file = xmalloc (SBYTES (file) + 1);
+ dpyinfo->bitmaps[id - 1].file = xlispstrdup (file);
dpyinfo->bitmaps[id - 1].depth = 1;
dpyinfo->bitmaps[id - 1].height = ns_image_width (bitmap);
dpyinfo->bitmaps[id - 1].width = ns_image_height (bitmap);
- strcpy (dpyinfo->bitmaps[id - 1].file, SSDATA (file));
return id;
#endif
dpyinfo->bitmaps[id - 1].pixmap = bitmap;
dpyinfo->bitmaps[id - 1].have_mask = 0;
dpyinfo->bitmaps[id - 1].refcount = 1;
- dpyinfo->bitmaps[id - 1].file = xmalloc (SBYTES (file) + 1);
+ dpyinfo->bitmaps[id - 1].file = xlispstrdup (file);
dpyinfo->bitmaps[id - 1].depth = 1;
dpyinfo->bitmaps[id - 1].height = height;
dpyinfo->bitmaps[id - 1].width = width;
- strcpy (dpyinfo->bitmaps[id - 1].file, SSDATA (file));
return id;
#endif /* HAVE_X_WINDOWS */
extern void *xpalloc (void *, ptrdiff_t *, ptrdiff_t, ptrdiff_t, ptrdiff_t);
extern char *xstrdup (const char *);
+extern char *xlispstrdup (Lisp_Object);
extern void xputenv (const char *);
extern char *egetenv (const char *);
+/* Copy Lisp string to temporary (allocated on stack) C string. */
+
+#define xlispstrdupa(string) \
+ memcpy (alloca (SBYTES (string) + 1), \
+ SSDATA (string), SBYTES (string) + 1)
+
/* Set up the name of the machine we're running on. */
extern void init_system_name (void);
terminal = w32_create_terminal (dpyinfo);
/* Set the name of the terminal. */
- terminal->name = xmalloc (SBYTES (display_name) + 1);
- strncpy (terminal->name, SDATA (display_name), SBYTES (display_name));
- terminal->name[SBYTES (display_name)] = 0;
+ terminal->name = xlispstrdup (display_name);
dpyinfo->xrdb = xrm_option ? w32_make_rdb (xrm_option) : NULL;
dpyinfo->display = dpy;
/* Set the name of the terminal. */
- terminal->name = xmalloc (SBYTES (display_name) + 1);
- memcpy (terminal->name, SSDATA (display_name), SBYTES (display_name));
- terminal->name[SBYTES (display_name)] = 0;
+ terminal->name = xlispstrdup (display_name);
#if 0
XSetAfterFunction (x_current_display, x_trace_wire);