]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Check required length of enum type name for GType support
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 17 Nov 2021 20:26:39 +0000 (21:26 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 18 Nov 2021 19:45:24 +0000 (20:45 +0100)
Add corresponding tests for types which have support for GType

codegen/valaccodestructmodule.vala
codegen/valagtypemodule.vala
tests/Makefile.am
tests/enums/enum-gtype-too-short.test [new file with mode: 0644]
tests/objects/class-gtype-too-short.test [new file with mode: 0644]
tests/objects/interface-gtype-too-short.test [new file with mode: 0644]
tests/structs/bug764041.test [deleted file]
tests/structs/struct-gtype-too-short.test [new file with mode: 0644]

index 5042698cd82a1b0006030cb821a9fe85d43a6118..c82b79671479ee845c691cd347dfb0f478352aad 100644 (file)
@@ -143,12 +143,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 ();
 
index e97aeb1dfeec1bbc42c078a2de3607451787ac5b..bb78d025a93d3f2923e6b43d2d8c11841d5d56c7 100644 (file)
@@ -2316,6 +2316,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);
@@ -2328,6 +2334,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);
index 1fb4e1d1ac21d5b9c385d0ca7c8d7f2482e7a868..cf7198fa4069973f135bf3a4f8f595bdb5b46e50 100644 (file)
@@ -324,6 +324,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 \
@@ -343,6 +344,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 \
@@ -391,7 +393,6 @@ TESTS = \
        structs/bug690380.vala \
        structs/bug694140.vala \
        structs/bug749952.vala \
-       structs/bug764041.test \
        structs/bug775761.vala \
        structs/bug777194.vala \
        structs/bug777194-2.vala \
@@ -441,6 +442,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 \
@@ -472,6 +474,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 (file)
index 0000000..b897ab5
--- /dev/null
@@ -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 (file)
index 0000000..de346c0
--- /dev/null
@@ -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 (file)
index 0000000..6a13b8c
--- /dev/null
@@ -0,0 +1,7 @@
+Invalid Code
+
+interface I {
+}
+
+void main () {
+}
diff --git a/tests/structs/bug764041.test b/tests/structs/bug764041.test
deleted file mode 100644 (file)
index 1911cda..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-Invalid Code
-
-struct N {
-       public int i;
-}
-
-void main() {
-       N n = { 42 };
-       Value v = n;
-}
diff --git a/tests/structs/struct-gtype-too-short.test b/tests/structs/struct-gtype-too-short.test
new file mode 100644 (file)
index 0000000..a260d15
--- /dev/null
@@ -0,0 +1,8 @@
+Invalid Code
+
+struct S {
+       public int i;
+}
+
+void main () {
+}