emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 366e25a 05/14: Simplify interface of dynlib_attr.


From: Philipp Stephani
Subject: [Emacs-diffs] master 366e25a 05/14: Simplify interface of dynlib_attr.
Date: Sun, 4 Jun 2017 13:54:06 -0400 (EDT)

branch: master
commit 366e25a6d1caa30d8d336ce556f90f9ee46ca531
Author: Philipp Stephani <address@hidden>
Commit: Philipp Stephani <address@hidden>

    Simplify interface of dynlib_attr.
    
    Instead of returning bool, set the argument pointers to NULL if the
    information is not available.
    
    * src/dynlib.c (dynlib_addr): Don't return bool.
---
 src/dynlib.c | 34 +++++++++++++++-------------------
 src/dynlib.h |  5 ++++-
 2 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/src/dynlib.c b/src/dynlib.c
index 9561923..79e98b0 100644
--- a/src/dynlib.c
+++ b/src/dynlib.c
@@ -28,6 +28,8 @@ along with GNU Emacs.  If not, see 
<http://www.gnu.org/licenses/>.  */
 
 #include "dynlib.h"
 
+#include <stddef.h>
+
 #ifdef WINDOWSNT
 
 /* MS-Windows systems.  */
@@ -120,7 +122,7 @@ dynlib_sym (dynlib_handle_ptr h, const char *sym)
   return (void *)sym_addr;
 }
 
-bool
+void
 dynlib_addr (void *addr, const char **fname, const char **symname)
 {
   static char dll_filename[MAX_UTF8_PATH];
@@ -128,7 +130,6 @@ dynlib_addr (void *addr, const char **fname, const char 
**symname)
   static GetModuleHandleExA_Proc s_pfn_Get_Module_HandleExA = NULL;
   char *dll_fn = NULL;
   HMODULE hm_kernel32 = NULL;
-  bool result = false;
   HMODULE hm_dll = NULL;
   wchar_t mfn_w[MAX_PATH];
   char mfn_a[MAX_PATH];
@@ -206,23 +207,18 @@ dynlib_addr (void *addr, const char **fname, const char 
**symname)
            dynlib_last_err = GetLastError ();
        }
       if (dll_fn)
-       {
-         dostounix_filename (dll_fn);
-         /* We cannot easily produce the function name, since
-            typically all 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.  */
-         sprintf (addr_str, "at 0x%x", (DWORD_PTR)addr);
-         *symname = addr_str;
-         result = true;
-       }
+        dostounix_filename (dll_fn);
     }
 
   *fname = dll_fn;
-  return result;
+
+  /* We cannot easily produce the function name, since typically all
+     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.  */
+  *symname = NULL;
 }
 
 const char *
@@ -283,19 +279,19 @@ dynlib_sym (dynlib_handle_ptr h, const char *sym)
   return dlsym (h, sym);
 }
 
-bool
+void
 dynlib_addr (void *ptr, const char **path, const char **sym)
 {
+  *path = NULL;
+  *sym = NULL;
 #ifdef HAVE_DLADDR
   Dl_info info;
   if (dladdr (ptr, &info) && info.dli_fname && info.dli_sname)
     {
       *path = info.dli_fname;
       *sym = info.dli_sname;
-      return true;
     }
 #endif
-  return false;
 }
 
 const char *
diff --git a/src/dynlib.h b/src/dynlib.h
index 5ccec11..6246c6a 100644
--- a/src/dynlib.h
+++ b/src/dynlib.h
@@ -27,8 +27,11 @@ dynlib_handle_ptr dynlib_open (const char *path);
 void *dynlib_sym (dynlib_handle_ptr h, const char *sym);
 typedef struct dynlib_function_ptr_nonce *(*dynlib_function_ptr) (void);
 dynlib_function_ptr dynlib_func (dynlib_handle_ptr h, const char *sym);
-bool dynlib_addr (void *ptr, const char **path, const char **sym);
 const char *dynlib_error (void);
 int dynlib_close (dynlib_handle_ptr h);
+/* Sets *FILE to the file name from which PTR was loaded, and *SYM to
+   its symbol name.  If the file or symbol name could not be
+   determined, set the corresponding argument to NULL.  */
+void dynlib_addr (void *ptr, const char **file, const char **sym);
 
 #endif /* DYNLIB_H */



reply via email to

[Prev in Thread] Current Thread [Next in Thread]