]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
methodcall: Don't try to remove N_/NC_ while they are properly handled in C
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 30 Nov 2016 18:27:17 +0000 (19:27 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 30 Nov 2016 22:47:53 +0000 (23:47 +0100)
This avoids messing around with the ownership and properly invokes copying
if needed.

https://bugzilla.gnome.org/show_bug.cgi?id=642350

tests/Makefile.am
tests/methods/bug642350.vala [new file with mode: 0644]
tests/testrunner.sh
vala/valamethodcall.vala

index c94096d540472cd28a9e931ff40667fb136f83d8..ba8895135cf66724a7b8dec5e5bd31051526e830 100644 (file)
@@ -59,6 +59,7 @@ TESTS = \
        methods/bug622570.vala \
        methods/bug626783.vala \
        methods/bug639054.vala \
+       methods/bug642350.vala \
        methods/bug642885.vala \
        methods/bug642899.vala \
        methods/bug646345.vala \
diff --git a/tests/methods/bug642350.vala b/tests/methods/bug642350.vala
new file mode 100644 (file)
index 0000000..e2edffb
--- /dev/null
@@ -0,0 +1,52 @@
+const string[] FOO = { N_ ("foo"), NC_ ("valac", "bar") };
+const string BAZ = N_ ("bar");
+
+struct Foo {
+       public string foo;
+       public unowned string bar;
+}
+
+class Bar : Object {
+       public static string foo = N_ ("foo");
+       public string bar { get { return N_ ("bar"); } }
+       public string get_baz () { return N_ ("baz"); }
+}
+
+const Foo STRUCT = { "foo", N_ ("bar") };
+
+void main () {
+       assert (FOO[1] == "bar");
+       assert (BAZ == "bar");
+       assert (STRUCT.bar == "bar");
+
+       const string[] LOCAL_FOO = { N_ ("foo"), N_ ("bar") };
+       assert (LOCAL_FOO[1] == "bar");
+       const string LOCAL_BAZ = N_ ("bar");
+       assert (LOCAL_BAZ == "bar");
+       const Foo LOCAL_STRUCT = { "foo", N_ ("bar") };
+       assert (LOCAL_STRUCT.bar == "bar");
+
+       Foo f = { N_ ("foo"), NC_ ("valac", "bar") };
+       assert (f.foo == "foo");
+       assert (f.bar == "bar");
+
+       Bar b = new Bar ();
+       assert (b.foo == "foo");
+       assert (b.bar == "bar");
+       assert (b.get_baz () == "baz");
+
+       string s1 = N_ ("bar");
+       assert (s1 == "bar");
+       s1 = N_ (s1);
+       assert (s1 == "bar");
+
+       unowned string s2 = N_ ("bar");
+       assert (s2 == "bar");
+       s2 = N_ (s2);
+       assert (s2 == "bar");
+
+       string[] a1 = FOO;
+       assert (a1[1] == "bar");
+       unowned string[] a2 = FOO;
+       assert (a2[0] == "foo");
+}
index aecc847fe5d6178391864feadfe540da1ec93121..3d680c7fb2ea9faf1f514f78741aef6f209f5b91 100755 (executable)
@@ -29,7 +29,7 @@ vapidir=$topsrcdir/vapi
 export G_DEBUG=fatal_warnings
 
 VALAC=$topbuilddir/compiler/valac$EXEEXT
-VALAFLAGS="--vapidir $vapidir --disable-warnings --main main --save-temps -X -g -X -O0 -X -pipe -X -lm -X -Werror=return-type -X -Werror=init-self -X -Werror=implicit -X -Werror=sequence-point -X -Werror=return-type -X -Werror=uninitialized -X -Werror=pointer-arith -X -Werror=int-to-pointer-cast -X -Werror=pointer-to-int-cast -X -Wformat -X -Werror=format-security -X -Werror=format-nonliteral -X -Werror=redundant-decls"
+VALAFLAGS="--vapidir $vapidir --disable-warnings --main main --save-temps -X -g -X -O0 -X -pipe -X -lm -X -DGETTEXT_PACKAGE=valac -X -Werror=return-type -X -Werror=init-self -X -Werror=implicit -X -Werror=sequence-point -X -Werror=return-type -X -Werror=uninitialized -X -Werror=pointer-arith -X -Werror=int-to-pointer-cast -X -Werror=pointer-to-int-cast -X -Wformat -X -Werror=format-security -X -Werror=format-nonliteral -X -Werror=redundant-decls"
 VAPIGEN=$topbuilddir/vapigen/vapigen$EXEEXT
 VAPIGENFLAGS="--vapidir $vapidir"
 
index 7bf0e49c3b5a526d0491fd2fc58c96f850d49b13..4e9d474dae9ca2a2fa8a7811fb1c0f64f107010b 100644 (file)
@@ -672,25 +672,6 @@ public class Vala.MethodCall : Expression {
        public override void emit (CodeGenerator codegen) {
                var method_type = call.value_type as MethodType;
 
-               if (method_type != null) {
-                       // N_ and NC_ do not have any effect on the C code,
-                       // they are only interpreted by xgettext
-                       // this means that it is ok to use them in constant initializers
-                       // however, we must avoid generating regular method call code
-                       // as that may include temporary variables
-                       if (method_type.method_symbol.get_full_name () == "GLib.N_") {
-                               // first argument is string
-                               argument_list[0].emit (codegen);
-                               this.target_value = argument_list[0].target_value;
-                               return;
-                       } else if (method_type.method_symbol.get_full_name () == "GLib.NC_") {
-                               // second argument is string
-                               argument_list[1].emit (codegen);
-                               this.target_value = argument_list[1].target_value;
-                               return;
-                       }
-               }
-
                if (method_type != null && method_type.method_symbol.parent_symbol is Signal) {
                        var signal_access = ((MemberAccess) call).inner;
                        signal_access.emit (codegen);