Unix Technical Forum

Re: Two patches for lib/libc/db/hash/hash.c

This is a discussion on Re: Two patches for lib/libc/db/hash/hash.c within the mailing.openbsd.tech forums, part of the OpenBSD category; --> On Sun, Apr 06, 2008 at 09:39:20AM -0400, Todd C. Miller wrote: > In message <20080406082118.GA19070@roppongi.boxsoft.com> > so spake ...


Go Back   Unix Technical Forum > Unix Operating Systems > OpenBSD > mailing.openbsd.tech

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-07-2008, 08:36 AM
patrick keshishian
 
Posts: n/a
Default Re: Two patches for lib/libc/db/hash/hash.c

On Sun, Apr 06, 2008 at 09:39:20AM -0400, Todd C. Miller wrote:
> In message <20080406082118.GA19070@roppongi.boxsoft.com>
> so spake patrick keshishian (sidster):
>
> > Also, hashp->cndx is decremented (adjusted) during deletion of
> > the key/data pair if hashp->cndx is pointing to the entry being
> > deleted. The side-effect of not doing this is entries are
> > skipped due to the way __delpair "shuffles" keys.

>
> Looks reasonable, though I wonder if it would not be better to do
> the cndx fixup inside __delpair() for the shuffle case.


Does this look OK?


(Again hash.c diff is based on first patch in my original email)

--- /usr/src/lib/libc/db/hash/hash.c Tue Aug 1 03:11:31 2006
+++ hash/hash.c Sun Apr 6 18:18:38 2008
@@ -705,7 +708,7 @@ hash_seq(const DB *dbp, DBT *key, DBT *data, u_int32_t
hashp->cndx = 1;
hashp->cpage = NULL;
}
-
+ next_bucket:
for (bp = NULL; !bp || !bp[0]; ) {
if (!(bufp = hashp->cpage)) {
for (bucket = hashp->cbucket;
@@ -724,8 +727,18 @@ hash_seq(const DB *dbp, DBT *key, DBT *data, u_int32_t
hashp->cbucket = -1;
return (ABNORMAL);
}
- } else
+ } else {
bp = (u_int16_t *)hashp->cpage->page;
+ if (flag == R_NEXT) {
+ hashp->cndx += 2;
+ if (hashp->cndx > bp[0]) {
+ hashp->cpage = NULL;
+ hashp->cbucket++;
+ hashp->cndx = 1;
+ goto next_bucket;
+ }
+ }
+ }

#ifdef DEBUG
assert(bp);
@@ -755,13 +768,6 @@ hash_seq(const DB *dbp, DBT *key, DBT *data, u_int32_t
key->size = (ndx > 1 ? bp[ndx - 1] : hashp->BSIZE) - bp[ndx];
data->data = (u_char *)hashp->cpage->page + bp[ndx + 1];
data->size = bp[ndx] - bp[ndx + 1];
- ndx += 2;
- if (ndx > bp[0]) {
- hashp->cpage = NULL;
- hashp->cbucket++;
- hashp->cndx = 1;
- } else
- hashp->cndx = ndx;
}
return (SUCCESS);
}

--- /usr/src/lib/libc/db/hash/hash_page.c Fri Aug 5 06:03:00 2005
+++ hash/hash_page.c Sun Apr 6 18:18:05 2008
@@ -149,6 +149,14 @@ __delpair(HTAB *hashp, BUFHEAD *bufp, int ndx)
bp[i - 1] = bp[i + 1] + pairlen;
}
}
+ if (ndx == hashp->cndx) {
+ /*
+ * We just removed pair we were "pointing" to.
+ * By moving back the cndx we ensure subsequent
+ * hash_seq() calls won't skip over any entries.
+ */
+ hashp->cndx -= 2;
+ }
}
/* Finally adjust the page data */
bp[n] = OFFSET(bp) + pairlen;

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:42 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com