]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
girparser: grok "nullable"
authorRyan Lortie <desrt@desrt.ca>
Wed, 16 Apr 2014 14:54:57 +0000 (10:54 -0400)
committerRyan Lortie <desrt@desrt.ca>
Tue, 6 May 2014 17:28:07 +0000 (13:28 -0400)
Understand the new "nullable" attribute in .gir files.

Presently, this is mostly an alias for allow-none='', but it will also
allows a new feature: we can explicitly mark out parameters as having a
nullable type (as a distinct concept from accepting 'NULL' as a
parameter to the C function call in order to ignore the result).

.gir may eventually want to remove allow-none='' some day, so make sure
we also accept nullable='' in all places that we accepted allow-none=''
to mean 'can be NULL'.

https://bugzilla.gnome.org/show_bug.cgi?id=660879

vala/valagirparser.vala

index 961d9a6da29f537edab5abb515204e304d217cff..025384c0a5d0f59d791a9b40d7e89f3a6605ebe5 100644 (file)
@@ -2217,6 +2217,7 @@ public class Vala.GirParser : CodeVisitor {
                start_element ("return-value");
 
                string transfer = reader.get_attribute ("transfer-ownership");
+               string nullable = reader.get_attribute ("nullable");
                string allow_none = reader.get_attribute ("allow-none");
                next ();
 
@@ -2227,7 +2228,7 @@ public class Vala.GirParser : CodeVisitor {
                if (transfer == "full" || transfer == "container") {
                        type.value_owned = true;
                }
-               if (allow_none == "1") {
+               if (nullable == "1" || allow_none == "1") {
                        type.nullable = true;
                }
                type = element_get_type (type, true, ref no_array_length, ref array_null_terminated);
@@ -2260,6 +2261,7 @@ public class Vala.GirParser : CodeVisitor {
                        direction = reader.get_attribute ("direction");
                }
                string transfer = reader.get_attribute ("transfer-ownership");
+               string nullable = reader.get_attribute ("nullable");
                string allow_none = reader.get_attribute ("allow-none");
 
                scope = element_get_string ("scope", ArgumentType.SCOPE);
@@ -2293,7 +2295,7 @@ public class Vala.GirParser : CodeVisitor {
                        if (transfer == "full" || transfer == "container" || destroy != null) {
                                type.value_owned = true;
                        }
-                       if (allow_none == "1" && direction != "out") {
+                       if (nullable == "1" || (allow_none == "1" && direction != "out")) {
                                type.nullable = true;
                        }
 
@@ -2714,6 +2716,7 @@ public class Vala.GirParser : CodeVisitor {
                start_element ("field");
                push_node (element_get_name (), false);
 
+               string nullable = reader.get_attribute ("nullable");
                string allow_none = reader.get_attribute ("allow-none");
                next ();
 
@@ -2739,7 +2742,7 @@ public class Vala.GirParser : CodeVisitor {
                        }
                        field.set_attribute_bool ("CCode", "array_null_terminated", true);
                }
-               if (allow_none == "1") {
+               if (nullable == "1" || allow_none == "1") {
                        type.nullable = true;
                }
                current.symbol = field;