summaryrefslogtreecommitdiffstats
path: root/mandocdb.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-11-20 12:39:08 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-11-20 12:39:08 +0000
commit128b2e9569342adb6a230c39530c1386a24d423c (patch)
tree24c34899384d4b78e02777db602df64613de0bf0 /mandocdb.c
parente6a940ec63910db636acab48c5362bfbc6d35975 (diff)
downloadmandoc-128b2e9569342adb6a230c39530c1386a24d423c.tar.gz
Merge schwarze@'s work for 64-bit types. This is based on a tweaked patch
submitted to tech@ on 16/11/2011, 01:39. It has been updated to account for the logical-operator functions and to avoid keeping a live pointer into the DBT value, which is not guaranteed to be consistent across calls into the bdb library.
Diffstat (limited to 'mandocdb.c')
-rw-r--r--mandocdb.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/mandocdb.c b/mandocdb.c
index d1eb31c9..883bffbf 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -83,7 +83,7 @@ static void buf_append(struct buf *, const char *);
static void buf_appendb(struct buf *,
const void *, size_t);
static void dbt_put(DB *, const char *, DBT *, DBT *);
-static void hash_put(DB *, const struct buf *, int);
+static void hash_put(DB *, const struct buf *, uint64_t);
static void hash_reset(DB **);
static void index_merge(const struct of *, struct mparse *,
struct buf *, struct buf *,
@@ -450,7 +450,7 @@ index_merge(const struct of *of, struct mparse *mp,
const char *fn, *msec, *mtitle, *arch;
size_t sv;
unsigned seq;
- char vbuf[8];
+ struct db_val vbuf;
for (rec = 0; of; of = of->next) {
fn = of->fname;
@@ -513,17 +513,15 @@ index_merge(const struct of *of, struct mparse *mp,
* Copy from the in-memory hashtable of pending keywords
* into the database.
*/
-
- memset(vbuf, 0, sizeof(uint32_t));
- memcpy(vbuf + 4, &rec, sizeof(uint32_t));
+ vbuf.rec = rec;
seq = R_FIRST;
while (0 == (ch = (*hash->seq)(hash, &key, &val, seq))) {
seq = R_NEXT;
- memcpy(vbuf, val.data, sizeof(uint32_t));
- val.size = sizeof(vbuf);
- val.data = vbuf;
+ vbuf.mask = *(uint64_t *)val.data;
+ val.size = sizeof(struct db_val);
+ val.data = &vbuf;
if (verb > 1)
printf("%s: Added keyword: %s\n",
@@ -568,6 +566,7 @@ index_prune(const struct of *ofile, DB *db, const char *dbf,
{
const struct of *of;
const char *fn;
+ struct db_val *vbuf;
unsigned seq, sseq;
DBT key, val;
size_t reccur;
@@ -600,8 +599,9 @@ index_prune(const struct of *ofile, DB *db, const char *dbf,
sseq = R_FIRST;
while (0 == (ch = (*db->seq)(db, &key, &val, sseq))) {
sseq = R_NEXT;
- assert(8 == val.size);
- if (*maxrec != *(recno_t *)(val.data + 4))
+ assert(sizeof(struct db_val) == val.size);
+ vbuf = val.data;
+ if (*maxrec != vbuf->rec)
continue;
if (verb)
printf("%s: Deleted keyword: %s\n",
@@ -982,7 +982,7 @@ pmdoc_Nm(MDOC_ARGS)
}
static void
-hash_put(DB *db, const struct buf *buf, int mask)
+hash_put(DB *db, const struct buf *buf, uint64_t mask)
{
DBT key, val;
int rc;
@@ -997,10 +997,10 @@ hash_put(DB *db, const struct buf *buf, int mask)
perror("hash");
exit((int)MANDOCLEVEL_SYSERR);
} else if (0 == rc)
- mask |= *(int *)val.data;
+ mask |= *(uint64_t *)val.data;
val.data = &mask;
- val.size = sizeof(int);
+ val.size = sizeof(uint64_t);
if ((rc = (*db->put)(db, &key, &val, 0)) < 0) {
perror("hash");