From: Rico Tzschichholz Date: Wed, 30 Nov 2016 18:27:17 +0000 (+0100) Subject: methodcall: Don't try to remove N_/NC_ while they are properly handled in C X-Git-Tag: 0.35.2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a75f2461db03198d624410434d253dee502c65d7;p=thirdparty%2Fvala.git methodcall: Don't try to remove N_/NC_ while they are properly handled in C This avoids messing around with the ownership and properly invokes copying if needed. https://bugzilla.gnome.org/show_bug.cgi?id=642350 --- diff --git a/tests/Makefile.am b/tests/Makefile.am index c94096d54..ba8895135 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 000000000..e2edffbbc --- /dev/null +++ b/tests/methods/bug642350.vala @@ -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"); +} diff --git a/tests/testrunner.sh b/tests/testrunner.sh index aecc847fe..3d680c7fb 100755 --- a/tests/testrunner.sh +++ b/tests/testrunner.sh @@ -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" diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala index 7bf0e49c3..4e9d474da 100644 --- a/vala/valamethodcall.vala +++ b/vala/valamethodcall.vala @@ -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);