From 6cda572a0f7da777cea9680131aa79be3f9be999 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Wed, 26 Dec 2012 19:40:19 +0400 Subject: [PATCH] * 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. --- src/ChangeLog | 4 ++++ src/alloc.c | 12 ++++++------ src/print.c | 42 ++++++++++++++++++++++++++++++++++++------ 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index d0e08317fba..d4794667ead 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -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 diff --git a/src/alloc.c b/src/alloc.c index 5a3ba465d81..f33c423ece7 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -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) diff --git a/src/print.c b/src/print.c index bf86be5622e..b89d5685fba 100644 --- a/src/print.c +++ b/src/print.c @@ -2034,14 +2034,44 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag break; case Lisp_Misc_Save_Value: - strout ("#pointer, - XSAVE_VALUE (obj)->integer); - strout (buf, len, len, printcharfun); + int i; + struct Lisp_Save_Value *v = XSAVE_VALUE (obj); + + strout ("#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 (" ", -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: -- 2.11.4.GIT