initialize all DBT structs with 0

This commit is contained in:
eknauel 2004-09-20 14:39:57 +00:00
parent 68a340c591
commit fb5c2a89bc
1 changed files with 14 additions and 11 deletions

21
c/bdb.c
View File

@ -407,12 +407,8 @@ s48_value scsh_enter_DBT_as_bytevector(DBT* dt)
void scsh_extract_bytevector_as_DBT(s48_value bytevector, DBT* dt) void scsh_extract_bytevector_as_DBT(s48_value bytevector, DBT* dt)
{ {
S48_DECLARE_GC_PROTECT(1);
S48_GC_PROTECT_1(bytevector);
dt->data = s48_extract_byte_vector(bytevector); dt->data = s48_extract_byte_vector(bytevector);
dt->size = S48_BYTE_VECTOR_LENGTH(bytevector); dt->size = S48_BYTE_VECTOR_LENGTH(bytevector);
S48_GC_UNPROTECT();
} }
/* DBT operations */ /* DBT operations */
@ -421,7 +417,7 @@ void scsh_extract_bytevector_as_DBT(s48_value bytevector, DBT* dt)
s48_value scsh_bdb_put(s48_value db, s48_value skey, s48_value sdata, s48_value scsh_bdb_put(s48_value db, s48_value skey, s48_value sdata,
s48_value stxnid, s48_value sflags) s48_value stxnid, s48_value sflags)
{ {
int res; int res = 0;
DB *dbp; DB *dbp;
DB_TXN *txnid; DB_TXN *txnid;
DBT key, data; DBT key, data;
@ -434,11 +430,13 @@ s48_value scsh_bdb_put(s48_value db, s48_value skey, s48_value sdata,
txnid = EXTRACT_OPTIONAL_TXNID(stxnid); txnid = EXTRACT_OPTIONAL_TXNID(stxnid);
flags = s48_extract_integer(sflags); flags = s48_extract_integer(sflags);
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));
scsh_extract_bytevector_as_DBT(skey, &key); scsh_extract_bytevector_as_DBT(skey, &key);
scsh_extract_bytevector_as_DBT(sdata, &data); scsh_extract_bytevector_as_DBT(sdata, &data);
S48_GC_UNPROTECT();
res = dbp->put(dbp, txnid, &key, &data, flags); res = dbp->put(dbp, txnid, &key, &data, flags);
S48_GC_UNPROTECT();
CHECK_BDB_RESULT_CODE(res); CHECK_BDB_RESULT_CODE(res);
return S48_TRUE; return S48_TRUE;
} }
@ -454,14 +452,17 @@ s48_value scsh_bdb_get(s48_value handle, s48_value skey,
DBT key, data; DBT key, data;
S48_DECLARE_GC_PROTECT(4); S48_DECLARE_GC_PROTECT(4);
S48_GC_PROTECT_4(handle, skey, stxnid, sflags); S48_GC_PROTECT_4(handle, skey, stxnid, sflags);
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));
dbp = scsh_extract_db(handle); dbp = scsh_extract_db(handle);
flags = s48_extract_integer(sflags); flags = s48_extract_integer(sflags);
txnid = EXTRACT_OPTIONAL_TXNID(stxnid); txnid = EXTRACT_OPTIONAL_TXNID(stxnid);
scsh_extract_bytevector_as_DBT(skey, &key); scsh_extract_bytevector_as_DBT(skey, &key);
S48_GC_UNPROTECT(); S48_GC_UNPROTECT();
res = dbp->get(dbp, txnid, &key, &data, flags); res = dbp->get(dbp, txnid, &key, &data, flags);
switch (res) { switch (res) {
@ -491,6 +492,7 @@ s48_value scsh_bdb_del(s48_value handle, s48_value skey,
dbp = scsh_extract_db(handle); dbp = scsh_extract_db(handle);
flags = s48_extract_integer(sflags); flags = s48_extract_integer(sflags);
txnid = EXTRACT_OPTIONAL_TXNID(stxnid); txnid = EXTRACT_OPTIONAL_TXNID(stxnid);
memset(&key, 0, sizeof(DBT));
scsh_extract_bytevector_as_DBT(skey, &key); scsh_extract_bytevector_as_DBT(skey, &key);
S48_GC_UNPROTECT(); S48_GC_UNPROTECT();
@ -544,10 +546,11 @@ s48_value scsh_bdb_cursor_cget(s48_value dbc, s48_value sflags)
DBC* dbcp; DBC* dbcp;
u_int32_t flags; u_int32_t flags;
DBT *key, *data; DBT *key, *data;
S48_DECLARE_GC_PROTECT(2); S48_DECLARE_GC_PROTECT(2);
S48_GC_PROTECT_2(dbc, sflags);
S48_GC_PROTECT_2(dbc, sflags);
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));
dbcp = scsh_extract_cursor(dbc); dbcp = scsh_extract_cursor(dbc);
flags = s48_extract_integer(sflags); flags = s48_extract_integer(sflags);
S48_GC_UNPROTECT(); S48_GC_UNPROTECT();