Commit b127f31e authored by Pieter Noordhuis's avatar Pieter Noordhuis
Browse files

Rename macros

parent 61346066
...@@ -58,15 +58,19 @@ static const char * strstate[] = { ...@@ -58,15 +58,19 @@ static const char * strstate[] = {
goto finalize; \ goto finalize; \
} }
#define TRANSITION(st) do { \ #define ADVANCE(bytes) do { \
pos++; nread++; \ pos += (bytes); nread += (bytes); \
TRANSITION_WITHOUT_POS_INCR(st); \
} while(0) } while(0)
#define TRANSITION_WITHOUT_POS_INCR(st) do { \ #define MOVE(st) do { \
goto l_##st; \ goto l_##st; \
} while(0) } while(0)
#define ADVANCE_AND_MOVE(st) do { \
ADVANCE(1); \
MOVE(st); \
} while(0)
#ifdef DEBUG #ifdef DEBUG
#define LOG(fmt, args...) do { \ #define LOG(fmt, args...) do { \
fprintf(stderr, fmt "\n" , ## args); \ fprintf(stderr, fmt "\n" , ## args); \
...@@ -161,13 +165,13 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons ...@@ -161,13 +165,13 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
switch (*pos) { switch (*pos) {
case '$': case '$':
cur->type = REDIS_STRING_T; cur->type = REDIS_STRING_T;
TRANSITION(integer_start); ADVANCE_AND_MOVE(integer_start);
case '*': case '*':
cur->type = REDIS_ARRAY_T; cur->type = REDIS_ARRAY_T;
TRANSITION(integer_start); ADVANCE_AND_MOVE(integer_start);
case ':': case ':':
cur->type = REDIS_INTEGER_T; cur->type = REDIS_INTEGER_T;
TRANSITION(integer_start); ADVANCE_AND_MOVE(integer_start);
case '+': case '+':
cur->type = REDIS_STATUS_T; cur->type = REDIS_STATUS_T;
assert(NULL); assert(NULL);
...@@ -187,24 +191,24 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons ...@@ -187,24 +191,24 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
/* Start with number */ /* Start with number */
if (ch >= '1' && ch <= '9') { if (ch >= '1' && ch <= '9') {
i64.ui64 = ch - '0'; i64.ui64 = ch - '0';
TRANSITION(integer_09); ADVANCE_AND_MOVE(integer_09);
} }
/* Start with negative sign */ /* Start with negative sign */
if (ch == '-') { if (ch == '-') {
i64.neg = 1; i64.neg = 1;
TRANSITION(integer_19); ADVANCE_AND_MOVE(integer_19);
} }
/* Start with positive sign */ /* Start with positive sign */
if (ch == '+') { if (ch == '+') {
i64.neg = 0; i64.neg = 0;
TRANSITION(integer_19); ADVANCE_AND_MOVE(integer_19);
} }
/* Single integer character is a zero */ /* Single integer character is a zero */
if (ch == '0') { if (ch == '0') {
TRANSITION(integer_cr); ADVANCE_AND_MOVE(integer_cr);
} }
goto error; goto error;
...@@ -215,7 +219,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons ...@@ -215,7 +219,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
if (ch >= '1' && ch <= '9') { if (ch >= '1' && ch <= '9') {
i64.ui64 = ch - '0'; i64.ui64 = ch - '0';
TRANSITION(integer_09); ADVANCE_AND_MOVE(integer_09);
} }
goto error; goto error;
...@@ -231,9 +235,9 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons ...@@ -231,9 +235,9 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
if (i64.ui64 > (UINT64_MAX - (ch - '0'))) /* Overflow */ if (i64.ui64 > (UINT64_MAX - (ch - '0'))) /* Overflow */
goto error; goto error;
i64.ui64 += ch - '0'; i64.ui64 += ch - '0';
TRANSITION(integer_09); ADVANCE_AND_MOVE(integer_09);
} else if (ch == '\r') { } else if (ch == '\r') {
TRANSITION(integer_lf); ADVANCE_AND_MOVE(integer_lf);
} }
goto error; goto error;
...@@ -241,7 +245,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons ...@@ -241,7 +245,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
STATE(integer_cr) { STATE(integer_cr) {
if (*pos == '\r') { if (*pos == '\r') {
TRANSITION(integer_lf); ADVANCE_AND_MOVE(integer_lf);
} }
goto error; goto error;
...@@ -279,7 +283,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons ...@@ -279,7 +283,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
/* Store remaining bytes for a complete bulk */ /* Store remaining bytes for a complete bulk */
cur->remaining = (unsigned)i64.i64; cur->remaining = (unsigned)i64.i64;
TRANSITION(bulk); ADVANCE_AND_MOVE(bulk);
} }
if (cur->type == REDIS_ARRAY_T) { if (cur->type == REDIS_ARRAY_T) {
...@@ -313,8 +317,8 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons ...@@ -313,8 +317,8 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
if (remaining <= available) { if (remaining <= available) {
cur->remaining = 0; cur->remaining = 0;
CALLBACK(string, pos, remaining); CALLBACK(string, pos, remaining);
pos += remaining; nread += remaining; ADVANCE(remaining);
TRANSITION_WITHOUT_POS_INCR(bulk_cr); MOVE(bulk_cr);
} }
/* Not everything can be read */ /* Not everything can be read */
...@@ -326,7 +330,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons ...@@ -326,7 +330,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
STATE(bulk_cr) { STATE(bulk_cr) {
if (*pos == '\r') { if (*pos == '\r') {
TRANSITION(bulk_lf); ADVANCE_AND_MOVE(bulk_lf);
} }
goto error; goto error;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment