summaryrefslogtreecommitdiff
path: root/lib/tdb2
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2011-09-14 07:45:13 +0930
committerRusty Russell <rusty@rustcorp.com.au>2011-09-14 07:45:13 +0930
commit77d7ff6c34f16dec70da3f3abc1c19d217e944a9 (patch)
treef4d1d7c3e4e489dda24ae21950aa32b4ba6c0f9e /lib/tdb2
parent75d69ce4f7135fa82d1743fdb61e37ee0bbc1508 (diff)
downloadsamba-77d7ff6c34f16dec70da3f3abc1c19d217e944a9.tar.gz
samba-77d7ff6c34f16dec70da3f3abc1c19d217e944a9.tar.bz2
samba-77d7ff6c34f16dec70da3f3abc1c19d217e944a9.zip
tdb2: make jenkins_hash function non-static, rename to tdb_jenkins_hash.
We're going to need access to it from tdb1_open, so expose it now. It's better in hash.c anyway. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (Imported from CCAN commit c8f6f8c2dea76042f74c02eff048847e62adcca6)
Diffstat (limited to 'lib/tdb2')
-rw-r--r--lib/tdb2/hash.c12
-rw-r--r--lib/tdb2/open.c13
-rw-r--r--lib/tdb2/private.h3
-rw-r--r--lib/tdb2/test/failtest_helper.h6
-rw-r--r--lib/tdb2/test/run-90-get-set-attributes.c2
5 files changed, 20 insertions, 16 deletions
diff --git a/lib/tdb2/hash.c b/lib/tdb2/hash.c
index 1359cfecd6..56c5086e74 100644
--- a/lib/tdb2/hash.c
+++ b/lib/tdb2/hash.c
@@ -16,8 +16,20 @@
License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include "private.h"
+#include <ccan/hash/hash.h>
#include <assert.h>
+/* Default hash function. */
+uint64_t tdb_jenkins_hash(const void *key, size_t length, uint64_t seed,
+ void *unused)
+{
+ uint64_t ret;
+ /* hash64_stable assumes lower bits are more important; they are a
+ * slightly better hash. We use the upper bits first, so swap them. */
+ ret = hash64_stable((const unsigned char *)key, length, seed);
+ return (ret >> 32) | (ret << 32);
+}
+
uint64_t tdb_hash(struct tdb_context *tdb, const void *ptr, size_t len)
{
return tdb->hash_fn(ptr, len, tdb->hash_seed, tdb->hash_data);
diff --git a/lib/tdb2/open.c b/lib/tdb2/open.c
index 94f09e7a2f..a9df85758d 100644
--- a/lib/tdb2/open.c
+++ b/lib/tdb2/open.c
@@ -16,7 +16,6 @@
License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include "private.h"
-#include <ccan/hash/hash.h>
#include <assert.h>
/* all tdbs, to detect double-opens (fcntl file don't nest!) */
@@ -242,16 +241,6 @@ enum TDB_ERROR tdb_set_attribute(struct tdb_context *tdb,
return TDB_SUCCESS;
}
-static uint64_t jenkins_hash(const void *key, size_t length, uint64_t seed,
- void *unused)
-{
- uint64_t ret;
- /* hash64_stable assumes lower bits are more important; they are a
- * slightly better hash. We use the upper bits first, so swap them. */
- ret = hash64_stable((const unsigned char *)key, length, seed);
- return (ret >> 32) | (ret << 32);
-}
-
enum TDB_ERROR tdb_get_attribute(struct tdb_context *tdb,
union tdb_attribute *attr)
{
@@ -371,7 +360,7 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
tdb->openhook = NULL;
tdb->lock_fn = tdb_fcntl_lock;
tdb->unlock_fn = tdb_fcntl_unlock;
- tdb->hash_fn = jenkins_hash;
+ tdb->hash_fn = tdb_jenkins_hash;
memset(&tdb->stats, 0, sizeof(tdb->stats));
tdb->stats.base.attr = TDB_ATTRIBUTE_STATS;
tdb->stats.size = sizeof(tdb->stats);
diff --git a/lib/tdb2/private.h b/lib/tdb2/private.h
index 4f09c58848..33d756f291 100644
--- a/lib/tdb2/private.h
+++ b/lib/tdb2/private.h
@@ -350,6 +350,9 @@ struct tdb_methods {
internal prototypes
*/
/* hash.c: */
+uint64_t tdb_jenkins_hash(const void *key, size_t length, uint64_t seed,
+ void *unused);
+
tdb_bool_err first_in_hash(struct tdb_context *tdb,
struct traverse_info *tinfo,
TDB_DATA *kbuf, size_t *dlen);
diff --git a/lib/tdb2/test/failtest_helper.h b/lib/tdb2/test/failtest_helper.h
index 73cd1aeb1e..a585dc2b65 100644
--- a/lib/tdb2/test/failtest_helper.h
+++ b/lib/tdb2/test/failtest_helper.h
@@ -4,9 +4,9 @@
#include <stdbool.h>
/* FIXME: Check these! */
-#define INITIAL_TDB_MALLOC "open.c", 354, FAILTEST_MALLOC
-#define URANDOM_OPEN "open.c", 62, FAILTEST_OPEN
-#define URANDOM_READ "open.c", 42, FAILTEST_READ
+#define INITIAL_TDB_MALLOC "open.c", 343, FAILTEST_MALLOC
+#define URANDOM_OPEN "open.c", 61, FAILTEST_OPEN
+#define URANDOM_READ "open.c", 41, FAILTEST_READ
bool exit_check_log(struct failtest_call *history, unsigned num);
bool failmatch(const struct failtest_call *call,
diff --git a/lib/tdb2/test/run-90-get-set-attributes.c b/lib/tdb2/test/run-90-get-set-attributes.c
index 6cb889f4d1..e2cde96a96 100644
--- a/lib/tdb2/test/run-90-get-set-attributes.c
+++ b/lib/tdb2/test/run-90-get-set-attributes.c
@@ -61,7 +61,7 @@ int main(int argc, char *argv[])
attr.base.attr = TDB_ATTRIBUTE_HASH;
ok1(tdb_get_attribute(tdb, &attr) == 0);
ok1(attr.base.attr == TDB_ATTRIBUTE_HASH);
- ok1(attr.hash.fn == jenkins_hash);
+ ok1(attr.hash.fn == tdb_jenkins_hash);
attr.base.attr = TDB_ATTRIBUTE_FLOCK;
ok1(tdb_get_attribute(tdb, &attr) == 0);
ok1(attr.base.attr == TDB_ATTRIBUTE_FLOCK);