Rename COUNTOF() to ARRAY_SIZE().

Consistent with Node, it has an ARRAY_SIZE() macro but not COUNTOF().
This commit is contained in:
Ben Noordhuis 2012-01-18 15:43:21 +01:00
parent dee86dd5b0
commit fbbc085448
9 changed files with 17 additions and 21 deletions

View File

@ -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 {

View File

@ -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);

View File

@ -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;
}

View File

@ -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);
@ -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;
@ -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);
@ -1048,7 +1048,7 @@ done:
/* 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);
}
}

View File

@ -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;
}
@ -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;
}
@ -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;
}
@ -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;
}

View File

@ -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_;

View File

@ -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();
@ -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);

View File

@ -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,

View File

@ -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)))