summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2017-06-27 17:27:18 +0300
committerValentin Bartenev <vbart@nginx.com>2017-06-27 17:27:18 +0300
commitdfd3cc8c0eb7f3479ee08b5e518abd264da56a29 (patch)
treeb6cdbfab23ce9ea2c498bcb0f540d4847472f067 /src
parentf86c80309885230df2960ef8e1db337f04b11926 (diff)
downloadunit-dfd3cc8c0eb7f3479ee08b5e518abd264da56a29.tar.gz
unit-dfd3cc8c0eb7f3479ee08b5e518abd264da56a29.tar.bz2
Applied nxt_pointer_to() and nxt_value_at() where possible.
Diffstat (limited to 'src')
-rw-r--r--src/nginext/nxt_go_array.c2
-rw-r--r--src/nginext/nxt_go_array.h2
-rw-r--r--src/nginext/nxt_go_run_ctx.c3
-rw-r--r--src/nxt_array.c4
-rw-r--r--src/nxt_array.h4
-rw-r--r--src/nxt_buf.c2
-rw-r--r--src/nxt_conn_proxy.c9
-rw-r--r--src/nxt_errno.c2
-rw-r--r--src/nxt_http_parse.c2
-rw-r--r--src/nxt_list.h2
-rw-r--r--src/nxt_mem_zone.c2
-rw-r--r--src/nxt_sockaddr.c8
-rw-r--r--src/nxt_sockaddr.h6
-rw-r--r--src/nxt_string.c2
-rw-r--r--src/nxt_vector.c8
-rw-r--r--src/nxt_vector.h7
16 files changed, 28 insertions, 37 deletions
diff --git a/src/nginext/nxt_go_array.c b/src/nginext/nxt_go_array.c
index a788811a..f409cb10 100644
--- a/src/nginext/nxt_go_array.c
+++ b/src/nginext/nxt_go_array.c
@@ -57,7 +57,7 @@ nxt_go_array_add(nxt_array_t *array)
array->nalloc = new_alloc;
}
- p = (char *) array->elts + array->size * array->nelts;
+ p = nxt_pointer_to(array->elts, array->size * array->nelts);
array->nelts++;
return p;
diff --git a/src/nginext/nxt_go_array.h b/src/nginext/nxt_go_array.h
index 0c3ba336..d96db663 100644
--- a/src/nginext/nxt_go_array.h
+++ b/src/nginext/nxt_go_array.h
@@ -30,7 +30,7 @@ nxt_go_array_zero_add(nxt_array_t *array)
#define \
nxt_go_array_at(array, n) \
- ((void *) ((char *) (array)->elts + (array)->size * (n)))
+ nxt_pointer_to((array)->elts, (array)->size * (n))
#endif /* _NXT_GO_ARRAY_H_INCLUDED_ */
diff --git a/src/nginext/nxt_go_run_ctx.c b/src/nginext/nxt_go_run_ctx.c
index 6a5f8d6b..2d284bc5 100644
--- a/src/nginext/nxt_go_run_ctx.c
+++ b/src/nginext/nxt_go_run_ctx.c
@@ -96,8 +96,7 @@ nxt_go_ctx_init_msg(nxt_go_msg_t *msg, nxt_port_msg_t *port_msg,
if (nxt_fast_path(port_msg->mmap != 0)) {
msg->mmap_msg = (nxt_port_mmap_msg_t *) (port_msg + 1);
- msg->end = (nxt_port_mmap_msg_t *) ( (char *) msg->mmap_msg +
- payload_size );
+ msg->end = nxt_pointer_to(msg->mmap_msg, payload_size);
mmap_msg = msg->mmap_msg;
while(mmap_msg < msg->end) {
diff --git a/src/nxt_array.c b/src/nxt_array.c
index d7bc28bd..f26670f5 100644
--- a/src/nxt_array.c
+++ b/src/nxt_array.c
@@ -18,7 +18,7 @@ nxt_array_create(nxt_mp_t *mp, nxt_uint_t n, size_t size)
return NULL;
}
- array->elts = (char *) array + sizeof(nxt_array_t);
+ array->elts = nxt_pointer_to(array, sizeof(nxt_array_t));
array->nelts = 0;
array->size = size;
array->nalloc = n;
@@ -61,7 +61,7 @@ nxt_array_add(nxt_array_t *array)
array->nalloc = new_alloc;
}
- p = (char *) array->elts + array->size * array->nelts;
+ p = nxt_pointer_to(array->elts, array->size * array->nelts);
array->nelts++;
return p;
diff --git a/src/nxt_array.h b/src/nxt_array.h
index 33e9807a..8a99aa2c 100644
--- a/src/nxt_array.h
+++ b/src/nxt_array.h
@@ -27,7 +27,7 @@ NXT_EXPORT void nxt_array_remove(nxt_array_t *array, void *elt);
#define \
nxt_array_last(array) \
- ((void *) ((char *) (array)->elts + (array)->size * ((array)->nelts - 1)))
+ nxt_pointer_to((array)->elts, (array)->size * ((array)->nelts - 1))
#define \
@@ -44,7 +44,7 @@ nxt_inline void *
nxt_array_remove_last(nxt_array_t *array)
{
array->nelts--;
- return (char *) array->elts + array->size * array->nelts;
+ return nxt_pointer_to(array->elts, array->size * array->nelts);
}
diff --git a/src/nxt_buf.c b/src/nxt_buf.c
index e07326ef..cb0faf7c 100644
--- a/src/nxt_buf.c
+++ b/src/nxt_buf.c
@@ -18,7 +18,7 @@ nxt_buf_mem_init(nxt_buf_t *b, void *start, size_t size)
b->mem.start = start;
b->mem.pos = start;
b->mem.free = start;
- b->mem.end = (u_char *) start + size;
+ b->mem.end = nxt_pointer_to(start, size);
}
diff --git a/src/nxt_conn_proxy.c b/src/nxt_conn_proxy.c
index 63a41c39..055a288d 100644
--- a/src/nxt_conn_proxy.c
+++ b/src/nxt_conn_proxy.c
@@ -782,14 +782,7 @@ nxt_conn_proxy_write_timeout(nxt_task_t *task, void *obj, void *data)
static nxt_msec_t
nxt_conn_proxy_timeout_value(nxt_conn_t *c, uintptr_t data)
{
- nxt_msec_t *timer;
- nxt_conn_proxy_t *p;
-
- p = c->socket.data;
-
- timer = (nxt_msec_t *) ((char *) p + data);
-
- return *timer;
+ return nxt_value_at(nxt_msec_t, c->socket.data, data);
}
diff --git a/src/nxt_errno.c b/src/nxt_errno.c
index 9ac79936..29f270e0 100644
--- a/src/nxt_errno.c
+++ b/src/nxt_errno.c
@@ -107,7 +107,7 @@ nxt_strerror_start(void)
return NXT_ERROR;
}
- p = (u_char *) nxt_sys_errlist + n;
+ p = nxt_pointer_to(nxt_sys_errlist, n);
for (err = 0; err < nxt_sys_nerr; err++) {
msg = strerror((int) err);
diff --git a/src/nxt_http_parse.c b/src/nxt_http_parse.c
index 21d8f99c..abdb23fa 100644
--- a/src/nxt_http_parse.c
+++ b/src/nxt_http_parse.c
@@ -746,7 +746,7 @@ nxt_http_fields_hash_create(nxt_http_fields_hash_entry_t *entries,
break;
}
- elt = (nxt_http_fields_hash_elt_t *) ((u_char *) elt + size);
+ elt = nxt_pointer_to(elt, size);
}
}
diff --git a/src/nxt_list.h b/src/nxt_list.h
index 39ad2742..3bb2b139 100644
--- a/src/nxt_list.h
+++ b/src/nxt_list.h
@@ -43,7 +43,7 @@ nxt_list_part(list) \
#define \
nxt_list_data(part) \
- ((char *) (part) + sizeof(nxt_list_part_t))
+ nxt_pointer_to(part, sizeof(nxt_list_part_t))
#define \
diff --git a/src/nxt_mem_zone.c b/src/nxt_mem_zone.c
index eacb455d..9214a422 100644
--- a/src/nxt_mem_zone.c
+++ b/src/nxt_mem_zone.c
@@ -764,7 +764,7 @@ nxt_mem_zone_find_free_block(nxt_mem_zone_t *zone, nxt_rbtree_node_t *node,
} else { /* pages < block->size */
aligned += pages << zone->page_size_shift;
- end = (u_char *) block + (block->size << zone->page_size_shift);
+ end = nxt_pointer_to(block, block->size << zone->page_size_shift);
if (aligned <= end) {
return block;
diff --git a/src/nxt_sockaddr.c b/src/nxt_sockaddr.c
index 6db15d13..3ec4abb6 100644
--- a/src/nxt_sockaddr.c
+++ b/src/nxt_sockaddr.c
@@ -189,7 +189,7 @@ nxt_sockaddr_text(nxt_sockaddr_t *sa)
u_char *p, *start, *end, *octet;
uint32_t port;
- end = (u_char *) sa + sa->sockaddr_size;
+ end = nxt_pointer_to(sa, sa->sockaddr_size);
switch (sa->u.sockaddr.sa_family) {
@@ -199,7 +199,7 @@ nxt_sockaddr_text(nxt_sockaddr_t *sa)
sa->start = offset;
sa->address_start = offset;
- start = (u_char *) sa + offset;
+ start = nxt_pointer_to(sa, offset);
octet = (u_char *) &sa->u.sockaddr_in.sin_addr;
p = nxt_sprintf(start, end, "%ud.%ud.%ud.%ud",
@@ -220,7 +220,7 @@ nxt_sockaddr_text(nxt_sockaddr_t *sa)
sa->start = offset;
sa->address_start = offset;
- start = (u_char *) sa + offset;
+ start = nxt_pointer_to(sa, offset);
p = start;
*p++ = '[';
@@ -247,7 +247,7 @@ nxt_sockaddr_text(nxt_sockaddr_t *sa)
sa->start = offset;
sa->address_start = offset;
- start = (u_char *) sa + offset;
+ start = nxt_pointer_to(sa, offset);
p = start;
#if (NXT_LINUX)
diff --git a/src/nxt_sockaddr.h b/src/nxt_sockaddr.h
index 11f4b9d1..dc4477c9 100644
--- a/src/nxt_sockaddr.h
+++ b/src/nxt_sockaddr.h
@@ -102,9 +102,9 @@ NXT_EXPORT nxt_int_t nxt_inet6_addr(struct in6_addr *in6_addr, u_char *buf,
(sizeof("[ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]:65535") - 1)
-#define nxt_sockaddr_start(sa) ((u_char *) (sa) + (sa)->start)
-#define nxt_sockaddr_address(sa) ((u_char *) (sa) + (sa)->address_start)
-#define nxt_sockaddr_port(sa) ((u_char *) (sa) + (sa)->port_start)
+#define nxt_sockaddr_start(sa) nxt_pointer_to(sa, (sa)->start)
+#define nxt_sockaddr_address(sa) nxt_pointer_to(sa, (sa)->address_start)
+#define nxt_sockaddr_port(sa) nxt_pointer_to(sa, (sa)->port_start)
#define nxt_sockaddr_length(sa) ((sa)->length - (sa)->port_start)
diff --git a/src/nxt_string.c b/src/nxt_string.c
index 79dfe72d..fb1cafd6 100644
--- a/src/nxt_string.c
+++ b/src/nxt_string.c
@@ -17,7 +17,7 @@ nxt_str_alloc(nxt_mp_t *mp, size_t length)
if (nxt_fast_path(s != NULL)) {
s->length = length;
- s->start = (u_char *) s + sizeof(nxt_str_t);
+ s->start = nxt_pointer_to(s, sizeof(nxt_str_t));
}
return s;
diff --git a/src/nxt_vector.c b/src/nxt_vector.c
index faaf2f54..4737248c 100644
--- a/src/nxt_vector.c
+++ b/src/nxt_vector.c
@@ -16,7 +16,7 @@ nxt_vector_create(nxt_uint_t items, size_t item_size,
vector = proto->alloc(pool, sizeof(nxt_vector_t) + items * item_size);
if (nxt_fast_path(vector != NULL)) {
- vector->start = (char *) vector + sizeof(nxt_vector_t);
+ vector->start = nxt_pointer_to(vector, sizeof(nxt_vector_t));
vector->items = 0;
vector->item_size = item_size;
vector->avalaible = items;
@@ -112,7 +112,7 @@ nxt_vector_add(nxt_vector_t *vector, const nxt_mem_proto_t *proto, void *pool)
}
}
- item = (char *) vector->start + vector->item_size * vector->items;
+ item = nxt_pointer_to(vector->start, vector->item_size * vector->items);
vector->items++;
@@ -143,11 +143,11 @@ nxt_vector_remove(nxt_vector_t *vector, void *item)
uint32_t item_size;
item_size = vector->item_size;
- end = (u_char *) vector->start + item_size * vector->items;
+ end = nxt_pointer_to(vector->start, item_size * vector->items);
last = end - item_size;
if (item != last) {
- next = (u_char *) item + item_size;
+ next = nxt_pointer_to(item, item_size);
nxt_memmove(item, next, end - next);
}
diff --git a/src/nxt_vector.h b/src/nxt_vector.h
index ddd3e220..e8836dbf 100644
--- a/src/nxt_vector.h
+++ b/src/nxt_vector.h
@@ -43,9 +43,8 @@ NXT_EXPORT void nxt_vector_remove(nxt_vector_t *vector, void *item);
#define \
nxt_vector_last(vector) \
- ((void *) \
- ((char *) (vector)->start \
- + (vector)->item_size * ((vector)->items - 1)))
+ nxt_pointer_to((vector)->start, \
+ (vector)->item_size * ((vector)->items - 1))
#define \
@@ -62,7 +61,7 @@ nxt_inline void *
nxt_vector_remove_last(nxt_vector_t *vector)
{
vector->items--;
- return (char *) vector->start + vector->item_size * vector->items;
+ return nxt_pointer_to(vector->start, vector->item_size * vector->items);
}