Skip to content

Commit 26fde48

Browse files
committed
Shorten pointer printing code using a small helper function.
* src/print.c (print_pointer): New helper function. (print_vectorlike): Use it.
1 parent fc92c2d commit 26fde48

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

src/print.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,22 @@ data_from_funcptr (void (*funcptr) (void))
13651365
interchangeably, so it's OK to assume that here too. */
13661366
return (void const *) funcptr;
13671367
}
1368+
1369+
/* Print the value of the pointer PTR. */
1370+
1371+
static void
1372+
print_pointer (Lisp_Object printcharfun, char *buf, const char *prefix,
1373+
const void *ptr)
1374+
{
1375+
uintptr_t ui = (uintptr_t) ptr;
1376+
1377+
/* In theory this assignment could lose info on pre-C99 hosts, but
1378+
in practice it doesn't. */
1379+
uintmax_t up = ui;
1380+
1381+
int len = sprintf (buf, "%s 0x%" PRIxMAX, prefix, up);
1382+
strout (buf, len, len, printcharfun);
1383+
}
13681384
#endif
13691385

13701386
static bool
@@ -1803,33 +1819,15 @@ print_vectorlike (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag,
18031819
dynlib_addr (ptr, &file, &symbol);
18041820

18051821
if (symbol == NULL)
1806-
{
1807-
uintptr_t ui = (uintptr_t) data_from_funcptr (ptr);
1808-
1809-
/* In theory this assignment could lose info on pre-C99
1810-
hosts, but in practice it doesn't. */
1811-
uintmax_t up = ui;
1812-
1813-
int len = sprintf (buf, "at 0x%"PRIxMAX, up);
1814-
strout (buf, len, len, printcharfun);
1815-
}
1816-
else
1822+
print_pointer (printcharfun, buf, "at", data_from_funcptr (ptr));
1823+
else
18171824
print_c_string (symbol, printcharfun);
18181825

18191826
void *data = module_function_data (function);
18201827
if (data != NULL)
1821-
{
1822-
uintptr_t ui = (uintptr_t) data;
1823-
1824-
/* In theory this assignment could lose info on pre-C99
1825-
hosts, but in practice it doesn't. */
1826-
uintmax_t up = ui;
1827-
1828-
int len = sprintf (buf, " with data 0x%"PRIxMAX, up);
1829-
strout (buf, len, len, printcharfun);
1830-
}
1828+
print_pointer (printcharfun, buf, " with data", data);
18311829

1832-
if (file != NULL)
1830+
if (file != NULL)
18331831
{
18341832
print_c_string (" from ", printcharfun);
18351833
print_c_string (file, printcharfun);

0 commit comments

Comments
 (0)