]> code.delx.au - gnu-emacs/blobdiff - src/vm-limit.c
(x_display_pixel_height, x_display_pixel_width): New functions.
[gnu-emacs] / src / vm-limit.c
index 348fccbb827ad64bcf8cf678a586a20e82a4f781..907732c82afd784aaf4ba601df5c9421d9988457 100644 (file)
@@ -65,6 +65,21 @@ get_lim_data ()
 }
 #else /* not NO_LIM_DATA */
 
+#if defined (HAVE_GETRLIMIT) && defined (RLIMIT_AS)
+static void
+get_lim_data ()
+{
+  struct rlimit rlimit;
+
+  getrlimit (RLIMIT_AS, &rlimit);
+  if (rlimit.rlim_cur == RLIM_INFINITY)
+    lim_data = -1;
+  else
+    lim_data = rlimit.rlim_cur;
+}
+
+#else /* not HAVE_GETRLIMIT */
+
 #ifdef USG
 
 static void
@@ -106,9 +121,29 @@ void
 get_lim_data ()
 {
   _go32_dpmi_meminfo info;
+  unsigned long lim1, lim2;
 
   _go32_dpmi_get_free_memory_information (&info);
-  lim_data = info.available_memory;
+  /* DPMI server of Windows NT and its descendants reports in
+     info.available_memory a much lower amount that is really
+     available, which causes bogus "past 95% of memory limit"
+     warnings.  Try to overcome that via circumstantial evidence.  */
+  lim1 = info.available_memory;
+  lim2 = info.available_physical_pages * 4096;
+  /* DPMI Spec: "Fields that are unavailable will hold -1."  */
+  if ((long)lim1 == -1L)
+    lim1 = 0;
+  if ((long)lim2 == -1L)
+    lim2 = 0;
+  /* Surely, the available memory is at least what we have physically
+     available, right?  */
+  if (lim1 > lim2)
+    lim_data = lim1;
+  else
+    lim_data = lim2;
+  /* Don't believe they will give us more that 0.5 GB.   */
+  if (lim_data > 512 * 1024 * 1024)
+    lim_data = 512 * 1024 * 1024;
 }
 #else /* not MSDOS */
 static void
@@ -135,6 +170,7 @@ get_lim_data ()
 #endif /* BSD4_2 */
 #endif /* not WINDOWSNT */
 #endif /* not USG */
+#endif /* not HAVE_GETRLIMIT */
 #endif /* not NO_LIM_DATA */
 \f
 /* Verify amount of memory available, complaining if we're near the end. */
@@ -148,34 +184,14 @@ check_memory_limits ()
   extern POINTER (*__morecore) ();
 
   register POINTER cp;
-#if defined (HAVE_GETRLIMIT) && ! defined (CYGWIN)
-  rlim_t five_percent;
-#else
   unsigned long five_percent;
-#endif
   unsigned long data_size;
   enum warnlevel new_warnlevel;
 
-  /* Cygwin has a faulty getrlimit implementation:
-     http://lists.gnu.org/archive/html/emacs-devel/2008-08/msg00125.html  */
-#if defined (HAVE_GETRLIMIT) && ! defined (CYGWIN)
-  struct rlimit rlimit;
-
-  getrlimit (RLIMIT_AS, &rlimit);
-  if (RLIM_INFINITY == rlimit.rlim_max
-      /* This is a nonsensical case, but it happens -- rms.  */
-      || rlimit.rlim_cur > rlimit.rlim_max)
-    return;
-  five_percent = rlimit.rlim_max / 20;
-
-#else /* not HAVE_GETRLIMIT */
-
   if (lim_data == 0)
     get_lim_data ();
   five_percent = lim_data / 20;
 
-#endif /* not HAVE_GETRLIMIT */
-
   /* Find current end of memory and issue warning if getting near max */
 #ifdef REL_ALLOC
   if (real_morecore)
@@ -230,10 +246,8 @@ check_memory_limits ()
        warnlevel = warned_85;
     }
 
-#if ! defined (HAVE_GETRLIMIT) || defined (CYGWIN)
   if (EXCEEDS_LISP_PTR (cp))
     (*warn_function) ("Warning: memory in use exceeds lisp pointer size");
-#endif
 }
 \f
 /* Enable memory usage warnings.