Use Get/SetLastError on Win32

Using errno on win32 doesn't quite work, because the value set in a shared
library can't be read from e.g. an executable calling the function setting
errno.

At the same time, since buferror always uses errno/GetLastError, don't pass
it.
This commit is contained in:
Mike Hommey
2012-04-30 12:38:26 +02:00
committed by Jason Evans
parent af04b744bd
commit a14bce85e8
7 changed files with 71 additions and 33 deletions

View File

@@ -41,7 +41,7 @@ pages_map(void *addr, size_t size)
if (munmap(ret, size) == -1) {
char buf[BUFERROR_BUF];
buferror(errno, buf, sizeof(buf));
buferror(buf, sizeof(buf));
malloc_printf("<jemalloc: Error in munmap(): %s\n",
buf);
if (opt_abort)
@@ -67,7 +67,7 @@ pages_unmap(void *addr, size_t size)
{
char buf[BUFERROR_BUF];
buferror(errno, buf, sizeof(buf));
buferror(buf, sizeof(buf));
malloc_printf("<jemalloc>: Error in "
#ifdef _WIN32
"VirtualFree"

View File

@@ -168,7 +168,7 @@ huge_ralloc(void *ptr, size_t oldsize, size_t size, size_t extra,
*/
char buf[BUFERROR_BUF];
buferror(errno, buf, sizeof(buf));
buferror(buf, sizeof(buf));
malloc_printf("<jemalloc>: Error in mremap(): %s\n",
buf);
if (opt_abort)

View File

@@ -472,9 +472,9 @@ malloc_conf_init(void)
uintmax_t um; \
char *end; \
\
errno = 0; \
set_errno(0); \
um = malloc_strtoumax(v, &end, 0); \
if (errno != 0 || (uintptr_t)end - \
if (get_errno() != 0 || (uintptr_t)end -\
(uintptr_t)v != vlen) { \
malloc_conf_error( \
"Invalid conf value", \
@@ -493,9 +493,9 @@ malloc_conf_init(void)
long l; \
char *end; \
\
errno = 0; \
set_errno(0); \
l = strtol(v, &end, 0); \
if (errno != 0 || (uintptr_t)end - \
if (get_errno() != 0 || (uintptr_t)end -\
(uintptr_t)v != vlen) { \
malloc_conf_error( \
"Invalid conf value", \
@@ -831,7 +831,7 @@ label_oom:
"out of memory\n");
abort();
}
errno = ENOMEM;
set_errno(ENOMEM);
}
if (config_prof && opt_prof && ret != NULL)
prof_malloc(ret, usize, cnt);
@@ -959,7 +959,7 @@ je_aligned_alloc(size_t alignment, size_t size)
if ((err = imemalign(&ret, alignment, size, 1)) != 0) {
ret = NULL;
errno = err;
set_errno(err);
}
JEMALLOC_VALGRIND_MALLOC(err == 0, ret, isalloc(ret, config_prof),
false);
@@ -1029,7 +1029,7 @@ label_return:
"memory\n");
abort();
}
errno = ENOMEM;
set_errno(ENOMEM);
}
if (config_prof && opt_prof && ret != NULL)
@@ -1130,7 +1130,7 @@ label_oom:
"out of memory\n");
abort();
}
errno = ENOMEM;
set_errno(ENOMEM);
}
} else {
/* realloc(NULL, size) is equivalent to malloc(size). */
@@ -1172,7 +1172,7 @@ label_oom:
"out of memory\n");
abort();
}
errno = ENOMEM;
set_errno(ENOMEM);
}
}

View File

@@ -65,7 +65,7 @@ void (*je_malloc_message)(void *, const char *s)
* provide a wrapper.
*/
int
buferror(int errnum, char *buf, size_t buflen)
buferror(char *buf, size_t buflen)
{
#ifdef _WIN32
@@ -93,7 +93,7 @@ malloc_strtoumax(const char *nptr, char **endptr, int base)
const char *p, *ns;
if (base < 0 || base == 1 || base > 36) {
errno = EINVAL;
set_errno(EINVAL);
return (UINTMAX_MAX);
}
b = base;
@@ -168,7 +168,7 @@ malloc_strtoumax(const char *nptr, char **endptr, int base)
ret += digit;
if (ret < pret) {
/* Overflow. */
errno = ERANGE;
set_errno(ERANGE);
return (UINTMAX_MAX);
}
p++;
@@ -416,9 +416,9 @@ malloc_vsnprintf(char *str, size_t size, const char *format, va_list ap)
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9': {
uintmax_t uwidth;
errno = 0;
set_errno(0);
uwidth = malloc_strtoumax(f, (char **)&f, 10);
assert(uwidth != UINTMAX_MAX || errno !=
assert(uwidth != UINTMAX_MAX || get_errno() !=
ERANGE);
width = (int)uwidth;
if (*f == '.') {
@@ -442,9 +442,10 @@ malloc_vsnprintf(char *str, size_t size, const char *format, va_list ap)
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9': {
uintmax_t uprec;
errno = 0;
set_errno(0);
uprec = malloc_strtoumax(f, (char **)&f, 10);
assert(uprec != UINTMAX_MAX || errno != ERANGE);
assert(uprec != UINTMAX_MAX || get_errno() !=
ERANGE);
prec = (int)uprec;
break;
}