Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add macro for gcc specific fallthrough attribute #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/api/yajl_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ extern "C" {
# endif
#endif

#if defined(__GNUC__) && __GNUC__ >= 7
# define YAJL_FALLTHROUGH __attribute__((fallthrough))
#else
# define YAJL_FALLTHROUGH
#endif

/** pointer to a malloc function, supporting client overriding memory
* allocation routines */
typedef void * (*yajl_malloc_func)(void *ctx, size_t sz);
Expand Down
7 changes: 4 additions & 3 deletions src/yajl_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

#include "api/yajl_parse.h"
#include "api/yajl_common.h"
#include "yajl_lex.h"
#include "yajl_parser.h"
#include "yajl_encode.h"
Expand Down Expand Up @@ -343,7 +344,7 @@ yajl_do_parse(yajl_handle hand, const unsigned char * jsonText,
goto around_again;
}
/* intentional fall-through */
__attribute__((fallthrough));
YAJL_FALLTHROUGH;
}
case yajl_tok_colon:
case yajl_tok_comma:
Expand Down Expand Up @@ -395,7 +396,7 @@ yajl_do_parse(yajl_handle hand, const unsigned char * jsonText,
bufLen = yajl_buf_len(hand->decodeBuf);
}
/* intentional fall-through */
__attribute__((fallthrough));
YAJL_FALLTHROUGH;
case yajl_tok_string:
if (hand->callbacks && hand->callbacks->yajl_map_key) {
_CC_CHK(hand->callbacks->yajl_map_key(hand->ctx, buf,
Expand All @@ -416,7 +417,7 @@ yajl_do_parse(yajl_handle hand, const unsigned char * jsonText,
default:
yajl_bs_set(hand->stateStack, yajl_state_parse_error);
hand->parseError =
"invalid object key (must be a string)";
"invalid object key (must be a string)";
goto around_again;
}
}
Expand Down