aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2015-04-19 08:53:35 -0700
committerPaul Eggert2015-04-19 08:55:36 -0700
commit96bfe816d8107003dba7fd824c2ac2b999a84ae9 (patch)
tree515ecdd0b9cd007a7b1a16c09ff69b6a8f46cd84
parent65ac8bc6a9e256b60c8ddfa3c99a1b28145a0763 (diff)
downloademacs-96bfe816d8107003dba7fd824c2ac2b999a84ae9.tar.gz
emacs-96bfe816d8107003dba7fd824c2ac2b999a84ae9.zip
Refactor low-level printing for simplicity
* src/print.c (PRINTDECLARE): Remove. Move its contents into PRINTPREPARE; doable now that we assume C99. All callers changed. (PRINTCHAR): Remove, as it adds more mystery than clarity. All callers changed. (strout): Assume that caller computes length. All callers changed. (print_c_string): New function. (write_string, write_string_1): Compute length instead of asking the caller to compute it. All callers changed. (write_string): Simplify by using write_string_1. (write_string_1): Simplify by using print_c_string. (Fterpri): Compute default val more clearly. (Fprin1_to_string, print_object): Assume C99 to avoid unnecessary nesting. (print_object): Prefer print_c_string to multiple printchar, or to calling strout with -1 length. Coalesce into sprintf when this is easy.
-rw-r--r--src/eval.c10
-rw-r--r--src/lisp.h2
-rw-r--r--src/print.c470
3 files changed, 211 insertions, 271 deletions
diff --git a/src/eval.c b/src/eval.c
index 11d08895c37..490226149ff 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -3305,27 +3305,27 @@ Output stream used is value of `standard-output'. */)
3305 3305
3306 while (backtrace_p (pdl)) 3306 while (backtrace_p (pdl))
3307 { 3307 {
3308 write_string (backtrace_debug_on_exit (pdl) ? "* " : " ", 2); 3308 write_string (backtrace_debug_on_exit (pdl) ? "* " : " ");
3309 if (backtrace_nargs (pdl) == UNEVALLED) 3309 if (backtrace_nargs (pdl) == UNEVALLED)
3310 { 3310 {
3311 Fprin1 (Fcons (backtrace_function (pdl), *backtrace_args (pdl)), 3311 Fprin1 (Fcons (backtrace_function (pdl), *backtrace_args (pdl)),
3312 Qnil); 3312 Qnil);
3313 write_string ("\n", -1); 3313 write_string ("\n");
3314 } 3314 }
3315 else 3315 else
3316 { 3316 {
3317 tem = backtrace_function (pdl); 3317 tem = backtrace_function (pdl);
3318 Fprin1 (tem, Qnil); /* This can QUIT. */ 3318 Fprin1 (tem, Qnil); /* This can QUIT. */
3319 write_string ("(", -1); 3319 write_string ("(");
3320 { 3320 {
3321 ptrdiff_t i; 3321 ptrdiff_t i;
3322 for (i = 0; i < backtrace_nargs (pdl); i++) 3322 for (i = 0; i < backtrace_nargs (pdl); i++)
3323 { 3323 {
3324 if (i) write_string (" ", -1); 3324 if (i) write_string (" ");
3325 Fprin1 (backtrace_args (pdl)[i], Qnil); 3325 Fprin1 (backtrace_args (pdl)[i], Qnil);
3326 } 3326 }
3327 } 3327 }
3328 write_string (")\n", -1); 3328 write_string (")\n");
3329 } 3329 }
3330 pdl = backtrace_next (pdl); 3330 pdl = backtrace_next (pdl);
3331 } 3331 }
diff --git a/src/lisp.h b/src/lisp.h
index b730619726b..55c4c662c06 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -3923,7 +3923,7 @@ extern Lisp_Object Vprin1_to_string_buffer;
3923extern void debug_print (Lisp_Object) EXTERNALLY_VISIBLE; 3923extern void debug_print (Lisp_Object) EXTERNALLY_VISIBLE;
3924extern void temp_output_buffer_setup (const char *); 3924extern void temp_output_buffer_setup (const char *);
3925extern int print_level; 3925extern int print_level;
3926extern void write_string (const char *, int); 3926extern void write_string (const char *);
3927extern void print_error_message (Lisp_Object, Lisp_Object, const char *, 3927extern void print_error_message (Lisp_Object, Lisp_Object, const char *,
3928 Lisp_Object); 3928 Lisp_Object);
3929extern Lisp_Object internal_with_output_to_temp_buffer 3929extern Lisp_Object internal_with_output_to_temp_buffer
diff --git a/src/print.c b/src/print.c
index 58b9c706bae..916276bc961 100644
--- a/src/print.c
+++ b/src/print.c
@@ -83,12 +83,11 @@ bool print_output_debug_flag EXTERNALLY_VISIBLE = 1;
83 83
84/* Lisp functions to do output using a stream 84/* Lisp functions to do output using a stream
85 must have the stream in a variable called printcharfun 85 must have the stream in a variable called printcharfun
86 and must start with PRINTPREPARE, end with PRINTFINISH, 86 and must start with PRINTPREPARE, end with PRINTFINISH.
87 and use PRINTDECLARE to declare common variables. 87 Use printchar to output one character,
88 Use PRINTCHAR to output one character,
89 or call strout to output a block of characters. */ 88 or call strout to output a block of characters. */
90 89
91#define PRINTDECLARE \ 90#define PRINTPREPARE \
92 struct buffer *old = current_buffer; \ 91 struct buffer *old = current_buffer; \
93 ptrdiff_t old_point = -1, start_point = -1; \ 92 ptrdiff_t old_point = -1, start_point = -1; \
94 ptrdiff_t old_point_byte = -1, start_point_byte = -1; \ 93 ptrdiff_t old_point_byte = -1, start_point_byte = -1; \
@@ -96,10 +95,7 @@ bool print_output_debug_flag EXTERNALLY_VISIBLE = 1;
96 bool free_print_buffer = 0; \ 95 bool free_print_buffer = 0; \
97 bool multibyte \ 96 bool multibyte \
98 = !NILP (BVAR (current_buffer, enable_multibyte_characters)); \ 97 = !NILP (BVAR (current_buffer, enable_multibyte_characters)); \
99 Lisp_Object original 98 Lisp_Object original = printcharfun; \
100
101#define PRINTPREPARE \
102 original = printcharfun; \
103 if (NILP (printcharfun)) printcharfun = Qt; \ 99 if (NILP (printcharfun)) printcharfun = Qt; \
104 if (BUFFERP (printcharfun)) \ 100 if (BUFFERP (printcharfun)) \
105 { \ 101 { \
@@ -189,8 +185,6 @@ bool print_output_debug_flag EXTERNALLY_VISIBLE = 1;
189 ? PT_BYTE - start_point_byte : 0)); \ 185 ? PT_BYTE - start_point_byte : 0)); \
190 set_buffer_internal (old); 186 set_buffer_internal (old);
191 187
192#define PRINTCHAR(ch) printchar (ch, printcharfun)
193
194/* This is used to restore the saved contents of print_buffer 188/* This is used to restore the saved contents of print_buffer
195 when there is a recursive call to print. */ 189 when there is a recursive call to print. */
196 190
@@ -248,8 +242,7 @@ printchar (unsigned int ch, Lisp_Object fun)
248 242
249 243
250/* Output SIZE characters, SIZE_BYTE bytes from string PTR using 244/* Output SIZE characters, SIZE_BYTE bytes from string PTR using
251 method PRINTCHARFUN. If SIZE < 0, use the string length of PTR for 245 method PRINTCHARFUN. PRINTCHARFUN nil means output to
252 both SIZE and SIZE_BYTE. PRINTCHARFUN nil means output to
253 print_buffer. PRINTCHARFUN t means output to the echo area or to 246 print_buffer. PRINTCHARFUN t means output to the echo area or to
254 stdout if non-interactive. If neither nil nor t, call Lisp 247 stdout if non-interactive. If neither nil nor t, call Lisp
255 function PRINTCHARFUN for each character printed. MULTIBYTE 248 function PRINTCHARFUN for each character printed. MULTIBYTE
@@ -262,9 +255,6 @@ static void
262strout (const char *ptr, ptrdiff_t size, ptrdiff_t size_byte, 255strout (const char *ptr, ptrdiff_t size, ptrdiff_t size_byte,
263 Lisp_Object printcharfun) 256 Lisp_Object printcharfun)
264{ 257{
265 if (size < 0)
266 size_byte = size = strlen (ptr);
267
268 if (NILP (printcharfun)) 258 if (NILP (printcharfun))
269 { 259 {
270 ptrdiff_t incr = size_byte - (print_buffer_size - print_buffer_pos_byte); 260 ptrdiff_t incr = size_byte - (print_buffer_size - print_buffer_pos_byte);
@@ -317,7 +307,7 @@ strout (const char *ptr, ptrdiff_t size, ptrdiff_t size_byte,
317 while (i < size_byte) 307 while (i < size_byte)
318 { 308 {
319 int ch = ptr[i++]; 309 int ch = ptr[i++];
320 PRINTCHAR (ch); 310 printchar (ch, printcharfun);
321 } 311 }
322 } 312 }
323 else 313 else
@@ -330,7 +320,7 @@ strout (const char *ptr, ptrdiff_t size, ptrdiff_t size_byte,
330 int len; 320 int len;
331 int ch = STRING_CHAR_AND_LENGTH ((const unsigned char *) ptr + i, 321 int ch = STRING_CHAR_AND_LENGTH ((const unsigned char *) ptr + i,
332 len); 322 len);
333 PRINTCHAR (ch); 323 printchar (ch, printcharfun);
334 i += len; 324 i += len;
335 } 325 }
336 } 326 }
@@ -407,7 +397,7 @@ print_string (Lisp_Object string, Lisp_Object printcharfun)
407 GCPRO1 (string); 397 GCPRO1 (string);
408 if (size == size_byte) 398 if (size == size_byte)
409 for (i = 0; i < size; i++) 399 for (i = 0; i < size; i++)
410 PRINTCHAR (SREF (string, i)); 400 printchar (SREF (string, i), printcharfun);
411 else 401 else
412 for (i = 0; i < size_byte; ) 402 for (i = 0; i < size_byte; )
413 { 403 {
@@ -415,7 +405,7 @@ print_string (Lisp_Object string, Lisp_Object printcharfun)
415 corresponding character code before handing it to PRINTCHAR. */ 405 corresponding character code before handing it to PRINTCHAR. */
416 int len; 406 int len;
417 int ch = STRING_CHAR_AND_LENGTH (SDATA (string) + i, len); 407 int ch = STRING_CHAR_AND_LENGTH (SDATA (string) + i, len);
418 PRINTCHAR (ch); 408 printchar (ch, printcharfun);
419 i += len; 409 i += len;
420 } 410 }
421 UNGCPRO; 411 UNGCPRO;
@@ -427,46 +417,45 @@ DEFUN ("write-char", Fwrite_char, Swrite_char, 1, 2, 0,
427PRINTCHARFUN defaults to the value of `standard-output' (which see). */) 417PRINTCHARFUN defaults to the value of `standard-output' (which see). */)
428 (Lisp_Object character, Lisp_Object printcharfun) 418 (Lisp_Object character, Lisp_Object printcharfun)
429{ 419{
430 PRINTDECLARE;
431
432 if (NILP (printcharfun)) 420 if (NILP (printcharfun))
433 printcharfun = Vstandard_output; 421 printcharfun = Vstandard_output;
434 CHECK_NUMBER (character); 422 CHECK_NUMBER (character);
435 PRINTPREPARE; 423 PRINTPREPARE;
436 PRINTCHAR (XINT (character)); 424 printchar (XINT (character), printcharfun);
437 PRINTFINISH; 425 PRINTFINISH;
438 return character; 426 return character;
439} 427}
440 428
441/* Used from outside of print.c to print a block of SIZE 429/* Print the contents of a unibyte C string STRING using PRINTCHARFUN.
442 single-byte chars at DATA on the default output stream. 430 The caller should arrange to put this inside PRINTPREPARE and PRINTFINISH.
443 Do not use this on the contents of a Lisp string. */ 431 Do not use this on the contents of a Lisp string. */
444 432
445void 433static void
446write_string (const char *data, int size) 434print_c_string (char const *string, Lisp_Object printcharfun)
447{ 435{
448 PRINTDECLARE; 436 ptrdiff_t len = strlen (string);
449 Lisp_Object printcharfun; 437 strout (string, len, len, printcharfun);
438}
450 439
451 printcharfun = Vstandard_output; 440/* Print unibyte C string at DATA on a specified stream PRINTCHARFUN.
441 Do not use this on the contents of a Lisp string. */
452 442
443static void
444write_string_1 (const char *data, Lisp_Object printcharfun)
445{
453 PRINTPREPARE; 446 PRINTPREPARE;
454 strout (data, size, size, printcharfun); 447 print_c_string (data, printcharfun);
455 PRINTFINISH; 448 PRINTFINISH;
456} 449}
457 450
458/* Used to print a block of SIZE single-byte chars at DATA on a 451/* Used from outside of print.c to print a C unibyte
459 specified stream PRINTCHARFUN. 452 string at DATA on the default output stream.
460 Do not use this on the contents of a Lisp string. */ 453 Do not use this on the contents of a Lisp string. */
461 454
462static void 455void
463write_string_1 (const char *data, int size, Lisp_Object printcharfun) 456write_string (const char *data)
464{ 457{
465 PRINTDECLARE; 458 write_string_1 (data, Vstandard_output);
466
467 PRINTPREPARE;
468 strout (data, size, size, printcharfun);
469 PRINTFINISH;
470} 459}
471 460
472 461
@@ -515,9 +504,8 @@ beginning of a line. Value is non-nil if a newline is printed.
515If PRINTCHARFUN is omitted or nil, the value of `standard-output' is used. */) 504If PRINTCHARFUN is omitted or nil, the value of `standard-output' is used. */)
516 (Lisp_Object printcharfun, Lisp_Object ensure) 505 (Lisp_Object printcharfun, Lisp_Object ensure)
517{ 506{
518 Lisp_Object val = Qnil; 507 Lisp_Object val;
519 508
520 PRINTDECLARE;
521 if (NILP (printcharfun)) 509 if (NILP (printcharfun))
522 printcharfun = Vstandard_output; 510 printcharfun = Vstandard_output;
523 PRINTPREPARE; 511 PRINTPREPARE;
@@ -529,10 +517,11 @@ If PRINTCHARFUN is omitted or nil, the value of `standard-output' is used. */)
529 signal_error ("Unsupported function argument", printcharfun); 517 signal_error ("Unsupported function argument", printcharfun);
530 else if (noninteractive && !NILP (printcharfun)) 518 else if (noninteractive && !NILP (printcharfun))
531 val = printchar_stdout_last == 10 ? Qnil : Qt; 519 val = printchar_stdout_last == 10 ? Qnil : Qt;
532 else if (NILP (Fbolp ())) 520 else
533 val = Qt; 521 val = NILP (Fbolp ()) ? Qt : Qnil;
534 522
535 if (!NILP (val)) PRINTCHAR ('\n'); 523 if (!NILP (val))
524 printchar ('\n', printcharfun);
536 PRINTFINISH; 525 PRINTFINISH;
537 return val; 526 return val;
538} 527}
@@ -562,8 +551,6 @@ If PRINTCHARFUN is omitted, the value of `standard-output' (which see)
562is used instead. */) 551is used instead. */)
563 (Lisp_Object object, Lisp_Object printcharfun) 552 (Lisp_Object object, Lisp_Object printcharfun)
564{ 553{
565 PRINTDECLARE;
566
567 if (NILP (printcharfun)) 554 if (NILP (printcharfun))
568 printcharfun = Vstandard_output; 555 printcharfun = Vstandard_output;
569 PRINTPREPARE; 556 PRINTPREPARE;
@@ -588,32 +575,24 @@ a list, a buffer, a window, a frame, etc.
588A printed representation of an object is text which describes that object. */) 575A printed representation of an object is text which describes that object. */)
589 (Lisp_Object object, Lisp_Object noescape) 576 (Lisp_Object object, Lisp_Object noescape)
590{ 577{
591 Lisp_Object printcharfun;
592 bool prev_abort_on_gc;
593 Lisp_Object save_deactivate_mark;
594 ptrdiff_t count = SPECPDL_INDEX (); 578 ptrdiff_t count = SPECPDL_INDEX ();
595 struct buffer *previous;
596 579
597 specbind (Qinhibit_modification_hooks, Qt); 580 specbind (Qinhibit_modification_hooks, Qt);
598 581
599 { 582 /* Save and restore this: we are altering a buffer
600 PRINTDECLARE; 583 but we don't want to deactivate the mark just for that.
601 584 No need for specbind, since errors deactivate the mark. */
602 /* Save and restore this--we are altering a buffer 585 Lisp_Object save_deactivate_mark = Vdeactivate_mark;
603 but we don't want to deactivate the mark just for that. 586 bool prev_abort_on_gc = abort_on_gc;
604 No need for specbind, since errors deactivate the mark. */ 587 abort_on_gc = true;
605 save_deactivate_mark = Vdeactivate_mark;
606 prev_abort_on_gc = abort_on_gc;
607 abort_on_gc = 1;
608
609 printcharfun = Vprin1_to_string_buffer;
610 PRINTPREPARE;
611 print (object, printcharfun, NILP (noescape));
612 /* Make Vprin1_to_string_buffer be the default buffer after PRINTFINISH */
613 PRINTFINISH;
614 }
615 588
616 previous = current_buffer; 589 Lisp_Object printcharfun = Vprin1_to_string_buffer;
590 PRINTPREPARE;
591 print (object, printcharfun, NILP (noescape));
592 /* Make Vprin1_to_string_buffer be the default buffer after PRINTFINISH */
593 PRINTFINISH;
594
595 struct buffer *previous = current_buffer;
617 set_buffer_internal (XBUFFER (Vprin1_to_string_buffer)); 596 set_buffer_internal (XBUFFER (Vprin1_to_string_buffer));
618 object = Fbuffer_string (); 597 object = Fbuffer_string ();
619 if (SBYTES (object) == SCHARS (object)) 598 if (SBYTES (object) == SCHARS (object))
@@ -655,8 +634,6 @@ If PRINTCHARFUN is omitted, the value of `standard-output' (which see)
655is used instead. */) 634is used instead. */)
656 (Lisp_Object object, Lisp_Object printcharfun) 635 (Lisp_Object object, Lisp_Object printcharfun)
657{ 636{
658 PRINTDECLARE;
659
660 if (NILP (printcharfun)) 637 if (NILP (printcharfun))
661 printcharfun = Vstandard_output; 638 printcharfun = Vstandard_output;
662 PRINTPREPARE; 639 PRINTPREPARE;
@@ -690,16 +667,15 @@ If PRINTCHARFUN is omitted, the value of `standard-output' (which see)
690is used instead. */) 667is used instead. */)
691 (Lisp_Object object, Lisp_Object printcharfun) 668 (Lisp_Object object, Lisp_Object printcharfun)
692{ 669{
693 PRINTDECLARE;
694 struct gcpro gcpro1; 670 struct gcpro gcpro1;
695 671
696 if (NILP (printcharfun)) 672 if (NILP (printcharfun))
697 printcharfun = Vstandard_output; 673 printcharfun = Vstandard_output;
698 GCPRO1 (object); 674 GCPRO1 (object);
699 PRINTPREPARE; 675 PRINTPREPARE;
700 PRINTCHAR ('\n'); 676 printchar ('\n', printcharfun);
701 print (object, printcharfun, 1); 677 print (object, printcharfun, 1);
702 PRINTCHAR ('\n'); 678 printchar ('\n', printcharfun);
703 PRINTFINISH; 679 PRINTFINISH;
704 UNGCPRO; 680 UNGCPRO;
705 return object; 681 return object;
@@ -869,7 +845,7 @@ print_error_message (Lisp_Object data, Lisp_Object stream, const char *context,
869 struct gcpro gcpro1; 845 struct gcpro gcpro1;
870 846
871 if (context != 0) 847 if (context != 0)
872 write_string_1 (context, -1, stream); 848 write_string_1 (context, stream);
873 849
874 /* If we know from where the error was signaled, show it in 850 /* If we know from where the error was signaled, show it in
875 *Messages*. */ 851 *Messages*. */
@@ -916,7 +892,7 @@ print_error_message (Lisp_Object data, Lisp_Object stream, const char *context,
916 const char *sep = ": "; 892 const char *sep = ": ";
917 893
918 if (!STRINGP (errmsg)) 894 if (!STRINGP (errmsg))
919 write_string_1 ("peculiar error", -1, stream); 895 write_string_1 ("peculiar error", stream);
920 else if (SCHARS (errmsg)) 896 else if (SCHARS (errmsg))
921 Fprinc (errmsg, stream); 897 Fprinc (errmsg, stream);
922 else 898 else
@@ -927,7 +903,7 @@ print_error_message (Lisp_Object data, Lisp_Object stream, const char *context,
927 Lisp_Object obj; 903 Lisp_Object obj;
928 904
929 if (sep) 905 if (sep)
930 write_string_1 (sep, 2, stream); 906 write_string_1 (sep, stream);
931 obj = XCAR (tail); 907 obj = XCAR (tail);
932 if (!NILP (file_error) 908 if (!NILP (file_error)
933 || EQ (errname, Qend_of_file) || EQ (errname, Quser_error)) 909 || EQ (errname, Qend_of_file) || EQ (errname, Quser_error))
@@ -1420,18 +1396,15 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
1420 obj = print_prune_string_charset (obj); 1396 obj = print_prune_string_charset (obj);
1421 1397
1422 if (string_intervals (obj)) 1398 if (string_intervals (obj))
1423 { 1399 print_c_string ("#(", printcharfun);
1424 PRINTCHAR ('#');
1425 PRINTCHAR ('(');
1426 }
1427 1400
1428 PRINTCHAR ('\"'); 1401 printchar ('\"', printcharfun);
1429 size_byte = SBYTES (obj); 1402 size_byte = SBYTES (obj);
1430 1403
1431 for (i = 0, i_byte = 0; i_byte < size_byte;) 1404 for (i = 0, i_byte = 0; i_byte < size_byte;)
1432 { 1405 {
1433 /* Here, we must convert each multi-byte form to the 1406 /* Here, we must convert each multi-byte form to the
1434 corresponding character code before handing it to PRINTCHAR. */ 1407 corresponding character code before handing it to printchar. */
1435 int c; 1408 int c;
1436 1409
1437 FETCH_STRING_CHAR_ADVANCE (c, obj, i, i_byte); 1410 FETCH_STRING_CHAR_ADVANCE (c, obj, i, i_byte);
@@ -1439,15 +1412,9 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
1439 QUIT; 1412 QUIT;
1440 1413
1441 if (c == '\n' && print_escape_newlines) 1414 if (c == '\n' && print_escape_newlines)
1442 { 1415 print_c_string ("\\n", printcharfun);
1443 PRINTCHAR ('\\');
1444 PRINTCHAR ('n');
1445 }
1446 else if (c == '\f' && print_escape_newlines) 1416 else if (c == '\f' && print_escape_newlines)
1447 { 1417 print_c_string ("\\f", printcharfun);
1448 PRINTCHAR ('\\');
1449 PRINTCHAR ('f');
1450 }
1451 else if (multibyte 1418 else if (multibyte
1452 && (CHAR_BYTE8_P (c) 1419 && (CHAR_BYTE8_P (c)
1453 || (! ASCII_CHAR_P (c) && print_escape_multibyte))) 1420 || (! ASCII_CHAR_P (c) && print_escape_multibyte)))
@@ -1492,21 +1459,21 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
1492 if ((c >= 'a' && c <= 'f') 1459 if ((c >= 'a' && c <= 'f')
1493 || (c >= 'A' && c <= 'F') 1460 || (c >= 'A' && c <= 'F')
1494 || (c >= '0' && c <= '9')) 1461 || (c >= '0' && c <= '9'))
1495 strout ("\\ ", -1, -1, printcharfun); 1462 print_c_string ("\\ ", printcharfun);
1496 } 1463 }
1497 1464
1498 if (c == '\"' || c == '\\') 1465 if (c == '\"' || c == '\\')
1499 PRINTCHAR ('\\'); 1466 printchar ('\\', printcharfun);
1500 PRINTCHAR (c); 1467 printchar (c, printcharfun);
1501 } 1468 }
1502 } 1469 }
1503 PRINTCHAR ('\"'); 1470 printchar ('\"', printcharfun);
1504 1471
1505 if (string_intervals (obj)) 1472 if (string_intervals (obj))
1506 { 1473 {
1507 traverse_intervals (string_intervals (obj), 1474 traverse_intervals (string_intervals (obj),
1508 0, print_interval, printcharfun); 1475 0, print_interval, printcharfun);
1509 PRINTCHAR (')'); 1476 printchar (')', printcharfun);
1510 } 1477 }
1511 1478
1512 UNGCPRO; 1479 UNGCPRO;
@@ -1550,14 +1517,10 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
1550 size_byte = SBYTES (name); 1517 size_byte = SBYTES (name);
1551 1518
1552 if (! NILP (Vprint_gensym) && !SYMBOL_INTERNED_P (obj)) 1519 if (! NILP (Vprint_gensym) && !SYMBOL_INTERNED_P (obj))
1553 { 1520 print_c_string ("#:", printcharfun);
1554 PRINTCHAR ('#');
1555 PRINTCHAR (':');
1556 }
1557 else if (size_byte == 0) 1521 else if (size_byte == 0)
1558 { 1522 {
1559 PRINTCHAR ('#'); 1523 print_c_string ("##", printcharfun);
1560 PRINTCHAR ('#');
1561 break; 1524 break;
1562 } 1525 }
1563 1526
@@ -1575,9 +1538,12 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
1575 || c == ',' || c == '.' || c == '`' 1538 || c == ',' || c == '.' || c == '`'
1576 || c == '[' || c == ']' || c == '?' || c <= 040 1539 || c == '[' || c == ']' || c == '?' || c <= 040
1577 || confusing) 1540 || confusing)
1578 PRINTCHAR ('\\'), confusing = 0; 1541 {
1542 printchar ('\\', printcharfun);
1543 confusing = false;
1544 }
1579 } 1545 }
1580 PRINTCHAR (c); 1546 printchar (c, printcharfun);
1581 } 1547 }
1582 } 1548 }
1583 break; 1549 break;
@@ -1586,18 +1552,17 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
1586 /* If deeper than spec'd depth, print placeholder. */ 1552 /* If deeper than spec'd depth, print placeholder. */
1587 if (INTEGERP (Vprint_level) 1553 if (INTEGERP (Vprint_level)
1588 && print_depth > XINT (Vprint_level)) 1554 && print_depth > XINT (Vprint_level))
1589 strout ("...", -1, -1, printcharfun); 1555 print_c_string ("...", printcharfun);
1590 else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj))) 1556 else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj)))
1591 && (EQ (XCAR (obj), Qquote))) 1557 && (EQ (XCAR (obj), Qquote)))
1592 { 1558 {
1593 PRINTCHAR ('\''); 1559 printchar ('\'', printcharfun);
1594 print_object (XCAR (XCDR (obj)), printcharfun, escapeflag); 1560 print_object (XCAR (XCDR (obj)), printcharfun, escapeflag);
1595 } 1561 }
1596 else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj))) 1562 else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj)))
1597 && (EQ (XCAR (obj), Qfunction))) 1563 && (EQ (XCAR (obj), Qfunction)))
1598 { 1564 {
1599 PRINTCHAR ('#'); 1565 print_c_string ("#'", printcharfun);
1600 PRINTCHAR ('\'');
1601 print_object (XCAR (XCDR (obj)), printcharfun, escapeflag); 1566 print_object (XCAR (XCDR (obj)), printcharfun, escapeflag);
1602 } 1567 }
1603 else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj))) 1568 else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj)))
@@ -1622,75 +1587,71 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
1622 } 1587 }
1623 else 1588 else
1624 { 1589 {
1625 PRINTCHAR ('('); 1590 printchar ('(', printcharfun);
1626 1591
1627 { 1592 Lisp_Object halftail = obj;
1628 printmax_t i, print_length;
1629 Lisp_Object halftail = obj;
1630 1593
1631 /* Negative values of print-length are invalid in CL. 1594 /* Negative values of print-length are invalid in CL.
1632 Treat them like nil, as CMUCL does. */ 1595 Treat them like nil, as CMUCL does. */
1633 if (NATNUMP (Vprint_length)) 1596 printmax_t print_length = (NATNUMP (Vprint_length)
1634 print_length = XFASTINT (Vprint_length); 1597 ? XFASTINT (Vprint_length)
1635 else 1598 : TYPE_MAXIMUM (printmax_t));
1636 print_length = TYPE_MAXIMUM (printmax_t);
1637 1599
1638 i = 0; 1600 printmax_t i = 0;
1639 while (CONSP (obj)) 1601 while (CONSP (obj))
1640 { 1602 {
1641 /* Detect circular list. */ 1603 /* Detect circular list. */
1642 if (NILP (Vprint_circle)) 1604 if (NILP (Vprint_circle))
1643 { 1605 {
1644 /* Simple but incomplete way. */ 1606 /* Simple but incomplete way. */
1645 if (i != 0 && EQ (obj, halftail)) 1607 if (i != 0 && EQ (obj, halftail))
1646 { 1608 {
1647 int len = sprintf (buf, " . #%"pMd, i / 2); 1609 int len = sprintf (buf, " . #%"pMd, i / 2);
1648 strout (buf, len, len, printcharfun); 1610 strout (buf, len, len, printcharfun);
1649 goto end_of_list; 1611 goto end_of_list;
1650 } 1612 }
1651 } 1613 }
1652 else 1614 else
1653 { 1615 {
1654 /* With the print-circle feature. */ 1616 /* With the print-circle feature. */
1655 if (i != 0) 1617 if (i != 0)
1656 { 1618 {
1657 Lisp_Object num = Fgethash (obj, Vprint_number_table, Qnil); 1619 Lisp_Object num = Fgethash (obj, Vprint_number_table, Qnil);
1658 if (INTEGERP (num)) 1620 if (INTEGERP (num))
1659 { 1621 {
1660 strout (" . ", 3, 3, printcharfun); 1622 print_c_string (" . ", printcharfun);
1661 print_object (obj, printcharfun, escapeflag); 1623 print_object (obj, printcharfun, escapeflag);
1662 goto end_of_list; 1624 goto end_of_list;
1663 } 1625 }
1664 } 1626 }
1665 } 1627 }
1666 1628
1667 if (i) 1629 if (i)
1668 PRINTCHAR (' '); 1630 printchar (' ', printcharfun);
1669 1631
1670 if (print_length <= i) 1632 if (print_length <= i)
1671 { 1633 {
1672 strout ("...", 3, 3, printcharfun); 1634 print_c_string ("...", printcharfun);
1673 goto end_of_list; 1635 goto end_of_list;
1674 } 1636 }
1675 1637
1676 i++; 1638 i++;
1677 print_object (XCAR (obj), printcharfun, escapeflag); 1639 print_object (XCAR (obj), printcharfun, escapeflag);
1678 1640
1679 obj = XCDR (obj); 1641 obj = XCDR (obj);
1680 if (!(i & 1)) 1642 if (!(i & 1))
1681 halftail = XCDR (halftail); 1643 halftail = XCDR (halftail);
1682 }
1683 } 1644 }
1684 1645
1685 /* OBJ non-nil here means it's the end of a dotted list. */ 1646 /* OBJ non-nil here means it's the end of a dotted list. */
1686 if (!NILP (obj)) 1647 if (!NILP (obj))
1687 { 1648 {
1688 strout (" . ", 3, 3, printcharfun); 1649 print_c_string (" . ", printcharfun);
1689 print_object (obj, printcharfun, escapeflag); 1650 print_object (obj, printcharfun, escapeflag);
1690 } 1651 }
1691 1652
1692 end_of_list: 1653 end_of_list:
1693 PRINTCHAR (')'); 1654 printchar (')', printcharfun);
1694 } 1655 }
1695 break; 1656 break;
1696 1657
@@ -1699,9 +1660,9 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
1699 { 1660 {
1700 if (escapeflag) 1661 if (escapeflag)
1701 { 1662 {
1702 strout ("#<process ", -1, -1, printcharfun); 1663 print_c_string ("#<process ", printcharfun);
1703 print_string (XPROCESS (obj)->name, printcharfun); 1664 print_string (XPROCESS (obj)->name, printcharfun);
1704 PRINTCHAR ('>'); 1665 printchar ('>', printcharfun);
1705 } 1666 }
1706 else 1667 else
1707 print_string (XPROCESS (obj)->name, printcharfun); 1668 print_string (XPROCESS (obj)->name, printcharfun);
@@ -1709,7 +1670,6 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
1709 else if (BOOL_VECTOR_P (obj)) 1670 else if (BOOL_VECTOR_P (obj))
1710 { 1671 {
1711 ptrdiff_t i; 1672 ptrdiff_t i;
1712 int len;
1713 unsigned char c; 1673 unsigned char c;
1714 struct gcpro gcpro1; 1674 struct gcpro gcpro1;
1715 EMACS_INT size = bool_vector_size (obj); 1675 EMACS_INT size = bool_vector_size (obj);
@@ -1717,11 +1677,8 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
1717 ptrdiff_t real_size_in_chars = size_in_chars; 1677 ptrdiff_t real_size_in_chars = size_in_chars;
1718 GCPRO1 (obj); 1678 GCPRO1 (obj);
1719 1679
1720 PRINTCHAR ('#'); 1680 int len = sprintf (buf, "#&%"pI"d\"", size);
1721 PRINTCHAR ('&');
1722 len = sprintf (buf, "%"pI"d", size);
1723 strout (buf, len, len, printcharfun); 1681 strout (buf, len, len, printcharfun);
1724 PRINTCHAR ('\"');
1725 1682
1726 /* Don't print more characters than the specified maximum. 1683 /* Don't print more characters than the specified maximum.
1727 Negative values of print-length are invalid. Treat them 1684 Negative values of print-length are invalid. Treat them
@@ -1735,42 +1692,34 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
1735 QUIT; 1692 QUIT;
1736 c = bool_vector_uchar_data (obj)[i]; 1693 c = bool_vector_uchar_data (obj)[i];
1737 if (c == '\n' && print_escape_newlines) 1694 if (c == '\n' && print_escape_newlines)
1738 { 1695 print_c_string ("\\n", printcharfun);
1739 PRINTCHAR ('\\');
1740 PRINTCHAR ('n');
1741 }
1742 else if (c == '\f' && print_escape_newlines) 1696 else if (c == '\f' && print_escape_newlines)
1743 { 1697 print_c_string ("\\f", printcharfun);
1744 PRINTCHAR ('\\');
1745 PRINTCHAR ('f');
1746 }
1747 else if (c > '\177') 1698 else if (c > '\177')
1748 { 1699 {
1749 /* Use octal escapes to avoid encoding issues. */ 1700 /* Use octal escapes to avoid encoding issues. */
1750 PRINTCHAR ('\\'); 1701 len = sprintf (buf, "\\%o", c);
1751 PRINTCHAR ('0' + ((c >> 6) & 3)); 1702 strout (buf, len, len, printcharfun);
1752 PRINTCHAR ('0' + ((c >> 3) & 7));
1753 PRINTCHAR ('0' + (c & 7));
1754 } 1703 }
1755 else 1704 else
1756 { 1705 {
1757 if (c == '\"' || c == '\\') 1706 if (c == '\"' || c == '\\')
1758 PRINTCHAR ('\\'); 1707 printchar ('\\', printcharfun);
1759 PRINTCHAR (c); 1708 printchar (c, printcharfun);
1760 } 1709 }
1761 } 1710 }
1762 1711
1763 if (size_in_chars < real_size_in_chars) 1712 if (size_in_chars < real_size_in_chars)
1764 strout (" ...", 4, 4, printcharfun); 1713 print_c_string (" ...", printcharfun);
1765 PRINTCHAR ('\"'); 1714 printchar ('\"', printcharfun);
1766 1715
1767 UNGCPRO; 1716 UNGCPRO;
1768 } 1717 }
1769 else if (SUBRP (obj)) 1718 else if (SUBRP (obj))
1770 { 1719 {
1771 strout ("#<subr ", -1, -1, printcharfun); 1720 print_c_string ("#<subr ", printcharfun);
1772 strout (XSUBR (obj)->symbol_name, -1, -1, printcharfun); 1721 print_c_string (XSUBR (obj)->symbol_name, printcharfun);
1773 PRINTCHAR ('>'); 1722 printchar ('>', printcharfun);
1774 } 1723 }
1775 else if (WINDOWP (obj)) 1724 else if (WINDOWP (obj))
1776 { 1725 {
@@ -1779,25 +1728,23 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
1779 strout (buf, len, len, printcharfun); 1728 strout (buf, len, len, printcharfun);
1780 if (BUFFERP (XWINDOW (obj)->contents)) 1729 if (BUFFERP (XWINDOW (obj)->contents))
1781 { 1730 {
1782 strout (" on ", -1, -1, printcharfun); 1731 print_c_string (" on ", printcharfun);
1783 print_string (BVAR (XBUFFER (XWINDOW (obj)->contents), name), 1732 print_string (BVAR (XBUFFER (XWINDOW (obj)->contents), name),
1784 printcharfun); 1733 printcharfun);
1785 } 1734 }
1786 PRINTCHAR ('>'); 1735 printchar ('>', printcharfun);
1787 } 1736 }
1788 else if (TERMINALP (obj)) 1737 else if (TERMINALP (obj))
1789 { 1738 {
1790 int len;
1791 struct terminal *t = XTERMINAL (obj); 1739 struct terminal *t = XTERMINAL (obj);
1792 strout ("#<terminal ", -1, -1, printcharfun); 1740 int len = sprintf (buf, "#<terminal %d", t->id);
1793 len = sprintf (buf, "%d", t->id);
1794 strout (buf, len, len, printcharfun); 1741 strout (buf, len, len, printcharfun);
1795 if (t->name) 1742 if (t->name)
1796 { 1743 {
1797 strout (" on ", -1, -1, printcharfun); 1744 print_c_string (" on ", printcharfun);
1798 strout (t->name, -1, -1, printcharfun); 1745 print_c_string (t->name, printcharfun);
1799 } 1746 }
1800 PRINTCHAR ('>'); 1747 printchar ('>', printcharfun);
1801 } 1748 }
1802 else if (HASH_TABLE_P (obj)) 1749 else if (HASH_TABLE_P (obj))
1803 { 1750 {
@@ -1807,16 +1754,14 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
1807 int len; 1754 int len;
1808#if 0 1755#if 0
1809 void *ptr = h; 1756 void *ptr = h;
1810 strout ("#<hash-table", -1, -1, printcharfun); 1757 print_c_string ("#<hash-table", printcharfun);
1811 if (SYMBOLP (h->test)) 1758 if (SYMBOLP (h->test))
1812 { 1759 {
1813 PRINTCHAR (' '); 1760 print_c_string (" '", printcharfun);
1814 PRINTCHAR ('\''); 1761 print_c_string (SSDATA (SYMBOL_NAME (h->test)), printcharfun);
1815 strout (SDATA (SYMBOL_NAME (h->test)), -1, -1, printcharfun); 1762 printchar (' ', printcharfun);
1816 PRINTCHAR (' '); 1763 print_c_string (SSDATA (SYMBOL_NAME (h->weak)), printcharfun);
1817 strout (SDATA (SYMBOL_NAME (h->weak)), -1, -1, printcharfun); 1764 len = sprintf (buf, " %"pD"d/%"pD"d", h->count, ASIZE (h->next));
1818 PRINTCHAR (' ');
1819 len = sprintf (buf, "%"pD"d/%"pD"d", h->count, ASIZE (h->next));
1820 strout (buf, len, len, printcharfun); 1765 strout (buf, len, len, printcharfun);
1821 } 1766 }
1822 len = sprintf (buf, " %p>", ptr); 1767 len = sprintf (buf, " %p>", ptr);
@@ -1830,29 +1775,29 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
1830 1775
1831 if (!NILP (h->test.name)) 1776 if (!NILP (h->test.name))
1832 { 1777 {
1833 strout (" test ", -1, -1, printcharfun); 1778 print_c_string (" test ", printcharfun);
1834 print_object (h->test.name, printcharfun, escapeflag); 1779 print_object (h->test.name, printcharfun, escapeflag);
1835 } 1780 }
1836 1781
1837 if (!NILP (h->weak)) 1782 if (!NILP (h->weak))
1838 { 1783 {
1839 strout (" weakness ", -1, -1, printcharfun); 1784 print_c_string (" weakness ", printcharfun);
1840 print_object (h->weak, printcharfun, escapeflag); 1785 print_object (h->weak, printcharfun, escapeflag);
1841 } 1786 }
1842 1787
1843 if (!NILP (h->rehash_size)) 1788 if (!NILP (h->rehash_size))
1844 { 1789 {
1845 strout (" rehash-size ", -1, -1, printcharfun); 1790 print_c_string (" rehash-size ", printcharfun);
1846 print_object (h->rehash_size, printcharfun, escapeflag); 1791 print_object (h->rehash_size, printcharfun, escapeflag);
1847 } 1792 }
1848 1793
1849 if (!NILP (h->rehash_threshold)) 1794 if (!NILP (h->rehash_threshold))
1850 { 1795 {
1851 strout (" rehash-threshold ", -1, -1, printcharfun); 1796 print_c_string (" rehash-threshold ", printcharfun);
1852 print_object (h->rehash_threshold, printcharfun, escapeflag); 1797 print_object (h->rehash_threshold, printcharfun, escapeflag);
1853 } 1798 }
1854 1799
1855 strout (" data ", -1, -1, printcharfun); 1800 print_c_string (" data ", printcharfun);
1856 1801
1857 /* Print the data here as a plist. */ 1802 /* Print the data here as a plist. */
1858 real_size = HASH_TABLE_SIZE (h); 1803 real_size = HASH_TABLE_SIZE (h);
@@ -1863,49 +1808,47 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
1863 && XFASTINT (Vprint_length) < size) 1808 && XFASTINT (Vprint_length) < size)
1864 size = XFASTINT (Vprint_length); 1809 size = XFASTINT (Vprint_length);
1865 1810
1866 PRINTCHAR ('('); 1811 printchar ('(', printcharfun);
1867 for (i = 0; i < size; i++) 1812 for (i = 0; i < size; i++)
1868 if (!NILP (HASH_HASH (h, i))) 1813 if (!NILP (HASH_HASH (h, i)))
1869 { 1814 {
1870 if (i) PRINTCHAR (' '); 1815 if (i) printchar (' ', printcharfun);
1871 print_object (HASH_KEY (h, i), printcharfun, escapeflag); 1816 print_object (HASH_KEY (h, i), printcharfun, escapeflag);
1872 PRINTCHAR (' '); 1817 printchar (' ', printcharfun);
1873 print_object (HASH_VALUE (h, i), printcharfun, escapeflag); 1818 print_object (HASH_VALUE (h, i), printcharfun, escapeflag);
1874 } 1819 }
1875 1820
1876 if (size < real_size) 1821 if (size < real_size)
1877 strout (" ...", 4, 4, printcharfun); 1822 print_c_string (" ...", printcharfun);
1878 1823
1879 PRINTCHAR (')'); 1824 print_c_string ("))", printcharfun);
1880 PRINTCHAR (')');
1881 1825
1882 } 1826 }
1883 else if (BUFFERP (obj)) 1827 else if (BUFFERP (obj))
1884 { 1828 {
1885 if (!BUFFER_LIVE_P (XBUFFER (obj))) 1829 if (!BUFFER_LIVE_P (XBUFFER (obj)))
1886 strout ("#<killed buffer>", -1, -1, printcharfun); 1830 print_c_string ("#<killed buffer>", printcharfun);
1887 else if (escapeflag) 1831 else if (escapeflag)
1888 { 1832 {
1889 strout ("#<buffer ", -1, -1, printcharfun); 1833 print_c_string ("#<buffer ", printcharfun);
1890 print_string (BVAR (XBUFFER (obj), name), printcharfun); 1834 print_string (BVAR (XBUFFER (obj), name), printcharfun);
1891 PRINTCHAR ('>'); 1835 printchar ('>', printcharfun);
1892 } 1836 }
1893 else 1837 else
1894 print_string (BVAR (XBUFFER (obj), name), printcharfun); 1838 print_string (BVAR (XBUFFER (obj), name), printcharfun);
1895 } 1839 }
1896 else if (WINDOW_CONFIGURATIONP (obj)) 1840 else if (WINDOW_CONFIGURATIONP (obj))
1897 { 1841 print_c_string ("#<window-configuration>", printcharfun);
1898 strout ("#<window-configuration>", -1, -1, printcharfun);
1899 }
1900 else if (FRAMEP (obj)) 1842 else if (FRAMEP (obj))
1901 { 1843 {
1902 int len; 1844 int len;
1903 void *ptr = XFRAME (obj); 1845 void *ptr = XFRAME (obj);
1904 Lisp_Object frame_name = XFRAME (obj)->name; 1846 Lisp_Object frame_name = XFRAME (obj)->name;
1905 1847
1906 strout ((FRAME_LIVE_P (XFRAME (obj)) 1848 print_c_string ((FRAME_LIVE_P (XFRAME (obj))
1907 ? "#<frame " : "#<dead frame "), 1849 ? "#<frame "
1908 -1, -1, printcharfun); 1850 : "#<dead frame "),
1851 printcharfun);
1909 if (!STRINGP (frame_name)) 1852 if (!STRINGP (frame_name))
1910 { 1853 {
1911 /* A frame could be too young and have no name yet; 1854 /* A frame could be too young and have no name yet;
@@ -1926,12 +1869,12 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
1926 if (! FONT_OBJECT_P (obj)) 1869 if (! FONT_OBJECT_P (obj))
1927 { 1870 {
1928 if (FONT_SPEC_P (obj)) 1871 if (FONT_SPEC_P (obj))
1929 strout ("#<font-spec", -1, -1, printcharfun); 1872 print_c_string ("#<font-spec", printcharfun);
1930 else 1873 else
1931 strout ("#<font-entity", -1, -1, printcharfun); 1874 print_c_string ("#<font-entity", printcharfun);
1932 for (i = 0; i < FONT_SPEC_MAX; i++) 1875 for (i = 0; i < FONT_SPEC_MAX; i++)
1933 { 1876 {
1934 PRINTCHAR (' '); 1877 printchar (' ', printcharfun);
1935 if (i < FONT_WEIGHT_INDEX || i > FONT_WIDTH_INDEX) 1878 if (i < FONT_WEIGHT_INDEX || i > FONT_WIDTH_INDEX)
1936 print_object (AREF (obj, i), printcharfun, escapeflag); 1879 print_object (AREF (obj, i), printcharfun, escapeflag);
1937 else 1880 else
@@ -1941,18 +1884,18 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
1941 } 1884 }
1942 else 1885 else
1943 { 1886 {
1944 strout ("#<font-object ", -1, -1, printcharfun); 1887 print_c_string ("#<font-object ", printcharfun);
1945 print_object (AREF (obj, FONT_NAME_INDEX), printcharfun, 1888 print_object (AREF (obj, FONT_NAME_INDEX), printcharfun,
1946 escapeflag); 1889 escapeflag);
1947 } 1890 }
1948 PRINTCHAR ('>'); 1891 printchar ('>', printcharfun);
1949 } 1892 }
1950 else 1893 else
1951 { 1894 {
1952 ptrdiff_t size = ASIZE (obj); 1895 ptrdiff_t size = ASIZE (obj);
1953 if (COMPILEDP (obj)) 1896 if (COMPILEDP (obj))
1954 { 1897 {
1955 PRINTCHAR ('#'); 1898 printchar ('#', printcharfun);
1956 size &= PSEUDOVECTOR_SIZE_MASK; 1899 size &= PSEUDOVECTOR_SIZE_MASK;
1957 } 1900 }
1958 if (CHAR_TABLE_P (obj) || SUB_CHAR_TABLE_P (obj)) 1901 if (CHAR_TABLE_P (obj) || SUB_CHAR_TABLE_P (obj))
@@ -1966,20 +1909,19 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
1966 results in slow redisplay. */ 1909 results in slow redisplay. */
1967 if (SUB_CHAR_TABLE_P (obj) 1910 if (SUB_CHAR_TABLE_P (obj)
1968 && XSUB_CHAR_TABLE (obj)->depth == 3) 1911 && XSUB_CHAR_TABLE (obj)->depth == 3)
1969 PRINTCHAR ('\n'); 1912 printchar ('\n', printcharfun);
1970 PRINTCHAR ('#'); 1913 print_c_string ("#^", printcharfun);
1971 PRINTCHAR ('^');
1972 if (SUB_CHAR_TABLE_P (obj)) 1914 if (SUB_CHAR_TABLE_P (obj))
1973 PRINTCHAR ('^'); 1915 printchar ('^', printcharfun);
1974 size &= PSEUDOVECTOR_SIZE_MASK; 1916 size &= PSEUDOVECTOR_SIZE_MASK;
1975 } 1917 }
1976 if (size & PSEUDOVECTOR_FLAG) 1918 if (size & PSEUDOVECTOR_FLAG)
1977 goto badtype; 1919 goto badtype;
1978 1920
1979 PRINTCHAR ('['); 1921 printchar ('[', printcharfun);
1980 { 1922 {
1981 int i, idx = SUB_CHAR_TABLE_P (obj) ? SUB_CHAR_TABLE_OFFSET : 0; 1923 int i, idx = SUB_CHAR_TABLE_P (obj) ? SUB_CHAR_TABLE_OFFSET : 0;
1982 register Lisp_Object tem; 1924 Lisp_Object tem;
1983 ptrdiff_t real_size = size; 1925 ptrdiff_t real_size = size;
1984 1926
1985 /* For a sub char-table, print heading non-Lisp data first. */ 1927 /* For a sub char-table, print heading non-Lisp data first. */
@@ -1997,14 +1939,14 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
1997 1939
1998 for (i = idx; i < size; i++) 1940 for (i = idx; i < size; i++)
1999 { 1941 {
2000 if (i) PRINTCHAR (' '); 1942 if (i) printchar (' ', printcharfun);
2001 tem = AREF (obj, i); 1943 tem = AREF (obj, i);
2002 print_object (tem, printcharfun, escapeflag); 1944 print_object (tem, printcharfun, escapeflag);
2003 } 1945 }
2004 if (size < real_size) 1946 if (size < real_size)
2005 strout (" ...", 4, 4, printcharfun); 1947 print_c_string (" ...", printcharfun);
2006 } 1948 }
2007 PRINTCHAR (']'); 1949 printchar (']', printcharfun);
2008 } 1950 }
2009 break; 1951 break;
2010 1952
@@ -2012,26 +1954,25 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
2012 switch (XMISCTYPE (obj)) 1954 switch (XMISCTYPE (obj))
2013 { 1955 {
2014 case Lisp_Misc_Marker: 1956 case Lisp_Misc_Marker:
2015 strout ("#<marker ", -1, -1, printcharfun); 1957 print_c_string ("#<marker ", printcharfun);
2016 /* Do you think this is necessary? */ 1958 /* Do you think this is necessary? */
2017 if (XMARKER (obj)->insertion_type != 0) 1959 if (XMARKER (obj)->insertion_type != 0)
2018 strout ("(moves after insertion) ", -1, -1, printcharfun); 1960 print_c_string ("(moves after insertion) ", printcharfun);
2019 if (! XMARKER (obj)->buffer) 1961 if (! XMARKER (obj)->buffer)
2020 strout ("in no buffer", -1, -1, printcharfun); 1962 print_c_string ("in no buffer", printcharfun);
2021 else 1963 else
2022 { 1964 {
2023 int len = sprintf (buf, "at %"pD"d", marker_position (obj)); 1965 int len = sprintf (buf, "at %"pD"d in ", marker_position (obj));
2024 strout (buf, len, len, printcharfun); 1966 strout (buf, len, len, printcharfun);
2025 strout (" in ", -1, -1, printcharfun);
2026 print_string (BVAR (XMARKER (obj)->buffer, name), printcharfun); 1967 print_string (BVAR (XMARKER (obj)->buffer, name), printcharfun);
2027 } 1968 }
2028 PRINTCHAR ('>'); 1969 printchar ('>', printcharfun);
2029 break; 1970 break;
2030 1971
2031 case Lisp_Misc_Overlay: 1972 case Lisp_Misc_Overlay:
2032 strout ("#<overlay ", -1, -1, printcharfun); 1973 print_c_string ("#<overlay ", printcharfun);
2033 if (! XMARKER (OVERLAY_START (obj))->buffer) 1974 if (! XMARKER (OVERLAY_START (obj))->buffer)
2034 strout ("in no buffer", -1, -1, printcharfun); 1975 print_c_string ("in no buffer", printcharfun);
2035 else 1976 else
2036 { 1977 {
2037 int len = sprintf (buf, "from %"pD"d to %"pD"d in ", 1978 int len = sprintf (buf, "from %"pD"d to %"pD"d in ",
@@ -2041,21 +1982,21 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
2041 print_string (BVAR (XMARKER (OVERLAY_START (obj))->buffer, name), 1982 print_string (BVAR (XMARKER (OVERLAY_START (obj))->buffer, name),
2042 printcharfun); 1983 printcharfun);
2043 } 1984 }
2044 PRINTCHAR ('>'); 1985 printchar ('>', printcharfun);
2045 break; 1986 break;
2046 1987
2047 case Lisp_Misc_Finalizer: 1988 case Lisp_Misc_Finalizer:
2048 strout ("#<finalizer", -1, -1, printcharfun); 1989 print_c_string ("#<finalizer", printcharfun);
2049 if (NILP (XFINALIZER (obj)->function)) 1990 if (NILP (XFINALIZER (obj)->function))
2050 strout (" used", -1, -1, printcharfun); 1991 print_c_string (" used", printcharfun);
2051 strout (">", -1, -1, printcharfun); 1992 printchar ('>', printcharfun);
2052 break; 1993 break;
2053 1994
2054 /* Remaining cases shouldn't happen in normal usage, but let's 1995 /* Remaining cases shouldn't happen in normal usage, but let's
2055 print them anyway for the benefit of the debugger. */ 1996 print them anyway for the benefit of the debugger. */
2056 1997
2057 case Lisp_Misc_Free: 1998 case Lisp_Misc_Free:
2058 strout ("#<misc free cell>", -1, -1, printcharfun); 1999 print_c_string ("#<misc free cell>", printcharfun);
2059 break; 2000 break;
2060 2001
2061 case Lisp_Misc_Save_Value: 2002 case Lisp_Misc_Save_Value:
@@ -2063,7 +2004,7 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
2063 int i; 2004 int i;
2064 struct Lisp_Save_Value *v = XSAVE_VALUE (obj); 2005 struct Lisp_Save_Value *v = XSAVE_VALUE (obj);
2065 2006
2066 strout ("#<save-value ", -1, -1, printcharfun); 2007 print_c_string ("#<save-value ", printcharfun);
2067 2008
2068 if (v->save_type == SAVE_TYPE_MEMORY) 2009 if (v->save_type == SAVE_TYPE_MEMORY)
2069 { 2010 {
@@ -2086,17 +2027,15 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
2086 Lisp_Object maybe = area[i]; 2027 Lisp_Object maybe = area[i];
2087 int valid = valid_lisp_object_p (maybe); 2028 int valid = valid_lisp_object_p (maybe);
2088 2029
2030 printchar (' ', printcharfun);
2089 if (0 < valid) 2031 if (0 < valid)
2090 { 2032 print_object (maybe, printcharfun, escapeflag);
2091 PRINTCHAR (' ');
2092 print_object (maybe, printcharfun, escapeflag);
2093 }
2094 else 2033 else
2095 strout (valid ? " <some>" : " <invalid>", 2034 print_c_string (valid < 0 ? "<some>" : "<invalid>",
2096 -1, -1, printcharfun); 2035 printcharfun);
2097 } 2036 }
2098 if (i == limit && i < amount) 2037 if (i == limit && i < amount)
2099 strout (" ...", 4, 4, printcharfun); 2038 print_c_string (" ...", printcharfun);
2100 2039
2101#else /* not GC_MARK_STACK */ 2040#else /* not GC_MARK_STACK */
2102 2041
@@ -2115,7 +2054,7 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
2115 for (index = 0; index < SAVE_VALUE_SLOTS; index++) 2054 for (index = 0; index < SAVE_VALUE_SLOTS; index++)
2116 { 2055 {
2117 if (index) 2056 if (index)
2118 PRINTCHAR (' '); 2057 printchar (' ', printcharfun);
2119 2058
2120 switch (save_type (v, index)) 2059 switch (save_type (v, index))
2121 { 2060 {
@@ -2151,7 +2090,7 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
2151 strout (buf, i, i, printcharfun); 2090 strout (buf, i, i, printcharfun);
2152 } 2091 }
2153 } 2092 }
2154 PRINTCHAR ('>'); 2093 printchar ('>', printcharfun);
2155 } 2094 }
2156 break; 2095 break;
2157 2096
@@ -2166,7 +2105,7 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
2166 int len; 2105 int len;
2167 /* We're in trouble if this happens! 2106 /* We're in trouble if this happens!
2168 Probably should just emacs_abort (). */ 2107 Probably should just emacs_abort (). */
2169 strout ("#<EMACS BUG: INVALID DATATYPE ", -1, -1, printcharfun); 2108 print_c_string ("#<EMACS BUG: INVALID DATATYPE ", printcharfun);
2170 if (MISCP (obj)) 2109 if (MISCP (obj))
2171 len = sprintf (buf, "(MISC 0x%04x)", (int) XMISCTYPE (obj)); 2110 len = sprintf (buf, "(MISC 0x%04x)", (int) XMISCTYPE (obj));
2172 else if (VECTORLIKEP (obj)) 2111 else if (VECTORLIKEP (obj))
@@ -2174,8 +2113,9 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
2174 else 2113 else
2175 len = sprintf (buf, "(0x%02x)", (int) XTYPE (obj)); 2114 len = sprintf (buf, "(0x%02x)", (int) XTYPE (obj));
2176 strout (buf, len, len, printcharfun); 2115 strout (buf, len, len, printcharfun);
2177 strout (" Save your buffers immediately and please report this bug>", 2116 print_c_string ((" Save your buffers immediately"
2178 -1, -1, printcharfun); 2117 " and please report this bug>"),
2118 printcharfun);
2179 } 2119 }
2180 } 2120 }
2181 2121
@@ -2191,12 +2131,12 @@ print_interval (INTERVAL interval, Lisp_Object printcharfun)
2191{ 2131{
2192 if (NILP (interval->plist)) 2132 if (NILP (interval->plist))
2193 return; 2133 return;
2194 PRINTCHAR (' '); 2134 printchar (' ', printcharfun);
2195 print_object (make_number (interval->position), printcharfun, 1); 2135 print_object (make_number (interval->position), printcharfun, 1);
2196 PRINTCHAR (' '); 2136 printchar (' ', printcharfun);
2197 print_object (make_number (interval->position + LENGTH (interval)), 2137 print_object (make_number (interval->position + LENGTH (interval)),
2198 printcharfun, 1); 2138 printcharfun, 1);
2199 PRINTCHAR (' '); 2139 printchar (' ', printcharfun);
2200 print_object (interval->plist, printcharfun, 1); 2140 print_object (interval->plist, printcharfun, 1);
2201} 2141}
2202 2142