Fix get_multi with an 0-sequence.
Used to give weird errors like NULL return w/o exception etc. Fixes #7.
This commit is contained in:
parent
8a1e5c752d
commit
c3215866c5
@ -643,10 +643,13 @@ static PyObject *PylibMC_Client_get_multi(PylibMC_Client *self, PyObject *args,
|
|||||||
}
|
}
|
||||||
Py_XDECREF(key_it);
|
Py_XDECREF(key_it);
|
||||||
|
|
||||||
if (i == 0) {
|
if (nkeys != 0 && i != nkeys) {
|
||||||
/* No usable keys to fetch. */
|
/* There were keys given, but some keys didn't pass validation. */
|
||||||
nkeys = 0;
|
nkeys = 0;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
} else if (nkeys == 0) {
|
||||||
|
retval = PyDict_New();
|
||||||
|
goto earlybird;
|
||||||
} else if (PyErr_Occurred()) {
|
} else if (PyErr_Occurred()) {
|
||||||
nkeys--;
|
nkeys--;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -700,6 +703,7 @@ static PyObject *PylibMC_Client_get_multi(PylibMC_Client *self, PyObject *args,
|
|||||||
free(curr_val);
|
free(curr_val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
earlybird:
|
||||||
PyMem_Free(key_lens);
|
PyMem_Free(key_lens);
|
||||||
PyMem_Free(keys);
|
PyMem_Free(keys);
|
||||||
for (i = 0; i < nkeys; i++) {
|
for (i = 0; i < nkeys; i++) {
|
||||||
@ -710,6 +714,7 @@ static PyObject *PylibMC_Client_get_multi(PylibMC_Client *self, PyObject *args,
|
|||||||
/* Not INCREFing because the only two outcomes are NULL and a new dict.
|
/* Not INCREFing because the only two outcomes are NULL and a new dict.
|
||||||
* We're the owner of that dict already, so. */
|
* We're the owner of that dict already, so. */
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
Py_XDECREF(retval);
|
Py_XDECREF(retval);
|
||||||
PyMem_Free(key_lens);
|
PyMem_Free(key_lens);
|
||||||
|
4
tests.py
4
tests.py
@ -98,6 +98,10 @@ Traceback (most recent call last):
|
|||||||
...
|
...
|
||||||
TypeError: key must be an instance of str
|
TypeError: key must be an instance of str
|
||||||
|
|
||||||
|
This didn't use to work, but now it does.
|
||||||
|
>>> c.get_multi([])
|
||||||
|
{}
|
||||||
|
|
||||||
Getting stats is fun!
|
Getting stats is fun!
|
||||||
>>> for (svr, stats) in c.get_stats():
|
>>> for (svr, stats) in c.get_stats():
|
||||||
... print svr
|
... print svr
|
||||||
|
Reference in New Issue
Block a user