aboutsummaryrefslogtreecommitdiffstats
path: root/src/print.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/print.c')
-rw-r--r--src/print.c64
1 files changed, 35 insertions, 29 deletions
diff --git a/src/print.c b/src/print.c
index 14b4326bb6f..40e0fb6b855 100644
--- a/src/print.c
+++ b/src/print.c
@@ -1,6 +1,6 @@
1/* Lisp object printing and output streams. 1/* Lisp object printing and output streams.
2 2
3Copyright (C) 1985-1986, 1988, 1993-1995, 1997-2011 3Copyright (C) 1985-1986, 1988, 1993-1995, 1997-2012
4 Free Software Foundation, Inc. 4 Free Software Foundation, Inc.
5 5
6This file is part of GNU Emacs. 6This file is part of GNU Emacs.
@@ -46,10 +46,7 @@ static Lisp_Object Qtemp_buffer_setup_hook;
46static Lisp_Object Qfloat_output_format; 46static Lisp_Object Qfloat_output_format;
47 47
48#include <math.h> 48#include <math.h>
49
50#if STDC_HEADERS
51#include <float.h> 49#include <float.h>
52#endif
53#include <ftoastr.h> 50#include <ftoastr.h>
54 51
55/* Default to values appropriate for IEEE floating point. */ 52/* Default to values appropriate for IEEE floating point. */
@@ -623,7 +620,7 @@ A printed representation of an object is text which describes that object. */)
623 printcharfun = Vprin1_to_string_buffer; 620 printcharfun = Vprin1_to_string_buffer;
624 PRINTPREPARE; 621 PRINTPREPARE;
625 print (object, printcharfun, NILP (noescape)); 622 print (object, printcharfun, NILP (noescape));
626 /* Make Vprin1_to_string_buffer be the default buffer after PRINTFINSH */ 623 /* Make Vprin1_to_string_buffer be the default buffer after PRINTFINISH */
627 PRINTFINISH; 624 PRINTFINISH;
628 } 625 }
629 626
@@ -1019,12 +1016,15 @@ float_to_string (char *buf, double data)
1019 { 1016 {
1020 width = 0; 1017 width = 0;
1021 do 1018 do
1022 width = (width * 10) + (*cp++ - '0'); 1019 {
1020 width = (width * 10) + (*cp++ - '0');
1021 if (DBL_DIG < width)
1022 goto lose;
1023 }
1023 while (*cp >= '0' && *cp <= '9'); 1024 while (*cp >= '0' && *cp <= '9');
1024 1025
1025 /* A precision of zero is valid only for %f. */ 1026 /* A precision of zero is valid only for %f. */
1026 if (width > DBL_DIG 1027 if (width == 0 && *cp != 'f')
1027 || (width == 0 && *cp != 'f'))
1028 goto lose; 1028 goto lose;
1029 } 1029 }
1030 1030
@@ -1317,7 +1317,9 @@ print_prune_string_charset (Lisp_Object string)
1317static void 1317static void
1318print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag) 1318print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag)
1319{ 1319{
1320 char buf[40]; 1320 char buf[max (sizeof "from..to..in " + 2 * INT_STRLEN_BOUND (EMACS_INT),
1321 max (sizeof " . #" + INT_STRLEN_BOUND (printmax_t),
1322 40))];
1321 1323
1322 QUIT; 1324 QUIT;
1323 1325
@@ -1539,13 +1541,19 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1539 else 1541 else
1540 confusing = 0; 1542 confusing = 0;
1541 1543
1544 size_byte = SBYTES (name);
1545
1542 if (! NILP (Vprint_gensym) && !SYMBOL_INTERNED_P (obj)) 1546 if (! NILP (Vprint_gensym) && !SYMBOL_INTERNED_P (obj))
1543 { 1547 {
1544 PRINTCHAR ('#'); 1548 PRINTCHAR ('#');
1545 PRINTCHAR (':'); 1549 PRINTCHAR (':');
1546 } 1550 }
1547 1551 else if (size_byte == 0)
1548 size_byte = SBYTES (name); 1552 {
1553 PRINTCHAR ('#');
1554 PRINTCHAR ('#');
1555 break;
1556 }
1549 1557
1550 for (i = 0, i_byte = 0; i_byte < size_byte;) 1558 for (i = 0, i_byte = 0; i_byte < size_byte;)
1551 { 1559 {
@@ -1558,7 +1566,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1558 { 1566 {
1559 if (c == '\"' || c == '\\' || c == '\'' 1567 if (c == '\"' || c == '\\' || c == '\''
1560 || c == ';' || c == '#' || c == '(' || c == ')' 1568 || c == ';' || c == '#' || c == '(' || c == ')'
1561 || c == ',' || c =='.' || c == '`' 1569 || c == ',' || c == '.' || c == '`'
1562 || c == '[' || c == ']' || c == '?' || c <= 040 1570 || c == '[' || c == ']' || c == '?' || c <= 040
1563 || confusing) 1571 || confusing)
1564 PRINTCHAR ('\\'), confusing = 0; 1572 PRINTCHAR ('\\'), confusing = 0;
@@ -1611,8 +1619,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1611 PRINTCHAR ('('); 1619 PRINTCHAR ('(');
1612 1620
1613 { 1621 {
1614 EMACS_INT print_length; 1622 printmax_t i, print_length;
1615 int i;
1616 Lisp_Object halftail = obj; 1623 Lisp_Object halftail = obj;
1617 1624
1618 /* Negative values of print-length are invalid in CL. 1625 /* Negative values of print-length are invalid in CL.
@@ -1620,7 +1627,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1620 if (NATNUMP (Vprint_length)) 1627 if (NATNUMP (Vprint_length))
1621 print_length = XFASTINT (Vprint_length); 1628 print_length = XFASTINT (Vprint_length);
1622 else 1629 else
1623 print_length = 0; 1630 print_length = TYPE_MAXIMUM (printmax_t);
1624 1631
1625 i = 0; 1632 i = 0;
1626 while (CONSP (obj)) 1633 while (CONSP (obj))
@@ -1628,10 +1635,10 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1628 /* Detect circular list. */ 1635 /* Detect circular list. */
1629 if (NILP (Vprint_circle)) 1636 if (NILP (Vprint_circle))
1630 { 1637 {
1631 /* Simple but imcomplete way. */ 1638 /* Simple but incomplete way. */
1632 if (i != 0 && EQ (obj, halftail)) 1639 if (i != 0 && EQ (obj, halftail))
1633 { 1640 {
1634 sprintf (buf, " . #%d", i / 2); 1641 sprintf (buf, " . #%"pMd, i / 2);
1635 strout (buf, -1, -1, printcharfun); 1642 strout (buf, -1, -1, printcharfun);
1636 goto end_of_list; 1643 goto end_of_list;
1637 } 1644 }
@@ -1651,15 +1658,16 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1651 } 1658 }
1652 } 1659 }
1653 1660
1654 if (i++) 1661 if (i)
1655 PRINTCHAR (' '); 1662 PRINTCHAR (' ');
1656 1663
1657 if (print_length && i > print_length) 1664 if (print_length <= i)
1658 { 1665 {
1659 strout ("...", 3, 3, printcharfun); 1666 strout ("...", 3, 3, printcharfun);
1660 goto end_of_list; 1667 goto end_of_list;
1661 } 1668 }
1662 1669
1670 i++;
1663 print_object (XCAR (obj), printcharfun, escapeflag); 1671 print_object (XCAR (obj), printcharfun, escapeflag);
1664 1672
1665 obj = XCDR (obj); 1673 obj = XCDR (obj);
@@ -1694,7 +1702,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1694 } 1702 }
1695 else if (BOOL_VECTOR_P (obj)) 1703 else if (BOOL_VECTOR_P (obj))
1696 { 1704 {
1697 register int i; 1705 ptrdiff_t i;
1698 register unsigned char c; 1706 register unsigned char c;
1699 struct gcpro gcpro1; 1707 struct gcpro gcpro1;
1700 EMACS_INT size_in_chars 1708 EMACS_INT size_in_chars
@@ -1795,19 +1803,17 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1795 PRINTCHAR (' '); 1803 PRINTCHAR (' ');
1796 strout (SDATA (SYMBOL_NAME (h->weak)), -1, -1, printcharfun); 1804 strout (SDATA (SYMBOL_NAME (h->weak)), -1, -1, printcharfun);
1797 PRINTCHAR (' '); 1805 PRINTCHAR (' ');
1798 sprintf (buf, "%ld/%ld", (long) h->count, 1806 sprintf (buf, "%"pI"d/%"pI"d", h->count, ASIZE (h->next));
1799 (long) ASIZE (h->next));
1800 strout (buf, -1, -1, printcharfun); 1807 strout (buf, -1, -1, printcharfun);
1801 } 1808 }
1802 sprintf (buf, " 0x%lx", (unsigned long) h); 1809 sprintf (buf, " %p", h);
1803 strout (buf, -1, -1, printcharfun); 1810 strout (buf, -1, -1, printcharfun);
1804 PRINTCHAR ('>'); 1811 PRINTCHAR ('>');
1805#endif 1812#endif
1806 /* Implement a readable output, e.g.: 1813 /* Implement a readable output, e.g.:
1807 #s(hash-table size 2 test equal data (k1 v1 k2 v2)) */ 1814 #s(hash-table size 2 test equal data (k1 v1 k2 v2)) */
1808 /* Always print the size. */ 1815 /* Always print the size. */
1809 sprintf (buf, "#s(hash-table size %ld", 1816 sprintf (buf, "#s(hash-table size %"pI"d", ASIZE (h->next));
1810 (long) ASIZE (h->next));
1811 strout (buf, -1, -1, printcharfun); 1817 strout (buf, -1, -1, printcharfun);
1812 1818
1813 if (!NILP (h->test)) 1819 if (!NILP (h->test))
@@ -2014,9 +2020,9 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
2014 2020
2015 case Lisp_Misc_Save_Value: 2021 case Lisp_Misc_Save_Value:
2016 strout ("#<save_value ", -1, -1, printcharfun); 2022 strout ("#<save_value ", -1, -1, printcharfun);
2017 sprintf(buf, "ptr=%p int=%"pD"d", 2023 sprintf (buf, "ptr=%p int=%"pD"d",
2018 XSAVE_VALUE (obj)->pointer, 2024 XSAVE_VALUE (obj)->pointer,
2019 XSAVE_VALUE (obj)->integer); 2025 XSAVE_VALUE (obj)->integer);
2020 strout (buf, -1, -1, printcharfun); 2026 strout (buf, -1, -1, printcharfun);
2021 PRINTCHAR ('>'); 2027 PRINTCHAR ('>');
2022 break; 2028 break;
@@ -2035,7 +2041,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
2035 if (MISCP (obj)) 2041 if (MISCP (obj))
2036 sprintf (buf, "(MISC 0x%04x)", (int) XMISCTYPE (obj)); 2042 sprintf (buf, "(MISC 0x%04x)", (int) XMISCTYPE (obj));
2037 else if (VECTORLIKEP (obj)) 2043 else if (VECTORLIKEP (obj))
2038 sprintf (buf, "(PVEC 0x%08lx)", (unsigned long) ASIZE (obj)); 2044 sprintf (buf, "(PVEC 0x%08"pI"x)", ASIZE (obj));
2039 else 2045 else
2040 sprintf (buf, "(0x%02x)", (int) XTYPE (obj)); 2046 sprintf (buf, "(0x%02x)", (int) XTYPE (obj));
2041 strout (buf, -1, -1, printcharfun); 2047 strout (buf, -1, -1, printcharfun);