aboutsummaryrefslogtreecommitdiffstats
path: root/src/print.c
diff options
context:
space:
mode:
authorEli Zaretskii2013-03-28 20:13:59 +0200
committerEli Zaretskii2013-03-28 20:13:59 +0200
commitd76bf86f438d4f5f9fe493ab76f02ffc78f3ae2e (patch)
tree04fa8bc7bd2058a316a7ee30f8741d25bfd0b060 /src/print.c
parent2ef26ceb192c7683754cf0b4aa3087f501254332 (diff)
parente74aeda863cd6896e06e92586f87b45d63d67d15 (diff)
downloademacs-d76bf86f438d4f5f9fe493ab76f02ffc78f3ae2e.tar.gz
emacs-d76bf86f438d4f5f9fe493ab76f02ffc78f3ae2e.zip
Merge from trunk and resolve conflicts.
Diffstat (limited to 'src/print.c')
-rw-r--r--src/print.c164
1 files changed, 124 insertions, 40 deletions
diff --git a/src/print.c b/src/print.c
index bf86be5622e..811ab5011ce 100644
--- a/src/print.c
+++ b/src/print.c
@@ -1,7 +1,7 @@
1/* Lisp object printing and output streams. 1/* Lisp object printing and output streams.
2 2
3Copyright (C) 1985-1986, 1988, 1993-1995, 1997-2012 3Copyright (C) 1985-1986, 1988, 1993-1995, 1997-2013 Free Software
4 Free Software Foundation, Inc. 4Foundation, Inc.
5 5
6This file is part of GNU Emacs. 6This file is part of GNU Emacs.
7 7
@@ -84,7 +84,7 @@ static ptrdiff_t print_number_index;
84static void print_interval (INTERVAL interval, Lisp_Object printcharfun); 84static void print_interval (INTERVAL interval, Lisp_Object printcharfun);
85 85
86/* GDB resets this to zero on W32 to disable OutputDebugString calls. */ 86/* GDB resets this to zero on W32 to disable OutputDebugString calls. */
87int print_output_debug_flag EXTERNALLY_VISIBLE = 1; 87bool print_output_debug_flag EXTERNALLY_VISIBLE = 1;
88 88
89 89
90/* Low level output routines for characters and strings. */ 90/* Low level output routines for characters and strings. */
@@ -101,8 +101,9 @@ int print_output_debug_flag EXTERNALLY_VISIBLE = 1;
101 ptrdiff_t old_point = -1, start_point = -1; \ 101 ptrdiff_t old_point = -1, start_point = -1; \
102 ptrdiff_t old_point_byte = -1, start_point_byte = -1; \ 102 ptrdiff_t old_point_byte = -1, start_point_byte = -1; \
103 ptrdiff_t specpdl_count = SPECPDL_INDEX (); \ 103 ptrdiff_t specpdl_count = SPECPDL_INDEX (); \
104 int free_print_buffer = 0; \ 104 bool free_print_buffer = 0; \
105 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); \ 105 bool multibyte \
106 = !NILP (BVAR (current_buffer, enable_multibyte_characters)); \
106 Lisp_Object original 107 Lisp_Object original
107 108
108#define PRINTPREPARE \ 109#define PRINTPREPARE \
@@ -226,9 +227,9 @@ printchar (unsigned int ch, Lisp_Object fun)
226 if (NILP (fun)) 227 if (NILP (fun))
227 { 228 {
228 ptrdiff_t incr = len - (print_buffer_size - print_buffer_pos_byte); 229 ptrdiff_t incr = len - (print_buffer_size - print_buffer_pos_byte);
229 if (0 < incr) 230 if (incr > 0)
230 print_buffer = 231 print_buffer = xpalloc (print_buffer, &print_buffer_size,
231 xpalloc (print_buffer, &print_buffer_size, incr, -1, 1); 232 incr, -1, 1);
232 memcpy (print_buffer + print_buffer_pos_byte, str, len); 233 memcpy (print_buffer + print_buffer_pos_byte, str, len);
233 print_buffer_pos += 1; 234 print_buffer_pos += 1;
234 print_buffer_pos_byte += len; 235 print_buffer_pos_byte += len;
@@ -240,7 +241,7 @@ printchar (unsigned int ch, Lisp_Object fun)
240 } 241 }
241 else 242 else
242 { 243 {
243 int multibyte_p 244 bool multibyte_p
244 = !NILP (BVAR (current_buffer, enable_multibyte_characters)); 245 = !NILP (BVAR (current_buffer, enable_multibyte_characters));
245 246
246 setup_echo_area_for_printing (multibyte_p); 247 setup_echo_area_for_printing (multibyte_p);
@@ -272,7 +273,7 @@ strout (const char *ptr, ptrdiff_t size, ptrdiff_t size_byte,
272 if (NILP (printcharfun)) 273 if (NILP (printcharfun))
273 { 274 {
274 ptrdiff_t incr = size_byte - (print_buffer_size - print_buffer_pos_byte); 275 ptrdiff_t incr = size_byte - (print_buffer_size - print_buffer_pos_byte);
275 if (0 < incr) 276 if (incr > 0)
276 print_buffer = xpalloc (print_buffer, &print_buffer_size, incr, -1, 1); 277 print_buffer = xpalloc (print_buffer, &print_buffer_size, incr, -1, 1);
277 memcpy (print_buffer + print_buffer_pos_byte, ptr, size_byte); 278 memcpy (print_buffer + print_buffer_pos_byte, ptr, size_byte);
278 print_buffer_pos += size; 279 print_buffer_pos += size;
@@ -289,7 +290,7 @@ strout (const char *ptr, ptrdiff_t size, ptrdiff_t size_byte,
289 here, that's the reason we don't call printchar to do the 290 here, that's the reason we don't call printchar to do the
290 job. */ 291 job. */
291 int i; 292 int i;
292 int multibyte_p 293 bool multibyte_p
293 = !NILP (BVAR (current_buffer, enable_multibyte_characters)); 294 = !NILP (BVAR (current_buffer, enable_multibyte_characters));
294 295
295 setup_echo_area_for_printing (multibyte_p); 296 setup_echo_area_for_printing (multibyte_p);
@@ -507,10 +508,10 @@ temp_output_buffer_setup (const char *bufname)
507 specbind (Qstandard_output, buf); 508 specbind (Qstandard_output, buf);
508} 509}
509 510
510static void print (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag); 511static void print (Lisp_Object, Lisp_Object, bool);
511static void print_preprocess (Lisp_Object obj); 512static void print_preprocess (Lisp_Object);
512static void print_preprocess_string (INTERVAL interval, Lisp_Object arg); 513static void print_preprocess_string (INTERVAL, Lisp_Object);
513static void print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag); 514static void print_object (Lisp_Object, Lisp_Object, bool);
514 515
515DEFUN ("terpri", Fterpri, Sterpri, 0, 1, 0, 516DEFUN ("terpri", Fterpri, Sterpri, 0, 1, 0,
516 doc: /* Output a newline to stream PRINTCHARFUN. 517 doc: /* Output a newline to stream PRINTCHARFUN.
@@ -726,9 +727,9 @@ to make it write to the debugging output. */)
726/* This function is never called. Its purpose is to prevent 727/* This function is never called. Its purpose is to prevent
727 print_output_debug_flag from being optimized away. */ 728 print_output_debug_flag from being optimized away. */
728 729
729extern void debug_output_compilation_hack (int) EXTERNALLY_VISIBLE; 730extern void debug_output_compilation_hack (bool) EXTERNALLY_VISIBLE;
730void 731void
731debug_output_compilation_hack (int x) 732debug_output_compilation_hack (bool x)
732{ 733{
733 print_output_debug_flag = x; 734 print_output_debug_flag = x;
734} 735}
@@ -966,7 +967,7 @@ float_to_string (char *buf, double data)
966 static char const NaN_string[] = "0.0e+NaN"; 967 static char const NaN_string[] = "0.0e+NaN";
967 int i; 968 int i;
968 union { double d; char c[sizeof (double)]; } u_data, u_minus_zero; 969 union { double d; char c[sizeof (double)]; } u_data, u_minus_zero;
969 int negative = 0; 970 bool negative = 0;
970 u_data.d = data; 971 u_data.d = data;
971 u_minus_zero.d = - 0.0; 972 u_minus_zero.d = - 0.0;
972 for (i = 0; i < sizeof (double); i++) 973 for (i = 0; i < sizeof (double); i++)
@@ -1063,7 +1064,7 @@ float_to_string (char *buf, double data)
1063 1064
1064 1065
1065static void 1066static void
1066print (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag) 1067print (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
1067{ 1068{
1068 new_backquote_output = 0; 1069 new_backquote_output = 0;
1069 1070
@@ -1313,7 +1314,7 @@ print_prune_string_charset (Lisp_Object string)
1313} 1314}
1314 1315
1315static void 1316static void
1316print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag) 1317print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
1317{ 1318{
1318 char buf[max (sizeof "from..to..in " + 2 * INT_STRLEN_BOUND (EMACS_INT), 1319 char buf[max (sizeof "from..to..in " + 2 * INT_STRLEN_BOUND (EMACS_INT),
1319 max (sizeof " . #" + INT_STRLEN_BOUND (printmax_t), 1320 max (sizeof " . #" + INT_STRLEN_BOUND (printmax_t),
@@ -1395,8 +1396,8 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1395 ptrdiff_t size_byte; 1396 ptrdiff_t size_byte;
1396 /* 1 means we must ensure that the next character we output 1397 /* 1 means we must ensure that the next character we output
1397 cannot be taken as part of a hex character escape. */ 1398 cannot be taken as part of a hex character escape. */
1398 int need_nonhex = 0; 1399 bool need_nonhex = 0;
1399 int multibyte = STRING_MULTIBYTE (obj); 1400 bool multibyte = STRING_MULTIBYTE (obj);
1400 1401
1401 GCPRO1 (obj); 1402 GCPRO1 (obj);
1402 1403
@@ -1507,10 +1508,10 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1507 1508
1508 case Lisp_Symbol: 1509 case Lisp_Symbol:
1509 { 1510 {
1510 register int confusing; 1511 bool confusing;
1511 register unsigned char *p = SDATA (SYMBOL_NAME (obj)); 1512 unsigned char *p = SDATA (SYMBOL_NAME (obj));
1512 register unsigned char *end = p + SBYTES (SYMBOL_NAME (obj)); 1513 unsigned char *end = p + SBYTES (SYMBOL_NAME (obj));
1513 register int c; 1514 int c;
1514 ptrdiff_t i, i_byte; 1515 ptrdiff_t i, i_byte;
1515 ptrdiff_t size_byte; 1516 ptrdiff_t size_byte;
1516 Lisp_Object name; 1517 Lisp_Object name;
@@ -1766,12 +1767,12 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1766 { 1767 {
1767 int len; 1768 int len;
1768 strout ("#<window ", -1, -1, printcharfun); 1769 strout ("#<window ", -1, -1, printcharfun);
1769 len = sprintf (buf, "%d", XWINDOW (obj)->sequence_number); 1770 len = sprintf (buf, "%p", XWINDOW (obj));
1770 strout (buf, len, len, printcharfun); 1771 strout (buf, len, len, printcharfun);
1771 if (!NILP (XWINDOW (obj)->buffer)) 1772 if (BUFFERP (XWINDOW (obj)->contents))
1772 { 1773 {
1773 strout (" on ", -1, -1, printcharfun); 1774 strout (" on ", -1, -1, printcharfun);
1774 print_string (BVAR (XBUFFER (XWINDOW (obj)->buffer), name), 1775 print_string (BVAR (XBUFFER (XWINDOW (obj)->contents), name),
1775 printcharfun); 1776 printcharfun);
1776 } 1777 }
1777 PRINTCHAR ('>'); 1778 PRINTCHAR ('>');
@@ -2027,21 +2028,97 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
2027 PRINTCHAR ('>'); 2028 PRINTCHAR ('>');
2028 break; 2029 break;
2029 2030
2030 /* Remaining cases shouldn't happen in normal usage, but let's print 2031 /* Remaining cases shouldn't happen in normal usage, but let's
2031 them anyway for the benefit of the debugger. */ 2032 print them anyway for the benefit of the debugger. */
2033
2032 case Lisp_Misc_Free: 2034 case Lisp_Misc_Free:
2033 strout ("#<misc free cell>", -1, -1, printcharfun); 2035 strout ("#<misc free cell>", -1, -1, printcharfun);
2034 break; 2036 break;
2035 2037
2036 case Lisp_Misc_Save_Value: 2038 case Lisp_Misc_Save_Value:
2037 strout ("#<save_value ", -1, -1, printcharfun);
2038 { 2039 {
2039 int len = sprintf (buf, "ptr=%p int=%"pD"d", 2040 int i;
2040 XSAVE_VALUE (obj)->pointer, 2041 struct Lisp_Save_Value *v = XSAVE_VALUE (obj);
2041 XSAVE_VALUE (obj)->integer); 2042
2042 strout (buf, len, len, printcharfun); 2043 strout ("#<save-value ", -1, -1, printcharfun);
2044
2045 if (v->save_type == SAVE_TYPE_MEMORY)
2046 {
2047 ptrdiff_t amount = v->data[1].integer;
2048
2049#if GC_MARK_STACK
2050
2051 /* valid_lisp_object_p is reliable, so try to print up
2052 to 8 saved objects. This code is rarely used, so
2053 it's OK that valid_lisp_object_p is slow. */
2054
2055 int limit = min (amount, 8);
2056 Lisp_Object *area = v->data[0].pointer;
2057
2058 i = sprintf (buf, "with %"pD"d objects", amount);
2059 strout (buf, i, i, printcharfun);
2060
2061 for (i = 0; i < limit; i++)
2062 {
2063 Lisp_Object maybe = area[i];
2064
2065 if (valid_lisp_object_p (maybe) > 0)
2066 {
2067 PRINTCHAR (' ');
2068 print_object (maybe, printcharfun, escapeflag);
2069 }
2070 else
2071 strout (" <invalid>", -1, -1, printcharfun);
2072 }
2073 if (i == limit && i < amount)
2074 strout (" ...", 4, 4, printcharfun);
2075
2076#else /* not GC_MARK_STACK */
2077
2078 /* There is no reliable way to determine whether the objects
2079 are initialized, so do not try to print them. */
2080
2081 i = sprintf (buf, "with %"pD"d objects", amount);
2082 strout (buf, i, i, printcharfun);
2083
2084#endif /* GC_MARK_STACK */
2085 }
2086 else
2087 {
2088 /* Print each slot according to its type. */
2089 int index;
2090 for (index = 0; index < SAVE_VALUE_SLOTS; index++)
2091 {
2092 if (index)
2093 PRINTCHAR (' ');
2094
2095 switch (save_type (v, index))
2096 {
2097 case SAVE_UNUSED:
2098 i = sprintf (buf, "<unused>");
2099 break;
2100
2101 case SAVE_POINTER:
2102 i = sprintf (buf, "<pointer %p>",
2103 v->data[index].pointer);
2104 break;
2105
2106 case SAVE_INTEGER:
2107 i = sprintf (buf, "<integer %"pD"d>",
2108 v->data[index].integer);
2109 break;
2110
2111 case SAVE_OBJECT:
2112 print_object (v->data[index].object, printcharfun,
2113 escapeflag);
2114 continue;
2115 }
2116
2117 strout (buf, i, i, printcharfun);
2118 }
2119 }
2120 PRINTCHAR ('>');
2043 } 2121 }
2044 PRINTCHAR ('>');
2045 break; 2122 break;
2046 2123
2047 default: 2124 default:
@@ -2089,7 +2166,16 @@ print_interval (INTERVAL interval, Lisp_Object printcharfun)
2089 print_object (interval->plist, printcharfun, 1); 2166 print_object (interval->plist, printcharfun, 1);
2090} 2167}
2091 2168
2092 2169/* Initialize debug_print stuff early to have it working from the very
2170 beginning. */
2171
2172void
2173init_print_once (void)
2174{
2175 DEFSYM (Qexternal_debugging_output, "external-debugging-output");
2176 defsubr (&Sexternal_debugging_output);
2177}
2178
2093void 2179void
2094syms_of_print (void) 2180syms_of_print (void)
2095{ 2181{
@@ -2221,12 +2307,10 @@ priorities. */);
2221 defsubr (&Sprint); 2307 defsubr (&Sprint);
2222 defsubr (&Sterpri); 2308 defsubr (&Sterpri);
2223 defsubr (&Swrite_char); 2309 defsubr (&Swrite_char);
2224 defsubr (&Sexternal_debugging_output);
2225#ifdef WITH_REDIRECT_DEBUGGING_OUTPUT 2310#ifdef WITH_REDIRECT_DEBUGGING_OUTPUT
2226 defsubr (&Sredirect_debugging_output); 2311 defsubr (&Sredirect_debugging_output);
2227#endif 2312#endif
2228 2313
2229 DEFSYM (Qexternal_debugging_output, "external-debugging-output");
2230 DEFSYM (Qprint_escape_newlines, "print-escape-newlines"); 2314 DEFSYM (Qprint_escape_newlines, "print-escape-newlines");
2231 DEFSYM (Qprint_escape_multibyte, "print-escape-multibyte"); 2315 DEFSYM (Qprint_escape_multibyte, "print-escape-multibyte");
2232 DEFSYM (Qprint_escape_nonascii, "print-escape-nonascii"); 2316 DEFSYM (Qprint_escape_nonascii, "print-escape-nonascii");