[gjs: 13/16] gi: Remove all use of g_irepository_get_default()
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 13/16] gi: Remove all use of g_irepository_get_default()
- Date: Sat, 13 Oct 2018 21:28:06 +0000 (UTC)
commit bbba30555746917e75847e4522a0e56fdf2aafc2
Author: Philip Chimento <philip chimento gmail com>
Date: Sun Oct 7 23:27:49 2018 -0700
gi: Remove all use of g_irepository_get_default()
Since all methods that take a GIRepository* also take NULL to indicate
g_irepository_get_default(), just use nullptr instead. This also cleans
up some of the surrounding code of these instances to use GjsAutoInfo for
better type-safety.
Includes bugfix by Marco Trevisan.
gi/arg.cpp | 7 ++-----
gi/fundamental.cpp | 39 ++++++++++++---------------------------
gi/ns.cpp | 21 ++++++---------------
gi/object.cpp | 2 +-
gi/param.cpp | 35 ++++++++++-------------------------
gi/repo.cpp | 9 ++++-----
gi/value.cpp | 38 +++++++++++++-------------------------
7 files changed, 48 insertions(+), 103 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index 35965ad2..b0979fbc 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -1328,9 +1328,8 @@ static void
intern_gdk_atom(const char *name,
GArgument *ret)
{
- GIRepository *repo = g_irepository_get_default();
- GIFunctionInfo *atom_intern_fun =
- g_irepository_find_by_name(repo, "Gdk", "atom_intern");
+ GjsAutoFunctionInfo atom_intern_fun =
+ g_irepository_find_by_name(nullptr, "Gdk", "atom_intern");
GIArgument atom_intern_args[2];
@@ -1345,8 +1344,6 @@ intern_gdk_atom(const char *name,
nullptr, 0,
ret,
nullptr);
-
- g_base_info_unref(atom_intern_fun);
}
bool
diff --git a/gi/fundamental.cpp b/gi/fundamental.cpp
index b7015018..a8706e9e 100644
--- a/gi/fundamental.cpp
+++ b/gi/fundamental.cpp
@@ -243,7 +243,6 @@ fundamental_instance_resolve_interface(JSContext *context,
Fundamental *proto_priv,
const char *name)
{
- GIFunctionInfo *method_info;
bool ret;
GType *interfaces;
guint n_interfaces;
@@ -252,37 +251,23 @@ fundamental_instance_resolve_interface(JSContext *context,
ret = true;
interfaces = g_type_interfaces(proto_priv->gtype, &n_interfaces);
for (i = 0; i < n_interfaces; i++) {
- GIBaseInfo *base_info;
- GIInterfaceInfo *iface_info;
-
- base_info = g_irepository_find_by_gtype(g_irepository_get_default(),
- interfaces[i]);
+ GjsAutoInterfaceInfo iface_info =
+ g_irepository_find_by_gtype(nullptr, interfaces[i]);
- if (base_info == NULL)
+ if (!iface_info)
continue;
- /* An interface GType ought to have interface introspection info */
- g_assert(g_base_info_get_type(base_info) == GI_INFO_TYPE_INTERFACE);
-
- iface_info = (GIInterfaceInfo *) base_info;
-
- method_info = g_interface_info_find_method(iface_info, name);
+ GjsAutoFunctionInfo method_info =
+ g_interface_info_find_method(iface_info, name);
- g_base_info_unref(base_info);
-
-
- if (method_info != NULL) {
- if (g_function_info_get_flags (method_info) & GI_FUNCTION_IS_METHOD) {
- if (gjs_define_function(context, obj,
- proto_priv->gtype,
- (GICallableInfo *) method_info)) {
- *resolved = true;
- } else {
- ret = false;
- }
+ if (method_info &&
+ g_function_info_get_flags(method_info) & GI_FUNCTION_IS_METHOD) {
+ if (gjs_define_function(context, obj, proto_priv->gtype,
+ method_info)) {
+ *resolved = true;
+ } else {
+ ret = false;
}
-
- g_base_info_unref((GIBaseInfo *) method_info);
}
}
diff --git a/gi/ns.cpp b/gi/ns.cpp
index 17d09fd2..04ae2b33 100644
--- a/gi/ns.cpp
+++ b/gi/ns.cpp
@@ -52,8 +52,6 @@ ns_resolve(JSContext *context,
bool *resolved)
{
Ns *priv;
- GIRepository *repo;
- GIBaseInfo *info;
bool defined;
if (!JSID_IS_STRING(id)) {
@@ -85,33 +83,26 @@ ns_resolve(JSContext *context,
return true; /* not resolved, but no error */
}
- repo = g_irepository_get_default();
-
- info = g_irepository_find_by_name(repo, priv->gi_namespace, name);
- if (info == NULL) {
+ GjsAutoBaseInfo info =
+ g_irepository_find_by_name(nullptr, priv->gi_namespace, name);
+ if (!info) {
*resolved = false; /* No property defined, but no error either */
return true;
}
gjs_debug(GJS_DEBUG_GNAMESPACE,
"Found info type %s for '%s' in namespace '%s'",
- gjs_info_type_name(g_base_info_get_type(info)),
- g_base_info_get_name(info),
- g_base_info_get_namespace(info));
+ gjs_info_type_name(info.type()), info.name(), info.ns());
JSAutoRequest ar(context);
if (!gjs_define_info(context, obj, info, &defined)) {
- gjs_debug(GJS_DEBUG_GNAMESPACE,
- "Failed to define info '%s'",
- g_base_info_get_name(info));
-
- g_base_info_unref(info);
+ gjs_debug(GJS_DEBUG_GNAMESPACE, "Failed to define info '%s'",
+ info.name());
return false;
}
/* we defined the property in this object? */
- g_base_info_unref(info);
*resolved = defined;
return true;
}
diff --git a/gi/object.cpp b/gi/object.cpp
index 26fbc74f..c276adba 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -2452,7 +2452,7 @@ bool ObjectPrototype::hook_up_vfunc_impl(JSContext* cx,
while (!info && info_gtype != G_TYPE_OBJECT) {
info_gtype = g_type_parent(info_gtype);
- info = g_irepository_find_by_gtype(g_irepository_get_default(), info_gtype);
+ info = g_irepository_find_by_gtype(nullptr, info_gtype);
}
/* If we don't have 'info', we don't have the base class (GObject).
diff --git a/gi/param.cpp b/gi/param.cpp
index 4c780113..20bdf324 100644
--- a/gi/param.cpp
+++ b/gi/param.cpp
@@ -55,12 +55,7 @@ param_resolve(JSContext *context,
JS::HandleId id,
bool *resolved)
{
- GIObjectInfo *info = NULL;
- GIFunctionInfo *method_info;
- Param *priv;
- bool ret = false;
-
- priv = priv_from_js(context, obj);
+ Param* priv = priv_from_js(context, obj);
if (priv != NULL) {
/* instance, not prototype */
*resolved = false;
@@ -73,39 +68,29 @@ param_resolve(JSContext *context,
return true; /* not resolved, but no error */
}
- info = (GIObjectInfo*)g_irepository_find_by_gtype(g_irepository_get_default(), G_TYPE_PARAM);
- method_info = g_object_info_find_method(info, name);
+ GjsAutoObjectInfo info = g_irepository_find_by_gtype(nullptr, G_TYPE_PARAM);
+ GjsAutoFunctionInfo method_info = g_object_info_find_method(info, name);
- if (method_info == NULL) {
+ if (!method_info) {
*resolved = false;
- ret = true;
- goto out;
+ return true;
}
#if GJS_VERBOSE_ENABLE_GI_USAGE
- _gjs_log_info_usage((GIBaseInfo*) method_info);
+ _gjs_log_info_usage(method_info);
#endif
if (g_function_info_get_flags (method_info) & GI_FUNCTION_IS_METHOD) {
gjs_debug(GJS_DEBUG_GOBJECT,
"Defining method %s in prototype for GObject.ParamSpec",
- g_base_info_get_name( (GIBaseInfo*) method_info));
+ method_info.name());
- if (gjs_define_function(context, obj, G_TYPE_PARAM, method_info) == NULL) {
- g_base_info_unref( (GIBaseInfo*) method_info);
- goto out;
- }
+ if (!gjs_define_function(context, obj, G_TYPE_PARAM, method_info))
+ return false;
*resolved = true; /* we defined the prop in obj */
}
- g_base_info_unref( (GIBaseInfo*) method_info);
-
- ret = true;
- out:
- if (info != NULL)
- g_base_info_unref( (GIBaseInfo*)info);
-
- return ret;
+ return true;
}
GJS_NATIVE_CONSTRUCTOR_DECLARE(param)
diff --git a/gi/repo.cpp b/gi/repo.cpp
index 2e67bfd7..90f9d37d 100644
--- a/gi/repo.cpp
+++ b/gi/repo.cpp
@@ -86,7 +86,6 @@ resolve_namespace_object(JSContext *context,
JS::HandleId ns_id,
const char *ns_name)
{
- GIRepository *repo;
GError *error;
JSAutoRequest ar(context);
@@ -95,11 +94,10 @@ resolve_namespace_object(JSContext *context,
if (!get_version_for_ns(context, repo_obj, ns_id, &version))
return false;
- repo = g_irepository_get_default();
- GList *versions = g_irepository_enumerate_versions(repo, ns_name);
+ GList* versions = g_irepository_enumerate_versions(nullptr, ns_name);
unsigned nversions = g_list_length(versions);
if (nversions > 1 && !version &&
- !g_irepository_is_registered(repo, ns_name, NULL)) {
+ !g_irepository_is_registered(nullptr, ns_name, NULL)) {
GjsAutoChar warn_text = g_strdup_printf("Requiring %s but it has %u "
"versions available; use "
"imports.gi.versions to pick one",
@@ -109,7 +107,8 @@ resolve_namespace_object(JSContext *context,
g_list_free_full(versions, g_free);
error = NULL;
- g_irepository_require(repo, ns_name, version, (GIRepositoryLoadFlags) 0, &error);
+ g_irepository_require(nullptr, ns_name, version, (GIRepositoryLoadFlags)0,
+ &error);
if (error != NULL) {
gjs_throw(context,
"Requiring %s, version %s: %s",
diff --git a/gi/value.cpp b/gi/value.cpp
index 4cf4ae4e..04104373 100644
--- a/gi/value.cpp
+++ b/gi/value.cpp
@@ -717,15 +717,11 @@ convert_int_to_enum (GType gtype,
/* Optimize the unambiguous case */
v_double = v;
} else {
- GIBaseInfo *info;
-
/* Need to distinguish between negative integers and unsigned integers */
-
- info = g_irepository_find_by_gtype(g_irepository_get_default(), gtype);
+ GjsAutoEnumInfo info = g_irepository_find_by_gtype(nullptr, gtype);
g_assert (info);
- v_double = _gjs_enum_from_int ((GIEnumInfo *)info, v);
- g_base_info_unref(info);
+ v_double = _gjs_enum_from_int(info, v);
}
return JS::NumberValue(v_double);
@@ -811,7 +807,6 @@ gjs_value_from_g_value_internal(JSContext *context,
} else if (g_type_is_a(gtype, G_TYPE_BOXED) ||
g_type_is_a(gtype, G_TYPE_VARIANT)) {
GjsBoxedCreationFlags boxed_flags;
- GIBaseInfo *info;
void *gboxed;
JSObject *obj;
@@ -837,43 +832,36 @@ gjs_value_from_g_value_internal(JSContext *context,
/* The only way to differentiate unions and structs is from
* their g-i info as both GBoxed */
- info = g_irepository_find_by_gtype(g_irepository_get_default(),
- gtype);
- if (info == NULL) {
+ GjsAutoBaseInfo info = g_irepository_find_by_gtype(nullptr, gtype);
+ if (!info) {
gjs_throw(context,
"No introspection information found for %s",
g_type_name(gtype));
return false;
}
- if (g_base_info_get_type(info) == GI_INFO_TYPE_STRUCT &&
- g_struct_info_is_foreign((GIStructInfo*)info)) {
- bool ret;
+ if (info.type() == GI_INFO_TYPE_STRUCT &&
+ g_struct_info_is_foreign(info)) {
GIArgument arg;
arg.v_pointer = gboxed;
- ret = gjs_struct_foreign_convert_from_g_argument(context, value_p, info, &arg);
- g_base_info_unref(info);
- return ret;
+ return gjs_struct_foreign_convert_from_g_argument(context, value_p,
+ info, &arg);
}
- GIInfoType type = g_base_info_get_type(info);
+ GIInfoType type = info.type();
if (type == GI_INFO_TYPE_BOXED || type == GI_INFO_TYPE_STRUCT) {
if (no_copy)
boxed_flags = (GjsBoxedCreationFlags) (boxed_flags | GJS_BOXED_CREATION_NO_COPY);
- obj = gjs_boxed_from_c_struct(context, (GIStructInfo *)info, gboxed, boxed_flags);
+ obj = gjs_boxed_from_c_struct(context, info, gboxed, boxed_flags);
} else if (type == GI_INFO_TYPE_UNION) {
- obj = gjs_union_from_c_union(context, (GIUnionInfo *)info, gboxed);
+ obj = gjs_union_from_c_union(context, info, gboxed);
} else {
- gjs_throw(context,
- "Unexpected introspection type %d for %s",
- g_base_info_get_type(info),
- g_type_name(gtype));
- g_base_info_unref(info);
+ gjs_throw(context, "Unexpected introspection type %d for %s",
+ info.type(), g_type_name(gtype));
return false;
}
value_p.setObjectOrNull(obj);
- g_base_info_unref(info);
} else if (g_type_is_a(gtype, G_TYPE_ENUM)) {
value_p.set(convert_int_to_enum(gtype, g_value_get_enum(gvalue)));
} else if (g_type_is_a(gtype, G_TYPE_PARAM)) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]