Use longer variable names for the iteration over channels, options,
annotation classes and rows, and binary classes when a decoder gets
loaded. This improves readability, especially in nested loops with
complex test conditions and diagnostics messages.
Although the Python variables were checked for their availability and
expected data type, and we should only see non-negative index values,
the iteration variable's data type remains unchanged in this commit
(sticks with signed size types).
PyObject *py_channellist, *py_entry;
struct srd_channel *pdch;
GSList *pdchl;
PyObject *py_channellist, *py_entry;
struct srd_channel *pdch;
GSList *pdchl;
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
- for (i = PyTuple_Size(py_channellist) - 1; i >= 0; i--) {
- py_entry = PyTuple_GetItem(py_channellist, i);
+ ch_idx = PyTuple_Size(py_channellist);
+ while (ch_idx--) {
+ py_entry = PyTuple_GetItem(py_channellist, ch_idx);
if (!py_entry)
goto except_out;
if (!py_entry)
goto except_out;
if (py_dictitem_as_str(py_entry, "desc", &pdch->desc) != SRD_OK)
goto err_out;
if (py_dictitem_as_str(py_entry, "desc", &pdch->desc) != SRD_OK)
goto err_out;
- pdch->order = offset + i;
+ pdch->order = offset + ch_idx;
}
Py_DECREF(py_channellist);
}
Py_DECREF(py_channellist);
GSList *options;
struct srd_decoder_option *o;
GVariant *gvar;
GSList *options;
struct srd_decoder_option *o;
GVariant *gvar;
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
- for (i = PyTuple_Size(py_values) - 1; i >= 0; i--) {
- py_item = PyTuple_GetItem(py_values, i);
+ val_idx = PyTuple_Size(py_values);
+ while (val_idx--) {
+ py_item = PyTuple_GetItem(py_values, val_idx);
if (!py_item)
goto except_out;
if (!py_item)
goto except_out;
PyObject *py_annlist, *py_ann;
GSList *annotations;
char **annpair;
PyObject *py_annlist, *py_ann;
GSList *annotations;
char **annpair;
PyGILState_STATE gstate;
if (ret_count)
PyGILState_STATE gstate;
if (ret_count)
- i = PyTuple_Size(py_annlist);
+ ann_idx = PyTuple_Size(py_annlist);
- *ret_count = i;
- while (i--) {
- py_ann = PyTuple_GetItem(py_annlist, i);
+ *ret_count = ann_idx;
+ while (ann_idx--) {
+ py_ann = PyTuple_GetItem(py_annlist, ann_idx);
if (!py_ann)
goto except_out;
if (!PyTuple_Check(py_ann) || PyTuple_Size(py_ann) != 2) {
srd_err("Protocol decoder %s annotation %zd should be a tuple with two elements.",
if (!py_ann)
goto except_out;
if (!PyTuple_Check(py_ann) || PyTuple_Size(py_ann) != 2) {
srd_err("Protocol decoder %s annotation %zd should be a tuple with two elements.",
+ dec->name, ann_idx + 1);
goto err_out;
}
if (py_strseq_to_char(py_ann, &annpair) != SRD_OK)
goto err_out;
}
if (py_strseq_to_char(py_ann, &annpair) != SRD_OK)
PyObject *py_ann_rows, *py_ann_row, *py_ann_classes, *py_item;
GSList *annotation_rows;
struct srd_decoder_annotation_row *ann_row;
PyObject *py_ann_rows, *py_ann_row, *py_ann_classes, *py_item;
GSList *annotation_rows;
struct srd_decoder_annotation_row *ann_row;
+ ssize_t row_idx, item_idx;
size_t class_idx;
PyGILState_STATE gstate;
size_t class_idx;
PyGILState_STATE gstate;
- for (i = PyTuple_Size(py_ann_rows) - 1; i >= 0; i--) {
- py_ann_row = PyTuple_GetItem(py_ann_rows, i);
+ row_idx = PyTuple_Size(py_ann_rows);
+ while (row_idx--) {
+ py_ann_row = PyTuple_GetItem(py_ann_rows, row_idx);
if (!py_ann_row)
goto except_out;
if (!py_ann_row)
goto except_out;
- for (k = PyTuple_Size(py_ann_classes) - 1; k >= 0; k--) {
- py_item = PyTuple_GetItem(py_ann_classes, k);
+ item_idx = PyTuple_Size(py_ann_classes);
+ while (item_idx--) {
+ py_item = PyTuple_GetItem(py_ann_classes, item_idx);
if (!py_item)
goto except_out;
if (!py_item)
goto except_out;
goto except_out;
if (class_idx >= cls_count) {
srd_err("Protocol decoder %s annotation row %zd references invalid class %zu.",
goto except_out;
if (class_idx >= cls_count) {
srd_err("Protocol decoder %s annotation row %zd references invalid class %zu.",
- dec->name, i, class_idx);
+ dec->name, row_idx, class_idx);
PyObject *py_bin_classes, *py_bin_class;
GSList *bin_classes;
char **bin;
PyObject *py_bin_classes, *py_bin_class;
GSList *bin_classes;
char **bin;
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
- for (i = PyTuple_Size(py_bin_classes) - 1; i >= 0; i--) {
- py_bin_class = PyTuple_GetItem(py_bin_classes, i);
+ bin_idx = PyTuple_Size(py_bin_classes);
+ while (bin_idx--) {
+ py_bin_class = PyTuple_GetItem(py_bin_classes, bin_idx);
if (!py_bin_class)
goto except_out;
if (!py_bin_class)
goto except_out;