| 734 | } |
| 735 | |
| 736 | bool GjsCallbackTrampoline::initialize() { |
| 737 | g_assert(is_valid()); |
| 738 | g_assert(!m_closure); |
| 739 | |
| 740 | /* Analyze param types and directions, similarly to |
| 741 | * init_cached_function_data */ |
| 742 | unsigned n_param_types = m_info.n_args(); |
| 743 | for (unsigned i = 0; i < n_param_types; i++) { |
| 744 | GI::StackArgInfo arg_info; |
| 745 | GI::StackTypeInfo type_info; |
| 746 | |
| 747 | if (m_param_types[i] == PARAM_SKIPPED) |
| 748 | continue; |
| 749 | |
| 750 | m_info.load_arg(i, &arg_info); |
| 751 | arg_info.load_type(&type_info); |
| 752 | |
| 753 | GIDirection direction = arg_info.direction(); |
| 754 | GITypeTag type_tag = type_info.tag(); |
| 755 | |
| 756 | if (direction != GI_DIRECTION_IN) { |
| 757 | // INOUT and OUT arguments are handled differently. |
| 758 | continue; |
| 759 | } |
| 760 | |
| 761 | if (type_tag == GI_TYPE_TAG_INTERFACE) { |
| 762 | if (type_info.interface().is_callback()) { |
| 763 | gjs_throw(cx(), |
| 764 | "%s %s accepts another callback as a parameter. This " |
| 765 | "is not supported", |
| 766 | m_is_vfunc ? "VFunc" : "Callback", m_info.name()); |
| 767 | return false; |
| 768 | } |
| 769 | } else if (type_tag == GI_TYPE_TAG_ARRAY) { |
| 770 | if (type_info.array_type() == GI_ARRAY_TYPE_C) { |
| 771 | Maybe<unsigned> array_length_pos = |
| 772 | type_info.array_length_index(); |
| 773 | if (!array_length_pos) |
| 774 | continue; |
| 775 | |
| 776 | if (*array_length_pos < n_param_types) { |
| 777 | GI::StackArgInfo length_arg_info; |
| 778 | m_info.load_arg(*array_length_pos, &length_arg_info); |
| 779 | |
| 780 | if (length_arg_info.direction() != direction) { |
| 781 | gjs_throw(cx(), |
| 782 | "%s %s has an array with different-direction " |
| 783 | "length argument. This is not supported", |
| 784 | m_is_vfunc ? "VFunc" : "Callback", |
| 785 | m_info.name()); |
| 786 | return false; |
| 787 | } |
| 788 | |
| 789 | m_param_types[*array_length_pos] = PARAM_SKIPPED; |
| 790 | m_param_types[i] = PARAM_ARRAY; |
| 791 | } |
| 792 | } |
| 793 | } |
no test coverage detected