]> git.eshelyaron.com Git - emacs.git/commitdiff
Shorten pointer printing code using a small helper function.
authorPhilipp Stephani <phst@google.com>
Sun, 5 Jan 2020 16:04:17 +0000 (17:04 +0100)
committerPhilipp Stephani <phst@google.com>
Sun, 5 Jan 2020 16:12:27 +0000 (17:12 +0100)
* src/print.c (print_pointer): New helper function.
(print_vectorlike): Use it.

src/print.c

index b373aaf65513a43f9513f57155137e5061297036..634169dbdbd4f4033f8e6a63cf04aaccb4f7548f 100644 (file)
@@ -1365,6 +1365,22 @@ data_from_funcptr (void (*funcptr) (void))
      interchangeably, so it's OK to assume that here too.  */
   return (void const *) funcptr;
 }
+
+/* Print the value of the pointer PTR.  */
+
+static void
+print_pointer (Lisp_Object printcharfun, char *buf, const char *prefix,
+               const void *ptr)
+{
+  uintptr_t ui = (uintptr_t) ptr;
+
+  /* In theory this assignment could lose info on pre-C99 hosts, but
+     in practice it doesn't.  */
+  uintmax_t up = ui;
+
+  int len = sprintf (buf, "%s 0x%" PRIxMAX, prefix, up);
+  strout (buf, len, len, printcharfun);
+}
 #endif
 
 static bool
@@ -1803,33 +1819,15 @@ print_vectorlike (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag,
        dynlib_addr (ptr, &file, &symbol);
 
        if (symbol == NULL)
-         {
-           uintptr_t ui = (uintptr_t) data_from_funcptr (ptr);
-
-           /* In theory this assignment could lose info on pre-C99
-              hosts, but in practice it doesn't.  */
-           uintmax_t up = ui;
-
-           int len = sprintf (buf, "at 0x%"PRIxMAX, up);
-           strout (buf, len, len, printcharfun);
-         }
-       else
+          print_pointer (printcharfun, buf, "at", data_from_funcptr (ptr));
+        else
          print_c_string (symbol, printcharfun);
 
         void *data = module_function_data (function);
         if (data != NULL)
-          {
-           uintptr_t ui = (uintptr_t) data;
-
-           /* In theory this assignment could lose info on pre-C99
-              hosts, but in practice it doesn't.  */
-           uintmax_t up = ui;
-
-           int len = sprintf (buf, " with data 0x%"PRIxMAX, up);
-           strout (buf, len, len, printcharfun);
-          }
+          print_pointer (printcharfun, buf, " with data", data);
 
-       if (file != NULL)
+        if (file != NULL)
          {
            print_c_string (" from ", printcharfun);
            print_c_string (file, printcharfun);