Skip to content
Prev Previous commit
Next Next commit
Keep using G_N_ELEMENTS in mono
  • Loading branch information
am11 committed Nov 23, 2021
commit 350dd4ff6e2deea92e887fb0b025516331c19650
30 changes: 15 additions & 15 deletions src/mono/mono/component/debugger-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -9952,63 +9952,63 @@ cmd_to_string (CommandSet set, int command)
switch (set) {
case CMD_SET_VM:
cmds = vm_cmds_str;
cmds_len = ARRAY_SIZE (vm_cmds_str);
cmds_len = G_N_ELEMENTS (vm_cmds_str);
break;
case CMD_SET_OBJECT_REF:
cmds = object_cmds_str;
cmds_len = ARRAY_SIZE (object_cmds_str);
cmds_len = G_N_ELEMENTS (object_cmds_str);
break;
case CMD_SET_STRING_REF:
cmds = string_cmds_str;
cmds_len = ARRAY_SIZE (string_cmds_str);
cmds_len = G_N_ELEMENTS (string_cmds_str);
break;
case CMD_SET_THREAD:
cmds = thread_cmds_str;
cmds_len = ARRAY_SIZE (thread_cmds_str);
cmds_len = G_N_ELEMENTS (thread_cmds_str);
break;
case CMD_SET_ARRAY_REF:
cmds = array_cmds_str;
cmds_len = ARRAY_SIZE (array_cmds_str);
cmds_len = G_N_ELEMENTS (array_cmds_str);
break;
case CMD_SET_EVENT_REQUEST:
cmds = event_cmds_str;
cmds_len = ARRAY_SIZE (event_cmds_str);
cmds_len = G_N_ELEMENTS (event_cmds_str);
break;
case CMD_SET_STACK_FRAME:
cmds = stack_frame_cmds_str;
cmds_len = ARRAY_SIZE (stack_frame_cmds_str);
cmds_len = G_N_ELEMENTS (stack_frame_cmds_str);
break;
case CMD_SET_APPDOMAIN:
cmds = appdomain_cmds_str;
cmds_len = ARRAY_SIZE (appdomain_cmds_str);
cmds_len = G_N_ELEMENTS (appdomain_cmds_str);
break;
case CMD_SET_ASSEMBLY:
cmds = assembly_cmds_str;
cmds_len = ARRAY_SIZE (assembly_cmds_str);
cmds_len = G_N_ELEMENTS (assembly_cmds_str);
break;
case CMD_SET_METHOD:
cmds = method_cmds_str;
cmds_len = ARRAY_SIZE (method_cmds_str);
cmds_len = G_N_ELEMENTS (method_cmds_str);
break;
case CMD_SET_TYPE:
cmds = type_cmds_str;
cmds_len = ARRAY_SIZE (type_cmds_str);
cmds_len = G_N_ELEMENTS (type_cmds_str);
break;
case CMD_SET_MODULE:
cmds = module_cmds_str;
cmds_len = ARRAY_SIZE (module_cmds_str);
cmds_len = G_N_ELEMENTS (module_cmds_str);
break;
case CMD_SET_FIELD:
cmds = field_cmds_str;
cmds_len = ARRAY_SIZE (field_cmds_str);
cmds_len = G_N_ELEMENTS (field_cmds_str);
break;
case CMD_SET_EVENT:
cmds = event_cmds_str;
cmds_len = ARRAY_SIZE (event_cmds_str);
cmds_len = G_N_ELEMENTS (event_cmds_str);
break;
case CMD_SET_POINTER:
cmds = pointer_cmds_str;
cmds_len = ARRAY_SIZE (pointer_cmds_str);
cmds_len = G_N_ELEMENTS (pointer_cmds_str);
break;
default:
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/eglib/ghashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ g_spaced_primes_closest (guint x)
{
int i;

for (i = 0; i < ARRAY_SIZE (prime_tbl); i++) {
for (i = 0; i < G_N_ELEMENTS (prime_tbl); i++) {
if (x <= prime_tbl [i])
return prime_tbl [i];
}
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/eglib/giconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ g_iconv_open (const char *to_charset, const char *from_charset)
return (GIConv) -1;
}

for (i = 0; i < ARRAY_SIZE (charsets); i++) {
for (i = 0; i < G_N_ELEMENTS (charsets); i++) {
if (!g_ascii_strcasecmp (charsets[i].name, from_charset))
decoder = charsets[i].decoder;

Expand Down
1 change: 1 addition & 0 deletions src/mono/mono/eglib/glib.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ typedef guint32 gunichar;
/*
* Macros
*/
#define G_N_ELEMENTS(s) ARRAY_SIZE(s)

#define FALSE 0
#define TRUE 1
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/eglib/gmodule-win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ g_module_address (void *addr, char *file_name, size_t file_name_len,
if (file_name != NULL && file_name_len >= 1) {
/* sigh, non-const. AIX for POSIX is the same way. */
WCHAR fname [MAX_PATH];
DWORD bytes = GetModuleFileNameW (module, fname, ARRAY_SIZE (fname));
DWORD bytes = GetModuleFileNameW (module, fname, G_N_ELEMENTS (fname));
if (bytes) {
/* Convert back to UTF-8 from wide for runtime */
GFixedBufferCustomAllocatorData custom_alloc_data;
Expand Down
16 changes: 8 additions & 8 deletions src/mono/mono/eglib/test/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ test_module_get_module_filename (void)
#if _WIN32
const HMODULE mods [ ] = {NULL, LoadLibraryW (L"msvcrt.dll"), (HMODULE)(gssize)-1 };

for (int i = 0; i < ARRAY_SIZE (mods); ++i) {
for (int i = 0; i < G_N_ELEMENTS (mods); ++i) {
const HMODULE mod = mods [i];
for (int j = 0; j <= 2; ++j) {
wchar_t* str = { 0 };
Expand All @@ -89,21 +89,21 @@ test_module_get_module_filename (void)
switch (j) {
case 0:
success = mono_get_module_filename (mod, &str, &length);
length2 = GetModuleFileNameW (mod, buf2, ARRAY_SIZE (buf2)); // large buf
length2 = GetModuleFileNameW (mod, buf2, G_N_ELEMENTS (buf2)); // large buf
length3 = GetModuleFileNameW (mod, buf3, 1); // small buf
break;
case 1:
success = mono_get_module_filename_ex (GetCurrentProcess (), mods [i], &str, &length);
length2 = GetModuleFileNameExW (GetCurrentProcess (), mod, buf2, ARRAY_SIZE (buf2)); // large buf
length2 = GetModuleFileNameExW (GetCurrentProcess (), mod, buf2, G_N_ELEMENTS (buf2)); // large buf
length3 = GetModuleFileNameExW (GetCurrentProcess (), mod, buf3, 1); // small buf
break;
case 2:
success = mono_get_module_basename (GetCurrentProcess (), mod, &str, &length);
length2 = GetModuleBaseNameW (GetCurrentProcess (), mod, buf2, ARRAY_SIZE (buf2)); // large buf
length2 = GetModuleBaseNameW (GetCurrentProcess (), mod, buf2, G_N_ELEMENTS (buf2)); // large buf
length3 = GetModuleBaseNameW (GetCurrentProcess (), mod, buf3, 1); // small buf
break;
}
success2 = length2 && length2 < ARRAY_SIZE (buf2);
success2 = length2 && length2 < G_N_ELEMENTS (buf2);
success3 = length3 == 1;
printf ("j:%d s:%X s2:%X s3:%X l:%u l2:%u l3:%u str:%X b2:%X b3:%X\n",
j,
Expand Down Expand Up @@ -137,10 +137,10 @@ test_get_current_directory (void)
guint32 length = { 0 };
gboolean success = mono_get_current_directory (&str, &length);
wchar_t buf2 [999] = { 0 };
const int length2 = GetCurrentDirectoryW (ARRAY_SIZE (buf2), buf2);
const gboolean success2 = length2 && length2 < ARRAY_SIZE (buf2);
const int length2 = GetCurrentDirectoryW (G_N_ELEMENTS (buf2), buf2);
const gboolean success2 = length2 && length2 < G_N_ELEMENTS (buf2);
wchar_t buf3 [2] = { 0 };
const int length3 = GetCurrentDirectoryW (ARRAY_SIZE (buf3), buf3);
const int length3 = GetCurrentDirectoryW (G_N_ELEMENTS (buf3), buf3);
const gboolean success3 = length3 > 0;
printf ("s:%X s2:%X s3:%X str:%X b2:%X b3:%X\n", success, success2, success3, str ? str [0] : 0, buf2 [0], buf3 [0]);
g_assert (length == length2);
Expand Down
16 changes: 8 additions & 8 deletions src/mono/mono/eglib/test/utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,10 @@ test_convert (void)
if (!(srcdir = getenv ("srcdir")) && !(srcdir = getenv ("PWD")))
return FAILED ("srcdir not defined!");

expected = g_malloc (sizeof (convert_result_t *) * ARRAY_SIZE (charsets));
expected = g_malloc (sizeof (convert_result_t *) * G_N_ELEMENTS (charsets));

/* first load all our test samples... */
for (i = 0; i < ARRAY_SIZE (charsets); i++) {
for (i = 0; i < G_N_ELEMENTS (charsets); i++) {
path = g_strdup_printf ("%s%c%s.txt", srcdir, G_DIR_SEPARATOR, charsets[i]);
loaded = g_file_get_contents (path, &content, &length, &err);
g_free (path);
Expand All @@ -341,13 +341,13 @@ test_convert (void)
}

/* test conversion from every charset to every other charset */
for (i = 0; i < ARRAY_SIZE (charsets); i++) {
for (j = 0; j < ARRAY_SIZE (charsets); j++) {
for (i = 0; i < G_N_ELEMENTS (charsets); i++) {
for (j = 0; j < G_N_ELEMENTS (charsets); j++) {
converted = g_convert (expected[i]->content, expected[i]->length, charsets[j],
charsets[i], NULL, &converted_length, NULL);

if (converted == NULL) {
for (k = 0; k < ARRAY_SIZE (charsets); k++) {
for (k = 0; k < G_N_ELEMENTS (charsets); k++) {
g_free (expected[k]->content);
g_free (expected[k]);
}
Expand All @@ -360,7 +360,7 @@ test_convert (void)
if (converted_length != expected[j]->length) {
length = expected[j]->length;

for (k = 0; k < ARRAY_SIZE (charsets); k++) {
for (k = 0; k < G_N_ELEMENTS (charsets); k++) {
g_free (expected[k]->content);
g_free (expected[k]);
}
Expand All @@ -376,7 +376,7 @@ test_convert (void)
if (converted[n] != expected[j]->content[n]) {
c = expected[j]->content[n];

for (k = 0; k < ARRAY_SIZE (charsets); k++) {
for (k = 0; k < G_N_ELEMENTS (charsets); k++) {
g_free (expected[k]->content);
g_free (expected[k]);
}
Expand All @@ -393,7 +393,7 @@ test_convert (void)
}
}

for (k = 0; k < ARRAY_SIZE (charsets); k++) {
for (k = 0; k < G_N_ELEMENTS (charsets); k++) {
g_free (expected[k]->content);
g_free (expected[k]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/assembly.c
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ static void
remap_keys (MonoAssemblyName *aname)
{
int i;
for (i = 0; i < ARRAY_SIZE (key_remap_table); i++) {
for (i = 0; i < G_N_ELEMENTS (key_remap_table); i++) {
const KeyRemapEntry *entry = &key_remap_table [i];

if (strcmp (aname->name, entry->name) ||
Expand Down
6 changes: 3 additions & 3 deletions src/mono/mono/metadata/components.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,23 @@ mono_components_init (void)
* to pass us the address of each component that isn't disabled.
*
*/
for (int i = 0; i < ARRAY_SIZE (components); ++i)
for (int i = 0; i < G_N_ELEMENTS (components); ++i)
*components [i].component = components [i].init ();
#else
component_library_load_history = g_hash_table_new (g_str_hash, g_str_equal);

/* call get_component for each component and init it or its stubs and add it to loaded_components */
MonoComponentLibrary *component_lib = NULL;

for (int i = 0; i < ARRAY_SIZE (components); ++i) {
for (int i = 0; i < G_N_ELEMENTS (components); ++i) {
*components [i].component = get_component (&components [i], &component_lib);
components [i].lib = component_lib;
if (!*components [i].component)
*components [i].component = components [i].init ();
}
#endif
/* validate components interface version */
for (int i = 0; i < ARRAY_SIZE (components); ++i) {
for (int i = 0; i < G_N_ELEMENTS (components); ++i) {
guint64 version = (guint64)(*components [i].component)->itf_version;
g_assertf (version == MONO_COMPONENT_ITF_VERSION, "%s component returned unexpected interface version (expected %" PRIu64 " got %" PRIu64 ")", components [i].name, (guint64)MONO_COMPONENT_ITF_VERSION, version);
}
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ static const MonoRuntimeInfo*
get_runtime_by_version (const char *version)
{
int n;
int max = ARRAY_SIZE (supported_runtimes);
int max = G_N_ELEMENTS (supported_runtimes);
int vlen;

if (!version)
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/icall.c
Original file line number Diff line number Diff line change
Expand Up @@ -7296,7 +7296,7 @@ mono_create_icall_signatures (void)
gsize_a *types = (gsize_a*)(sig + 1);
for (int i = 0; i < n; ++i) {
gsize index = *types++;
g_assert (index < ARRAY_SIZE (lookup));
g_assert (index < G_N_ELEMENTS (lookup));
// Casts on next line are attempt to follow strict aliasing rules,
// to ensure reading from *types precedes writing
// to params [].
Expand Down
4 changes: 2 additions & 2 deletions src/mono/mono/metadata/metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -1962,7 +1962,7 @@ mono_metadata_init (void)

type_cache = g_hash_table_new (mono_type_hash, mono_type_equal);

for (i = 0; i < ARRAY_SIZE (builtin_types); ++i)
for (i = 0; i < G_N_ELEMENTS (builtin_types); ++i)
g_hash_table_insert (type_cache, (gpointer) &builtin_types [i], (gpointer) &builtin_types [i]);

mono_metadata_update_init ();
Expand Down Expand Up @@ -4087,7 +4087,7 @@ mono_metadata_free_type (MonoType *type)
{
/* Note: keep in sync with do_mono_metadata_parse_type and try_get_canonical_type which
* allocate memory or try to avoid allocating memory. */
if (type >= builtin_types && type < builtin_types + ARRAY_SIZE (builtin_types))
if (type >= builtin_types && type < builtin_types + G_N_ELEMENTS (builtin_types))
return;

switch (type->type){
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/mono-perfcounters.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ static int
perfctr_type_compress (int type)
{
int i;
for (i = 0; i < ARRAY_SIZE (simple_type_to_type); ++i) {
for (i = 0; i < G_N_ELEMENTS (simple_type_to_type); ++i) {
if (simple_type_to_type [i] == type)
return i;
}
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/native-library-qcall.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ static Entry mono_qcalls[] =
gpointer
mono_lookup_pinvoke_qcall_internal (const char *name)
{
return (gpointer)minipal_resolve_dllimport(mono_qcalls, ARRAY_SIZE(mono_qcalls), name);
return (gpointer)minipal_resolve_dllimport(mono_qcalls, G_N_ELEMENTS(mono_qcalls), name);
}
16 changes: 8 additions & 8 deletions src/mono/mono/mini/aot-compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -5867,7 +5867,7 @@ add_generic_instances (MonoAotCompile *acfg)
const char *enum_names [] = { "I8Enum", "I16Enum", "I32Enum", "I64Enum", "UI8Enum", "UI16Enum", "UI32Enum", "UI64Enum" };

ninsts = 0;
for (int i = 0; i < ARRAY_SIZE (enum_names); ++i) {
for (int i = 0; i < G_N_ELEMENTS (enum_names); ++i) {
k = mono_class_try_load_from_name (acfg->image, "Mono", enum_names [i]);
g_assert (k);
insts [ninsts ++] = m_class_get_byval_arg (k);
Expand Down Expand Up @@ -6621,7 +6621,7 @@ get_debug_sym (MonoMethod *method, const char *prefix, GHashTable *cache)

#if defined(TARGET_WIN32) && defined(TARGET_X86)
char adjustedPrefix [MAX_SYMBOL_SIZE];
prefix = mangle_symbol (prefix, adjustedPrefix, ARRAY_SIZE (adjustedPrefix));
prefix = mangle_symbol (prefix, adjustedPrefix, G_N_ELEMENTS (adjustedPrefix));
#endif

len = strlen (name1);
Expand Down Expand Up @@ -11892,7 +11892,7 @@ codeview_parse_compiler_version (gchar *version, CodeViewCompilerVersion *data)
gint values[4] = { 0 };
gint *value = values;

while (*version && (value < values + ARRAY_SIZE (values))) {
while (*version && (value < values + G_N_ELEMENTS (values))) {
if (isdigit (*version)) {
*value *= 10;
*value += *version - '0';
Expand Down Expand Up @@ -12070,8 +12070,8 @@ emit_codeview_info (MonoAotCompile *acfg)
if (!cfg || COMPILE_LLVM (cfg))
continue;

int ret = g_snprintf (symbol_buffer, ARRAY_SIZE (symbol_buffer), "%sme_%x", acfg->temp_prefix, i);
if (ret > 0 && ret < ARRAY_SIZE (symbol_buffer))
int ret = g_snprintf (symbol_buffer, G_N_ELEMENTS (symbol_buffer), "%sme_%x", acfg->temp_prefix, i);
if (ret > 0 && ret < G_N_ELEMENTS (symbol_buffer))
emit_codeview_function_info (acfg, cfg->method, &section_id, cfg->asm_debug_symbol, cfg->asm_symbol, symbol_buffer);
}
}
Expand Down Expand Up @@ -13512,7 +13512,7 @@ add_preinit_got_slots (MonoAotCompile *acfg)
ji->data.jit_icall_id = MONO_JIT_ICALL_mono_threads_attach_coop;
add_preinit_slot (acfg, ji);

for (i = 0; i < ARRAY_SIZE (preinited_jit_icalls); ++i) {
for (i = 0; i < G_N_ELEMENTS (preinited_jit_icalls); ++i) {
ji = (MonoJumpInfo *)mono_mempool_alloc0 (acfg->mempool, sizeof (MonoJumpInfo));
ji->type = MONO_PATCH_INFO_JIT_ICALL_ID;
ji->data.jit_icall_id = preinited_jit_icalls [i];
Expand Down Expand Up @@ -14190,10 +14190,10 @@ mono_compile_assembly (MonoAssembly *ass, guint32 opts, const char *aot_options,
add_method (acfg, wrapper);

#ifndef MONO_ARCH_HAVE_INTERP_ENTRY_TRAMPOLINE
for (int i = 0; i < ARRAY_SIZE (interp_in_static_sigs); i++)
for (int i = 0; i < G_N_ELEMENTS (interp_in_static_sigs); i++)
add_interp_in_wrapper_for_sig (acfg, *interp_in_static_sigs [i]);
#else
for (int i = 0; i < ARRAY_SIZE (interp_in_static_common_sigs); i++)
for (int i = 0; i < G_N_ELEMENTS (interp_in_static_common_sigs); i++)
add_interp_in_wrapper_for_sig (acfg, *interp_in_static_common_sigs [i]);
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/aot-runtime-wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ mono_wasm_get_interp_to_native_trampoline (MonoMethodSignature *sig)
}
cookie [c_count] = 0;

void *p = bsearch (cookie, interp_to_native_signatures, ARRAY_SIZE (interp_to_native_signatures), sizeof (gpointer), compare_icall_tramp);
void *p = bsearch (cookie, interp_to_native_signatures, G_N_ELEMENTS (interp_to_native_signatures), sizeof (gpointer), compare_icall_tramp);
if (!p)
g_error ("CANNOT HANDLE INTERP ICALL SIG %s\n", cookie);
int idx = (const char**)p - (const char**)interp_to_native_signatures;
Expand Down
Loading