[gobject-introspection: 1/4] Use uint8 as default element type when constructing ByteArray.



commit c6646852cd8638d1363ca915bfc2862b4666e067
Author: Tomasz Miąsko <tomasz miasko gmail com>
Date:   Sun Apr 15 00:00:00 2018 +0000

    Use uint8 as default element type when constructing ByteArray.
    
    Fixes issue #184.

 giscanner/ast.py             |  4 +++-
 giscanner/maintransformer.py | 13 +++++--------
 giscanner/transformer.py     |  9 ++++++---
 3 files changed, 14 insertions(+), 12 deletions(-)
---
diff --git a/giscanner/ast.py b/giscanner/ast.py
index 2dff8bd0..44ce523c 100644
--- a/giscanner/ast.py
+++ b/giscanner/ast.py
@@ -109,7 +109,9 @@ in contrast to the other create_type() functions."""
                        ctype=fundamental.ctype)
         if gtype_name == 'GHashTable':
             return Map(TYPE_ANY, TYPE_ANY, gtype_name=gtype_name)
-        elif gtype_name in ('GArray', 'GPtrArray', 'GByteArray'):
+        elif gtype_name == 'GByteArray':
+            return Array('GLib.ByteArray', TYPE_UINT8, gtype_name=gtype_name)
+        elif gtype_name in ('GArray', 'GPtrArray'):
             return Array('GLib.' + gtype_name[1:], TYPE_ANY,
                          gtype_name=gtype_name)
         elif gtype_name == 'GStrv':
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index e5e77338..4f6db545 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -361,14 +361,11 @@ class MainTransformer(object):
                 message.warn("invalid (element-type) for a GPtrArray, "
                              "must be a pointer", annotations.position)
 
-        # GByteArrays have (element-type) guint8 by default
-        if array_type == ast.Array.GLIB_BYTEARRAY:
-            if element_type == ast.TYPE_ANY:
-                array.element_type = ast.TYPE_UINT8
-            elif element_type not in [ast.TYPE_UINT8, ast.TYPE_INT8, ast.TYPE_CHAR]:
-                message.warn("invalid (element-type) for a GByteArray, "
-                             "must be one of guint8, gint8 or gchar",
-                             annotations.position)
+        if (array_type == ast.Array.GLIB_BYTEARRAY
+        and element_type not in [ast.TYPE_UINT8, ast.TYPE_INT8, ast.TYPE_CHAR]):
+            message.warn("invalid (element-type) for a GByteArray, "
+                         "must be one of guint8, gint8 or gchar",
+                         annotations.position)
 
     def _apply_annotations_array(self, parent, node, annotations):
         element_type_options = annotations.get(ANN_ELEMENT_TYPE)
diff --git a/giscanner/transformer.py b/giscanner/transformer.py
index 50018cd2..000a4a44 100644
--- a/giscanner/transformer.py
+++ b/giscanner/transformer.py
@@ -669,9 +669,12 @@ raise ValueError."""
                 name = base
             return ast.List(name, ast.TYPE_ANY, ctype=ctype,
                         is_const=is_const, complete_ctype=complete_ctype)
-        elif base in ('GArray', 'GPtrArray', 'GByteArray',
-                      'GLib.Array', 'GLib.PtrArray', 'GLib.ByteArray',
-                      'GObject.Array', 'GObject.PtrArray', 'GObject.ByteArray'):
+        elif base in ('GByteArray', 'GLib.ByteArray', 'GObject.ByteArray'):
+            return ast.Array('GLib.ByteArray', ast.TYPE_UINT8, ctype=ctype,
+                         is_const=is_const, complete_ctype=complete_ctype)
+        elif base in ('GArray', 'GPtrArray',
+                      'GLib.Array', 'GLib.PtrArray',
+                      'GObject.Array', 'GObject.PtrArray'):
             if '.' in base:
                 name = 'GLib.' + base.split('.', 1)[1]
             else:


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