Second pass of syntax nitpicks
This commit is contained in:
parent
2e83a68ed9
commit
66f4bcfc41
@ -1089,11 +1089,12 @@ memcached_return pylibmc_memcached_fetch_multi(memcached_st* mc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static PyObject *PylibMC_Client_get_multi(PylibMC_Client *self, PyObject *args,
|
static PyObject *PylibMC_Client_get_multi(
|
||||||
PyObject *kwds) {
|
PylibMC_Client *self, PyObject *args, PyObject *kwds) {
|
||||||
PyObject *key_seq, **key_objs, *retval = NULL;
|
PyObject *key_seq, **key_objs, *retval = NULL;
|
||||||
char **keys, *prefix = NULL;
|
char **keys, *prefix = NULL;
|
||||||
pylibmc_mget_result* results = NULL;
|
char *err_func = NULL;
|
||||||
|
pylibmc_mget_result *res, *results = NULL;
|
||||||
Py_ssize_t prefix_len = 0;
|
Py_ssize_t prefix_len = 0;
|
||||||
Py_ssize_t i;
|
Py_ssize_t i;
|
||||||
PyObject *key_it, *ckey;
|
PyObject *key_it, *ckey;
|
||||||
@ -1101,19 +1102,14 @@ static PyObject *PylibMC_Client_get_multi(PylibMC_Client *self, PyObject *args,
|
|||||||
size_t nkeys, nresults = 0;
|
size_t nkeys, nresults = 0;
|
||||||
memcached_return rc;
|
memcached_return rc;
|
||||||
|
|
||||||
char** err_func = NULL;
|
|
||||||
|
|
||||||
static char *kws[] = { "keys", "key_prefix", NULL };
|
static char *kws[] = { "keys", "key_prefix", NULL };
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|s#:get_multi", kws,
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|s#:get_multi", kws,
|
||||||
&key_seq, &prefix, &prefix_len)) {
|
&key_seq, &prefix, &prefix_len))
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
if ((nkeys = (size_t)PySequence_Length(key_seq)) == -1) {
|
if ((nkeys = (size_t)PySequence_Length(key_seq)) == -1)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
/* this is over-allocating in the majority of cases */
|
/* this is over-allocating in the majority of cases */
|
||||||
results = PyMem_New(pylibmc_mget_result, nkeys);
|
results = PyMem_New(pylibmc_mget_result, nkeys);
|
||||||
|
|
||||||
@ -1168,7 +1164,7 @@ static PyObject *PylibMC_Client_get_multi(PylibMC_Client *self, PyObject *args,
|
|||||||
goto earlybird;
|
goto earlybird;
|
||||||
} else if (PyErr_Occurred()) {
|
} else if (PyErr_Occurred()) {
|
||||||
nkeys--;
|
nkeys--;
|
||||||
goto cleanup;
|
goto earlybird;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO Make an iterator interface for getting each key separately.
|
/* TODO Make an iterator interface for getting each key separately.
|
||||||
@ -1180,76 +1176,61 @@ static PyObject *PylibMC_Client_get_multi(PylibMC_Client *self, PyObject *args,
|
|||||||
Py_BEGIN_ALLOW_THREADS;
|
Py_BEGIN_ALLOW_THREADS;
|
||||||
rc = pylibmc_memcached_fetch_multi(self->mc,
|
rc = pylibmc_memcached_fetch_multi(self->mc,
|
||||||
keys, nkeys, key_lens,
|
keys, nkeys, key_lens,
|
||||||
results,
|
&results, &nresults,
|
||||||
&nresults,
|
&err_func);
|
||||||
err_func);
|
|
||||||
Py_END_ALLOW_THREADS;
|
Py_END_ALLOW_THREADS;
|
||||||
|
|
||||||
if(rc != MEMCACHED_SUCCESS) {
|
if (rc != MEMCACHED_SUCCESS) {
|
||||||
PylibMC_ErrFromMemcached(self, *err_func, rc);
|
PylibMC_ErrFromMemcached(self, err_func, rc);
|
||||||
goto cleanup;
|
goto earlybird;
|
||||||
}
|
}
|
||||||
|
|
||||||
retval = PyDict_New();
|
retval = PyDict_New();
|
||||||
|
|
||||||
for(i = 0; i<nresults; i++) {
|
for (i = 0; i < nresults; i++) {
|
||||||
PyObject *val;
|
PyObject *val;
|
||||||
|
res = results + i;
|
||||||
|
|
||||||
/* This is safe because libmemcached's max key length
|
/* This is safe because libmemcached's max key length
|
||||||
* includes space for a NUL-byte. */
|
* includes space for a NUL-byte. */
|
||||||
results[i].key[results[i].key_len] = 0;
|
res->key[res->key_len] = '\0';
|
||||||
val = _PylibMC_parse_memcached_value(results[i].value,
|
val = _PylibMC_parse_memcached_value(res->value, res->value_len,
|
||||||
results[i].value_len,
|
res->flags);
|
||||||
results[i].flags);
|
|
||||||
if (val == NULL) {
|
if (val == NULL) {
|
||||||
/* PylibMC_parse_memcached_value raises the exception on its
|
/* PylibMC_parse_memcached_value raises the exception on its own */
|
||||||
own */
|
Py_DECREF(retval);
|
||||||
goto cleanup;
|
break;
|
||||||
}
|
}
|
||||||
PyDict_SetItemString(retval, results[i].key + prefix_len,
|
|
||||||
val);
|
PyDict_SetItemString(retval, res->key + prefix_len, val);
|
||||||
Py_DECREF(val);
|
Py_DECREF(val);
|
||||||
|
|
||||||
if(PyErr_Occurred()) {
|
if (PyErr_Occurred()) {
|
||||||
/* only PyDict_SetItemString can incur this one */
|
/* only PyDict_SetItemString can incur this one */
|
||||||
goto cleanup;
|
Py_DECREF(retval);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
earlybird:
|
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++)
|
||||||
Py_DECREF(key_objs[i]);
|
Py_DECREF(key_objs[i]);
|
||||||
}
|
PyMem_Free(key_objs);
|
||||||
if(results != NULL){
|
|
||||||
for (i = 0; i < nresults; i++) {
|
/* libmemcached mallocs, so we need to free that memory */
|
||||||
/* libmemcached mallocs, so we need to free its memory in
|
if (results != NULL) {
|
||||||
the same way */
|
for (i = 0; i < nresults && results != NULL; i++) {
|
||||||
free(results[i].value);
|
free(results[i].value);
|
||||||
}
|
}
|
||||||
PyMem_Free(results);
|
PyMem_Free(results);
|
||||||
}
|
}
|
||||||
PyMem_Free(key_objs);
|
|
||||||
|
|
||||||
/* 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:
|
|
||||||
Py_XDECREF(retval);
|
|
||||||
PyMem_Free(key_lens);
|
|
||||||
PyMem_Free(keys);
|
|
||||||
for (i = 0; i < nkeys; i++)
|
|
||||||
Py_DECREF(key_objs[i]);
|
|
||||||
if(results != NULL){
|
|
||||||
for (i = 0; i < nresults; i++) {
|
|
||||||
free(results[i].value);
|
|
||||||
}
|
|
||||||
PyMem_Free(results);
|
|
||||||
}
|
|
||||||
PyMem_Free(key_objs);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,7 +76,7 @@ typedef memcached_return (*_PylibMC_IncrCommand)(memcached_st *,
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
char key[MEMCACHED_MAX_KEY];
|
char key[MEMCACHED_MAX_KEY];
|
||||||
size_t key_len;
|
size_t key_len;
|
||||||
char* value;
|
char *value;
|
||||||
size_t value_len;
|
size_t value_len;
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
} pylibmc_mget_result;
|
} pylibmc_mget_result;
|
||||||
|
Reference in New Issue
Block a user