girepository: Fix declaration of ‘find using interfaces’ methods

Fix the declaration and documentation of
`gi_object_info_find_method_using_interfaces()` and
`gi_object_info_find_vfunc_using_interfaces()`. The documentation was
wrong when I wrote it: the value returned is the object or interface
which declares the method or vfunc, not the one which implements it.

The returned declarer info may be a `GIObjectInfo` or a
`GIInterfaceInfo`. Since those two types have no subtype relation
between them, the return type has to be changed to `GIBaseInfo`. Using
`GIObjectInfo` would have been fine in girepository-1.0 because all
`*Info` types were aliases of each other — but since the move to
`GTypeInstance` this is no longer true.

A unit test will be in the following commit.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Fixes: #3246
This commit is contained in:
Philip Withnall 2024-02-05 18:40:03 +00:00
parent 702719dee9
commit 7acef299c2
3 changed files with 33 additions and 26 deletions

View File

@ -53,6 +53,7 @@ your code if integer type warnings are enabled.
| `g_callable_info_invoke` arguments | `is_method` and `throws` dropped in [method@GIRepository.CallableInfo.invoke] | | `g_callable_info_invoke` arguments | `is_method` and `throws` dropped in [method@GIRepository.CallableInfo.invoke] |
| `g_constant_info_get_type` | [method@GIRepository.ConstantInfo.get_type_info] | | `g_constant_info_get_type` | [method@GIRepository.ConstantInfo.get_type_info] |
| `g_field_info_get_type` | [method@GIRepository.FieldInfo.get_type_info] | | `g_field_info_get_type` | [method@GIRepository.FieldInfo.get_type_info] |
| `g_object_info_find_method_using_interfaces` and `g_object_info_find_vfunc_using_interfaces` | The `implementor` out argument has been renamed to `declarer` and is now of type [type@GIRepository.BaseInfo] |
| `g_object_info_get_type_init` | [method@GIRepository.ObjectInfo.get_type_init_function_name] | | `g_object_info_get_type_init` | [method@GIRepository.ObjectInfo.get_type_init_function_name] |
| `g_object_info_get_ref_function` | [method@GIRepository.ObjectInfo.get_ref_function_name] | | `g_object_info_get_ref_function` | [method@GIRepository.ObjectInfo.get_ref_function_name] |
| `g_object_info_get_unref_function` | [method@GIRepository.ObjectInfo.get_unref_function_name] | | `g_object_info_get_unref_function` | [method@GIRepository.ObjectInfo.get_unref_function_name] |

View File

@ -496,9 +496,10 @@ gi_object_info_find_method (GIObjectInfo *info,
* gi_object_info_find_method_using_interfaces: * gi_object_info_find_method_using_interfaces:
* @info: a #GIObjectInfo * @info: a #GIObjectInfo
* @name: name of method to obtain * @name: name of method to obtain
* @implementor: (out) (transfer full) (optional) (nullable): The implementor of * @declarer: (out) (transfer full) (optional) (nullable): The
* the interface, or `NULL` to ignore. If no method is found, this will return * [class@GIRepository.ObjectInfo] or [class@GIRepository.InterfaceInfo] which
* `NULL`. * declares the method, or `NULL` to ignore. If no method is found, this will
* return `NULL`.
* *
* Obtain a method of the object given a @name, searching both the * Obtain a method of the object given a @name, searching both the
* object @info and any interfaces it implements. * object @info and any interfaces it implements.
@ -516,14 +517,14 @@ gi_object_info_find_method (GIObjectInfo *info,
GIFunctionInfo * GIFunctionInfo *
gi_object_info_find_method_using_interfaces (GIObjectInfo *info, gi_object_info_find_method_using_interfaces (GIObjectInfo *info,
const char *name, const char *name,
GIObjectInfo **implementor) GIBaseInfo **declarer)
{ {
GIFunctionInfo *result = NULL; GIFunctionInfo *result = NULL;
GIObjectInfo *implementor_result = NULL; GIBaseInfo *declarer_result = NULL;
result = gi_object_info_find_method (info, name); result = gi_object_info_find_method (info, name);
if (result) if (result)
implementor_result = (GIObjectInfo *) gi_base_info_ref ((GIBaseInfo*) info); declarer_result = gi_base_info_ref (info);
if (result == NULL) if (result == NULL)
{ {
@ -541,17 +542,19 @@ gi_object_info_find_method_using_interfaces (GIObjectInfo *info,
if (result != NULL) if (result != NULL)
{ {
implementor_result = (GIObjectInfo *) iface_info; declarer_result = GI_BASE_INFO (g_steal_pointer (&iface_info));
break; break;
} }
gi_base_info_unref ((GIBaseInfo*) iface_info); gi_base_info_unref ((GIBaseInfo*) iface_info);
} }
} }
if (implementor)
*implementor = implementor_result; if (declarer)
else if (implementor_result != NULL) *declarer = g_steal_pointer (&declarer_result);
gi_base_info_unref ((GIBaseInfo*) implementor_result);
return result; g_clear_pointer (&declarer_result, gi_base_info_unref);
return g_steal_pointer (&result);
} }
/** /**
@ -766,9 +769,10 @@ gi_object_info_find_vfunc (GIObjectInfo *info,
* gi_object_info_find_vfunc_using_interfaces: * gi_object_info_find_vfunc_using_interfaces:
* @info: a #GIObjectInfo * @info: a #GIObjectInfo
* @name: name of vfunc to obtain * @name: name of vfunc to obtain
* @implementor: (out) (transfer full) (optional) (nullable): The implementor of * @declarer: (out) (transfer full) (optional) (nullable): The
* the interface, or `NULL` to ignore. If no vfunc is found, this will return * [class@GIRepository.ObjectInfo] or [class@GIRepository.InterfaceInfo] which
* `NULL`. * declares the vfunc, or `NULL` to ignore. If no vfunc is found, this will
* return `NULL`.
* *
* Locate a virtual function slot with name @name, searching both the object * Locate a virtual function slot with name @name, searching both the object
* @info and any interfaces it implements. * @info and any interfaces it implements.
@ -791,14 +795,14 @@ gi_object_info_find_vfunc (GIObjectInfo *info,
GIVFuncInfo * GIVFuncInfo *
gi_object_info_find_vfunc_using_interfaces (GIObjectInfo *info, gi_object_info_find_vfunc_using_interfaces (GIObjectInfo *info,
const char *name, const char *name,
GIObjectInfo **implementor) GIBaseInfo **declarer)
{ {
GIVFuncInfo *result = NULL; GIVFuncInfo *result = NULL;
GIObjectInfo *implementor_result = NULL; GIBaseInfo *declarer_result = NULL;
result = gi_object_info_find_vfunc (info, name); result = gi_object_info_find_vfunc (info, name);
if (result) if (result)
implementor_result = (GIObjectInfo *) gi_base_info_ref ((GIBaseInfo*) info); declarer_result = gi_base_info_ref (info);
if (result == NULL) if (result == NULL)
{ {
@ -816,17 +820,19 @@ gi_object_info_find_vfunc_using_interfaces (GIObjectInfo *info,
if (result != NULL) if (result != NULL)
{ {
implementor_result = (GIObjectInfo *) iface_info; declarer_result = GI_BASE_INFO (g_steal_pointer (&iface_info));
break; break;
} }
gi_base_info_unref ((GIBaseInfo*) iface_info); gi_base_info_unref ((GIBaseInfo*) iface_info);
} }
} }
if (implementor)
*implementor = implementor_result; if (declarer)
else if (implementor_result != NULL) *declarer = g_steal_pointer (&declarer_result);
gi_base_info_unref ((GIBaseInfo*) implementor_result);
return result; g_clear_pointer (&declarer_result, gi_base_info_unref);
return g_steal_pointer (&result);
} }
/** /**

View File

@ -156,7 +156,7 @@ GIFunctionInfo * gi_object_info_find_method (GIObjectInfo *info,
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL
GIFunctionInfo * gi_object_info_find_method_using_interfaces (GIObjectInfo *info, GIFunctionInfo * gi_object_info_find_method_using_interfaces (GIObjectInfo *info,
const char *name, const char *name,
GIObjectInfo **implementor); GIBaseInfo **declarer);
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL
@ -186,7 +186,7 @@ GIVFuncInfo * gi_object_info_find_vfunc (GIObjectInfo *info,
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL
GIVFuncInfo * gi_object_info_find_vfunc_using_interfaces (GIObjectInfo *info, GIVFuncInfo * gi_object_info_find_vfunc_using_interfaces (GIObjectInfo *info,
const char *name, const char *name,
GIObjectInfo **implementor); GIBaseInfo **declarer);
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL
unsigned int gi_object_info_get_n_constants (GIObjectInfo *info); unsigned int gi_object_info_get_n_constants (GIObjectInfo *info);