diff options
| author | Philipp Stephani | 2020-01-05 17:04:17 +0100 |
|---|---|---|
| committer | Philipp Stephani | 2020-01-05 17:12:27 +0100 |
| commit | 26fde487cb3740cdc678e76c62f1320d47b4d6f5 (patch) | |
| tree | bc3a5e9d7714faeef95134291bcbde9236486051 | |
| parent | fc92c2d8942cf466aa6dbc422f2e798801b18408 (diff) | |
| download | emacs-26fde487cb3740cdc678e76c62f1320d47b4d6f5.tar.gz emacs-26fde487cb3740cdc678e76c62f1320d47b4d6f5.zip | |
Shorten pointer printing code using a small helper function.
* src/print.c (print_pointer): New helper function.
(print_vectorlike): Use it.
| -rw-r--r-- | src/print.c | 42 |
1 files changed, 20 insertions, 22 deletions
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)) | |||
| 1365 | interchangeably, so it's OK to assume that here too. */ | 1365 | interchangeably, so it's OK to assume that here too. */ |
| 1366 | return (void const *) funcptr; | 1366 | return (void const *) funcptr; |
| 1367 | } | 1367 | } |
| 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 | } | ||
| 1368 | #endif | 1384 | #endif |
| 1369 | 1385 | ||
| 1370 | static bool | 1386 | static bool |
| @@ -1803,33 +1819,15 @@ print_vectorlike (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag, | |||
| 1803 | dynlib_addr (ptr, &file, &symbol); | 1819 | dynlib_addr (ptr, &file, &symbol); |
| 1804 | 1820 | ||
| 1805 | if (symbol == NULL) | 1821 | if (symbol == NULL) |
| 1806 | { | 1822 | print_pointer (printcharfun, buf, "at", data_from_funcptr (ptr)); |
| 1807 | uintptr_t ui = (uintptr_t) data_from_funcptr (ptr); | 1823 | else |
| 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 | ||
| 1817 | print_c_string (symbol, printcharfun); | 1824 | print_c_string (symbol, printcharfun); |
| 1818 | 1825 | ||
| 1819 | void *data = module_function_data (function); | 1826 | void *data = module_function_data (function); |
| 1820 | if (data != NULL) | 1827 | if (data != NULL) |
| 1821 | { | 1828 | print_pointer (printcharfun, buf, " with data", data); |
| 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 | } | ||
| 1831 | 1829 | ||
| 1832 | if (file != NULL) | 1830 | if (file != NULL) |
| 1833 | { | 1831 | { |
| 1834 | print_c_string (" from ", printcharfun); | 1832 | print_c_string (" from ", printcharfun); |
| 1835 | print_c_string (file, printcharfun); | 1833 | print_c_string (file, printcharfun); |