MINOR: buffer: use b_orig() to replace most references to b->data

This patch updates most users of b->data to use b_orig().
This commit is contained in:
Willy Tarreau 2018-06-15 17:21:00 +02:00
parent 50227f9b88
commit 591d445049
9 changed files with 39 additions and 46 deletions

View File

@ -364,7 +364,7 @@ static inline size_t b_getblk_nc(const struct buffer *buf, const char **blk1, si
if (l1 < max) { if (l1 < max) {
*len1 = l1; *len1 = l1;
*len2 = max - l1; *len2 = max - l1;
*blk2 = buf->data; *blk2 = b_orig(buf);
return 2; return 2;
} }
*len1 = max; *len1 = max;

View File

@ -64,7 +64,7 @@ void buffer_dump(FILE *o, struct buffer *b, int from, int to);
/* Normalizes a pointer after an addition */ /* Normalizes a pointer after an addition */
static inline char *buffer_wrap_add(const struct buffer *buf, char *ptr) static inline char *buffer_wrap_add(const struct buffer *buf, char *ptr)
{ {
if (ptr - buf->size >= buf->data) if (ptr - buf->size >= b_orig(buf))
ptr -= buf->size; ptr -= buf->size;
return ptr; return ptr;
} }
@ -77,9 +77,9 @@ static inline char *buffer_wrap_add(const struct buffer *buf, char *ptr)
*/ */
static inline const char *buffer_pointer(const struct buffer *buf, const char *ptr) static inline const char *buffer_pointer(const struct buffer *buf, const char *ptr)
{ {
if (ptr < buf->data) if (ptr < b_orig(buf))
ptr += buf->size; ptr += buf->size;
else if (ptr - buf->size >= buf->data) else if (ptr - buf->size >= b_orig(buf))
ptr -= buf->size; ptr -= buf->size;
return ptr; return ptr;
} }
@ -405,7 +405,7 @@ static inline int b_isteq(const struct buffer *b, unsigned int o, size_t n, cons
if (*p++ != *r.ptr++) if (*p++ != *r.ptr++)
return -1; return -1;
if (unlikely(p == end)) if (unlikely(p == end))
p = b->data; p = b_orig(b);
} }
return ist.len; return ist.len;
} }
@ -447,7 +447,7 @@ static inline int bi_istput(struct buffer *b, const struct ist ist)
while (r.len--) { while (r.len--) {
*p++ = *r.ptr++; *p++ = *r.ptr++;
if (unlikely(p == end)) if (unlikely(p == end))
p = b->data; p = b_orig(b);
} }
return ist.len; return ist.len;
} }
@ -477,7 +477,7 @@ static inline int bo_istput(struct buffer *b, const struct ist ist)
while (r.len--) { while (r.len--) {
*p++ = *r.ptr++; *p++ = *r.ptr++;
if (unlikely(p == end)) if (unlikely(p == end))
p = b->data; p = b_orig(b);
} }
return ist.len; return ist.len;
} }

View File

@ -163,7 +163,7 @@ static inline int h1_skip_chunk_crlf(const struct buffer *buf, int start, int st
bytes++; bytes++;
ptr++; ptr++;
if (ptr >= b_wrap(buf)) if (ptr >= b_wrap(buf))
ptr = buf->data; ptr = b_orig(buf);
} }
if (bytes > stop - start) if (bytes > stop - start)
@ -210,7 +210,7 @@ static inline int h1_parse_chunk_size(const struct buffer *buf, int start, int s
if (c < 0) /* not a hex digit anymore */ if (c < 0) /* not a hex digit anymore */
break; break;
if (unlikely(++ptr >= end)) if (unlikely(++ptr >= end))
ptr = buf->data; ptr = b_orig(buf);
if (unlikely(chunk & 0xF8000000)) /* integer overflow will occur if result >= 2GB */ if (unlikely(chunk & 0xF8000000)) /* integer overflow will occur if result >= 2GB */
goto error; goto error;
chunk = (chunk << 4) + c; chunk = (chunk << 4) + c;
@ -223,7 +223,7 @@ static inline int h1_parse_chunk_size(const struct buffer *buf, int start, int s
while (HTTP_IS_SPHT(*ptr)) { while (HTTP_IS_SPHT(*ptr)) {
if (++ptr >= end) if (++ptr >= end)
ptr = buf->data; ptr = b_orig(buf);
if (--stop == 0) if (--stop == 0)
return 0; return 0;
} }
@ -236,7 +236,7 @@ static inline int h1_parse_chunk_size(const struct buffer *buf, int start, int s
/* we now have a CR or an LF at ptr */ /* we now have a CR or an LF at ptr */
if (likely(*ptr == '\r')) { if (likely(*ptr == '\r')) {
if (++ptr >= end) if (++ptr >= end)
ptr = buf->data; ptr = b_orig(buf);
if (--stop == 0) if (--stop == 0)
return 0; return 0;
} }
@ -244,7 +244,7 @@ static inline int h1_parse_chunk_size(const struct buffer *buf, int start, int s
if (*ptr != '\n') if (*ptr != '\n')
goto error; goto error;
if (++ptr >= end) if (++ptr >= end)
ptr = buf->data; ptr = b_orig(buf);
--stop; --stop;
/* done */ /* done */
break; break;
@ -252,13 +252,13 @@ static inline int h1_parse_chunk_size(const struct buffer *buf, int start, int s
else if (likely(*ptr == ';')) { else if (likely(*ptr == ';')) {
/* chunk extension, ends at next CRLF */ /* chunk extension, ends at next CRLF */
if (++ptr >= end) if (++ptr >= end)
ptr = buf->data; ptr = b_orig(buf);
if (--stop == 0) if (--stop == 0)
return 0; return 0;
while (!HTTP_IS_CRLF(*ptr)) { while (!HTTP_IS_CRLF(*ptr)) {
if (++ptr >= end) if (++ptr >= end)
ptr = buf->data; ptr = b_orig(buf);
if (--stop == 0) if (--stop == 0)
return 0; return 0;
} }

View File

@ -86,7 +86,7 @@ int buffer_replace2(struct buffer *b, char *pos, char *end, const char *str, int
delta = len - (end - pos); delta = len - (end - pos);
if (b_tail(b) + delta > b->data + b->size) if (b_tail(b) + delta > b_wrap(b))
return 0; /* no space left */ return 0; /* no space left */
if (b_data(b) && if (b_data(b) &&
@ -123,7 +123,7 @@ int buffer_insert_line2(struct buffer *b, char *pos, const char *str, int len)
delta = len + 2; delta = len + 2;
if (b_tail(b) + delta >= b->data + b->size) if (b_tail(b) + delta >= b_wrap(b))
return 0; /* no space left */ return 0; /* no space left */
if (b_data(b) && if (b_data(b) &&

View File

@ -169,7 +169,7 @@ int ci_putblk(struct channel *chn, const char *blk, int len)
max = b_contig_space(chn->buf); max = b_contig_space(chn->buf);
memcpy(ci_tail(chn), blk, MIN(len, max)); memcpy(ci_tail(chn), blk, MIN(len, max));
if (len > max) if (len > max)
memcpy(chn->buf->data, blk + max, len - max); memcpy(b_orig(chn->buf), blk + max, len - max);
chn->buf->i += len; chn->buf->i += len;
chn->total += len; chn->total += len;
@ -386,10 +386,10 @@ int ci_getblk_nc(const struct channel *chn,
return 0; return 0;
} }
if (unlikely(chn->buf->p + chn->buf->i > chn->buf->data + chn->buf->size)) { if (unlikely(chn->buf->p + chn->buf->i > b_wrap(chn->buf))) {
*blk1 = chn->buf->p; *blk1 = chn->buf->p;
*len1 = chn->buf->data + chn->buf->size - chn->buf->p; *len1 = b_wrap(chn->buf) - chn->buf->p;
*blk2 = chn->buf->data; *blk2 = b_orig(chn->buf);
*len2 = chn->buf->i - *len1; *len2 = chn->buf->i - *len1;
return 2; return 2;
} }

View File

@ -516,22 +516,22 @@ static inline __maybe_unused void h2_set_frame_size(void *frame, uint32_t len)
static inline __maybe_unused void h2_get_buf_bytes(void *dst, size_t bytes, static inline __maybe_unused void h2_get_buf_bytes(void *dst, size_t bytes,
const struct buffer *b, int o) const struct buffer *b, int o)
{ {
readv_bytes(dst, bytes, b_peek(b, o), b_wrap(b) - b_peek(b, o), b->data); readv_bytes(dst, bytes, b_peek(b, o), b_wrap(b) - b_peek(b, o), b_orig(b));
} }
static inline __maybe_unused uint16_t h2_get_n16(const struct buffer *b, int o) static inline __maybe_unused uint16_t h2_get_n16(const struct buffer *b, int o)
{ {
return readv_n16(b_peek(b, o), b_wrap(b) - b_peek(b, o), b->data); return readv_n16(b_peek(b, o), b_wrap(b) - b_peek(b, o), b_orig(b));
} }
static inline __maybe_unused uint32_t h2_get_n32(const struct buffer *b, int o) static inline __maybe_unused uint32_t h2_get_n32(const struct buffer *b, int o)
{ {
return readv_n32(b_peek(b, o), b_wrap(b) - b_peek(b, o), b->data); return readv_n32(b_peek(b, o), b_wrap(b) - b_peek(b, o), b_orig(b));
} }
static inline __maybe_unused uint64_t h2_get_n64(const struct buffer *b, int o) static inline __maybe_unused uint64_t h2_get_n64(const struct buffer *b, int o)
{ {
return readv_n64(b_peek(b, o), b_wrap(b) - b_peek(b, o), b->data); return readv_n64(b_peek(b, o), b_wrap(b) - b_peek(b, o), b_orig(b));
} }

View File

@ -284,14 +284,10 @@ static size_t raw_sock_to_buf(struct connection *conn, struct buffer *buf, size_
* EINTR too. * EINTR too.
*/ */
while (count > 0) { while (count > 0) {
/* first check if we have some room after p+i */ try = b_contig_space(buf);
try = buf->data + buf->size - (buf->p + buf->i); if (!try)
/* otherwise continue between data and p-o */ break;
if (try <= 0) {
try = buf->p - (buf->data + buf->o);
if (try <= 0)
break;
}
if (try > count) if (try > count)
try = count; try = count;

View File

@ -5361,16 +5361,13 @@ static size_t ssl_sock_to_buf(struct connection *conn, struct buffer *buf, size_
while (count > 0) { while (count > 0) {
int need_out = 0; int need_out = 0;
/* first check if we have some room after p+i */ try = b_contig_space(buf);
try = buf->data + buf->size - (buf->p + buf->i); if (!try)
/* otherwise continue between data and p-o */ break;
if (try <= 0) {
try = buf->p - (buf->data + buf->o);
if (try <= 0)
break;
}
if (try > count) if (try > count)
try = count; try = count;
if (((conn->flags & (CO_FL_EARLY_SSL_HS | CO_FL_EARLY_DATA)) == CO_FL_EARLY_SSL_HS) && if (((conn->flags & (CO_FL_EARLY_SSL_HS | CO_FL_EARLY_DATA)) == CO_FL_EARLY_SSL_HS) &&
conn->tmp_early_data != -1) { conn->tmp_early_data != -1) {
*b_tail(buf) = conn->tmp_early_data; *b_tail(buf) = conn->tmp_early_data;

View File

@ -2979,9 +2979,9 @@ static int stats_dump_full_strm_to_buffer(struct stream_interface *si, struct st
human_time(TICKS_TO_MS(strm->req.wex - now_ms), human_time(TICKS_TO_MS(strm->req.wex - now_ms),
TICKS_TO_MS(1000)) : "<NEVER>", TICKS_TO_MS(1000)) : "<NEVER>",
strm->req.buf, strm->req.buf,
strm->req.buf->data, (unsigned int)strm->req.buf->o, b_orig(strm->req.buf), (unsigned int)co_data(&strm->req),
(int)(strm->req.buf->p - strm->req.buf->data), (int)(strm->req.buf->p - b_orig(strm->req.buf)),
strm->txn ? strm->txn->req.next : 0, (unsigned int)strm->req.buf->i, strm->txn ? strm->txn->req.next : 0, (unsigned int)ci_data(&strm->req),
(unsigned int)strm->req.buf->size); (unsigned int)strm->req.buf->size);
chunk_appendf(&trash, chunk_appendf(&trash,
@ -3008,9 +3008,9 @@ static int stats_dump_full_strm_to_buffer(struct stream_interface *si, struct st
human_time(TICKS_TO_MS(strm->res.wex - now_ms), human_time(TICKS_TO_MS(strm->res.wex - now_ms),
TICKS_TO_MS(1000)) : "<NEVER>", TICKS_TO_MS(1000)) : "<NEVER>",
strm->res.buf, strm->res.buf,
strm->res.buf->data, (unsigned int)strm->res.buf->o, b_orig(strm->res.buf), (unsigned int)co_data(&strm->res),
(int)(strm->res.buf->p - strm->res.buf->data), (int)(strm->res.buf->p - b_orig(strm->res.buf)),
strm->txn ? strm->txn->rsp.next : 0, (unsigned int)strm->res.buf->i, strm->txn ? strm->txn->rsp.next : 0, (unsigned int)ci_data(&strm->res),
(unsigned int)strm->res.buf->size); (unsigned int)strm->res.buf->size);
if (ci_putchk(si_ic(si), &trash) == -1) { if (ci_putchk(si_ic(si), &trash) == -1) {