Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
BTrees
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
BTrees
Commits
4f3f61ed
Commit
4f3f61ed
authored
Aug 03, 2016
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better param and macro names.
parent
247377ed
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
13 deletions
+18
-13
BTrees/BTreeTemplate.c
BTrees/BTreeTemplate.c
+18
-13
No files found.
BTrees/BTreeTemplate.c
View file @
4f3f61ed
...
...
@@ -219,8 +219,8 @@ BTree_check(BTree *self)
return
result
;
}
#define _
GET_KEY
_ERROR 1
#define _
GET_ALL
_ERROR 0
#define _
BGET_REPLACE_TYPE
_ERROR 1
#define _
BGET_ALLOW_TYPE
_ERROR 0
/*
** _BTree_get
**
...
...
@@ -231,9 +231,14 @@ BTree_check(BTree *self)
** keyarg the key to search for, as a Python object
** has_key true/false; when false, try to return the associated
** value; when true, return a boolean
** ignore_key_err true/false: When true, ignore the TypeError from
** a key conversion issue, and return NULL with
** a KeyError set.
** replace_type_err true/false: When true, ignore the TypeError from
** a key conversion issue, instead
** transforming it into a KeyError set. If
** you are just reading/searching, set to
** true. If you will be adding/updating,
** however, set to false. Or use
** _BGET_REPLACE_TYPE_ERROR
** and _BGET_ALLOW_TYPE_ERROR, respectively.
** Return
** When has_key false:
** If key exists, its associated value.
...
...
@@ -244,7 +249,7 @@ BTree_check(BTree *self)
** If key doesn't exist, 0.
*/
static
PyObject
*
_BTree_get
(
BTree
*
self
,
PyObject
*
keyarg
,
int
has_key
,
int
ignore_key
_err
)
_BTree_get
(
BTree
*
self
,
PyObject
*
keyarg
,
int
has_key
,
int
replace_type
_err
)
{
KEY_TYPE
key
;
PyObject
*
result
=
NULL
;
/* guilty until proved innocent */
...
...
@@ -253,7 +258,7 @@ _BTree_get(BTree *self, PyObject *keyarg, int has_key, int ignore_key_err)
COPY_KEY_FROM_ARG
(
key
,
keyarg
,
copied
);
UNLESS
(
copied
)
{
if
(
ignore_key
_err
&&
PyErr_ExceptionMatches
(
PyExc_TypeError
))
if
(
replace_type
_err
&&
PyErr_ExceptionMatches
(
PyExc_TypeError
))
{
PyErr_Clear
();
PyErr_SetObject
(
PyExc_KeyError
,
keyarg
);
...
...
@@ -302,7 +307,7 @@ Done:
static
PyObject
*
BTree_get
(
BTree
*
self
,
PyObject
*
key
)
{
return
_BTree_get
(
self
,
key
,
0
,
_
GET_KEY
_ERROR
);
return
_BTree_get
(
self
,
key
,
0
,
_
BGET_REPLACE_TYPE
_ERROR
);
}
/* Create a new bucket for the BTree or TreeSet using the class attribute
...
...
@@ -1953,7 +1958,7 @@ BTree_getm(BTree *self, PyObject *args)
UNLESS
(
PyArg_ParseTuple
(
args
,
"O|O"
,
&
key
,
&
d
))
return
NULL
;
if
((
r
=
_BTree_get
(
self
,
key
,
0
,
_
GET_KEY
_ERROR
)))
if
((
r
=
_BTree_get
(
self
,
key
,
0
,
_
BGET_REPLACE_TYPE
_ERROR
)))
return
r
;
UNLESS
(
PyErr_ExceptionMatches
(
PyExc_KeyError
))
return
NULL
;
...
...
@@ -1965,7 +1970,7 @@ BTree_getm(BTree *self, PyObject *args)
static
PyObject
*
BTree_has_key
(
BTree
*
self
,
PyObject
*
key
)
{
return
_BTree_get
(
self
,
key
,
1
,
_
GET_KEY
_ERROR
);
return
_BTree_get
(
self
,
key
,
1
,
_
BGET_REPLACE_TYPE
_ERROR
);
}
static
PyObject
*
...
...
@@ -1978,7 +1983,7 @@ BTree_setdefault(BTree *self, PyObject *args)
if
(
!
PyArg_UnpackTuple
(
args
,
"setdefault"
,
2
,
2
,
&
key
,
&
failobj
))
return
NULL
;
value
=
_BTree_get
(
self
,
key
,
0
,
_
GET_ALL
_ERROR
);
value
=
_BTree_get
(
self
,
key
,
0
,
_
BGET_ALLOW_TYPE
_ERROR
);
if
(
value
!=
NULL
)
return
value
;
...
...
@@ -2011,7 +2016,7 @@ BTree_pop(BTree *self, PyObject *args)
if
(
!
PyArg_UnpackTuple
(
args
,
"pop"
,
1
,
2
,
&
key
,
&
failobj
))
return
NULL
;
value
=
_BTree_get
(
self
,
key
,
0
,
_
GET_ALL
_ERROR
);
value
=
_BTree_get
(
self
,
key
,
0
,
_
BGET_ALLOW_TYPE
_ERROR
);
if
(
value
!=
NULL
)
{
/* Delete key and associated value. */
...
...
@@ -2056,7 +2061,7 @@ BTree_pop(BTree *self, PyObject *args)
static
int
BTree_contains
(
BTree
*
self
,
PyObject
*
key
)
{
PyObject
*
asobj
=
_BTree_get
(
self
,
key
,
1
,
_
GET_KEY
_ERROR
);
PyObject
*
asobj
=
_BTree_get
(
self
,
key
,
1
,
_
BGET_REPLACE_TYPE
_ERROR
);
int
result
=
-
1
;
if
(
asobj
!=
NULL
)
...
...
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