diff options
| author | Paul Eggert | 2014-09-29 19:43:23 -0700 |
|---|---|---|
| committer | Paul Eggert | 2014-09-29 19:43:23 -0700 |
| commit | dc4525691c2c236abdb6c074438223413f80091c (patch) | |
| tree | 86305e7415bcf1b5cc6ddad6879e922f9e5e163c /src/fileio.c | |
| parent | a19f0977a96ee74b96410b41a8ea793c86f64b58 (diff) | |
| download | emacs-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/fileio.c')
| -rw-r--r-- | src/fileio.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/fileio.c b/src/fileio.c index 13e2c889020..2590942d42e 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -1111,7 +1111,7 @@ filesystem tree, not (expand-file-name ".." dirname). */) | |||
| 1111 | 1111 | ||
| 1112 | name = make_specified_string (nm, -1, p - nm, multibyte); | 1112 | name = make_specified_string (nm, -1, p - nm, multibyte); |
| 1113 | temp[0] = DRIVE_LETTER (drive); | 1113 | temp[0] = DRIVE_LETTER (drive); |
| 1114 | name = concat2 (build_local_string (temp), name); | 1114 | name = concat2 (SCOPED_STRING (temp), name); |
| 1115 | } | 1115 | } |
| 1116 | #ifdef WINDOWSNT | 1116 | #ifdef WINDOWSNT |
| 1117 | if (!NILP (Vw32_downcase_file_names)) | 1117 | if (!NILP (Vw32_downcase_file_names)) |
| @@ -1162,11 +1162,11 @@ filesystem tree, not (expand-file-name ".." dirname). */) | |||
| 1162 | char newdir_utf8[MAX_UTF8_PATH]; | 1162 | char newdir_utf8[MAX_UTF8_PATH]; |
| 1163 | 1163 | ||
| 1164 | filename_from_ansi (newdir, newdir_utf8); | 1164 | filename_from_ansi (newdir, newdir_utf8); |
| 1165 | tem = build_local_string (newdir_utf8); | 1165 | tem = build_string (newdir_utf8); |
| 1166 | } | 1166 | } |
| 1167 | else | 1167 | else |
| 1168 | #endif | 1168 | #endif |
| 1169 | tem = build_local_string (newdir); | 1169 | tem = build_string (newdir); |
| 1170 | newdirlim = newdir + SBYTES (tem); | 1170 | newdirlim = newdir + SBYTES (tem); |
| 1171 | if (multibyte && !STRING_MULTIBYTE (tem)) | 1171 | if (multibyte && !STRING_MULTIBYTE (tem)) |
| 1172 | { | 1172 | { |
| @@ -1198,7 +1198,7 @@ filesystem tree, not (expand-file-name ".." dirname). */) | |||
| 1198 | /* `getpwnam' may return a unibyte string, which will | 1198 | /* `getpwnam' may return a unibyte string, which will |
| 1199 | bite us since we expect the directory to be | 1199 | bite us since we expect the directory to be |
| 1200 | multibyte. */ | 1200 | multibyte. */ |
| 1201 | tem = build_local_string (newdir); | 1201 | tem = build_string (newdir); |
| 1202 | newdirlim = newdir + SBYTES (tem); | 1202 | newdirlim = newdir + SBYTES (tem); |
| 1203 | if (multibyte && !STRING_MULTIBYTE (tem)) | 1203 | if (multibyte && !STRING_MULTIBYTE (tem)) |
| 1204 | { | 1204 | { |
| @@ -1231,7 +1231,7 @@ filesystem tree, not (expand-file-name ".." dirname). */) | |||
| 1231 | adir = NULL; | 1231 | adir = NULL; |
| 1232 | else if (multibyte) | 1232 | else if (multibyte) |
| 1233 | { | 1233 | { |
| 1234 | Lisp_Object tem = build_local_string (adir); | 1234 | Lisp_Object tem = build_string (adir); |
| 1235 | 1235 | ||
| 1236 | tem = DECODE_FILE (tem); | 1236 | tem = DECODE_FILE (tem); |
| 1237 | newdirlim = adir + SBYTES (tem); | 1237 | newdirlim = adir + SBYTES (tem); |
| @@ -1334,7 +1334,7 @@ filesystem tree, not (expand-file-name ".." dirname). */) | |||
| 1334 | getcwd (adir, adir_size); | 1334 | getcwd (adir, adir_size); |
| 1335 | if (multibyte) | 1335 | if (multibyte) |
| 1336 | { | 1336 | { |
| 1337 | Lisp_Object tem = build_local_string (adir); | 1337 | Lisp_Object tem = build_string (adir); |
| 1338 | 1338 | ||
| 1339 | tem = DECODE_FILE (tem); | 1339 | tem = DECODE_FILE (tem); |
| 1340 | newdirlim = adir + SBYTES (tem); | 1340 | newdirlim = adir + SBYTES (tem); |
| @@ -5420,7 +5420,7 @@ auto_save_error (Lisp_Object error_val) | |||
| 5420 | ring_bell (XFRAME (selected_frame)); | 5420 | ring_bell (XFRAME (selected_frame)); |
| 5421 | 5421 | ||
| 5422 | msg = Fformat (3, ((Lisp_Object []) | 5422 | msg = Fformat (3, ((Lisp_Object []) |
| 5423 | { build_local_string ("Auto-saving %s: %s"), | 5423 | { SCOPED_STRING ("Auto-saving %s: %s"), |
| 5424 | BVAR (current_buffer, name), | 5424 | BVAR (current_buffer, name), |
| 5425 | Ferror_message_string (error_val) })); | 5425 | Ferror_message_string (error_val) })); |
| 5426 | GCPRO1 (msg); | 5426 | GCPRO1 (msg); |