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;
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);
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");
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]";