[vala/staging] codegen: Create alternative for G_N_ELEMENTS in POSIX profile
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] codegen: Create alternative for G_N_ELEMENTS in POSIX profile
- Date: Sat, 19 Oct 2019 13:25:57 +0000 (UTC)
commit bf3fd54c105907bb517bf8811c3dd46903c0c4cc
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sat Oct 19 15:15:42 2019 +0200
codegen: Create alternative for G_N_ELEMENTS in POSIX profile
codegen/valaccodebasemodule.vala | 5 +++++
codegen/valaccodememberaccessmodule.vala | 8 +++++++-
2 files changed, 12 insertions(+), 1 deletion(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 849e3ac2b..873f1ad34 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -344,6 +344,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
public bool requires_array_free;
public bool requires_array_move;
public bool requires_array_length;
+ public bool requires_array_n_elements;
public bool requires_clear_mutex;
public Set<string> wrappers;
@@ -773,6 +774,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
requires_array_free = false;
requires_array_move = false;
requires_array_length = false;
+ requires_array_n_elements = false;
requires_clear_mutex = false;
wrappers = new HashSet<string> (str_hash, str_equal);
@@ -807,6 +809,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
if (requires_array_length) {
append_vala_array_length ();
}
+ if (requires_array_n_elements) {
+ cfile.add_type_declaration (new CCodeMacroReplacement.with_expression
("VALA_N_ELEMENTS(arr)", new CCodeConstant ("(sizeof (arr) / sizeof ((arr)[0]))")));
+ }
if (requires_clear_mutex) {
append_vala_clear_mutex ("GMutex", "g_mutex");
append_vala_clear_mutex ("GRecMutex", "g_rec_mutex");
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 3b8933d04..7674402ca 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -165,7 +165,13 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
if (array_type != null) {
string sub = "";
for (int i = 0; i < array_type.rank; i++) {
- var ccall = new CCodeFunctionCall (new CCodeIdentifier
("G_N_ELEMENTS"));
+ CCodeFunctionCall ccall;
+ if (context.profile == Profile.POSIX) {
+ requires_array_n_elements = true;
+ ccall = new CCodeFunctionCall (new CCodeIdentifier
("VALA_N_ELEMENTS"));
+ } else {
+ ccall = new CCodeFunctionCall (new CCodeIdentifier
("G_N_ELEMENTS"));
+ }
ccall.add_argument (new CCodeIdentifier (get_ccode_name (c) + sub));
append_array_length (expr, ccall);
sub += "[0]";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]