From: Philipp Stephani Date: Sun, 5 Jan 2020 16:04:17 +0000 (+0100) Subject: Shorten pointer printing code using a small helper function. X-Git-Tag: emacs-28.0.90~7908^2~168 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=26fde487cb3740cdc678e76c62f1320d47b4d6f5;p=emacs.git Shorten pointer printing code using a small helper function. * src/print.c (print_pointer): New helper function. (print_vectorlike): Use it. --- diff --git a/src/print.c b/src/print.c index b373aaf6551..634169dbdbd 100644 --- a/src/print.c +++ b/src/print.c @@ -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);