changeset 3634:286ba0251c0a v7.3.577

updated for version 7.3.577 Problem: Size of memory does not fit in 32 bit unsigned. Solution: Use Kbyte instead of byte. Call GlobalMemoryStatusEx() instead of GlobalMemoryStatus() when available.
author Bram Moolenaar <bram@vim.org>
date Fri, 29 Jun 2012 15:51:30 +0200
parents 79053041fb31
children e57accfea24e
files src/misc2.c src/option.c src/os_amiga.c src/os_msdos.c src/os_win16.c src/os_win32.c src/version.c
diffstat 7 files changed, 32 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/misc2.c
+++ b/src/misc2.c
@@ -815,6 +815,7 @@ vim_mem_profile_dump()
 #else
 # define KEEP_ROOM (2 * 8192L)
 #endif
+#define KEEP_ROOM_KB (KEEP_ROOM / 1024L)
 
 /*
  * Note: if unsigned is 16 bits we can only allocate up to 64K with alloc().
@@ -940,7 +941,7 @@ lalloc(size, message)
 	    allocated = 0;
 # endif
 	    /* 3. check for available memory: call mch_avail_mem() */
-	    if (mch_avail_mem(TRUE) < KEEP_ROOM && !releasing)
+	    if (mch_avail_mem(TRUE) < KEEP_ROOM_KB && !releasing)
 	    {
 		free((char *)p);	/* System is low... no go! */
 		p = NULL;
--- a/src/option.c
+++ b/src/option.c
@@ -3154,7 +3154,7 @@ set_init_1()
 	{
 #ifdef HAVE_AVAIL_MEM
 	    /* Use amount of memory available at this moment. */
-	    n = (mch_avail_mem(FALSE) >> 11);
+	    n = (mch_avail_mem(FALSE) >> 1);
 #else
 # ifdef HAVE_TOTAL_MEM
 	    /* Use amount of memory available to Vim. */
@@ -6702,7 +6702,7 @@ did_set_string_option(opt_idx, varp, new
     {
 	for (s = *varp; *s;)
 	{
-	    while(*s == ',' || *s == ' ')
+	    while (*s == ',' || *s == ' ')
 		s++;
 	    if (!*s)
 		break;
@@ -7391,7 +7391,7 @@ check_clipboard_option()
 	    new_unnamed |= CLIP_UNNAMED;
 	    p += 7;
 	}
-        else if (STRNCMP(p, "unnamedplus", 11) == 0
+	else if (STRNCMP(p, "unnamedplus", 11) == 0
 					    && (p[11] == ',' || p[11] == NUL))
 	{
 	    new_unnamed |= CLIP_UNNAMED_PLUS;
--- a/src/os_amiga.c
+++ b/src/os_amiga.c
@@ -191,16 +191,16 @@ mch_char_avail()
 }
 
 /*
- * Return amount of memory still available.
+ * Return amount of memory still available in Kbyte.
  */
     long_u
 mch_avail_mem(special)
     int	    special;
 {
 #ifdef __amigaos4__
-    return (long_u)AvailMem(MEMF_ANY);
+    return (long_u)AvailMem(MEMF_ANY) >> 10;
 #else
-    return (long_u)AvailMem(special ? (long)MEMF_CHIP : (long)MEMF_ANY);
+    return (long_u)(AvailMem(special ? (long)MEMF_CHIP : (long)MEMF_ANY)) >> 10;
 #endif
 }
 
--- a/src/os_msdos.c
+++ b/src/os_msdos.c
@@ -550,15 +550,15 @@ mch_update_cursor(void)
 #endif
 
 /*
- * Return amount of memory currently available.
+ * Return amount of memory currently available in Kbyte.
  */
     long_u
 mch_avail_mem(int special)
 {
 #ifdef DJGPP
-    return _go32_dpmi_remaining_virtual_memory();
+    return _go32_dpmi_remaining_virtual_memory() >> 10;
 #else
-    return coreleft();
+    return coreleft() >> 10;
 #endif
 }
 
--- a/src/os_win16.c
+++ b/src/os_win16.c
@@ -379,13 +379,13 @@ mch_breakcheck()
 
 
 /*
- * How much memory is available?
+ * How much memory is available in Kbyte?
  */
     long_u
 mch_avail_mem(
     int special)
 {
-    return GetFreeSpace(0);
+    return GetFreeSpace(0) >> 10;
 }
 
 
--- a/src/os_win32.c
+++ b/src/os_win32.c
@@ -4992,18 +4992,29 @@ mch_breakcheck(void)
 
 
 /*
- * How much memory is available?
+ * How much memory is available in Kbyte?
  * Return sum of available physical and page file memory.
  */
 /*ARGSUSED*/
     long_u
 mch_avail_mem(int special)
 {
-    MEMORYSTATUS	ms;
-
-    ms.dwLength = sizeof(MEMORYSTATUS);
-    GlobalMemoryStatus(&ms);
-    return (long_u) (ms.dwAvailPhys + ms.dwAvailPageFile);
+    if (g_PlatformId != VER_PLATFORM_WIN32_NT)
+    {
+	MEMORYSTATUS	ms;
+
+	ms.dwLength = sizeof(MEMORYSTATUS);
+	GlobalMemoryStatus(&ms);
+	return (long_u)((ms.dwAvailPhys + ms.dwAvailPageFile) >> 10);
+    }
+    else
+    {
+	MEMORYSTATUSEX	ms;
+
+	ms.dwLength = sizeof(MEMORYSTATUSEX);
+	GlobalMemoryStatusEx(&ms);
+	return (long_u)((ms.ullAvailPhys + ms.ullAvailPageFile) >> 10);
+    }
 }
 
 #ifdef FEAT_MBYTE
--- a/src/version.c
+++ b/src/version.c
@@ -715,6 +715,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    577,
+/**/
     576,
 /**/
     575,