Fix MinGW-related portability issues.

Create and use FMT* macros that are equivalent to the PRI* macros that
inttypes.h defines.  This allows uniform use of the Unix-specific format
specifiers, e.g. "%zu", as well as avoiding Windows-specific definitions
of e.g. PRIu64.

Add ffs()/ffsl() support for compiling with gcc.

Extract compatibility definitions of ENOENT, EINVAL, EAGAIN, EPERM,
ENOMEM, and ENORANGE into include/msvc_compat/windows_extra.h and
use the file for tests as well as for core jemalloc code.
This commit is contained in:
Jason Evans
2015-07-23 13:56:25 -07:00
parent e475ff1600
commit 5fae7dc1b3
18 changed files with 224 additions and 494 deletions

View File

@@ -4,27 +4,8 @@
#include <math.h>
#ifdef _WIN32
# include <windows.h>
# ifndef ENOENT
# define ENOENT ERROR_PATH_NOT_FOUND
# endif
# ifndef EINVAL
# define EINVAL ERROR_BAD_ARGUMENTS
# endif
# ifndef EAGAIN
# define EAGAIN ERROR_OUTOFMEMORY
# endif
# ifndef EPERM
# define EPERM ERROR_WRITE_FAULT
# endif
# ifndef EFAULT
# define EFAULT ERROR_INVALID_ADDRESS
# endif
# ifndef ENOMEM
# define ENOMEM ERROR_NOT_ENOUGH_MEMORY
# endif
# ifndef ERANGE
# define ERANGE ERROR_INVALID_DATA
# endif
# include "msvc_compat/windows_extra.h"
#else
# include <sys/param.h>
# include <sys/mman.h>
@@ -53,16 +34,6 @@
#ifndef offsetof
# define offsetof(type, member) ((size_t)&(((type *)NULL)->member))
#endif
#include <inttypes.h>
#ifdef _WIN32
# define PRIzu "Iu"
# define PRIzd "Id"
# define PRIzx "Ix"
#else
# define PRIzu "zu"
# define PRIzd "zd"
# define PRIzx "zx"
#endif
#include <string.h>
#include <strings.h>
#include <ctype.h>

View File

@@ -1,6 +1,47 @@
/******************************************************************************/
#ifdef JEMALLOC_H_TYPES
#ifdef _WIN32
# ifdef _WIN64
# define FMT64_PREFIX "ll"
# define FMTPTR_PREFIX "ll"
# else
# define FMT64_PREFIX "ll"
# define FMTPTR_PREFIX ""
# endif
# define FMTd32 "d"
# define FMTu32 "u"
# define FMTx32 "x"
# define FMTd64 FMT64_PREFIX "d"
# define FMTu64 FMT64_PREFIX "u"
# define FMTx64 FMT64_PREFIX "x"
# define FMTdPTR FMTPTR_PREFIX "d"
# define FMTuPTR FMTPTR_PREFIX "u"
# define FMTxPTR FMTPTR_PREFIX "x"
#else
# include <inttypes.h>
# define FMTd32 PRId32
# define FMTu32 PRIu32
# define FMTx32 PRIx32
# define FMTd64 PRId64
# define FMTu64 PRIu64
# define FMTx64 PRIx64
# define FMTdPTR PRIdPTR
# define FMTuPTR PRIuPTR
# define FMTxPTR PRIxPTR
/* Prevent PRI* macros from accidentally being used. */
# undef PRId32
# undef PRIu32
# undef PRIx32
# undef PRId64
# undef PRIu64
# undef PRIx64
# undef PRIdPTR
# undef PRIuPTR
# undef PRIxPTR
#endif
/* Size of stack-allocated buffer passed to buferror(). */
#define BUFERROR_BUF 64