aboutsummaryrefslogtreecommitdiffstats
path: root/src/data.c
diff options
context:
space:
mode:
authorPaul Eggert2014-09-29 19:43:23 -0700
committerPaul Eggert2014-09-29 19:43:23 -0700
commitdc4525691c2c236abdb6c074438223413f80091c (patch)
tree86305e7415bcf1b5cc6ddad6879e922f9e5e163c /src/data.c
parenta19f0977a96ee74b96410b41a8ea793c86f64b58 (diff)
downloademacs-dc4525691c2c236abdb6c074438223413f80091c.tar.gz
emacs-dc4525691c2c236abdb6c074438223413f80091c.zip
Simplify stack-allocated Lisp objects, and make them more portable.
The build_local_string macro was used in two ways: (1) string literals for which scoped allocation suffices, and (2) file name components, where it's not safe in general to assume bounded-size ASCII data. Simplify by defining a new macro SCOPED_STRING that allocates a block-scope string, and by using SCOPED_STRING for (1) and build_string for (2). Furthermore, actually use stack allocation only for objects known to have sufficient alignment. This simpler implementation means Emacs can make USE_STACK_LISP_OBJECTS the default unless GC_MARK_STACK != GC_MAKE_GCPROS_NOOPS. * lisp.h (GCALIGNED): Align even if !USE_STACK_LISP_OBJECTS, for fewer differences among implementations. (struct Lisp_String): Now GCALIGNED. (USE_STACK_LISP_OBJECTS): Default to true, since the implementation no longer insists on a nonempty GCALIGNED. But make it false if GC_MARK_STACK != GC_MAKE_GCPROS_NOOPS. (SCOPED_CONS_INITIALIZER): Remove, since it's no longer needed separately. Move definiens to scoped_cons. The old definition was incorrect when GCALIGNED was defined to be empty. (union Aligned_String): New type. (USE_STACK_CONS, USE_STACK_STRING): New constants, so that the implementation ports to compilers that don't align strictly enough. Don't worry about the union sizes; it's not worth bothering about. (scoped_cons, scoped_list1, scoped_list3, scoped_list4): Rewrite using USE_STACK_CONS. (scoped_cons): Assume the use of union Aligned_Cons. (lisp_string_size, make_local_string, build_local_string): Remove. Unless otherwise specified, all callers of build_local_string changed to use SCOPED_STRING. (SCOPED_STRING): New macro. * data.c (wrong_choice): * menu.c (single_menu_item): * process.c (Fformat_network_address): Hoist use of SCOPED_STRING out of a scope, so that its returned object lives long enough. * fileio.c (Fexpand_file_name): Use build_string, not SCOPED_STRING, as the string might be long or might not be ASCII.
Diffstat (limited to 'src/data.c')
-rw-r--r--src/data.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/data.c b/src/data.c
index 414da4cf6f7..b71d88506d0 100644
--- a/src/data.c
+++ b/src/data.c
@@ -979,18 +979,20 @@ wrong_choice (Lisp_Object choice, Lisp_Object wrong)
979{ 979{
980 ptrdiff_t i = 0, len = XINT (Flength (choice)); 980 ptrdiff_t i = 0, len = XINT (Flength (choice));
981 Lisp_Object obj, *args; 981 Lisp_Object obj, *args;
982 Lisp_Object should_be_specified = SCOPED_STRING (" should be specified");
983 Lisp_Object or = SCOPED_STRING (" or ");
984 Lisp_Object comma = SCOPED_STRING (", ");
982 985
983 USE_SAFE_ALLOCA; 986 USE_SAFE_ALLOCA;
984 SAFE_ALLOCA_LISP (args, len * 2 + 1); 987 SAFE_ALLOCA_LISP (args, len * 2 + 1);
985 988
986 args[i++] = build_local_string ("One of "); 989 args[i++] = SCOPED_STRING ("One of ");
987 990
988 for (obj = choice; !NILP (obj); obj = XCDR (obj)) 991 for (obj = choice; !NILP (obj); obj = XCDR (obj))
989 { 992 {
990 args[i++] = SYMBOL_NAME (XCAR (obj)); 993 args[i++] = SYMBOL_NAME (XCAR (obj));
991 args[i++] = build_local_string 994 args[i++] = (NILP (XCDR (obj)) ? should_be_specified
992 (NILP (XCDR (obj)) ? " should be specified" 995 : NILP (XCDR (XCDR (obj))) ? or : comma);
993 : (NILP (XCDR (XCDR (obj))) ? " or " : ", "));
994 } 996 }
995 997
996 obj = Fconcat (i, args); 998 obj = Fconcat (i, args);
@@ -1005,9 +1007,9 @@ static void
1005wrong_range (Lisp_Object min, Lisp_Object max, Lisp_Object wrong) 1007wrong_range (Lisp_Object min, Lisp_Object max, Lisp_Object wrong)
1006{ 1008{
1007 xsignal2 (Qerror, Fconcat (4, ((Lisp_Object []) 1009 xsignal2 (Qerror, Fconcat (4, ((Lisp_Object [])
1008 { build_local_string ("Value should be from "), 1010 { SCOPED_STRING ("Value should be from "),
1009 Fnumber_to_string (min), 1011 Fnumber_to_string (min),
1010 build_local_string (" to "), 1012 SCOPED_STRING (" to "),
1011 Fnumber_to_string (max) })), wrong); 1013 Fnumber_to_string (max) })), wrong);
1012} 1014}
1013 1015