[vala/wip/error-gtype: 3/5] codegen: Emit GType definition for error domains




commit da4ff03c5ca427cf7cc4574f52f5190dc1b0dfb9
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sat Nov 17 22:22:03 2018 +0100

    codegen: Emit GType definition for error domains
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/699

 codegen/Makefile.am                                |  1 +
 codegen/valaccode.vala                             |  2 +-
 codegen/valaccodeattribute.vala                    | 13 ++++--
 codegen/valaerrordomainregisterfunction.vala       | 51 ++++++++++++++++++++++
 codegen/valagerrormodule.vala                      | 25 +++++++++++
 codegen/valagirwriter.vala                         |  6 ++-
 codegen/valagtypemodule.vala                       | 12 +++++
 codegen/valatyperegisterfunction.vala              | 30 +++++++++++++
 tests/asynchronous/bug793158.c-expected            | 25 +++++++++++
 tests/asynchronous/catch-error-scope.c-expected    | 26 ++++++++++-
 tests/asynchronous/catch-in-finally.c-expected     | 26 ++++++++++-
 .../out-parameter-free-on-error.c-expected         | 25 +++++++++++
 tests/basic-types/default-gtype.c-expected         | 25 +++++++++++
 tests/control-flow/bug764440.c-expected            | 25 +++++++++++
 tests/control-flow/lock-if-throw.c-expected        | 25 +++++++++++
 tests/dbus/errors_client.c-expected                |  4 ++
 tests/dbus/errors_server.c-expected                |  4 ++
 tests/delegates/error-pos.c-expected               | 26 ++++++++++-
 .../delegates/params-array-with-throws.c-expected  | 24 ++++++++++
 tests/delegates/variadic.c-expected                | 25 +++++++++++
 tests/errors/bug567181.c-expected                  | 25 +++++++++++
 tests/errors/bug579101.c-expected                  | 24 ++++++++++
 tests/errors/bug623049.c-expected                  | 25 +++++++++++
 tests/errors/bug778224.c-expected                  | 25 +++++++++++
 tests/errors/catch-error-code.c-expected           | 25 +++++++++++
 tests/errors/catch-in-finally.c-expected           | 24 ++++++++++
 tests/errors/default-gtype.c-expected              | 23 ++++++++++
 tests/errors/delegate-throws-error-code.c-expected | 24 ++++++++++
 tests/errors/errorcode.c-expected                  | 24 ++++++++++
 tests/errors/errordomain-static-method.c-expected  | 24 ++++++++++
 tests/errors/errordomain.c-expected                | 25 +++++++++++
 tests/errors/errors.c-expected                     | 25 +++++++++++
 tests/errors/loops.c-expected                      | 24 ++++++++++
 tests/errors/method-throws-error-code.c-expected   | 25 +++++++++++
 tests/errors/unhandled.c-expected                  | 25 +++++++++++
 tests/genie/exception.c-expected                   | 24 ++++++++++
 tests/girwriter/GirTest-1.0.gir-expected           |  9 +++-
 tests/girwriter/girtest.vala                       |  7 +++
 tests/girwriter/girtest.vapi-expected              |  6 +++
 tests/girwriter/girtest.vapigen-expected           | 10 ++++-
 tests/methods/bug781061.c-expected                 | 25 +++++++++++
 .../methods/parameter-out-free-on-error.c-expected | 25 +++++++++++
 tests/methods/params-array-with-throws.c-expected  | 27 +++++++++++-
 tests/methods/print-attribute.c-expected           | 25 +++++++++++
 tests/objects/signals-error-marshal.c-expected     | 25 +++++++++++
 vala/valaerrorcode.vala                            | 16 +++++++
 46 files changed, 953 insertions(+), 13 deletions(-)
---
diff --git a/codegen/Makefile.am b/codegen/Makefile.am
index c7fc91341..b786e66ec 100644
--- a/codegen/Makefile.am
+++ b/codegen/Makefile.am
@@ -40,6 +40,7 @@ libvalaccodegen_la_VALASOURCES = \
        valaclassregisterfunction.vala \
        valactype.vala \
        valaenumregisterfunction.vala \
+       valaerrordomainregisterfunction.vala \
        valagasyncmodule.vala \
        valagdbusclientmodule.vala \
        valagdbusmodule.vala \
diff --git a/codegen/valaccode.vala b/codegen/valaccode.vala
index 80e0f1c0f..25a0d11af 100644
--- a/codegen/valaccode.vala
+++ b/codegen/valaccode.vala
@@ -237,7 +237,7 @@ namespace Vala {
        }
 
        public static string get_ccode_type_function (TypeSymbol sym) {
-               assert (!((sym is Class && ((Class) sym).is_compact) || sym is ErrorCode || sym is 
ErrorDomain || sym is Delegate));
+               assert (!((sym is Class && ((Class) sym).is_compact) || sym is ErrorCode || sym is Delegate));
                return "%s_get_type".printf (get_ccode_lower_case_name (sym));
        }
 
diff --git a/codegen/valaccodeattribute.vala b/codegen/valaccodeattribute.vala
index bd4c6b29d..3c3b18ef4 100644
--- a/codegen/valaccodeattribute.vala
+++ b/codegen/valaccodeattribute.vala
@@ -1073,6 +1073,13 @@ public class Vala.CCodeAttribute : AttributeCache {
                                } else {
                                        return en.is_flags ? "G_TYPE_UINT" : "G_TYPE_INT";
                                }
+                       } else if (sym is ErrorDomain) {
+                               unowned ErrorDomain edomain = (ErrorDomain) sym;
+                               if (get_ccode_has_type_id (edomain)) {
+                                       return get_ccode_upper_case_name (edomain, "TYPE_");
+                               } else {
+                                       return "G_TYPE_ERROR";
+                               }
                        } else {
                                return "G_TYPE_POINTER";
                        }
@@ -1199,7 +1206,7 @@ public class Vala.CCodeAttribute : AttributeCache {
                                return get_ccode_lower_case_name (cl, "value_get_");
                        } else if (cl.base_class != null) {
                                return get_ccode_get_value_function (cl.base_class);
-                       } else if (type_id == "G_TYPE_POINTER") {
+                       } else if (type_id == "G_TYPE_POINTER" || cl.is_error_base) {
                                return "g_value_get_pointer";
                        } else {
                                return "g_value_get_boxed";
@@ -1257,7 +1264,7 @@ public class Vala.CCodeAttribute : AttributeCache {
                                return get_ccode_lower_case_name (cl, "value_set_");
                        } else if (cl.base_class != null) {
                                return get_ccode_set_value_function (cl.base_class);
-                       } else if (type_id == "G_TYPE_POINTER") {
+                       } else if (type_id == "G_TYPE_POINTER" || cl.is_error_base) {
                                return "g_value_set_pointer";
                        } else {
                                return "g_value_set_boxed";
@@ -1315,7 +1322,7 @@ public class Vala.CCodeAttribute : AttributeCache {
                                return get_ccode_lower_case_name (cl, "value_take_");
                        } else if (cl.base_class != null) {
                                return get_ccode_take_value_function (cl.base_class);
-                       } else if (type_id == "G_TYPE_POINTER") {
+                       } else if (type_id == "G_TYPE_POINTER" || cl.is_error_base) {
                                return "g_value_set_pointer";
                        } else {
                                return "g_value_take_boxed";
diff --git a/codegen/valaerrordomainregisterfunction.vala b/codegen/valaerrordomainregisterfunction.vala
new file mode 100644
index 000000000..b4be3295e
--- /dev/null
+++ b/codegen/valaerrordomainregisterfunction.vala
@@ -0,0 +1,51 @@
+/* valaerrordomainregisterfunction.vala
+ *
+ * Copyright (C) 2018  Rico Tzschichholz
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Rico Tzschichholz <ricotz ubuntu com>
+ */
+
+using GLib;
+
+/**
+ * C function to register an error domain at runtime.
+ */
+public class Vala.ErrorDomainRegisterFunction : TypeRegisterFunction {
+       /**
+        * Specifies the error domain to be registered.
+        */
+       public weak ErrorDomain error_domain_reference { get; set; }
+
+       /**
+        * Creates a new C function to register the specified error domain at runtime.
+        *
+        * @param edomain an error domain
+        * @return        newly created error domain register function
+        */
+       public ErrorDomainRegisterFunction (ErrorDomain edomain) {
+               error_domain_reference = edomain;
+       }
+
+       public override TypeSymbol get_type_declaration () {
+               return error_domain_reference;
+       }
+
+       public override SymbolAccessibility get_accessibility () {
+               return error_domain_reference.access;
+       }
+}
diff --git a/codegen/valagerrormodule.vala b/codegen/valagerrormodule.vala
index a559a4d00..2b4c6cf85 100644
--- a/codegen/valagerrormodule.vala
+++ b/codegen/valagerrormodule.vala
@@ -56,6 +56,31 @@ public class Vala.GErrorModule : CCodeDelegateModule {
                requires_vala_extern = true;
 
                decl_space.add_function_declaration (cquark_fun);
+               decl_space.add_type_definition (new CCodeNewline ());
+
+               if (!get_ccode_has_type_id (edomain)) {
+                       return;
+               }
+
+               decl_space.add_include ("glib-object.h");
+               decl_space.add_type_declaration (new CCodeNewline ());
+
+               var fun_name = get_ccode_type_function (edomain);
+
+               var macro = "(%s ())".printf (fun_name);
+               decl_space.add_type_declaration (new CCodeMacroReplacement (get_ccode_type_id (edomain), 
macro));
+
+               var regfun = new CCodeFunction (fun_name, "GType");
+               regfun.modifiers = CCodeModifiers.CONST;
+
+               if (edomain.is_private_symbol ()) {
+                       // avoid C warning as this function is not always used
+                       regfun.modifiers |= CCodeModifiers.STATIC | CCodeModifiers.UNUSED;
+               } else if (context.hide_internal && edomain.is_internal_symbol ()) {
+                       regfun.modifiers |= CCodeModifiers.INTERNAL;
+               }
+
+               decl_space.add_function_declaration (regfun);
        }
 
        public override void visit_error_domain (ErrorDomain edomain) {
diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala
index 696c6c8a6..115d4ff98 100644
--- a/codegen/valagirwriter.vala
+++ b/codegen/valagirwriter.vala
@@ -932,7 +932,11 @@ public class Vala.GIRWriter : CodeVisitor {
 
                write_indent ();
                buffer.append_printf ("<enumeration name=\"%s\"", get_gir_name (edomain));
-               write_ctype_attributes (edomain);
+               if (get_ccode_has_type_id (edomain)) {
+                       write_gtype_attributes (edomain);
+               } else {
+                       write_ctype_attributes (edomain);
+               }
                buffer.append_printf (" glib:error-domain=\"%s\"", get_ccode_quark_name (edomain));
                write_symbol_attributes (edomain);
                buffer.append_printf (">\n");
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index 28a29744c..7bc8eaf83 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -2408,6 +2408,18 @@ public class Vala.GTypeModule : GErrorModule {
                }
        }
 
+       public override void visit_error_domain (ErrorDomain edomain) {
+               base.visit_error_domain (edomain);
+
+               if (get_ccode_has_type_id (edomain)) {
+                       push_line (edomain.source_reference);
+                       var type_fun = new ErrorDomainRegisterFunction (edomain);
+                       type_fun.init_from_type (context, false, false);
+                       cfile.add_type_member_definition (type_fun.get_definition ());
+                       pop_line ();
+               }
+       }
+
        public override void visit_method_call (MethodCall expr) {
                var ma = expr.call as MemberAccess;
                var mtype = expr.call.value_type as MethodType;
diff --git a/codegen/valatyperegisterfunction.vala b/codegen/valatyperegisterfunction.vala
index a3236b94c..7502294cb 100644
--- a/codegen/valatyperegisterfunction.vala
+++ b/codegen/valatyperegisterfunction.vala
@@ -155,6 +155,8 @@ public abstract class Vala.TypeRegisterFunction {
                        } else {
                                reg_call = new CCodeFunctionCall (new CCodeIdentifier 
("g_enum_register_static"));
                        }
+               } else if (type_symbol is ErrorDomain) {
+                       reg_call = new CCodeFunctionCall (new CCodeIdentifier ("g_enum_register_static"));
                } else if (fundamental) {
                        reg_call = new CCodeFunctionCall (new CCodeIdentifier 
("g_type_register_fundamental"));
                        reg_call.add_argument (new CCodeFunctionCall (new CCodeIdentifier 
("g_type_fundamental_next")));
@@ -203,6 +205,34 @@ public abstract class Vala.TypeRegisterFunction {
 
                        type_init.add_statement (cdecl);
 
+                       reg_call.add_argument (new CCodeIdentifier ("values"));
+               } else if (type_symbol is ErrorDomain) {
+                       unowned ErrorDomain edomain = (ErrorDomain) type_symbol;
+                       var clist = new CCodeInitializerList (); /* or during visit time? */
+
+                       CCodeInitializerList clist_ec = null;
+                       foreach (ErrorCode ec in edomain.get_codes ()) {
+                               clist_ec = new CCodeInitializerList ();
+                               clist_ec.append (new CCodeConstant (get_ccode_name (ec)));
+                               clist_ec.append (new CCodeConstant ("\"%s\"".printf (get_ccode_name (ec))));
+                               clist_ec.append (new CCodeConstant ("\"%s\"".printf (ec.nick)));
+                               clist.append (clist_ec);
+                       }
+
+                       clist_ec = new CCodeInitializerList ();
+                       clist_ec.append (new CCodeConstant ("0"));
+                       clist_ec.append (new CCodeConstant ("NULL"));
+                       clist_ec.append (new CCodeConstant ("NULL"));
+                       clist.append (clist_ec);
+
+                       var edomain_decl = new CCodeVariableDeclarator ("values[]", clist);
+
+                       cdecl = new CCodeDeclaration ("const GEnumValue");
+                       cdecl.add_declarator (edomain_decl);
+                       cdecl.modifiers = CCodeModifiers.STATIC;
+
+                       type_init.add_statement (cdecl);
+
                        reg_call.add_argument (new CCodeIdentifier ("values"));
                } else {
                        reg_call.add_argument (new CCodeIdentifier ("&g_define_type_info"));
diff --git a/tests/asynchronous/bug793158.c-expected b/tests/asynchronous/bug793158.c-expected
index 218575392..8ad749607 100644
--- a/tests/asynchronous/bug793158.c-expected
+++ b/tests/asynchronous/bug793158.c-expected
@@ -15,6 +15,8 @@
 #endif
 #endif
 
+#define TYPE_FOO_ERROR (foo_error_get_type ())
+
 #define TYPE_FOO (foo_get_type ())
 #define FOO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FOO, Foo))
 #define FOO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FOO, FooClass))
@@ -38,6 +40,7 @@ typedef enum  {
        FOO_ERROR_BAR
 } FooError;
 #define FOO_ERROR foo_error_quark ()
+
 struct _Foo {
        GObject parent_instance;
        FooPrivate * priv;
@@ -61,6 +64,7 @@ VALA_EXTERN GMainLoop* loop;
 GMainLoop* loop = NULL;
 
 VALA_EXTERN GQuark foo_error_quark (void);
+GType foo_error_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN GType foo_get_type (void) G_GNUC_CONST ;
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (Foo, g_object_unref)
 static void foo_bar_data_free (gpointer _data);
@@ -87,6 +91,27 @@ foo_error_quark (void)
        return g_quark_from_static_string ("foo-error-quark");
 }
 
+static GType
+foo_error_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_ERROR_BAR, "FOO_ERROR_BAR", "bar"}, {0, NULL, NULL}};
+       GType foo_error_type_id;
+       foo_error_type_id = g_enum_register_static ("FooError", values);
+       return foo_error_type_id;
+}
+
+GType
+foo_error_get_type (void)
+{
+       static volatile gsize foo_error_type_id__once = 0;
+       if (g_once_init_enter (&foo_error_type_id__once)) {
+               GType foo_error_type_id;
+               foo_error_type_id = foo_error_get_type_once ();
+               g_once_init_leave (&foo_error_type_id__once, foo_error_type_id);
+       }
+       return foo_error_type_id__once;
+}
+
 static void
 foo_bar_data_free (gpointer _data)
 {
diff --git a/tests/asynchronous/catch-error-scope.c-expected b/tests/asynchronous/catch-error-scope.c-expected
index 289b79029..4f15904f8 100644
--- a/tests/asynchronous/catch-error-scope.c-expected
+++ b/tests/asynchronous/catch-error-scope.c-expected
@@ -2,10 +2,10 @@
  * generated from asynchronous_catch_error_scope.vala, do not modify */
 
 #include <glib.h>
+#include <glib-object.h>
 #include <gio/gio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <glib-object.h>
 
 #if !defined(VALA_EXTERN)
 #if defined(_MSC_VER)
@@ -17,6 +17,7 @@
 #endif
 #endif
 
+#define TYPE_FOO_ERROR (foo_error_get_type ())
 #define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
 typedef struct _FooData FooData;
 typedef struct _Block1Data Block1Data;
@@ -30,6 +31,7 @@ typedef enum  {
        FOO_ERROR_FAIL
 } FooError;
 #define FOO_ERROR foo_error_quark ()
+
 struct _FooData {
        int _state_;
        GObject* _source_object_;
@@ -50,6 +52,7 @@ struct _Block1Data {
 };
 
 VALA_EXTERN GQuark foo_error_quark (void);
+GType foo_error_get_type (void) G_GNUC_CONST ;
 static void foo_data_free (gpointer _data);
 VALA_EXTERN void foo (GAsyncReadyCallback _callback_,
           gpointer _user_data_);
@@ -71,6 +74,27 @@ foo_error_quark (void)
        return g_quark_from_static_string ("foo-error-quark");
 }
 
+static GType
+foo_error_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_ERROR_FAIL, "FOO_ERROR_FAIL", "fail"}, {0, NULL, NULL}};
+       GType foo_error_type_id;
+       foo_error_type_id = g_enum_register_static ("FooError", values);
+       return foo_error_type_id;
+}
+
+GType
+foo_error_get_type (void)
+{
+       static volatile gsize foo_error_type_id__once = 0;
+       if (g_once_init_enter (&foo_error_type_id__once)) {
+               GType foo_error_type_id;
+               foo_error_type_id = foo_error_get_type_once ();
+               g_once_init_leave (&foo_error_type_id__once, foo_error_type_id);
+       }
+       return foo_error_type_id__once;
+}
+
 static void
 foo_data_free (gpointer _data)
 {
diff --git a/tests/asynchronous/catch-in-finally.c-expected b/tests/asynchronous/catch-in-finally.c-expected
index 9779a393a..ca37912bb 100644
--- a/tests/asynchronous/catch-in-finally.c-expected
+++ b/tests/asynchronous/catch-in-finally.c-expected
@@ -2,8 +2,8 @@
  * generated from asynchronous_catch_in_finally.vala, do not modify */
 
 #include <glib.h>
-#include <gio/gio.h>
 #include <glib-object.h>
+#include <gio/gio.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -17,6 +17,7 @@
 #endif
 #endif
 
+#define TYPE_FOO_ERROR (foo_error_get_type ())
 typedef struct _FailData FailData;
 typedef struct _MayFailData MayFailData;
 typedef struct _FooData FooData;
@@ -33,6 +34,7 @@ typedef enum  {
        FOO_ERROR_FAIL
 } FooError;
 #define FOO_ERROR foo_error_quark ()
+
 struct _FailData {
        int _state_;
        GObject* _source_object_;
@@ -78,6 +80,7 @@ VALA_EXTERN GMainLoop* loop;
 GMainLoop* loop = NULL;
 
 VALA_EXTERN GQuark foo_error_quark (void);
+GType foo_error_get_type (void) G_GNUC_CONST ;
 static void fail_data_free (gpointer _data);
 VALA_EXTERN void fail (GAsyncReadyCallback _callback_,
            gpointer _user_data_);
@@ -131,6 +134,27 @@ foo_error_quark (void)
        return g_quark_from_static_string ("foo-error-quark");
 }
 
+static GType
+foo_error_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_ERROR_FAIL, "FOO_ERROR_FAIL", "fail"}, {0, NULL, NULL}};
+       GType foo_error_type_id;
+       foo_error_type_id = g_enum_register_static ("FooError", values);
+       return foo_error_type_id;
+}
+
+GType
+foo_error_get_type (void)
+{
+       static volatile gsize foo_error_type_id__once = 0;
+       if (g_once_init_enter (&foo_error_type_id__once)) {
+               GType foo_error_type_id;
+               foo_error_type_id = foo_error_get_type_once ();
+               g_once_init_leave (&foo_error_type_id__once, foo_error_type_id);
+       }
+       return foo_error_type_id__once;
+}
+
 static void
 fail_data_free (gpointer _data)
 {
diff --git a/tests/asynchronous/out-parameter-free-on-error.c-expected 
b/tests/asynchronous/out-parameter-free-on-error.c-expected
index f6468651b..a4673d0a8 100644
--- a/tests/asynchronous/out-parameter-free-on-error.c-expected
+++ b/tests/asynchronous/out-parameter-free-on-error.c-expected
@@ -15,6 +15,8 @@
 #endif
 #endif
 
+#define TYPE_FOO_ERROR (foo_error_get_type ())
+
 #define TYPE_MANAM (manam_get_type ())
 #define MANAM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MANAM, Manam))
 #define MANAM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MANAM, ManamClass))
@@ -43,6 +45,7 @@ typedef enum  {
        FOO_ERROR_FAIL
 } FooError;
 #define FOO_ERROR foo_error_quark ()
+
 struct _Manam {
        GObject parent_instance;
        ManamPrivate * priv;
@@ -82,6 +85,7 @@ VALA_EXTERN GMainLoop* loop;
 GMainLoop* loop = NULL;
 
 VALA_EXTERN GQuark foo_error_quark (void);
+GType foo_error_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN GType manam_get_type (void) G_GNUC_CONST ;
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (Manam, g_object_unref)
 VALA_EXTERN Manam* manam_new (void);
@@ -111,6 +115,27 @@ foo_error_quark (void)
        return g_quark_from_static_string ("foo-error-quark");
 }
 
+static GType
+foo_error_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_ERROR_FAIL, "FOO_ERROR_FAIL", "fail"}, {0, NULL, NULL}};
+       GType foo_error_type_id;
+       foo_error_type_id = g_enum_register_static ("FooError", values);
+       return foo_error_type_id;
+}
+
+GType
+foo_error_get_type (void)
+{
+       static volatile gsize foo_error_type_id__once = 0;
+       if (g_once_init_enter (&foo_error_type_id__once)) {
+               GType foo_error_type_id;
+               foo_error_type_id = foo_error_get_type_once ();
+               g_once_init_leave (&foo_error_type_id__once, foo_error_type_id);
+       }
+       return foo_error_type_id__once;
+}
+
 Manam*
 manam_construct (GType object_type)
 {
diff --git a/tests/basic-types/default-gtype.c-expected b/tests/basic-types/default-gtype.c-expected
index 4d1268f2e..995f00be5 100644
--- a/tests/basic-types/default-gtype.c-expected
+++ b/tests/basic-types/default-gtype.c-expected
@@ -35,6 +35,8 @@ typedef enum  {
 
 #define TYPE_FOO_FLAG (foo_flag_get_type ())
 
+#define TYPE_FOO_ERROR (foo_error_get_type ())
+
 #define TYPE_FOO_STRUCT (foo_struct_get_type ())
 typedef struct _FooStruct FooStruct;
 typedef enum  {
@@ -60,6 +62,7 @@ typedef enum  {
        FOO_ERROR_FAIL
 } FooError;
 #define FOO_ERROR foo_error_quark ()
+
 struct _FooStruct {
        gint i;
 };
@@ -77,6 +80,7 @@ static GType ifoo_get_type_once (void);
 VALA_EXTERN GType foo_enum_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN GType foo_flag_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN GQuark foo_error_quark (void);
+GType foo_error_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN GType foo_struct_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN FooStruct* foo_struct_dup (const FooStruct* self);
 VALA_EXTERN void foo_struct_free (FooStruct* self);
@@ -159,6 +163,27 @@ foo_error_quark (void)
        return g_quark_from_static_string ("foo-error-quark");
 }
 
+static GType
+foo_error_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_ERROR_FAIL, "FOO_ERROR_FAIL", "fail"}, {0, NULL, NULL}};
+       GType foo_error_type_id;
+       foo_error_type_id = g_enum_register_static ("FooError", values);
+       return foo_error_type_id;
+}
+
+GType
+foo_error_get_type (void)
+{
+       static volatile gsize foo_error_type_id__once = 0;
+       if (g_once_init_enter (&foo_error_type_id__once)) {
+               GType foo_error_type_id;
+               foo_error_type_id = foo_error_get_type_once ();
+               g_once_init_leave (&foo_error_type_id__once, foo_error_type_id);
+       }
+       return foo_error_type_id__once;
+}
+
 FooStruct*
 foo_struct_dup (const FooStruct* self)
 {
diff --git a/tests/control-flow/bug764440.c-expected b/tests/control-flow/bug764440.c-expected
index b49776996..e5e3b5b8a 100644
--- a/tests/control-flow/bug764440.c-expected
+++ b/tests/control-flow/bug764440.c-expected
@@ -2,6 +2,7 @@
  * generated from control_flow_bug764440.vala, do not modify */
 
 #include <glib.h>
+#include <glib-object.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -15,12 +16,15 @@
 #endif
 #endif
 
+#define TYPE_FOO_ERROR (foo_error_get_type ())
+
 typedef enum  {
        FOO_ERROR_BAR
 } FooError;
 #define FOO_ERROR foo_error_quark ()
 
 VALA_EXTERN GQuark foo_error_quark (void);
+GType foo_error_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN const gchar* get_bar (GError** error);
 static void _vala_main (void);
 
@@ -30,6 +34,27 @@ foo_error_quark (void)
        return g_quark_from_static_string ("foo-error-quark");
 }
 
+static GType
+foo_error_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_ERROR_BAR, "FOO_ERROR_BAR", "bar"}, {0, NULL, NULL}};
+       GType foo_error_type_id;
+       foo_error_type_id = g_enum_register_static ("FooError", values);
+       return foo_error_type_id;
+}
+
+GType
+foo_error_get_type (void)
+{
+       static volatile gsize foo_error_type_id__once = 0;
+       if (g_once_init_enter (&foo_error_type_id__once)) {
+               GType foo_error_type_id;
+               foo_error_type_id = foo_error_get_type_once ();
+               g_once_init_leave (&foo_error_type_id__once, foo_error_type_id);
+       }
+       return foo_error_type_id__once;
+}
+
 const gchar*
 get_bar (GError** error)
 {
diff --git a/tests/control-flow/lock-if-throw.c-expected b/tests/control-flow/lock-if-throw.c-expected
index ee259cffc..7912c9826 100644
--- a/tests/control-flow/lock-if-throw.c-expected
+++ b/tests/control-flow/lock-if-throw.c-expected
@@ -15,6 +15,8 @@
 #endif
 #endif
 
+#define TYPE_FOO_ERROR (foo_error_get_type ())
+
 #define TYPE_FOO (foo_get_type ())
 #define FOO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FOO, Foo))
 #define FOO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FOO, FooClass))
@@ -32,6 +34,7 @@ typedef enum  {
        FOO_ERROR_FAIL
 } FooError;
 #define FOO_ERROR foo_error_quark ()
+
 struct _Foo {
        GTypeInstance parent_instance;
        volatile int ref_count;
@@ -56,6 +59,7 @@ static gint Foo_private_offset;
 static gpointer foo_parent_class = NULL;
 
 VALA_EXTERN GQuark foo_error_quark (void);
+GType foo_error_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN gpointer foo_ref (gpointer instance);
 VALA_EXTERN void foo_unref (gpointer instance);
 VALA_EXTERN GParamSpec* param_spec_foo (const gchar* name,
@@ -84,6 +88,27 @@ foo_error_quark (void)
        return g_quark_from_static_string ("foo-error-quark");
 }
 
+static GType
+foo_error_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_ERROR_FAIL, "FOO_ERROR_FAIL", "fail"}, {0, NULL, NULL}};
+       GType foo_error_type_id;
+       foo_error_type_id = g_enum_register_static ("FooError", values);
+       return foo_error_type_id;
+}
+
+GType
+foo_error_get_type (void)
+{
+       static volatile gsize foo_error_type_id__once = 0;
+       if (g_once_init_enter (&foo_error_type_id__once)) {
+               GType foo_error_type_id;
+               foo_error_type_id = foo_error_get_type_once ();
+               g_once_init_leave (&foo_error_type_id__once, foo_error_type_id);
+       }
+       return foo_error_type_id__once;
+}
+
 static inline gpointer
 foo_get_instance_private (Foo* self)
 {
diff --git a/tests/dbus/errors_client.c-expected b/tests/dbus/errors_client.c-expected
index 908ddc35c..8f1209285 100644
--- a/tests/dbus/errors_client.c-expected
+++ b/tests/dbus/errors_client.c-expected
@@ -17,6 +17,8 @@
 #endif
 #endif
 
+#define TYPE_TEST_ERROR (test_error_get_type ())
+
 #define TYPE_TEST (test_get_type ())
 #define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test))
 #define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST))
@@ -42,6 +44,7 @@ typedef enum  {
        TEST_ERROR_WORSE
 } TestError;
 #define TEST_ERROR test_error_quark ()
+
 struct _TestIface {
        GTypeInterface parent_iface;
        void (*test_void) (Test* self, GError** error);
@@ -52,6 +55,7 @@ struct _TestIface {
 };
 
 VALA_EXTERN GQuark test_error_quark (void);
+GType test_error_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN GType test_proxy_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN guint test_register_object (void* object,
                             GDBusConnection* connection,
diff --git a/tests/dbus/errors_server.c-expected b/tests/dbus/errors_server.c-expected
index 3bcdc0c48..8406a6eab 100644
--- a/tests/dbus/errors_server.c-expected
+++ b/tests/dbus/errors_server.c-expected
@@ -17,6 +17,8 @@
 #endif
 #endif
 
+#define TYPE_TEST_ERROR (test_error_get_type ())
+
 #define TYPE_TEST (test_get_type ())
 #define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test))
 #define TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST, TestClass))
@@ -47,6 +49,7 @@ typedef enum  {
        TEST_ERROR_WORSE
 } TestError;
 #define TEST_ERROR test_error_quark ()
+
 struct _Test {
        GObject parent_instance;
        TestPrivate * priv;
@@ -61,6 +64,7 @@ VALA_EXTERN GMainLoop* main_loop;
 GMainLoop* main_loop = NULL;
 
 VALA_EXTERN GQuark test_error_quark (void);
+GType test_error_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ;
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (Test, g_object_unref)
 VALA_EXTERN guint test_register_object (void* object,
diff --git a/tests/delegates/error-pos.c-expected b/tests/delegates/error-pos.c-expected
index 25e92dc3b..1aa5874f1 100644
--- a/tests/delegates/error-pos.c-expected
+++ b/tests/delegates/error-pos.c-expected
@@ -2,9 +2,9 @@
  * generated from delegates_error_pos.vala, do not modify */
 
 #include <glib.h>
+#include <glib-object.h>
 #include <stdlib.h>
 #include <string.h>
-#include <glib-object.h>
 #include <gobject/gvaluecollector.h>
 
 #if !defined(VALA_EXTERN)
@@ -17,6 +17,7 @@
 #endif
 #endif
 
+#define TYPE_FOO_ERROR (foo_error_get_type ())
 typedef gchar* (*FooFunc) (gint i, GError** error, gpointer user_data);
 
 #define TYPE_BAR (bar_get_type ())
@@ -42,6 +43,7 @@ typedef enum  {
        FOO_ERROR_BAR
 } FooError;
 #define FOO_ERROR foo_error_quark ()
+
 struct _Bar {
        GTypeInstance parent_instance;
        volatile int ref_count;
@@ -60,6 +62,7 @@ struct _ParamSpecBar {
 static gpointer bar_parent_class = NULL;
 
 VALA_EXTERN GQuark foo_error_quark (void);
+GType foo_error_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN gpointer bar_ref (gpointer instance);
 VALA_EXTERN void bar_unref (gpointer instance);
 VALA_EXTERN GParamSpec* param_spec_bar (const gchar* name,
@@ -97,6 +100,27 @@ foo_error_quark (void)
        return g_quark_from_static_string ("foo-error-quark");
 }
 
+static GType
+foo_error_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_ERROR_BAR, "FOO_ERROR_BAR", "bar"}, {0, NULL, NULL}};
+       GType foo_error_type_id;
+       foo_error_type_id = g_enum_register_static ("FooError", values);
+       return foo_error_type_id;
+}
+
+GType
+foo_error_get_type (void)
+{
+       static volatile gsize foo_error_type_id__once = 0;
+       if (g_once_init_enter (&foo_error_type_id__once)) {
+               GType foo_error_type_id;
+               foo_error_type_id = foo_error_get_type_once ();
+               g_once_init_leave (&foo_error_type_id__once, foo_error_type_id);
+       }
+       return foo_error_type_id__once;
+}
+
 gchar*
 bar_foo (Bar* self,
          GError** error,
diff --git a/tests/delegates/params-array-with-throws.c-expected 
b/tests/delegates/params-array-with-throws.c-expected
index a00603906..68b33b8d7 100644
--- a/tests/delegates/params-array-with-throws.c-expected
+++ b/tests/delegates/params-array-with-throws.c-expected
@@ -2,6 +2,7 @@
  * generated from delegates_params_array_with_throws.vala, do not modify */
 
 #include <glib.h>
+#include <glib-object.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -15,6 +16,7 @@
 #endif
 #endif
 
+#define TYPE_FOO_ERROR (foo_error_get_type ())
 typedef void (*FooFunc) (GError** error, const gchar* _first_array, ...);
 #define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, 
__LINE__, G_STRFUNC, msg);
 #define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, 
G_STRFUNC, msg); return; }
@@ -28,6 +30,7 @@ typedef enum  {
 #define FOO_ERROR foo_error_quark ()
 
 VALA_EXTERN GQuark foo_error_quark (void);
+GType foo_error_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN void foo (GError** error,
           gchar* _first_array,
           ...);
@@ -50,6 +53,27 @@ foo_error_quark (void)
        return g_quark_from_static_string ("foo-error-quark");
 }
 
+static GType
+foo_error_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_ERROR_BAD, "FOO_ERROR_BAD", "bad"}, {FOO_ERROR_WORSE, 
"FOO_ERROR_WORSE", "worse"}, {0, NULL, NULL}};
+       GType foo_error_type_id;
+       foo_error_type_id = g_enum_register_static ("FooError", values);
+       return foo_error_type_id;
+}
+
+GType
+foo_error_get_type (void)
+{
+       static volatile gsize foo_error_type_id__once = 0;
+       if (g_once_init_enter (&foo_error_type_id__once)) {
+               GType foo_error_type_id;
+               foo_error_type_id = foo_error_get_type_once ();
+               g_once_init_leave (&foo_error_type_id__once, foo_error_type_id);
+       }
+       return foo_error_type_id__once;
+}
+
 static void
 _vala_array_add1 (const gchar** * array,
                   gint* length,
diff --git a/tests/delegates/variadic.c-expected b/tests/delegates/variadic.c-expected
index ae5d477d6..176dd015e 100644
--- a/tests/delegates/variadic.c-expected
+++ b/tests/delegates/variadic.c-expected
@@ -4,6 +4,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
+#include <glib-object.h>
 #include <stdarg.h>
 
 #if !defined(VALA_EXTERN)
@@ -18,6 +19,8 @@
 
 typedef void (*FooFunc) (const gchar* first, ...);
 typedef void (*BarFunc) (const gchar* first, ...);
+
+#define TYPE_BAZ_ERROR (baz_error_get_type ())
 typedef void (*BazFunc) (const gchar* first, GError** error, ...);
 #define _g_free0(var) (var = (g_free (var), NULL))
 #define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, 
__LINE__, G_STRFUNC, msg);
@@ -32,6 +35,7 @@ typedef enum  {
 #define BAZ_ERROR baz_error_quark ()
 
 VALA_EXTERN GQuark baz_error_quark (void);
+GType baz_error_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN void foo (const gchar* first,
           ...);
 VALA_EXTERN void baz (const gchar* first,
@@ -49,6 +53,27 @@ baz_error_quark (void)
        return g_quark_from_static_string ("baz-error-quark");
 }
 
+static GType
+baz_error_get_type_once (void)
+{
+       static const GEnumValue values[] = {{BAZ_ERROR_BAD, "BAZ_ERROR_BAD", "bad"}, {BAZ_ERROR_WORSE, 
"BAZ_ERROR_WORSE", "worse"}, {0, NULL, NULL}};
+       GType baz_error_type_id;
+       baz_error_type_id = g_enum_register_static ("BazError", values);
+       return baz_error_type_id;
+}
+
+GType
+baz_error_get_type (void)
+{
+       static volatile gsize baz_error_type_id__once = 0;
+       if (g_once_init_enter (&baz_error_type_id__once)) {
+               GType baz_error_type_id;
+               baz_error_type_id = baz_error_get_type_once ();
+               g_once_init_leave (&baz_error_type_id__once, baz_error_type_id);
+       }
+       return baz_error_type_id__once;
+}
+
 void
 foo (const gchar* first,
      ...)
diff --git a/tests/errors/bug567181.c-expected b/tests/errors/bug567181.c-expected
index db3a661b0..6d811473f 100644
--- a/tests/errors/bug567181.c-expected
+++ b/tests/errors/bug567181.c-expected
@@ -23,6 +23,8 @@
 
 typedef struct _Foo Foo;
 typedef struct _FooClass FooClass;
+
+#define TYPE_ERROR (error_get_type ())
 typedef struct _FooPrivate FooPrivate;
 enum  {
        FOO_0_PROPERTY,
@@ -39,6 +41,7 @@ typedef enum  {
        ERROR_FOOBAR
 } Error;
 #define ERROR error_quark ()
+
 struct _Foo {
        GObject parent_instance;
        FooPrivate * priv;
@@ -55,6 +58,7 @@ static gpointer foo_parent_class = NULL;
 VALA_EXTERN GType foo_get_type (void) G_GNUC_CONST ;
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (Foo, g_object_unref)
 VALA_EXTERN GQuark error_quark (void);
+GType error_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN Foo* foo_new (GError** error);
 VALA_EXTERN Foo* foo_construct (GType object_type,
                     GError** error);
@@ -69,6 +73,27 @@ error_quark (void)
        return g_quark_from_static_string ("error-quark");
 }
 
+static GType
+error_get_type_once (void)
+{
+       static const GEnumValue values[] = {{ERROR_FOOBAR, "ERROR_FOOBAR", "foobar"}, {0, NULL, NULL}};
+       GType error_type_id;
+       error_type_id = g_enum_register_static ("Error", values);
+       return error_type_id;
+}
+
+GType
+error_get_type (void)
+{
+       static volatile gsize error_type_id__once = 0;
+       if (g_once_init_enter (&error_type_id__once)) {
+               GType error_type_id;
+               error_type_id = error_get_type_once ();
+               g_once_init_leave (&error_type_id__once, error_type_id);
+       }
+       return error_type_id__once;
+}
+
 static gpointer
 _g_object_ref0 (gpointer self)
 {
diff --git a/tests/errors/bug579101.c-expected b/tests/errors/bug579101.c-expected
index a3b312bab..0fac3fdd2 100644
--- a/tests/errors/bug579101.c-expected
+++ b/tests/errors/bug579101.c-expected
@@ -2,6 +2,7 @@
  * generated from errors_bug579101.vala, do not modify */
 
 #include <glib.h>
+#include <glib-object.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -15,6 +16,7 @@
 #endif
 #endif
 
+#define TYPE_FOO_ERROR (foo_error_get_type ())
 #define _g_free0(var) (var = (g_free (var), NULL))
 #define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, 
__LINE__, G_STRFUNC, msg);
 #define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, 
G_STRFUNC, msg); return; }
@@ -27,6 +29,7 @@ typedef enum  {
 #define FOO_ERROR foo_error_quark ()
 
 VALA_EXTERN GQuark foo_error_quark (void);
+GType foo_error_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN void do_foo (gint* i);
 VALA_EXTERN gchar* do_bar (gint* i);
 VALA_EXTERN gchar* do_manam (gint* i);
@@ -38,6 +41,27 @@ foo_error_quark (void)
        return g_quark_from_static_string ("foo-error-quark");
 }
 
+static GType
+foo_error_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_ERROR_FAIL, "FOO_ERROR_FAIL", "fail"}, {0, NULL, NULL}};
+       GType foo_error_type_id;
+       foo_error_type_id = g_enum_register_static ("FooError", values);
+       return foo_error_type_id;
+}
+
+GType
+foo_error_get_type (void)
+{
+       static volatile gsize foo_error_type_id__once = 0;
+       if (g_once_init_enter (&foo_error_type_id__once)) {
+               GType foo_error_type_id;
+               foo_error_type_id = foo_error_get_type_once ();
+               g_once_init_leave (&foo_error_type_id__once, foo_error_type_id);
+       }
+       return foo_error_type_id__once;
+}
+
 void
 do_foo (gint* i)
 {
diff --git a/tests/errors/bug623049.c-expected b/tests/errors/bug623049.c-expected
index 0dc36ff53..403ab58af 100644
--- a/tests/errors/bug623049.c-expected
+++ b/tests/errors/bug623049.c-expected
@@ -14,6 +14,8 @@
 #endif
 #endif
 
+#define TYPE_FOO (foo_get_type ())
+
 #define TYPE_CLS_A (cls_a_get_type ())
 #define CLS_A(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CLS_A, ClsA))
 #define CLS_A_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CLS_A, ClsAClass))
@@ -51,6 +53,7 @@ typedef enum  {
        FOO_BAR
 } Foo;
 #define FOO foo_quark ()
+
 struct _ClsA {
        GObject parent_instance;
        ClsAPrivate * priv;
@@ -73,6 +76,7 @@ static gpointer cls_a_parent_class = NULL;
 static gpointer cls_b_parent_class = NULL;
 
 VALA_EXTERN GQuark foo_quark (void);
+GType foo_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN GType cls_a_get_type (void) G_GNUC_CONST ;
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClsA, g_object_unref)
 VALA_EXTERN ClsA* cls_a_new (GError** error);
@@ -93,6 +97,27 @@ foo_quark (void)
        return g_quark_from_static_string ("foo-quark");
 }
 
+static GType
+foo_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_BAR, "FOO_BAR", "bar"}, {0, NULL, NULL}};
+       GType foo_type_id;
+       foo_type_id = g_enum_register_static ("Foo", values);
+       return foo_type_id;
+}
+
+GType
+foo_get_type (void)
+{
+       static volatile gsize foo_type_id__once = 0;
+       if (g_once_init_enter (&foo_type_id__once)) {
+               GType foo_type_id;
+               foo_type_id = foo_get_type_once ();
+               g_once_init_leave (&foo_type_id__once, foo_type_id);
+       }
+       return foo_type_id__once;
+}
+
 ClsA*
 cls_a_construct (GType object_type,
                  GError** error)
diff --git a/tests/errors/bug778224.c-expected b/tests/errors/bug778224.c-expected
index b62036448..1ebb8379a 100644
--- a/tests/errors/bug778224.c-expected
+++ b/tests/errors/bug778224.c-expected
@@ -2,6 +2,7 @@
  * generated from errors_bug778224.vala, do not modify */
 
 #include <glib.h>
+#include <glib-object.h>
 
 #if !defined(VALA_EXTERN)
 #if defined(_MSC_VER)
@@ -13,12 +14,14 @@
 #endif
 #endif
 
+#define TYPE_FOO_ERROR (foo_error_get_type ())
 typedef struct _Foo Foo;
 
 typedef enum  {
        FOO_ERROR_BAR
 } FooError;
 #define FOO_ERROR foo_error_quark ()
+
 struct _Foo {
        gint i;
 };
@@ -27,6 +30,7 @@ VALA_EXTERN gboolean true;
 gboolean true = TRUE;
 
 VALA_EXTERN GQuark foo_error_quark (void);
+GType foo_error_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN Foo foo (GError** error);
 static void _vala_main (void);
 
@@ -36,6 +40,27 @@ foo_error_quark (void)
        return g_quark_from_static_string ("foo-error-quark");
 }
 
+static GType
+foo_error_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_ERROR_BAR, "FOO_ERROR_BAR", "bar"}, {0, NULL, NULL}};
+       GType foo_error_type_id;
+       foo_error_type_id = g_enum_register_static ("FooError", values);
+       return foo_error_type_id;
+}
+
+GType
+foo_error_get_type (void)
+{
+       static volatile gsize foo_error_type_id__once = 0;
+       if (g_once_init_enter (&foo_error_type_id__once)) {
+               GType foo_error_type_id;
+               foo_error_type_id = foo_error_get_type_once ();
+               g_once_init_leave (&foo_error_type_id__once, foo_error_type_id);
+       }
+       return foo_error_type_id__once;
+}
+
 Foo
 foo (GError** error)
 {
diff --git a/tests/errors/catch-error-code.c-expected b/tests/errors/catch-error-code.c-expected
index e5132b736..7fcd6f486 100644
--- a/tests/errors/catch-error-code.c-expected
+++ b/tests/errors/catch-error-code.c-expected
@@ -2,6 +2,7 @@
  * generated from errors_catch_error_code.vala, do not modify */
 
 #include <glib.h>
+#include <glib-object.h>
 
 #if !defined(VALA_EXTERN)
 #if defined(_MSC_VER)
@@ -13,6 +14,8 @@
 #endif
 #endif
 
+#define TYPE_FOO_ERROR (foo_error_get_type ())
+
 typedef enum  {
        FOO_ERROR_BAR,
        FOO_ERROR_FOO
@@ -20,6 +23,7 @@ typedef enum  {
 #define FOO_ERROR foo_error_quark ()
 
 VALA_EXTERN GQuark foo_error_quark (void);
+GType foo_error_get_type (void) G_GNUC_CONST ;
 static void _vala_main (void);
 
 GQuark
@@ -28,6 +32,27 @@ foo_error_quark (void)
        return g_quark_from_static_string ("foo-error-quark");
 }
 
+static GType
+foo_error_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_ERROR_BAR, "FOO_ERROR_BAR", "bar"}, {FOO_ERROR_FOO, 
"FOO_ERROR_FOO", "foo"}, {0, NULL, NULL}};
+       GType foo_error_type_id;
+       foo_error_type_id = g_enum_register_static ("FooError", values);
+       return foo_error_type_id;
+}
+
+GType
+foo_error_get_type (void)
+{
+       static volatile gsize foo_error_type_id__once = 0;
+       if (g_once_init_enter (&foo_error_type_id__once)) {
+               GType foo_error_type_id;
+               foo_error_type_id = foo_error_get_type_once ();
+               g_once_init_leave (&foo_error_type_id__once, foo_error_type_id);
+       }
+       return foo_error_type_id__once;
+}
+
 static void
 _vala_main (void)
 {
diff --git a/tests/errors/catch-in-finally.c-expected b/tests/errors/catch-in-finally.c-expected
index cecb359e8..fadaeed6d 100644
--- a/tests/errors/catch-in-finally.c-expected
+++ b/tests/errors/catch-in-finally.c-expected
@@ -2,6 +2,7 @@
  * generated from errors_catch_in_finally.vala, do not modify */
 
 #include <glib.h>
+#include <glib-object.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -15,6 +16,7 @@
 #endif
 #endif
 
+#define TYPE_FOO_ERROR (foo_error_get_type ())
 #define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
 #define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, 
__LINE__, G_STRFUNC, msg);
 #define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, 
G_STRFUNC, msg); return; }
@@ -27,6 +29,7 @@ typedef enum  {
 #define FOO_ERROR foo_error_quark ()
 
 VALA_EXTERN GQuark foo_error_quark (void);
+GType foo_error_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN void fail (GError** error);
 VALA_EXTERN void may_fail (GError** error);
 VALA_EXTERN void foo (GError** error);
@@ -39,6 +42,27 @@ foo_error_quark (void)
        return g_quark_from_static_string ("foo-error-quark");
 }
 
+static GType
+foo_error_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_ERROR_FAIL, "FOO_ERROR_FAIL", "fail"}, {0, NULL, NULL}};
+       GType foo_error_type_id;
+       foo_error_type_id = g_enum_register_static ("FooError", values);
+       return foo_error_type_id;
+}
+
+GType
+foo_error_get_type (void)
+{
+       static volatile gsize foo_error_type_id__once = 0;
+       if (g_once_init_enter (&foo_error_type_id__once)) {
+               GType foo_error_type_id;
+               foo_error_type_id = foo_error_get_type_once ();
+               g_once_init_leave (&foo_error_type_id__once, foo_error_type_id);
+       }
+       return foo_error_type_id__once;
+}
+
 void
 fail (GError** error)
 {
diff --git a/tests/errors/default-gtype.c-expected b/tests/errors/default-gtype.c-expected
index a65b92b1f..d38b8aaf2 100644
--- a/tests/errors/default-gtype.c-expected
+++ b/tests/errors/default-gtype.c-expected
@@ -14,6 +14,7 @@
 #endif
 #endif
 
+#define TYPE_FOO (foo_get_type ())
 #define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, 
__LINE__, G_STRFUNC, msg);
 #define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, 
G_STRFUNC, msg); return; }
 #define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning 
(G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
@@ -25,6 +26,7 @@ typedef enum  {
 #define FOO foo_quark ()
 
 VALA_EXTERN GQuark foo_quark (void);
+GType foo_get_type (void) G_GNUC_CONST ;
 static void _vala_main (void);
 
 GQuark
@@ -33,6 +35,27 @@ foo_quark (void)
        return g_quark_from_static_string ("foo-quark");
 }
 
+static GType
+foo_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_MANAM, "FOO_MANAM", "manam"}, {0, NULL, NULL}};
+       GType foo_type_id;
+       foo_type_id = g_enum_register_static ("Foo", values);
+       return foo_type_id;
+}
+
+GType
+foo_get_type (void)
+{
+       static volatile gsize foo_type_id__once = 0;
+       if (g_once_init_enter (&foo_type_id__once)) {
+               GType foo_type_id;
+               foo_type_id = foo_get_type_once ();
+               g_once_init_leave (&foo_type_id__once, foo_type_id);
+       }
+       return foo_type_id__once;
+}
+
 static void
 _vala_main (void)
 {
diff --git a/tests/errors/delegate-throws-error-code.c-expected 
b/tests/errors/delegate-throws-error-code.c-expected
index 5ccd6e4de..fadfb48f8 100644
--- a/tests/errors/delegate-throws-error-code.c-expected
+++ b/tests/errors/delegate-throws-error-code.c-expected
@@ -2,6 +2,7 @@
  * generated from errors_delegate_throws_error_code.vala, do not modify */
 
 #include <glib.h>
+#include <glib-object.h>
 
 #if !defined(VALA_EXTERN)
 #if defined(_MSC_VER)
@@ -13,6 +14,7 @@
 #endif
 #endif
 
+#define TYPE_FOO_ERROR (foo_error_get_type ())
 typedef void (*FooFunc) (gpointer user_data, GError** error);
 
 typedef enum  {
@@ -22,6 +24,7 @@ typedef enum  {
 #define FOO_ERROR foo_error_quark ()
 
 VALA_EXTERN GQuark foo_error_quark (void);
+GType foo_error_get_type (void) G_GNUC_CONST ;
 static void _vala_main (void);
 static void __lambda4_ (GError** error);
 static void ___lambda4__foo_func (gpointer self,
@@ -33,6 +36,27 @@ foo_error_quark (void)
        return g_quark_from_static_string ("foo-error-quark");
 }
 
+static GType
+foo_error_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_ERROR_FOO, "FOO_ERROR_FOO", "foo"}, {FOO_ERROR_BAR, 
"FOO_ERROR_BAR", "bar"}, {0, NULL, NULL}};
+       GType foo_error_type_id;
+       foo_error_type_id = g_enum_register_static ("FooError", values);
+       return foo_error_type_id;
+}
+
+GType
+foo_error_get_type (void)
+{
+       static volatile gsize foo_error_type_id__once = 0;
+       if (g_once_init_enter (&foo_error_type_id__once)) {
+               GType foo_error_type_id;
+               foo_error_type_id = foo_error_get_type_once ();
+               g_once_init_leave (&foo_error_type_id__once, foo_error_type_id);
+       }
+       return foo_error_type_id__once;
+}
+
 static void
 __lambda4_ (GError** error)
 {
diff --git a/tests/errors/errorcode.c-expected b/tests/errors/errorcode.c-expected
index 45c7db847..1e25de2fb 100644
--- a/tests/errors/errorcode.c-expected
+++ b/tests/errors/errorcode.c-expected
@@ -2,6 +2,7 @@
  * generated from errors_errorcode.vala, do not modify */
 
 #include <glib.h>
+#include <glib-object.h>
 #include <gio/gio.h>
 
 #if !defined(VALA_EXTERN)
@@ -14,6 +15,7 @@
 #endif
 #endif
 
+#define TYPE_FOO_ERROR (foo_error_get_type ())
 #define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
 #define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, 
__LINE__, G_STRFUNC, msg);
 #define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, 
G_STRFUNC, msg); return; }
@@ -28,6 +30,7 @@ typedef enum  {
 #define FOO_ERROR foo_error_quark ()
 
 VALA_EXTERN GQuark foo_error_quark (void);
+GType foo_error_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN void bar (gint code);
 static void _vala_main (void);
 
@@ -37,6 +40,27 @@ foo_error_quark (void)
        return g_quark_from_static_string ("foo-error-quark");
 }
 
+static GType
+foo_error_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_ERROR_REALLY_BAD, "FOO_ERROR_REALLY_BAD", "really-bad"}, 
{FOO_ERROR_NOT_SO_GOOD, "FOO_ERROR_NOT_SO_GOOD", "not-so-good"}, {FOO_ERROR_EVEN_WORSE, 
"FOO_ERROR_EVEN_WORSE", "even-worse"}, {0, NULL, NULL}};
+       GType foo_error_type_id;
+       foo_error_type_id = g_enum_register_static ("FooError", values);
+       return foo_error_type_id;
+}
+
+GType
+foo_error_get_type (void)
+{
+       static volatile gsize foo_error_type_id__once = 0;
+       if (g_once_init_enter (&foo_error_type_id__once)) {
+               GType foo_error_type_id;
+               foo_error_type_id = foo_error_get_type_once ();
+               g_once_init_leave (&foo_error_type_id__once, foo_error_type_id);
+       }
+       return foo_error_type_id__once;
+}
+
 void
 bar (gint code)
 {
diff --git a/tests/errors/errordomain-static-method.c-expected 
b/tests/errors/errordomain-static-method.c-expected
index f369c2d79..070ee2e7c 100644
--- a/tests/errors/errordomain-static-method.c-expected
+++ b/tests/errors/errordomain-static-method.c-expected
@@ -2,6 +2,7 @@
  * generated from errors_errordomain_static_method.vala, do not modify */
 
 #include <glib.h>
+#include <glib-object.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -15,6 +16,7 @@
 #endif
 #endif
 
+#define TYPE_FOO (foo_get_type ())
 #define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
 #define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, 
__LINE__, G_STRFUNC, msg);
 #define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, 
G_STRFUNC, msg); return; }
@@ -27,6 +29,7 @@ typedef enum  {
 #define FOO foo_quark ()
 
 VALA_EXTERN GQuark foo_quark (void);
+GType foo_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN GError* foo_from_string (const gchar* _error_);
 static void _vala_main (void);
 
@@ -48,6 +51,27 @@ foo_quark (void)
        return g_quark_from_static_string ("foo-quark");
 }
 
+static GType
+foo_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_BAD, "FOO_BAD", "bad"}, {0, NULL, NULL}};
+       GType foo_type_id;
+       foo_type_id = g_enum_register_static ("Foo", values);
+       return foo_type_id;
+}
+
+GType
+foo_get_type (void)
+{
+       static volatile gsize foo_type_id__once = 0;
+       if (g_once_init_enter (&foo_type_id__once)) {
+               GType foo_type_id;
+               foo_type_id = foo_get_type_once ();
+               g_once_init_leave (&foo_type_id__once, foo_type_id);
+       }
+       return foo_type_id__once;
+}
+
 static void
 _vala_main (void)
 {
diff --git a/tests/errors/errordomain.c-expected b/tests/errors/errordomain.c-expected
index 3ef447771..51d8a1f06 100644
--- a/tests/errors/errordomain.c-expected
+++ b/tests/errors/errordomain.c-expected
@@ -2,6 +2,7 @@
  * generated from errors_errordomain.vala, do not modify */
 
 #include <glib.h>
+#include <glib-object.h>
 
 #if !defined(VALA_EXTERN)
 #if defined(_MSC_VER)
@@ -13,12 +14,15 @@
 #endif
 #endif
 
+#define TYPE_FOO (foo_get_type ())
+
 typedef enum  {
        FOO_BAD
 } Foo;
 #define FOO foo_quark ()
 
 VALA_EXTERN GQuark foo_quark (void);
+GType foo_get_type (void) G_GNUC_CONST ;
 static void _vala_main (void);
 
 GQuark
@@ -27,6 +31,27 @@ foo_quark (void)
        return g_quark_from_static_string ("foo-quark");
 }
 
+static GType
+foo_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_BAD, "FOO_BAD", "bad"}, {0, NULL, NULL}};
+       GType foo_type_id;
+       foo_type_id = g_enum_register_static ("Foo", values);
+       return foo_type_id;
+}
+
+GType
+foo_get_type (void)
+{
+       static volatile gsize foo_type_id__once = 0;
+       if (g_once_init_enter (&foo_type_id__once)) {
+               GType foo_type_id;
+               foo_type_id = foo_get_type_once ();
+               g_once_init_leave (&foo_type_id__once, foo_type_id);
+       }
+       return foo_type_id__once;
+}
+
 static void
 _vala_main (void)
 {
diff --git a/tests/errors/errors.c-expected b/tests/errors/errors.c-expected
index 6294d88ea..25c46745a 100644
--- a/tests/errors/errors.c-expected
+++ b/tests/errors/errors.c-expected
@@ -17,6 +17,8 @@
 #endif
 #endif
 
+#define TYPE_BAR_ERROR (bar_error_get_type ())
+
 #define TYPE_BAR (bar_get_type ())
 #define BAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_BAR, Bar))
 #define BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_BAR, BarClass))
@@ -40,6 +42,7 @@ typedef enum  {
        BAR_ERROR_BAR
 } BarError;
 #define BAR_ERROR bar_error_quark ()
+
 struct _Bar {
        GObject parent_instance;
        BarPrivate * priv;
@@ -52,6 +55,7 @@ struct _BarClass {
 static gpointer bar_parent_class = NULL;
 
 VALA_EXTERN GQuark bar_error_quark (void);
+GType bar_error_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN GType bar_get_type (void) G_GNUC_CONST ;
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (Bar, g_object_unref)
 VALA_EXTERN void bar_foo (Bar* self,
@@ -76,6 +80,27 @@ bar_error_quark (void)
        return g_quark_from_static_string ("bar-error-quark");
 }
 
+static GType
+bar_error_get_type_once (void)
+{
+       static const GEnumValue values[] = {{BAR_ERROR_FOO, "BAR_ERROR_FOO", "foo"}, {BAR_ERROR_BAR, 
"BAR_ERROR_BAR", "bar"}, {0, NULL, NULL}};
+       GType bar_error_type_id;
+       bar_error_type_id = g_enum_register_static ("BarError", values);
+       return bar_error_type_id;
+}
+
+GType
+bar_error_get_type (void)
+{
+       static volatile gsize bar_error_type_id__once = 0;
+       if (g_once_init_enter (&bar_error_type_id__once)) {
+               GType bar_error_type_id;
+               bar_error_type_id = bar_error_get_type_once ();
+               g_once_init_leave (&bar_error_type_id__once, bar_error_type_id);
+       }
+       return bar_error_type_id__once;
+}
+
 void
 bar_foo (Bar* self,
          GError** error)
diff --git a/tests/errors/loops.c-expected b/tests/errors/loops.c-expected
index b85da1cf9..e42138013 100644
--- a/tests/errors/loops.c-expected
+++ b/tests/errors/loops.c-expected
@@ -2,6 +2,7 @@
  * generated from errors_loops.vala, do not modify */
 
 #include <glib.h>
+#include <glib-object.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -15,6 +16,7 @@
 #endif
 #endif
 
+#define TYPE_FOO_ERROR (foo_error_get_type ())
 #define _g_free0(var) (var = (g_free (var), NULL))
 
 typedef enum  {
@@ -23,6 +25,7 @@ typedef enum  {
 #define FOO_ERROR foo_error_quark ()
 
 VALA_EXTERN GQuark foo_error_quark (void);
+GType foo_error_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN gchar** get_array (gint* result_length1,
                    GError** error);
 VALA_EXTERN gboolean get_bool (GError** error);
@@ -45,6 +48,27 @@ foo_error_quark (void)
        return g_quark_from_static_string ("foo-error-quark");
 }
 
+static GType
+foo_error_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_ERROR_FAIL, "FOO_ERROR_FAIL", "fail"}, {0, NULL, NULL}};
+       GType foo_error_type_id;
+       foo_error_type_id = g_enum_register_static ("FooError", values);
+       return foo_error_type_id;
+}
+
+GType
+foo_error_get_type (void)
+{
+       static volatile gsize foo_error_type_id__once = 0;
+       if (g_once_init_enter (&foo_error_type_id__once)) {
+               GType foo_error_type_id;
+               foo_error_type_id = foo_error_get_type_once ();
+               g_once_init_leave (&foo_error_type_id__once, foo_error_type_id);
+       }
+       return foo_error_type_id__once;
+}
+
 gchar**
 get_array (gint* result_length1,
            GError** error)
diff --git a/tests/errors/method-throws-error-code.c-expected 
b/tests/errors/method-throws-error-code.c-expected
index 1fa8f2be4..dceef5dfb 100644
--- a/tests/errors/method-throws-error-code.c-expected
+++ b/tests/errors/method-throws-error-code.c-expected
@@ -2,6 +2,7 @@
  * generated from errors_method_throws_error_code.vala, do not modify */
 
 #include <glib.h>
+#include <glib-object.h>
 
 #if !defined(VALA_EXTERN)
 #if defined(_MSC_VER)
@@ -13,6 +14,8 @@
 #endif
 #endif
 
+#define TYPE_FOO_ERROR (foo_error_get_type ())
+
 typedef enum  {
        FOO_ERROR_FOO,
        FOO_ERROR_BAR
@@ -20,6 +23,7 @@ typedef enum  {
 #define FOO_ERROR foo_error_quark ()
 
 VALA_EXTERN GQuark foo_error_quark (void);
+GType foo_error_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN void foo (GError** error);
 static void _vala_main (void);
 
@@ -29,6 +33,27 @@ foo_error_quark (void)
        return g_quark_from_static_string ("foo-error-quark");
 }
 
+static GType
+foo_error_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_ERROR_FOO, "FOO_ERROR_FOO", "foo"}, {FOO_ERROR_BAR, 
"FOO_ERROR_BAR", "bar"}, {0, NULL, NULL}};
+       GType foo_error_type_id;
+       foo_error_type_id = g_enum_register_static ("FooError", values);
+       return foo_error_type_id;
+}
+
+GType
+foo_error_get_type (void)
+{
+       static volatile gsize foo_error_type_id__once = 0;
+       if (g_once_init_enter (&foo_error_type_id__once)) {
+               GType foo_error_type_id;
+               foo_error_type_id = foo_error_get_type_once ();
+               g_once_init_leave (&foo_error_type_id__once, foo_error_type_id);
+       }
+       return foo_error_type_id__once;
+}
+
 void
 foo (GError** error)
 {
diff --git a/tests/errors/unhandled.c-expected b/tests/errors/unhandled.c-expected
index 6de43da7c..deb2f7f3f 100644
--- a/tests/errors/unhandled.c-expected
+++ b/tests/errors/unhandled.c-expected
@@ -16,6 +16,8 @@
 #endif
 #endif
 
+#define TYPE_FOO_ERROR (foo_error_get_type ())
+
 #define TYPE_FOO (foo_get_type ())
 #define FOO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FOO, Foo))
 #define FOO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FOO, FooClass))
@@ -37,6 +39,7 @@ typedef enum  {
        FOO_ERROR_FAIL
 } FooError;
 #define FOO_ERROR foo_error_quark ()
+
 struct _Foo {
        GObject parent_instance;
        FooPrivate * priv;
@@ -49,6 +52,7 @@ struct _FooClass {
 static gpointer foo_parent_class = NULL;
 
 VALA_EXTERN GQuark foo_error_quark (void);
+GType foo_error_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN GType foo_get_type (void) G_GNUC_CONST ;
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (Foo, g_object_unref)
 VALA_EXTERN Foo* foo_new (void);
@@ -80,6 +84,27 @@ foo_error_quark (void)
        return g_quark_from_static_string ("foo-error-quark");
 }
 
+static GType
+foo_error_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_ERROR_FAIL, "FOO_ERROR_FAIL", "fail"}, {0, NULL, NULL}};
+       GType foo_error_type_id;
+       foo_error_type_id = g_enum_register_static ("FooError", values);
+       return foo_error_type_id;
+}
+
+GType
+foo_error_get_type (void)
+{
+       static volatile gsize foo_error_type_id__once = 0;
+       if (g_once_init_enter (&foo_error_type_id__once)) {
+               GType foo_error_type_id;
+               foo_error_type_id = foo_error_get_type_once ();
+               g_once_init_leave (&foo_error_type_id__once, foo_error_type_id);
+       }
+       return foo_error_type_id__once;
+}
+
 Foo*
 foo_construct (GType object_type)
 {
diff --git a/tests/genie/exception.c-expected b/tests/genie/exception.c-expected
index 976e2c579..d75111d7f 100644
--- a/tests/genie/exception.c-expected
+++ b/tests/genie/exception.c-expected
@@ -4,6 +4,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
+#include <glib-object.h>
 
 #if !defined(VALA_EXTERN)
 #if defined(_MSC_VER)
@@ -15,6 +16,7 @@
 #endif
 #endif
 
+#define TYPE_TEST_ERROR (test_error_get_type ())
 #define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
 
 typedef enum  {
@@ -27,6 +29,7 @@ typedef enum  {
 static void _vala_main (gchar** args,
                  gint args_length1);
 VALA_EXTERN GQuark test_error_quark (void);
+GType test_error_get_type (void) G_GNUC_CONST ;
 
 static void
 _vala_main (gchar** args,
@@ -53,3 +56,24 @@ test_error_quark (void)
        return g_quark_from_static_string ("test-error-quark");
 }
 
+static GType
+test_error_get_type_once (void)
+{
+       static const GEnumValue values[] = {{TEST_ERROR_FAIL, "TEST_ERROR_FAIL", "fail"}, {TEST_ERROR_BAD, 
"TEST_ERROR_BAD", "bad"}, {TEST_ERROR_WORSE, "TEST_ERROR_WORSE", "worse"}, {0, NULL, NULL}};
+       GType test_error_type_id;
+       test_error_type_id = g_enum_register_static ("TestError", values);
+       return test_error_type_id;
+}
+
+GType
+test_error_get_type (void)
+{
+       static volatile gsize test_error_type_id__once = 0;
+       if (g_once_init_enter (&test_error_type_id__once)) {
+               GType test_error_type_id;
+               test_error_type_id = test_error_get_type_once ();
+               g_once_init_leave (&test_error_type_id__once, test_error_type_id);
+       }
+       return test_error_type_id__once;
+}
+
diff --git a/tests/girwriter/GirTest-1.0.gir-expected b/tests/girwriter/GirTest-1.0.gir-expected
index 72b408d5a..c308e62a1 100644
--- a/tests/girwriter/GirTest-1.0.gir-expected
+++ b/tests/girwriter/GirTest-1.0.gir-expected
@@ -37,12 +37,17 @@
        <bitfield name="RenamedBitfield" c:type="GirTestNamedBitfield" glib:type-name="GirTestNamedBitfield" 
glib:get-type="gir_test_named_bitfield_get_type">
                <member name="value1" c:identifier="GIR_TEST_NAMED_BITFIELD_VALUE1" value="1"/>
        </bitfield>
-       <enumeration name="ErrorTest" c:type="GirTestErrorTest" glib:error-domain="gir-test-error-test-quark">
+       <enumeration name="ErrorTest" c:type="GirTestErrorTest" glib:type-name="GirTestErrorTest" 
glib:get-type="gir_test_error_test_get_type" glib:error-domain="gir-test-error-test-quark">
                <member name="failed" c:identifier="GIR_TEST_ERROR_TEST_FAILED" value="0"/>
                <member name="smelly" c:identifier="GIR_TEST_ERROR_TEST_SMELLY" value="1"/>
                <member name="fishy" c:identifier="GIR_TEST_ERROR_TEST_FISHY" value="23"/>
        </enumeration>
-       <enumeration name="RenamedError" c:type="GirTestNamedError" 
glib:error-domain="gir-test-named-error-quark">
+       <enumeration name="PlainErrorTest" c:type="GirTestPlainErrorTest" 
glib:error-domain="gir-test-plain-error-test-quark">
+               <member name="failed" c:identifier="GIR_TEST_PLAIN_ERROR_TEST_FAILED" value="0"/>
+               <member name="smelly" c:identifier="GIR_TEST_PLAIN_ERROR_TEST_SMELLY" value="1"/>
+               <member name="fishy" c:identifier="GIR_TEST_PLAIN_ERROR_TEST_FISHY" value="23"/>
+       </enumeration>
+       <enumeration name="RenamedError" c:type="GirTestNamedError" glib:type-name="GirTestNamedError" 
glib:get-type="gir_test_named_error_get_type" glib:error-domain="gir-test-named-error-quark">
                <member name="failed" c:identifier="GIR_TEST_NAMED_ERROR_FAILED" value="0"/>
        </enumeration>
        <class name="TypeTest" c:type="GirTestTypeTest" c:symbol-prefix="typetest" 
glib:type-name="GirTestTypeTest" glib:get-type="gir_test_typetest_get_type" glib:type-struct="TypeTestClass" 
glib:fundamental="1" glib:ref-func="gir_test_typetest_ref" glib:unref-func="gir_test_typetest_unref" 
glib:set-value-func="gir_test_value_set_typetest" glib:get-value-func="gir_test_value_get_typetest">
diff --git a/tests/girwriter/girtest.vala b/tests/girwriter/girtest.vala
index 82d146ecc..b2b107385 100644
--- a/tests/girwriter/girtest.vala
+++ b/tests/girwriter/girtest.vala
@@ -111,6 +111,13 @@ namespace GirTest {
                FISHY = 23
        }
 
+       [CCode (has_type_id = false)]
+       public errordomain PlainErrorTest {
+               FAILED,
+               SMELLY,
+               FISHY = 23
+       }
+
        [GIR (name = "RenamedError")]
        public errordomain NamedError {
                FAILED
diff --git a/tests/girwriter/girtest.vapi-expected b/tests/girwriter/girtest.vapi-expected
index 0350bd8e6..578d588dc 100644
--- a/tests/girwriter/girtest.vapi-expected
+++ b/tests/girwriter/girtest.vapi-expected
@@ -249,6 +249,12 @@ namespace GirTest {
        public errordomain NamedError {
                FAILED
        }
+       [CCode (cheader_filename = "girtest.h", has_type_id = false)]
+       public errordomain PlainErrorTest {
+               FAILED,
+               SMELLY,
+               FISHY
+       }
        [CCode (cheader_filename = "girtest.h")]
        public delegate bool DelegateErrorTest () throws GirTest.ErrorTest;
        [CCode (cheader_filename = "girtest.h")]
diff --git a/tests/girwriter/girtest.vapigen-expected b/tests/girwriter/girtest.vapigen-expected
index ad33e3c96..d559fbea0 100644
--- a/tests/girwriter/girtest.vapigen-expected
+++ b/tests/girwriter/girtest.vapigen-expected
@@ -251,13 +251,19 @@ namespace GirTest {
        public enum RenamedEnumeration {
                VALUE1
        }
-       [CCode (cheader_filename = "girtest.h", cprefix = "GIR_TEST_ERROR_TEST_")]
+       [CCode (cheader_filename = "girtest.h", cprefix = "GIR_TEST_ERROR_TEST_", type_id = 
"gir_test_error_test_get_type ()")]
        public errordomain ErrorTest {
                FAILED,
                SMELLY,
                FISHY
        }
-       [CCode (cheader_filename = "girtest.h", cname = "GirTestNamedError", cprefix = 
"GIR_TEST_NAMED_ERROR_")]
+       [CCode (cheader_filename = "girtest.h", cprefix = "GIR_TEST_PLAIN_ERROR_TEST_", has_type_id = false)]
+       public errordomain PlainErrorTest {
+               FAILED,
+               SMELLY,
+               FISHY
+       }
+       [CCode (cheader_filename = "girtest.h", cname = "GirTestNamedError", cprefix = 
"GIR_TEST_NAMED_ERROR_", type_id = "gir_test_named_error_get_type ()")]
        public errordomain RenamedError {
                FAILED
        }
diff --git a/tests/methods/bug781061.c-expected b/tests/methods/bug781061.c-expected
index 91d787d5e..352fa1e2f 100644
--- a/tests/methods/bug781061.c-expected
+++ b/tests/methods/bug781061.c-expected
@@ -2,6 +2,7 @@
  * generated from methods_bug781061.vala, do not modify */
 
 #include <glib.h>
+#include <glib-object.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdarg.h>
@@ -16,12 +17,15 @@
 #endif
 #endif
 
+#define TYPE_FOO_ERROR (foo_error_get_type ())
+
 typedef enum  {
        FOO_ERROR_FAILED
 } FooError;
 #define FOO_ERROR foo_error_quark ()
 
 VALA_EXTERN GQuark foo_error_quark (void);
+GType foo_error_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN void print_something_throws (gboolean ok,
                              const gchar* format,
                              GError** error,
@@ -46,6 +50,27 @@ foo_error_quark (void)
        return g_quark_from_static_string ("foo-error-quark");
 }
 
+static GType
+foo_error_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_ERROR_FAILED, "FOO_ERROR_FAILED", "failed"}, {0, NULL, 
NULL}};
+       GType foo_error_type_id;
+       foo_error_type_id = g_enum_register_static ("FooError", values);
+       return foo_error_type_id;
+}
+
+GType
+foo_error_get_type (void)
+{
+       static volatile gsize foo_error_type_id__once = 0;
+       if (g_once_init_enter (&foo_error_type_id__once)) {
+               GType foo_error_type_id;
+               foo_error_type_id = foo_error_get_type_once ();
+               g_once_init_leave (&foo_error_type_id__once, foo_error_type_id);
+       }
+       return foo_error_type_id__once;
+}
+
 void
 print_something_throws (gboolean ok,
                         const gchar* format,
diff --git a/tests/methods/parameter-out-free-on-error.c-expected 
b/tests/methods/parameter-out-free-on-error.c-expected
index db888bd11..18e4fcc18 100644
--- a/tests/methods/parameter-out-free-on-error.c-expected
+++ b/tests/methods/parameter-out-free-on-error.c-expected
@@ -14,6 +14,8 @@
 #endif
 #endif
 
+#define TYPE_FOO_ERROR (foo_error_get_type ())
+
 #define TYPE_MANAM (manam_get_type ())
 #define MANAM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MANAM, Manam))
 #define MANAM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MANAM, ManamClass))
@@ -39,6 +41,7 @@ typedef enum  {
        FOO_ERROR_FAIL
 } FooError;
 #define FOO_ERROR foo_error_quark ()
+
 struct _Manam {
        GObject parent_instance;
        ManamPrivate * priv;
@@ -51,6 +54,7 @@ struct _ManamClass {
 static gpointer manam_parent_class = NULL;
 
 VALA_EXTERN GQuark foo_error_quark (void);
+GType foo_error_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN GType manam_get_type (void) G_GNUC_CONST ;
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (Manam, g_object_unref)
 VALA_EXTERN Manam* manam_new (void);
@@ -70,6 +74,27 @@ foo_error_quark (void)
        return g_quark_from_static_string ("foo-error-quark");
 }
 
+static GType
+foo_error_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_ERROR_FAIL, "FOO_ERROR_FAIL", "fail"}, {0, NULL, NULL}};
+       GType foo_error_type_id;
+       foo_error_type_id = g_enum_register_static ("FooError", values);
+       return foo_error_type_id;
+}
+
+GType
+foo_error_get_type (void)
+{
+       static volatile gsize foo_error_type_id__once = 0;
+       if (g_once_init_enter (&foo_error_type_id__once)) {
+               GType foo_error_type_id;
+               foo_error_type_id = foo_error_get_type_once ();
+               g_once_init_leave (&foo_error_type_id__once, foo_error_type_id);
+       }
+       return foo_error_type_id__once;
+}
+
 Manam*
 manam_construct (GType object_type)
 {
diff --git a/tests/methods/params-array-with-throws.c-expected 
b/tests/methods/params-array-with-throws.c-expected
index a456b3329..0d25797cc 100644
--- a/tests/methods/params-array-with-throws.c-expected
+++ b/tests/methods/params-array-with-throws.c-expected
@@ -2,9 +2,9 @@
  * generated from methods_params_array_with_throws.vala, do not modify */
 
 #include <glib.h>
+#include <glib-object.h>
 #include <stdlib.h>
 #include <string.h>
-#include <glib-object.h>
 #include <gobject/gvaluecollector.h>
 
 #if !defined(VALA_EXTERN)
@@ -17,6 +17,8 @@
 #endif
 #endif
 
+#define TYPE_FOO_ERROR (foo_error_get_type ())
+
 #define TYPE_FOO (foo_get_type ())
 #define FOO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FOO, Foo))
 #define FOO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FOO, FooClass))
@@ -39,6 +41,7 @@ typedef enum  {
        FOO_ERROR_WORSE
 } FooError;
 #define FOO_ERROR foo_error_quark ()
+
 struct _Foo {
        GTypeInstance parent_instance;
        volatile int ref_count;
@@ -57,6 +60,7 @@ struct _ParamSpecFoo {
 static gpointer foo_parent_class = NULL;
 
 VALA_EXTERN GQuark foo_error_quark (void);
+GType foo_error_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN void foo (GError** error,
           const gchar* _first_array,
           ...);
@@ -113,6 +117,27 @@ foo_error_quark (void)
        return g_quark_from_static_string ("foo-error-quark");
 }
 
+static GType
+foo_error_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_ERROR_BAD, "FOO_ERROR_BAD", "bad"}, {FOO_ERROR_WORSE, 
"FOO_ERROR_WORSE", "worse"}, {0, NULL, NULL}};
+       GType foo_error_type_id;
+       foo_error_type_id = g_enum_register_static ("FooError", values);
+       return foo_error_type_id;
+}
+
+GType
+foo_error_get_type (void)
+{
+       static volatile gsize foo_error_type_id__once = 0;
+       if (g_once_init_enter (&foo_error_type_id__once)) {
+               GType foo_error_type_id;
+               foo_error_type_id = foo_error_get_type_once ();
+               g_once_init_leave (&foo_error_type_id__once, foo_error_type_id);
+       }
+       return foo_error_type_id__once;
+}
+
 static void
 _vala_array_add1 (const gchar** * array,
                   gint* length,
diff --git a/tests/methods/print-attribute.c-expected b/tests/methods/print-attribute.c-expected
index bd627c809..d3b9ae59e 100644
--- a/tests/methods/print-attribute.c-expected
+++ b/tests/methods/print-attribute.c-expected
@@ -17,6 +17,8 @@
 #endif
 #endif
 
+#define TYPE_FOO_ERROR (foo_error_get_type ())
+
 #define TYPE_FOO (foo_get_type ())
 #define FOO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FOO, Foo))
 #define FOO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FOO, FooClass))
@@ -39,6 +41,7 @@ typedef enum  {
        FOO_ERROR_FAIL
 } FooError;
 #define FOO_ERROR foo_error_quark ()
+
 struct _Foo {
        GTypeInstance parent_instance;
        volatile int ref_count;
@@ -57,6 +60,7 @@ struct _ParamSpecFoo {
 static gpointer foo_parent_class = NULL;
 
 VALA_EXTERN GQuark foo_error_quark (void);
+GType foo_error_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN gpointer foo_ref (gpointer instance);
 VALA_EXTERN void foo_unref (gpointer instance);
 VALA_EXTERN GParamSpec* param_spec_foo (const gchar* name,
@@ -88,6 +92,27 @@ foo_error_quark (void)
        return g_quark_from_static_string ("foo-error-quark");
 }
 
+static GType
+foo_error_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_ERROR_FAIL, "FOO_ERROR_FAIL", "fail"}, {0, NULL, NULL}};
+       GType foo_error_type_id;
+       foo_error_type_id = g_enum_register_static ("FooError", values);
+       return foo_error_type_id;
+}
+
+GType
+foo_error_get_type (void)
+{
+       static volatile gsize foo_error_type_id__once = 0;
+       if (g_once_init_enter (&foo_error_type_id__once)) {
+               GType foo_error_type_id;
+               foo_error_type_id = foo_error_get_type_once ();
+               g_once_init_leave (&foo_error_type_id__once, foo_error_type_id);
+       }
+       return foo_error_type_id__once;
+}
+
 void
 foo_foo (Foo* self,
          const gchar* s)
diff --git a/tests/objects/signals-error-marshal.c-expected b/tests/objects/signals-error-marshal.c-expected
index 35e69052c..110f63cf4 100644
--- a/tests/objects/signals-error-marshal.c-expected
+++ b/tests/objects/signals-error-marshal.c-expected
@@ -15,6 +15,8 @@
 #endif
 #endif
 
+#define TYPE_FOO_ERROR (foo_error_get_type ())
+
 #define TYPE_BAR (bar_get_type ())
 typedef struct _Bar Bar;
 
@@ -50,6 +52,7 @@ typedef enum  {
        FOO_ERROR_BAD
 } FooError;
 #define FOO_ERROR foo_error_quark ()
+
 struct _Bar {
        gint i;
 };
@@ -66,6 +69,7 @@ struct _FooClass {
 static gpointer foo_parent_class = NULL;
 
 VALA_EXTERN GQuark foo_error_quark (void);
+GType foo_error_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN GType bar_get_type (void) G_GNUC_CONST ;
 VALA_EXTERN Bar* bar_dup (const Bar* self);
 VALA_EXTERN void bar_free (Bar* self);
@@ -101,6 +105,27 @@ foo_error_quark (void)
        return g_quark_from_static_string ("foo-error-quark");
 }
 
+static GType
+foo_error_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_ERROR_BAD, "FOO_ERROR_BAD", "bad"}, {0, NULL, NULL}};
+       GType foo_error_type_id;
+       foo_error_type_id = g_enum_register_static ("FooError", values);
+       return foo_error_type_id;
+}
+
+GType
+foo_error_get_type (void)
+{
+       static volatile gsize foo_error_type_id__once = 0;
+       if (g_once_init_enter (&foo_error_type_id__once)) {
+               GType foo_error_type_id;
+               foo_error_type_id = foo_error_get_type_once ();
+               g_once_init_leave (&foo_error_type_id__once, foo_error_type_id);
+       }
+       return foo_error_type_id__once;
+}
+
 Bar*
 bar_dup (const Bar* self)
 {
diff --git a/vala/valaerrorcode.vala b/vala/valaerrorcode.vala
index 525fb7d55..5fcff7585 100644
--- a/vala/valaerrorcode.vala
+++ b/vala/valaerrorcode.vala
@@ -54,8 +54,24 @@ public class Vala.ErrorCode : TypeSymbol {
                }
        }
 
+       /**
+        * The nick of this error code
+        */
+       public string nick {
+               get {
+                       if (_nick == null) {
+                               _nick = get_attribute_string ("Description", "nick");
+                               if (_nick == null) {
+                                       _nick = name.down ().replace ("_", "-");
+                               }
+                       }
+                       return _nick;
+               }
+       }
+
        private Expression _value;
        private Constant _code;
+       private string? _nick = null;
 
        /**
         * Creates a new enum value.


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