From 28d776e9d26136c818613d7d1c04c302634213f6 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 23 Nov 2016 10:16:53 -0800 Subject: [PATCH] Make everything compile for clang & gcc --- .../ext/transport/chttp2/transport/hpack_parser.c | 13 +++++-------- .../ext/transport/chttp2/transport/hpack_parser.h | 4 +--- src/core/lib/transport/static_metadata.h | 9 +++++---- .../transport/chttp2/hpack_parser_fuzzer_test.c | 4 ++-- test/core/transport/chttp2/hpack_parser_test.c | 5 ++--- tools/codegen/core/gen_static_metadata.py | 2 +- 6 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.c b/src/core/ext/transport/chttp2/transport/hpack_parser.c index 23fb1d12cad..5ff768baae2 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.c +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.c @@ -1615,15 +1615,14 @@ void grpc_chttp2_hpack_parser_destroy(grpc_exec_ctx *exec_ctx, grpc_error *grpc_chttp2_hpack_parser_parse(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, - grpc_slice_refcount *refcount, - const uint8_t *beg, - const uint8_t *end) { + grpc_slice slice) { /* TODO(ctiller): limit the distance of end from beg, and perform multiple steps in the event of a large chunk of data to limit stack space usage when no tail call optimization is available */ - p->current_slice_refcount = refcount; - grpc_error *error = p->state(exec_ctx, p, beg, end); + p->current_slice_refcount = slice.refcount; + grpc_error *error = p->state(exec_ctx, p, GRPC_SLICE_START_PTR(slice), + GRPC_SLICE_END_PTR(slice)); p->current_slice_refcount = NULL; return error; } @@ -1659,9 +1658,7 @@ grpc_error *grpc_chttp2_header_parser_parse(grpc_exec_ctx *exec_ctx, if (s != NULL) { s->stats.incoming.header_bytes += GRPC_SLICE_LENGTH(slice); } - grpc_error *error = grpc_chttp2_hpack_parser_parse( - exec_ctx, parser, slice.refcount, GRPC_SLICE_START_PTR(slice), - GRPC_SLICE_END_PTR(slice)); + grpc_error *error = grpc_chttp2_hpack_parser_parse(exec_ctx, parser, slice); if (error != GRPC_ERROR_NONE) { GPR_TIMER_END("grpc_chttp2_hpack_parser_parse", 0); return error; diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.h b/src/core/ext/transport/chttp2/transport/hpack_parser.h index 3ab0a2a34b8..a817183eb5b 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.h +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.h @@ -116,9 +116,7 @@ void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser *p); grpc_error *grpc_chttp2_hpack_parser_parse(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, - grpc_slice_refcount *refcount, - const uint8_t *beg, - const uint8_t *end); + grpc_slice slice); /* wraps grpc_chttp2_hpack_parser_parse to provide a frame level parser for the transport */ diff --git a/src/core/lib/transport/static_metadata.h b/src/core/lib/transport/static_metadata.h index e782a1f1c37..7649ccd5d2d 100644 --- a/src/core/lib/transport/static_metadata.h +++ b/src/core/lib/transport/static_metadata.h @@ -549,10 +549,11 @@ typedef union { } named; } grpc_metadata_batch_callouts; -#define GRPC_BATCH_INDEX_OF(slice) \ - (GRPC_IS_STATIC_METADATA_STRING((slice)) \ - ? GPR_CLAMP(GRPC_STATIC_METADATA_INDEX((slice)), 0, \ - GRPC_BATCH_CALLOUTS_COUNT) \ +#define GRPC_BATCH_INDEX_OF(slice) \ + (GRPC_IS_STATIC_METADATA_STRING((slice)) \ + ? (grpc_metadata_batch_callouts_index)GPR_CLAMP( \ + GRPC_STATIC_METADATA_INDEX((slice)), 0, \ + GRPC_BATCH_CALLOUTS_COUNT) \ : GRPC_BATCH_CALLOUTS_COUNT) extern const uint8_t grpc_static_accept_encoding_metadata[8]; diff --git a/test/core/transport/chttp2/hpack_parser_fuzzer_test.c b/test/core/transport/chttp2/hpack_parser_fuzzer_test.c index cfa3c5c088d..e9ac16df2de 100644 --- a/test/core/transport/chttp2/hpack_parser_fuzzer_test.c +++ b/test/core/transport/chttp2/hpack_parser_fuzzer_test.c @@ -57,8 +57,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_chttp2_hpack_parser_init(&exec_ctx, &parser); parser.on_header = onhdr; - GRPC_ERROR_UNREF( - grpc_chttp2_hpack_parser_parse(&exec_ctx, &parser, data, data + size)); + GRPC_ERROR_UNREF(grpc_chttp2_hpack_parser_parse( + &exec_ctx, &parser, grpc_slice_from_static_buffer(data, size))); grpc_chttp2_hpack_parser_destroy(&exec_ctx, &parser); grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); diff --git a/test/core/transport/chttp2/hpack_parser_test.c b/test/core/transport/chttp2/hpack_parser_test.c index b7f35a5e445..01789c4fb40 100644 --- a/test/core/transport/chttp2/hpack_parser_test.c +++ b/test/core/transport/chttp2/hpack_parser_test.c @@ -76,9 +76,8 @@ static void test_vector(grpc_chttp2_hpack_parser *parser, for (i = 0; i < nslices; i++) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GPR_ASSERT(grpc_chttp2_hpack_parser_parse( - &exec_ctx, parser, GRPC_SLICE_START_PTR(slices[i]), - GRPC_SLICE_END_PTR(slices[i])) == GRPC_ERROR_NONE); + GPR_ASSERT(grpc_chttp2_hpack_parser_parse(&exec_ctx, parser, slices[i]) == + GRPC_ERROR_NONE); grpc_exec_ctx_finish(&exec_ctx); } diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index bd05853f117..18f71646f84 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -498,7 +498,7 @@ print >>H, ' } named;' print >>H, '} grpc_metadata_batch_callouts;' print >>H print >>H, '#define GRPC_BATCH_INDEX_OF(slice) \\' -print >>H, ' (GRPC_IS_STATIC_METADATA_STRING((slice)) ? GPR_CLAMP(GRPC_STATIC_METADATA_INDEX((slice)), 0, GRPC_BATCH_CALLOUTS_COUNT) : GRPC_BATCH_CALLOUTS_COUNT)' +print >>H, ' (GRPC_IS_STATIC_METADATA_STRING((slice)) ? (grpc_metadata_batch_callouts_index)GPR_CLAMP(GRPC_STATIC_METADATA_INDEX((slice)), 0, GRPC_BATCH_CALLOUTS_COUNT) : GRPC_BATCH_CALLOUTS_COUNT)' print >>H print >>H, 'extern const uint8_t grpc_static_accept_encoding_metadata[%d];' % (1 << len(COMPRESSION_ALGORITHMS))