[gobject-introspection] scanner: Don't barf on anonymous unions



commit 6b44b271fb27dc46175b58fbd7e1f36ac0419943
Author: Colin Walters <walters verbum org>
Date:   Wed Oct 30 15:24:06 2013 +0000

    scanner: Don't barf on anonymous unions
    
    I'd like to be able to use this inside GTK+.
    
    See: https://bugzilla.gnome.org/show_bug.cgi?id=711153
    
    https://bugzilla.gnome.org/show_bug.cgi?id=711157

 giscanner/maintransformer.py                       |    1 +
 .../Regress.AnAnonymousUnion.None.page             |   25 ++++++++++++++++++++
 .../Regress.AnAnonymousUnion.page                  |   25 ++++++++++++++++++++
 .../Regress.AnAnonymousUnion.None.page             |   25 ++++++++++++++++++++
 .../Regress.AnAnonymousUnion.page                  |   25 ++++++++++++++++++++
 .../Regress.AnAnonymousUnion.None.page             |   25 ++++++++++++++++++++
 .../Regress.AnAnonymousUnion.page                  |   25 ++++++++++++++++++++
 tests/scanner/Regress-1.0-expected.gir             |   20 ++++++++++++++++
 tests/scanner/regress.h                            |   12 +++++++++
 9 files changed, 183 insertions(+), 0 deletions(-)
---
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index 67cbec8..c107bee 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -107,6 +107,7 @@ class MainTransformer(object):
         if isinstance(node, (ast.Class, ast.Interface, ast.Record, ast.Union)):
             for field in node.fields:
                 if (field
+                and field.name is not None
                 and field.name.startswith('_')
                 and field.anonymous_node is not None
                 and isinstance(field.anonymous_node, ast.Callback)):
diff --git a/tests/scanner/Regress-1.0-C-expected/Regress.AnAnonymousUnion.None.page 
b/tests/scanner/Regress-1.0-C-expected/Regress.AnAnonymousUnion.None.page
new file mode 100644
index 0000000..6dc17b3
--- /dev/null
+++ b/tests/scanner/Regress-1.0-C-expected/Regress.AnAnonymousUnion.None.page
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<page id="Regress.AnAnonymousUnion.None"
+      type="topic"
+      style="default"
+      xmlns="http://projectmallard.org/1.0/";
+      xmlns:api="http://projectmallard.org/experimental/api/";
+      xmlns:ui="http://projectmallard.org/1.0/ui/";>
+  <info>
+    
+      <link xref="index" group="default" type="guide"/>
+    
+  </info>
+  <title>Regress.AnAnonymousUnion.None</title>
+  
+  
+  
+    
+  
+  
+  
+  
+  
+  
+  
+</page>
diff --git a/tests/scanner/Regress-1.0-C-expected/Regress.AnAnonymousUnion.page 
b/tests/scanner/Regress-1.0-C-expected/Regress.AnAnonymousUnion.page
new file mode 100644
index 0000000..f9323c6
--- /dev/null
+++ b/tests/scanner/Regress-1.0-C-expected/Regress.AnAnonymousUnion.page
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<page id="Regress.AnAnonymousUnion"
+      type="topic"
+      style="record"
+      xmlns="http://projectmallard.org/1.0/";
+      xmlns:api="http://projectmallard.org/experimental/api/";
+      xmlns:ui="http://projectmallard.org/1.0/ui/";>
+  <info>
+    
+      <link xref="index" group="record" type="guide"/>
+    
+  </info>
+  <title>Regress.AnAnonymousUnion</title>
+  
+  
+  
+    
+  
+  
+  
+  
+  
+  
+  
+</page>
diff --git a/tests/scanner/Regress-1.0-Gjs-expected/Regress.AnAnonymousUnion.None.page 
b/tests/scanner/Regress-1.0-Gjs-expected/Regress.AnAnonymousUnion.None.page
new file mode 100644
index 0000000..6dc17b3
--- /dev/null
+++ b/tests/scanner/Regress-1.0-Gjs-expected/Regress.AnAnonymousUnion.None.page
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<page id="Regress.AnAnonymousUnion.None"
+      type="topic"
+      style="default"
+      xmlns="http://projectmallard.org/1.0/";
+      xmlns:api="http://projectmallard.org/experimental/api/";
+      xmlns:ui="http://projectmallard.org/1.0/ui/";>
+  <info>
+    
+      <link xref="index" group="default" type="guide"/>
+    
+  </info>
+  <title>Regress.AnAnonymousUnion.None</title>
+  
+  
+  
+    
+  
+  
+  
+  
+  
+  
+  
+</page>
diff --git a/tests/scanner/Regress-1.0-Gjs-expected/Regress.AnAnonymousUnion.page 
b/tests/scanner/Regress-1.0-Gjs-expected/Regress.AnAnonymousUnion.page
new file mode 100644
index 0000000..2556fed
--- /dev/null
+++ b/tests/scanner/Regress-1.0-Gjs-expected/Regress.AnAnonymousUnion.page
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<page id="Regress.AnAnonymousUnion"
+      type="guide"
+      style="record"
+      xmlns="http://projectmallard.org/1.0/";
+      xmlns:api="http://projectmallard.org/experimental/api/";
+      xmlns:ui="http://projectmallard.org/1.0/ui/";>
+  <info>
+    
+      <link xref="index" group="record" type="guide"/>
+    
+  </info>
+  <title>Regress.AnAnonymousUnion</title>
+  
+  
+  
+    
+  
+  
+  
+  
+  
+  
+  
+</page>
diff --git a/tests/scanner/Regress-1.0-Python-expected/Regress.AnAnonymousUnion.None.page 
b/tests/scanner/Regress-1.0-Python-expected/Regress.AnAnonymousUnion.None.page
new file mode 100644
index 0000000..6dc17b3
--- /dev/null
+++ b/tests/scanner/Regress-1.0-Python-expected/Regress.AnAnonymousUnion.None.page
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<page id="Regress.AnAnonymousUnion.None"
+      type="topic"
+      style="default"
+      xmlns="http://projectmallard.org/1.0/";
+      xmlns:api="http://projectmallard.org/experimental/api/";
+      xmlns:ui="http://projectmallard.org/1.0/ui/";>
+  <info>
+    
+      <link xref="index" group="default" type="guide"/>
+    
+  </info>
+  <title>Regress.AnAnonymousUnion.None</title>
+  
+  
+  
+    
+  
+  
+  
+  
+  
+  
+  
+</page>
diff --git a/tests/scanner/Regress-1.0-Python-expected/Regress.AnAnonymousUnion.page 
b/tests/scanner/Regress-1.0-Python-expected/Regress.AnAnonymousUnion.page
new file mode 100644
index 0000000..2556fed
--- /dev/null
+++ b/tests/scanner/Regress-1.0-Python-expected/Regress.AnAnonymousUnion.page
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<page id="Regress.AnAnonymousUnion"
+      type="guide"
+      style="record"
+      xmlns="http://projectmallard.org/1.0/";
+      xmlns:api="http://projectmallard.org/experimental/api/";
+      xmlns:ui="http://projectmallard.org/1.0/ui/";>
+  <info>
+    
+      <link xref="index" group="record" type="guide"/>
+    
+  </info>
+  <title>Regress.AnAnonymousUnion</title>
+  
+  
+  
+    
+  
+  
+  
+  
+  
+  
+  
+</page>
diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir
index a16205b..c6ae224 100644
--- a/tests/scanner/Regress-1.0-expected.gir
+++ b/tests/scanner/Regress-1.0-expected.gir
@@ -68,6 +68,26 @@ and/or use gtk-doc annotations.  -->
       <member name="code2" value="2" c:identifier="REGRESS_ATEST_ERROR_CODE2">
       </member>
     </enumeration>
+    <record name="AnAnonymousUnion" c:type="RegressAnAnonymousUnion">
+      <field name="x" writable="1">
+        <type name="gint" c:type="int"/>
+      </field>
+      <union>
+        <field name="a" writable="1">
+          <array zero-terminated="0"
+                 c:type="RegressLikeGnomeKeyringPasswordSchema"
+                 fixed-size="2">
+            <type name="LikeGnomeKeyringPasswordSchema"
+                  c:type="RegressLikeGnomeKeyringPasswordSchema*"/>
+          </array>
+        </field>
+        <field name="padding" writable="1">
+          <array zero-terminated="0" c:type="guint" fixed-size="4">
+            <type name="guint" c:type="guint"/>
+          </array>
+        </field>
+      </union>
+    </record>
     <bitfield name="AnnotationBitfield" c:type="RegressAnnotationBitfield">
       <member name="foo" value="1" c:identifier="ANN_FLAG_FOO">
       </member>
diff --git a/tests/scanner/regress.h b/tests/scanner/regress.h
index 9c85884..079c6fe 100644
--- a/tests/scanner/regress.h
+++ b/tests/scanner/regress.h
@@ -962,4 +962,16 @@ typedef struct {
 #endif
 #endif
 
+/* This struct is one pattern by which padding can be consumed, if
+ * you're willing to take a hard dependency on anonymous unions. */
+typedef struct {
+  int x;
+
+  union {
+    RegressLikeGnomeKeyringPasswordSchema *a[2];
+
+    guint padding[4];
+  };
+} RegressAnAnonymousUnion;
+
 #endif /* __GITESTTYPES_H__ */


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