changeset 72846:c6e33127381a

(print_string): When printcharfun is t, copy string contents and call strout on the copy.
author Richard M. Stallman <rms@gnu.org>
date Wed, 13 Sep 2006 15:15:54 +0000
parents becf85cadcc0
children 03031b73c9aa
files src/print.c
diffstat 1 files changed, 27 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/print.c	Wed Sep 13 15:12:59 2006 +0000
+++ b/src/print.c	Wed Sep 13 15:15:54 2006 +0000
@@ -364,7 +364,10 @@
    print_buffer.  PRINTCHARFUN t means output to the echo area or to
    stdout if non-interactive.  If neither nil nor t, call Lisp
    function PRINTCHARFUN for each character printed.  MULTIBYTE
-   non-zero means PTR contains multibyte characters.  */
+   non-zero means PTR contains multibyte characters.
+
+   In the case where PRINTCHARFUN is nil, it is safe for PTR to point
+   to data in a Lisp string.  Otherwise that is not safe.  */
 
 static void
 strout (ptr, size, size_byte, printcharfun, multibyte)
@@ -497,10 +500,29 @@
       else
 	chars = SBYTES (string);
 
-      /* strout is safe for output to a frame (echo area) or to print_buffer.  */
-      strout (SDATA (string),
-	      chars, SBYTES (string),
-	      printcharfun, STRING_MULTIBYTE (string));
+      if (EQ (printcharfun, Qt))
+	{
+	  /* Output to echo area.  */
+	  int nbytes = SBYTES (string);
+	  char *buffer;
+
+	  /* Copy the string contents so that relocation of STRING by
+	     GC does not cause trouble.  */
+	  USE_SAFE_ALLOCA;
+
+	  SAFE_ALLOCA (buffer, char *, nbytes);
+	  bcopy (SDATA (string), buffer, nbytes);
+
+	  strout (buffer, chars, SBYTES (string),
+		  printcharfun, STRING_MULTIBYTE (string));
+
+	  SAFE_FREE ();
+	}
+      else
+	/* No need to copy, since output to print_buffer can't GC.  */
+	strout (SDATA (string),
+		chars, SBYTES (string),
+		printcharfun, STRING_MULTIBYTE (string));
     }
   else
     {