tt/mini_isam: add new isam_prototypes.h include file and fix up problems
There were a variety of potential 64b problems due to the complete lack of prototype declarations. So, we add a file, isam_prototypes.h, generated mostly by the 'cproto' tool. We also fixed up some errors that having proper prototypes pointed out, mainly in passing ints where pointers were expected and vice versa. The iserase() function was supposed to accept a char *, but was defined as only accepting a char. Fun stuff like that.
This commit is contained in:
@@ -35,16 +35,15 @@
|
||||
*
|
||||
* Description:
|
||||
* B-tree operations: SEARCH
|
||||
*
|
||||
*
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "isam_impl.h"
|
||||
|
||||
extern int _iskeycmp();
|
||||
|
||||
/*
|
||||
* _isbtree_create()
|
||||
/*
|
||||
* _isbtree_create()
|
||||
*
|
||||
* Create a B-tree path object that will used in subsequent operations.
|
||||
*/
|
||||
@@ -53,28 +52,28 @@ Btree *
|
||||
_isbtree_create(Fcb *fcb, Keydesc2 *pkeydesc2)
|
||||
{
|
||||
Btree *p;
|
||||
|
||||
|
||||
p = (Btree *) _ismalloc(sizeof(*p));
|
||||
memset((char *)p, 0, sizeof(*p));
|
||||
|
||||
|
||||
p->fcb = fcb;
|
||||
p->keydesc2 = pkeydesc2;
|
||||
|
||||
p->keydesc2 = pkeydesc2;
|
||||
|
||||
return (p);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* _isbtr_destroy()
|
||||
/*
|
||||
* _isbtr_destroy()
|
||||
*
|
||||
* Destroy B-tree path object
|
||||
* Destroy B-tree path object
|
||||
*/
|
||||
|
||||
void
|
||||
_isbtree_destroy(Btree *btree)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
||||
for (i = 0; i < btree->depth;i++) {
|
||||
_isdisk_unfix(btree->bufhdr[i]);
|
||||
}
|
||||
@@ -82,8 +81,8 @@ _isbtree_destroy(Btree *btree)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* _isbtree_search()
|
||||
/*
|
||||
* _isbtree_search()
|
||||
*
|
||||
* Descend the B-tree, position pointer on or before the matched key.
|
||||
*/
|
||||
@@ -102,61 +101,61 @@ _isbtree_search( Btree *btree, char *key)
|
||||
char *key2; /* Equal or next lower key */
|
||||
int curpos; /* index of key2 in key page */
|
||||
Blkno blkno;
|
||||
|
||||
|
||||
/* Set comparison function. */
|
||||
_iskeycmp_set(pkeydesc2, pkeydesc2->k2_nparts + 1); /* +1 for recno field */
|
||||
|
||||
|
||||
index = 0;
|
||||
blkno = rootblkno;
|
||||
do {
|
||||
btree->bufhdr[index] =
|
||||
btree->bufhdr[index] =
|
||||
_isdisk_fix(btree->fcb, btree->fcb->indfd, blkno, ISFIXREAD);
|
||||
p = btree->bufhdr[index]->isb_buffer; /* pointer to buffer */
|
||||
|
||||
|
||||
/* Load some fields from the key page. */
|
||||
nkeys = ldshort(p+BT_NKEYS_OFF); /* Number of keys in the page */
|
||||
elevation = ldshort(p+BT_LEVEL_OFF); /* Level of the page */
|
||||
|
||||
|
||||
/* Binary search in the key page to find equal or next lowere key. */
|
||||
key2 = _isbsearch(key, p+BT_KEYS_OFF, nkeys, keylength, _iskeycmp);
|
||||
|
||||
|
||||
curpos = (key2) ? ((key2 - p - BT_NKEYS_OFF) / keylength) : 0;
|
||||
|
||||
btree->curpos[index] =
|
||||
|
||||
btree->curpos[index] =
|
||||
(key2 == (char *)0 && elevation==0)? -1 : curpos;
|
||||
|
||||
if (elevation > 0)
|
||||
|
||||
if (elevation > 0)
|
||||
blkno = ldblkno(p + ISPAGESIZE - (curpos + 1) * BLKNOSIZE);
|
||||
|
||||
|
||||
index++;
|
||||
} while (elevation > 0);
|
||||
|
||||
|
||||
btree->depth = index;
|
||||
}
|
||||
|
||||
/*
|
||||
* _isbtree_current()
|
||||
/*
|
||||
* _isbtree_current()
|
||||
*
|
||||
* Get pointer to the current key
|
||||
* Get pointer to the current key
|
||||
*/
|
||||
|
||||
char *
|
||||
_isbtree_current(Btree *btree)
|
||||
{
|
||||
int curpos;
|
||||
|
||||
|
||||
assert(btree->depth > 0);
|
||||
if ((curpos = btree->curpos[btree->depth - 1]) == -1)
|
||||
return (NULL);
|
||||
else
|
||||
return (btree->bufhdr[btree->depth - 1]->isb_buffer
|
||||
return (btree->bufhdr[btree->depth - 1]->isb_buffer
|
||||
+ BT_KEYS_OFF + curpos * btree->keydesc2->k2_len);
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* _isbtree_next()
|
||||
*
|
||||
* Get pointer to the next key
|
||||
* Get pointer to the next key
|
||||
*/
|
||||
|
||||
char *
|
||||
@@ -167,41 +166,40 @@ _isbtree_next(Btree *btree)
|
||||
char *p;
|
||||
int level;
|
||||
Blkno blkno;
|
||||
|
||||
|
||||
assert(depth > 0);
|
||||
|
||||
/*
|
||||
|
||||
/*
|
||||
* Move up along the path, find first block where we can move to the right.
|
||||
*/
|
||||
for (level = depth - 1; level >= 0; level--) {
|
||||
p = btree->bufhdr[level]->isb_buffer;
|
||||
|
||||
|
||||
if (btree->curpos[level] < ldshort(p + BT_NKEYS_OFF) - 1)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (level < 0) {
|
||||
/* Logical end of the index file. No next record. */
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
||||
curpos = ++(btree->curpos[level]);
|
||||
|
||||
|
||||
while (++level < depth) {
|
||||
|
||||
|
||||
/* Get block number to block in next lower level. */
|
||||
if (level > 0)
|
||||
blkno = ldblkno(p + ISPAGESIZE - (curpos + 1) * BLKNOSIZE);
|
||||
|
||||
|
||||
/* Unfix page in this level, fetch its right brother. */
|
||||
_isdisk_unfix(btree->bufhdr[level]);
|
||||
btree->bufhdr[level] =
|
||||
btree->bufhdr[level] =
|
||||
_isdisk_fix(btree->fcb, btree->fcb->indfd, blkno, ISFIXREAD);
|
||||
p = btree->bufhdr[level]->isb_buffer;
|
||||
|
||||
|
||||
curpos = btree->curpos[level] = 0;
|
||||
}
|
||||
|
||||
|
||||
return (p + BT_KEYS_OFF + curpos * btree->keydesc2->k2_len);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user