Port recent Gnulib changes to MS-Windows
* nt/gnulib-cfg.mk (OMIT_GNULIB_MODULE_free-posix) (OMIT_GNULIB_MODULE_malloc-posix) (OMIT_GNULIB_MODULE_realloc-gnu) (OMIT_GNULIB_MODULE_realloc-posix): New macros, since we don’t want these modules on MS-Windows. * src/w32heap.c (heap_alloc, heap_realloc): New functions. (malloc_after_dump, realloc_after_dump, realloc_before_dump): Use them.
This commit is contained in:
parent
68a256c892
commit
1a65d49931
2 changed files with 30 additions and 16 deletions
|
@ -49,10 +49,14 @@ OMIT_GNULIB_MODULE_dirent = true
|
||||||
OMIT_GNULIB_MODULE_dirfd = true
|
OMIT_GNULIB_MODULE_dirfd = true
|
||||||
OMIT_GNULIB_MODULE_fcntl = true
|
OMIT_GNULIB_MODULE_fcntl = true
|
||||||
OMIT_GNULIB_MODULE_fcntl-h = true
|
OMIT_GNULIB_MODULE_fcntl-h = true
|
||||||
|
OMIT_GNULIB_MODULE_free-posix = true
|
||||||
OMIT_GNULIB_MODULE_fsusage = true
|
OMIT_GNULIB_MODULE_fsusage = true
|
||||||
OMIT_GNULIB_MODULE_inttypes-incomplete = true
|
OMIT_GNULIB_MODULE_inttypes-incomplete = true
|
||||||
|
OMIT_GNULIB_MODULE_malloc-posix = true
|
||||||
OMIT_GNULIB_MODULE_open = true
|
OMIT_GNULIB_MODULE_open = true
|
||||||
OMIT_GNULIB_MODULE_pipe2 = true
|
OMIT_GNULIB_MODULE_pipe2 = true
|
||||||
|
OMIT_GNULIB_MODULE_realloc-gnu = true
|
||||||
|
OMIT_GNULIB_MODULE_realloc-posix = true
|
||||||
OMIT_GNULIB_MODULE_secure_getenv = true
|
OMIT_GNULIB_MODULE_secure_getenv = true
|
||||||
OMIT_GNULIB_MODULE_signal-h = true
|
OMIT_GNULIB_MODULE_signal-h = true
|
||||||
OMIT_GNULIB_MODULE_stdio = true
|
OMIT_GNULIB_MODULE_stdio = true
|
||||||
|
|
|
@ -189,6 +189,26 @@ malloc_fn the_malloc_fn;
|
||||||
realloc_fn the_realloc_fn;
|
realloc_fn the_realloc_fn;
|
||||||
free_fn the_free_fn;
|
free_fn the_free_fn;
|
||||||
|
|
||||||
|
static void *
|
||||||
|
heap_alloc (size_t size)
|
||||||
|
{
|
||||||
|
void *p = size <= PTRDIFF_MAX ? HeapAlloc (heap, 0, size | !size) : NULL;
|
||||||
|
if (!p)
|
||||||
|
errno = ENOMEM;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *
|
||||||
|
heap_realloc (void *ptr, size_t size)
|
||||||
|
{
|
||||||
|
void *p = (size <= PTRDIFF_MAX
|
||||||
|
? HeapReAlloc (heap, 0, ptr, size | !size)
|
||||||
|
: NULL);
|
||||||
|
if (!p)
|
||||||
|
errno = ENOMEM;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
/* It doesn't seem to be useful to allocate from a file mapping.
|
/* It doesn't seem to be useful to allocate from a file mapping.
|
||||||
It would be if the memory was shared.
|
It would be if the memory was shared.
|
||||||
https://stackoverflow.com/questions/307060/what-is-the-purpose-of-allocating-pages-in-the-pagefile-with-createfilemapping */
|
https://stackoverflow.com/questions/307060/what-is-the-purpose-of-allocating-pages-in-the-pagefile-with-createfilemapping */
|
||||||
|
@ -346,7 +366,7 @@ void *
|
||||||
malloc_after_dump (size_t size)
|
malloc_after_dump (size_t size)
|
||||||
{
|
{
|
||||||
/* Use the new private heap. */
|
/* Use the new private heap. */
|
||||||
void *p = HeapAlloc (heap, 0, size);
|
void *p = heap_alloc (size);
|
||||||
|
|
||||||
/* After dump, keep track of the "brk value" for sbrk(0). */
|
/* After dump, keep track of the "brk value" for sbrk(0). */
|
||||||
if (p)
|
if (p)
|
||||||
|
@ -356,8 +376,6 @@ malloc_after_dump (size_t size)
|
||||||
if (new_brk > data_region_end)
|
if (new_brk > data_region_end)
|
||||||
data_region_end = new_brk;
|
data_region_end = new_brk;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
errno = ENOMEM;
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,9 +391,7 @@ malloc_before_dump (size_t size)
|
||||||
if (size < MaxBlockSize)
|
if (size < MaxBlockSize)
|
||||||
{
|
{
|
||||||
/* Use the private heap if possible. */
|
/* Use the private heap if possible. */
|
||||||
p = HeapAlloc (heap, 0, size);
|
p = heap_alloc (size);
|
||||||
if (!p)
|
|
||||||
errno = ENOMEM;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -433,18 +449,14 @@ realloc_after_dump (void *ptr, size_t size)
|
||||||
if (FREEABLE_P (ptr))
|
if (FREEABLE_P (ptr))
|
||||||
{
|
{
|
||||||
/* Reallocate the block since it lies in the new heap. */
|
/* Reallocate the block since it lies in the new heap. */
|
||||||
p = HeapReAlloc (heap, 0, ptr, size);
|
p = heap_realloc (ptr, size);
|
||||||
if (!p)
|
|
||||||
errno = ENOMEM;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* If the block lies in the dumped data, do not free it. Only
|
/* If the block lies in the dumped data, do not free it. Only
|
||||||
allocate a new one. */
|
allocate a new one. */
|
||||||
p = HeapAlloc (heap, 0, size);
|
p = heap_alloc (size);
|
||||||
if (!p)
|
if (p && ptr)
|
||||||
errno = ENOMEM;
|
|
||||||
else if (ptr)
|
|
||||||
CopyMemory (p, ptr, size);
|
CopyMemory (p, ptr, size);
|
||||||
}
|
}
|
||||||
/* After dump, keep track of the "brk value" for sbrk(0). */
|
/* After dump, keep track of the "brk value" for sbrk(0). */
|
||||||
|
@ -467,9 +479,7 @@ realloc_before_dump (void *ptr, size_t size)
|
||||||
if (dumped_data < (unsigned char *)ptr
|
if (dumped_data < (unsigned char *)ptr
|
||||||
&& (unsigned char *)ptr < bc_limit && size <= MaxBlockSize)
|
&& (unsigned char *)ptr < bc_limit && size <= MaxBlockSize)
|
||||||
{
|
{
|
||||||
p = HeapReAlloc (heap, 0, ptr, size);
|
p = heap_realloc (ptr, size);
|
||||||
if (!p)
|
|
||||||
errno = ENOMEM;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue