mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
Merge branch '3246-object-info-docs' into 'main'
girepository: Fix declaration of ‘find using interfaces’ methods Closes #3246 See merge request GNOME/glib!3883
This commit is contained in:
commit
78698af73f
@ -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_constant_info_get_type` | [method@GIRepository.ConstantInfo.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_ref_function` | [method@GIRepository.ObjectInfo.get_ref_function_name] |
|
||||
| `g_object_info_get_unref_function` | [method@GIRepository.ObjectInfo.get_unref_function_name] |
|
||||
|
@ -496,9 +496,10 @@ gi_object_info_find_method (GIObjectInfo *info,
|
||||
* gi_object_info_find_method_using_interfaces:
|
||||
* @info: a #GIObjectInfo
|
||||
* @name: name of method to obtain
|
||||
* @implementor: (out) (transfer full) (optional) (nullable): The implementor of
|
||||
* the interface, or `NULL` to ignore. If no method is found, this will return
|
||||
* `NULL`.
|
||||
* @declarer: (out) (transfer full) (optional) (nullable): The
|
||||
* [class@GIRepository.ObjectInfo] or [class@GIRepository.InterfaceInfo] which
|
||||
* 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
|
||||
* object @info and any interfaces it implements.
|
||||
@ -516,14 +517,14 @@ gi_object_info_find_method (GIObjectInfo *info,
|
||||
GIFunctionInfo *
|
||||
gi_object_info_find_method_using_interfaces (GIObjectInfo *info,
|
||||
const char *name,
|
||||
GIObjectInfo **implementor)
|
||||
GIBaseInfo **declarer)
|
||||
{
|
||||
GIFunctionInfo *result = NULL;
|
||||
GIObjectInfo *implementor_result = NULL;
|
||||
GIBaseInfo *declarer_result = NULL;
|
||||
|
||||
result = gi_object_info_find_method (info, name);
|
||||
if (result)
|
||||
implementor_result = (GIObjectInfo *) gi_base_info_ref ((GIBaseInfo*) info);
|
||||
declarer_result = gi_base_info_ref (info);
|
||||
|
||||
if (result == NULL)
|
||||
{
|
||||
@ -541,17 +542,19 @@ gi_object_info_find_method_using_interfaces (GIObjectInfo *info,
|
||||
|
||||
if (result != NULL)
|
||||
{
|
||||
implementor_result = (GIObjectInfo *) iface_info;
|
||||
declarer_result = GI_BASE_INFO (g_steal_pointer (&iface_info));
|
||||
break;
|
||||
}
|
||||
gi_base_info_unref ((GIBaseInfo*) iface_info);
|
||||
}
|
||||
}
|
||||
if (implementor)
|
||||
*implementor = implementor_result;
|
||||
else if (implementor_result != NULL)
|
||||
gi_base_info_unref ((GIBaseInfo*) implementor_result);
|
||||
return result;
|
||||
|
||||
if (declarer)
|
||||
*declarer = g_steal_pointer (&declarer_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:
|
||||
* @info: a #GIObjectInfo
|
||||
* @name: name of vfunc to obtain
|
||||
* @implementor: (out) (transfer full) (optional) (nullable): The implementor of
|
||||
* the interface, or `NULL` to ignore. If no vfunc is found, this will return
|
||||
* `NULL`.
|
||||
* @declarer: (out) (transfer full) (optional) (nullable): The
|
||||
* [class@GIRepository.ObjectInfo] or [class@GIRepository.InterfaceInfo] which
|
||||
* 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
|
||||
* @info and any interfaces it implements.
|
||||
@ -791,14 +795,14 @@ gi_object_info_find_vfunc (GIObjectInfo *info,
|
||||
GIVFuncInfo *
|
||||
gi_object_info_find_vfunc_using_interfaces (GIObjectInfo *info,
|
||||
const char *name,
|
||||
GIObjectInfo **implementor)
|
||||
GIBaseInfo **declarer)
|
||||
{
|
||||
GIVFuncInfo *result = NULL;
|
||||
GIObjectInfo *implementor_result = NULL;
|
||||
GIBaseInfo *declarer_result = NULL;
|
||||
|
||||
result = gi_object_info_find_vfunc (info, name);
|
||||
if (result)
|
||||
implementor_result = (GIObjectInfo *) gi_base_info_ref ((GIBaseInfo*) info);
|
||||
declarer_result = gi_base_info_ref (info);
|
||||
|
||||
if (result == NULL)
|
||||
{
|
||||
@ -816,17 +820,19 @@ gi_object_info_find_vfunc_using_interfaces (GIObjectInfo *info,
|
||||
|
||||
if (result != NULL)
|
||||
{
|
||||
implementor_result = (GIObjectInfo *) iface_info;
|
||||
declarer_result = GI_BASE_INFO (g_steal_pointer (&iface_info));
|
||||
break;
|
||||
}
|
||||
gi_base_info_unref ((GIBaseInfo*) iface_info);
|
||||
}
|
||||
}
|
||||
if (implementor)
|
||||
*implementor = implementor_result;
|
||||
else if (implementor_result != NULL)
|
||||
gi_base_info_unref ((GIBaseInfo*) implementor_result);
|
||||
return result;
|
||||
|
||||
if (declarer)
|
||||
*declarer = g_steal_pointer (&declarer_result);
|
||||
|
||||
g_clear_pointer (&declarer_result, gi_base_info_unref);
|
||||
|
||||
return g_steal_pointer (&result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -156,7 +156,7 @@ GIFunctionInfo * gi_object_info_find_method (GIObjectInfo *info,
|
||||
GI_AVAILABLE_IN_ALL
|
||||
GIFunctionInfo * gi_object_info_find_method_using_interfaces (GIObjectInfo *info,
|
||||
const char *name,
|
||||
GIObjectInfo **implementor);
|
||||
GIBaseInfo **declarer);
|
||||
|
||||
|
||||
GI_AVAILABLE_IN_ALL
|
||||
@ -186,7 +186,7 @@ GIVFuncInfo * gi_object_info_find_vfunc (GIObjectInfo *info,
|
||||
GI_AVAILABLE_IN_ALL
|
||||
GIVFuncInfo * gi_object_info_find_vfunc_using_interfaces (GIObjectInfo *info,
|
||||
const char *name,
|
||||
GIObjectInfo **implementor);
|
||||
GIBaseInfo **declarer);
|
||||
|
||||
GI_AVAILABLE_IN_ALL
|
||||
unsigned int gi_object_info_get_n_constants (GIObjectInfo *info);
|
||||
|
@ -17,6 +17,9 @@ if enable_gir
|
||||
'dependencies': [libffi_dep],
|
||||
'depends': [glib_gir],
|
||||
},
|
||||
'object-info' : {
|
||||
'depends': [gio_gir],
|
||||
},
|
||||
'repository' : {
|
||||
'depends': [glib_gir, gio_gir, gobject_gir],
|
||||
},
|
||||
|
82
girepository/tests/object-info.c
Normal file
82
girepository/tests/object-info.c
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright 2024 Philip Chimento <philip.chimento@gmail.com>
|
||||
* Copyright 2024 GNOME Foundation
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General
|
||||
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "girepository.h"
|
||||
#include "test-common.h"
|
||||
|
||||
static void
|
||||
test_object_info_find_method_using_interfaces (RepositoryFixture *fx,
|
||||
const void *unused)
|
||||
{
|
||||
GIObjectInfo *class_info = NULL;
|
||||
GIFunctionInfo *method_info = NULL;
|
||||
GIBaseInfo *declarer_info = NULL;
|
||||
|
||||
class_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "Gio", "DBusProxy"));
|
||||
g_assert_nonnull (class_info);
|
||||
|
||||
method_info = gi_object_info_find_method_using_interfaces (class_info, "init", &declarer_info);
|
||||
|
||||
g_assert_nonnull (declarer_info);
|
||||
g_assert_cmpstr (gi_base_info_get_namespace (declarer_info), ==, "Gio");
|
||||
g_assert_cmpstr (gi_base_info_get_name (declarer_info), ==, "Initable");
|
||||
g_assert_true (GI_IS_INTERFACE_INFO (declarer_info));
|
||||
|
||||
g_clear_pointer (&class_info, gi_base_info_unref);
|
||||
g_clear_pointer (&method_info, gi_base_info_unref);
|
||||
g_clear_pointer (&declarer_info, gi_base_info_unref);
|
||||
}
|
||||
|
||||
static void
|
||||
test_object_info_find_vfunc_using_interfaces (RepositoryFixture *fx,
|
||||
const void *unused)
|
||||
{
|
||||
GIObjectInfo *class_info = NULL;
|
||||
GIVFuncInfo *vfunc_info = NULL;
|
||||
GIBaseInfo *declarer_info = NULL;
|
||||
|
||||
class_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "Gio", "Application"));
|
||||
g_assert_nonnull (class_info);
|
||||
|
||||
vfunc_info = gi_object_info_find_vfunc_using_interfaces (class_info, "after_emit", &declarer_info);
|
||||
|
||||
g_assert_nonnull (declarer_info);
|
||||
g_assert_cmpstr (gi_base_info_get_namespace (declarer_info), ==, "Gio");
|
||||
g_assert_cmpstr (gi_base_info_get_name (declarer_info), ==, "Application");
|
||||
g_assert_true (GI_IS_OBJECT_INFO (declarer_info));
|
||||
|
||||
g_clear_pointer (&class_info, gi_base_info_unref);
|
||||
g_clear_pointer (&vfunc_info, gi_base_info_unref);
|
||||
g_clear_pointer (&declarer_info, gi_base_info_unref);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc,
|
||||
char *argv[])
|
||||
{
|
||||
repository_init (&argc, &argv);
|
||||
|
||||
ADD_REPOSITORY_TEST ("/object-info/find-method-using-interfaces", test_object_info_find_method_using_interfaces, &typelib_load_spec_gio);
|
||||
ADD_REPOSITORY_TEST ("/object-info/find-vfunc-using-interfaces", test_object_info_find_vfunc_using_interfaces, &typelib_load_spec_gio);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
Loading…
Reference in New Issue
Block a user