summaryrefslogtreecommitdiff
path: root/src/libical-glib
diff options
context:
space:
mode:
authorCorentin Noël <corentin@elementary.io>2021-11-11 17:01:37 +0100
committerAllen Winter <allen.winter@kdab.com>2021-11-20 17:18:04 -0500
commitf67777be914326d37abf537df707f57a926c1543 (patch)
tree60e1a3d8ee25f79a51cbaa7cab1f0449669ee011 /src/libical-glib
parent4af3a94ff10b4877df2897e91ebfbdd7106a8204 (diff)
downloadlibical-git-f67777be914326d37abf537df707f57a926c1543.tar.gz
generator.c - Handle the optional parameter
Do not return if the value is null for optional parameters as it is explicitly allowed.
Diffstat (limited to 'src/libical-glib')
-rw-r--r--src/libical-glib/tools/generator.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/libical-glib/tools/generator.c b/src/libical-glib/tools/generator.c
index b05c2153..f00d6ec8 100644
--- a/src/libical-glib/tools/generator.c
+++ b/src/libical-glib/tools/generator.c
@@ -1597,6 +1597,20 @@ gchar *get_translator_for_return(Ret *ret)
return res;
}
+static gboolean parameter_is_out(Parameter *para)
+{
+ GList *link;
+ for (link = para->annotations; link; link = g_list_next(link)) {
+ if (g_strcmp0(link->data, "out") == 0 ||
+ g_strcmp0(link->data, "inout") == 0 ||
+ g_str_has_prefix(link->data, "out ")) {
+ break;
+ }
+ }
+
+ return link != NULL;
+}
+
static gboolean annotation_contains_nullable(GList *annotations) /* gchar * */
{
GList *link;
@@ -1611,6 +1625,19 @@ static gboolean annotation_contains_nullable(GList *annotations) /* gchar * */
return link != NULL;
}
+static gboolean annotation_contains_optional(GList *annotations) /* gchar * */
+{
+ GList *link;
+
+ for (link = annotations; link; link = g_list_next(link)) {
+ if (g_strcmp0(link->data, "optional") == 0) {
+ break;
+ }
+ }
+
+ return link != NULL;
+}
+
gchar *get_inline_parameter(Parameter *para)
{
gchar *buffer;
@@ -2055,6 +2082,7 @@ gchar *get_source_run_time_checkers(Method *method, const gchar *namespace)
gchar *defaultValue;
gchar *retTrueType;
guint namespace_len;
+ gboolean param_is_out;
g_return_val_if_fail(method != NULL, NULL);
g_return_val_if_fail(namespace != NULL && *namespace != '\0', NULL);
@@ -2117,7 +2145,10 @@ gchar *get_source_run_time_checkers(Method *method, const gchar *namespace)
(void)g_stpcpy(buffer + strlen(buffer), "\n");
}
- if (i != namespace_len && !annotation_contains_nullable(parameter->annotations)) {
+ param_is_out = parameter_is_out(parameter);
+ if (i != namespace_len && (
+ (!param_is_out && !annotation_contains_nullable(parameter->annotations)) ||
+ (param_is_out && !annotation_contains_optional(parameter->annotations)))) {
(void)g_stpcpy(buffer + strlen(buffer), "\t");
if (method->ret != NULL) {
(void)g_stpcpy(buffer + strlen(buffer), "g_return_val_if_fail (");