Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
Rename COUNTOF() to ARRAY_SIZE().
Browse files Browse the repository at this point in the history
Consistent with Node, it has an ARRAY_SIZE() macro but not COUNTOF().
  • Loading branch information
bnoordhuis committed Jan 18, 2012
1 parent dee86dd commit fbbc085
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/uv-common.h
Expand Up @@ -29,7 +29,7 @@

#include "uv.h"

#define COUNTOF(a) (sizeof(a) / sizeof(a[0]))
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))


struct uv_ares_task_s {
Expand Down
2 changes: 1 addition & 1 deletion src/win/core.c
Expand Up @@ -197,7 +197,7 @@ static void uv_poll_ex(uv_loop_t* loop, int block) {

success = pGetQueuedCompletionStatusEx(loop->iocp,
overlappeds,
COUNTOF(overlappeds),
ARRAY_SIZE(overlappeds),
&count,
timeout,
FALSE);
Expand Down
2 changes: 1 addition & 1 deletion src/win/fs-event.c
Expand Up @@ -178,7 +178,7 @@ int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle,
*/

/* Convert to short path. */
if (!GetShortPathNameW(filenamew, short_path, COUNTOF(short_path))) {
if (!GetShortPathNameW(filenamew, short_path, ARRAY_SIZE(short_path))) {
last_error = GetLastError();
goto error;
}
Expand Down
10 changes: 5 additions & 5 deletions src/win/process.c
Expand Up @@ -545,12 +545,12 @@ wchar_t* make_program_env(char** env_block) {

for (env = env_block; *env; env++) {
check_required_vars_contains_var(required_vars,
COUNTOF(required_vars),
ARRAY_SIZE(required_vars),
*env);
env_len += (uv_utf8_to_utf16(*env, NULL, 0) * sizeof(wchar_t));
}

for (i = 0; i < COUNTOF(required_vars); ++i) {
for (i = 0; i < ARRAY_SIZE(required_vars); ++i) {
if (!required_vars[i].supplied) {
env_len += required_vars[i].len * sizeof(wchar_t);
var_size = GetEnvironmentVariableW(required_vars[i].wide, NULL, 0);
Expand All @@ -577,7 +577,7 @@ wchar_t* make_program_env(char** env_block) {
}
}

for (i = 0; i < COUNTOF(required_vars); ++i) {
for (i = 0; i < ARRAY_SIZE(required_vars); ++i) {
if (!required_vars[i].supplied) {
wcscpy(ptr, required_vars[i].wide);
ptr += required_vars[i].len - 1;
Expand Down Expand Up @@ -675,7 +675,7 @@ static void close_child_stdio(uv_process_t* process) {
int i;
HANDLE handle;

for (i = 0; i < COUNTOF(process->child_stdio); i++) {
for (i = 0; i < ARRAY_SIZE(process->child_stdio); i++) {
handle = process->child_stdio[i];
if (handle != NULL && handle != INVALID_HANDLE_VALUE) {
CloseHandle(handle);
Expand Down Expand Up @@ -1048,7 +1048,7 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process,
/* We're keeping the handles open, the thread pool is going to have */
/* it's way with them. But at least make them non-inheritable. */
int i;
for (i = 0; i < COUNTOF(process->child_stdio); i++) {
for (i = 0; i < ARRAY_SIZE(process->child_stdio); i++) {
SetHandleInformation(child_stdio[i], HANDLE_FLAG_INHERIT, 0);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/win/tty.c
Expand Up @@ -1376,7 +1376,7 @@ static int uv_tty_write_bufs(uv_tty_t* handle, uv_buf_t bufs[], int bufcnt,
/* We were not currently parsing a number */

/* Check for too many arguments */
if (handle->ansi_csi_argc >= COUNTOF(handle->ansi_csi_argv)) {
if (handle->ansi_csi_argc >= ARRAY_SIZE(handle->ansi_csi_argv)) {
ansi_parser_state |= ANSI_IGNORE;
continue;
}
Expand Down Expand Up @@ -1412,7 +1412,7 @@ static int uv_tty_write_bufs(uv_tty_t* handle, uv_buf_t bufs[], int bufcnt,
/* If ANSI_IN_ARG is not set, add another argument and */
/* default it to 0. */
/* Check for too many arguments */
if (handle->ansi_csi_argc >= COUNTOF(handle->ansi_csi_argv)) {
if (handle->ansi_csi_argc >= ARRAY_SIZE(handle->ansi_csi_argv)) {
ansi_parser_state |= ANSI_IGNORE;
continue;
}
Expand Down Expand Up @@ -1592,7 +1592,7 @@ static int uv_tty_write_bufs(uv_tty_t* handle, uv_buf_t bufs[], int bufcnt,
/* If a \n immediately follows a \r or vice versa, ignore it. */
if (previous_eol == 0 || utf8_codepoint == previous_eol) {
/* If there's no room in the utf16 buf, flush it first. */
if (2 > COUNTOF(utf16_buf) - utf16_buf_used) {
if (2 > ARRAY_SIZE(utf16_buf) - utf16_buf_used) {
uv_tty_emit_text(handle, utf16_buf, utf16_buf_used, error);
utf16_buf_used = 0;
}
Expand All @@ -1609,7 +1609,7 @@ static int uv_tty_write_bufs(uv_tty_t* handle, uv_buf_t bufs[], int bufcnt,
/* Encode character into utf-16 buffer. */

/* If there's no room in the utf16 buf, flush it first. */
if (1 > COUNTOF(utf16_buf) - utf16_buf_used) {
if (1 > ARRAY_SIZE(utf16_buf) - utf16_buf_used) {
uv_tty_emit_text(handle, utf16_buf, utf16_buf_used, error);
utf16_buf_used = 0;
}
Expand Down
2 changes: 0 additions & 2 deletions test/benchmark-udp-packet-storm.c
Expand Up @@ -35,8 +35,6 @@

#define BASE_PORT 12345

#define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))

static uv_loop_t* loop;

static int n_senders_;
Expand Down
8 changes: 4 additions & 4 deletions test/run-tests.c
Expand Up @@ -201,8 +201,8 @@ static int stdio_over_pipes_helper() {
"\n"
};

uv_write_t write_req[COUNTOF(buffers)];
uv_buf_t buf[COUNTOF(buffers)];
uv_write_t write_req[ARRAY_SIZE(buffers)];
uv_buf_t buf[ARRAY_SIZE(buffers)];
int r, i;
uv_loop_t* loop = uv_default_loop();

Expand All @@ -221,11 +221,11 @@ static int stdio_over_pipes_helper() {
uv_unref(loop);
uv_unref(loop);

for (i = 0; i < COUNTOF(buffers); i++) {
for (i = 0; i < ARRAY_SIZE(buffers); i++) {
buf[i] = uv_buf_init((char*)buffers[i], strlen(buffers[i]));
}

for (i = 0; i < COUNTOF(buffers); i++) {
for (i = 0; i < ARRAY_SIZE(buffers); i++) {
r = uv_write(&write_req[i], (uv_stream_t*)&stdout_pipe, &buf[i], 1,
after_pipe_write);
ASSERT(r == 0);
Expand Down
2 changes: 1 addition & 1 deletion test/task.h
Expand Up @@ -38,7 +38,7 @@
# define TEST_PIPENAME_2 "/tmp/uv-test-sock2"
#endif

#define COUNTOF(a) (sizeof(a) / sizeof(a[0]))
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))

typedef enum {
TCP = 0,
Expand Down
2 changes: 0 additions & 2 deletions test/test-thread.c
Expand Up @@ -26,8 +26,6 @@
#include <stddef.h>
#include <stdlib.h>

#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))

#define container_of(ptr, type, member) \
((type *) ((char *) (ptr) - offsetof(type, member)))

Expand Down

0 comments on commit fbbc085

Please sign in to comment.