Fix empty memcached value exception bug.
pylibmc would produce non-error exceptions because the memcached value pointer would be NULL, while the return code would be zero.
This commit is contained in:
parent
f5b756deb8
commit
343286a34b
@ -195,9 +195,10 @@ static PyObject *PylibMC_Client_get(PylibMC_Client *self, PyObject *arg) {
|
|||||||
PyObject *r = _PylibMC_parse_memcached_value(mc_val, val_size, flags);
|
PyObject *r = _PylibMC_parse_memcached_value(mc_val, val_size, flags);
|
||||||
free(mc_val);
|
free(mc_val);
|
||||||
return r;
|
return r;
|
||||||
}
|
} else if (error == MEMCACHED_SUCCESS) {
|
||||||
|
/* This happens for empty values, and so we fake an empty string. */
|
||||||
if (error == MEMCACHED_NOTFOUND) {
|
return PyString_FromStringAndSize("", 0);
|
||||||
|
} else if (error == MEMCACHED_NOTFOUND) {
|
||||||
/* Since python-memcache returns None when the key doesn't exist,
|
/* Since python-memcache returns None when the key doesn't exist,
|
||||||
* so shall we. */
|
* so shall we. */
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
|
6
tests.py
6
tests.py
@ -14,6 +14,12 @@ True
|
|||||||
>>> c.get("test_key")
|
>>> c.get("test_key")
|
||||||
>>>
|
>>>
|
||||||
|
|
||||||
|
We should handle empty values just nicely.
|
||||||
|
>>> c.set("foo", "")
|
||||||
|
True
|
||||||
|
>>> c.get("foo")
|
||||||
|
''
|
||||||
|
|
||||||
Now this section is because most other implementations ignore zero-keys.
|
Now this section is because most other implementations ignore zero-keys.
|
||||||
>>> c.get("")
|
>>> c.get("")
|
||||||
>>> c.set("", "hi")
|
>>> c.set("", "hi")
|
||||||
|
Reference in New Issue
Block a user