emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] trunk r117507: * configure.ac: Check whether sys/sysinfo.h


From: Dmitry Antipov
Subject: [Emacs-diffs] trunk r117507: * configure.ac: Check whether sys/sysinfo.h provides
Date: Thu, 10 Jul 2014 12:34:23 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 117507
revision-id: address@hidden
parent: address@hidden
committer: Dmitry Antipov <address@hidden>
branch nick: trunk
timestamp: Thu 2014-07-10 16:33:35 +0400
message:
  * configure.ac: Check whether sys/sysinfo.h provides
  Linux 'sysinfo' function and 'struct sysinfo' type.
  * src/alloc.c (Fmemory_info): New function.
  * lisp/files.el (warn-maybe-out-of-memory): New function.
  (find-file-noselect): Use it.
modified:
  ChangeLog                      changelog-20091113204419-o5vbwnq5f7feedwu-1538
  configure.ac                   
configure.in-20091113204419-o5vbwnq5f7feedwu-783
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/files.el                  files.el-20091113204419-o5vbwnq5f7feedwu-265
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/alloc.c                    alloc.c-20091113204419-o5vbwnq5f7feedwu-252
=== modified file 'ChangeLog'
--- a/ChangeLog 2014-06-28 22:57:23 +0000
+++ b/ChangeLog 2014-07-10 12:33:35 +0000
@@ -1,3 +1,8 @@
+2014-07-10  Dmitry Antipov  <address@hidden>
+
+       * configure.ac: Check whether sys/sysinfo.h provides
+       Linux 'sysinfo' function and 'struct sysinfo' type.
+
 2014-06-28  Glenn Morris  <address@hidden>
 
        * configure.ac (lwlib_deps_frag, oldxmenu_deps_frag): New output files.

=== modified file 'configure.ac'
--- a/configure.ac      2014-06-28 22:57:23 +0000
+++ b/configure.ac      2014-07-10 12:33:35 +0000
@@ -1510,6 +1510,7 @@
 dnl checks for header files
 AC_CHECK_HEADERS_ONCE(
   sys/systeminfo.h
+  sys/sysinfo.h
   coff.h pty.h
   sys/resource.h
   sys/utsname.h pwd.h utmp.h util.h)
@@ -1525,6 +1526,21 @@
             [Define to 1 if personality LINUX32 can be set.])
 fi
 
+if test "$ac_cv_header_sys_sysinfo_h" = yes; then
+  AC_MSG_CHECKING([if Linux sysinfo may be used])
+  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/sysinfo.h>]],
+                                     [[struct sysinfo si; sysinfo (&si)]])],
+    emacs_cv_linux_sysinfo=yes, emacs_cv_linux_sysinfo=no)
+  AC_MSG_RESULT($emacs_cv_linux_sysinfo)
+  if test $emacs_cv_linux_sysinfo = yes; then
+    AC_DEFINE([HAVE_LINUX_SYSINFO], 1, [Define to 1 if you have Linux sysinfo 
function.])
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/sysinfo.h>]],
+                                       [[struct sysinfo si; return 
si.mem_unit]])],
+      AC_DEFINE(LINUX_SYSINFO_UNIT, 1,
+                [Define to 1 if Linux sysinfo sizes are in multiples of 
mem_unit bytes.]))
+  fi
+fi  
+
 dnl On Solaris 8 there's a compilation warning for term.h because
 dnl it doesn't define `bool'.
 AC_CHECK_HEADERS(term.h, , , -)

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2014-07-09 14:51:52 +0000
+++ b/lisp/ChangeLog    2014-07-10 12:33:35 +0000
@@ -1,3 +1,8 @@
+2014-07-10  Dmitry Antipov  <address@hidden>
+
+       * files.el (warn-maybe-out-of-memory): New function.
+       (find-file-noselect): Use it.
+
 2014-07-09  Sam Steingold  <address@hidden>
 
        * progmodes/cperl-mode.el (cperl-block-p): Treat the perl keyword

=== modified file 'lisp/files.el'
--- a/lisp/files.el     2014-06-28 01:10:27 +0000
+++ b/lisp/files.el     2014-07-10 12:33:35 +0000
@@ -1796,6 +1796,22 @@
                                    (file-size-human-readable size) op-type))))
     (error "Aborted")))
 
+(defun warn-maybe-out-of-memory (size)
+  "Warn if an attempt to open file of SIZE bytes may run out of memory."
+  (let ((meminfo (memory-info)))
+    (when (consp meminfo)
+      (let ((total-free-memory (+ (nth 1 meminfo) (nth 3 meminfo))))
+       (when (and (not (zerop size))
+                  (> (/ size 1024) total-free-memory))
+         (warn
+          "You are trying to open file which size (%s)
+exceeds an amount of available free memory (%s).  If that
+fails, try to open it with `find-file-literally' (but note
+that some characters may be displayed incorrectly)."
+          (file-size-human-readable size)
+          (file-size-human-readable
+           (* (float total-free-memory) 1024))))))))
+
 (defun find-file-noselect (filename &optional nowarn rawfile wildcards)
   "Read file FILENAME into a buffer and return the buffer.
 If a buffer exists visiting FILENAME, return that one, but
@@ -1848,7 +1864,8 @@
                  (setq buf other))))
        ;; Check to see if the file looks uncommonly large.
        (when (not (or buf nowarn))
-         (abort-if-file-too-large (nth 7 attributes) "open" filename))
+         (abort-if-file-too-large (nth 7 attributes) "open" filename)
+         (warn-maybe-out-of-memory (nth 7 attributes)))
        (if buf
            ;; We are using an existing buffer.
            (let (nonexistent)

=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2014-07-10 04:35:55 +0000
+++ b/src/ChangeLog     2014-07-10 12:33:35 +0000
@@ -9,6 +9,8 @@
        (decode_coding_big5, decode_coding_charset, decode_coding)
        (encode_coding): Adjust users.
 
+       * alloc.c (Fmemory_info): New function.
+
 2014-07-09  Paul Eggert  <address@hidden>
 
        * syntax.c (back_comment): Use more-natural location for label.

=== modified file 'src/alloc.c'
--- a/src/alloc.c       2014-07-02 03:26:19 +0000
+++ b/src/alloc.c       2014-07-10 12:33:35 +0000
@@ -49,6 +49,10 @@
 #include <verify.h>
 #include <execinfo.h>           /* For backtrace.  */
 
+#ifdef HAVE_LINUX_SYSINFO
+#include <sys/sysinfo.h>
+#endif
+
 #if (defined ENABLE_CHECKING                   \
      && defined HAVE_VALGRIND_VALGRIND_H       \
      && !defined USE_VALGRIND)
@@ -6865,7 +6869,33 @@
   check_string_bytes (!noninteractive);
 }
 
-
+DEFUN ("memory-info", Fmemory_info, Smemory_info, 0, 0, 0,
+       doc: /* Return a list of (TOTAL-RAM FREE-RAM TOTAL-SWAP FREE-SWAP).
+All values are in Kbytes.  If there is no swap space, last two
+values are zero.  If the system is not supported, return nil.  */)
+  (void)
+{
+#ifdef HAVE_LINUX_SYSINFO
+  struct sysinfo si;
+  uintmax_t units;
+
+  if (sysinfo (&si))
+    emacs_abort ();
+#ifdef LINUX_SYSINFO_UNIT
+  units = si.mem_unit;
+#else
+  units = 1;
+#endif  
+  return list4i ((uintmax_t) si.totalram * units / 1024,
+                (uintmax_t) si.freeram * units / 1024,
+                (uintmax_t) si.totalswap * units / 1024,
+                (uintmax_t) si.freeswap * units / 1024);
+#else /* not HAVE_LINUX_SYSINFO */
+  /* FIXME: add more systems.  */
+  return Qnil;
+#endif /* HAVE_LINUX_SYSINFO */
+}
+
 /* Debugging aids.  */
 
 DEFUN ("memory-limit", Fmemory_limit, Smemory_limit, 0, 0, 0,
@@ -7204,6 +7234,7 @@
   defsubr (&Spurecopy);
   defsubr (&Sgarbage_collect);
   defsubr (&Smemory_limit);
+  defsubr (&Smemory_info);
   defsubr (&Smemory_use_counts);
   defsubr (&Ssuspicious_object);
 


reply via email to

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