Commit 29617b1a authored by Pieter Noordhuis's avatar Pieter Noordhuis
Browse files

Rename occurances of errno (conflict with errno.h)

parent 82555dfa
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#define ERRNO(code) REDIS_PARSER_##code #define ERRNO(code) REDIS_PARSER_##code
#define SET_ERRNO(code) do { \ #define SET_ERRNO(code) do { \
parser->errno = ERRNO(code); \ parser->err = ERRNO(code); \
} while(0) } while(0)
/* The redis_protocol_t argument to the callback function must be provided by /* The redis_protocol_t argument to the callback function must be provided by
...@@ -56,7 +56,7 @@ enum state { ...@@ -56,7 +56,7 @@ enum state {
#undef _GEN #undef _GEN
#define _GEN(code, description) description, #define _GEN(code, description) description,
static const char *errno_str[] = { static const char *strerror_map[] = {
REDIS_PARSER_ERRORS(_GEN) REDIS_PARSER_ERRORS(_GEN)
}; };
#undef _GEN #undef _GEN
...@@ -131,7 +131,7 @@ static const char *chrtos(char byte) { ...@@ -131,7 +131,7 @@ static const char *chrtos(char byte) {
void redis_parser_init(redis_parser_t *parser, const redis_parser_callbacks_t *callbacks) { void redis_parser_init(redis_parser_t *parser, const redis_parser_callbacks_t *callbacks) {
parser->stackidx = -1; parser->stackidx = -1;
parser->callbacks = callbacks; parser->callbacks = callbacks;
parser->errno = 0; parser->err = 0;
} }
/* Execute the parser against len bytes in buf. When a full message was read, /* Execute the parser against len bytes in buf. When a full message was read,
...@@ -155,7 +155,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons ...@@ -155,7 +155,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
/* Abort immediately if the parser is in an error state. It should be /* Abort immediately if the parser is in an error state. It should be
* re-initialized before attempting to execute it with new data. */ * re-initialized before attempting to execute it with new data. */
if (parser->errno) { if (parser->err) {
return 0; return 0;
} }
...@@ -486,19 +486,19 @@ finalize: ...@@ -486,19 +486,19 @@ finalize:
error: error:
if (parser->errno == ERRNO(OK)) { if (parser->err == ERRNO(OK)) {
SET_ERRNO(ERR_UNKNOWN); SET_ERRNO(ERR_UNKNOWN);
} }
return pos-buf; return pos-buf;
} }
redis_parser_errno_t redis_parser_errno(redis_parser_t *parser) { redis_parser_err_t redis_parser_err(redis_parser_t *parser) {
return parser->errno; return parser->err;
} }
const char *redis_parser_strerror(redis_parser_errno_t errno) { const char *redis_parser_strerror(redis_parser_err_t err) {
if (errno < (sizeof(errno_str)/sizeof(errno_str[0]))) if (err < (sizeof(strerror_map)/sizeof(strerror_map[0])))
return errno_str[errno]; return strerror_map[err];
return NULL; return NULL;
} }
...@@ -45,9 +45,9 @@ struct redis_parser_callbacks_s { ...@@ -45,9 +45,9 @@ struct redis_parser_callbacks_s {
_X(ERR_EXPECTED_LF, "expected \\n") \ _X(ERR_EXPECTED_LF, "expected \\n") \
#define _REDIS_PARSER_ERRNO_ENUM_GEN(code, description) REDIS_PARSER_##code, #define _REDIS_PARSER_ERRNO_ENUM_GEN(code, description) REDIS_PARSER_##code,
typedef enum redis_parser_errno_e { typedef enum redis_parser_err_e {
REDIS_PARSER_ERRORS(_REDIS_PARSER_ERRNO_ENUM_GEN) REDIS_PARSER_ERRORS(_REDIS_PARSER_ERRNO_ENUM_GEN)
} redis_parser_errno_t; } redis_parser_err_t;
#undef _REDIS_PARSER_ERRNO_ENUM_GEN #undef _REDIS_PARSER_ERRNO_ENUM_GEN
struct redis_protocol_s { struct redis_protocol_s {
...@@ -75,7 +75,7 @@ struct redis_parser_s { ...@@ -75,7 +75,7 @@ struct redis_parser_s {
/* private: parser state */ /* private: parser state */
unsigned char state; unsigned char state;
unsigned char errno; redis_parser_err_t err;
/* private: temporary integer (integer reply, bulk length) */ /* private: temporary integer (integer reply, bulk length) */
struct redis_parser_int64_s { struct redis_parser_int64_s {
...@@ -86,7 +86,7 @@ struct redis_parser_s { ...@@ -86,7 +86,7 @@ struct redis_parser_s {
void redis_parser_init(redis_parser_t *parser, const redis_parser_callbacks_t *callbacks); void redis_parser_init(redis_parser_t *parser, const redis_parser_callbacks_t *callbacks);
size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, const char *buf, size_t len); size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, const char *buf, size_t len);
redis_parser_errno_t redis_parser_errno(redis_parser_t *parser); redis_parser_err_t redis_parser_err(redis_parser_t *parser);
const char *redis_parser_strerror(redis_parser_errno_t errno); const char *redis_parser_strerror(redis_parser_err_t err);
#endif // __REDIS_PARSER_H #endif // __REDIS_PARSER_H
...@@ -358,42 +358,42 @@ void test_integer(redis_parser_t *p) { ...@@ -358,42 +358,42 @@ void test_integer(redis_parser_t *p) {
RESET_PARSER_T(p); RESET_PARSER_T(p);
assert_equal_size_t(redis_parser_execute(p, &res, buf, strlen(buf)), 2); assert_equal_size_t(redis_parser_execute(p, &res, buf, strlen(buf)), 2);
assert(res == NULL); assert(res == NULL);
assert(redis_parser_errno(p) == REDIS_PARSER_ERR_INVALID_INT); assert(redis_parser_err(p) == REDIS_PARSER_ERR_INVALID_INT);
/* Signed zero, negative */ /* Signed zero, negative */
buf = ":-0\r\n"; buf = ":-0\r\n";
RESET_PARSER_T(p); RESET_PARSER_T(p);
assert_equal_size_t(redis_parser_execute(p, &res, buf, strlen(buf)), 2); assert_equal_size_t(redis_parser_execute(p, &res, buf, strlen(buf)), 2);
assert(res == NULL); assert(res == NULL);
assert(redis_parser_errno(p) == REDIS_PARSER_ERR_INVALID_INT); assert(redis_parser_err(p) == REDIS_PARSER_ERR_INVALID_INT);
/* Start with 0 */ /* Start with 0 */
buf = ":0123\r\n"; buf = ":0123\r\n";
RESET_PARSER_T(p); RESET_PARSER_T(p);
assert_equal_size_t(redis_parser_execute(p, &res, buf, strlen(buf)), 2); assert_equal_size_t(redis_parser_execute(p, &res, buf, strlen(buf)), 2);
assert(res == NULL); assert(res == NULL);
assert(redis_parser_errno(p) == REDIS_PARSER_ERR_EXPECTED_CR); assert(redis_parser_err(p) == REDIS_PARSER_ERR_EXPECTED_CR);
/* Start with non-digit */ /* Start with non-digit */
buf = ":x123\r\n"; buf = ":x123\r\n";
RESET_PARSER_T(p); RESET_PARSER_T(p);
assert_equal_size_t(redis_parser_execute(p, &res, buf, strlen(buf)), 1); assert_equal_size_t(redis_parser_execute(p, &res, buf, strlen(buf)), 1);
assert(res == NULL); assert(res == NULL);
assert(redis_parser_errno(p) == REDIS_PARSER_ERR_INVALID_INT); assert(redis_parser_err(p) == REDIS_PARSER_ERR_INVALID_INT);
/* Non-digit in the middle */ /* Non-digit in the middle */
buf = ":12x3\r\n"; buf = ":12x3\r\n";
RESET_PARSER_T(p); RESET_PARSER_T(p);
assert_equal_size_t(redis_parser_execute(p, &res, buf, strlen(buf)), 3); assert_equal_size_t(redis_parser_execute(p, &res, buf, strlen(buf)), 3);
assert(res == NULL); assert(res == NULL);
assert(redis_parser_errno(p) == REDIS_PARSER_ERR_INVALID_INT); assert(redis_parser_err(p) == REDIS_PARSER_ERR_INVALID_INT);
/* Non-digit at the end */ /* Non-digit at the end */
buf = ":123x\r\n"; buf = ":123x\r\n";
RESET_PARSER_T(p); RESET_PARSER_T(p);
assert_equal_size_t(redis_parser_execute(p, &res, buf, strlen(buf)), 4); assert_equal_size_t(redis_parser_execute(p, &res, buf, strlen(buf)), 4);
assert(res == NULL); assert(res == NULL);
assert(redis_parser_errno(p) == REDIS_PARSER_ERR_INVALID_INT); assert(redis_parser_err(p) == REDIS_PARSER_ERR_INVALID_INT);
/* Signed 64-bit maximum */ /* Signed 64-bit maximum */
buf = ":9223372036854775807\r\n"; buf = ":9223372036854775807\r\n";
...@@ -409,7 +409,7 @@ void test_integer(redis_parser_t *p) { ...@@ -409,7 +409,7 @@ void test_integer(redis_parser_t *p) {
RESET_PARSER_T(p); RESET_PARSER_T(p);
assert_equal_size_t(redis_parser_execute(p, &res, buf, strlen(buf)), strlen(buf)-3); assert_equal_size_t(redis_parser_execute(p, &res, buf, strlen(buf)), strlen(buf)-3);
assert(res == NULL); assert(res == NULL);
assert(redis_parser_errno(p) == REDIS_PARSER_ERR_OVERFLOW); assert(redis_parser_err(p) == REDIS_PARSER_ERR_OVERFLOW);
/* Signed 64-bit minimum */ /* Signed 64-bit minimum */
buf = ":-9223372036854775808\r\n"; buf = ":-9223372036854775808\r\n";
...@@ -425,7 +425,7 @@ void test_integer(redis_parser_t *p) { ...@@ -425,7 +425,7 @@ void test_integer(redis_parser_t *p) {
RESET_PARSER_T(p); RESET_PARSER_T(p);
assert_equal_size_t(redis_parser_execute(p, &res, buf, strlen(buf)), strlen(buf)-3); assert_equal_size_t(redis_parser_execute(p, &res, buf, strlen(buf)), strlen(buf)-3);
assert(res == NULL); assert(res == NULL);
assert(redis_parser_errno(p) == REDIS_PARSER_ERR_OVERFLOW); assert(redis_parser_err(p) == REDIS_PARSER_ERR_OVERFLOW);
} }
void test_nil(redis_parser_t *p) { void test_nil(redis_parser_t *p) {
...@@ -493,7 +493,7 @@ void test_error(redis_parser_t *p) { ...@@ -493,7 +493,7 @@ void test_error(redis_parser_t *p) {
void test_abort_after_error(redis_parser_t *p) { void test_abort_after_error(redis_parser_t *p) {
redis_protocol_t *res; redis_protocol_t *res;
redis_parser_errno_t errno; redis_parser_err_t err;
assert_equal_size_t(redis_parser_execute(p, &res, "+ok\r", 4), 4); assert_equal_size_t(redis_parser_execute(p, &res, "+ok\r", 4), 4);
assert(res == NULL); assert(res == NULL);
...@@ -501,9 +501,9 @@ void test_abort_after_error(redis_parser_t *p) { ...@@ -501,9 +501,9 @@ void test_abort_after_error(redis_parser_t *p) {
assert(res == NULL); assert(res == NULL);
/* Test if the error matches what we expect */ /* Test if the error matches what we expect */
errno = redis_parser_errno(p); err = redis_parser_err(p);
assert(errno == REDIS_PARSER_ERR_EXPECTED_LF); assert(err == REDIS_PARSER_ERR_EXPECTED_LF);
assert(strcmp("expected \\n", redis_parser_strerror(errno)) == 0); assert(strcmp("expected \\n", redis_parser_strerror(err)) == 0);
/* Test that the parser doesn't continue after an error */ /* Test that the parser doesn't continue after an error */
assert_equal_size_t(redis_parser_execute(p, &res, "\n", 1), 0); assert_equal_size_t(redis_parser_execute(p, &res, "\n", 1), 0);
......
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