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/process.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/process.c')
| -rw-r--r-- | src/process.c | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/src/process.c b/src/process.c index f6484d0370e..6d059af9cc8 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -620,7 +620,7 @@ status_message (struct Lisp_Process *p) | |||
| 620 | if (c1 != c2) | 620 | if (c1 != c2) |
| 621 | Faset (string, make_number (0), make_number (c2)); | 621 | Faset (string, make_number (0), make_number (c2)); |
| 622 | } | 622 | } |
| 623 | string2 = build_local_string (coredump ? " (core dumped)\n" : "\n"); | 623 | string2 = SCOPED_STRING (coredump ? " (core dumped)\n" : "\n"); |
| 624 | return concat2 (string, string2); | 624 | return concat2 (string, string2); |
| 625 | } | 625 | } |
| 626 | else if (EQ (symbol, Qexit)) | 626 | else if (EQ (symbol, Qexit)) |
| @@ -630,15 +630,15 @@ status_message (struct Lisp_Process *p) | |||
| 630 | if (code == 0) | 630 | if (code == 0) |
| 631 | return build_string ("finished\n"); | 631 | return build_string ("finished\n"); |
| 632 | string = Fnumber_to_string (make_number (code)); | 632 | string = Fnumber_to_string (make_number (code)); |
| 633 | string2 = build_local_string (coredump ? " (core dumped)\n" : "\n"); | 633 | string2 = SCOPED_STRING (coredump ? " (core dumped)\n" : "\n"); |
| 634 | return concat3 (build_local_string ("exited abnormally with code "), | 634 | return concat3 (SCOPED_STRING ("exited abnormally with code "), |
| 635 | string, string2); | 635 | string, string2); |
| 636 | } | 636 | } |
| 637 | else if (EQ (symbol, Qfailed)) | 637 | else if (EQ (symbol, Qfailed)) |
| 638 | { | 638 | { |
| 639 | string = Fnumber_to_string (make_number (code)); | 639 | string = Fnumber_to_string (make_number (code)); |
| 640 | string2 = build_local_string ("\n"); | 640 | string2 = SCOPED_STRING ("\n"); |
| 641 | return concat3 (build_local_string ("failed with code "), | 641 | return concat3 (SCOPED_STRING ("failed with code "), |
| 642 | string, string2); | 642 | string, string2); |
| 643 | } | 643 | } |
| 644 | else | 644 | else |
| @@ -1302,30 +1302,33 @@ Returns nil if format of ADDRESS is invalid. */) | |||
| 1302 | ptrdiff_t size = p->header.size; | 1302 | ptrdiff_t size = p->header.size; |
| 1303 | Lisp_Object args[10]; | 1303 | Lisp_Object args[10]; |
| 1304 | int nargs, i; | 1304 | int nargs, i; |
| 1305 | char const *format; | ||
| 1305 | 1306 | ||
| 1306 | if (size == 4 || (size == 5 && !NILP (omit_port))) | 1307 | if (size == 4 || (size == 5 && !NILP (omit_port))) |
| 1307 | { | 1308 | { |
| 1308 | args[0] = build_local_string ("%d.%d.%d.%d"); | 1309 | format = "%d.%d.%d.%d"; |
| 1309 | nargs = 4; | 1310 | nargs = 4; |
| 1310 | } | 1311 | } |
| 1311 | else if (size == 5) | 1312 | else if (size == 5) |
| 1312 | { | 1313 | { |
| 1313 | args[0] = build_local_string ("%d.%d.%d.%d:%d"); | 1314 | format = "%d.%d.%d.%d:%d"; |
| 1314 | nargs = 5; | 1315 | nargs = 5; |
| 1315 | } | 1316 | } |
| 1316 | else if (size == 8 || (size == 9 && !NILP (omit_port))) | 1317 | else if (size == 8 || (size == 9 && !NILP (omit_port))) |
| 1317 | { | 1318 | { |
| 1318 | args[0] = build_local_string ("%x:%x:%x:%x:%x:%x:%x:%x"); | 1319 | format = "%x:%x:%x:%x:%x:%x:%x:%x"; |
| 1319 | nargs = 8; | 1320 | nargs = 8; |
| 1320 | } | 1321 | } |
| 1321 | else if (size == 9) | 1322 | else if (size == 9) |
| 1322 | { | 1323 | { |
| 1323 | args[0] = build_local_string ("[%x:%x:%x:%x:%x:%x:%x:%x]:%d"); | 1324 | format = "[%x:%x:%x:%x:%x:%x:%x:%x]:%d"; |
| 1324 | nargs = 9; | 1325 | nargs = 9; |
| 1325 | } | 1326 | } |
| 1326 | else | 1327 | else |
| 1327 | return Qnil; | 1328 | return Qnil; |
| 1328 | 1329 | ||
| 1330 | args[0] = SCOPED_STRING (format); | ||
| 1331 | |||
| 1329 | for (i = 0; i < nargs; i++) | 1332 | for (i = 0; i < nargs; i++) |
| 1330 | { | 1333 | { |
| 1331 | if (! RANGED_INTEGERP (0, p->contents[i], 65535)) | 1334 | if (! RANGED_INTEGERP (0, p->contents[i], 65535)) |
| @@ -1344,7 +1347,7 @@ Returns nil if format of ADDRESS is invalid. */) | |||
| 1344 | 1347 | ||
| 1345 | if (CONSP (address)) | 1348 | if (CONSP (address)) |
| 1346 | return Fformat (2, ((Lisp_Object []) | 1349 | return Fformat (2, ((Lisp_Object []) |
| 1347 | { build_local_string ("<Family %d>"), Fcar (address) })); | 1350 | { SCOPED_STRING ("<Family %d>"), Fcar (address) })); |
| 1348 | 1351 | ||
| 1349 | return Qnil; | 1352 | return Qnil; |
| 1350 | } | 1353 | } |
| @@ -4060,11 +4063,11 @@ server_accept_connection (Lisp_Object server, int channel) | |||
| 4060 | unsigned char *ip = (unsigned char *)&saddr.in.sin_addr.s_addr; | 4063 | unsigned char *ip = (unsigned char *)&saddr.in.sin_addr.s_addr; |
| 4061 | 4064 | ||
| 4062 | host = Fformat (5, ((Lisp_Object []) | 4065 | host = Fformat (5, ((Lisp_Object []) |
| 4063 | { build_local_string ("%d.%d.%d.%d"), make_number (ip[0]), | 4066 | { SCOPED_STRING ("%d.%d.%d.%d"), make_number (ip[0]), |
| 4064 | make_number (ip[1]), make_number (ip[2]), make_number (ip[3]) })); | 4067 | make_number (ip[1]), make_number (ip[2]), make_number (ip[3]) })); |
| 4065 | service = make_number (ntohs (saddr.in.sin_port)); | 4068 | service = make_number (ntohs (saddr.in.sin_port)); |
| 4066 | caller = Fformat (3, ((Lisp_Object []) | 4069 | caller = Fformat (3, ((Lisp_Object []) |
| 4067 | { build_local_string (" <%s:%d>"), host, service })); | 4070 | { SCOPED_STRING (" <%s:%d>"), host, service })); |
| 4068 | } | 4071 | } |
| 4069 | break; | 4072 | break; |
| 4070 | 4073 | ||
| @@ -4075,13 +4078,13 @@ server_accept_connection (Lisp_Object server, int channel) | |||
| 4075 | uint16_t *ip6 = (uint16_t *)&saddr.in6.sin6_addr; | 4078 | uint16_t *ip6 = (uint16_t *)&saddr.in6.sin6_addr; |
| 4076 | int i; | 4079 | int i; |
| 4077 | 4080 | ||
| 4078 | args[0] = build_local_string ("%x:%x:%x:%x:%x:%x:%x:%x"); | 4081 | args[0] = SCOPED_STRING ("%x:%x:%x:%x:%x:%x:%x:%x"); |
| 4079 | for (i = 0; i < 8; i++) | 4082 | for (i = 0; i < 8; i++) |
| 4080 | args[i + 1] = make_number (ntohs (ip6[i])); | 4083 | args[i + 1] = make_number (ntohs (ip6[i])); |
| 4081 | host = Fformat (9, args); | 4084 | host = Fformat (9, args); |
| 4082 | service = make_number (ntohs (saddr.in.sin_port)); | 4085 | service = make_number (ntohs (saddr.in.sin_port)); |
| 4083 | caller = Fformat (3, ((Lisp_Object []) | 4086 | caller = Fformat (3, ((Lisp_Object []) |
| 4084 | { build_local_string (" <[%s]:%d>"), host, service })); | 4087 | { SCOPED_STRING (" <[%s]:%d>"), host, service })); |
| 4085 | } | 4088 | } |
| 4086 | break; | 4089 | break; |
| 4087 | #endif | 4090 | #endif |
| @@ -4092,7 +4095,7 @@ server_accept_connection (Lisp_Object server, int channel) | |||
| 4092 | default: | 4095 | default: |
| 4093 | caller = Fnumber_to_string (make_number (connect_counter)); | 4096 | caller = Fnumber_to_string (make_number (connect_counter)); |
| 4094 | caller = concat3 | 4097 | caller = concat3 |
| 4095 | (build_local_string (" <"), caller, build_local_string (">")); | 4098 | (SCOPED_STRING (" <"), caller, SCOPED_STRING (">")); |
| 4096 | break; | 4099 | break; |
| 4097 | } | 4100 | } |
| 4098 | 4101 | ||
| @@ -4191,14 +4194,14 @@ server_accept_connection (Lisp_Object server, int channel) | |||
| 4191 | 4194 | ||
| 4192 | if (!NILP (ps->log)) | 4195 | if (!NILP (ps->log)) |
| 4193 | call3 (ps->log, server, proc, | 4196 | call3 (ps->log, server, proc, |
| 4194 | concat3 (build_local_string ("accept from "), | 4197 | concat3 (SCOPED_STRING ("accept from "), |
| 4195 | (STRINGP (host) ? host : build_local_string ("-")), | 4198 | (STRINGP (host) ? host : SCOPED_STRING ("-")), |
| 4196 | build_local_string ("\n"))); | 4199 | SCOPED_STRING ("\n"))); |
| 4197 | 4200 | ||
| 4198 | exec_sentinel (proc, | 4201 | exec_sentinel (proc, |
| 4199 | concat3 (build_local_string ("open from "), | 4202 | concat3 (SCOPED_STRING ("open from "), |
| 4200 | (STRINGP (host) ? host : build_local_string ("-")), | 4203 | (STRINGP (host) ? host : SCOPED_STRING ("-")), |
| 4201 | build_local_string ("\n"))); | 4204 | SCOPED_STRING ("\n"))); |
| 4202 | } | 4205 | } |
| 4203 | 4206 | ||
| 4204 | /* This variable is different from waiting_for_input in keyboard.c. | 4207 | /* This variable is different from waiting_for_input in keyboard.c. |