Fix bug #16576 with PRINTCHARFUN that conses output a lot.
[bpt/emacs.git] / src / print.c
index 04552be..71fa30d 100644 (file)
@@ -1,6 +1,6 @@
 /* Lisp object printing and output streams.
 
-Copyright (C) 1985-1986, 1988, 1993-1995, 1997-2013 Free Software
+Copyright (C) 1985-1986, 1988, 1993-1995, 1997-2014 Free Software
 Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -1119,7 +1119,7 @@ print (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
    string (its text properties will be traced), or a symbol that has
    no obarray (this is for the print-gensym feature).
    The status fields of Vprint_number_table mean whether each object appears
-   more than once in OBJ: Qnil at the first time, and Qt after that .  */
+   more than once in OBJ: Qnil at the first time, and Qt after that.  */
 static void
 print_preprocess (Lisp_Object obj)
 {
@@ -1389,9 +1389,8 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
        print_string (obj, printcharfun);
       else
        {
-         register ptrdiff_t i_byte;
+         register ptrdiff_t i, i_byte;
          struct gcpro gcpro1;
-         unsigned char *str;
          ptrdiff_t size_byte;
          /* 1 means we must ensure that the next character we output
             cannot be taken as part of a hex character escape.  */
@@ -1410,23 +1409,15 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
            }
 
          PRINTCHAR ('\"');
-         str = SDATA (obj);
          size_byte = SBYTES (obj);
 
-         for (i_byte = 0; i_byte < size_byte;)
+         for (i = 0, i_byte = 0; i_byte < size_byte;)
            {
              /* Here, we must convert each multi-byte form to the
                 corresponding character code before handing it to PRINTCHAR.  */
-             int len;
              int c;
 
-             if (multibyte)
-               {
-                 c = STRING_CHAR_AND_LENGTH (str + i_byte, len);
-                 i_byte += len;
-               }
-             else
-               c = str[i_byte++];
+             FETCH_STRING_CHAR_ADVANCE (c, obj, i, i_byte);
 
              QUIT;
 
@@ -1705,8 +1696,8 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
          unsigned char c;
          struct gcpro gcpro1;
          EMACS_INT size = bool_vector_size (obj);
-         ptrdiff_t size_in_chars = ((size + BOOL_VECTOR_BITS_PER_CHAR - 1)
-                                    / BOOL_VECTOR_BITS_PER_CHAR);
+         ptrdiff_t size_in_chars = bool_vector_bytes (size);
+         ptrdiff_t real_size_in_chars = size_in_chars;
          GCPRO1 (obj);
 
          PRINTCHAR ('#');
@@ -1725,7 +1716,7 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
          for (i = 0; i < size_in_chars; i++)
            {
              QUIT;
-             c = XBOOL_VECTOR (obj)->data[i];
+             c = bool_vector_uchar_data (obj)[i];
              if (c == '\n' && print_escape_newlines)
                {
                  PRINTCHAR ('\\');
@@ -1751,6 +1742,9 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
                  PRINTCHAR (c);
                }
            }
+
+         if (size_in_chars < real_size_in_chars)
+           strout (" ...", 4, 4, printcharfun);
          PRINTCHAR ('\"');
 
          UNGCPRO;
@@ -1763,8 +1757,9 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
        }
       else if (WINDOWP (obj))
        {
-         void *ptr = XWINDOW (obj);
-         int len = sprintf (buf, "#<window %p", ptr);
+         int len;
+         strout ("#<window ", -1, -1, printcharfun);
+         len = sprintf (buf, "%d", XWINDOW (obj)->sequence_number);
          strout (buf, len, len, printcharfun);
          if (BUFFERP (XWINDOW (obj)->contents))
            {