aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDmitry Antipov2013-08-14 20:36:16 +0400
committerDmitry Antipov2013-08-14 20:36:16 +0400
commit5b71542de3ef7f08b7c30e93340502d7cc120910 (patch)
treedfb9bee6c19bf4467852500cf6b53771652e3d84 /src
parentd48d97ee4ab07e0c3e8c1a63efcfb707eef1b352 (diff)
downloademacs-5b71542de3ef7f08b7c30e93340502d7cc120910.tar.gz
emacs-5b71542de3ef7f08b7c30e93340502d7cc120910.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog14
-rw-r--r--src/alloc.c9
-rw-r--r--src/callint.c9
-rw-r--r--src/fileio.c9
-rw-r--r--src/frame.c12
-rw-r--r--src/image.c6
-rw-r--r--src/lisp.h7
-rw-r--r--src/w32term.c4
-rw-r--r--src/xterm.c4
9 files changed, 42 insertions, 32 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 8a3186b85f2..415c4c3f525 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,17 @@
12013-08-14 Dmitry Antipov <dmantipov@yandex.ru>
2
3 Utility function and macro to copy Lisp string to C string.
4 * lisp.h (xlispstrdupa): New macro.
5 (xlispstrdup): New prototype.
6 * alloc.c (xlispstrdup): New function.
7 * callint.c (Fcall_interactively):
8 * fileio.c (Ffile_name_directory, Fexpand_file_name)
9 (Fsubstitute_in_file_name):
10 * frame.c (Fmake_terminal_frame): Use xlispstrdupa.
11 * image.c (x_create_bitmap_from_file):
12 * w32term.c (w32_term_init):
13 * xterm.c (x_term_init): Use xlispstrdup.
14
12013-08-14 Lars Magne Ingebrigtsen <larsi@gnus.org> 152013-08-14 Lars Magne Ingebrigtsen <larsi@gnus.org>
2 16
3 * image.c (imagemagick_load_image): Make animated pictures work. 17 * image.c (imagemagick_load_image): Make animated pictures work.
diff --git a/src/alloc.c b/src/alloc.c
index 2c2232601cb..c0d8c32b440 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -802,6 +802,15 @@ xstrdup (const char *s)
802 return memcpy (xmalloc (size), s, size); 802 return memcpy (xmalloc (size), s, size);
803} 803}
804 804
805/* Like above, but duplicates Lisp string to C string. */
806
807char *
808xlispstrdup (Lisp_Object string)
809{
810 ptrdiff_t size = SBYTES (string) + 1;
811 return memcpy (xmalloc (size), SSDATA (string), size);
812}
813
805/* Like putenv, but (1) use the equivalent of xmalloc and (2) the 814/* Like putenv, but (1) use the equivalent of xmalloc and (2) the
806 argument is a const pointer. */ 815 argument is a const pointer. */
807 816
diff --git a/src/callint.c b/src/callint.c
index f43a5a990db..25096af5068 100644
--- a/src/callint.c
+++ b/src/callint.c
@@ -331,12 +331,9 @@ invoke it. If KEYS is omitted or nil, the return value of
331 331
332 /* If SPECS is set to a string, use it as an interactive prompt. */ 332 /* If SPECS is set to a string, use it as an interactive prompt. */
333 if (STRINGP (specs)) 333 if (STRINGP (specs))
334 { 334 /* Make a copy of string so that if a GC relocates specs,
335 /* Make a copy of string so that if a GC relocates specs, 335 `string' will still be valid. */
336 `string' will still be valid. */ 336 string = xlispstrdupa (specs);
337 string = alloca (SBYTES (specs) + 1);
338 memcpy (string, SSDATA (specs), SBYTES (specs) + 1);
339 }
340 else 337 else
341 { 338 {
342 Lisp_Object input; 339 Lisp_Object input;
diff --git a/src/fileio.c b/src/fileio.c
index 6ec5f78c2cf..08caf102266 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -366,8 +366,7 @@ Given a Unix syntax file name, returns a string ending in slash. */)
366 } 366 }
367 367
368#ifdef DOS_NT 368#ifdef DOS_NT
369 beg = alloca (SBYTES (filename) + 1); 369 beg = xlispstrdupa (filename);
370 memcpy (beg, SSDATA (filename), SBYTES (filename) + 1);
371#else 370#else
372 beg = SSDATA (filename); 371 beg = SSDATA (filename);
373#endif 372#endif
@@ -944,8 +943,7 @@ filesystem tree, not (expand-file-name ".." dirname). */)
944#endif 943#endif
945 944
946 /* Make a local copy of nm[] to protect it from GC in DECODE_FILE below. */ 945 /* Make a local copy of nm[] to protect it from GC in DECODE_FILE below. */
947 nm = alloca (SBYTES (name) + 1); 946 nm = xlispstrdupa (name);
948 memcpy (nm, SSDATA (name), SBYTES (name) + 1);
949 947
950#ifdef DOS_NT 948#ifdef DOS_NT
951 /* Note if special escape prefix is present, but remove for now. */ 949 /* Note if special escape prefix is present, but remove for now. */
@@ -1693,8 +1691,7 @@ those `/' is discarded. */)
1693 /* Always work on a copy of the string, in case GC happens during 1691 /* Always work on a copy of the string, in case GC happens during
1694 decode of environment variables, causing the original Lisp_String 1692 decode of environment variables, causing the original Lisp_String
1695 data to be relocated. */ 1693 data to be relocated. */
1696 nm = alloca (SBYTES (filename) + 1); 1694 nm = xlispstrdupa (filename);
1697 memcpy (nm, SDATA (filename), SBYTES (filename) + 1);
1698 1695
1699#ifdef DOS_NT 1696#ifdef DOS_NT
1700 dostounix_filename (nm, multibyte); 1697 dostounix_filename (nm, multibyte);
diff --git a/src/frame.c b/src/frame.c
index a1f151a221e..bb44f3cc987 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -692,22 +692,14 @@ affects all frames on the same terminal device. */)
692 ? FRAME_TTY (XFRAME (selected_frame))->name 692 ? FRAME_TTY (XFRAME (selected_frame))->name
693 : NULL)); 693 : NULL));
694 if (!NILP (tty)) 694 if (!NILP (tty))
695 { 695 name = xlispstrdupa (tty);
696 name = alloca (SBYTES (tty) + 1);
697 memcpy (name, SSDATA (tty), SBYTES (tty));
698 name[SBYTES (tty)] = 0;
699 }
700 696
701 tty_type = get_future_frame_param 697 tty_type = get_future_frame_param
702 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame)) 698 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
703 ? FRAME_TTY (XFRAME (selected_frame))->type 699 ? FRAME_TTY (XFRAME (selected_frame))->type
704 : NULL)); 700 : NULL));
705 if (!NILP (tty_type)) 701 if (!NILP (tty_type))
706 { 702 type = xlispstrdupa (tty_type);
707 type = alloca (SBYTES (tty_type) + 1);
708 memcpy (type, SSDATA (tty_type), SBYTES (tty_type));
709 type[SBYTES (tty_type)] = 0;
710 }
711 703
712 t = init_tty (name, type, 0); /* Errors are not fatal. */ 704 t = init_tty (name, type, 0); /* Errors are not fatal. */
713 } 705 }
diff --git a/src/image.c b/src/image.c
index b2d6726c1a4..f71ba211d44 100644
--- a/src/image.c
+++ b/src/image.c
@@ -302,11 +302,10 @@ x_create_bitmap_from_file (struct frame *f, Lisp_Object file)
302 id = x_allocate_bitmap_record (f); 302 id = x_allocate_bitmap_record (f);
303 dpyinfo->bitmaps[id - 1].img = bitmap; 303 dpyinfo->bitmaps[id - 1].img = bitmap;
304 dpyinfo->bitmaps[id - 1].refcount = 1; 304 dpyinfo->bitmaps[id - 1].refcount = 1;
305 dpyinfo->bitmaps[id - 1].file = xmalloc (SBYTES (file) + 1); 305 dpyinfo->bitmaps[id - 1].file = xlispstrdup (file);
306 dpyinfo->bitmaps[id - 1].depth = 1; 306 dpyinfo->bitmaps[id - 1].depth = 1;
307 dpyinfo->bitmaps[id - 1].height = ns_image_width (bitmap); 307 dpyinfo->bitmaps[id - 1].height = ns_image_width (bitmap);
308 dpyinfo->bitmaps[id - 1].width = ns_image_height (bitmap); 308 dpyinfo->bitmaps[id - 1].width = ns_image_height (bitmap);
309 strcpy (dpyinfo->bitmaps[id - 1].file, SSDATA (file));
310 return id; 309 return id;
311#endif 310#endif
312 311
@@ -345,11 +344,10 @@ x_create_bitmap_from_file (struct frame *f, Lisp_Object file)
345 dpyinfo->bitmaps[id - 1].pixmap = bitmap; 344 dpyinfo->bitmaps[id - 1].pixmap = bitmap;
346 dpyinfo->bitmaps[id - 1].have_mask = 0; 345 dpyinfo->bitmaps[id - 1].have_mask = 0;
347 dpyinfo->bitmaps[id - 1].refcount = 1; 346 dpyinfo->bitmaps[id - 1].refcount = 1;
348 dpyinfo->bitmaps[id - 1].file = xmalloc (SBYTES (file) + 1); 347 dpyinfo->bitmaps[id - 1].file = xlispstrdup (file);
349 dpyinfo->bitmaps[id - 1].depth = 1; 348 dpyinfo->bitmaps[id - 1].depth = 1;
350 dpyinfo->bitmaps[id - 1].height = height; 349 dpyinfo->bitmaps[id - 1].height = height;
351 dpyinfo->bitmaps[id - 1].width = width; 350 dpyinfo->bitmaps[id - 1].width = width;
352 strcpy (dpyinfo->bitmaps[id - 1].file, SSDATA (file));
353 351
354 return id; 352 return id;
355#endif /* HAVE_X_WINDOWS */ 353#endif /* HAVE_X_WINDOWS */
diff --git a/src/lisp.h b/src/lisp.h
index 8dca073a83a..6d79bb1d6a5 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4255,10 +4255,17 @@ extern void *xnrealloc (void *, ptrdiff_t, ptrdiff_t);
4255extern void *xpalloc (void *, ptrdiff_t *, ptrdiff_t, ptrdiff_t, ptrdiff_t); 4255extern void *xpalloc (void *, ptrdiff_t *, ptrdiff_t, ptrdiff_t, ptrdiff_t);
4256 4256
4257extern char *xstrdup (const char *); 4257extern char *xstrdup (const char *);
4258extern char *xlispstrdup (Lisp_Object);
4258extern void xputenv (const char *); 4259extern void xputenv (const char *);
4259 4260
4260extern char *egetenv (const char *); 4261extern char *egetenv (const char *);
4261 4262
4263/* Copy Lisp string to temporary (allocated on stack) C string. */
4264
4265#define xlispstrdupa(string) \
4266 memcpy (alloca (SBYTES (string) + 1), \
4267 SSDATA (string), SBYTES (string) + 1)
4268
4262/* Set up the name of the machine we're running on. */ 4269/* Set up the name of the machine we're running on. */
4263extern void init_system_name (void); 4270extern void init_system_name (void);
4264 4271
diff --git a/src/w32term.c b/src/w32term.c
index 03a9af12ea8..7d51850559b 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -6463,9 +6463,7 @@ w32_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
6463 terminal = w32_create_terminal (dpyinfo); 6463 terminal = w32_create_terminal (dpyinfo);
6464 6464
6465 /* Set the name of the terminal. */ 6465 /* Set the name of the terminal. */
6466 terminal->name = xmalloc (SBYTES (display_name) + 1); 6466 terminal->name = xlispstrdup (display_name);
6467 strncpy (terminal->name, SDATA (display_name), SBYTES (display_name));
6468 terminal->name[SBYTES (display_name)] = 0;
6469 6467
6470 dpyinfo->xrdb = xrm_option ? w32_make_rdb (xrm_option) : NULL; 6468 dpyinfo->xrdb = xrm_option ? w32_make_rdb (xrm_option) : NULL;
6471 6469
diff --git a/src/xterm.c b/src/xterm.c
index 15ad3bdf851..9e1e32a2faf 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -10038,9 +10038,7 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
10038 dpyinfo->display = dpy; 10038 dpyinfo->display = dpy;
10039 10039
10040 /* Set the name of the terminal. */ 10040 /* Set the name of the terminal. */
10041 terminal->name = xmalloc (SBYTES (display_name) + 1); 10041 terminal->name = xlispstrdup (display_name);
10042 memcpy (terminal->name, SSDATA (display_name), SBYTES (display_name));
10043 terminal->name[SBYTES (display_name)] = 0;
10044 10042
10045#if 0 10043#if 0
10046 XSetAfterFunction (x_current_display, x_trace_wire); 10044 XSetAfterFunction (x_current_display, x_trace_wire);