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.
This commit is contained in:
Dmitry Antipov 2013-08-14 20:36:16 +04:00
parent d48d97ee4a
commit 5b71542de3
9 changed files with 42 additions and 32 deletions

View file

@ -1,3 +1,17 @@
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.

View file

@ -802,6 +802,15 @@ xstrdup (const char *s)
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. */

View file

@ -331,12 +331,9 @@ invoke it. If KEYS is omitted or nil, the return value of
/* 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;

View file

@ -366,8 +366,7 @@ Given a Unix syntax file name, returns a string ending in slash. */)
}
#ifdef DOS_NT
beg = alloca (SBYTES (filename) + 1);
memcpy (beg, SSDATA (filename), SBYTES (filename) + 1);
beg = xlispstrdupa (filename);
#else
beg = SSDATA (filename);
#endif
@ -944,8 +943,7 @@ filesystem tree, not (expand-file-name ".." dirname). */)
#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. */
@ -1693,8 +1691,7 @@ those `/' is discarded. */)
/* 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);

View file

@ -692,22 +692,14 @@ affects all frames on the same terminal device. */)
? 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. */
}

View file

@ -302,11 +302,10 @@ x_create_bitmap_from_file (struct frame *f, Lisp_Object file)
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
@ -345,11 +344,10 @@ x_create_bitmap_from_file (struct frame *f, Lisp_Object file)
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 */

View file

@ -4255,10 +4255,17 @@ extern void *xnrealloc (void *, ptrdiff_t, ptrdiff_t);
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);

View file

@ -6463,9 +6463,7 @@ w32_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
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;

View file

@ -10038,9 +10038,7 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
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);