Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
zodb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Joshua
zodb
Commits
71580095
Commit
71580095
authored
Jun 17, 2002
by
Tim Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
_BTree_clear(): Made the Zope2 and Zope3 versions as similar as possible.
parent
149cb3ca
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
30 deletions
+34
-30
src/BTrees/BTreeTemplate.c
src/BTrees/BTreeTemplate.c
+34
-30
No files found.
src/BTrees/BTreeTemplate.c
View file @
71580095
...
...
@@ -12,7 +12,7 @@
****************************************************************************/
#define BTREETEMPLATE_C "$Id: BTreeTemplate.c,v 1.5
7 2002/06/17 18:49:4
9 tim_one Exp $\n"
#define BTREETEMPLATE_C "$Id: BTreeTemplate.c,v 1.5
8 2002/06/17 20:02:3
9 tim_one Exp $\n"
/*
** _BTree_get
...
...
@@ -578,49 +578,53 @@ BTree_setitem(BTree *self, PyObject *key, PyObject *v)
/*
** _BTree_clear
**
** Clears out all of the values in the BTree
** Clears out all of the values in the BTree (firstbucket, keys, and children);
** leaving self an empty BTree.
**
** Arguments: self The BTree
**
** Returns: 0 on success
** -1 on failure
*/
**
** Internal: Deallocation order is important. The danger is that a long
** list of buckets may get freed "at once" via decref'ing the first bucket,
** in which case a chain of consequenct Py_DECREF calls may blow the stack.
** Luckily, every bucket has a refcount of at least two, one due to being a
** BTree node's child, and another either because it's not the first bucket in
** the chain (so the preceding bucket points to it), or because firstbucket
** points to it. By clearing in the natural depth-first, left-to-right
** order, the BTree->bucket child pointers prevent Py_DECREF(bucket->next)
** calls from freeing bucket->next, and the maximum stack depth is equal
** to the height of the tree.
**/
static
int
_BTree_clear
(
BTree
*
self
)
{
int
i
,
l
;
/* The order in which we dealocate, from "top to bottom" is critical
to prevent memory memory errors when the deallocation stack
becomes huge when dealocating use linked lists of buckets.
*/
const
int
len
=
self
->
len
;
if
(
self
->
firstbucket
)
{
ASSERT
(
self
->
firstbucket
->
ob_refcnt
>
0
,
"Invalid firstbucket pointer"
,
-
1
);
Py_DECREF
(
self
->
firstbucket
);
self
->
firstbucket
=
NULL
;
if
(
self
->
firstbucket
)
{
ASSERT
(
self
->
firstbucket
->
ob_refcnt
>
1
,
"Invalid firstbucket pointer"
,
-
1
);
Py_DECREF
(
self
->
firstbucket
);
self
->
firstbucket
=
NULL
;
}
for
(
l
=
self
->
len
,
i
=
0
;
i
<
l
;
i
++
)
{
if
(
i
)
{
DECREF_KEY
(
self
->
data
[
i
].
key
);
}
Py_DECREF
(
self
->
data
[
i
].
child
);
}
self
->
len
=
0
;
if
(
self
->
data
)
{
int
i
;
if
(
len
>
0
)
{
/* 0 is special because key 0 is trash */
Py_DECREF
(
self
->
data
[
0
].
child
);
}
if
(
self
->
data
)
{
free
(
self
->
data
);
self
->
data
=
0
;
self
->
size
=
0
;
for
(
i
=
1
;
i
<
len
;
i
++
)
{
DECREF_KEY
(
self
->
data
[
i
].
key
);
Py_DECREF
(
self
->
data
[
i
].
child
);
}
free
(
self
->
data
);
self
->
data
=
NULL
;
}
return
0
;
self
->
len
=
self
->
size
=
0
;
return
0
;
}
#ifdef PERSISTENT
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment