emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 9f5f5ae: Fix MS-Windows build as followup to pdumpe


From: Eli Zaretskii
Subject: [Emacs-diffs] master 9f5f5ae: Fix MS-Windows build as followup to pdumper executable lookup
Date: Mon, 24 Jun 2019 13:08:19 -0400 (EDT)

branch: master
commit 9f5f5ae6386fe1ea9f31bd760d7ffd293d274502
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Fix MS-Windows build as followup to pdumper executable lookup
    
    * src/w32.c (w32_my_exename): New function.
    * src/w32.h (w32_my_exename): Add prototype.
    * src/emacs.c (load_pdump_find_executable) [WINDOWSNT]: Find
    the actual file name of the program without looking along
    PATH, by calling w32_my_exename.
    
    * nt/mingw-cfg.site (ac_cv_func_canonicalize_file_name)
    (ac_cv_func_realpath, gl_cv_func_realpath_works): Disable
    testing.
    * nt/gnulib-cfg.mk (OMIT_GNULIB_MODULE_canonicalize-lgpl): Set
    to true.
---
 nt/gnulib-cfg.mk  |  1 +
 nt/mingw-cfg.site |  4 ++++
 src/emacs.c       | 26 +++++++++++++++++++++++++-
 src/w32.c         | 15 +++++++++++++++
 src/w32.h         |  1 +
 5 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/nt/gnulib-cfg.mk b/nt/gnulib-cfg.mk
index 09cd582..91f30ec 100644
--- a/nt/gnulib-cfg.mk
+++ b/nt/gnulib-cfg.mk
@@ -62,3 +62,4 @@ OMIT_GNULIB_MODULE_sys_stat = true
 OMIT_GNULIB_MODULE_sys_time = true
 OMIT_GNULIB_MODULE_sys_types = true
 OMIT_GNULIB_MODULE_unistd = true
+OMIT_GNULIB_MODULE_canonicalize-lgpl = true
diff --git a/nt/mingw-cfg.site b/nt/mingw-cfg.site
index e15d14c..dfdca39 100644
--- a/nt/mingw-cfg.site
+++ b/nt/mingw-cfg.site
@@ -86,6 +86,10 @@ gl_cv_func_readlink_works=yes
 gl_cv_func_symlink_works=yes
 ac_cv_func_readlinkat=yes
 ac_cv_func_faccessat=yes
+# Avoid compiling Gnulib's canonicalize-lgpl.c, which fails
+ac_cv_func_canonicalize_file_name=yes
+ac_cv_func_realpath="not-needed"
+gl_cv_func_realpath_works="no-but-not-needed-so-yes"
 # Implemented in w32.c
 ac_cv_func_fcntl=yes
 gl_cv_func_fcntl_f_dupfd_cloexec=yes
diff --git a/src/emacs.c b/src/emacs.c
index a26eacb..1ddd10b 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -715,6 +715,24 @@ static enum pdumper_load_result
 load_pdump_find_executable (const char* argv0, char **exename)
 {
   enum pdumper_load_result result;
+#ifdef WINDOWSNT
+  result = PDUMPER_LOAD_ERROR;
+  *exename = NULL;
+  char *prog_fname = w32_my_exename ();
+  if (prog_fname)
+    {
+      result = PDUMPER_LOAD_OOM;
+      /* Use xstrdup, so as to call our private implementation of
+        malloc, since the caller calls our free.  */
+      char *ret = xstrdup (prog_fname);
+      if (ret)
+       {
+         *exename = ret;
+         result = PDUMPER_LOAD_SUCCESS;
+       }
+    }
+  return result;
+#else  /* !WINDOWSNT */
   char *candidate = NULL;
 
   /* If the executable name contains a slash, we have some kind of
@@ -784,6 +802,7 @@ load_pdump_find_executable (const char* argv0, char 
**exename)
  out:
   free (candidate);
   return result;
+#endif /* !WINDOWSNT */
 }
 
 static enum pdumper_load_result
@@ -848,10 +867,15 @@ load_pdump (int argc, char **argv)
      the dump in the hardcoded location.  */
   if (exename)
     {
+#ifdef WINDOWSNT
+      real_exename = exename;
+      exename = NULL;
+#else
       real_exename = realpath (exename, NULL);
       if (!real_exename)
         fatal ("could not resolve realpath of \"%s\": %s",
                exename, strerror (errno));
+#endif
       size_t real_exename_length = strlen (real_exename);
       if (strip_suffix)
         {
@@ -920,7 +944,7 @@ load_pdump (int argc, char **argv)
                          + strlen (suffix)
                          + 1);
 #ifdef DOS_NT
-      argv0_len = strlen (argv0_base);
+      size_t argv0_len = strlen (argv0_base);
       if (argv0_len >= 4
          && c_strcasecmp (argv0_base + argv0_len - 4, ".exe") == 0)
        sprintf (dump_file, "%s%c%.*s%s", path_exec, DIRECTORY_SEP,
diff --git a/src/w32.c b/src/w32.c
index 833ff4c..b2d1ffc 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -9988,6 +9988,21 @@ w32_relocate (const char *epath_dir)
   return epath_dir;
 }
 
+/* Return the full absolute name of the running executable.
+
+   Note: this function is called early during startup, when Unicode
+   file name are not yet supported.  */
+char *
+w32_my_exename (void)
+{
+  static char exename[MAX_PATH];
+  if (!GetModuleFileNameA (NULL, exename, MAX_PATH))
+    return NULL;
+  /* FIXME: Resolve possible symlinks in the last component of
+     exename, i.e. if the executable itself is a symlink.  */
+  return exename;
+}
+
 /*
        globals_of_w32 is used to initialize those global variables that
        must always be initialized on startup even when the global variable
diff --git a/src/w32.h b/src/w32.h
index 3790583..3ef78ec 100644
--- a/src/w32.h
+++ b/src/w32.h
@@ -185,6 +185,7 @@ extern MultiByteToWideChar_Proc pMultiByteToWideChar;
 extern WideCharToMultiByte_Proc pWideCharToMultiByte;
 extern DWORD multiByteToWideCharFlags;
 
+extern char *w32_my_exename (void);
 extern const char *w32_relocate (const char *);
 
 extern void init_environment (char **);



reply via email to

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