* print.c (print_object): If Lisp_Save_Value object's pointer
authorDmitry Antipov <dmantipov@yandex.ru>
Wed, 26 Dec 2012 15:40:19 +0000 (19:40 +0400)
committerDmitry Antipov <dmantipov@yandex.ru>
Wed, 26 Dec 2012 15:40:19 +0000 (19:40 +0400)
is the address of a memory area containing Lisp_Objects, try
to print them.
* alloc.c (valid_lisp_object_p): Adjust comment.

src/ChangeLog
src/alloc.c
src/print.c

index d0e0831..d479466 100644 (file)
@@ -2,6 +2,10 @@
 
        * lisp.h (toplevel): Add two notices to the comment about
        defining a new Lisp data type.
+       * print.c (print_object): If Lisp_Save_Value object's pointer
+       is the address of a memory area containing Lisp_Objects, try
+       to print them.
+       * alloc.c (valid_lisp_object_p): Adjust comment.
 
 2012-12-26  Dmitry Antipov  <dmantipov@yandex.ru>
 
index 5a3ba46..f33c423 100644 (file)
@@ -4721,12 +4721,12 @@ valid_pointer_p (void *p)
 #endif
 }
 
-/* Return 2 if OBJ is a killed or special buffer object.
-   Return 1 if OBJ is a valid lisp object.
-   Return 0 if OBJ is NOT a valid lisp object.
-   Return -1 if we cannot validate OBJ.
-   This function can be quite slow,
-   so it should only be used in code for manual debugging.  */
+/* Return 2 if OBJ is a killed or special buffer object, 1 if OBJ is a
+   valid lisp object, 0 if OBJ is NOT a valid lisp object, or -1 if we
+   cannot validate OBJ.  This function can be quite slow, so its primary
+   use is the manual debugging.  The only exception is print_object, where
+   we use it to check whether the memory referenced by the pointer of
+   Lisp_Save_Value object contains valid objects.  */
 
 int
 valid_lisp_object_p (Lisp_Object obj)
index bf86be5..b89d568 100644 (file)
@@ -2034,14 +2034,44 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
          break;
 
        case Lisp_Misc_Save_Value:
-         strout ("#<save_value ", -1, -1, printcharfun);
          {
-           int len = sprintf (buf, "ptr=%p int=%"pD"d",
-                              XSAVE_VALUE (obj)->pointer,
-                              XSAVE_VALUE (obj)->integer);
-           strout (buf, len, len, printcharfun);
+           int i;
+           struct Lisp_Save_Value *v = XSAVE_VALUE (obj);
+
+           strout ("#<save-value ", -1, -1, printcharfun);
+           if (v->dogc)
+             {
+               int lim = min (v->integer, 8);
+               
+               /* 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 such a saved values are quite rare.  */
+
+               i = sprintf (buf, "with %"pD"d objects", v->integer);
+               strout (buf, i, i, printcharfun);
+
+               for (i = 0; i < lim; i++)
+                 {
+                   Lisp_Object maybe = ((Lisp_Object *) v->pointer)[i];
+
+                   if (valid_lisp_object_p (maybe))
+                     {
+                       PRINTCHAR (' ');
+                       print_object (maybe, printcharfun, escapeflag);
+                     }
+                   else
+                     strout (" <invalid>", -1, -1, printcharfun);
+                 }
+               if (i == lim && i < v->integer)
+                 strout (" ...", 4, 4, printcharfun);
+             }
+           else
+             {
+               i = sprintf (buf, "ptr=%p int=%"pD"d", v->pointer, v->integer);
+               strout (buf, i, i, printcharfun);
+             }
+           PRINTCHAR ('>');
          }
-         PRINTCHAR ('>');
          break;
 
        default: