merge trunk
[bpt/emacs.git] / src / print.c
index 03b4674..811ab50 100644 (file)
@@ -227,9 +227,9 @@ printchar (unsigned int ch, Lisp_Object fun)
       if (NILP (fun))
        {
          ptrdiff_t incr = len - (print_buffer_size - print_buffer_pos_byte);
-         if (0 < incr)
-           print_buffer =
-             xpalloc (print_buffer, &print_buffer_size, incr, -1, 1);
+         if (incr > 0)
+           print_buffer = xpalloc (print_buffer, &print_buffer_size,
+                                   incr, -1, 1);
          memcpy (print_buffer + print_buffer_pos_byte, str, len);
          print_buffer_pos += 1;
          print_buffer_pos_byte += len;
@@ -273,7 +273,7 @@ strout (const char *ptr, ptrdiff_t size, ptrdiff_t size_byte,
   if (NILP (printcharfun))
     {
       ptrdiff_t incr = size_byte - (print_buffer_size - print_buffer_pos_byte);
-      if (0 < incr)
+      if (incr > 0)
        print_buffer = xpalloc (print_buffer, &print_buffer_size, incr, -1, 1);
       memcpy (print_buffer + print_buffer_pos_byte, ptr, size_byte);
       print_buffer_pos += size;
@@ -1769,10 +1769,10 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
          strout ("#<window ", -1, -1, printcharfun);
          len = sprintf (buf, "%p", XWINDOW (obj));
          strout (buf, len, len, printcharfun);
-         if (!NILP (XWINDOW (obj)->buffer))
+         if (BUFFERP (XWINDOW (obj)->contents))
            {
              strout (" on ", -1, -1, printcharfun);
-             print_string (BVAR (XBUFFER (XWINDOW (obj)->buffer), name),
+             print_string (BVAR (XBUFFER (XWINDOW (obj)->contents), name),
                            printcharfun);
            }
          PRINTCHAR ('>');
@@ -2042,17 +2042,15 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
 
            strout ("#<save-value ", -1, -1, printcharfun);
 
-           if (v->area)
+           if (v->save_type == SAVE_TYPE_MEMORY)
              {
                ptrdiff_t amount = v->data[1].integer;
 
 #if GC_MARK_STACK
 
-               /* If GC_MARK_STACK, valid_lisp_object_p is quite reliable,
-                  and so we try to print up to 8 objects we have saved.
-                  Although valid_lisp_object_p is slow, this shouldn't be
-                  a real bottleneck because we do not use this code under
-                  normal circumstances.  */
+               /* valid_lisp_object_p is reliable, so try to print up
+                  to 8 saved objects.  This code is rarely used, so
+                  it's OK that valid_lisp_object_p is slow.  */
 
                int limit = min (amount, 8);
                Lisp_Object *area = v->data[0].pointer;
@@ -2077,9 +2075,8 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
 
 #else /* not GC_MARK_STACK */
 
-               /* If !GC_MARK_STACK, we have no reliable way to find
-                  whether Lisp_Object pointers points to an initialized
-                  objects, and so we do not ever trying to print them.  */
+               /* There is no reliable way to determine whether the objects
+                  are initialized, so do not try to print them.  */
 
                i = sprintf (buf, "with %"pD"d objects", amount);
                strout (buf, i, i, printcharfun);
@@ -2088,33 +2085,37 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
              }
            else
              {
-               /* Print each `data[N]' slot according to its type.  */
-
-#define PRINTX(index)                                                  \
-  do {                                                                 \
-    i = 0;                                                             \
-    if (v->type ## index == SAVE_UNUSED)                               \
-      i = sprintf (buf, "<unused>");                                   \
-    else if (v->type ## index == SAVE_INTEGER)                         \
-      i = sprintf (buf, "<integer %"pD"d>", v->data[index].integer);   \
-    else if (v->type ## index == SAVE_POINTER)                         \
-      i = sprintf (buf, "<pointer %p>", v->data[index].pointer);       \
-    else /* SAVE_OBJECT */                                             \
-      print_object (v->data[index].object, printcharfun, escapeflag);  \
-    if (i)                                                             \
-      strout (buf, i, i, printcharfun);                                        \
-  } while (0)
-
-               PRINTX (0);
-               PRINTCHAR (' ');
-               PRINTX (1);
-               PRINTCHAR (' ');
-               PRINTX (2);
-               PRINTCHAR (' ');
-               PRINTX (3);
+               /* Print each slot according to its type.  */
+               int index;
+               for (index = 0; index < SAVE_VALUE_SLOTS; index++)
+                 {
+                   if (index)
+                     PRINTCHAR (' ');
 
-#undef PRINTX
+                   switch (save_type (v, index))
+                     {
+                     case SAVE_UNUSED:
+                       i = sprintf (buf, "<unused>");
+                       break;
+
+                     case SAVE_POINTER:
+                       i = sprintf (buf, "<pointer %p>",
+                                    v->data[index].pointer);
+                       break;
+
+                     case SAVE_INTEGER:
+                       i = sprintf (buf, "<integer %"pD"d>",
+                                    v->data[index].integer);
+                       break;
+
+                     case SAVE_OBJECT:
+                       print_object (v->data[index].object, printcharfun,
+                                     escapeflag);
+                       continue;
+                     }
 
+                   strout (buf, i, i, printcharfun);
+                 }
              }
            PRINTCHAR ('>');
          }
@@ -2165,7 +2166,16 @@ print_interval (INTERVAL interval, Lisp_Object printcharfun)
   print_object (interval->plist, printcharfun, 1);
 }
 
-\f
+/* Initialize debug_print stuff early to have it working from the very
+   beginning.  */
+
+void
+init_print_once (void)
+{
+  DEFSYM (Qexternal_debugging_output, "external-debugging-output");
+  defsubr (&Sexternal_debugging_output);
+}
+
 void
 syms_of_print (void)
 {
@@ -2297,12 +2307,10 @@ priorities.  */);
   defsubr (&Sprint);
   defsubr (&Sterpri);
   defsubr (&Swrite_char);
-  defsubr (&Sexternal_debugging_output);
 #ifdef WITH_REDIRECT_DEBUGGING_OUTPUT
   defsubr (&Sredirect_debugging_output);
 #endif
 
-  DEFSYM (Qexternal_debugging_output, "external-debugging-output");
   DEFSYM (Qprint_escape_newlines, "print-escape-newlines");
   DEFSYM (Qprint_escape_multibyte, "print-escape-multibyte");
   DEFSYM (Qprint_escape_nonascii, "print-escape-nonascii");