aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.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/buffer.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/buffer.c')
-rw-r--r--src/buffer.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 39d08950bf8..9d376346a0a 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1552,10 +1552,10 @@ exists, return the buffer `*scratch*' (creating it if necessary). */)
1552 return notsogood; 1552 return notsogood;
1553 else 1553 else
1554 { 1554 {
1555 buf = Fget_buffer (build_local_string ("*scratch*")); 1555 buf = Fget_buffer (SCOPED_STRING ("*scratch*"));
1556 if (NILP (buf)) 1556 if (NILP (buf))
1557 { 1557 {
1558 buf = Fget_buffer_create (build_local_string ("*scratch*")); 1558 buf = Fget_buffer_create (SCOPED_STRING ("*scratch*"));
1559 Fset_buffer_major_mode (buf); 1559 Fset_buffer_major_mode (buf);
1560 } 1560 }
1561 return buf; 1561 return buf;
@@ -1575,10 +1575,10 @@ other_buffer_safely (Lisp_Object buffer)
1575 if (candidate_buffer (buf, buffer)) 1575 if (candidate_buffer (buf, buffer))
1576 return buf; 1576 return buf;
1577 1577
1578 buf = Fget_buffer (build_local_string ("*scratch*")); 1578 buf = Fget_buffer (SCOPED_STRING ("*scratch*"));
1579 if (NILP (buf)) 1579 if (NILP (buf))
1580 { 1580 {
1581 buf = Fget_buffer_create (build_local_string ("*scratch*")); 1581 buf = Fget_buffer_create (SCOPED_STRING ("*scratch*"));
1582 Fset_buffer_major_mode (buf); 1582 Fset_buffer_major_mode (buf);
1583 } 1583 }
1584 1584
@@ -5289,7 +5289,7 @@ init_buffer (int initialized)
5289 (void) initialized; 5289 (void) initialized;
5290#endif /* USE_MMAP_FOR_BUFFERS */ 5290#endif /* USE_MMAP_FOR_BUFFERS */
5291 5291
5292 Fset_buffer (Fget_buffer_create (build_local_string ("*scratch*"))); 5292 Fset_buffer (Fget_buffer_create (SCOPED_STRING ("*scratch*")));
5293 if (NILP (BVAR (&buffer_defaults, enable_multibyte_characters))) 5293 if (NILP (BVAR (&buffer_defaults, enable_multibyte_characters)))
5294 Fset_buffer_multibyte (Qnil); 5294 Fset_buffer_multibyte (Qnil);
5295 5295
@@ -5328,7 +5328,7 @@ init_buffer (int initialized)
5328 && strcmp ("/", SSDATA (BVAR (current_buffer, directory)))) 5328 && strcmp ("/", SSDATA (BVAR (current_buffer, directory))))
5329 bset_directory 5329 bset_directory
5330 (current_buffer, 5330 (current_buffer,
5331 concat2 (build_local_string ("/:"), BVAR (current_buffer, directory))); 5331 concat2 (SCOPED_STRING ("/:"), BVAR (current_buffer, directory)));
5332 5332
5333 temp = get_minibuffer (0); 5333 temp = get_minibuffer (0);
5334 bset_directory (XBUFFER (temp), BVAR (current_buffer, directory)); 5334 bset_directory (XBUFFER (temp), BVAR (current_buffer, directory));