Skip to content

Commit 258ef54

Browse files
committed
replace ARR_COUNT with countof
see also recent commit 951f964 countof seem to be upcoming C2Y language macro (and _Countof operator) so make use of it instead of ARR_COUNT that is now removed.
1 parent ff7a29d commit 258ef54

File tree

12 files changed

+46
-47
lines changed

12 files changed

+46
-47
lines changed

src/audio/capture/fluidsynth.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author Martin Pulec <pulec@cesnet.cz>
44
*/
55
/*
6-
* Copyright (c) 2025 CESNET
6+
* Copyright (c) 2025-2026 CESNET, zájmové sdružení právnických osob
77
* All rights reserved.
88
*
99
* Redistribution and use in source and binary forms, with or without
@@ -56,7 +56,7 @@
5656
#include "types.h" // for device_info
5757
#include "utils/color_out.h" // for color_printf, TBOLD, TRED
5858
#include "utils/fs.h" // for get_install_root, get_temp_file
59-
#include "utils/macros.h" // for ARR_COUNT, IS_KEY_PREFIX
59+
#include "utils/macros.h" // for IS_KEY_PREFIX, countof
6060

6161
struct module;
6262

@@ -196,13 +196,13 @@ get_soundfont()
196196

197197
const char *force_bundled_sf = getenv("ULTRAGRID_BUNDLED_SF");
198198
if (force_bundled_sf != NULL && strcmp(force_bundled_sf, "1") == 0) {
199-
for (size_t i = ARR_COUNT(sf_candidates) - 1; i > 0; --i) {
199+
for (size_t i = countof(sf_candidates) - 1; i > 0; --i) {
200200
sf_candidates[i] = sf_candidates[i - 1];
201201
}
202202
sf_candidates[0] = bundled;
203203
}
204204

205-
for (size_t i = 0; i < ARR_COUNT(sf_candidates); ++i) {
205+
for (size_t i = 0; i < countof(sf_candidates); ++i) {
206206
const char *path = sf_candidates[i];
207207
FILE *f = fopen(path, "rb");
208208
debug_msg(MOD_NAME

src/blackmagic_common.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author Martin Pulec <pulec@cesnet.cz>
44
*/
55
/*
6-
* Copyright (c) 2014-2025 CESNET, zájmové sdružení právnických osob
6+
* Copyright (c) 2014-2026 CESNET, zájmové sdružení právnických osob
77
* All rights reserved.
88
*
99
* Redistribution and use in source and binary forms, with or without
@@ -66,7 +66,7 @@
6666
#include "tv.h"
6767
#include "utils/color_out.h"
6868
#include "utils/debug.h" // for DEBUG_TIMER_*
69-
#include "utils/macros.h"
69+
#include "utils/macros.h" // for countof
7070
#include "utils/string.h" // for DELDEL
7171
#include "utils/windows.h"
7272
#include "utils/worker.h"
@@ -786,12 +786,12 @@ static const struct {
786786
#undef BMDFCC
787787

788788
static string fcc_to_string(uint32_t fourcc) {
789-
for (unsigned i = 0; i < ARR_COUNT(opt_name_map); ++i) {
789+
for (unsigned i = 0; i < countof(opt_name_map); ++i) {
790790
if (opt_name_map[i].fourcc == fourcc) {
791791
return opt_name_map[i].name;
792792
}
793793
}
794-
for (unsigned i = 0; i < ARR_COUNT(val_name_map); ++i) {
794+
for (unsigned i = 0; i < countof(val_name_map); ++i) {
795795
if (val_name_map[i].fourcc == fourcc) {
796796
return val_name_map[i].name;
797797
}
@@ -936,7 +936,7 @@ bmd_opt_help()
936936
color_printf("\n");
937937

938938
color_printf("List of keys:\n");
939-
for (unsigned i = 0; i < ARR_COUNT(opt_name_map); ++i) {
939+
for (unsigned i = 0; i < countof(opt_name_map); ++i) {
940940
if (opt_name_map[i].fourcc == 0) {
941941
color_printf("\n%s:\n", opt_name_map[0].name);
942942
} else {
@@ -952,7 +952,7 @@ bmd_opt_help()
952952
color_printf("\n");
953953
color_printf("Incomplete " TBOLD("(!)") " list of values:\n");
954954
color_printf("(note that the value belongs to its appropriate key)\n");
955-
for (unsigned i = 0; i < ARR_COUNT(val_name_map); ++i) {
955+
for (unsigned i = 0; i < countof(val_name_map); ++i) {
956956
uint32_t val = htonl(val_name_map[i].fourcc);
957957
color_printf("- " TBOLD("%.4s") " - %s\n", (char *) &val,
958958
val_name_map[i].name);
@@ -1589,7 +1589,7 @@ print_status_item(IDeckLinkStatus *deckLinkStatus, BMDDeckLinkStatusID prop,
15891589
{
15901590
const struct status_property *s_prop = nullptr;
15911591

1592-
for (unsigned i = 0; i < ARR_COUNT(status_map); ++i) {
1592+
for (unsigned i = 0; i < countof(status_map); ++i) {
15931593
if (status_map[i].prop == prop) {
15941594
s_prop = &status_map[i];
15951595
break;
@@ -1835,7 +1835,7 @@ bmd_print_status_subscribe_notify(IDeckLink *deckLink, const char *log_prefix,
18351835
"Cannot obtain IID_IDeckLinkStatus from DeckLink",
18361836
return nullptr);
18371837
// print status_map values now
1838-
for (unsigned u = 0; u < ARR_COUNT(status_map); ++u) {
1838+
for (unsigned u = 0; u < countof(status_map); ++u) {
18391839
if (capture && status_map[u].playback_only) {
18401840
continue;
18411841
}

src/libavcodec/from_lavc_vid_conv.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @author Martin Piatka <445597@mail.muni.cz>
55
*/
66
/*
7-
* Copyright (c) 2013-2025 CESNET
7+
* Copyright (c) 2013-2026 CESNET, zájmové sdružení právnických osob
88
* All rights reserved.
99
*
1010
* Redistribution and use in source and binary forms, with or without
@@ -72,7 +72,7 @@
7272
#include "pixfmt_conv.h"
7373
#include "types.h"
7474
#include "utils/debug.h" // for DEBUG_TIMER_*
75-
#include "utils/macros.h" // OPTIMIZED_FOR
75+
#include "utils/macros.h" // for OPTIMIZED_FOR, countof
7676
#include "utils/misc.h" // get_cpu_core_count
7777
#include "utils/worker.h" // task_run_parallel
7878
#include "video.h"
@@ -3174,7 +3174,7 @@ int
31743174
from_lavc_pf_priority(struct pixfmt_desc internal, codec_t ugc)
31753175
{
31763176
bool found_a_conversion = false;
3177-
for (unsigned i = 0; i < ARR_COUNT(av_to_uv_conversions); i++) {
3177+
for (unsigned i = 0; i < countof(av_to_uv_conversions); i++) {
31783178
if (av_to_uv_conversions[i].uv_codec == ugc) {
31793179
found_a_conversion = true;
31803180
break;
@@ -3186,7 +3186,7 @@ from_lavc_pf_priority(struct pixfmt_desc internal, codec_t ugc)
31863186
if (internal.depth == 0) { // unspecified internal format
31873187
return VDEC_PRIO_LOW;
31883188
}
3189-
for (unsigned i = 0; i < ARR_COUNT(av_to_uv_conversions); i++) {
3189+
for (unsigned i = 0; i < countof(av_to_uv_conversions); i++) {
31903190
if (av_to_uv_conversions[i].uv_codec != ugc) {
31913191
continue;
31923192
}

src/module.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author Martin Pulec <pulec@cesnet.cz>
44
*/
55
/*
6-
* Copyright (c) 2013-2025 CESNET
6+
* Copyright (c) 2013-2026 CESNET, zájmové sdružení právnických osob
77
* All rights reserved.
88
*
99
* Redistribution and use in source and binary forms, with or without
@@ -50,7 +50,7 @@
5050
#include "debug.h"
5151
#include "messaging.h" // for check_message, free_message, ...
5252
#include "utils/list.h"
53-
#include "utils/macros.h" // for ARR_COUNT, to_fourcc
53+
#include "utils/macros.h" // for countof, to_fourcc
5454

5555
#define MOD_NAME "[module] "
5656
#define MODULE_MAGIC to_fourcc('M', 'O', 'D', ' ')
@@ -212,7 +212,7 @@ static const char *const module_class_name_pairs[] = {
212212

213213
const char *module_class_name(enum module_class cls)
214214
{
215-
if ((unsigned int) cls >= ARR_COUNT(module_class_name_pairs)) {
215+
if ((unsigned int) cls >= countof(module_class_name_pairs)) {
216216
MSG(ERROR, "No name for module class %d!\n", (int) cls);
217217
return NULL;
218218
}

src/utils/macros.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
#ifndef countof // defined in C2Y stdcountof.h
6565
#define countof(arr) (sizeof (arr) / sizeof (arr)[0])
6666
#endif
67-
#define ARR_COUNT(arr) countof(arr)
6867

6968
#undef MIN
7069
#define MIN(a,b) (((a)<(b))?(a):(b))

src/utils/opencl.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author Martin Pulec <martin.pulec@cesnet.cz>
44
*/
55
/*
6-
* Copyright (c) 2025 CESNET
6+
* Copyright (c) 2025-2026 CESNET, zájmové sdružení právnických osob
77
* All rights reserved.
88
*
99
* Redistribution and use in source and binary forms, with or without
@@ -60,7 +60,7 @@ ADD_TO_PARAM(PARAM_NAME, PARAM_HELP);
6060

6161
#include "compat/strings.h" // for strcasecmp
6262
#include "debug.h" // for MSG
63-
#include "utils/macros.h" // for ARR_COUNT, SHORT_STR
63+
#include "utils/macros.h" // for SHORT_STR, countof
6464
#include "utils/color_out.h" // for TBOLD
6565

6666
#define CHECK_OPENCL(cmd, errmsg, erraction) \
@@ -93,7 +93,7 @@ print_device_details(cl_device_id device)
9393
if (clGetDeviceInfo(device, CL_DEVICE_TYPE, sizeof device_type,
9494
&device_type, NULL) == CL_SUCCESS) {
9595
const char *type = "UNKNOWN";
96-
for (unsigned i = 0; i < ARR_COUNT(dev_type_map); ++i) {
96+
for (unsigned i = 0; i < countof(dev_type_map); ++i) {
9797
if (dev_type_map[i].cl_type == device_type) {
9898
type = dev_type_map[i].name;
9999
}
@@ -265,7 +265,7 @@ opencl_get_device(void **platform_id, void **device_id)
265265
CL_DEVICE_TYPE_GPU,
266266
CL_DEVICE_TYPE_CPU,
267267
CL_DEVICE_TYPE_ALL };
268-
for (unsigned i = 0; i < ARR_COUNT(try_type); i++) {
268+
for (unsigned i = 0; i < countof(try_type); i++) {
269269
if (get_device(try_type[i], 0, 0, platform_id,
270270
device_id)) {
271271
return true;
@@ -284,7 +284,7 @@ opencl_get_device(void **platform_id, void **device_id)
284284
req_device_idx = atoi(strchr(req_device, '-') + 1);
285285
}
286286
} else {
287-
for (unsigned i = 0; i < ARR_COUNT(dev_type_map); ++i) {
287+
for (unsigned i = 0; i < countof(dev_type_map); ++i) {
288288
if (strcasecmp(dev_type_map[i].name, req_device) == 0) {
289289
req_type = dev_type_map[i].cl_type;
290290
}

src/utils/video_pattern_generator.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
/*
1515
* Copyright (c) 2005-2006 University of Glasgow
16-
* Copyright (c) 2005-2025 CESNET, zájmové sdružení právnických osob
16+
* Copyright (c) 2005-2026 CESNET, zájmové sdružení právnických osob
1717
* All rights reserved.
1818
*
1919
* Redistribution and use in source and binary forms, with or without
@@ -66,7 +66,7 @@
6666
#include "ug_runtime_error.hpp"
6767
#include "utils/bitmap_font.h" // for FONT_H
6868
#include "utils/color_out.h"
69-
#include "utils/macros.h"
69+
#include "utils/macros.h" // for countof
7070
#include "utils/string_view_utils.hpp"
7171
#include "utils/text.h"
7272
#include "video.h"
@@ -129,7 +129,7 @@ get_color_by_name(const char *col)
129129
color_printf("Leading zeros can be omitted, eg. "
130130
"`0xFF` produces a red pattern.\n");
131131
color_printf("\nfollowing symbolic names can be also used:\n");
132-
for (unsigned i = 0; i < ARR_COUNT(colors); ++i) {
132+
for (unsigned i = 0; i < countof(colors); ++i) {
133133
color_printf("\t- " TBOLD("%s") "\n", colors[i].name);
134134
}
135135
color_printf("\n");
@@ -141,7 +141,7 @@ get_color_by_name(const char *col)
141141
if (errno == 0 && endptr[0] == '\0') {
142142
return (uint32_t) val;
143143
}
144-
for (unsigned i = 0; i < ARR_COUNT(colors); ++i) {
144+
for (unsigned i = 0; i < countof(colors); ++i) {
145145
if (strcasecmp(col, colors[i].name) == 0) {
146146
return 0xFFU << 24 | colors[i].val;
147147
}
@@ -555,7 +555,7 @@ struct image_pattern_strips : public image_pattern
555555
: type == ROWS ? i
556556
: j;
557557
*ptr++ = pattern[(col_idx / fill_w) %
558-
ARR_COUNT(pattern)];
558+
countof(pattern)];
559559
}
560560
}
561561
return generator_depth::bits8;

src/video_compress/cmpto_j2k.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author Martin Pulec <pulec@cesnet.cz>
44
*/
55
/*
6-
* Copyright (c) 2013-2025 CESNET
6+
* Copyright (c) 2013-2026 CESNET, zájmové sdružení právnických osob
77
* All rights reserved.
88
*
99
* Redistribution and use in source and binary forms, with or without
@@ -74,7 +74,7 @@
7474
#include "lib_common.h"
7575
#include "tv.h"
7676
#include "utils/color_out.h"
77-
#include "utils/macros.h" // for IS_KEY_PREFIX, TOSTRING
77+
#include "utils/macros.h" // for IS_KEY_PREFIX, TOSTRING, countof
7878
#include "utils/misc.h"
7979
#include "utils/opencl.h"
8080
#include "utils/parallel_conv.h"
@@ -239,7 +239,7 @@ const static struct cmpto_j2k_technology *const technologies[] = {
239239
*/
240240
static const struct cmpto_j2k_technology *
241241
get_technology_by_name(const char *name) {
242-
for (size_t i = 0; i < ARR_COUNT(technologies); ++i) {
242+
for (size_t i = 0; i < countof(technologies); ++i) {
243243
if (strcasecmp(name, technologies[i]->name) == 0) {
244244
return technologies[i];
245245
}
@@ -684,14 +684,14 @@ print_cmpto_j2k_technologies(bool full)
684684
MSG(ERROR, "Cannot get list of technologies!\n");
685685
return;
686686
}
687-
for (size_t i = 0; i < ARR_COUNT(technologies); ++i) {
687+
for (size_t i = 0; i < countof(technologies); ++i) {
688688
if ((version->technology & technologies[i]->cmpto_supp_bit) !=
689689
0) {
690690
color_printf("\t" TBOLD("- %s") "\n", technologies[i]->name);
691691
}
692692
}
693693

694-
for (size_t i = 0; i < ARR_COUNT(technologies); ++i) {
694+
for (size_t i = 0; i < countof(technologies); ++i) {
695695
if ((version->technology & technologies[i]->cmpto_supp_bit) !=
696696
0) {
697697
printf("\n");

src/video_decompress/libavcodec.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author Martin Pulec <pulec@cesnet.cz>
44
*/
55
/*
6-
* Copyright (c) 2013-2025 CESNET
6+
* Copyright (c) 2013-2026 CESNET, zájmové sdružení právických osob
77
* All rights reserved.
88
*
99
* Redistribution and use in source and binary forms, with or without
@@ -58,7 +58,7 @@
5858
#include "rtp/rtpenc_h264.h"
5959
#include "tv.h"
6060
#include "utils/debug.h" // for debug_file_dump
61-
#include "utils/macros.h"
61+
#include "utils/macros.h" // for countof
6262
#include "video.h"
6363
#include "video_codec.h"
6464
#include "video_decompress.h"
@@ -265,7 +265,7 @@ get_decoders(
265265
const AVCodec *usable_decoders[static DEC_LEN])
266266
{
267267
const char *const *preferred_decoders = (const char *[]){ NULL };
268-
for (unsigned int i = 0; i < ARR_COUNT(decoders); ++i) {
268+
for (unsigned int i = 0; i < countof(decoders); ++i) {
269269
if (decoders[i].avcodec_id == avcodec_id) {
270270
preferred_decoders = decoders[i].preferred_decoders;
271271
break;

src/video_display/gl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
#include "types.h"
8181
#include "utils/color_out.h"
8282
#include "utils/debug.h" // for DEBUG_TIMER_*
83-
#include "utils/macros.h" // OPTIMIZED_FOR
83+
#include "utils/macros.h" // for OPTIMIZED_FOR, countof
8484
#include "utils/ref_count.hpp"
8585
#include "video.h"
8686
#include "video_display.h"
@@ -549,7 +549,7 @@ static void
549549
gl_print_platforms()
550550
{
551551
printf("available platforms:\n");
552-
for (unsigned i = 0; i < ARR_COUNT(platform_map); ++i) {
552+
for (unsigned i = 0; i < countof(platform_map); ++i) {
553553
if (glfwPlatformSupported(platform_map[i].platform_id)) {
554554
color_printf("\t- " TBOLD("%s") "\n", platform_map[i].name);
555555
}
@@ -562,7 +562,7 @@ gl_print_current_platform()
562562
{
563563
const int platform = glfwGetPlatform();
564564
const char *name = "UNKNOWN/ERROR";
565-
for (unsigned i = 0; i < ARR_COUNT(platform_map); ++i) {
565+
for (unsigned i = 0; i < countof(platform_map); ++i) {
566566
if (platform_map[i].platform_id == platform) {
567567
name = platform_map[i].name;
568568
break;
@@ -769,7 +769,7 @@ static bool
769769
set_platform(struct state_gl *s, const char *platform)
770770
{
771771
#ifdef GLFW_PLATFORM
772-
for (unsigned i = 0; i < ARR_COUNT(platform_map); ++i) {
772+
for (unsigned i = 0; i < countof(platform_map); ++i) {
773773
if (strcasecmp(platform_map[i].name, platform) == 0) {
774774
s->init_hints[GLFW_PLATFORM] = platform_map[i].platform_id;
775775
return true;

0 commit comments

Comments
 (0)