Commit 4d47e89f authored by Hallvard Furuseth's avatar Hallvard Furuseth
Browse files

MDB_VL32: Switch to mdb_size_t formats PRIu64 & co

Drop macro Y=MDB_FMT_Y, add Yu/Yd=MDB_PRIy(). Replace
Y"d..." -> Yd"...", Y"u..." -> Yu"..." / MDB_SCNy(u)"...".
parent 65d9791a
......@@ -186,31 +186,21 @@ typedef mode_t mdb_mode_t;
# define MDB_FMT_Z "z" /**< printf/scanf format modifier for size_t */
#endif
#if !defined(MDB_VL32) || SIZE_MAX > 0xffffffffU
#ifndef MDB_VL32
typedef size_t mdb_size_t;
# define MDB_SIZE_MAX SIZE_MAX /**< max #mdb_size_t */
# define MDB_FMT_Y MDB_FMT_Z /**< Obsolescent, see #MDB_PRIz()/#MDB_SCNz() */
/* TODO: For VL32, use uint64_t (trivial) and therefore PRI<c>64 (big patch) */
#elif defined(_WIN32)
typedef unsigned __int64 mdb_size_t;
# define MDB_SIZE_MAX _UI64_MAX
# define MDB_FMT_Y "I64"
#elif defined(ULLONG_MAX)
typedef unsigned long long mdb_size_t;
# define MDB_SIZE_MAX ULLONG_MAX
# define MDB_FMT_Y "ll"
/** #mdb_size_t printf formats, \b t = one of [diouxX] without quotes */
# define MDB_PRIy(t) MDB_FMT_Z #t
/** #mdb_size_t scanf formats, \b t = one of [dioux] without quotes */
# define MDB_SCNy(t) MDB_FMT_Z #t
#else
# error "Found no acceptable integer type for mdb_size_t"
#endif
#ifdef MDB_VL32
typedef uint64_t mdb_size_t;
# define MDB_SIZE_MAX UINT64_MAX
# define MDB_PRIy(t) PRI##t##64
# define MDB_SCNy(t) SCN##t##64
# define mdb_env_create mdb_env_create_vl32 /**< Prevent mixing with non-VL32 builds */
#endif
/** #mdb_size_t printf formats, \b t = one of [diouxX] without quotes */
#define MDB_PRIz(t) MDB_FMT_Y #t
/** #mdb_size_t scanf formats, \b t = one of [dioux] without quotes */
#define MDB_SCNz(t) MDB_FMT_Y #t
/** An abstraction for a file handle.
* On POSIX systems file handles are small integers. On Windows
* they're opaque pointers.
......
This diff is collapsed.
......@@ -20,7 +20,7 @@
#include <signal.h>
#include "lmdb.h"
#define Y MDB_FMT_Y
#define Yu MDB_PRIy(u)
#define PRINT 1
static int mode;
......@@ -111,7 +111,7 @@ static int dumpit(MDB_txn *txn, MDB_dbi dbi, char *name)
if (name)
printf("database=%s\n", name);
printf("type=btree\n");
printf("mapsize=%" Y "u\n", info.me_mapsize);
printf("mapsize=%"Yu"\n", info.me_mapsize);
if (info.me_mapaddr)
printf("mapaddr=%p\n", info.me_mapaddr);
printf("maxreaders=%u\n", info.me_maxreaders);
......
......@@ -38,7 +38,7 @@ static MDB_envinfo info;
static MDB_val kbuf, dbuf;
#define Y MDB_FMT_Y
#define Yu MDB_PRIy(u)
#define STRLENOF(s) (sizeof(s)-1)
......@@ -69,7 +69,7 @@ static void readhdr(void)
if (!strncmp(dbuf.mv_data, "VERSION=", STRLENOF("VERSION="))) {
version=atoi((char *)dbuf.mv_data+STRLENOF("VERSION="));
if (version > 3) {
fprintf(stderr, "%s: line %" Y "u: unsupported VERSION %d\n",
fprintf(stderr, "%s: line %"Yu": unsupported VERSION %d\n",
prog, lineno, version);
exit(EXIT_FAILURE);
}
......@@ -79,7 +79,7 @@ static void readhdr(void)
if (!strncmp((char *)dbuf.mv_data+STRLENOF("FORMAT="), "print", STRLENOF("print")))
mode |= PRINT;
else if (strncmp((char *)dbuf.mv_data+STRLENOF("FORMAT="), "bytevalue", STRLENOF("bytevalue"))) {
fprintf(stderr, "%s: line %" Y "u: unsupported FORMAT %s\n",
fprintf(stderr, "%s: line %"Yu": unsupported FORMAT %s\n",
prog, lineno, (char *)dbuf.mv_data+STRLENOF("FORMAT="));
exit(EXIT_FAILURE);
}
......@@ -90,7 +90,7 @@ static void readhdr(void)
subname = strdup((char *)dbuf.mv_data+STRLENOF("database="));
} else if (!strncmp(dbuf.mv_data, "type=", STRLENOF("type="))) {
if (strncmp((char *)dbuf.mv_data+STRLENOF("type="), "btree", STRLENOF("btree"))) {
fprintf(stderr, "%s: line %" Y "u: unsupported type %s\n",
fprintf(stderr, "%s: line %"Yu": unsupported type %s\n",
prog, lineno, (char *)dbuf.mv_data+STRLENOF("type="));
exit(EXIT_FAILURE);
}
......@@ -100,7 +100,7 @@ static void readhdr(void)
if (ptr) *ptr = '\0';
i = sscanf((char *)dbuf.mv_data+STRLENOF("mapaddr="), "%p", &info.me_mapaddr);
if (i != 1) {
fprintf(stderr, "%s: line %" Y "u: invalid mapaddr %s\n",
fprintf(stderr, "%s: line %"Yu": invalid mapaddr %s\n",
prog, lineno, (char *)dbuf.mv_data+STRLENOF("mapaddr="));
exit(EXIT_FAILURE);
}
......@@ -108,9 +108,10 @@ static void readhdr(void)
int i;
ptr = memchr(dbuf.mv_data, '\n', dbuf.mv_size);
if (ptr) *ptr = '\0';
i = sscanf((char *)dbuf.mv_data+STRLENOF("mapsize="), "%" Y "u", &info.me_mapsize);
i = sscanf((char *)dbuf.mv_data+STRLENOF("mapsize="),
"%" MDB_SCNy(u), &info.me_mapsize);
if (i != 1) {
fprintf(stderr, "%s: line %" Y "u: invalid mapsize %s\n",
fprintf(stderr, "%s: line %"Yu": invalid mapsize %s\n",
prog, lineno, (char *)dbuf.mv_data+STRLENOF("mapsize="));
exit(EXIT_FAILURE);
}
......@@ -120,7 +121,7 @@ static void readhdr(void)
if (ptr) *ptr = '\0';
i = sscanf((char *)dbuf.mv_data+STRLENOF("maxreaders="), "%u", &info.me_maxreaders);
if (i != 1) {
fprintf(stderr, "%s: line %" Y "u: invalid maxreaders %s\n",
fprintf(stderr, "%s: line %"Yu": invalid maxreaders %s\n",
prog, lineno, (char *)dbuf.mv_data+STRLENOF("maxreaders="));
exit(EXIT_FAILURE);
}
......@@ -136,12 +137,12 @@ static void readhdr(void)
if (!dbflags[i].bit) {
ptr = memchr(dbuf.mv_data, '=', dbuf.mv_size);
if (!ptr) {
fprintf(stderr, "%s: line %" Y "u: unexpected format\n",
fprintf(stderr, "%s: line %"Yu": unexpected format\n",
prog, lineno);
exit(EXIT_FAILURE);
} else {
*ptr = '\0';
fprintf(stderr, "%s: line %" Y "u: unrecognized keyword ignored: %s\n",
fprintf(stderr, "%s: line %"Yu": unrecognized keyword ignored: %s\n",
prog, lineno, (char *)dbuf.mv_data);
}
}
......@@ -151,7 +152,7 @@ static void readhdr(void)
static void badend(void)
{
fprintf(stderr, "%s: line %" Y "u: unexpected end of input\n",
fprintf(stderr, "%s: line %"Yu": unexpected end of input\n",
prog, lineno);
}
......@@ -209,7 +210,7 @@ badend:
buf->mv_data = realloc(buf->mv_data, buf->mv_size*2);
if (!buf->mv_data) {
Eof = 1;
fprintf(stderr, "%s: line %" Y "u: out of memory, line too long\n",
fprintf(stderr, "%s: line %"Yu": out of memory, line too long\n",
prog, lineno);
return EOF;
}
......@@ -401,7 +402,7 @@ int main(int argc, char *argv[])
rc = readline(&data, &dbuf);
if (rc) {
fprintf(stderr, "%s: line %" Y "u: failed to read key value\n", prog, lineno);
fprintf(stderr, "%s: line %"Yu": failed to read key value\n", prog, lineno);
goto txn_abort;
}
......@@ -416,7 +417,7 @@ int main(int argc, char *argv[])
if (batch == 100) {
rc = mdb_txn_commit(txn);
if (rc) {
fprintf(stderr, "%s: line %" Y "u: txn_commit: %s\n",
fprintf(stderr, "%s: line %"Yu": txn_commit: %s\n",
prog, lineno, mdb_strerror(rc));
goto env_close;
}
......@@ -436,7 +437,7 @@ int main(int argc, char *argv[])
rc = mdb_txn_commit(txn);
txn = NULL;
if (rc) {
fprintf(stderr, "%s: line %" Y "u: txn_commit: %s\n",
fprintf(stderr, "%s: line %"Yu": txn_commit: %s\n",
prog, lineno, mdb_strerror(rc));
goto env_close;
}
......
......@@ -18,7 +18,7 @@
#include "lmdb.h"
#define Z MDB_FMT_Z
#define Y MDB_FMT_Y
#define Yu MDB_PRIy(u)
static void prstat(MDB_stat *ms)
{
......@@ -26,10 +26,10 @@ static void prstat(MDB_stat *ms)
printf(" Page size: %u\n", ms->ms_psize);
#endif
printf(" Tree depth: %u\n", ms->ms_depth);
printf(" Branch pages: %"Y"u\n", ms->ms_branch_pages);
printf(" Leaf pages: %"Y"u\n", ms->ms_leaf_pages);
printf(" Overflow pages: %"Y"u\n", ms->ms_overflow_pages);
printf(" Entries: %"Y"u\n", ms->ms_entries);
printf(" Branch pages: %"Yu"\n", ms->ms_branch_pages);
printf(" Leaf pages: %"Yu"\n", ms->ms_leaf_pages);
printf(" Overflow pages: %"Yu"\n", ms->ms_overflow_pages);
printf(" Entries: %"Yu"\n", ms->ms_entries);
}
static void usage(char *prog)
......@@ -122,11 +122,11 @@ int main(int argc, char *argv[])
(void)mdb_env_info(env, &mei);
printf("Environment Info\n");
printf(" Map address: %p\n", mei.me_mapaddr);
printf(" Map size: %"Y"u\n", mei.me_mapsize);
printf(" Map size: %"Yu"\n", mei.me_mapsize);
printf(" Page size: %u\n", mst.ms_psize);
printf(" Max pages: %"Y"u\n", mei.me_mapsize / mst.ms_psize);
printf(" Number of pages used: %"Y"u\n", mei.me_last_pgno+1);
printf(" Last transaction ID: %"Y"u\n", mei.me_last_txnid);
printf(" Max pages: %"Yu"\n", mei.me_mapsize / mst.ms_psize);
printf(" Number of pages used: %"Yu"\n", mei.me_last_pgno+1);
printf(" Last transaction ID: %"Yu"\n", mei.me_last_txnid);
printf(" Max readers: %u\n", mei.me_maxreaders);
printf(" Number of readers used: %u\n", mei.me_numreaders);
}
......@@ -184,20 +184,20 @@ int main(int argc, char *argv[])
pg += span;
for (; i >= span && iptr[i-span] == pg; span++, pg++) ;
}
printf(" Transaction %"Y"u, %"Z"d pages, maxspan %"Z"d%s\n",
printf(" Transaction %"Yu", %"Z"d pages, maxspan %"Z"d%s\n",
*(mdb_size_t *)key.mv_data, j, span, bad);
if (freinfo > 2) {
for (--j; j >= 0; ) {
pg = iptr[j];
for (span=1; --j >= 0 && iptr[j] == pg+span; span++) ;
printf(span>1 ? " %9"Y"u[%"Z"d]\n" : " %9"Y"u\n",
printf(span>1 ? " %9"Yu"[%"Z"d]\n" : " %9"Yu"\n",
pg, span);
}
}
}
}
mdb_cursor_close(cursor);
printf(" Free pages: %"Y"u\n", pages);
printf(" Free pages: %"Yu"\n", pages);
}
rc = mdb_open(txn, subname, 0, &dbi);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment