summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Evans <jasone@canonware.com>2015-07-23 20:56:25 (GMT)
committerJason Evans <jasone@canonware.com>2015-07-23 20:56:25 (GMT)
commit5fae7dc1b316d0e93aa20cc3aaf050f509aec705 (patch)
treee17384be2f44b4cdffa4748f50f4f30dc7dd9c12 /src
parente475ff16004d9a7c76a01a71e6a52323e6bf1485 (diff)
downloadjemalloc-5fae7dc1b316d0e93aa20cc3aaf050f509aec705.zip
jemalloc-5fae7dc1b316d0e93aa20cc3aaf050f509aec705.tar.gz
jemalloc-5fae7dc1b316d0e93aa20cc3aaf050f509aec705.tar.bz2
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.
Diffstat (limited to 'src')
-rw-r--r--src/arena.c4
-rw-r--r--src/ckh.c6
-rw-r--r--src/prof.c20
-rw-r--r--src/stats.c89
4 files changed, 59 insertions, 60 deletions
diff --git a/src/arena.c b/src/arena.c
index 65aad20..10cd0d2 100644
--- a/src/arena.c
+++ b/src/arena.c
@@ -1886,8 +1886,8 @@ arena_redzone_corruption(void *ptr, size_t usize, bool after,
size_t offset, uint8_t byte)
{
- malloc_printf("<jemalloc>: Corrupt redzone %"PRIzu" byte%s %s %p "
- "(size %"PRIzu"), byte=%#x\n", offset, (offset == 1) ? "" : "s",
+ malloc_printf("<jemalloc>: Corrupt redzone %zu byte%s %s %p "
+ "(size %zu), byte=%#x\n", offset, (offset == 1) ? "" : "s",
after ? "after" : "before", ptr, usize, byte);
}
#ifdef JEMALLOC_JET
diff --git a/src/ckh.c b/src/ckh.c
index da78d1b..53a1c1e 100644
--- a/src/ckh.c
+++ b/src/ckh.c
@@ -411,9 +411,9 @@ ckh_delete(tsd_t *tsd, ckh_t *ckh)
#ifdef CKH_VERBOSE
malloc_printf(
- "%s(%p): ngrows: %"PRIu64", nshrinks: %"PRIu64","
- " nshrinkfails: %"PRIu64", ninserts: %"PRIu64","
- " nrelocs: %"PRIu64"\n", __func__, ckh,
+ "%s(%p): ngrows: %"FMTu64", nshrinks: %"FMTu64","
+ " nshrinkfails: %"FMTu64", ninserts: %"FMTu64","
+ " nrelocs: %"FMTu64"\n", __func__, ckh,
(unsigned long long)ckh->ngrows,
(unsigned long long)ckh->nshrinks,
(unsigned long long)ckh->nshrinkfails,
diff --git a/src/prof.c b/src/prof.c
index babdbd6..a05792f 100644
--- a/src/prof.c
+++ b/src/prof.c
@@ -1095,7 +1095,7 @@ prof_tctx_dump_iter(prof_tctx_tree_t *tctxs, prof_tctx_t *tctx, void *arg)
bool propagate_err = *(bool *)arg;
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->dump_cnts.accumobjs, tctx->dump_cnts.accumbytes))
return (tctx);
@@ -1247,7 +1247,7 @@ prof_tdata_dump_iter(prof_tdata_tree_t *tdatas, prof_tdata_t *tdata, void *arg)
return (NULL);
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->cnt_summed.curbytes, tdata->cnt_summed.accumobjs,
tdata->cnt_summed.accumbytes,
@@ -1267,8 +1267,8 @@ prof_dump_header(bool propagate_err, const prof_cnt_t *cnt_all)
bool ret;
if (prof_dump_printf(propagate_err,
- "heap_v2/%"PRIu64"\n"
- " t*: %"PRIu64": %"PRIu64" [%"PRIu64": %"PRIu64"]\n",
+ "heap_v2/%"FMTu64"\n"
+ " t*: %"FMTu64": %"FMTu64" [%"FMTu64": %"FMTu64"]\n",
((uint64_t)1U << lg_prof_sample), cnt_all->curobjs,
cnt_all->curbytes, cnt_all->accumobjs, cnt_all->accumbytes))
return (true);
@@ -1311,7 +1311,7 @@ prof_dump_gctx(bool propagate_err, prof_gctx_t *gctx, const prof_bt_t *bt,
goto label_return;
}
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])) {
ret = true;
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,
"\n"
- " t*: %"PRIu64": %"PRIu64" [%"PRIu64": %"PRIu64"]\n",
+ " t*: %"FMTu64": %"FMTu64" [%"FMTu64": %"FMTu64"]\n",
gctx->cnt_summed.curobjs, gctx->cnt_summed.curbytes,
gctx->cnt_summed.accumobjs, gctx->cnt_summed.accumbytes)) {
ret = true;
@@ -1412,8 +1412,8 @@ prof_leakcheck(const prof_cnt_t *cnt_all, size_t leak_ngctx,
{
if (cnt_all->curbytes != 0) {
- malloc_printf("<jemalloc>: Leak summary: %"PRIu64" byte%s, %"
- PRIu64" object%s, %"PRIzu" context%s\n",
+ malloc_printf("<jemalloc>: Leak summary: %"FMTu64" byte%s, %"
+ FMTu64" object%s, %zu context%s\n",
cnt_all->curbytes, (cnt_all->curbytes != 1) ? "s" : "",
cnt_all->curobjs, (cnt_all->curobjs != 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) {
/* "<prefix>.<pid>.<seq>.v<vseq>.heap" */
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);
} else {
/* "<prefix>.<pid>.<seq>.<v>.heap" */
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);
}
prof_dump_seq++;
diff --git a/src/stats.c b/src/stats.c
index 57fd650..154c3e7 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -119,32 +119,32 @@ stats_arena_bins_print(void (*write_cb)(void *, const char *), void *cbopaque,
assert(milli <= 1000);
if (milli < 10) {
malloc_snprintf(util, sizeof(util),
- "0.00%"PRIzu, milli);
+ "0.00%zu", milli);
} else if (milli < 100) {
- malloc_snprintf(util, sizeof(util), "0.0%"PRIzu,
+ malloc_snprintf(util, sizeof(util), "0.0%zu",
milli);
} else if (milli < 1000) {
- malloc_snprintf(util, sizeof(util), "0.%"PRIzu,
+ malloc_snprintf(util, sizeof(util), "0.%zu",
milli);
} else
malloc_snprintf(util, sizeof(util), "1");
if (config_tcache) {
malloc_cprintf(write_cb, cbopaque,
- "%20"PRIzu" %3u %12"PRIzu" %12"PRIu64
- " %12"PRIu64" %12"PRIu64" %12"PRIzu
- " %12"PRIzu" %4u %3"PRIzu" %-5s %12"PRIu64
- " %12"PRIu64" %12"PRIu64" %12"PRIu64"\n",
+ "%20zu %3u %12zu %12"FMTu64
+ " %12"FMTu64" %12"FMTu64" %12zu"
+ " %12zu %4u %3zu %-5s %12"FMTu64
+ " %12"FMTu64" %12"FMTu64" %12"FMTu64"\n",
reg_size, j, curregs * reg_size, nmalloc,
ndalloc, nrequests, curregs, curruns, nregs,
run_size / page, util, nfills, nflushes,
nruns, reruns);
} else {
malloc_cprintf(write_cb, cbopaque,
- "%20"PRIzu" %3u %12"PRIzu" %12"PRIu64
- " %12"PRIu64" %12"PRIu64" %12"PRIzu
- " %12"PRIzu" %4u %3"PRIzu" %-5s %12"PRIu64
- " %12"PRIu64"\n",
+ "%20zu %3u %12zu %12"FMTu64
+ " %12"FMTu64" %12"FMTu64" %12zu"
+ " %12zu %4u %3zu %-5s %12"FMTu64
+ " %12"FMTu64"\n",
reg_size, j, curregs * reg_size, nmalloc,
ndalloc, nrequests, curregs, curruns, nregs,
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;
}
malloc_cprintf(write_cb, cbopaque,
- "%20"PRIzu" %3u %12"PRIzu" %12"PRIu64" %12"PRIu64
- " %12"PRIu64" %12"PRIzu"\n",
+ "%20zu %3u %12zu %12"FMTu64" %12"FMTu64
+ " %12"FMTu64" %12zu\n",
run_size, nbins + j, curruns * run_size, nmalloc,
ndalloc, nrequests, curruns);
}
@@ -239,8 +239,8 @@ stats_arena_hchunks_print(void (*write_cb)(void *, const char *),
in_gap = false;
}
malloc_cprintf(write_cb, cbopaque,
- "%20"PRIzu" %3u %12"PRIzu" %12"PRIu64" %12"PRIu64
- " %12"PRIu64" %12"PRIzu"\n",
+ "%20zu %3u %12zu %12"FMTu64" %12"FMTu64
+ " %12"FMTu64" %12zu\n",
hchunk_size, nbins + nlruns + j,
curhchunks * hchunk_size, nmalloc, ndalloc,
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.purged", i, &purged, uint64_t);
malloc_cprintf(write_cb, cbopaque,
- "dirty pages: %"PRIzu":%"PRIzu" active:dirty, %"PRIu64" sweep%s,"
- " %"PRIu64" madvise%s, %"PRIu64" purged\n",
- pactive, pdirty, npurge, npurge == 1 ? "" : "s",
- nmadvise, nmadvise == 1 ? "" : "s", purged);
+ "dirty pages: %zu:%zu active:dirty, %"FMTu64" sweep%s, %"FMTu64
+ " madvise%s, %"FMTu64" purged\n", pactive, pdirty, npurge, npurge ==
+ 1 ? "" : "s", nmadvise, nmadvise == 1 ? "" : "s", purged);
malloc_cprintf(write_cb, cbopaque,
" 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,
uint64_t);
malloc_cprintf(write_cb, cbopaque,
- "small: %12"PRIzu" %12"PRIu64" %12"PRIu64
- " %12"PRIu64"\n",
+ "small: %12zu %12"FMTu64" %12"FMTu64
+ " %12"FMTu64"\n",
small_allocated, small_nmalloc, small_ndalloc, small_nrequests);
CTL_M2_GET("stats.arenas.0.large.allocated", i, &large_allocated,
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,
uint64_t);
malloc_cprintf(write_cb, cbopaque,
- "large: %12"PRIzu" %12"PRIu64" %12"PRIu64
- " %12"PRIu64"\n",
+ "large: %12zu %12"FMTu64" %12"FMTu64
+ " %12"FMTu64"\n",
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.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,
uint64_t);
malloc_cprintf(write_cb, cbopaque,
- "huge: %12"PRIzu" %12"PRIu64" %12"PRIu64
- " %12"PRIu64"\n",
+ "huge: %12zu %12"FMTu64" %12"FMTu64
+ " %12"FMTu64"\n",
huge_allocated, huge_nmalloc, huge_ndalloc, huge_nrequests);
malloc_cprintf(write_cb, cbopaque,
- "total: %12"PRIzu" %12"PRIu64" %12"PRIu64
- " %12"PRIu64"\n",
+ "total: %12zu %12"FMTu64" %12"FMTu64
+ " %12"FMTu64"\n",
small_allocated + large_allocated + huge_allocated,
small_nmalloc + large_nmalloc + huge_nmalloc,
small_ndalloc + large_ndalloc + huge_ndalloc,
small_nrequests + large_nrequests + huge_nrequests);
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);
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,
size_t);
CTL_M2_GET("stats.arenas.0.metadata.allocated", i, &metadata_allocated,
size_t);
malloc_cprintf(write_cb, cbopaque,
- "metadata: mapped: %"PRIzu", allocated: %"PRIzu"\n",
+ "metadata: mapped: %zu, allocated: %zu\n",
metadata_mapped, metadata_allocated);
if (bins)
@@ -457,19 +456,19 @@ stats_print(void (*write_cb)(void *, const char *), void *cbopaque,
#define OPT_WRITE_SIZE_T(n) \
if (je_mallctl("opt."#n, &sv, &ssz, NULL, 0) == 0) { \
malloc_cprintf(write_cb, cbopaque, \
- " opt."#n": %"PRIzu"\n", sv); \
+ " opt."#n": %zu\n", sv); \
}
#define OPT_WRITE_SSIZE_T(n) \
if (je_mallctl("opt."#n, &ssv, &sssz, NULL, 0) == 0) { \
malloc_cprintf(write_cb, cbopaque, \
- " opt."#n": %"PRIzd"\n", ssv); \
+ " opt."#n": %zd\n", ssv); \
}
#define OPT_WRITE_SSIZE_T_MUTABLE(n, m) { \
ssize_t ssv2; \
if (je_mallctl("opt."#n, &ssv, &sssz, NULL, 0) == 0 && \
je_mallctl(#m, &ssv2, &sssz, NULL, 0) == 0) { \
malloc_cprintf(write_cb, cbopaque, \
- " opt."#n": %"PRIzd" ("#m": %"PRIzd")\n", \
+ " opt."#n": %zd ("#m": %zd)\n", \
ssv, ssv2); \
} \
}
@@ -519,15 +518,15 @@ stats_print(void (*write_cb)(void *, const char *), void *cbopaque,
CTL_GET("arenas.narenas", &uv, unsigned);
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 *));
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);
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);
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) {
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) {
CTL_GET("prof.lg_sample", &sv, size_t);
malloc_cprintf(write_cb, cbopaque,
- "Average profile sample interval: %"PRIu64
- " (2^%"PRIzu")\n", (((uint64_t)1U) << sv), sv);
+ "Average profile sample interval: %"FMTu64
+ " (2^%zu)\n", (((uint64_t)1U) << sv), sv);
CTL_GET("opt.lg_prof_interval", &ssv, ssize_t);
if (ssv >= 0) {
malloc_cprintf(write_cb, cbopaque,
- "Average profile dump interval: %"PRIu64
- " (2^%"PRIzd")\n",
+ "Average profile dump interval: %"FMTu64
+ " (2^%zd)\n",
(((uint64_t)1U) << ssv), ssv);
} else {
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);
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) {
@@ -575,11 +574,11 @@ stats_print(void (*write_cb)(void *, const char *), void *cbopaque,
CTL_GET("stats.resident", &resident, size_t);
CTL_GET("stats.mapped", &mapped, size_t);
malloc_cprintf(write_cb, cbopaque,
- "Allocated: %"PRIzu", active: %"PRIzu", metadata: %"PRIzu","
- " resident: %"PRIzu", mapped: %"PRIzu"\n",
+ "Allocated: %zu, active: %zu, metadata: %zu,"
+ " resident: %zu, mapped: %zu\n",
allocated, active, metadata, resident, mapped);
malloc_cprintf(write_cb, cbopaque,
- "Current active ceiling: %"PRIzu"\n",
+ "Current active ceiling: %zu\n",
atomic_read_z(cactive));
if (merged) {