[vala/staging] codegen: Don't write declaration of extern symbols with given header
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] codegen: Don't write declaration of extern symbols with given header
- Date: Sat, 10 Nov 2018 12:33:03 +0000 (UTC)
commit 4a1629f93e15d53b8ac4ddc71ec422b1c2af3a3c
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sun Jan 8 14:14:42 2017 +0100
codegen: Don't write declaration of extern symbols with given header
The corresponding header will provide the declaration and therefore fix
build with -Werror=redundant-decls.
Set cheader_filename for implicit to_string() method of enums which is
transformed into symbol calls from glib-object.h. This avoids the leak of
an superfluous prototype of that method into the generated c code.
codegen/valaccodeattribute.vala | 4 ++--
codegen/valaccodebasemodule.vala | 8 ++++----
tests/Makefile.am | 1 +
tests/methods/extern.vala | 27 +++++++++++++++++++++++++++
vala/valaenumvaluetype.vala | 1 +
5 files changed, 35 insertions(+), 6 deletions(-)
---
diff --git a/codegen/valaccodeattribute.vala b/codegen/valaccodeattribute.vala
index 3740d232a..16b0d99cc 100644
--- a/codegen/valaccodeattribute.vala
+++ b/codegen/valaccodeattribute.vala
@@ -793,13 +793,13 @@ public class Vala.CCodeAttribute : AttributeCache {
if (sym is DynamicProperty || sym is DynamicMethod) {
return "";
}
- if (sym.parent_symbol != null) {
+ if (sym.parent_symbol != null && ((!sym.external_package && !sym.external) ||
sym.parent_symbol.external_package)) {
var parent_headers = get_ccode_header_filenames (sym.parent_symbol);
if (parent_headers.length > 0) {
return parent_headers;
}
}
- if (sym.source_reference != null && !sym.external_package) {
+ if (sym.source_reference != null && !sym.external_package && !sym.external) {
// don't add default include directives for VAPI files
return sym.source_reference.file.get_cinclude_filename ();
}
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 394d710e1..a45cdeb9d 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -629,16 +629,16 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
if (sym.anonymous) {
return !decl_space.is_header && CodeContext.get ().use_header;
}
- if (sym.external_package || (!decl_space.is_header && CodeContext.get ().use_header &&
!sym.is_internal_symbol ())) {
+ if (sym.external_package || (!decl_space.is_header && CodeContext.get ().use_header &&
!sym.is_internal_symbol ())
+ || (sym.external && !sym.external_package && get_ccode_header_filenames (sym).length >
0)) {
// add feature test macros
foreach (unowned string feature_test_macro in get_ccode_feature_test_macros
(sym).split (",")) {
decl_space.add_feature_test_macro (feature_test_macro);
}
// add appropriate include file
foreach (unowned string header_filename in get_ccode_header_filenames (sym).split
(",")) {
- decl_space.add_include (header_filename, !sym.external_package ||
- (sym.external_package &&
- sym.from_commandline));
+ decl_space.add_include (header_filename,
+ !sym.external && (!sym.external_package || (sym.external_package &&
sym.from_commandline)));
}
// declaration complete
return true;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b84d952a6..00ebc97ce 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -84,6 +84,7 @@ TESTS = \
methods/lambda.vala \
methods/closures.vala \
methods/contains.vala \
+ methods/extern.vala \
methods/iterator.vala \
methods/prepostconditions.vala \
methods/same-name.vala \
diff --git a/tests/methods/extern.vala b/tests/methods/extern.vala
new file mode 100644
index 000000000..5e99478b7
--- /dev/null
+++ b/tests/methods/extern.vala
@@ -0,0 +1,27 @@
+[CCode (cname = "g_strdup", cheader_filename = "glib.h")]
+extern string strdup (string s);
+
+[CCode (cname = "vala_some_thing")]
+extern void some_thing ();
+
+namespace Foo {
+ [CCode (cname = "g_strdup", cheader_filename = "glib.h")]
+ extern string strdup (string s);
+
+ [CCode (cname = "vala_some_thing")]
+ extern void some_thing ();
+}
+
+public class Bar {
+ [CCode (cname = "g_strdup", cheader_filename = "glib.h")]
+ public static extern string strdup (string s);
+
+ [CCode (cname = "vala_some_thing")]
+ public static extern void some_thing ();
+}
+
+void main () {
+ assert ("foo" == strdup ("foo"));
+ assert ("foo" == Foo.strdup ("foo"));
+ assert ("foo" == Bar.strdup ("foo"));
+}
diff --git a/vala/valaenumvaluetype.vala b/vala/valaenumvaluetype.vala
index c409763fe..ef44103ac 100644
--- a/vala/valaenumvaluetype.vala
+++ b/vala/valaenumvaluetype.vala
@@ -48,6 +48,7 @@ public class Vala.EnumValueType : ValueType {
to_string_method = new Method ("to_string", string_type);
to_string_method.access = SymbolAccessibility.PUBLIC;
to_string_method.external = true;
+ to_string_method.set_attribute_string ("CCode", "cheader_filename", "glib-object.h");
to_string_method.owner = type_symbol.scope;
to_string_method.this_parameter = new Parameter ("this", this);
to_string_method.scope.add (to_string_method.this_parameter.name,
to_string_method.this_parameter);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]