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> #include <math.h>
#ifdef _WIN32 #ifdef _WIN32
# include <windows.h> # include <windows.h>
# ifndef ENOENT # include "msvc_compat/windows_extra.h"
# 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
#else #else
# include <sys/param.h> # include <sys/param.h>
# include <sys/mman.h> # include <sys/mman.h>
@ -53,16 +34,6 @@
#ifndef offsetof #ifndef offsetof
# define offsetof(type, member) ((size_t)&(((type *)NULL)->member)) # define offsetof(type, member) ((size_t)&(((type *)NULL)->member))
#endif #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 <string.h>
#include <strings.h> #include <strings.h>
#include <ctype.h> #include <ctype.h>

View File

@ -1,6 +1,47 @@
/******************************************************************************/ /******************************************************************************/
#ifdef JEMALLOC_H_TYPES #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(). */ /* Size of stack-allocated buffer passed to buferror(). */
#define BUFERROR_BUF 64 #define BUFERROR_BUF 64

View File

@ -1,313 +0,0 @@
// ISO C9x compliant inttypes.h for Microsoft Visual Studio
// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
//
// Copyright (c) 2006 Alexander Chemeris
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. The name of the author may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef _MSC_VER // [
#error "Use this header only with Microsoft Visual C++ compilers!"
#endif // _MSC_VER ]
#ifndef _MSC_INTTYPES_H_ // [
#define _MSC_INTTYPES_H_
#if _MSC_VER > 1000
#pragma once
#endif
#include "stdint.h"
// 7.8 Format conversion of integer types
typedef struct {
intmax_t quot;
intmax_t rem;
} imaxdiv_t;
// 7.8.1 Macros for format specifiers
#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198
#ifdef _WIN64
# define __PRI64_PREFIX "l"
# define __PRIPTR_PREFIX "l"
#else
# define __PRI64_PREFIX "ll"
# define __PRIPTR_PREFIX
#endif
// The fprintf macros for signed integers are:
#define PRId8 "d"
#define PRIi8 "i"
#define PRIdLEAST8 "d"
#define PRIiLEAST8 "i"
#define PRIdFAST8 "d"
#define PRIiFAST8 "i"
#define PRId16 "hd"
#define PRIi16 "hi"
#define PRIdLEAST16 "hd"
#define PRIiLEAST16 "hi"
#define PRIdFAST16 "hd"
#define PRIiFAST16 "hi"
#define PRId32 "d"
#define PRIi32 "i"
#define PRIdLEAST32 "d"
#define PRIiLEAST32 "i"
#define PRIdFAST32 "d"
#define PRIiFAST32 "i"
#define PRId64 __PRI64_PREFIX "d"
#define PRIi64 __PRI64_PREFIX "i"
#define PRIdLEAST64 __PRI64_PREFIX "d"
#define PRIiLEAST64 __PRI64_PREFIX "i"
#define PRIdFAST64 __PRI64_PREFIX "d"
#define PRIiFAST64 __PRI64_PREFIX "i"
#define PRIdMAX __PRI64_PREFIX "d"
#define PRIiMAX __PRI64_PREFIX "i"
#define PRIdPTR __PRIPTR_PREFIX "d"
#define PRIiPTR __PRIPTR_PREFIX "i"
// The fprintf macros for unsigned integers are:
#define PRIo8 "o"
#define PRIu8 "u"
#define PRIx8 "x"
#define PRIX8 "X"
#define PRIoLEAST8 "o"
#define PRIuLEAST8 "u"
#define PRIxLEAST8 "x"
#define PRIXLEAST8 "X"
#define PRIoFAST8 "o"
#define PRIuFAST8 "u"
#define PRIxFAST8 "x"
#define PRIXFAST8 "X"
#define PRIo16 "ho"
#define PRIu16 "hu"
#define PRIx16 "hx"
#define PRIX16 "hX"
#define PRIoLEAST16 "ho"
#define PRIuLEAST16 "hu"
#define PRIxLEAST16 "hx"
#define PRIXLEAST16 "hX"
#define PRIoFAST16 "ho"
#define PRIuFAST16 "hu"
#define PRIxFAST16 "hx"
#define PRIXFAST16 "hX"
#define PRIo32 "o"
#define PRIu32 "u"
#define PRIx32 "x"
#define PRIX32 "X"
#define PRIoLEAST32 "o"
#define PRIuLEAST32 "u"
#define PRIxLEAST32 "x"
#define PRIXLEAST32 "X"
#define PRIoFAST32 "o"
#define PRIuFAST32 "u"
#define PRIxFAST32 "x"
#define PRIXFAST32 "X"
#define PRIo64 __PRI64_PREFIX "o"
#define PRIu64 __PRI64_PREFIX "u"
#define PRIx64 __PRI64_PREFIX "x"
#define PRIX64 __PRI64_PREFIX "X"
#define PRIoLEAST64 __PRI64_PREFIX "o"
#define PRIuLEAST64 __PRI64_PREFIX "u"
#define PRIxLEAST64 __PRI64_PREFIX "x"
#define PRIXLEAST64 __PRI64_PREFIX "X"
#define PRIoFAST64 __PRI64_PREFIX "o"
#define PRIuFAST64 __PRI64_PREFIX "u"
#define PRIxFAST64 __PRI64_PREFIX "x"
#define PRIXFAST64 __PRI64_PREFIX "X"
#define PRIoMAX __PRI64_PREFIX "o"
#define PRIuMAX __PRI64_PREFIX "u"
#define PRIxMAX __PRI64_PREFIX "x"
#define PRIXMAX __PRI64_PREFIX "X"
#define PRIoPTR __PRIPTR_PREFIX "o"
#define PRIuPTR __PRIPTR_PREFIX "u"
#define PRIxPTR __PRIPTR_PREFIX "x"
#define PRIXPTR __PRIPTR_PREFIX "X"
// The fscanf macros for signed integers are:
#define SCNd8 "d"
#define SCNi8 "i"
#define SCNdLEAST8 "d"
#define SCNiLEAST8 "i"
#define SCNdFAST8 "d"
#define SCNiFAST8 "i"
#define SCNd16 "hd"
#define SCNi16 "hi"
#define SCNdLEAST16 "hd"
#define SCNiLEAST16 "hi"
#define SCNdFAST16 "hd"
#define SCNiFAST16 "hi"
#define SCNd32 "ld"
#define SCNi32 "li"
#define SCNdLEAST32 "ld"
#define SCNiLEAST32 "li"
#define SCNdFAST32 "ld"
#define SCNiFAST32 "li"
#define SCNd64 "I64d"
#define SCNi64 "I64i"
#define SCNdLEAST64 "I64d"
#define SCNiLEAST64 "I64i"
#define SCNdFAST64 "I64d"
#define SCNiFAST64 "I64i"
#define SCNdMAX "I64d"
#define SCNiMAX "I64i"
#ifdef _WIN64 // [
# define SCNdPTR "I64d"
# define SCNiPTR "I64i"
#else // _WIN64 ][
# define SCNdPTR "ld"
# define SCNiPTR "li"
#endif // _WIN64 ]
// The fscanf macros for unsigned integers are:
#define SCNo8 "o"
#define SCNu8 "u"
#define SCNx8 "x"
#define SCNX8 "X"
#define SCNoLEAST8 "o"
#define SCNuLEAST8 "u"
#define SCNxLEAST8 "x"
#define SCNXLEAST8 "X"
#define SCNoFAST8 "o"
#define SCNuFAST8 "u"
#define SCNxFAST8 "x"
#define SCNXFAST8 "X"
#define SCNo16 "ho"
#define SCNu16 "hu"
#define SCNx16 "hx"
#define SCNX16 "hX"
#define SCNoLEAST16 "ho"
#define SCNuLEAST16 "hu"
#define SCNxLEAST16 "hx"
#define SCNXLEAST16 "hX"
#define SCNoFAST16 "ho"
#define SCNuFAST16 "hu"
#define SCNxFAST16 "hx"
#define SCNXFAST16 "hX"
#define SCNo32 "lo"
#define SCNu32 "lu"
#define SCNx32 "lx"
#define SCNX32 "lX"
#define SCNoLEAST32 "lo"
#define SCNuLEAST32 "lu"
#define SCNxLEAST32 "lx"
#define SCNXLEAST32 "lX"
#define SCNoFAST32 "lo"
#define SCNuFAST32 "lu"
#define SCNxFAST32 "lx"
#define SCNXFAST32 "lX"
#define SCNo64 "I64o"
#define SCNu64 "I64u"
#define SCNx64 "I64x"
#define SCNX64 "I64X"
#define SCNoLEAST64 "I64o"
#define SCNuLEAST64 "I64u"
#define SCNxLEAST64 "I64x"
#define SCNXLEAST64 "I64X"
#define SCNoFAST64 "I64o"
#define SCNuFAST64 "I64u"
#define SCNxFAST64 "I64x"
#define SCNXFAST64 "I64X"
#define SCNoMAX "I64o"
#define SCNuMAX "I64u"
#define SCNxMAX "I64x"
#define SCNXMAX "I64X"
#ifdef _WIN64 // [
# define SCNoPTR "I64o"
# define SCNuPTR "I64u"
# define SCNxPTR "I64x"
# define SCNXPTR "I64X"
#else // _WIN64 ][
# define SCNoPTR "lo"
# define SCNuPTR "lu"
# define SCNxPTR "lx"
# define SCNXPTR "lX"
#endif // _WIN64 ]
#endif // __STDC_FORMAT_MACROS ]
// 7.8.2 Functions for greatest-width integer types
// 7.8.2.1 The imaxabs function
#define imaxabs _abs64
// 7.8.2.2 The imaxdiv function
// This is modified version of div() function from Microsoft's div.c found
// in %MSVC.NET%\crt\src\div.c
#ifdef STATIC_IMAXDIV // [
static
#else // STATIC_IMAXDIV ][
_inline
#endif // STATIC_IMAXDIV ]
imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom)
{
imaxdiv_t result;
result.quot = numer / denom;
result.rem = numer % denom;
if (numer < 0 && result.rem > 0) {
// did division wrong; must fix up
++result.quot;
result.rem -= denom;
}
return result;
}
// 7.8.2.3 The strtoimax and strtoumax functions
#define strtoimax _strtoi64
#define strtoumax _strtoui64
// 7.8.2.4 The wcstoimax and wcstoumax functions
#define wcstoimax _wcstoi64
#define wcstoumax _wcstoui64
#endif // _MSC_INTTYPES_H_ ]

View File

@ -3,8 +3,9 @@
/* MSVC doesn't define ffs/ffsl. This dummy strings.h header is provided /* MSVC doesn't define ffs/ffsl. This dummy strings.h header is provided
* for both */ * for both */
#include <intrin.h> #ifdef _MSC_VER
#pragma intrinsic(_BitScanForward) # include <intrin.h>
# pragma intrinsic(_BitScanForward)
static __forceinline int ffsl(long x) static __forceinline int ffsl(long x)
{ {
unsigned long i; unsigned long i;
@ -20,4 +21,9 @@ static __forceinline int ffs(int x)
return (ffsl(x)); return (ffsl(x));
} }
#else
# define ffsl(x) __builtin_ffsl(x)
# define ffs(x) __builtin_ffs(x)
#endif #endif
#endif /* strings_h */

View File

@ -0,0 +1,26 @@
#ifndef MSVC_COMPAT_WINDOWS_EXTRA_H
#define MSVC_COMPAT_WINDOWS_EXTRA_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
#endif /* MSVC_COMPAT_WINDOWS_EXTRA_H */

View File

@ -1886,8 +1886,8 @@ arena_redzone_corruption(void *ptr, size_t usize, bool after,
size_t offset, uint8_t byte) size_t offset, uint8_t byte)
{ {
malloc_printf("<jemalloc>: Corrupt redzone %"PRIzu" byte%s %s %p " malloc_printf("<jemalloc>: Corrupt redzone %zu byte%s %s %p "
"(size %"PRIzu"), byte=%#x\n", offset, (offset == 1) ? "" : "s", "(size %zu), byte=%#x\n", offset, (offset == 1) ? "" : "s",
after ? "after" : "before", ptr, usize, byte); after ? "after" : "before", ptr, usize, byte);
} }
#ifdef JEMALLOC_JET #ifdef JEMALLOC_JET

View File

@ -411,9 +411,9 @@ ckh_delete(tsd_t *tsd, ckh_t *ckh)
#ifdef CKH_VERBOSE #ifdef CKH_VERBOSE
malloc_printf( malloc_printf(
"%s(%p): ngrows: %"PRIu64", nshrinks: %"PRIu64"," "%s(%p): ngrows: %"FMTu64", nshrinks: %"FMTu64","
" nshrinkfails: %"PRIu64", ninserts: %"PRIu64"," " nshrinkfails: %"FMTu64", ninserts: %"FMTu64","
" nrelocs: %"PRIu64"\n", __func__, ckh, " nrelocs: %"FMTu64"\n", __func__, ckh,
(unsigned long long)ckh->ngrows, (unsigned long long)ckh->ngrows,
(unsigned long long)ckh->nshrinks, (unsigned long long)ckh->nshrinks,
(unsigned long long)ckh->nshrinkfails, (unsigned long long)ckh->nshrinkfails,

View File

@ -1095,7 +1095,7 @@ prof_tctx_dump_iter(prof_tctx_tree_t *tctxs, prof_tctx_t *tctx, void *arg)
bool propagate_err = *(bool *)arg; bool propagate_err = *(bool *)arg;
if (prof_dump_printf(propagate_err, if (prof_dump_printf(propagate_err,
" t%"PRIu64": %"PRIu64": %"PRIu64" [%"PRIu64": %"PRIu64"]\n", " t%"FMTu64": %"FMTu64": %"FMTu64" [%"FMTu64": %"FMTu64"]\n",
tctx->thr_uid, tctx->dump_cnts.curobjs, tctx->dump_cnts.curbytes, tctx->thr_uid, tctx->dump_cnts.curobjs, tctx->dump_cnts.curbytes,
tctx->dump_cnts.accumobjs, tctx->dump_cnts.accumbytes)) tctx->dump_cnts.accumobjs, tctx->dump_cnts.accumbytes))
return (tctx); return (tctx);
@ -1247,7 +1247,7 @@ prof_tdata_dump_iter(prof_tdata_tree_t *tdatas, prof_tdata_t *tdata, void *arg)
return (NULL); return (NULL);
if (prof_dump_printf(propagate_err, if (prof_dump_printf(propagate_err,
" t%"PRIu64": %"PRIu64": %"PRIu64" [%"PRIu64": %"PRIu64"]%s%s\n", " t%"FMTu64": %"FMTu64": %"FMTu64" [%"FMTu64": %"FMTu64"]%s%s\n",
tdata->thr_uid, tdata->cnt_summed.curobjs, tdata->thr_uid, tdata->cnt_summed.curobjs,
tdata->cnt_summed.curbytes, tdata->cnt_summed.accumobjs, tdata->cnt_summed.curbytes, tdata->cnt_summed.accumobjs,
tdata->cnt_summed.accumbytes, tdata->cnt_summed.accumbytes,
@ -1267,8 +1267,8 @@ prof_dump_header(bool propagate_err, const prof_cnt_t *cnt_all)
bool ret; bool ret;
if (prof_dump_printf(propagate_err, if (prof_dump_printf(propagate_err,
"heap_v2/%"PRIu64"\n" "heap_v2/%"FMTu64"\n"
" t*: %"PRIu64": %"PRIu64" [%"PRIu64": %"PRIu64"]\n", " t*: %"FMTu64": %"FMTu64" [%"FMTu64": %"FMTu64"]\n",
((uint64_t)1U << lg_prof_sample), cnt_all->curobjs, ((uint64_t)1U << lg_prof_sample), cnt_all->curobjs,
cnt_all->curbytes, cnt_all->accumobjs, cnt_all->accumbytes)) cnt_all->curbytes, cnt_all->accumobjs, cnt_all->accumbytes))
return (true); return (true);
@ -1311,7 +1311,7 @@ prof_dump_gctx(bool propagate_err, prof_gctx_t *gctx, const prof_bt_t *bt,
goto label_return; goto label_return;
} }
for (i = 0; i < bt->len; i++) { for (i = 0; i < bt->len; i++) {
if (prof_dump_printf(propagate_err, " %#"PRIxPTR, if (prof_dump_printf(propagate_err, " %#"FMTxPTR,
(uintptr_t)bt->vec[i])) { (uintptr_t)bt->vec[i])) {
ret = true; ret = true;
goto label_return; goto label_return;
@ -1320,7 +1320,7 @@ prof_dump_gctx(bool propagate_err, prof_gctx_t *gctx, const prof_bt_t *bt,
if (prof_dump_printf(propagate_err, if (prof_dump_printf(propagate_err,
"\n" "\n"
" t*: %"PRIu64": %"PRIu64" [%"PRIu64": %"PRIu64"]\n", " t*: %"FMTu64": %"FMTu64" [%"FMTu64": %"FMTu64"]\n",
gctx->cnt_summed.curobjs, gctx->cnt_summed.curbytes, gctx->cnt_summed.curobjs, gctx->cnt_summed.curbytes,
gctx->cnt_summed.accumobjs, gctx->cnt_summed.accumbytes)) { gctx->cnt_summed.accumobjs, gctx->cnt_summed.accumbytes)) {
ret = true; ret = true;
@ -1412,8 +1412,8 @@ prof_leakcheck(const prof_cnt_t *cnt_all, size_t leak_ngctx,
{ {
if (cnt_all->curbytes != 0) { if (cnt_all->curbytes != 0) {
malloc_printf("<jemalloc>: Leak summary: %"PRIu64" byte%s, %" malloc_printf("<jemalloc>: Leak summary: %"FMTu64" byte%s, %"
PRIu64" object%s, %"PRIzu" context%s\n", FMTu64" object%s, %zu context%s\n",
cnt_all->curbytes, (cnt_all->curbytes != 1) ? "s" : "", cnt_all->curbytes, (cnt_all->curbytes != 1) ? "s" : "",
cnt_all->curobjs, (cnt_all->curobjs != 1) ? "s" : "", cnt_all->curobjs, (cnt_all->curobjs != 1) ? "s" : "",
leak_ngctx, (leak_ngctx != 1) ? "s" : ""); leak_ngctx, (leak_ngctx != 1) ? "s" : "");
@ -1533,12 +1533,12 @@ prof_dump_filename(char *filename, char v, uint64_t vseq)
if (vseq != VSEQ_INVALID) { if (vseq != VSEQ_INVALID) {
/* "<prefix>.<pid>.<seq>.v<vseq>.heap" */ /* "<prefix>.<pid>.<seq>.v<vseq>.heap" */
malloc_snprintf(filename, DUMP_FILENAME_BUFSIZE, malloc_snprintf(filename, DUMP_FILENAME_BUFSIZE,
"%s.%d.%"PRIu64".%c%"PRIu64".heap", "%s.%d.%"FMTu64".%c%"FMTu64".heap",
opt_prof_prefix, (int)getpid(), prof_dump_seq, v, vseq); opt_prof_prefix, (int)getpid(), prof_dump_seq, v, vseq);
} else { } else {
/* "<prefix>.<pid>.<seq>.<v>.heap" */ /* "<prefix>.<pid>.<seq>.<v>.heap" */
malloc_snprintf(filename, DUMP_FILENAME_BUFSIZE, malloc_snprintf(filename, DUMP_FILENAME_BUFSIZE,
"%s.%d.%"PRIu64".%c.heap", "%s.%d.%"FMTu64".%c.heap",
opt_prof_prefix, (int)getpid(), prof_dump_seq, v); opt_prof_prefix, (int)getpid(), prof_dump_seq, v);
} }
prof_dump_seq++; prof_dump_seq++;

View File

@ -119,32 +119,32 @@ stats_arena_bins_print(void (*write_cb)(void *, const char *), void *cbopaque,
assert(milli <= 1000); assert(milli <= 1000);
if (milli < 10) { if (milli < 10) {
malloc_snprintf(util, sizeof(util), malloc_snprintf(util, sizeof(util),
"0.00%"PRIzu, milli); "0.00%zu", milli);
} else if (milli < 100) { } else if (milli < 100) {
malloc_snprintf(util, sizeof(util), "0.0%"PRIzu, malloc_snprintf(util, sizeof(util), "0.0%zu",
milli); milli);
} else if (milli < 1000) { } else if (milli < 1000) {
malloc_snprintf(util, sizeof(util), "0.%"PRIzu, malloc_snprintf(util, sizeof(util), "0.%zu",
milli); milli);
} else } else
malloc_snprintf(util, sizeof(util), "1"); malloc_snprintf(util, sizeof(util), "1");
if (config_tcache) { if (config_tcache) {
malloc_cprintf(write_cb, cbopaque, malloc_cprintf(write_cb, cbopaque,
"%20"PRIzu" %3u %12"PRIzu" %12"PRIu64 "%20zu %3u %12zu %12"FMTu64
" %12"PRIu64" %12"PRIu64" %12"PRIzu " %12"FMTu64" %12"FMTu64" %12zu"
" %12"PRIzu" %4u %3"PRIzu" %-5s %12"PRIu64 " %12zu %4u %3zu %-5s %12"FMTu64
" %12"PRIu64" %12"PRIu64" %12"PRIu64"\n", " %12"FMTu64" %12"FMTu64" %12"FMTu64"\n",
reg_size, j, curregs * reg_size, nmalloc, reg_size, j, curregs * reg_size, nmalloc,
ndalloc, nrequests, curregs, curruns, nregs, ndalloc, nrequests, curregs, curruns, nregs,
run_size / page, util, nfills, nflushes, run_size / page, util, nfills, nflushes,
nruns, reruns); nruns, reruns);
} else { } else {
malloc_cprintf(write_cb, cbopaque, malloc_cprintf(write_cb, cbopaque,
"%20"PRIzu" %3u %12"PRIzu" %12"PRIu64 "%20zu %3u %12zu %12"FMTu64
" %12"PRIu64" %12"PRIu64" %12"PRIzu " %12"FMTu64" %12"FMTu64" %12zu"
" %12"PRIzu" %4u %3"PRIzu" %-5s %12"PRIu64 " %12zu %4u %3zu %-5s %12"FMTu64
" %12"PRIu64"\n", " %12"FMTu64"\n",
reg_size, j, curregs * reg_size, nmalloc, reg_size, j, curregs * reg_size, nmalloc,
ndalloc, nrequests, curregs, curruns, nregs, ndalloc, nrequests, curregs, curruns, nregs,
run_size / page, util, nruns, reruns); run_size / page, util, nruns, reruns);
@ -191,8 +191,8 @@ stats_arena_lruns_print(void (*write_cb)(void *, const char *), void *cbopaque,
in_gap = false; in_gap = false;
} }
malloc_cprintf(write_cb, cbopaque, malloc_cprintf(write_cb, cbopaque,
"%20"PRIzu" %3u %12"PRIzu" %12"PRIu64" %12"PRIu64 "%20zu %3u %12zu %12"FMTu64" %12"FMTu64
" %12"PRIu64" %12"PRIzu"\n", " %12"FMTu64" %12zu\n",
run_size, nbins + j, curruns * run_size, nmalloc, run_size, nbins + j, curruns * run_size, nmalloc,
ndalloc, nrequests, curruns); ndalloc, nrequests, curruns);
} }
@ -239,8 +239,8 @@ stats_arena_hchunks_print(void (*write_cb)(void *, const char *),
in_gap = false; in_gap = false;
} }
malloc_cprintf(write_cb, cbopaque, malloc_cprintf(write_cb, cbopaque,
"%20"PRIzu" %3u %12"PRIzu" %12"PRIu64" %12"PRIu64 "%20zu %3u %12zu %12"FMTu64" %12"FMTu64
" %12"PRIu64" %12"PRIzu"\n", " %12"FMTu64" %12zu\n",
hchunk_size, nbins + nlruns + j, hchunk_size, nbins + nlruns + j,
curhchunks * hchunk_size, nmalloc, ndalloc, curhchunks * hchunk_size, nmalloc, ndalloc,
nrequests, curhchunks); nrequests, curhchunks);
@ -292,10 +292,9 @@ stats_arena_print(void (*write_cb)(void *, const char *), void *cbopaque,
CTL_M2_GET("stats.arenas.0.nmadvise", i, &nmadvise, uint64_t); CTL_M2_GET("stats.arenas.0.nmadvise", i, &nmadvise, uint64_t);
CTL_M2_GET("stats.arenas.0.purged", i, &purged, uint64_t); CTL_M2_GET("stats.arenas.0.purged", i, &purged, uint64_t);
malloc_cprintf(write_cb, cbopaque, malloc_cprintf(write_cb, cbopaque,
"dirty pages: %"PRIzu":%"PRIzu" active:dirty, %"PRIu64" sweep%s," "dirty pages: %zu:%zu active:dirty, %"FMTu64" sweep%s, %"FMTu64
" %"PRIu64" madvise%s, %"PRIu64" purged\n", " madvise%s, %"FMTu64" purged\n", pactive, pdirty, npurge, npurge ==
pactive, pdirty, npurge, npurge == 1 ? "" : "s", 1 ? "" : "s", nmadvise, nmadvise == 1 ? "" : "s", purged);
nmadvise, nmadvise == 1 ? "" : "s", purged);
malloc_cprintf(write_cb, cbopaque, malloc_cprintf(write_cb, cbopaque,
" allocated nmalloc ndalloc" " allocated nmalloc ndalloc"
@ -307,8 +306,8 @@ stats_arena_print(void (*write_cb)(void *, const char *), void *cbopaque,
CTL_M2_GET("stats.arenas.0.small.nrequests", i, &small_nrequests, CTL_M2_GET("stats.arenas.0.small.nrequests", i, &small_nrequests,
uint64_t); uint64_t);
malloc_cprintf(write_cb, cbopaque, malloc_cprintf(write_cb, cbopaque,
"small: %12"PRIzu" %12"PRIu64" %12"PRIu64 "small: %12zu %12"FMTu64" %12"FMTu64
" %12"PRIu64"\n", " %12"FMTu64"\n",
small_allocated, small_nmalloc, small_ndalloc, small_nrequests); small_allocated, small_nmalloc, small_ndalloc, small_nrequests);
CTL_M2_GET("stats.arenas.0.large.allocated", i, &large_allocated, CTL_M2_GET("stats.arenas.0.large.allocated", i, &large_allocated,
size_t); size_t);
@ -317,8 +316,8 @@ stats_arena_print(void (*write_cb)(void *, const char *), void *cbopaque,
CTL_M2_GET("stats.arenas.0.large.nrequests", i, &large_nrequests, CTL_M2_GET("stats.arenas.0.large.nrequests", i, &large_nrequests,
uint64_t); uint64_t);
malloc_cprintf(write_cb, cbopaque, malloc_cprintf(write_cb, cbopaque,
"large: %12"PRIzu" %12"PRIu64" %12"PRIu64 "large: %12zu %12"FMTu64" %12"FMTu64
" %12"PRIu64"\n", " %12"FMTu64"\n",
large_allocated, large_nmalloc, large_ndalloc, large_nrequests); large_allocated, large_nmalloc, large_ndalloc, large_nrequests);
CTL_M2_GET("stats.arenas.0.huge.allocated", i, &huge_allocated, size_t); CTL_M2_GET("stats.arenas.0.huge.allocated", i, &huge_allocated, size_t);
CTL_M2_GET("stats.arenas.0.huge.nmalloc", i, &huge_nmalloc, uint64_t); CTL_M2_GET("stats.arenas.0.huge.nmalloc", i, &huge_nmalloc, uint64_t);
@ -326,27 +325,27 @@ stats_arena_print(void (*write_cb)(void *, const char *), void *cbopaque,
CTL_M2_GET("stats.arenas.0.huge.nrequests", i, &huge_nrequests, CTL_M2_GET("stats.arenas.0.huge.nrequests", i, &huge_nrequests,
uint64_t); uint64_t);
malloc_cprintf(write_cb, cbopaque, malloc_cprintf(write_cb, cbopaque,
"huge: %12"PRIzu" %12"PRIu64" %12"PRIu64 "huge: %12zu %12"FMTu64" %12"FMTu64
" %12"PRIu64"\n", " %12"FMTu64"\n",
huge_allocated, huge_nmalloc, huge_ndalloc, huge_nrequests); huge_allocated, huge_nmalloc, huge_ndalloc, huge_nrequests);
malloc_cprintf(write_cb, cbopaque, malloc_cprintf(write_cb, cbopaque,
"total: %12"PRIzu" %12"PRIu64" %12"PRIu64 "total: %12zu %12"FMTu64" %12"FMTu64
" %12"PRIu64"\n", " %12"FMTu64"\n",
small_allocated + large_allocated + huge_allocated, small_allocated + large_allocated + huge_allocated,
small_nmalloc + large_nmalloc + huge_nmalloc, small_nmalloc + large_nmalloc + huge_nmalloc,
small_ndalloc + large_ndalloc + huge_ndalloc, small_ndalloc + large_ndalloc + huge_ndalloc,
small_nrequests + large_nrequests + huge_nrequests); small_nrequests + large_nrequests + huge_nrequests);
malloc_cprintf(write_cb, cbopaque, malloc_cprintf(write_cb, cbopaque,
"active: %12"PRIzu"\n", pactive * page); "active: %12zu\n", pactive * page);
CTL_M2_GET("stats.arenas.0.mapped", i, &mapped, size_t); CTL_M2_GET("stats.arenas.0.mapped", i, &mapped, size_t);
malloc_cprintf(write_cb, cbopaque, malloc_cprintf(write_cb, cbopaque,
"mapped: %12"PRIzu"\n", mapped); "mapped: %12zu\n", mapped);
CTL_M2_GET("stats.arenas.0.metadata.mapped", i, &metadata_mapped, CTL_M2_GET("stats.arenas.0.metadata.mapped", i, &metadata_mapped,
size_t); size_t);
CTL_M2_GET("stats.arenas.0.metadata.allocated", i, &metadata_allocated, CTL_M2_GET("stats.arenas.0.metadata.allocated", i, &metadata_allocated,
size_t); size_t);
malloc_cprintf(write_cb, cbopaque, malloc_cprintf(write_cb, cbopaque,
"metadata: mapped: %"PRIzu", allocated: %"PRIzu"\n", "metadata: mapped: %zu, allocated: %zu\n",
metadata_mapped, metadata_allocated); metadata_mapped, metadata_allocated);
if (bins) if (bins)
@ -457,19 +456,19 @@ stats_print(void (*write_cb)(void *, const char *), void *cbopaque,
#define OPT_WRITE_SIZE_T(n) \ #define OPT_WRITE_SIZE_T(n) \
if (je_mallctl("opt."#n, &sv, &ssz, NULL, 0) == 0) { \ if (je_mallctl("opt."#n, &sv, &ssz, NULL, 0) == 0) { \
malloc_cprintf(write_cb, cbopaque, \ malloc_cprintf(write_cb, cbopaque, \
" opt."#n": %"PRIzu"\n", sv); \ " opt."#n": %zu\n", sv); \
} }
#define OPT_WRITE_SSIZE_T(n) \ #define OPT_WRITE_SSIZE_T(n) \
if (je_mallctl("opt."#n, &ssv, &sssz, NULL, 0) == 0) { \ if (je_mallctl("opt."#n, &ssv, &sssz, NULL, 0) == 0) { \
malloc_cprintf(write_cb, cbopaque, \ malloc_cprintf(write_cb, cbopaque, \
" opt."#n": %"PRIzd"\n", ssv); \ " opt."#n": %zd\n", ssv); \
} }
#define OPT_WRITE_SSIZE_T_MUTABLE(n, m) { \ #define OPT_WRITE_SSIZE_T_MUTABLE(n, m) { \
ssize_t ssv2; \ ssize_t ssv2; \
if (je_mallctl("opt."#n, &ssv, &sssz, NULL, 0) == 0 && \ if (je_mallctl("opt."#n, &ssv, &sssz, NULL, 0) == 0 && \
je_mallctl(#m, &ssv2, &sssz, NULL, 0) == 0) { \ je_mallctl(#m, &ssv2, &sssz, NULL, 0) == 0) { \
malloc_cprintf(write_cb, cbopaque, \ malloc_cprintf(write_cb, cbopaque, \
" opt."#n": %"PRIzd" ("#m": %"PRIzd")\n", \ " opt."#n": %zd ("#m": %zd)\n", \
ssv, ssv2); \ ssv, ssv2); \
} \ } \
} }
@ -519,15 +518,15 @@ stats_print(void (*write_cb)(void *, const char *), void *cbopaque,
CTL_GET("arenas.narenas", &uv, unsigned); CTL_GET("arenas.narenas", &uv, unsigned);
malloc_cprintf(write_cb, cbopaque, "Arenas: %u\n", uv); malloc_cprintf(write_cb, cbopaque, "Arenas: %u\n", uv);
malloc_cprintf(write_cb, cbopaque, "Pointer size: %"PRIzu"\n", malloc_cprintf(write_cb, cbopaque, "Pointer size: %zu\n",
sizeof(void *)); sizeof(void *));
CTL_GET("arenas.quantum", &sv, size_t); CTL_GET("arenas.quantum", &sv, size_t);
malloc_cprintf(write_cb, cbopaque, "Quantum size: %"PRIzu"\n", malloc_cprintf(write_cb, cbopaque, "Quantum size: %zu\n",
sv); sv);
CTL_GET("arenas.page", &sv, size_t); CTL_GET("arenas.page", &sv, size_t);
malloc_cprintf(write_cb, cbopaque, "Page size: %"PRIzu"\n", sv); malloc_cprintf(write_cb, cbopaque, "Page size: %zu\n", sv);
CTL_GET("arenas.lg_dirty_mult", &ssv, ssize_t); CTL_GET("arenas.lg_dirty_mult", &ssv, ssize_t);
if (ssv >= 0) { if (ssv >= 0) {
@ -540,19 +539,19 @@ stats_print(void (*write_cb)(void *, const char *), void *cbopaque,
} }
if (je_mallctl("arenas.tcache_max", &sv, &ssz, NULL, 0) == 0) { if (je_mallctl("arenas.tcache_max", &sv, &ssz, NULL, 0) == 0) {
malloc_cprintf(write_cb, cbopaque, malloc_cprintf(write_cb, cbopaque,
"Maximum thread-cached size class: %"PRIzu"\n", sv); "Maximum thread-cached size class: %zu\n", sv);
} }
if (je_mallctl("opt.prof", &bv, &bsz, NULL, 0) == 0 && bv) { if (je_mallctl("opt.prof", &bv, &bsz, NULL, 0) == 0 && bv) {
CTL_GET("prof.lg_sample", &sv, size_t); CTL_GET("prof.lg_sample", &sv, size_t);
malloc_cprintf(write_cb, cbopaque, malloc_cprintf(write_cb, cbopaque,
"Average profile sample interval: %"PRIu64 "Average profile sample interval: %"FMTu64
" (2^%"PRIzu")\n", (((uint64_t)1U) << sv), sv); " (2^%zu)\n", (((uint64_t)1U) << sv), sv);
CTL_GET("opt.lg_prof_interval", &ssv, ssize_t); CTL_GET("opt.lg_prof_interval", &ssv, ssize_t);
if (ssv >= 0) { if (ssv >= 0) {
malloc_cprintf(write_cb, cbopaque, malloc_cprintf(write_cb, cbopaque,
"Average profile dump interval: %"PRIu64 "Average profile dump interval: %"FMTu64
" (2^%"PRIzd")\n", " (2^%zd)\n",
(((uint64_t)1U) << ssv), ssv); (((uint64_t)1U) << ssv), ssv);
} else { } else {
malloc_cprintf(write_cb, cbopaque, malloc_cprintf(write_cb, cbopaque,
@ -561,7 +560,7 @@ stats_print(void (*write_cb)(void *, const char *), void *cbopaque,
} }
CTL_GET("opt.lg_chunk", &sv, size_t); CTL_GET("opt.lg_chunk", &sv, size_t);
malloc_cprintf(write_cb, cbopaque, malloc_cprintf(write_cb, cbopaque,
"Chunk size: %"PRIzu" (2^%"PRIzu")\n", (ZU(1) << sv), sv); "Chunk size: %zu (2^%zu)\n", (ZU(1) << sv), sv);
} }
if (config_stats) { if (config_stats) {
@ -575,11 +574,11 @@ stats_print(void (*write_cb)(void *, const char *), void *cbopaque,
CTL_GET("stats.resident", &resident, size_t); CTL_GET("stats.resident", &resident, size_t);
CTL_GET("stats.mapped", &mapped, size_t); CTL_GET("stats.mapped", &mapped, size_t);
malloc_cprintf(write_cb, cbopaque, malloc_cprintf(write_cb, cbopaque,
"Allocated: %"PRIzu", active: %"PRIzu", metadata: %"PRIzu"," "Allocated: %zu, active: %zu, metadata: %zu,"
" resident: %"PRIzu", mapped: %"PRIzu"\n", " resident: %zu, mapped: %zu\n",
allocated, active, metadata, resident, mapped); allocated, active, metadata, resident, mapped);
malloc_cprintf(write_cb, cbopaque, malloc_cprintf(write_cb, cbopaque,
"Current active ceiling: %"PRIzu"\n", "Current active ceiling: %zu\n",
atomic_read_z(cactive)); atomic_read_z(cactive));
if (merged) { if (merged) {

View File

@ -6,13 +6,16 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h> #include <stdbool.h>
#include <errno.h> #include <errno.h>
#include <inttypes.h>
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
#ifdef _WIN32
# include "msvc_compat/strings.h"
#endif
#include <sys/time.h> #include <sys/time.h>
#ifdef _WIN32 #ifdef _WIN32
# include <windows.h> # include <windows.h>
# include "msvc_compat/windows_extra.h"
#else #else
# include <pthread.h> # include <pthread.h>
#endif #endif

View File

@ -133,82 +133,82 @@
<=, "ju", __VA_ARGS__) <=, "ju", __VA_ARGS__)
#define assert_zd_eq(a, b, ...) assert_cmp(ssize_t, a, b, ==, \ #define assert_zd_eq(a, b, ...) assert_cmp(ssize_t, a, b, ==, \
!=, PRIzd, __VA_ARGS__) !=, "zd", __VA_ARGS__)
#define assert_zd_ne(a, b, ...) assert_cmp(ssize_t, a, b, !=, \ #define assert_zd_ne(a, b, ...) assert_cmp(ssize_t, a, b, !=, \
==, PRIzd, __VA_ARGS__) ==, "zd", __VA_ARGS__)
#define assert_zd_lt(a, b, ...) assert_cmp(ssize_t, a, b, <, \ #define assert_zd_lt(a, b, ...) assert_cmp(ssize_t, a, b, <, \
>=, PRIzd, __VA_ARGS__) >=, "zd", __VA_ARGS__)
#define assert_zd_le(a, b, ...) assert_cmp(ssize_t, a, b, <=, \ #define assert_zd_le(a, b, ...) assert_cmp(ssize_t, a, b, <=, \
>, PRIzd, __VA_ARGS__) >, "zd", __VA_ARGS__)
#define assert_zd_ge(a, b, ...) assert_cmp(ssize_t, a, b, >=, \ #define assert_zd_ge(a, b, ...) assert_cmp(ssize_t, a, b, >=, \
<, PRIzd, __VA_ARGS__) <, "zd", __VA_ARGS__)
#define assert_zd_gt(a, b, ...) assert_cmp(ssize_t, a, b, >, \ #define assert_zd_gt(a, b, ...) assert_cmp(ssize_t, a, b, >, \
<=, PRIzd, __VA_ARGS__) <=, "zd", __VA_ARGS__)
#define assert_zu_eq(a, b, ...) assert_cmp(size_t, a, b, ==, \ #define assert_zu_eq(a, b, ...) assert_cmp(size_t, a, b, ==, \
!=, PRIzu, __VA_ARGS__) !=, "zu", __VA_ARGS__)
#define assert_zu_ne(a, b, ...) assert_cmp(size_t, a, b, !=, \ #define assert_zu_ne(a, b, ...) assert_cmp(size_t, a, b, !=, \
==, PRIzu, __VA_ARGS__) ==, "zu", __VA_ARGS__)
#define assert_zu_lt(a, b, ...) assert_cmp(size_t, a, b, <, \ #define assert_zu_lt(a, b, ...) assert_cmp(size_t, a, b, <, \
>=, PRIzu, __VA_ARGS__) >=, "zu", __VA_ARGS__)
#define assert_zu_le(a, b, ...) assert_cmp(size_t, a, b, <=, \ #define assert_zu_le(a, b, ...) assert_cmp(size_t, a, b, <=, \
>, PRIzu, __VA_ARGS__) >, "zu", __VA_ARGS__)
#define assert_zu_ge(a, b, ...) assert_cmp(size_t, a, b, >=, \ #define assert_zu_ge(a, b, ...) assert_cmp(size_t, a, b, >=, \
<, PRIzu, __VA_ARGS__) <, "zu", __VA_ARGS__)
#define assert_zu_gt(a, b, ...) assert_cmp(size_t, a, b, >, \ #define assert_zu_gt(a, b, ...) assert_cmp(size_t, a, b, >, \
<=, PRIzu, __VA_ARGS__) <=, "zu", __VA_ARGS__)
#define assert_d32_eq(a, b, ...) assert_cmp(int32_t, a, b, ==, \ #define assert_d32_eq(a, b, ...) assert_cmp(int32_t, a, b, ==, \
!=, PRId32, __VA_ARGS__) !=, FMTd32, __VA_ARGS__)
#define assert_d32_ne(a, b, ...) assert_cmp(int32_t, a, b, !=, \ #define assert_d32_ne(a, b, ...) assert_cmp(int32_t, a, b, !=, \
==, PRId32, __VA_ARGS__) ==, FMTd32, __VA_ARGS__)
#define assert_d32_lt(a, b, ...) assert_cmp(int32_t, a, b, <, \ #define assert_d32_lt(a, b, ...) assert_cmp(int32_t, a, b, <, \
>=, PRId32, __VA_ARGS__) >=, FMTd32, __VA_ARGS__)
#define assert_d32_le(a, b, ...) assert_cmp(int32_t, a, b, <=, \ #define assert_d32_le(a, b, ...) assert_cmp(int32_t, a, b, <=, \
>, PRId32, __VA_ARGS__) >, FMTd32, __VA_ARGS__)
#define assert_d32_ge(a, b, ...) assert_cmp(int32_t, a, b, >=, \ #define assert_d32_ge(a, b, ...) assert_cmp(int32_t, a, b, >=, \
<, PRId32, __VA_ARGS__) <, FMTd32, __VA_ARGS__)
#define assert_d32_gt(a, b, ...) assert_cmp(int32_t, a, b, >, \ #define assert_d32_gt(a, b, ...) assert_cmp(int32_t, a, b, >, \
<=, PRId32, __VA_ARGS__) <=, FMTd32, __VA_ARGS__)
#define assert_u32_eq(a, b, ...) assert_cmp(uint32_t, a, b, ==, \ #define assert_u32_eq(a, b, ...) assert_cmp(uint32_t, a, b, ==, \
!=, PRIu32, __VA_ARGS__) !=, FMTu32, __VA_ARGS__)
#define assert_u32_ne(a, b, ...) assert_cmp(uint32_t, a, b, !=, \ #define assert_u32_ne(a, b, ...) assert_cmp(uint32_t, a, b, !=, \
==, PRIu32, __VA_ARGS__) ==, FMTu32, __VA_ARGS__)
#define assert_u32_lt(a, b, ...) assert_cmp(uint32_t, a, b, <, \ #define assert_u32_lt(a, b, ...) assert_cmp(uint32_t, a, b, <, \
>=, PRIu32, __VA_ARGS__) >=, FMTu32, __VA_ARGS__)
#define assert_u32_le(a, b, ...) assert_cmp(uint32_t, a, b, <=, \ #define assert_u32_le(a, b, ...) assert_cmp(uint32_t, a, b, <=, \
>, PRIu32, __VA_ARGS__) >, FMTu32, __VA_ARGS__)
#define assert_u32_ge(a, b, ...) assert_cmp(uint32_t, a, b, >=, \ #define assert_u32_ge(a, b, ...) assert_cmp(uint32_t, a, b, >=, \
<, PRIu32, __VA_ARGS__) <, FMTu32, __VA_ARGS__)
#define assert_u32_gt(a, b, ...) assert_cmp(uint32_t, a, b, >, \ #define assert_u32_gt(a, b, ...) assert_cmp(uint32_t, a, b, >, \
<=, PRIu32, __VA_ARGS__) <=, FMTu32, __VA_ARGS__)
#define assert_d64_eq(a, b, ...) assert_cmp(int64_t, a, b, ==, \ #define assert_d64_eq(a, b, ...) assert_cmp(int64_t, a, b, ==, \
!=, PRId64, __VA_ARGS__) !=, FMTd64, __VA_ARGS__)
#define assert_d64_ne(a, b, ...) assert_cmp(int64_t, a, b, !=, \ #define assert_d64_ne(a, b, ...) assert_cmp(int64_t, a, b, !=, \
==, PRId64, __VA_ARGS__) ==, FMTd64, __VA_ARGS__)
#define assert_d64_lt(a, b, ...) assert_cmp(int64_t, a, b, <, \ #define assert_d64_lt(a, b, ...) assert_cmp(int64_t, a, b, <, \
>=, PRId64, __VA_ARGS__) >=, FMTd64, __VA_ARGS__)
#define assert_d64_le(a, b, ...) assert_cmp(int64_t, a, b, <=, \ #define assert_d64_le(a, b, ...) assert_cmp(int64_t, a, b, <=, \
>, PRId64, __VA_ARGS__) >, FMTd64, __VA_ARGS__)
#define assert_d64_ge(a, b, ...) assert_cmp(int64_t, a, b, >=, \ #define assert_d64_ge(a, b, ...) assert_cmp(int64_t, a, b, >=, \
<, PRId64, __VA_ARGS__) <, FMTd64, __VA_ARGS__)
#define assert_d64_gt(a, b, ...) assert_cmp(int64_t, a, b, >, \ #define assert_d64_gt(a, b, ...) assert_cmp(int64_t, a, b, >, \
<=, PRId64, __VA_ARGS__) <=, FMTd64, __VA_ARGS__)
#define assert_u64_eq(a, b, ...) assert_cmp(uint64_t, a, b, ==, \ #define assert_u64_eq(a, b, ...) assert_cmp(uint64_t, a, b, ==, \
!=, PRIu64, __VA_ARGS__) !=, FMTu64, __VA_ARGS__)
#define assert_u64_ne(a, b, ...) assert_cmp(uint64_t, a, b, !=, \ #define assert_u64_ne(a, b, ...) assert_cmp(uint64_t, a, b, !=, \
==, PRIu64, __VA_ARGS__) ==, FMTu64, __VA_ARGS__)
#define assert_u64_lt(a, b, ...) assert_cmp(uint64_t, a, b, <, \ #define assert_u64_lt(a, b, ...) assert_cmp(uint64_t, a, b, <, \
>=, PRIu64, __VA_ARGS__) >=, FMTu64, __VA_ARGS__)
#define assert_u64_le(a, b, ...) assert_cmp(uint64_t, a, b, <=, \ #define assert_u64_le(a, b, ...) assert_cmp(uint64_t, a, b, <=, \
>, PRIu64, __VA_ARGS__) >, FMTu64, __VA_ARGS__)
#define assert_u64_ge(a, b, ...) assert_cmp(uint64_t, a, b, >=, \ #define assert_u64_ge(a, b, ...) assert_cmp(uint64_t, a, b, >=, \
<, PRIu64, __VA_ARGS__) <, FMTu64, __VA_ARGS__)
#define assert_u64_gt(a, b, ...) assert_cmp(uint64_t, a, b, >, \ #define assert_u64_gt(a, b, ...) assert_cmp(uint64_t, a, b, >, \
<=, PRIu64, __VA_ARGS__) <=, FMTu64, __VA_ARGS__)
#define assert_b_eq(a, b, ...) do { \ #define assert_b_eq(a, b, ...) do { \
bool a_ = (a); \ bool a_ = (a); \

View File

@ -61,7 +61,7 @@ timer_ratio(timedelta_t *a, timedelta_t *b, char *buf, size_t buflen)
int n; int n;
/* Whole. */ /* Whole. */
n = malloc_snprintf(&buf[i], buflen-i, "%"PRIu64, t0 / t1); n = malloc_snprintf(&buf[i], buflen-i, "%"FMTu64, t0 / t1);
i += n; i += n;
if (i >= buflen) if (i >= buflen)
return; return;
@ -78,7 +78,7 @@ timer_ratio(timedelta_t *a, timedelta_t *b, char *buf, size_t buflen)
uint64_t round = (i+1 == buflen-1 && ((t0 * mult * 10 / t1) % 10 uint64_t round = (i+1 == buflen-1 && ((t0 * mult * 10 / t1) % 10
>= 5)) ? 1 : 0; >= 5)) ? 1 : 0;
n = malloc_snprintf(&buf[i], buflen-i, n = malloc_snprintf(&buf[i], buflen-i,
"%"PRIu64, (t0 * mult / t1) % 10 + round); "%"FMTu64, (t0 * mult / t1) % 10 + round);
i += n; i += n;
mult *= 10; mult *= 10;
} }

View File

@ -31,8 +31,8 @@ compare_funcs(uint64_t nwarmup, uint64_t niter, const char *name_a,
time_func(&timer_b, nwarmup, niter, func_b); time_func(&timer_b, nwarmup, niter, func_b);
timer_ratio(&timer_a, &timer_b, ratio_buf, sizeof(ratio_buf)); timer_ratio(&timer_a, &timer_b, ratio_buf, sizeof(ratio_buf));
malloc_printf("%"PRIu64" iterations, %s=%"PRIu64"us, " malloc_printf("%"FMTu64" iterations, %s=%"FMTu64"us, "
"%s=%"PRIu64"us, ratio=1:%s\n", "%s=%"FMTu64"us, ratio=1:%s\n",
niter, name_a, timer_usec(&timer_a), name_b, timer_usec(&timer_b), niter, name_a, timer_usec(&timer_a), name_b, timer_usec(&timer_b),
ratio_buf); ratio_buf);

View File

@ -1543,13 +1543,13 @@ TEST_BEGIN(test_gen_rand_64)
} }
r = gen_rand64(ctx); r = gen_rand64(ctx);
assert_u64_eq(r, array64[i], assert_u64_eq(r, array64[i],
"Mismatch at array64[%d]=%"PRIx64", gen=%"PRIx64, i, "Mismatch at array64[%d]=%"FMTx64", gen=%"FMTx64, i,
array64[i], r); array64[i], r);
} }
for (i = 0; i < COUNT_2; i++) { for (i = 0; i < COUNT_2; i++) {
r = gen_rand64(ctx); r = gen_rand64(ctx);
assert_u64_eq(r, array64_2[i], assert_u64_eq(r, array64_2[i],
"Mismatch at array64_2[%d]=%"PRIx64" gen=%"PRIx64"", i, "Mismatch at array64_2[%d]=%"FMTx64" gen=%"FMTx64"", i,
array64_2[i], r); array64_2[i], r);
} }
fini_gen_rand(ctx); fini_gen_rand(ctx);
@ -1580,13 +1580,13 @@ TEST_BEGIN(test_by_array_64)
} }
r = gen_rand64(ctx); r = gen_rand64(ctx);
assert_u64_eq(r, array64[i], assert_u64_eq(r, array64[i],
"Mismatch at array64[%d]=%"PRIx64" gen=%"PRIx64, i, "Mismatch at array64[%d]=%"FMTx64" gen=%"FMTx64, i,
array64[i], r); array64[i], r);
} }
for (i = 0; i < COUNT_2; i++) { for (i = 0; i < COUNT_2; i++) {
r = gen_rand64(ctx); r = gen_rand64(ctx);
assert_u64_eq(r, array64_2[i], assert_u64_eq(r, array64_2[i],
"Mismatch at array64_2[%d]=%"PRIx64" gen=%"PRIx64, i, "Mismatch at array64_2[%d]=%"FMTx64" gen=%"FMTx64, i,
array64_2[i], r); array64_2[i], r);
} }
fini_gen_rand(ctx); fini_gen_rand(ctx);

View File

@ -8,7 +8,7 @@ struct p##_test_s { \
}; \ }; \
typedef struct p##_test_s p##_test_t; typedef struct p##_test_s p##_test_t;
#define TEST_BODY(p, t, tc, ta, PRI) do { \ #define TEST_BODY(p, t, tc, ta, FMT) do { \
const p##_test_t tests[] = { \ const p##_test_t tests[] = { \
{(t)-1, (t)-1, (t)-2}, \ {(t)-1, (t)-1, (t)-2}, \
{(t)-1, (t) 0, (t)-2}, \ {(t)-1, (t) 0, (t)-2}, \
@ -38,7 +38,7 @@ typedef struct p##_test_s p##_test_t;
\ \
assert_##ta##_eq(atomic_add_##p(&accum, tests[i].x), \ assert_##ta##_eq(atomic_add_##p(&accum, tests[i].x), \
(t)((tc)tests[i].accum0 + (tc)tests[i].x), \ (t)((tc)tests[i].accum0 + (tc)tests[i].x), \
"i=%u, accum=%"PRI", x=%"PRI, \ "i=%u, accum=%"FMT", x=%"FMT, \
i, tests[i].accum0, tests[i].x); \ i, tests[i].accum0, tests[i].x); \
assert_##ta##_eq(atomic_read_##p(&accum), accum, \ assert_##ta##_eq(atomic_read_##p(&accum), accum, \
"Erroneous add, i=%u", i); \ "Erroneous add, i=%u", i); \
@ -46,7 +46,7 @@ typedef struct p##_test_s p##_test_t;
accum = tests[i].accum0; \ accum = tests[i].accum0; \
assert_##ta##_eq(atomic_sub_##p(&accum, tests[i].x), \ assert_##ta##_eq(atomic_sub_##p(&accum, tests[i].x), \
(t)((tc)tests[i].accum0 - (tc)tests[i].x), \ (t)((tc)tests[i].accum0 - (tc)tests[i].x), \
"i=%u, accum=%"PRI", x=%"PRI, \ "i=%u, accum=%"FMT", x=%"FMT, \
i, tests[i].accum0, tests[i].x); \ i, tests[i].accum0, tests[i].x); \
assert_##ta##_eq(atomic_read_##p(&accum), accum, \ assert_##ta##_eq(atomic_read_##p(&accum), accum, \
"Erroneous sub, i=%u", i); \ "Erroneous sub, i=%u", i); \
@ -72,7 +72,7 @@ TEST_BEGIN(test_atomic_uint64)
#if !(LG_SIZEOF_PTR == 3 || LG_SIZEOF_INT == 3) #if !(LG_SIZEOF_PTR == 3 || LG_SIZEOF_INT == 3)
test_skip("64-bit atomic operations not supported"); test_skip("64-bit atomic operations not supported");
#else #else
TEST_BODY(uint64, uint64_t, uint64_t, u64, PRIx64); TEST_BODY(uint64, uint64_t, uint64_t, u64, FMTx64);
#endif #endif
} }
TEST_END TEST_END
@ -81,7 +81,7 @@ TEST_STRUCT(uint32, uint32_t)
TEST_BEGIN(test_atomic_uint32) TEST_BEGIN(test_atomic_uint32)
{ {
TEST_BODY(uint32, uint32_t, uint32_t, u32, "#"PRIx32); TEST_BODY(uint32, uint32_t, uint32_t, u32, "#"FMTx32);
} }
TEST_END TEST_END
@ -97,7 +97,7 @@ TEST_STRUCT(z, size_t)
TEST_BEGIN(test_atomic_z) TEST_BEGIN(test_atomic_z)
{ {
TEST_BODY(z, size_t, size_t, zu, "#"PRIzx); TEST_BODY(z, size_t, size_t, zu, "#zx");
} }
TEST_END TEST_END

View File

@ -35,15 +35,15 @@ TEST_BEGIN(test_count_insert_search_remove)
assert_false(ckh_new(tsd, &ckh, 2, ckh_string_hash, ckh_string_keycomp), assert_false(ckh_new(tsd, &ckh, 2, ckh_string_hash, ckh_string_keycomp),
"Unexpected ckh_new() error"); "Unexpected ckh_new() error");
assert_zu_eq(ckh_count(&ckh), 0, assert_zu_eq(ckh_count(&ckh), 0,
"ckh_count() should return %"PRIzu", but it returned %"PRIzu, ZU(0), "ckh_count() should return %zu, but it returned %zu", ZU(0),
ckh_count(&ckh)); ckh_count(&ckh));
/* Insert. */ /* Insert. */
for (i = 0; i < sizeof(strs)/sizeof(const char *); i++) { for (i = 0; i < sizeof(strs)/sizeof(const char *); i++) {
ckh_insert(tsd, &ckh, strs[i], strs[i]); ckh_insert(tsd, &ckh, strs[i], strs[i]);
assert_zu_eq(ckh_count(&ckh), i+1, assert_zu_eq(ckh_count(&ckh), i+1,
"ckh_count() should return %"PRIzu", but it returned " "ckh_count() should return %zu, but it returned %zu", i+1,
"%"PRIzu, i+1, ckh_count(&ckh)); ckh_count(&ckh));
} }
/* Search. */ /* Search. */
@ -64,10 +64,10 @@ TEST_BEGIN(test_count_insert_search_remove)
ks = (i & 1) ? strs[i] : (const char *)NULL; ks = (i & 1) ? strs[i] : (const char *)NULL;
vs = (i & 2) ? strs[i] : (const char *)NULL; vs = (i & 2) ? strs[i] : (const char *)NULL;
assert_ptr_eq((void *)ks, (void *)k.s, assert_ptr_eq((void *)ks, (void *)k.s, "Key mismatch, i=%zu",
"Key mismatch, i=%"PRIzu, i); i);
assert_ptr_eq((void *)vs, (void *)v.s, assert_ptr_eq((void *)vs, (void *)v.s, "Value mismatch, i=%zu",
"Value mismatch, i=%"PRIzu, i); i);
} }
assert_true(ckh_search(&ckh, missing, NULL, NULL), assert_true(ckh_search(&ckh, missing, NULL, NULL),
"Unexpected ckh_search() success"); "Unexpected ckh_search() success");
@ -90,14 +90,14 @@ TEST_BEGIN(test_count_insert_search_remove)
ks = (i & 1) ? strs[i] : (const char *)NULL; ks = (i & 1) ? strs[i] : (const char *)NULL;
vs = (i & 2) ? strs[i] : (const char *)NULL; vs = (i & 2) ? strs[i] : (const char *)NULL;
assert_ptr_eq((void *)ks, (void *)k.s, assert_ptr_eq((void *)ks, (void *)k.s, "Key mismatch, i=%zu",
"Key mismatch, i=%"PRIzu, i); i);
assert_ptr_eq((void *)vs, (void *)v.s, assert_ptr_eq((void *)vs, (void *)v.s, "Value mismatch, i=%zu",
"Value mismatch, i=%"PRIzu, i); i);
assert_zu_eq(ckh_count(&ckh), assert_zu_eq(ckh_count(&ckh),
sizeof(strs)/sizeof(const char *) - i - 1, sizeof(strs)/sizeof(const char *) - i - 1,
"ckh_count() should return %"PRIzu", but it returned " "ckh_count() should return %zu, but it returned %zu",
"%"PRIzu, sizeof(strs)/sizeof(const char *) - i - 1, sizeof(strs)/sizeof(const char *) - i - 1,
ckh_count(&ckh)); ckh_count(&ckh));
} }
@ -137,8 +137,8 @@ TEST_BEGIN(test_insert_iter_remove)
} }
assert_zu_eq(ckh_count(&ckh), NITEMS, assert_zu_eq(ckh_count(&ckh), NITEMS,
"ckh_count() should return %"PRIzu", but it returned " "ckh_count() should return %zu, but it returned %zu",
"%"PRIzu, NITEMS, ckh_count(&ckh)); NITEMS, ckh_count(&ckh));
for (j = i + 1; j < NITEMS; j++) { for (j = i + 1; j < NITEMS; j++) {
assert_false(ckh_search(&ckh, p[j], NULL, NULL), assert_false(ckh_search(&ckh, p[j], NULL, NULL),
@ -167,20 +167,17 @@ TEST_BEGIN(test_insert_iter_remove)
for (k = 0; k < NITEMS; k++) { for (k = 0; k < NITEMS; k++) {
if (p[k] == q) { if (p[k] == q) {
assert_false(seen[k], assert_false(seen[k],
"Item %"PRIzu" already " "Item %zu already seen", k);
"seen", k);
seen[k] = true; seen[k] = true;
break; break;
} }
} }
} }
for (j = 0; j < i + 1; j++) { for (j = 0; j < i + 1; j++)
assert_true(seen[j], "Item %"PRIzu" not seen", assert_true(seen[j], "Item %zu not seen", j);
j);
}
for (; j < NITEMS; j++) for (; j < NITEMS; j++)
assert_false(seen[j], "Item %"PRIzu" seen", j); assert_false(seen[j], "Item %zu seen", j);
} }
} }
@ -199,7 +196,7 @@ TEST_BEGIN(test_insert_iter_remove)
} }
assert_zu_eq(ckh_count(&ckh), 0, assert_zu_eq(ckh_count(&ckh), 0,
"ckh_count() should return %"PRIzu", but it returned %"PRIzu, "ckh_count() should return %zu, but it returned %zu",
ZU(0), ckh_count(&ckh)); ZU(0), ckh_count(&ckh));
ckh_delete(tsd, &ckh); ckh_delete(tsd, &ckh);
#undef NITEMS #undef NITEMS

View File

@ -30,8 +30,8 @@ arena_dalloc_junk_small_intercept(void *ptr, arena_bin_info_t *bin_info)
arena_dalloc_junk_small_orig(ptr, bin_info); arena_dalloc_junk_small_orig(ptr, bin_info);
for (i = 0; i < bin_info->reg_size; i++) { for (i = 0; i < bin_info->reg_size; i++) {
assert_c_eq(((char *)ptr)[i], 0x5a, assert_c_eq(((char *)ptr)[i], 0x5a,
"Missing junk fill for byte %"PRIzu"/%"PRIzu" of " "Missing junk fill for byte %zu/%zu of deallocated region",
"deallocated region", i, bin_info->reg_size); i, bin_info->reg_size);
} }
if (ptr == watch_for_junking) if (ptr == watch_for_junking)
saw_junking = true; saw_junking = true;
@ -45,8 +45,8 @@ arena_dalloc_junk_large_intercept(void *ptr, size_t usize)
arena_dalloc_junk_large_orig(ptr, usize); arena_dalloc_junk_large_orig(ptr, usize);
for (i = 0; i < usize; i++) { for (i = 0; i < usize; i++) {
assert_c_eq(((char *)ptr)[i], 0x5a, assert_c_eq(((char *)ptr)[i], 0x5a,
"Missing junk fill for byte %"PRIzu"/%"PRIzu" of " "Missing junk fill for byte %zu/%zu of deallocated region",
"deallocated region", i, usize); i, usize);
} }
if (ptr == watch_for_junking) if (ptr == watch_for_junking)
saw_junking = true; saw_junking = true;
@ -89,18 +89,18 @@ test_junk(size_t sz_min, size_t sz_max)
sz_prev = sz, sz = sallocx(s, 0)) { sz_prev = sz, sz = sallocx(s, 0)) {
if (sz_prev > 0) { if (sz_prev > 0) {
assert_c_eq(s[0], 'a', assert_c_eq(s[0], 'a',
"Previously allocated byte %"PRIzu"/%"PRIzu" is " "Previously allocated byte %zu/%zu is corrupted",
"corrupted", ZU(0), sz_prev); ZU(0), sz_prev);
assert_c_eq(s[sz_prev-1], 'a', assert_c_eq(s[sz_prev-1], 'a',
"Previously allocated byte %"PRIzu"/%"PRIzu" is " "Previously allocated byte %zu/%zu is corrupted",
"corrupted", sz_prev-1, sz_prev); sz_prev-1, sz_prev);
} }
for (i = sz_prev; i < sz; i++) { for (i = sz_prev; i < sz; i++) {
if (opt_junk_alloc) { if (opt_junk_alloc) {
assert_c_eq(s[i], 0xa5, assert_c_eq(s[i], 0xa5,
"Newly allocated byte %"PRIzu"/%"PRIzu "Newly allocated byte %zu/%zu isn't "
" isn't junk-filled", i, sz); "junk-filled", i, sz);
} }
s[i] = 'a'; s[i] = 'a';
} }
@ -111,15 +111,15 @@ test_junk(size_t sz_min, size_t sz_max)
assert_ptr_not_null((void *)s, assert_ptr_not_null((void *)s,
"Unexpected rallocx() failure"); "Unexpected rallocx() failure");
assert_true(!opt_junk_free || saw_junking, assert_true(!opt_junk_free || saw_junking,
"Expected region of size %"PRIzu" to be " "Expected region of size %zu to be junk-filled",
"junk-filled", sz); sz);
} }
} }
watch_junking(s); watch_junking(s);
dallocx(s, 0); dallocx(s, 0);
assert_true(!opt_junk_free || saw_junking, assert_true(!opt_junk_free || saw_junking,
"Expected region of size %"PRIzu" to be junk-filled", sz); "Expected region of size %zu to be junk-filled", sz);
if (opt_junk_free) { if (opt_junk_free) {
arena_dalloc_junk_small = arena_dalloc_junk_small_orig; arena_dalloc_junk_small = arena_dalloc_junk_small_orig;

View File

@ -72,7 +72,7 @@ TEST_BEGIN(test_rtree_bits)
&node, "rtree_get() should return " &node, "rtree_get() should return "
"previously set value and ignore " "previously set value and ignore "
"insignificant key bits; i=%u, j=%u, k=%u, " "insignificant key bits; i=%u, j=%u, k=%u, "
"set key=%#"PRIxPTR", get key=%#"PRIxPTR, i, "set key=%#"FMTxPTR", get key=%#"FMTxPTR, i,
j, k, keys[j], keys[k]); j, k, keys[j], keys[k]);
} }
assert_ptr_null(rtree_get(&rtree, assert_ptr_null(rtree_get(&rtree,