[pygobject] marshal refactoring: Move GIArgument from GValue code to new file



commit b8120d848dc5d36832123b1a913015f6e1fd8cdc
Author: Simon Feltman <sfeltman src gnome org>
Date:   Sun Jan 12 11:41:20 2014 -0800

    marshal refactoring: Move GIArgument from GValue code to new file
    
    Add gi/pygi-value.h and .c files with initial contents of
    _pygi_argument_from_g_value. Eventually this file will contain all code
    related to GValue marshaling from various code locations in the project.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=709700

 gi/Makefile.am           |    2 +
 gi/pygi-argument.c       |  126 +----------------------------------------
 gi/pygi-argument.h       |    3 -
 gi/pygi-signal-closure.c |    1 +
 gi/pygi-value.c          |  144 ++++++++++++++++++++++++++++++++++++++++++++++
 gi/pygi-value.h          |   32 ++++++++++
 6 files changed, 180 insertions(+), 128 deletions(-)
---
diff --git a/gi/Makefile.am b/gi/Makefile.am
index 2a2473d..b00d30a 100644
--- a/gi/Makefile.am
+++ b/gi/Makefile.am
@@ -109,6 +109,8 @@ _gi_la_SOURCES = \
        pygi-error.h \
        pygi-object.c \
        pygi-object.h \
+       pygi-value.c \
+       pygi-value.h \
        pygi-enum-marshal.c \
        pygi-enum-marshal.h \
        pygi-struct-marshal.c \
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index 5da8398..63149b0 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -31,6 +31,7 @@
 #include <pyglib-python-compat.h>
 #include <pyglib.h>
 
+#include "pygi-value.h"
 #include "pygi-basictype.h"
 #include "pygi-object.h"
 #include "pygi-struct-marshal.h"
@@ -1588,131 +1589,6 @@ _pygi_argument_to_object (GIArgument  *arg,
     return object;
 }
 
-
-GIArgument
-_pygi_argument_from_g_value(const GValue *value,
-                            GITypeInfo *type_info)
-{
-    GIArgument arg = { 0, };
-
-    GITypeTag type_tag = g_type_info_get_tag (type_info);
-
-    /* For the long handling: long can be equivalent to
-       int32 or int64, depending on the architecture, but
-       gi doesn't tell us (and same for ulong)
-    */
-    switch (type_tag) {
-        case GI_TYPE_TAG_BOOLEAN:
-            arg.v_boolean = g_value_get_boolean (value);
-            break;
-        case GI_TYPE_TAG_INT8:
-        case GI_TYPE_TAG_INT16:
-        case GI_TYPE_TAG_INT32:
-           if (g_type_is_a (G_VALUE_TYPE (value), G_TYPE_LONG))
-               arg.v_int = g_value_get_long (value);
-           else
-               arg.v_int = g_value_get_int (value);
-            break;
-        case GI_TYPE_TAG_INT64:
-           if (g_type_is_a (G_VALUE_TYPE (value), G_TYPE_LONG))
-               arg.v_int64 = g_value_get_long (value);
-           else
-               arg.v_int64 = g_value_get_int64 (value);
-            break;
-        case GI_TYPE_TAG_UINT8:
-        case GI_TYPE_TAG_UINT16:
-        case GI_TYPE_TAG_UINT32:
-           if (g_type_is_a (G_VALUE_TYPE (value), G_TYPE_ULONG))
-               arg.v_uint = g_value_get_ulong (value);
-           else
-               arg.v_uint = g_value_get_uint (value);
-            break;
-        case GI_TYPE_TAG_UINT64:
-           if (g_type_is_a (G_VALUE_TYPE (value), G_TYPE_ULONG))
-               arg.v_uint64 = g_value_get_ulong (value);
-           else
-               arg.v_uint64 = g_value_get_uint64 (value);
-            break;
-        case GI_TYPE_TAG_UNICHAR:
-            arg.v_uint32 = g_value_get_schar (value);
-            break;
-        case GI_TYPE_TAG_FLOAT:
-            arg.v_float = g_value_get_float (value);
-            break;
-        case GI_TYPE_TAG_DOUBLE:
-            arg.v_double = g_value_get_double (value);
-            break;
-        case GI_TYPE_TAG_GTYPE:
-            arg.v_long = g_value_get_gtype (value);
-            break;
-        case GI_TYPE_TAG_UTF8:
-        case GI_TYPE_TAG_FILENAME:
-            arg.v_string = g_value_dup_string (value);
-            break;
-        case GI_TYPE_TAG_GLIST:
-        case GI_TYPE_TAG_GSLIST:
-            arg.v_pointer = g_value_get_pointer (value);
-            break;
-        case GI_TYPE_TAG_ARRAY:
-        case GI_TYPE_TAG_GHASH:
-            if (G_VALUE_HOLDS_BOXED (value))
-                arg.v_pointer = g_value_get_boxed (value);
-            else
-                /* e. g. GSettings::change-event */
-                arg.v_pointer = g_value_get_pointer (value);
-            break;
-        case GI_TYPE_TAG_INTERFACE:
-        {
-            GIBaseInfo *info;
-            GIInfoType info_type;
-
-            info = g_type_info_get_interface (type_info);
-            info_type = g_base_info_get_type (info);
-
-            g_base_info_unref (info);
-
-            switch (info_type) {
-                case GI_INFO_TYPE_FLAGS:
-                    arg.v_uint = g_value_get_flags (value);
-                    break;
-                case GI_INFO_TYPE_ENUM:
-                    arg.v_int = g_value_get_enum (value);
-                    break;
-                case GI_INFO_TYPE_INTERFACE:
-                case GI_INFO_TYPE_OBJECT:
-                    if (G_VALUE_HOLDS_PARAM (value))
-                      arg.v_pointer = g_value_get_param (value);
-                    else
-                      arg.v_pointer = g_value_get_object (value);
-                    break;
-                case GI_INFO_TYPE_BOXED:
-                case GI_INFO_TYPE_STRUCT:
-                case GI_INFO_TYPE_UNION:
-                    if (G_VALUE_HOLDS(value, G_TYPE_BOXED)) {
-                        arg.v_pointer = g_value_get_boxed (value);
-                    } else if (G_VALUE_HOLDS(value, G_TYPE_VARIANT)) {
-                        arg.v_pointer = g_value_get_variant (value);
-                    } else {
-                        arg.v_pointer = g_value_get_pointer (value);
-                    }
-                    break;
-                default:
-                    g_warning("Converting of type '%s' is not implemented", 
g_info_type_to_string(info_type));
-                    g_assert_not_reached();
-            }
-            break;
-        }
-        case GI_TYPE_TAG_ERROR:
-            arg.v_pointer = g_value_get_boxed (value);
-            break;
-        case GI_TYPE_TAG_VOID:
-            arg.v_pointer = g_value_get_pointer (value);
-            break;
-    }
-
-    return arg;
-}
-
 void
 _pygi_argument_release (GIArgument   *arg,
                         GITypeInfo  *type_info,
diff --git a/gi/pygi-argument.h b/gi/pygi-argument.h
index ed88214..d32bd99 100644
--- a/gi/pygi-argument.h
+++ b/gi/pygi-argument.h
@@ -63,9 +63,6 @@ PyObject* _pygi_argument_to_object (GIArgument  *arg,
                                     GITypeInfo *type_info,
                                     GITransfer  transfer);
 
-GIArgument _pygi_argument_from_g_value(const GValue *value,
-                                       GITypeInfo *type_info);
-
 void _pygi_argument_release (GIArgument   *arg,
                              GITypeInfo  *type_info,
                              GITransfer   transfer,
diff --git a/gi/pygi-signal-closure.c b/gi/pygi-signal-closure.c
index bcd1320..60f6657 100644
--- a/gi/pygi-signal-closure.c
+++ b/gi/pygi-signal-closure.c
@@ -19,6 +19,7 @@
  */
 
 #include "pygi-private.h"
+#include "pygi-value.h"
 
 static GISignalInfo *
 _pygi_lookup_signal_from_g_type (GType g_type,
diff --git a/gi/pygi-value.c b/gi/pygi-value.c
new file mode 100644
index 0000000..6ac12cf
--- /dev/null
+++ b/gi/pygi-value.c
@@ -0,0 +1,144 @@
+
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * vim: tabstop=4 shiftwidth=4 expandtab
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "pygi-value.h"
+
+
+GIArgument
+_pygi_argument_from_g_value(const GValue *value,
+                            GITypeInfo *type_info)
+{
+    GIArgument arg = { 0, };
+
+    GITypeTag type_tag = g_type_info_get_tag (type_info);
+
+    /* For the long handling: long can be equivalent to
+       int32 or int64, depending on the architecture, but
+       gi doesn't tell us (and same for ulong)
+    */
+    switch (type_tag) {
+        case GI_TYPE_TAG_BOOLEAN:
+            arg.v_boolean = g_value_get_boolean (value);
+            break;
+        case GI_TYPE_TAG_INT8:
+        case GI_TYPE_TAG_INT16:
+        case GI_TYPE_TAG_INT32:
+           if (g_type_is_a (G_VALUE_TYPE (value), G_TYPE_LONG))
+               arg.v_int = g_value_get_long (value);
+           else
+               arg.v_int = g_value_get_int (value);
+            break;
+        case GI_TYPE_TAG_INT64:
+           if (g_type_is_a (G_VALUE_TYPE (value), G_TYPE_LONG))
+               arg.v_int64 = g_value_get_long (value);
+           else
+               arg.v_int64 = g_value_get_int64 (value);
+            break;
+        case GI_TYPE_TAG_UINT8:
+        case GI_TYPE_TAG_UINT16:
+        case GI_TYPE_TAG_UINT32:
+           if (g_type_is_a (G_VALUE_TYPE (value), G_TYPE_ULONG))
+               arg.v_uint = g_value_get_ulong (value);
+           else
+               arg.v_uint = g_value_get_uint (value);
+            break;
+        case GI_TYPE_TAG_UINT64:
+           if (g_type_is_a (G_VALUE_TYPE (value), G_TYPE_ULONG))
+               arg.v_uint64 = g_value_get_ulong (value);
+           else
+               arg.v_uint64 = g_value_get_uint64 (value);
+            break;
+        case GI_TYPE_TAG_UNICHAR:
+            arg.v_uint32 = g_value_get_schar (value);
+            break;
+        case GI_TYPE_TAG_FLOAT:
+            arg.v_float = g_value_get_float (value);
+            break;
+        case GI_TYPE_TAG_DOUBLE:
+            arg.v_double = g_value_get_double (value);
+            break;
+        case GI_TYPE_TAG_GTYPE:
+            arg.v_long = g_value_get_gtype (value);
+            break;
+        case GI_TYPE_TAG_UTF8:
+        case GI_TYPE_TAG_FILENAME:
+            arg.v_string = g_value_dup_string (value);
+            break;
+        case GI_TYPE_TAG_GLIST:
+        case GI_TYPE_TAG_GSLIST:
+            arg.v_pointer = g_value_get_pointer (value);
+            break;
+        case GI_TYPE_TAG_ARRAY:
+        case GI_TYPE_TAG_GHASH:
+            if (G_VALUE_HOLDS_BOXED (value))
+                arg.v_pointer = g_value_get_boxed (value);
+            else
+                /* e. g. GSettings::change-event */
+                arg.v_pointer = g_value_get_pointer (value);
+            break;
+        case GI_TYPE_TAG_INTERFACE:
+        {
+            GIBaseInfo *info;
+            GIInfoType info_type;
+
+            info = g_type_info_get_interface (type_info);
+            info_type = g_base_info_get_type (info);
+
+            g_base_info_unref (info);
+
+            switch (info_type) {
+                case GI_INFO_TYPE_FLAGS:
+                    arg.v_uint = g_value_get_flags (value);
+                    break;
+                case GI_INFO_TYPE_ENUM:
+                    arg.v_int = g_value_get_enum (value);
+                    break;
+                case GI_INFO_TYPE_INTERFACE:
+                case GI_INFO_TYPE_OBJECT:
+                    if (G_VALUE_HOLDS_PARAM (value))
+                      arg.v_pointer = g_value_get_param (value);
+                    else
+                      arg.v_pointer = g_value_get_object (value);
+                    break;
+                case GI_INFO_TYPE_BOXED:
+                case GI_INFO_TYPE_STRUCT:
+                case GI_INFO_TYPE_UNION:
+                    if (G_VALUE_HOLDS(value, G_TYPE_BOXED)) {
+                        arg.v_pointer = g_value_get_boxed (value);
+                    } else if (G_VALUE_HOLDS(value, G_TYPE_VARIANT)) {
+                        arg.v_pointer = g_value_get_variant (value);
+                    } else {
+                        arg.v_pointer = g_value_get_pointer (value);
+                    }
+                    break;
+                default:
+                    g_warning("Converting of type '%s' is not implemented", 
g_info_type_to_string(info_type));
+                    g_assert_not_reached();
+            }
+            break;
+        }
+        case GI_TYPE_TAG_ERROR:
+            arg.v_pointer = g_value_get_boxed (value);
+            break;
+        case GI_TYPE_TAG_VOID:
+            arg.v_pointer = g_value_get_pointer (value);
+            break;
+    }
+
+    return arg;
+}
diff --git a/gi/pygi-value.h b/gi/pygi-value.h
new file mode 100644
index 0000000..3e8d46a
--- /dev/null
+++ b/gi/pygi-value.h
@@ -0,0 +1,32 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * vim: tabstop=4 shiftwidth=4 expandtab
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __PYGI_VALUE_H__
+#define __PYGI_VALUE_H__
+
+#include <glib-object.h>
+#include <girepository.h>
+
+G_BEGIN_DECLS
+
+GIArgument _pygi_argument_from_g_value(const GValue *value,
+                                       GITypeInfo *type_info);
+
+
+G_END_DECLS
+
+#endif /* __PYGI_VALUE_H__ */


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