Merge pull request #3701 from yang-g/unreachable

mark unreachable code with a macro
pull/3766/head
Craig Tiller 9 years ago
commit 4c351aafed
  1. 12
      include/grpc/support/port_platform.h
  2. 4
      src/core/channel/client_channel.c
  3. 4
      src/core/client_config/uri_parser.c
  4. 11
      src/core/httpcli/parser.c
  5. 2
      src/core/iomgr/tcp_client_posix.c
  6. 2
      src/core/iomgr/tcp_server_posix.c
  7. 8
      src/core/surface/byte_buffer.c
  8. 3
      src/core/surface/call.c
  9. 8
      src/core/surface/channel_connectivity.c
  10. 3
      src/core/surface/completion_queue.c
  11. 4
      src/core/transport/chttp2/frame_data.c
  12. 4
      src/core/transport/chttp2/frame_goaway.c
  13. 8
      src/core/transport/chttp2/hpack_parser.c
  14. 16
      src/core/transport/chttp2/parsing.c
  15. 6
      src/core/transport/chttp2/stream_encoder.c
  16. 3
      src/cpp/server/server.cc

@ -181,6 +181,7 @@
#ifndef _BSD_SOURCE #ifndef _BSD_SOURCE
#define _BSD_SOURCE #define _BSD_SOURCE
#endif #endif
#define GPR_FORBID_UNREACHABLE_CODE
#define GPR_MSG_IOVLEN_TYPE int #define GPR_MSG_IOVLEN_TYPE int
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
#define GPR_PLATFORM_STRING "ios" #define GPR_PLATFORM_STRING "ios"
@ -336,4 +337,15 @@ typedef uintptr_t gpr_uintptr;
#endif #endif
#endif #endif
#ifdef GPR_FORBID_UNREACHABLE_CODE
#define GPR_UNREACHABLE_CODE(STATEMENT)
#else
#define GPR_UNREACHABLE_CODE(STATEMENT) \
do { \
gpr_log(GPR_ERROR, "Should never reach here."); \
abort(); \
STATEMENT; \
} while (0)
#endif /* GPR_FORBID_UNREACHABLE_CODE */
#endif /* GRPC_SUPPORT_PORT_PLATFORM_H */ #endif /* GRPC_SUPPORT_PORT_PLATFORM_H */

@ -645,9 +645,7 @@ static void destroy_call_elem(grpc_exec_ctx *exec_ctx,
case CALL_WAITING_FOR_CONFIG: case CALL_WAITING_FOR_CONFIG:
case CALL_WAITING_FOR_CALL: case CALL_WAITING_FOR_CALL:
case CALL_WAITING_FOR_SEND: case CALL_WAITING_FOR_SEND:
gpr_log(GPR_ERROR, "should never reach here"); GPR_UNREACHABLE_CODE(return );
abort();
break;
} }
} }

@ -37,6 +37,7 @@
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include <grpc/support/string_util.h> #include <grpc/support/string_util.h>
/** a size_t default value... maps to all 1's */ /** a size_t default value... maps to all 1's */
@ -120,8 +121,7 @@ static int parse_fragment_or_query(const char *uri_text, size_t *i) {
} else { } else {
return 1; return 1;
} }
gpr_log(GPR_ERROR, "should never reach here"); GPR_UNREACHABLE_CODE(return 0);
abort();
default: default:
(*i) += advance; (*i) += advance;
break; break;

@ -139,8 +139,7 @@ static int finish_line(grpc_httpcli_parser *parser) {
} }
break; break;
case GRPC_HTTPCLI_BODY: case GRPC_HTTPCLI_BODY:
gpr_log(GPR_ERROR, "should never reach here"); GPR_UNREACHABLE_CODE(return 0);
abort();
} }
parser->cur_line_length = 0; parser->cur_line_length = 0;
@ -165,8 +164,7 @@ static int addbyte(grpc_httpcli_parser *parser, gpr_uint8 byte) {
} else { } else {
return 1; return 1;
} }
gpr_log(GPR_ERROR, "should never reach here"); GPR_UNREACHABLE_CODE(return 0);
abort();
case GRPC_HTTPCLI_BODY: case GRPC_HTTPCLI_BODY:
if (parser->r.body_length == parser->body_capacity) { if (parser->r.body_length == parser->body_capacity) {
parser->body_capacity = GPR_MAX(8, parser->body_capacity * 3 / 2); parser->body_capacity = GPR_MAX(8, parser->body_capacity * 3 / 2);
@ -177,10 +175,7 @@ static int addbyte(grpc_httpcli_parser *parser, gpr_uint8 byte) {
parser->r.body_length++; parser->r.body_length++;
return 1; return 1;
} }
gpr_log(GPR_ERROR, "should never reach here"); GPR_UNREACHABLE_CODE(return 0);
abort();
return 0;
} }
void grpc_httpcli_parser_init(grpc_httpcli_parser *parser) { void grpc_httpcli_parser_init(grpc_httpcli_parser *parser) {

@ -191,7 +191,7 @@ static void on_writable(grpc_exec_ctx *exec_ctx, void *acp, int success) {
goto finish; goto finish;
} }
abort(); GPR_UNREACHABLE_CODE(return );
finish: finish:
if (fd != NULL) { if (fd != NULL) {

@ -352,7 +352,7 @@ static void on_read(grpc_exec_ctx *exec_ctx, void *arg, int success) {
gpr_free(addr_str); gpr_free(addr_str);
} }
abort(); GPR_UNREACHABLE_CODE(return );
error: error:
gpr_mu_lock(&sp->server->mu); gpr_mu_lock(&sp->server->mu);

@ -75,9 +75,7 @@ grpc_byte_buffer *grpc_byte_buffer_copy(grpc_byte_buffer *bb) {
return grpc_raw_byte_buffer_create(bb->data.raw.slice_buffer.slices, return grpc_raw_byte_buffer_create(bb->data.raw.slice_buffer.slices,
bb->data.raw.slice_buffer.count); bb->data.raw.slice_buffer.count);
} }
gpr_log(GPR_INFO, "should never get here"); GPR_UNREACHABLE_CODE(return NULL);
abort();
return NULL;
} }
void grpc_byte_buffer_destroy(grpc_byte_buffer *bb) { void grpc_byte_buffer_destroy(grpc_byte_buffer *bb) {
@ -95,7 +93,5 @@ size_t grpc_byte_buffer_length(grpc_byte_buffer *bb) {
case GRPC_BB_RAW: case GRPC_BB_RAW:
return bb->data.raw.slice_buffer.length; return bb->data.raw.slice_buffer.length;
} }
gpr_log(GPR_ERROR, "should never reach here"); GPR_UNREACHABLE_CODE(return 0);
abort();
return 0;
} }

@ -434,8 +434,7 @@ static grpc_cq_completion *allocate_completion(grpc_call *call) {
gpr_mu_unlock(&call->completion_mu); gpr_mu_unlock(&call->completion_mu);
return &call->completions[i]; return &call->completions[i];
} }
gpr_log(GPR_ERROR, "should never reach here"); GPR_UNREACHABLE_CODE(return NULL);
abort();
return NULL; return NULL;
} }

@ -100,9 +100,7 @@ static void finished_completion(grpc_exec_ctx *exec_ctx, void *pw,
switch (w->phase) { switch (w->phase) {
case WAITING: case WAITING:
case CALLED_BACK: case CALLED_BACK:
gpr_log(GPR_ERROR, "should never reach here"); GPR_UNREACHABLE_CODE(return );
abort();
break;
case CALLING_BACK: case CALLING_BACK:
w->phase = CALLED_BACK; w->phase = CALLED_BACK;
break; break;
@ -149,9 +147,7 @@ static void partly_done(grpc_exec_ctx *exec_ctx, state_watcher *w,
w->phase = CALLING_BACK_AND_FINISHED; w->phase = CALLING_BACK_AND_FINISHED;
break; break;
case CALLING_BACK_AND_FINISHED: case CALLING_BACK_AND_FINISHED:
gpr_log(GPR_ERROR, "should never reach here"); GPR_UNREACHABLE_CODE(return );
abort();
break;
case CALLED_BACK: case CALLED_BACK:
delete = 1; delete = 1;
break; break;

@ -254,8 +254,7 @@ static void del_plucker(grpc_completion_queue *cc, void *tag,
return; return;
} }
} }
gpr_log(GPR_ERROR, "should never reach here"); GPR_UNREACHABLE_CODE(return );
abort();
} }
grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cc, void *tag, grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cc, void *tag,

@ -168,7 +168,5 @@ grpc_chttp2_parse_error grpc_chttp2_data_parser_parse(
} }
} }
gpr_log(GPR_ERROR, "should never reach here"); GPR_UNREACHABLE_CODE(return GRPC_CHTTP2_CONNECTION_ERROR);
abort();
return GRPC_CHTTP2_CONNECTION_ERROR;
} }

@ -152,9 +152,7 @@ grpc_chttp2_parse_error grpc_chttp2_goaway_parser_parse(
} }
return GRPC_CHTTP2_PARSE_OK; return GRPC_CHTTP2_PARSE_OK;
} }
gpr_log(GPR_ERROR, "Should never end up here"); GPR_UNREACHABLE_CODE(return GRPC_CHTTP2_CONNECTION_ERROR);
abort();
return GRPC_CHTTP2_CONNECTION_ERROR;
} }
void grpc_chttp2_goaway_append(gpr_uint32 last_stream_id, gpr_uint32 error_code, void grpc_chttp2_goaway_append(gpr_uint32 last_stream_id, gpr_uint32 error_code,

@ -1166,9 +1166,7 @@ static int append_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
append_bytes(str, decoded, 3); append_bytes(str, decoded, 3);
goto b64_byte0; goto b64_byte0;
} }
gpr_log(GPR_ERROR, "should never reach here"); GPR_UNREACHABLE_CODE(return 1);
abort();
return 1;
} }
/* append a null terminator to a string */ /* append a null terminator to a string */
@ -1313,9 +1311,7 @@ static int parse_value_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
return 0; return 0;
} }
/* Add code to prevent return without value error */ /* Add code to prevent return without value error */
gpr_log(GPR_ERROR, "Should never reach beyond switch in parse_value_string"); GPR_UNREACHABLE_CODE(return 0);
abort();
return 0;
} }
static int parse_value_string_with_indexed_key(grpc_chttp2_hpack_parser *p, static int parse_value_string_with_indexed_key(grpc_chttp2_hpack_parser *p,

@ -417,14 +417,10 @@ int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx,
transport_parsing->incoming_frame_size -= (gpr_uint32)(end - cur); transport_parsing->incoming_frame_size -= (gpr_uint32)(end - cur);
return 1; return 1;
} }
gpr_log(GPR_ERROR, "should never reach here"); GPR_UNREACHABLE_CODE(return 0);
abort();
} }
gpr_log(GPR_ERROR, "should never reach here"); GPR_UNREACHABLE_CODE(return 0);
abort();
return 0;
} }
static int init_frame_parser(grpc_chttp2_transport_parsing *transport_parsing) { static int init_frame_parser(grpc_chttp2_transport_parsing *transport_parsing) {
@ -580,9 +576,7 @@ static int init_data_frame_parser(
case GRPC_CHTTP2_CONNECTION_ERROR: case GRPC_CHTTP2_CONNECTION_ERROR:
return 0; return 0;
} }
gpr_log(GPR_ERROR, "should never reach here"); GPR_UNREACHABLE_CODE(return 0);
abort();
return 0;
} }
static void free_timeout(void *p) { gpr_free(p); } static void free_timeout(void *p) { gpr_free(p); }
@ -820,7 +814,5 @@ static int parse_frame_slice(grpc_exec_ctx *exec_ctx,
case GRPC_CHTTP2_CONNECTION_ERROR: case GRPC_CHTTP2_CONNECTION_ERROR:
return 0; return 0;
} }
gpr_log(GPR_ERROR, "should never reach here"); GPR_UNREACHABLE_CODE(return 0);
abort();
return 0;
} }

@ -428,7 +428,7 @@ static grpc_mdelem *hpack_enc(grpc_chttp2_hpack_compressor *c,
emit_lithdr_noidx(c, dynidx(c, indices_key), elem, st); emit_lithdr_noidx(c, dynidx(c, indices_key), elem, st);
return elem; return elem;
} }
abort(); GPR_UNREACHABLE_CODE(return NULL);
} }
indices_key = c->indices_keys[HASH_FRAGMENT_3(key_hash)]; indices_key = c->indices_keys[HASH_FRAGMENT_3(key_hash)];
@ -442,7 +442,7 @@ static grpc_mdelem *hpack_enc(grpc_chttp2_hpack_compressor *c,
emit_lithdr_noidx(c, dynidx(c, indices_key), elem, st); emit_lithdr_noidx(c, dynidx(c, indices_key), elem, st);
return elem; return elem;
} }
abort(); GPR_UNREACHABLE_CODE(return NULL);
} }
/* no elem, key in the table... fall back to literal emission */ /* no elem, key in the table... fall back to literal emission */
@ -454,7 +454,7 @@ static grpc_mdelem *hpack_enc(grpc_chttp2_hpack_compressor *c,
emit_lithdr_noidx_v(c, elem, st); emit_lithdr_noidx_v(c, elem, st);
return elem; return elem;
} }
abort(); GPR_UNREACHABLE_CODE(return NULL);
} }
#define STRLEN_LIT(x) (sizeof(x) - 1) #define STRLEN_LIT(x) (sizeof(x) - 1)

@ -153,8 +153,7 @@ class Server::SyncRequest GRPC_FINAL : public CompletionQueueTag {
GPR_ASSERT((*req)->in_flight_); GPR_ASSERT((*req)->in_flight_);
return true; return true;
} }
gpr_log(GPR_ERROR, "Should never reach here"); GPR_UNREACHABLE_CODE(return false);
abort();
} }
void SetupRequest() { cq_ = grpc_completion_queue_create(nullptr); } void SetupRequest() { cq_ = grpc_completion_queue_create(nullptr); }

Loading…
Cancel
Save