Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Joe Martin
OpenLDAP
Commits
a1b4144b
Commit
a1b4144b
authored
Aug 19, 2011
by
Hallvard Furuseth
Committed by
Howard Chu
Sep 01, 2011
Browse files
Drop gcc extension ,##__VA_ARGS__. Add DPUTS().
C99 says DPRINTF(fmt, ...) must get at least 2 args. Using DPUTS for 1 arg.
parent
8f770433
Changes
1
Hide whitespace changes
Inline
Side-by-side
libraries/libmdb/mdb.c
View file @
a1b4144b
...
...
@@ -59,12 +59,15 @@ typedef ULONG pgno_t;
#define DEBUG 1
#endif
#if DEBUG && defined(__GNUC__)
# define DPRINTF(fmt, ...) \
fprintf(stderr, "%s:%d: " fmt "\n", __func__, __LINE__, ##__VA_ARGS__)
#if !(__STDC_VERSION__ >= 199901L || defined(__GNUC__))
# define DPRINTF (void)
/* Vararg macros may be unsupported */
#elif DEBUG
# define DPRINTF(fmt, ...)
/* Requires 2 or more args */
\
fprintf(stderr, "%s:%d: " fmt "\n", __func__, __LINE__, __VA_ARGS__)
#else
# define DPRINTF(...) ((void) 0)
# define DPRINTF(
fmt,
...) ((void) 0)
#endif
#define DPUTS(arg) DPRINTF("%s", arg)
#define PAGESIZE 4096
#define MDB_MINKEYS 4
...
...
@@ -665,7 +668,7 @@ mdb_txn_begin(MDB_env *env, int rdonly, MDB_txn **ret)
int
rc
,
toggle
;
if
(
env
->
me_flags
&
MDB_FATAL_ERROR
)
{
DP
RINTF
(
"mdb_txn_begin: environment had fatal error, must shutdown!"
);
DP
UTS
(
"mdb_txn_begin: environment had fatal error, must shutdown!"
);
return
MDB_PANIC
;
}
if
((
txn
=
calloc
(
1
,
sizeof
(
MDB_txn
)))
==
NULL
)
{
...
...
@@ -804,13 +807,13 @@ mdb_txn_commit(MDB_txn *txn)
}
if
(
txn
!=
env
->
me_txn
)
{
DP
RINTF
(
"attempt to commit unknown transaction"
);
DP
UTS
(
"attempt to commit unknown transaction"
);
mdb_txn_abort
(
txn
);
return
EINVAL
;
}
if
(
F_ISSET
(
txn
->
mt_flags
,
MDB_TXN_ERROR
))
{
DP
RINTF
(
"error flag is set, can't commit"
);
DP
UTS
(
"error flag is set, can't commit"
);
mdb_txn_abort
(
txn
);
return
EINVAL
;
}
...
...
@@ -898,7 +901,7 @@ mdb_txn_commit(MDB_txn *txn)
if
(
rc
!=
size
)
{
n
=
errno
;
if
(
rc
>
0
)
DP
RINTF
(
"short write, filesystem full?"
);
DP
UTS
(
"short write, filesystem full?"
);
else
DPRINTF
(
"writev: %s"
,
strerror
(
errno
));
mdb_txn_abort
(
txn
);
...
...
@@ -931,7 +934,7 @@ mdb_txn_commit(MDB_txn *txn)
if
(
rc
!=
size
)
{
n
=
errno
;
if
(
rc
>
0
)
DP
RINTF
(
"short write, filesystem full?"
);
DP
UTS
(
"short write, filesystem full?"
);
else
DPRINTF
(
"writev: %s"
,
strerror
(
errno
));
mdb_txn_abort
(
txn
);
...
...
@@ -1011,7 +1014,7 @@ mdb_env_read_header(MDB_env *env, MDB_meta *meta)
m
=
METADATA
(
p
);
if
(
m
->
mm_magic
!=
MDB_MAGIC
)
{
DP
RINTF
(
"meta has invalid magic"
);
DP
UTS
(
"meta has invalid magic"
);
return
EINVAL
;
}
...
...
@@ -1033,7 +1036,7 @@ mdb_env_init_meta(MDB_env *env, MDB_meta *meta)
int
rc
;
unsigned
int
psize
;
DP
RINTF
(
"writing new meta page"
);
DP
UTS
(
"writing new meta page"
);
psize
=
sysconf
(
_SC_PAGE_SIZE
);
meta
->
mm_magic
=
MDB_MAGIC
;
...
...
@@ -1103,7 +1106,7 @@ mdb_env_write_meta(MDB_txn *txn)
/* Write to the SYNC fd */
rc
=
pwrite
(
env
->
me_mfd
,
ptr
,
len
,
off
);
if
(
rc
!=
len
)
{
DP
RINTF
(
"write failed, disk error?"
);
DP
UTS
(
"write failed, disk error?"
);
/* On a failure, the pagecache still contains the new data.
* Write some old data back, to prevent it from being used.
* Use the non-SYNC fd; we know it will fail anyway.
...
...
@@ -1202,7 +1205,7 @@ mdb_env_open2(MDB_env *env, unsigned int flags)
if
((
i
=
mdb_env_read_header
(
env
,
&
meta
))
!=
0
)
{
if
(
i
!=
ENOENT
)
return
i
;
DP
RINTF
(
"new mdbenv"
);
DP
UTS
(
"new mdbenv"
);
newenv
=
1
;
}
...
...
@@ -1347,7 +1350,7 @@ mdb_env_setup_locks(MDB_env *env, char *lpath, int mode, int *excl)
}
else
{
if
(
env
->
me_txns
->
mti_magic
!=
MDB_MAGIC
)
{
DP
RINTF
(
"lock region has invalid magic"
);
DP
UTS
(
"lock region has invalid magic"
);
rc
=
EINVAL
;
goto
fail
;
}
...
...
@@ -1680,13 +1683,13 @@ mdb_search_page(MDB_txn *txn, MDB_dbi dbi, MDB_val *key,
* committed root page.
*/
if
(
F_ISSET
(
txn
->
mt_flags
,
MDB_TXN_ERROR
))
{
DP
RINTF
(
"transaction has failed, must abort"
);
DP
UTS
(
"transaction has failed, must abort"
);
return
EINVAL
;
}
else
root
=
txn
->
mt_dbs
[
dbi
].
md_root
;
if
(
root
==
P_INVALID
)
{
/* Tree is empty. */
DP
RINTF
(
"tree is empty"
);
DP
UTS
(
"tree is empty"
);
return
MDB_NOTFOUND
;
}
...
...
@@ -1873,7 +1876,7 @@ mdb_cursor_next(MDB_cursor *cursor, MDB_val *key, MDB_val *data, MDB_cursor_op o
DPRINTF
(
"cursor_next: top page is %lu in cursor %p"
,
mp
->
mp_pgno
,
(
void
*
)
cursor
);
if
(
top
->
mp_ki
+
1
>=
NUMKEYS
(
mp
))
{
DP
RINTF
(
"=====> move to next sibling page"
);
DP
UTS
(
"=====> move to next sibling page"
);
if
(
mdb_sibling
(
cursor
,
1
)
!=
MDB_SUCCESS
)
{
cursor
->
mc_eof
=
1
;
return
MDB_NOTFOUND
;
...
...
@@ -1932,7 +1935,7 @@ mdb_cursor_prev(MDB_cursor *cursor, MDB_val *key, MDB_val *data, MDB_cursor_op o
DPRINTF
(
"cursor_prev: top page is %lu in cursor %p"
,
mp
->
mp_pgno
,
(
void
*
)
cursor
);
if
(
top
->
mp_ki
==
0
)
{
DP
RINTF
(
"=====> move to prev sibling page"
);
DP
UTS
(
"=====> move to prev sibling page"
);
if
(
mdb_sibling
(
cursor
,
0
)
!=
MDB_SUCCESS
)
{
return
MDB_NOTFOUND
;
}
...
...
@@ -1996,7 +1999,7 @@ mdb_cursor_set(MDB_cursor *cursor, MDB_val *key, MDB_val *data,
}
if
(
leaf
==
NULL
)
{
DP
RINTF
(
"===> inexact leaf not found, goto sibling"
);
DP
UTS
(
"===> inexact leaf not found, goto sibling"
);
if
((
rc
=
mdb_sibling
(
cursor
,
1
))
!=
MDB_SUCCESS
)
return
rc
;
/* no entries matched */
top
=
CURSOR_TOP
(
cursor
);
...
...
@@ -2701,19 +2704,19 @@ mdb_rebalance(MDB_txn *txn, MDB_dbi dbi, MDB_pageparent *mpp)
if
(
mpp
->
mp_parent
==
NULL
)
{
if
(
NUMKEYS
(
mpp
->
mp_page
)
==
0
)
{
DP
RINTF
(
"tree is completely empty"
);
DP
UTS
(
"tree is completely empty"
);
txn
->
mt_dbs
[
dbi
].
md_root
=
P_INVALID
;
txn
->
mt_dbs
[
dbi
].
md_depth
--
;
txn
->
mt_dbs
[
dbi
].
md_leaf_pages
--
;
}
else
if
(
IS_BRANCH
(
mpp
->
mp_page
)
&&
NUMKEYS
(
mpp
->
mp_page
)
==
1
)
{
DP
RINTF
(
"collapsing root page!"
);
DP
UTS
(
"collapsing root page!"
);
txn
->
mt_dbs
[
dbi
].
md_root
=
NODEPGNO
(
NODEPTR
(
mpp
->
mp_page
,
0
));
if
((
root
=
mdb_get_page
(
txn
,
txn
->
mt_dbs
[
dbi
].
md_root
))
==
NULL
)
return
MDB_PAGE_NOTFOUND
;
txn
->
mt_dbs
[
dbi
].
md_depth
--
;
txn
->
mt_dbs
[
dbi
].
md_branch_pages
--
;
}
else
DP
RINTF
(
"root page doesn't need rebalancing"
);
DP
UTS
(
"root page doesn't need rebalancing"
);
return
MDB_SUCCESS
;
}
...
...
@@ -2732,7 +2735,7 @@ mdb_rebalance(MDB_txn *txn, MDB_dbi dbi, MDB_pageparent *mpp)
if
(
mpp
->
mp_pi
==
0
)
{
/* We're the leftmost leaf in our parent.
*/
DP
RINTF
(
"reading right neighbor"
);
DP
UTS
(
"reading right neighbor"
);
node
=
NODEPTR
(
mpp
->
mp_parent
,
mpp
->
mp_pi
+
1
);
if
((
npp
.
mp_page
=
mdb_get_page
(
txn
,
NODEPGNO
(
node
)))
==
NULL
)
return
MDB_PAGE_NOTFOUND
;
...
...
@@ -2742,7 +2745,7 @@ mdb_rebalance(MDB_txn *txn, MDB_dbi dbi, MDB_pageparent *mpp)
}
else
{
/* There is at least one neighbor to the left.
*/
DP
RINTF
(
"reading left neighbor"
);
DP
UTS
(
"reading left neighbor"
);
node
=
NODEPTR
(
mpp
->
mp_parent
,
mpp
->
mp_pi
-
1
);
if
((
npp
.
mp_page
=
mdb_get_page
(
txn
,
NODEPGNO
(
node
)))
==
NULL
)
return
MDB_PAGE_NOTFOUND
;
...
...
@@ -3109,7 +3112,7 @@ mdb_put0(MDB_txn *txn, MDB_dbi dbi,
}
else
if
(
rc
==
MDB_NOTFOUND
)
{
MDB_dpage
*
dp
;
/* new file, just write a root leaf page */
DP
RINTF
(
"allocating new root leaf page"
);
DP
UTS
(
"allocating new root leaf page"
);
if
((
dp
=
mdb_new_page
(
txn
,
dbi
,
P_LEAF
,
1
))
==
NULL
)
{
return
ENOMEM
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment