[vala] girparser: grok "nullable"



commit e935d4b50c402511a9ebf4bee6b3d5e67a981a43
Author: Ryan Lortie <desrt desrt ca>
Date:   Wed Apr 16 10:54:57 2014 -0400

    girparser: grok "nullable"
    
    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 |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
---
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 961d9a6..025384c 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -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;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]