aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Antipov2014-07-10 16:33:35 +0400
committerDmitry Antipov2014-07-10 16:33:35 +0400
commit9242810cd3bb14056dde937fc9ad39fc49261dfd (patch)
treeabd85cf5087ecbb123c3a511d78244fc9d069482
parent80fb41cd90467782f4cfb21074aaa4f95308985e (diff)
downloademacs-9242810cd3bb14056dde937fc9ad39fc49261dfd.tar.gz
emacs-9242810cd3bb14056dde937fc9ad39fc49261dfd.zip
* 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.
-rw-r--r--ChangeLog5
-rw-r--r--configure.ac16
-rw-r--r--lisp/ChangeLog5
-rw-r--r--lisp/files.el19
-rw-r--r--src/ChangeLog2
-rw-r--r--src/alloc.c33
6 files changed, 78 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 8226a138d06..f763607537f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
12014-07-10 Dmitry Antipov <dmantipov@yandex.ru>
2
3 * configure.ac: Check whether sys/sysinfo.h provides
4 Linux 'sysinfo' function and 'struct sysinfo' type.
5
12014-06-28 Glenn Morris <rgm@gnu.org> 62014-06-28 Glenn Morris <rgm@gnu.org>
2 7
3 * configure.ac (lwlib_deps_frag, oldxmenu_deps_frag): New output files. 8 * configure.ac (lwlib_deps_frag, oldxmenu_deps_frag): New output files.
diff --git a/configure.ac b/configure.ac
index 04c75e30df8..fc7a87a075a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1510,6 +1510,7 @@ fi
1510dnl checks for header files 1510dnl checks for header files
1511AC_CHECK_HEADERS_ONCE( 1511AC_CHECK_HEADERS_ONCE(
1512 sys/systeminfo.h 1512 sys/systeminfo.h
1513 sys/sysinfo.h
1513 coff.h pty.h 1514 coff.h pty.h
1514 sys/resource.h 1515 sys/resource.h
1515 sys/utsname.h pwd.h utmp.h util.h) 1516 sys/utsname.h pwd.h utmp.h util.h)
@@ -1525,6 +1526,21 @@ if test $emacs_cv_personality_linux32 = yes; then
1525 [Define to 1 if personality LINUX32 can be set.]) 1526 [Define to 1 if personality LINUX32 can be set.])
1526fi 1527fi
1527 1528
1529if test "$ac_cv_header_sys_sysinfo_h" = yes; then
1530 AC_MSG_CHECKING([if Linux sysinfo may be used])
1531 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/sysinfo.h>]],
1532 [[struct sysinfo si; sysinfo (&si)]])],
1533 emacs_cv_linux_sysinfo=yes, emacs_cv_linux_sysinfo=no)
1534 AC_MSG_RESULT($emacs_cv_linux_sysinfo)
1535 if test $emacs_cv_linux_sysinfo = yes; then
1536 AC_DEFINE([HAVE_LINUX_SYSINFO], 1, [Define to 1 if you have Linux sysinfo function.])
1537 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/sysinfo.h>]],
1538 [[struct sysinfo si; return si.mem_unit]])],
1539 AC_DEFINE(LINUX_SYSINFO_UNIT, 1,
1540 [Define to 1 if Linux sysinfo sizes are in multiples of mem_unit bytes.]))
1541 fi
1542fi
1543
1528dnl On Solaris 8 there's a compilation warning for term.h because 1544dnl On Solaris 8 there's a compilation warning for term.h because
1529dnl it doesn't define `bool'. 1545dnl it doesn't define `bool'.
1530AC_CHECK_HEADERS(term.h, , , -) 1546AC_CHECK_HEADERS(term.h, , , -)
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index d14a3a8584b..ffb1eee945e 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
12014-07-10 Dmitry Antipov <dmantipov@yandex.ru>
2
3 * files.el (warn-maybe-out-of-memory): New function.
4 (find-file-noselect): Use it.
5
12014-07-09 Sam Steingold <sds@gnu.org> 62014-07-09 Sam Steingold <sds@gnu.org>
2 7
3 * progmodes/cperl-mode.el (cperl-block-p): Treat the perl keyword 8 * progmodes/cperl-mode.el (cperl-block-p): Treat the perl keyword
diff --git a/lisp/files.el b/lisp/files.el
index 27d3ec7464e..63bdf636b63 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1796,6 +1796,22 @@ OP-TYPE specifies the file operation being performed (for message to user)."
1796 (file-size-human-readable size) op-type)))) 1796 (file-size-human-readable size) op-type))))
1797 (error "Aborted"))) 1797 (error "Aborted")))
1798 1798
1799(defun warn-maybe-out-of-memory (size)
1800 "Warn if an attempt to open file of SIZE bytes may run out of memory."
1801 (let ((meminfo (memory-info)))
1802 (when (consp meminfo)
1803 (let ((total-free-memory (+ (nth 1 meminfo) (nth 3 meminfo))))
1804 (when (and (not (zerop size))
1805 (> (/ size 1024) total-free-memory))
1806 (warn
1807 "You are trying to open file which size (%s)
1808exceeds an amount of available free memory (%s). If that
1809fails, try to open it with `find-file-literally' (but note
1810that some characters may be displayed incorrectly)."
1811 (file-size-human-readable size)
1812 (file-size-human-readable
1813 (* (float total-free-memory) 1024))))))))
1814
1799(defun find-file-noselect (filename &optional nowarn rawfile wildcards) 1815(defun find-file-noselect (filename &optional nowarn rawfile wildcards)
1800 "Read file FILENAME into a buffer and return the buffer. 1816 "Read file FILENAME into a buffer and return the buffer.
1801If a buffer exists visiting FILENAME, return that one, but 1817If a buffer exists visiting FILENAME, return that one, but
@@ -1848,7 +1864,8 @@ the various files."
1848 (setq buf other)))) 1864 (setq buf other))))
1849 ;; Check to see if the file looks uncommonly large. 1865 ;; Check to see if the file looks uncommonly large.
1850 (when (not (or buf nowarn)) 1866 (when (not (or buf nowarn))
1851 (abort-if-file-too-large (nth 7 attributes) "open" filename)) 1867 (abort-if-file-too-large (nth 7 attributes) "open" filename)
1868 (warn-maybe-out-of-memory (nth 7 attributes)))
1852 (if buf 1869 (if buf
1853 ;; We are using an existing buffer. 1870 ;; We are using an existing buffer.
1854 (let (nonexistent) 1871 (let (nonexistent)
diff --git a/src/ChangeLog b/src/ChangeLog
index 541697c5567..87a8f1c7814 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -9,6 +9,8 @@
9 (decode_coding_big5, decode_coding_charset, decode_coding) 9 (decode_coding_big5, decode_coding_charset, decode_coding)
10 (encode_coding): Adjust users. 10 (encode_coding): Adjust users.
11 11
12 * alloc.c (Fmemory_info): New function.
13
122014-07-09 Paul Eggert <eggert@cs.ucla.edu> 142014-07-09 Paul Eggert <eggert@cs.ucla.edu>
13 15
14 * syntax.c (back_comment): Use more-natural location for label. 16 * syntax.c (back_comment): Use more-natural location for label.
diff --git a/src/alloc.c b/src/alloc.c
index 6eb2e756ed1..c535e836397 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -49,6 +49,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
49#include <verify.h> 49#include <verify.h>
50#include <execinfo.h> /* For backtrace. */ 50#include <execinfo.h> /* For backtrace. */
51 51
52#ifdef HAVE_LINUX_SYSINFO
53#include <sys/sysinfo.h>
54#endif
55
52#if (defined ENABLE_CHECKING \ 56#if (defined ENABLE_CHECKING \
53 && defined HAVE_VALGRIND_VALGRIND_H \ 57 && defined HAVE_VALGRIND_VALGRIND_H \
54 && !defined USE_VALGRIND) 58 && !defined USE_VALGRIND)
@@ -6865,7 +6869,33 @@ gc_sweep (void)
6865 check_string_bytes (!noninteractive); 6869 check_string_bytes (!noninteractive);
6866} 6870}
6867 6871
6868 6872DEFUN ("memory-info", Fmemory_info, Smemory_info, 0, 0, 0,
6873 doc: /* Return a list of (TOTAL-RAM FREE-RAM TOTAL-SWAP FREE-SWAP).
6874All values are in Kbytes. If there is no swap space, last two
6875values are zero. If the system is not supported, return nil. */)
6876 (void)
6877{
6878#ifdef HAVE_LINUX_SYSINFO
6879 struct sysinfo si;
6880 uintmax_t units;
6881
6882 if (sysinfo (&si))
6883 emacs_abort ();
6884#ifdef LINUX_SYSINFO_UNIT
6885 units = si.mem_unit;
6886#else
6887 units = 1;
6888#endif
6889 return list4i ((uintmax_t) si.totalram * units / 1024,
6890 (uintmax_t) si.freeram * units / 1024,
6891 (uintmax_t) si.totalswap * units / 1024,
6892 (uintmax_t) si.freeswap * units / 1024);
6893#else /* not HAVE_LINUX_SYSINFO */
6894 /* FIXME: add more systems. */
6895 return Qnil;
6896#endif /* HAVE_LINUX_SYSINFO */
6897}
6898
6869/* Debugging aids. */ 6899/* Debugging aids. */
6870 6900
6871DEFUN ("memory-limit", Fmemory_limit, Smemory_limit, 0, 0, 0, 6901DEFUN ("memory-limit", Fmemory_limit, Smemory_limit, 0, 0, 0,
@@ -7204,6 +7234,7 @@ The time is in seconds as a floating point value. */);
7204 defsubr (&Spurecopy); 7234 defsubr (&Spurecopy);
7205 defsubr (&Sgarbage_collect); 7235 defsubr (&Sgarbage_collect);
7206 defsubr (&Smemory_limit); 7236 defsubr (&Smemory_limit);
7237 defsubr (&Smemory_info);
7207 defsubr (&Smemory_use_counts); 7238 defsubr (&Smemory_use_counts);
7208 defsubr (&Ssuspicious_object); 7239 defsubr (&Ssuspicious_object);
7209 7240