emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r117202: Debugging facility to check whether 'const


From: Dmitry Antipov
Subject: [Emacs-diffs] trunk r117202: Debugging facility to check whether 'const char *' points to
Date: Fri, 30 May 2014 07:40:49 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 117202
revision-id: address@hidden
parent: address@hidden
committer: Dmitry Antipov <address@hidden>
branch nick: trunk
timestamp: Fri 2014-05-30 11:40:29 +0400
message:
  Debugging facility to check whether 'const char *' points to
  relocatable data of non-pure Lisp string.
  * alloc.c (maybe_lisp_pointer): New function, refactored out of ...
  (mark_maybe_pointer): ... adjusted user.
  (relocatable_string_data_p): New function.
  * lisp.h (relocatable_string_data_p): Add prototype.
  * xdisp.c (message_with_string): If ENABLE_CHECKING, make sure
  the pointer to relocatable Lisp data is not used.
modified:
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/alloc.c                    alloc.c-20091113204419-o5vbwnq5f7feedwu-252
  src/lisp.h                     lisp.h-20091113204419-o5vbwnq5f7feedwu-253
  src/xdisp.c                    xdisp.c-20091113204419-o5vbwnq5f7feedwu-240
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2014-05-30 04:12:08 +0000
+++ b/src/ChangeLog     2014-05-30 07:40:29 +0000
@@ -1,3 +1,14 @@
+2014-05-30  Dmitry Antipov  <address@hidden>
+
+       Debugging facility to check whether 'const char *' points to
+       relocatable data of non-pure Lisp string.
+       * alloc.c (maybe_lisp_pointer): New function, refactored out of ...
+       (mark_maybe_pointer): ... adjusted user.
+       (relocatable_string_data_p): New function.
+       * lisp.h (relocatable_string_data_p): Add prototype.
+       * xdisp.c (message_with_string): If ENABLE_CHECKING, make sure
+       the pointer to relocatable Lisp data is not used.
+
 2014-05-30  Paul Eggert  <address@hidden>
 
        Don't let SIGINT handling block SIGCHLD indefinitely (Bug#17561).

=== modified file 'src/alloc.c'
--- a/src/alloc.c       2014-05-29 08:02:58 +0000
+++ b/src/alloc.c       2014-05-30 07:40:29 +0000
@@ -4547,7 +4547,16 @@
     }
 }
 
+/* Return true if P can point to Lisp data, and false otherwise.
+   USE_LSB_TAG needs Lisp data to be aligned on multiples of GCALIGNMENT.
+   Otherwise, assume that Lisp data is aligned on even addresses.  */
 
+static bool
+maybe_lisp_pointer (void *p)
+{
+  return !((intptr_t) p % (USE_LSB_TAG ? GCALIGNMENT : 2));
+}
+  
 /* If P points to Lisp data, mark that as live if it isn't already
    marked.  */
 
@@ -4561,10 +4570,7 @@
     VALGRIND_MAKE_MEM_DEFINED (&p, sizeof (p));
 #endif
 
-  /* Quickly rule out some values which can't point to Lisp data.
-     USE_LSB_TAG needs Lisp data to be aligned on multiples of GCALIGNMENT.
-     Otherwise, assume that Lisp data is aligned on even addresses.  */
-  if ((intptr_t) p % (USE_LSB_TAG ? GCALIGNMENT : 2))
+  if (!maybe_lisp_pointer (p))
     return;
 
   m = mem_find (p);
@@ -5007,9 +5013,34 @@
 #endif
 }
 
-
-
-
+/* If GC_MARK_STACK, return 1 if STR is a relocatable data of Lisp_String
+   (i.e. there is a non-pure Lisp_Object X so that SDATA (X) == STR) and 0
+   if not.  Otherwise we can't rely on valid_lisp_object_p and return -1.
+   This function is slow and should be used for debugging purposes.  */
+
+int
+relocatable_string_data_p (const char *str)
+{
+  if (PURE_POINTER_P (str))
+    return 0;
+#if GC_MARK_STACK  
+  if (str)
+    {
+      struct sdata *sdata
+       = (struct sdata *) (str - offsetof (struct sdata, data));
+
+      if (valid_pointer_p (sdata)
+         && valid_pointer_p (sdata->string)
+         && maybe_lisp_pointer (sdata->string))
+       return (valid_lisp_object_p
+               (make_lisp_ptr (sdata->string, Lisp_String))
+               && (const char *) sdata->string->data == str);
+    }
+  return 0;
+#endif /* GC_MARK_STACK */  
+  return -1;
+}
+
 /***********************************************************************
                       Pure Storage Management
  ***********************************************************************/

=== modified file 'src/lisp.h'
--- a/src/lisp.h        2014-05-29 14:52:47 +0000
+++ b/src/lisp.h        2014-05-30 07:40:29 +0000
@@ -3747,6 +3747,7 @@
 extern void syms_of_alloc (void);
 extern struct buffer * allocate_buffer (void);
 extern int valid_lisp_object_p (Lisp_Object);
+extern int relocatable_string_data_p (const char *);
 #ifdef GC_CHECK_CONS_LIST
 extern void check_cons_list (void);
 #else

=== modified file 'src/xdisp.c'
--- a/src/xdisp.c       2014-05-26 02:28:09 +0000
+++ b/src/xdisp.c       2014-05-30 07:40:29 +0000
@@ -10201,19 +10201,17 @@
     {
       if (m)
        {
-         /* ENCODE_SYSTEM below can GC and/or relocate the Lisp
-            String whose data pointer might be passed to us in M.  So
-            we use a local copy.  */
-         char *fmt = xstrdup (m);
+         /* ENCODE_SYSTEM below can GC and/or relocate the
+            Lisp data, so make sure we don't use it here.  */
+         eassert (relocatable_string_data_p (m) != 1);
 
          if (noninteractive_need_newline)
            putc ('\n', stderr);
          noninteractive_need_newline = 0;
-         fprintf (stderr, fmt, SDATA (ENCODE_SYSTEM (string)));
+         fprintf (stderr, m, SDATA (ENCODE_SYSTEM (string)));
          if (!cursor_in_echo_area)
            fprintf (stderr, "\n");
          fflush (stderr);
-         xfree (fmt);
        }
     }
   else if (INTERACTIVE)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]