Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is DB_HASH support broken in BerkeleyDB 4.6.19 ?

1 view
Skip to first unread message

Gregory P. Smith

unread,
Sep 8, 2007, 7:31:02 PM9/8/07
to
On both Linux and Mac OS X 10.4.9 the following simple code to write
values into a DB_HASH database locks up when compiled with BerkeleyDB
4.6.19. It works fine when compiled against 4.5. Why?


#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <db.h>

int main()
{
DB_ENV *db_env = NULL;
DB *db = NULL;
char *db_home;
char tmpstr[128];
char keystr[5];
char datastr[30];
DBT key = { 0 };
DBT data = { 0 };
int err, x;

strncpy(tmpstr, "/tmp/cdbtest.XXXXXX", sizeof(tmpstr)-1);
db_home = mkdtemp(tmpstr);
printf("running in %s.\n", db_home);

err = db_env_create(&db_env, 0);
if (err) { printf("a: %s\n", db_strerror(err)); goto errorexit; }
err = db_env->open(db_env, db_home,
DB_CREATE | DB_THREAD | DB_INIT_CDB | DB_INIT_MPOOL,
0660);
if (err) { printf("b: %s\n", db_strerror(err)); goto errorexit; }
err = db_create(&db, db_env, 0);
if (err) { printf("c: %s\n", db_strerror(err)); goto errorexit; }
err = db->open(db, NULL, "cdbtest", NULL, DB_HASH, DB_CREATE |
DB_THREAD, 0660);
if (err) { printf("d: %s\n", db_strerror(err)); goto errorexit; }
for (x = 0; x < 1000; ++x) {
snprintf(keystr,sizeof(keystr),"%04x",x);
key.data = keystr;
key.size = strlen(keystr);

snprintf(datastr,sizeof(datastr),"%04x-%04x-%04x-%04x-
%04x",x,x,x,x,x);
data.data = datastr;
data.size = strlen(datastr);

err = db->put(db, NULL, &key, &data, 0);
if (err) { printf("e: %s\n", db_strerror(err)); goto
errorexit; }
if (x % 50 == 0)
printf("put with x = %d\n", x);
}
db->close(db, 0);
db_env->remove(db_env, db_home, DB_FORCE);
printf("done.\n");
printf("remember to rm -r %s\n", db_home);

return 0;

errorexit:
if (db)
db->close(db, 0);
if (db_env)
db_env->remove(db_env, db_home, DB_FORCE);
return 1;
}

0 new messages