| 189 | } |
| 190 | |
| 191 | static int get_channels(const struct srd_decoder *d, const char *attr, |
| 192 | GSList **out_pdchl, int offset) |
| 193 | { |
| 194 | PyObject *py_channellist, *py_entry; |
| 195 | struct srd_channel *pdch; |
| 196 | GSList *pdchl; |
| 197 | ssize_t i; |
| 198 | PyGILState_STATE gstate; |
| 199 | |
| 200 | gstate = PyGILState_Ensure(); |
| 201 | |
| 202 | if (!PyObject_HasAttrString(d->py_dec, attr)) { |
| 203 | /* No channels of this type specified. */ |
| 204 | PyGILState_Release(gstate); |
| 205 | return SRD_OK; |
| 206 | } |
| 207 | |
| 208 | pdchl = NULL; |
| 209 | |
| 210 | py_channellist = PyObject_GetAttrString(d->py_dec, attr); |
| 211 | if (!py_channellist) |
| 212 | goto except_out; |
| 213 | |
| 214 | if (!PyTuple_Check(py_channellist)) { |
| 215 | srd_err("Protocol decoder %s %s attribute is not a tuple.", |
| 216 | d->name, attr); |
| 217 | goto err_out; |
| 218 | } |
| 219 | |
| 220 | for (i = PyTuple_Size(py_channellist) - 1; i >= 0; i--) { |
| 221 | py_entry = PyTuple_GetItem(py_channellist, i); |
| 222 | if (!py_entry) |
| 223 | goto except_out; |
| 224 | |
| 225 | if (!PyDict_Check(py_entry)) { |
| 226 | srd_err("Protocol decoder %s %s attribute is not " |
| 227 | "a list of dict elements.", d->name, attr); |
| 228 | goto err_out; |
| 229 | } |
| 230 | pdch = malloc(sizeof(struct srd_channel)); |
| 231 | if (pdch == NULL){ |
| 232 | srd_err("%s,ERROR:failed to alloc memory.", __func__); |
| 233 | goto err_out; |
| 234 | } |
| 235 | memset(pdch, 0, sizeof(struct srd_channel)); |
| 236 | |
| 237 | /* Add to list right away so it doesn't get lost. */ |
| 238 | pdchl = g_slist_prepend(pdchl, pdch); |
| 239 | |
| 240 | if (py_dictitem_as_str(py_entry, "id", &pdch->id) != SRD_OK) |
| 241 | goto err_out; |
| 242 | if (py_dictitem_as_str(py_entry, "name", &pdch->name) != SRD_OK) |
| 243 | goto err_out; |
| 244 | if (py_dictitem_as_str(py_entry, "desc", &pdch->desc) != SRD_OK) |
| 245 | goto err_out; |
| 246 | |
| 247 | py_dictitem_as_str(py_entry, "idn", &pdch->idn); |
| 248 |
no test coverage detected