Check whether the Decoder class defines the named method. */
| 657 | |
| 658 | /* Check whether the Decoder class defines the named method. */ |
| 659 | static int check_method(PyObject *py_dec, const char *mod_name, |
| 660 | const char *method_name) |
| 661 | { |
| 662 | PyObject *py_method; |
| 663 | int is_callable; |
| 664 | PyGILState_STATE gstate; |
| 665 | |
| 666 | gstate = PyGILState_Ensure(); |
| 667 | |
| 668 | py_method = PyObject_GetAttrString(py_dec, method_name); |
| 669 | if (!py_method) { |
| 670 | srd_exception_catch(NULL, "Protocol decoder %s Decoder class " |
| 671 | "has no %s() method", mod_name, method_name); |
| 672 | PyGILState_Release(gstate); |
| 673 | return SRD_ERR_PYTHON; |
| 674 | } |
| 675 | |
| 676 | is_callable = PyCallable_Check(py_method); |
| 677 | Py_DECREF(py_method); |
| 678 | |
| 679 | PyGILState_Release(gstate); |
| 680 | |
| 681 | if (!is_callable) { |
| 682 | srd_err("Protocol decoder %s Decoder class attribute '%s' " |
| 683 | "is not a method.", mod_name, method_name); |
| 684 | return SRD_ERR_PYTHON; |
| 685 | } |
| 686 | |
| 687 | return SRD_OK; |
| 688 | } |
| 689 | |
| 690 | /** |
| 691 | * Get the API version of the specified decoder. |
no test coverage detected