]> code.delx.au - gnu-emacs/blobdiff - src/w32fns.c
Fix handling of image cache refcounts. (Bug#20802)
[gnu-emacs] / src / w32fns.c
index 6abb433fd2f0c33943482d4a1505ff7aeadda269..5f40729011e91628e430580109e1eae3299c1767 100644 (file)
@@ -29,6 +29,8 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <fcntl.h>
 #include <unistd.h>
 
+#include <c-ctype.h>
+
 #include "lisp.h"
 #include "w32term.h"
 #include "frame.h"
@@ -202,7 +204,8 @@ unsigned int msh_mousewheel = 0;
 static unsigned menu_free_timer = 0;
 
 #ifdef GLYPH_DEBUG
-static int image_cache_refcount, dpyinfo_refcount;
+static ptrdiff_t image_cache_refcount;
+static int dpyinfo_refcount;
 #endif
 
 static HWND w32_visible_system_caret_hwnd;
@@ -7038,7 +7041,28 @@ a ShowWindow flag:
 
 #else  /* !CYGWIN */
 
-  current_dir = ENCODE_FILE (current_dir);
+  const char file_url_str[] = "file:///";
+  const int file_url_len = sizeof (file_url_str) - 1;
+  if (strncmp (SSDATA (document), file_url_str, file_url_len) == 0)
+    {
+      /* Passing "file:///" URLs to ShellExecute causes shlwapi.dll to
+        start a thread in some rare system configurations, for
+        unknown reasons.  That thread is started in the context of
+        the Emacs process, but out of control of our code, and seems
+        to never exit afterwards.  Each such thread reserves 8MB of
+        stack space (because that's the value recorded in the Emacs
+        executable at link time: Emacs needs a large stack).  So a
+        large enough number of invocations of w32-shell-execute can
+        potentially cause the Emacs process to run out of available
+        address space, which is nasty.  To work around this, we
+        convert such URLs to local file names, which seems to prevent
+        those threads from starting.  See bug #20220.  */
+      char *p = SSDATA (document) + file_url_len;
+
+      if (c_isalpha (*p) && p[1] == ':' && IS_DIRECTORY_SEP (p[2]))
+       document = Fsubstring_no_properties (document,
+                                            make_number (file_url_len), Qnil);
+    }
   /* We have a situation here.  If DOCUMENT is a relative file name,
      but its name includes leading directories, i.e. it lives not in
      CURRENT_DIR, but in its subdirectory, then ShellExecute below
@@ -7071,6 +7095,8 @@ a ShowWindow flag:
   else
     document = ENCODE_FILE (document);
   UNGCPRO;
+
+  current_dir = ENCODE_FILE (current_dir);
   if (use_unicode)
     {
       wchar_t document_w[MAX_PATH], current_dir_w[MAX_PATH];
@@ -7510,13 +7536,13 @@ elements (all size values are in pixels).
 
 - `title-bar-height' is the height of the title bar of FRAME.
 
-- `menu-bar-external' if `t' means the menu bar is by default external
+- `menu-bar-external' if t means the menu bar is by default external
   (not included in the inner size of FRAME).
 
 - `menu-bar-size' is a cons of the width and height of the menu bar of
   FRAME.
 
-- `tool-bar-external' if `t' means the tool bar is by default external
+- `tool-bar-external' if t means the tool bar is by default external
   (not included in the inner size of FRAME).
 
 - `tool-bar-side' tells tells on which side the tool bar on FRAME is by
@@ -8322,6 +8348,14 @@ syms_of_w32fns (void)
   DEFSYM (Qworkarea, "workarea");
   DEFSYM (Qmm_size, "mm-size");
   DEFSYM (Qframes, "frames");
+  DEFSYM (Qtip_frame, "tip-frame");
+  DEFSYM (Qunicode_sip, "unicode-sip");
+
+  /* Symbols used elsewhere, but only in MS-Windows-specific code.  */
+  DEFSYM (Qgnutls_dll, "gnutls");
+  DEFSYM (Qlibxml2_dll, "libxml2");
+  DEFSYM (Qserif, "serif");
+  DEFSYM (Qzlib_dll, "zlib");
 
   Fput (Qundefined_color, Qerror_conditions,
        listn (CONSTYPE_PURE, 2, Qundefined_color, Qerror));