[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] trunk r113879: Utility function and macro to copy Lisp str
From: |
Dmitry Antipov |
Subject: |
[Emacs-diffs] trunk r113879: Utility function and macro to copy Lisp string to C string. |
Date: |
Wed, 14 Aug 2013 16:37:19 +0000 |
User-agent: |
Bazaar (2.6b2) |
------------------------------------------------------------
revno: 113879
revision-id: address@hidden
parent: address@hidden
committer: Dmitry Antipov <address@hidden>
branch nick: trunk
timestamp: Wed 2013-08-14 20:36:16 +0400
message:
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.
modified:
src/ChangeLog changelog-20091113204419-o5vbwnq5f7feedwu-1438
src/alloc.c alloc.c-20091113204419-o5vbwnq5f7feedwu-252
src/callint.c callint.c-20091113204419-o5vbwnq5f7feedwu-279
src/fileio.c fileio.c-20091113204419-o5vbwnq5f7feedwu-210
src/frame.c frame.c-20091113204419-o5vbwnq5f7feedwu-243
src/image.c image.c-20091113204419-o5vbwnq5f7feedwu-2969
src/lisp.h lisp.h-20091113204419-o5vbwnq5f7feedwu-253
src/w32term.c w32term.c-20091113204419-o5vbwnq5f7feedwu-950
src/xterm.c xterm.c-20091113204419-o5vbwnq5f7feedwu-244
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog 2013-08-14 13:58:25 +0000
+++ b/src/ChangeLog 2013-08-14 16:36:16 +0000
@@ -1,3 +1,17 @@
+2013-08-14 Dmitry Antipov <address@hidden>
+
+ 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 <address@hidden>
* image.c (imagemagick_load_image): Make animated pictures work.
=== modified file 'src/alloc.c'
--- a/src/alloc.c 2013-08-11 01:30:20 +0000
+++ b/src/alloc.c 2013-08-14 16:36:16 +0000
@@ -802,6 +802,15 @@
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. */
=== modified file 'src/callint.c'
--- a/src/callint.c 2013-08-11 01:30:20 +0000
+++ b/src/callint.c 2013-08-14 16:36:16 +0000
@@ -331,12 +331,9 @@
/* 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;
=== modified file 'src/fileio.c'
--- a/src/fileio.c 2013-08-12 07:12:07 +0000
+++ b/src/fileio.c 2013-08-14 16:36:16 +0000
@@ -366,8 +366,7 @@
}
#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 @@
#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 @@
/* 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);
=== modified file 'src/frame.c'
--- a/src/frame.c 2013-08-11 01:30:20 +0000
+++ b/src/frame.c 2013-08-14 16:36:16 +0000
@@ -692,22 +692,14 @@
? 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. */
}
=== modified file 'src/image.c'
--- a/src/image.c 2013-08-14 13:50:03 +0000
+++ b/src/image.c 2013-08-14 16:36:16 +0000
@@ -302,11 +302,10 @@
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 @@
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 */
=== modified file 'src/lisp.h'
--- a/src/lisp.h 2013-08-12 07:12:07 +0000
+++ b/src/lisp.h 2013-08-14 16:36:16 +0000
@@ -4255,10 +4255,17 @@
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);
=== modified file 'src/w32term.c'
--- a/src/w32term.c 2013-08-13 18:01:18 +0000
+++ b/src/w32term.c 2013-08-14 16:36:16 +0000
@@ -6463,9 +6463,7 @@
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;
=== modified file 'src/xterm.c'
--- a/src/xterm.c 2013-08-13 15:29:25 +0000
+++ b/src/xterm.c 2013-08-14 16:36:16 +0000
@@ -10038,9 +10038,7 @@
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);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] trunk r113879: Utility function and macro to copy Lisp string to C string.,
Dmitry Antipov <=