summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/auto/configure56
-rw-r--r--src/config.h.in1
-rw-r--r--src/configure.in11
-rw-r--r--src/option.c2
-rw-r--r--src/os_unix.c38
-rw-r--r--src/version.c2
6 files changed, 102 insertions, 8 deletions
diff --git a/src/auto/configure b/src/auto/configure
index 43c161bdf..5659d38a0 100755
--- a/src/auto/configure
+++ b/src/auto/configure
@@ -13688,6 +13688,62 @@ echo "${ECHO_T}not usable" >&6
fi
rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+echo "$as_me:$LINENO: checking for sysinfo.mem_unit" >&5
+echo $ECHO_N "checking for sysinfo.mem_unit... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+#include <sys/types.h>
+#include <sys/sysinfo.h>
+int
+main ()
+{
+ struct sysinfo sinfo;
+ sinfo.mem_unit = 1;
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; cat >>confdefs.h <<\_ACEOF
+#define HAVE_SYSINFO_MEM_UNIT 1
+_ACEOF
+
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
echo "$as_me:$LINENO: checking for sysconf" >&5
echo $ECHO_N "checking for sysconf... $ECHO_C" >&6
cat >conftest.$ac_ext <<_ACEOF
diff --git a/src/config.h.in b/src/config.h.in
index 9b42b92ef..3d9e16212 100644
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -176,6 +176,7 @@
#undef HAVE_SYSCONF
#undef HAVE_SYSCTL
#undef HAVE_SYSINFO
+#undef HAVE_SYSINFO_MEM_UNIT
#undef HAVE_TGETENT
#undef HAVE_TOWLOWER
#undef HAVE_TOWUPPER
diff --git a/src/configure.in b/src/configure.in
index 66f629521..0af26bdd1 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -2590,6 +2590,17 @@ AC_TRY_COMPILE(
AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYSINFO),
AC_MSG_RESULT(not usable))
+dnl struct sysinfo may have the mem_unit field or not
+AC_MSG_CHECKING(for sysinfo.mem_unit)
+AC_TRY_COMPILE(
+[#include <sys/types.h>
+#include <sys/sysinfo.h>],
+[ struct sysinfo sinfo;
+ sinfo.mem_unit = 1;
+ ],
+ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYSINFO_MEM_UNIT),
+ AC_MSG_RESULT(no))
+
dnl sysconf() may exist but not support what we want to use
AC_MSG_CHECKING(for sysconf)
AC_TRY_COMPILE(
diff --git a/src/option.c b/src/option.c
index 3be561206..87cf5f6d2 100644
--- a/src/option.c
+++ b/src/option.c
@@ -3030,7 +3030,7 @@ set_init_1()
#else
# ifdef HAVE_TOTAL_MEM
/* Use amount of memory available to Vim. */
- n = (mch_total_mem(FALSE) >> 11);
+ n = (mch_total_mem(FALSE) >> 1);
# else
n = (0x7fffffff >> 11);
# endif
diff --git a/src/os_unix.c b/src/os_unix.c
index 5195b6b7b..a18845291 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -428,8 +428,8 @@ mch_char_avail()
# endif
/*
- * Return total amount of memory available. Doesn't change when memory has
- * been allocated.
+ * Return total amount of memory available in Kbyte.
+ * Doesn't change when memory has been allocated.
*/
/* ARGSUSED */
long_u
@@ -437,9 +437,10 @@ mch_total_mem(special)
int special;
{
# ifdef __EMX__
- return ulimit(3, 0L); /* always 32MB? */
+ return ulimit(3, 0L) >> 10; /* always 32MB? */
# else
long_u mem = 0;
+ long_u shiftright = 10; /* how much to shift "mem" right for Kbyte */
# ifdef HAVE_SYSCTL
int mib[2], physmem;
@@ -460,7 +461,19 @@ mch_total_mem(special)
/* Linux way of getting amount of RAM available */
if (sysinfo(&sinfo) == 0)
+ {
+# ifdef HAVE_SYSINFO_MEM_UNIT
+ /* avoid overflow as much as possible */
+ while (shiftright > 0 && (sinfo.mem_unit & 1) == 0)
+ {
+ sinfo.mem_unit = sinfo.mem_unit >> 1;
+ --shiftright;
+ }
+ mem = sinfo.totalram * sinfo.mem_unit;
+# else
mem = sinfo.totalram;
+# endif
+ }
}
# endif
@@ -473,7 +486,15 @@ mch_total_mem(special)
pagesize = sysconf(_SC_PAGESIZE);
pagecount = sysconf(_SC_PHYS_PAGES);
if (pagesize > 0 && pagecount > 0)
+ {
+ /* avoid overflow as much as possible */
+ while (shiftright > 0 && (pagesize & 1) == 0)
+ {
+ pagesize = pagesize >> 1;
+ --shiftright;
+ }
mem = (long_u)pagesize * pagecount;
+ }
}
# endif
@@ -488,15 +509,18 @@ mch_total_mem(special)
# ifdef RLIM_INFINITY
&& rlp.rlim_cur != RLIM_INFINITY
# endif
- && (long_u)rlp.rlim_cur < mem
+ && ((long_u)rlp.rlim_cur >> 10) < (mem >> shiftright)
)
- return (long_u)rlp.rlim_cur;
+ {
+ mem = (long_u)rlp.rlim_cur;
+ shiftright = 10;
+ }
}
# endif
if (mem > 0)
- return mem;
- return (long_u)0x7fffffff;
+ return mem >> shiftright;
+ return (long_u)0x1fffff;
# endif
}
#endif
diff --git a/src/version.c b/src/version.c
index 8e6c5504e..4152b506b 100644
--- a/src/version.c
+++ b/src/version.c
@@ -667,6 +667,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 236,
+/**/
235,
/**/
234,