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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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; |