Commit 149cb3ca authored by Tim Peters's avatar Tim Peters

PreviousBucket(): Beefed up docs; simplified code; squashed cases where

an error return leaked references.
parent 0b3504cd
...@@ -260,40 +260,38 @@ IndexError(int i) ...@@ -260,40 +260,38 @@ IndexError(int i)
return NULL; return NULL;
} }
/* Returns a new reference to the bucket before current, in the bucket
* chain starting at first.
* Returns NULL on error. IndexError(i) may or may not be set then (XXX I
* don't know what the intent is, that's just what it does; should be redone).
*/
static Bucket * static Bucket *
PreviousBucket(Bucket *current, Bucket *first, int i) PreviousBucket(Bucket *current, Bucket *first, int i)
{ {
if (! first) return NULL; if (! first) return NULL;
if (first==current) if (first == current)
{ {
IndexError(i); IndexError(i);
return NULL; return NULL;
} }
Py_INCREF(first);
while (1) while (1)
{ {
PER_USE_OR_RETURN(first,NULL); Bucket *next;
if (first->next==current) PER_USE_OR_RETURN(first, NULL);
next = first->next;
PER_ALLOW_DEACTIVATION(first);
PER_ACCESSED(first);
if (next == current)
{ {
PER_ALLOW_DEACTIVATION(first); Py_INCREF(first);
PER_ACCESSED(first);
return first; return first;
} }
else if (first->next) else if (next)
{ first=next;
Bucket *next = first->next;
Py_INCREF(next);
PER_ALLOW_DEACTIVATION(first);
PER_ACCESSED(first);
Py_DECREF(first);
first=next;
}
else else
{ {
PER_ALLOW_DEACTIVATION(first);
PER_ACCESSED(first);
Py_DECREF(first);
IndexError(i); IndexError(i);
return NULL; return NULL;
} }
...@@ -411,7 +409,7 @@ static char BTree_module_documentation[] = ...@@ -411,7 +409,7 @@ static char BTree_module_documentation[] =
"\n" "\n"
MASTER_ID MASTER_ID
BTREEITEMSTEMPLATE_C BTREEITEMSTEMPLATE_C
"$Id: BTreeModuleTemplate.c,v 1.31 2002/06/10 04:57:43 tim_one Exp $\n" "$Id: BTreeModuleTemplate.c,v 1.32 2002/06/17 19:21:39 tim_one Exp $\n"
BTREETEMPLATE_C BTREETEMPLATE_C
BUCKETTEMPLATE_C BUCKETTEMPLATE_C
KEYMACROS_H KEYMACROS_H
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment