]> git.eshelyaron.com Git - emacs.git/commitdiff
Implement memory-info for MS-DOS.
authorEli Zaretskii <eliz@gnu.org>
Fri, 11 Jul 2014 10:09:51 +0000 (13:09 +0300)
committerEli Zaretskii <eliz@gnu.org>
Fri, 11 Jul 2014 10:09:51 +0000 (13:09 +0300)
 src/dosfns.c (dos_memory_info): New function.
 src/dosfns.h (dos_memory_info): Add prototype.
 src/alloc.c (Fmemory_info) [MSDOS]: Call dos_memory_info.
 src/vm-limit.c (get_lim_data) [MSDOS]: Call dos_memory_info, instead
 of doing some of its job.

src/ChangeLog
src/alloc.c
src/dosfns.c
src/dosfns.h
src/vm-limit.c

index 1e0a3a92f5de9ae9a68f49cd2a3bd909aa19493c..e469880a4ceb9fc7f9d9680768c22e3bba9fb89d 100644 (file)
@@ -1,5 +1,12 @@
 2014-07-11  Eli Zaretskii  <eliz@gnu.org>
 
+       Implement memory-info for MS-DOS.
+       * dosfns.c (dos_memory_info): New function.
+       * dosfns.h (dos_memory_info): Add prototype.
+       * alloc.c (Fmemory_info) [MSDOS]: Call dos_memory_info.
+       * vm-limit.c (get_lim_data) [MSDOS]: Call dos_memory_info, instead
+       of doing some of its job.
+
        * minibuf.c (read_minibuf_noninteractive) [WINDOWSNT]: Don't
        reference termios structure members.
 
index 4a912703c39824098fccae21b875a0770148c387..77be94d73d10fb43b2b36a7515ced861894d3bf8 100644 (file)
@@ -53,6 +53,10 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <sys/sysinfo.h>
 #endif
 
+#ifdef MSDOS
+#include "dosfns.h"            /* For dos_memory_info.  */
+#endif
+
 #if (defined ENABLE_CHECKING                   \
      && defined HAVE_VALGRIND_VALGRIND_H       \
      && !defined USE_VALGRIND)
@@ -6900,10 +6904,21 @@ values are zero.  If the system is not supported, return nil.  */)
                   (uintmax_t) freeswap / 1024);
   else
     return Qnil;
-#else /* not HAVE_LINUX_SYSINFO, not WINDOWSNT */
+#elif defined MSDOS
+  unsigned long totalram, freeram, totalswap, freeswap;
+
+  if (dos_memory_info (&totalram, &freeram, &totalswap, &freeswap) == 0)
+    return list4i ((uintmax_t) totalram / 1024,
+                  (uintmax_t) freeram / 1024,
+                  (uintmax_t) totalswap / 1024,
+                  (uintmax_t) freeswap / 1024);
+  else
+    return Qnil;
+}
+#else /* not HAVE_LINUX_SYSINFO, not WINDOWSNT, not MSDOS */
   /* FIXME: add more systems.  */
   return Qnil;
-#endif /* HAVE_LINUX_SYSINFO */
+#endif /* HAVE_LINUX_SYSINFO, not WINDOWSNT, not MSDOS */
 }
 
 /* Debugging aids.  */
index baa0358d725dc5456163e70ad22545191dd39771..e557dcba022abb7404d7020b4ca06748372e8cd3 100644 (file)
@@ -640,6 +640,48 @@ system_process_attributes (Lisp_Object pid)
 
   return attrs;
 }
+\f
+/* Support for memory-info.  */
+int
+dos_memory_info (unsigned long *totalram, unsigned long *freeram,
+                unsigned long *totalswap, unsigned long *freeswap)
+{
+  _go32_dpmi_meminfo info;
+  unsigned long mem1, mem2, freemem;
+
+  _go32_dpmi_get_free_memory_information (&info);
+  /* 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.  */
+  mem1 = info.available_memory;
+  mem2 = info.available_physical_pages;
+  /* DPMI Spec: "Fields that are unavailable will hold -1."  */
+  if ((long)mem1 == -1L)
+    mem1 = 0;
+  if ((long)mem2 == -1L)
+    mem2 = 0;
+  else
+    mem2 *= 4096;
+  /* Surely, the available memory is at least what we have physically
+     available, right?  */
+  if (mem1 >= mem2)
+    freemem = mem1;
+  else
+    freemem = mem2;
+  *freeram = freemem;
+  *totalswap =
+    ((long)info.max_pages_in_paging_file == -1L)
+    ? 0
+    : info.max_pages_in_paging_file * 4096;
+  *totalram =
+    ((long)info.total_physical_pages == -1L)
+    ? (freemem + (unsigned long)sbrk (0) + *totalswap)
+    : info.total_physical_pages * 4096;
+  *freeswap = 0;
+  return 0;
+}
+
 \f
 void
 dos_cleanup (void)
index 3409b2247b7463191a0d1fc30963b3a12bfadbf8..f32e6342fc93d044eb6d6131e161844aadb74ec0 100644 (file)
@@ -22,7 +22,8 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #define DOS_COUNTRY_INFO 34    /* no of bytes returned by dos int 38h */
 extern unsigned char dos_country_info[DOS_COUNTRY_INFO];
-
+extern int dos_memory_info (unsigned long *, unsigned long *,
+                           unsigned long *, unsigned long *);
 #ifndef HAVE_X_WINDOWS
 extern int         msdos_stdcolor_idx  (const char *);
 extern Lisp_Object msdos_stdcolor_name (int);
index f138dc28b2e3304020935cbfe20803adc7ea85cb..308613f7eb40ba9f51ecf8b62f555cf641aa7ae6 100644 (file)
@@ -21,7 +21,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "lisp.h"
 
 #ifdef MSDOS
-#include <dpmi.h>
+#include "dosfns.h"
 extern int etext;
 #endif
 
@@ -106,29 +106,10 @@ get_lim_data (void)
 void
 get_lim_data (void)
 {
-  _go32_dpmi_meminfo info;
-  unsigned long lim1, lim2;
-
-  _go32_dpmi_get_free_memory_information (&info);
-  /* 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;
-  /* DPMI Spec: "Fields that are unavailable will hold -1."  */
-  if ((long)lim1 == -1L)
-    lim1 = 0;
-  if ((long)lim2 == -1L)
-    lim2 = 0;
-  else
-    lim2 *= 4096;
-  /* Surely, the available memory is at least what we have physically
-     available, right?  */
-  if (lim1 >= lim2)
-    lim_data = lim1;
-  else
-    lim_data = lim2;
+  unsigned long totalram, freeram, totalswap, freeswap;
+
+  dos_memory_info (&totalram, &freeram, &totalswap, &freeswap);
+  lim_data = freeram;
   /* Don't believe they will give us more that 0.5 GB.   */
   if (lim_data > 512U * 1024U * 1024U)
     lim_data = 512U * 1024U * 1024U;