0
0
mirror of https://github.com/vim/vim.git synced 2025-09-27 04:14:06 -04:00

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.
This commit is contained in:
Bram Moolenaar
2012-06-29 15:51:30 +02:00
parent 96b7ca5142
commit 11b73d668f
7 changed files with 31 additions and 17 deletions

View File

@@ -815,6 +815,7 @@ vim_mem_profile_dump()
#else #else
# define KEEP_ROOM (2 * 8192L) # define KEEP_ROOM (2 * 8192L)
#endif #endif
#define KEEP_ROOM_KB (KEEP_ROOM / 1024L)
/* /*
* Note: if unsigned is 16 bits we can only allocate up to 64K with alloc(). * Note: if unsigned is 16 bits we can only allocate up to 64K with alloc().
@@ -940,7 +941,7 @@ lalloc(size, message)
allocated = 0; allocated = 0;
# endif # endif
/* 3. check for available memory: call mch_avail_mem() */ /* 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! */ free((char *)p); /* System is low... no go! */
p = NULL; p = NULL;

View File

@@ -3154,7 +3154,7 @@ set_init_1()
{ {
#ifdef HAVE_AVAIL_MEM #ifdef HAVE_AVAIL_MEM
/* Use amount of memory available at this moment. */ /* Use amount of memory available at this moment. */
n = (mch_avail_mem(FALSE) >> 11); n = (mch_avail_mem(FALSE) >> 1);
#else #else
# ifdef HAVE_TOTAL_MEM # ifdef HAVE_TOTAL_MEM
/* Use amount of memory available to Vim. */ /* Use amount of memory available to Vim. */

View File

@@ -191,16 +191,16 @@ mch_char_avail()
} }
/* /*
* Return amount of memory still available. * Return amount of memory still available in Kbyte.
*/ */
long_u long_u
mch_avail_mem(special) mch_avail_mem(special)
int special; int special;
{ {
#ifdef __amigaos4__ #ifdef __amigaos4__
return (long_u)AvailMem(MEMF_ANY); return (long_u)AvailMem(MEMF_ANY) >> 10;
#else #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 #endif
} }

View File

@@ -550,15 +550,15 @@ mch_update_cursor(void)
#endif #endif
/* /*
* Return amount of memory currently available. * Return amount of memory currently available in Kbyte.
*/ */
long_u long_u
mch_avail_mem(int special) mch_avail_mem(int special)
{ {
#ifdef DJGPP #ifdef DJGPP
return _go32_dpmi_remaining_virtual_memory(); return _go32_dpmi_remaining_virtual_memory() >> 10;
#else #else
return coreleft(); return coreleft() >> 10;
#endif #endif
} }

View File

@@ -379,13 +379,13 @@ mch_breakcheck()
/* /*
* How much memory is available? * How much memory is available in Kbyte?
*/ */
long_u long_u
mch_avail_mem( mch_avail_mem(
int special) int special)
{ {
return GetFreeSpace(0); return GetFreeSpace(0) >> 10;
} }

View File

@@ -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. * Return sum of available physical and page file memory.
*/ */
/*ARGSUSED*/ /*ARGSUSED*/
long_u long_u
mch_avail_mem(int special) mch_avail_mem(int special)
{
if (g_PlatformId != VER_PLATFORM_WIN32_NT)
{ {
MEMORYSTATUS ms; MEMORYSTATUS ms;
ms.dwLength = sizeof(MEMORYSTATUS); ms.dwLength = sizeof(MEMORYSTATUS);
GlobalMemoryStatus(&ms); GlobalMemoryStatus(&ms);
return (long_u) (ms.dwAvailPhys + ms.dwAvailPageFile); 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 #ifdef FEAT_MBYTE

View File

@@ -714,6 +714,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
577,
/**/ /**/
576, 576,
/**/ /**/