[vala/0.54] codegen: Check required length of enum type name for GType support



commit bf729356381403c958b620501b64a7266a010970
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed Nov 17 21:26:39 2021 +0100

    codegen: Check required length of enum type name for GType support
    
    Add corresponding tests for types which have support for GType

 codegen/valaccodestructmodule.vala           |  6 ------
 codegen/valagtypemodule.vala                 | 12 ++++++++++++
 tests/Makefile.am                            |  5 ++++-
 tests/enums/enum-gtype-too-short.test        |  8 ++++++++
 tests/objects/class-gtype-too-short.test     |  7 +++++++
 tests/objects/interface-gtype-too-short.test |  7 +++++++
 tests/structs/bug764041.test                 | 10 ----------
 tests/structs/struct-gtype-too-short.test    |  8 ++++++++
 8 files changed, 46 insertions(+), 17 deletions(-)
---
diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala
index d019a95e1..d9577e7df 100644
--- a/codegen/valaccodestructmodule.vala
+++ b/codegen/valaccodestructmodule.vala
@@ -157,12 +157,6 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
                push_context (new EmitContext (st));
                push_line (st.source_reference);
 
-               if (get_ccode_has_type_id (st) && get_ccode_name (st).length < 3) {
-                       st.error = true;
-                       Report.error (st.source_reference, "Name `%s' is too short for struct using GType", 
get_ccode_name (st));
-                       return;
-               }
-
                var old_instance_finalize_context = instance_finalize_context;
                instance_finalize_context = new EmitContext ();
 
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index 95e49c56a..ab6c5647f 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -2358,6 +2358,12 @@ public class Vala.GTypeModule : GErrorModule {
                }
 
                if (get_ccode_has_type_id (st)) {
+                       if (get_ccode_name (st).length < 3) {
+                               st.error = true;
+                               Report.error (st.source_reference, "Struct name `%s' is too short", 
get_ccode_name (st));
+                               return;
+                       }
+
                        push_line (st.source_reference);
                        var type_fun = new StructRegisterFunction (st);
                        type_fun.init_from_type (context, false, false);
@@ -2370,6 +2376,12 @@ public class Vala.GTypeModule : GErrorModule {
                base.visit_enum (en);
 
                if (get_ccode_has_type_id (en)) {
+                       if (get_ccode_name (en).length < 3) {
+                               en.error = true;
+                               Report.error (en.source_reference, "Enum name `%s' is too short", 
get_ccode_name (en));
+                               return;
+                       }
+
                        push_line (en.source_reference);
                        var type_fun = new EnumRegisterFunction (en);
                        type_fun.init_from_type (context, false, false);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 515813465..4b0425979 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -330,6 +330,7 @@ TESTS = \
        enums/default-gtype.vala \
        enums/enum_only.vala \
        enums/enum-no-gtype.vala \
+       enums/enum-gtype-too-short.test \
        enums/enums.vala \
        enums/flags.vala \
        enums/from-0-literal.vala \
@@ -349,6 +350,7 @@ TESTS = \
        structs/struct-base-types.vala \
        structs/struct-boxed-cast.vala \
        structs/struct-empty-still.test \
+       structs/struct-gtype-too-short.test \
        structs/struct-initializer-list-in-array.vala \
        structs/struct-initializer-list-nested.vala \
        structs/struct-no-gtype.vala \
@@ -397,7 +399,6 @@ TESTS = \
        structs/bug690380.vala \
        structs/bug694140.vala \
        structs/bug749952.vala \
-       structs/bug764041.test \
        structs/bug775761.vala \
        structs/bug777194.vala \
        structs/bug777194-2.vala \
@@ -450,6 +451,7 @@ TESTS = \
        objects/class-ccode-cprefix.vala \
        objects/class_only.vala \
        objects/class-destroysinstance.vala \
+       objects/class-gtype-too-short.test \
        objects/class-inner-types.vala \
        objects/class-new-no-override.vala \
        objects/class-vfunc-base-access.vala \
@@ -481,6 +483,7 @@ TESTS = \
        objects/interface_only.vala \
        objects/interface-async-base-access.vala \
        objects/interface-base-access.vala \
+       objects/interface-gtype-too-short.test \
        objects/interface-inner-types.vala \
        objects/interfaces.vala \
        objects/interface-abstract-async-override.vala \
diff --git a/tests/enums/enum-gtype-too-short.test b/tests/enums/enum-gtype-too-short.test
new file mode 100644
index 000000000..b897ab50c
--- /dev/null
+++ b/tests/enums/enum-gtype-too-short.test
@@ -0,0 +1,8 @@
+Invalid Code
+
+enum E {
+       FOO
+}
+
+void main () {
+}
diff --git a/tests/objects/class-gtype-too-short.test b/tests/objects/class-gtype-too-short.test
new file mode 100644
index 000000000..de346c0aa
--- /dev/null
+++ b/tests/objects/class-gtype-too-short.test
@@ -0,0 +1,7 @@
+Invalid Code
+
+class C {
+}
+
+void main () {
+}
diff --git a/tests/objects/interface-gtype-too-short.test b/tests/objects/interface-gtype-too-short.test
new file mode 100644
index 000000000..6a13b8cf7
--- /dev/null
+++ b/tests/objects/interface-gtype-too-short.test
@@ -0,0 +1,7 @@
+Invalid Code
+
+interface I {
+}
+
+void main () {
+}
diff --git a/tests/structs/struct-gtype-too-short.test b/tests/structs/struct-gtype-too-short.test
new file mode 100644
index 000000000..a260d155e
--- /dev/null
+++ b/tests/structs/struct-gtype-too-short.test
@@ -0,0 +1,8 @@
+Invalid Code
+
+struct S {
+       public int i;
+}
+
+void main () {
+}


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