From 9ae5c0a2e12c25f37736d9b106c55227b55521e6 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Mon, 5 Jun 2017 19:16:04 +0300 Subject: [PATCH] Fix emacs-module-tests on MS-Windows * src/print.c (print_vectorlike): Make sure module function's address prints with a leading "0x". This fixes emacs-module-tests on MS-Windows. Fix whitespace. * src/dynlib.c (dynlib_addr): Remove unused variable. Update commentary. --- src/dynlib.c | 6 +++--- src/print.c | 55 ++++++++++++++++++++++++++++------------------------ 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/dynlib.c b/src/dynlib.c index 79e98b0f288..47ba5e3d91b 100644 --- a/src/dynlib.c +++ b/src/dynlib.c @@ -126,7 +126,6 @@ void dynlib_addr (void *addr, const char **fname, const char **symname) { static char dll_filename[MAX_UTF8_PATH]; - static char addr_str[22]; static GetModuleHandleExA_Proc s_pfn_Get_Module_HandleExA = NULL; char *dll_fn = NULL; HMODULE hm_kernel32 = NULL; @@ -216,8 +215,9 @@ dynlib_addr (void *addr, const char **fname, const char **symname) of the module functions will be unexported, and probably even static, which means the symbols can be obtained only if we link against libbfd (and the DLL can be stripped anyway). So we just - show the address and the file name; they can use that with - addr2line or GDB to recover the symbolic name. */ + show the address and the file name (see print_vectorlike in + print.c); they can use that with addr2line or GDB to recover the + symbolic name. */ *symname = NULL; } diff --git a/src/print.c b/src/print.c index 76ae10fe132..aaec5b04956 100644 --- a/src/print.c +++ b/src/print.c @@ -1701,31 +1701,36 @@ print_vectorlike (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag, #ifdef HAVE_MODULES case PVEC_MODULE_FUNCTION: { - print_c_string ("#subr; - const char *file = NULL; - const char *symbol = NULL; - dynlib_addr (ptr, &file, &symbol); - - if (symbol == NULL) - { - print_c_string ("at ", printcharfun); - enum { pointer_bufsize = sizeof ptr * 16 / CHAR_BIT + 2 + 1 }; - char buffer[pointer_bufsize]; - int needed = snprintf (buffer, sizeof buffer, "%p", ptr); - eassert (needed <= sizeof buffer); - print_c_string (buffer, printcharfun); - } - else - print_c_string (symbol, printcharfun); - - if (file != NULL) - { - print_c_string (" from ", printcharfun); - print_c_string (file, printcharfun); - } - - printchar ('>', printcharfun); + print_c_string ("#subr; + const char *file = NULL; + const char *symbol = NULL; + dynlib_addr (ptr, &file, &symbol); + + if (symbol == NULL) + { + print_c_string ("at ", printcharfun); + enum { pointer_bufsize = sizeof ptr * 16 / CHAR_BIT + 2 + 1 }; + char buffer[pointer_bufsize]; + int needed = snprintf (buffer, sizeof buffer, "%p", ptr); + const char p0x[] = "0x"; + eassert (needed <= sizeof buffer); + /* ANSI C doesn't guarantee that %p produces a string that + begins with a "0x". */ + if (c_strncasecmp (buffer, p0x, sizeof (p0x) - 1) != 0) + print_c_string (p0x, printcharfun); + print_c_string (buffer, printcharfun); + } + else + print_c_string (symbol, printcharfun); + + if (file != NULL) + { + print_c_string (" from ", printcharfun); + print_c_string (file, printcharfun); + } + + printchar ('>', printcharfun); } break; #endif -- 2.39.2