summaryrefslogtreecommitdiff
path: root/codegen
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2023-03-09 09:34:36 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2023-03-09 09:34:36 +0100
commitd5ecd13849a6a9126d3b90d16a3268f860800b41 (patch)
tree4cb4da99594d12a3782940970503da46a43501ea /codegen
parent2485098aa1a16018b2b748a723177e71e093ab73 (diff)
downloadvala-d5ecd13849a6a9126d3b90d16a3268f860800b41.tar.gz
codegen: Consistently handle GLib.Error as boxed type
Use G_TYPE_ERROR and GBoxed API for all error domains. Fixes https://gitlab.gnome.org/GNOME/vala/issues/1418
Diffstat (limited to 'codegen')
-rw-r--r--codegen/valaccodeattribute.vala16
-rw-r--r--codegen/valagsignalmodule.vala4
-rw-r--r--codegen/valagtypemodule.vala3
3 files changed, 17 insertions, 6 deletions
diff --git a/codegen/valaccodeattribute.vala b/codegen/valaccodeattribute.vala
index 9b49fe9e1..3901e65d9 100644
--- a/codegen/valaccodeattribute.vala
+++ b/codegen/valaccodeattribute.vala
@@ -1174,7 +1174,7 @@ public class Vala.CCodeAttribute : AttributeCache {
} else if (node is PointerType || node is GenericType) {
return "POINTER";
} else if (node is ErrorType) {
- return "POINTER";
+ return "BOXED";
} else if (node is ArrayType) {
unowned ArrayType array_type = (ArrayType) node;
if (array_type.element_type.type_symbol == CodeContext.get ().analyzer.string_type.type_symbol) {
@@ -1212,7 +1212,7 @@ public class Vala.CCodeAttribute : AttributeCache {
return get_ccode_lower_case_name (cl, "value_get_");
} else if (cl.base_class != null) {
return get_ccode_get_value_function (cl.base_class);
- } else if (type_id == "G_TYPE_POINTER" || cl.is_error_base) {
+ } else if (type_id == "G_TYPE_POINTER") {
return "g_value_get_pointer";
} else {
return "g_value_get_boxed";
@@ -1232,6 +1232,8 @@ public class Vala.CCodeAttribute : AttributeCache {
return "g_value_get_int";
}
}
+ } else if (sym is ErrorDomain) {
+ return "g_value_get_boxed";
} else if (sym is Interface) {
foreach (var prereq in ((Interface) sym).get_prerequisites ()) {
var type_name = get_ccode_get_value_function (prereq.type_symbol);
@@ -1270,7 +1272,7 @@ public class Vala.CCodeAttribute : AttributeCache {
return get_ccode_lower_case_name (cl, "value_set_");
} else if (cl.base_class != null) {
return get_ccode_set_value_function (cl.base_class);
- } else if (type_id == "G_TYPE_POINTER" || cl.is_error_base) {
+ } else if (type_id == "G_TYPE_POINTER") {
return "g_value_set_pointer";
} else {
return "g_value_set_boxed";
@@ -1290,6 +1292,8 @@ public class Vala.CCodeAttribute : AttributeCache {
return "g_value_set_int";
}
}
+ } else if (sym is ErrorDomain) {
+ return "g_value_set_boxed";
} else if (sym is Interface) {
foreach (var prereq in ((Interface) sym).get_prerequisites ()) {
var type_name = get_ccode_set_value_function (prereq.type_symbol);
@@ -1328,7 +1332,7 @@ public class Vala.CCodeAttribute : AttributeCache {
return get_ccode_lower_case_name (cl, "value_take_");
} else if (cl.base_class != null) {
return get_ccode_take_value_function (cl.base_class);
- } else if (type_id == "G_TYPE_POINTER" || cl.is_error_base) {
+ } else if (type_id == "G_TYPE_POINTER") {
return "g_value_set_pointer";
} else {
return "g_value_take_boxed";
@@ -1348,6 +1352,8 @@ public class Vala.CCodeAttribute : AttributeCache {
return "g_value_take_int";
}
}
+ } else if (sym is ErrorDomain) {
+ return "g_value_take_boxed";
} else if (sym is Interface) {
foreach (var prereq in ((Interface) sym).get_prerequisites ()) {
var func = get_ccode_take_value_function (prereq.type_symbol);
@@ -1415,6 +1421,8 @@ public class Vala.CCodeAttribute : AttributeCache {
return "g_param_spec_int";
}
}
+ } else if (sym is ErrorDomain) {
+ return "g_param_spec_boxed";
} else if (sym is Struct) {
var type_id = get_ccode_type_id (sym);
if (type_id == "G_TYPE_INT") {
diff --git a/codegen/valagsignalmodule.vala b/codegen/valagsignalmodule.vala
index 4186859cf..7f02b17f1 100644
--- a/codegen/valagsignalmodule.vala
+++ b/codegen/valagsignalmodule.vala
@@ -413,7 +413,7 @@ public class Vala.GSignalModule : GObjectModule {
if (sig.return_type is PointerType || sig.return_type is GenericType) {
csignew.add_argument (new CCodeConstant ("G_TYPE_POINTER"));
} else if (sig.return_type is ErrorType) {
- csignew.add_argument (new CCodeConstant ("G_TYPE_POINTER"));
+ csignew.add_argument (new CCodeConstant ("G_TYPE_ERROR"));
} else if (sig.return_type is ValueType && sig.return_type.nullable) {
csignew.add_argument (new CCodeConstant ("G_TYPE_POINTER"));
} else if (sig.return_type.type_symbol == null) {
@@ -469,7 +469,7 @@ public class Vala.GSignalModule : GObjectModule {
} else if (param.variable_type is PointerType || param.variable_type is GenericType || param.direction != ParameterDirection.IN) {
csignew.add_argument (new CCodeConstant ("G_TYPE_POINTER"));
} else if (param.variable_type is ErrorType) {
- csignew.add_argument (new CCodeConstant ("G_TYPE_POINTER"));
+ csignew.add_argument (new CCodeConstant ("G_TYPE_ERROR"));
} else if (param.variable_type is ValueType && param.variable_type.nullable) {
csignew.add_argument (new CCodeConstant ("G_TYPE_POINTER"));
} else {
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index 2ad38d650..c1f7a1df1 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -1963,6 +1963,9 @@ public class Vala.GTypeModule : GErrorModule {
} else {
cspec.add_argument (new CCodeConstant (get_ccode_default_value (type_symbol)));
}
+ } else if (type_symbol is ErrorDomain) {
+ cspec.call = new CCodeIdentifier ("g_param_spec_boxed");
+ cspec.add_argument (new CCodeIdentifier ("G_TYPE_ERROR"));
} else if (type_symbol is Struct) {
unowned Struct st = (Struct) type_symbol;
var type_id = get_ccode_type_id (st);