Convert binary classes to GSList of char **. */
| 594 | |
| 595 | /* Convert binary classes to GSList of char **. */ |
| 596 | static int get_binary_classes(struct srd_decoder *dec) |
| 597 | { |
| 598 | PyObject *py_bin_classes, *py_bin_class; |
| 599 | GSList *bin_classes; |
| 600 | char **bin; |
| 601 | ssize_t i; |
| 602 | PyGILState_STATE gstate; |
| 603 | |
| 604 | gstate = PyGILState_Ensure(); |
| 605 | |
| 606 | if (!PyObject_HasAttrString(dec->py_dec, "binary")) { |
| 607 | PyGILState_Release(gstate); |
| 608 | return SRD_OK; |
| 609 | } |
| 610 | |
| 611 | bin_classes = NULL; |
| 612 | |
| 613 | py_bin_classes = PyObject_GetAttrString(dec->py_dec, "binary"); |
| 614 | if (!py_bin_classes) |
| 615 | goto except_out; |
| 616 | |
| 617 | if (!PyTuple_Check(py_bin_classes)) { |
| 618 | srd_err("Protocol decoder %s binary classes should " |
| 619 | "be a tuple.", dec->name); |
| 620 | goto err_out; |
| 621 | } |
| 622 | |
| 623 | for (i = PyTuple_Size(py_bin_classes) - 1; i >= 0; i--) { |
| 624 | py_bin_class = PyTuple_GetItem(py_bin_classes, i); |
| 625 | if (!py_bin_class) |
| 626 | goto except_out; |
| 627 | |
| 628 | if (!PyTuple_Check(py_bin_class) |
| 629 | || PyTuple_Size(py_bin_class) != 2) { |
| 630 | srd_err("Protocol decoder %s binary classes should " |
| 631 | "consist only of tuples of 2 elements.", |
| 632 | dec->name); |
| 633 | goto err_out; |
| 634 | } |
| 635 | if (py_strseq_to_char(py_bin_class, &bin) != SRD_OK) |
| 636 | goto err_out; |
| 637 | |
| 638 | bin_classes = g_slist_prepend(bin_classes, bin); |
| 639 | } |
| 640 | dec->binary = bin_classes; |
| 641 | Py_DECREF(py_bin_classes); |
| 642 | PyGILState_Release(gstate); |
| 643 | |
| 644 | return SRD_OK; |
| 645 | |
| 646 | except_out: |
| 647 | srd_exception_catch(NULL, "Failed to get %s decoder binary classes", |
| 648 | dec->name); |
| 649 | |
| 650 | err_out: |
| 651 | g_slist_free_full(bin_classes, (GDestroyNotify)&g_strfreev); |
| 652 | Py_XDECREF(py_bin_classes); |
| 653 | PyGILState_Release(gstate); |
no test coverage detected