Convert annotation_rows to GSList of 'struct srd_decoder_annotation_row'. */
| 484 | |
| 485 | /* Convert annotation_rows to GSList of 'struct srd_decoder_annotation_row'. */ |
| 486 | static int get_annotation_rows(struct srd_decoder *dec) |
| 487 | { |
| 488 | PyObject *py_ann_rows, *py_ann_row, *py_ann_classes, *py_item; |
| 489 | GSList *annotation_rows; |
| 490 | struct srd_decoder_annotation_row *ann_row; |
| 491 | ssize_t i, k; |
| 492 | size_t class_idx; |
| 493 | PyGILState_STATE gstate; |
| 494 | |
| 495 | gstate = PyGILState_Ensure(); |
| 496 | |
| 497 | if (!PyObject_HasAttrString(dec->py_dec, "annotation_rows")) { |
| 498 | PyGILState_Release(gstate); |
| 499 | return SRD_OK; |
| 500 | } |
| 501 | |
| 502 | annotation_rows = NULL; |
| 503 | |
| 504 | py_ann_rows = PyObject_GetAttrString(dec->py_dec, "annotation_rows"); |
| 505 | if (!py_ann_rows) |
| 506 | goto except_out; |
| 507 | |
| 508 | if (!PyTuple_Check(py_ann_rows)) { |
| 509 | srd_err("Protocol decoder %s annotation_rows " |
| 510 | "must be a tuple.", dec->name); |
| 511 | goto err_out; |
| 512 | } |
| 513 | |
| 514 | for (i = PyTuple_Size(py_ann_rows) - 1; i >= 0; i--) { |
| 515 | py_ann_row = PyTuple_GetItem(py_ann_rows, i); |
| 516 | if (!py_ann_row) |
| 517 | goto except_out; |
| 518 | |
| 519 | if (!PyTuple_Check(py_ann_row) || PyTuple_Size(py_ann_row) != 3) { |
| 520 | srd_err("Protocol decoder %s annotation_rows " |
| 521 | "must contain only tuples of 3 elements.", |
| 522 | dec->name); |
| 523 | goto err_out; |
| 524 | } |
| 525 | ann_row = malloc(sizeof(struct srd_decoder_annotation_row)); |
| 526 | if (ann_row == NULL){ |
| 527 | srd_err("%s,ERROR:failed to alloc memory.", __func__); |
| 528 | goto err_out; |
| 529 | } |
| 530 | memset(ann_row, 0, sizeof(struct srd_decoder_annotation_row)); |
| 531 | |
| 532 | /* Add to list right away so it doesn't get lost. */ |
| 533 | annotation_rows = g_slist_prepend(annotation_rows, ann_row); |
| 534 | |
| 535 | py_item = PyTuple_GetItem(py_ann_row, 0); |
| 536 | if (!py_item) |
| 537 | goto except_out; |
| 538 | if (py_str_as_str(py_item, &ann_row->id) != SRD_OK) |
| 539 | goto err_out; |
| 540 | |
| 541 | py_item = PyTuple_GetItem(py_ann_row, 1); |
| 542 | if (!py_item) |
| 543 | goto except_out; |
no test coverage detected