Example #1
0
def vfunc_info_get_address(vfunc_info, gtype):
    '''
        GIRepository.vfunc_info_get_address almost does what we need... but it
        derefs the address, so it cannot be used for our purposes. This code is
        a translation of that C code into python
    '''
    container_info = vfunc_info.get_container()
    if container_info.get_type() == GIRepository.InfoType.OBJECT:
        object_info = container_info
        interface_info = None
        struct_info = GIRepository.object_info_get_class_struct(object_info)
    else:
        interface_info = container_info
        object_info = None
        struct_info = GIRepository.interface_info_get_iface_struct(
            interface_info)

    field_info = GIRepository.struct_info_find_field(struct_info,
                                                     vfunc_info.get_name())
    if field_info is None:
        raise AttributeError("Could not find struct field for vfunc")

    implementor_class = GObject.type_class_ref(gtype)
    if object_info:
        implementor_vtable = implementor_class
    else:
        interface_type = GIRepository.registered_type_info_get_g_type(
            interface_info)
        implementor_vtable = GObject.type_interface_peek(
            implementor_class, interface_type)

    offset = GIRepository.field_info_get_offset(field_info)
    return hash(implementor_vtable) + offset