Commit 4f3f61ed authored by Jason Madden's avatar Jason Madden

Better param and macro names.

parent 247377ed
...@@ -219,8 +219,8 @@ BTree_check(BTree *self) ...@@ -219,8 +219,8 @@ BTree_check(BTree *self)
return result; return result;
} }
#define _GET_KEY_ERROR 1 #define _BGET_REPLACE_TYPE_ERROR 1
#define _GET_ALL_ERROR 0 #define _BGET_ALLOW_TYPE_ERROR 0
/* /*
** _BTree_get ** _BTree_get
** **
...@@ -231,9 +231,14 @@ BTree_check(BTree *self) ...@@ -231,9 +231,14 @@ BTree_check(BTree *self)
** keyarg the key to search for, as a Python object ** keyarg the key to search for, as a Python object
** has_key true/false; when false, try to return the associated ** has_key true/false; when false, try to return the associated
** value; when true, return a boolean ** value; when true, return a boolean
** ignore_key_err true/false: When true, ignore the TypeError from ** replace_type_err true/false: When true, ignore the TypeError from
** a key conversion issue, and return NULL with ** a key conversion issue, instead
** a KeyError set. ** 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 ** Return
** When has_key false: ** When has_key false:
** If key exists, its associated value. ** If key exists, its associated value.
...@@ -244,7 +249,7 @@ BTree_check(BTree *self) ...@@ -244,7 +249,7 @@ BTree_check(BTree *self)
** If key doesn't exist, 0. ** If key doesn't exist, 0.
*/ */
static PyObject * 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; KEY_TYPE key;
PyObject *result = NULL; /* guilty until proved innocent */ PyObject *result = NULL; /* guilty until proved innocent */
...@@ -253,7 +258,7 @@ _BTree_get(BTree *self, PyObject *keyarg, int has_key, int ignore_key_err) ...@@ -253,7 +258,7 @@ _BTree_get(BTree *self, PyObject *keyarg, int has_key, int ignore_key_err)
COPY_KEY_FROM_ARG(key, keyarg, copied); COPY_KEY_FROM_ARG(key, keyarg, copied);
UNLESS (copied) UNLESS (copied)
{ {
if (ignore_key_err && PyErr_ExceptionMatches(PyExc_TypeError)) if (replace_type_err && PyErr_ExceptionMatches(PyExc_TypeError))
{ {
PyErr_Clear(); PyErr_Clear();
PyErr_SetObject(PyExc_KeyError, keyarg); PyErr_SetObject(PyExc_KeyError, keyarg);
...@@ -302,7 +307,7 @@ Done: ...@@ -302,7 +307,7 @@ Done:
static PyObject * static PyObject *
BTree_get(BTree *self, PyObject *key) 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 /* Create a new bucket for the BTree or TreeSet using the class attribute
...@@ -1953,7 +1958,7 @@ BTree_getm(BTree *self, PyObject *args) ...@@ -1953,7 +1958,7 @@ BTree_getm(BTree *self, PyObject *args)
UNLESS (PyArg_ParseTuple(args, "O|O", &key, &d)) UNLESS (PyArg_ParseTuple(args, "O|O", &key, &d))
return NULL; 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; return r;
UNLESS (PyErr_ExceptionMatches(PyExc_KeyError)) UNLESS (PyErr_ExceptionMatches(PyExc_KeyError))
return NULL; return NULL;
...@@ -1965,7 +1970,7 @@ BTree_getm(BTree *self, PyObject *args) ...@@ -1965,7 +1970,7 @@ BTree_getm(BTree *self, PyObject *args)
static PyObject * static PyObject *
BTree_has_key(BTree *self, PyObject *key) 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 * static PyObject *
...@@ -1978,7 +1983,7 @@ BTree_setdefault(BTree *self, PyObject *args) ...@@ -1978,7 +1983,7 @@ BTree_setdefault(BTree *self, PyObject *args)
if (! PyArg_UnpackTuple(args, "setdefault", 2, 2, &key, &failobj)) if (! PyArg_UnpackTuple(args, "setdefault", 2, 2, &key, &failobj))
return NULL; return NULL;
value = _BTree_get(self, key, 0, _GET_ALL_ERROR); value = _BTree_get(self, key, 0, _BGET_ALLOW_TYPE_ERROR);
if (value != NULL) if (value != NULL)
return value; return value;
...@@ -2011,7 +2016,7 @@ BTree_pop(BTree *self, PyObject *args) ...@@ -2011,7 +2016,7 @@ BTree_pop(BTree *self, PyObject *args)
if (! PyArg_UnpackTuple(args, "pop", 1, 2, &key, &failobj)) if (! PyArg_UnpackTuple(args, "pop", 1, 2, &key, &failobj))
return NULL; return NULL;
value = _BTree_get(self, key, 0, _GET_ALL_ERROR); value = _BTree_get(self, key, 0, _BGET_ALLOW_TYPE_ERROR);
if (value != NULL) if (value != NULL)
{ {
/* Delete key and associated value. */ /* Delete key and associated value. */
...@@ -2056,7 +2061,7 @@ BTree_pop(BTree *self, PyObject *args) ...@@ -2056,7 +2061,7 @@ BTree_pop(BTree *self, PyObject *args)
static int static int
BTree_contains(BTree *self, PyObject *key) 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; int result = -1;
if (asobj != NULL) if (asobj != NULL)
......
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