Use clang-format-4.0

This commit is contained in:
Tatsuhiro Tsujikawa 2017-04-30 15:45:53 +09:00
parent 77f7a2fa7f
commit a584cf5a4f
18 changed files with 75 additions and 66 deletions

View File

@ -78,6 +78,7 @@ PointerAlignment: Right
ReflowComments: true ReflowComments: true
SortIncludes: false SortIncludes: false
SpaceAfterCStyleCast: false SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false SpaceInEmptyParentheses: false

View File

@ -26,8 +26,7 @@ Coding style
We use clang-format to format source code consistently. The We use clang-format to format source code consistently. The
clang-format configuration file .clang-format is located at the root clang-format configuration file .clang-format is located at the root
directory. Since clang-format produces slightly different results directory. Since clang-format produces slightly different results
between versions, we currently use clang-format which comes with between versions, we currently use clang-format 4.0.
clang-3.9.
To detect any violation to the coding style, we recommend to setup git To detect any violation to the coding style, we recommend to setup git
pre-commit hook to check coding style of the changes you introduced. pre-commit hook to check coding style of the changes you introduced.
@ -35,7 +34,7 @@ The pre-commit file is located at the root directory. Copy it under
.git/hooks and make sure that it is executable. The pre-commit script .git/hooks and make sure that it is executable. The pre-commit script
uses clang-format-diff.py to detect any style errors. If it is not in uses clang-format-diff.py to detect any style errors. If it is not in
your PATH or it exists under different name (e.g., your PATH or it exists under different name (e.g.,
clang-format-diff-3.9 in debian), either add it to PATH variable or clang-format-diff-4.0 in debian), either add it to PATH variable or
add git option ``clangformatdiff.binary`` to point to the script. add git option ``clangformatdiff.binary`` to point to the script.
For emacs users, integrating clang-format to emacs is very easy. For emacs users, integrating clang-format to emacs is very easy.

View File

@ -662,9 +662,9 @@ static int hd_context_init(nghttp2_hd_context *context, nghttp2_mem *mem) {
context->mem = mem; context->mem = mem;
context->bad = 0; context->bad = 0;
context->hd_table_bufsize_max = NGHTTP2_HD_DEFAULT_MAX_BUFFER_SIZE; context->hd_table_bufsize_max = NGHTTP2_HD_DEFAULT_MAX_BUFFER_SIZE;
rv = hd_ringbuf_init(&context->hd_table, context->hd_table_bufsize_max / rv = hd_ringbuf_init(
NGHTTP2_HD_ENTRY_OVERHEAD, &context->hd_table,
mem); context->hd_table_bufsize_max / NGHTTP2_HD_ENTRY_OVERHEAD, mem);
if (rv != 0) { if (rv != 0) {
return rv; return rv;
} }

View File

@ -5590,8 +5590,8 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in,
iframe->max_niv = iframe->max_niv =
iframe->frame.hd.length / NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH + 1; iframe->frame.hd.length / NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH + 1;
iframe->iv = nghttp2_mem_malloc(mem, sizeof(nghttp2_settings_entry) * iframe->iv = nghttp2_mem_malloc(
iframe->max_niv); mem, sizeof(nghttp2_settings_entry) * iframe->max_niv);
if (!iframe->iv) { if (!iframe->iv) {
return NGHTTP2_ERR_NOMEM; return NGHTTP2_ERR_NOMEM;
@ -6054,7 +6054,8 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in,
/* Use promised stream ID for PUSH_PROMISE */ /* Use promised stream ID for PUSH_PROMISE */
rv = nghttp2_session_add_rst_stream( rv = nghttp2_session_add_rst_stream(
session, iframe->frame.hd.type == NGHTTP2_PUSH_PROMISE session,
iframe->frame.hd.type == NGHTTP2_PUSH_PROMISE
? iframe->frame.push_promise.promised_stream_id ? iframe->frame.push_promise.promised_stream_id
: iframe->frame.hd.stream_id, : iframe->frame.hd.stream_id,
NGHTTP2_INTERNAL_ERROR); NGHTTP2_INTERNAL_ERROR);

View File

@ -2197,7 +2197,8 @@ int HttpServer::run() {
return -1; return -1;
} }
if (config_->verify_client) { if (config_->verify_client) {
SSL_CTX_set_verify(ssl_ctx, SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE | SSL_CTX_set_verify(ssl_ctx,
SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE |
SSL_VERIFY_FAIL_IF_NO_PEER_CERT, SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
verify_callback); verify_callback);
} }

View File

@ -1859,8 +1859,9 @@ int main(int argc, char **argv) {
{"encoder-header-table-size", required_argument, &flag, 8}, {"encoder-header-table-size", required_argument, &flag, 8},
{nullptr, 0, nullptr, 0}}; {nullptr, 0, nullptr, 0}};
int option_index = 0; int option_index = 0;
auto c = getopt_long(argc, argv, "hvW:c:d:m:n:p:t:w:H:i:r:T:N:B:", auto c =
long_options, &option_index); getopt_long(argc, argv, "hvW:c:d:m:n:p:t:w:H:i:r:T:N:B:", long_options,
&option_index);
if (c == -1) { if (c == -1) {
break; break;
} }

View File

@ -448,9 +448,9 @@ void copy_headers_to_nva(std::vector<nghttp2_nv> &nva,
void copy_headers_to_nva_nocopy(std::vector<nghttp2_nv> &nva, void copy_headers_to_nva_nocopy(std::vector<nghttp2_nv> &nva,
const HeaderRefs &headers, uint32_t flags) { const HeaderRefs &headers, uint32_t flags) {
copy_headers_to_nva_internal(nva, headers, NGHTTP2_NV_FLAG_NO_COPY_NAME | copy_headers_to_nva_internal(
NGHTTP2_NV_FLAG_NO_COPY_VALUE, nva, headers,
flags); NGHTTP2_NV_FLAG_NO_COPY_NAME | NGHTTP2_NV_FLAG_NO_COPY_VALUE, flags);
} }
void build_http1_headers_from_headers(DefaultMemchunks *buf, void build_http1_headers_from_headers(DefaultMemchunks *buf,
@ -1624,8 +1624,8 @@ StringRef path_join(BlockAllocator &balloc, const StringRef &base_path,
const StringRef &base_query, const StringRef &rel_path, const StringRef &base_query, const StringRef &rel_path,
const StringRef &rel_query) { const StringRef &rel_query) {
auto res = make_byte_ref( auto res = make_byte_ref(
balloc, std::max(static_cast<size_t>(1), base_path.size()) + balloc,
rel_path.size() + 1 + std::max(static_cast<size_t>(1), base_path.size()) + rel_path.size() + 1 +
std::max(base_query.size(), rel_query.size()) + 1); std::max(base_query.size(), rel_query.size()) + 1);
auto p = res.base; auto p = res.base;

View File

@ -2791,8 +2791,9 @@ int main(int argc, char **argv) {
{"encoder-header-table-size", required_argument, &flag, 14}, {"encoder-header-table-size", required_argument, &flag, 14},
{nullptr, 0, nullptr, 0}}; {nullptr, 0, nullptr, 0}};
int option_index = 0; int option_index = 0;
int c = getopt_long(argc, argv, "M:Oab:c:d:m:np:r:hH:vst:uw:yW:", int c =
long_options, &option_index); getopt_long(argc, argv, "M:Oab:c:d:m:np:r:hH:vst:uw:yW:", long_options,
&option_index);
if (c == -1) { if (c == -1) {
break; break;
} }

View File

@ -816,9 +816,9 @@ int on_stream_close_callback(nghttp2_session *session, int32_t stream_id,
uint32_t error_code, void *user_data) { uint32_t error_code, void *user_data) {
auto http2session = static_cast<Http2Session *>(user_data); auto http2session = static_cast<Http2Session *>(user_data);
if (LOG_ENABLED(INFO)) { if (LOG_ENABLED(INFO)) {
SSLOG(INFO, http2session) << "Stream stream_id=" << stream_id SSLOG(INFO, http2session)
<< " is being closed with error code " << "Stream stream_id=" << stream_id
<< error_code; << " is being closed with error code " << error_code;
} }
auto sd = static_cast<StreamData *>( auto sd = static_cast<StreamData *>(
nghttp2_session_get_stream_user_data(session, stream_id)); nghttp2_session_get_stream_user_data(session, stream_id));
@ -1152,8 +1152,8 @@ int on_response_headers(Http2Session *http2session, Downstream *downstream,
} }
downstream->set_request_state(Downstream::HEADER_COMPLETE); downstream->set_request_state(Downstream::HEADER_COMPLETE);
if (LOG_ENABLED(INFO)) { if (LOG_ENABLED(INFO)) {
SSLOG(INFO, http2session) << "HTTP upgrade success. stream_id=" SSLOG(INFO, http2session)
<< frame->hd.stream_id; << "HTTP upgrade success. stream_id=" << frame->hd.stream_id;
} }
} else { } else {
auto content_length = resp.fs.header(http2::HD_CONTENT_LENGTH); auto content_length = resp.fs.header(http2::HD_CONTENT_LENGTH);

View File

@ -1006,8 +1006,8 @@ int ensure_max_header_fields(const Downstream *downstream,
if (resp.fs.num_fields() >= httpconf.max_response_header_fields) { if (resp.fs.num_fields() >= httpconf.max_response_header_fields) {
if (LOG_ENABLED(INFO)) { if (LOG_ENABLED(INFO)) {
DLOG(INFO, downstream) << "Too many header field num=" DLOG(INFO, downstream)
<< resp.fs.num_fields() + 1; << "Too many header field num=" << resp.fs.num_fields() + 1;
} }
return -1; return -1;
} }

View File

@ -43,7 +43,8 @@ void test_shrpx_http_create_forwarded(void) {
CU_ASSERT("by=\"example.com:3000\";for=\"[::1]\";host=\"www.example.com\";" CU_ASSERT("by=\"example.com:3000\";for=\"[::1]\";host=\"www.example.com\";"
"proto=https" == "proto=https" ==
http::create_forwarded(balloc, FORWARDED_BY | FORWARDED_FOR | http::create_forwarded(balloc,
FORWARDED_BY | FORWARDED_FOR |
FORWARDED_HOST | FORWARDED_PROTO, FORWARDED_HOST | FORWARDED_PROTO,
StringRef::from_lit("example.com:3000"), StringRef::from_lit("example.com:3000"),
StringRef::from_lit("[::1]"), StringRef::from_lit("[::1]"),
@ -68,9 +69,10 @@ void test_shrpx_http_create_forwarded(void) {
StringRef::from_lit("[::1]"), StringRef::from_lit("_hidden"), StringRef::from_lit("[::1]"), StringRef::from_lit("_hidden"),
StringRef::from_lit(""), StringRef::from_lit(""))); StringRef::from_lit(""), StringRef::from_lit("")));
CU_ASSERT("" == http::create_forwarded( CU_ASSERT("" ==
balloc, FORWARDED_BY | FORWARDED_FOR | FORWARDED_HOST | http::create_forwarded(
FORWARDED_PROTO, balloc,
FORWARDED_BY | FORWARDED_FOR | FORWARDED_HOST | FORWARDED_PROTO,
StringRef::from_lit(""), StringRef::from_lit(""), StringRef::from_lit(""), StringRef::from_lit(""),
StringRef::from_lit(""), StringRef::from_lit(""))); StringRef::from_lit(""), StringRef::from_lit("")));
} }

View File

@ -150,8 +150,8 @@ int htp_hdr_keycb(http_parser *htp, const char *data, size_t len) {
} else { } else {
if (req.fs.num_fields() >= httpconf.max_request_header_fields) { if (req.fs.num_fields() >= httpconf.max_request_header_fields) {
if (LOG_ENABLED(INFO)) { if (LOG_ENABLED(INFO)) {
ULOG(INFO, upstream) << "Too many header field num=" ULOG(INFO, upstream)
<< req.fs.num_fields() + 1; << "Too many header field num=" << req.fs.num_fields() + 1;
} }
downstream->set_request_state( downstream->set_request_state(
Downstream::HTTP1_REQUEST_HEADER_TOO_LARGE); Downstream::HTTP1_REQUEST_HEADER_TOO_LARGE);
@ -166,8 +166,8 @@ int htp_hdr_keycb(http_parser *htp, const char *data, size_t len) {
} else { } else {
if (req.fs.num_fields() >= httpconf.max_request_header_fields) { if (req.fs.num_fields() >= httpconf.max_request_header_fields) {
if (LOG_ENABLED(INFO)) { if (LOG_ENABLED(INFO)) {
ULOG(INFO, upstream) << "Too many header field num=" ULOG(INFO, upstream)
<< req.fs.num_fields() + 1; << "Too many header field num=" << req.fs.num_fields() + 1;
} }
return -1; return -1;
} }

View File

@ -62,14 +62,14 @@ using namespace nghttp2;
// Upstream log // Upstream log
#define ULOG(SEVERITY, UPSTREAM) \ #define ULOG(SEVERITY, UPSTREAM) \
(shrpx::Log(SEVERITY, __FILE__, __LINE__) << "[UPSTREAM:" << UPSTREAM \ (shrpx::Log(SEVERITY, __FILE__, __LINE__) \
<< "]" \ << "[UPSTREAM:" << UPSTREAM << "]" \
" ") " ")
// Downstream log // Downstream log
#define DLOG(SEVERITY, DOWNSTREAM) \ #define DLOG(SEVERITY, DOWNSTREAM) \
(shrpx::Log(SEVERITY, __FILE__, __LINE__) << "[DOWNSTREAM:" << DOWNSTREAM \ (shrpx::Log(SEVERITY, __FILE__, __LINE__) \
<< "] ") << "[DOWNSTREAM:" << DOWNSTREAM << "] ")
// Downstream connection log // Downstream connection log
#define DCLOG(SEVERITY, DCONN) \ #define DCLOG(SEVERITY, DCONN) \

View File

@ -538,8 +538,8 @@ int MemcachedConnection::parse_packet() {
if (LOG_ENABLED(INFO)) { if (LOG_ENABLED(INFO)) {
if (parse_state_.status_code) { if (parse_state_.status_code) {
MCLOG(INFO, this) << "response returned error status: " MCLOG(INFO, this)
<< parse_state_.status_code; << "response returned error status: " << parse_state_.status_code;
} }
} }

View File

@ -880,8 +880,8 @@ ssize_t spdy_data_read_callback(spdylay_session *session, int32_t stream_id,
} else { } else {
// For tunneling, issue RST_STREAM to finish the stream. // For tunneling, issue RST_STREAM to finish the stream.
if (LOG_ENABLED(INFO)) { if (LOG_ENABLED(INFO)) {
ULOG(INFO, upstream) << "RST_STREAM to tunneled stream stream_id=" ULOG(INFO, upstream)
<< stream_id; << "RST_STREAM to tunneled stream stream_id=" << stream_id;
} }
upstream->rst_stream( upstream->rst_stream(
downstream, infer_upstream_rst_stream_status_code( downstream, infer_upstream_rst_stream_status_code(

View File

@ -857,7 +857,8 @@ SSL_CTX *create_ssl_context(const char *private_key_file, const char *cert_file,
} }
SSL_CTX_set_client_CA_list(ssl_ctx, list); SSL_CTX_set_client_CA_list(ssl_ctx, list);
} }
SSL_CTX_set_verify(ssl_ctx, SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE | SSL_CTX_set_verify(ssl_ctx,
SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE |
SSL_VERIFY_FAIL_IF_NO_PEER_CERT, SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
verify_callback); verify_callback);
} }
@ -996,8 +997,8 @@ SSL_CTX *create_ssl_client_context(
SSL_CTX_set_options(ssl_ctx, ssl_opts | tlsconf.tls_proto_mask); SSL_CTX_set_options(ssl_ctx, ssl_opts | tlsconf.tls_proto_mask);
SSL_CTX_set_session_cache_mode(ssl_ctx, SSL_SESS_CACHE_CLIENT | SSL_CTX_set_session_cache_mode(
SSL_SESS_CACHE_NO_INTERNAL_STORE); ssl_ctx, SSL_SESS_CACHE_CLIENT | SSL_SESS_CACHE_NO_INTERNAL_STORE);
SSL_CTX_sess_set_new_cb(ssl_ctx, tls_session_client_new_cb); SSL_CTX_sess_set_new_cb(ssl_ctx, tls_session_client_new_cb);
if (nghttp2::tls::ssl_ctx_set_proto_versions( if (nghttp2::tls::ssl_ctx_set_proto_versions(

View File

@ -295,9 +295,10 @@ void test_nghttp2_hd_inflate_indname_inc(void) {
assert_nv_equal(&nv, out.nva, 1, mem); assert_nv_equal(&nv, out.nva, 1, mem);
CU_ASSERT(1 == inflater.ctx.hd_table.len); CU_ASSERT(1 == inflater.ctx.hd_table.len);
CU_ASSERT(62 == nghttp2_hd_inflate_get_num_table_entries(&inflater)); CU_ASSERT(62 == nghttp2_hd_inflate_get_num_table_entries(&inflater));
assert_nv_equal(&nv, nghttp2_hd_inflate_get_table_entry( assert_nv_equal(
&inflater, NGHTTP2_STATIC_TABLE_LENGTH + &nv,
inflater.ctx.hd_table.len), nghttp2_hd_inflate_get_table_entry(
&inflater, NGHTTP2_STATIC_TABLE_LENGTH + inflater.ctx.hd_table.len),
1, mem); 1, mem);
nva_out_reset(&out, mem); nva_out_reset(&out, mem);
@ -424,9 +425,10 @@ void test_nghttp2_hd_inflate_newname_inc(void) {
CU_ASSERT(1 == out.nvlen); CU_ASSERT(1 == out.nvlen);
assert_nv_equal(&nv, out.nva, 1, mem); assert_nv_equal(&nv, out.nva, 1, mem);
CU_ASSERT(1 == inflater.ctx.hd_table.len); CU_ASSERT(1 == inflater.ctx.hd_table.len);
assert_nv_equal(&nv, nghttp2_hd_inflate_get_table_entry( assert_nv_equal(
&inflater, NGHTTP2_STATIC_TABLE_LENGTH + &nv,
inflater.ctx.hd_table.len), nghttp2_hd_inflate_get_table_entry(
&inflater, NGHTTP2_STATIC_TABLE_LENGTH + inflater.ctx.hd_table.len),
1, mem); 1, mem);
nva_out_reset(&out, mem); nva_out_reset(&out, mem);

View File

@ -6484,8 +6484,8 @@ void test_nghttp2_session_flow_control_data_recv(void) {
nghttp2_frame_pack_frame_hd(data, &hd); nghttp2_frame_pack_frame_hd(data, &hd);
CU_ASSERT(NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN == CU_ASSERT(NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN ==
nghttp2_session_mem_recv(session, data, NGHTTP2_MAX_PAYLOADLEN + nghttp2_session_mem_recv(
NGHTTP2_FRAME_HDLEN)); session, data, NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN));
item = nghttp2_session_get_next_ob_item(session); item = nghttp2_session_get_next_ob_item(session);
/* Since this is the last frame, stream-level WINDOW_UPDATE is not /* Since this is the last frame, stream-level WINDOW_UPDATE is not
@ -6503,8 +6503,8 @@ void test_nghttp2_session_flow_control_data_recv(void) {
sending DATA frames. Without calculating connection-level window, sending DATA frames. Without calculating connection-level window,
the subsequent flow control gets confused. */ the subsequent flow control gets confused. */
CU_ASSERT(NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN == CU_ASSERT(NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN ==
nghttp2_session_mem_recv(session, data, NGHTTP2_MAX_PAYLOADLEN + nghttp2_session_mem_recv(
NGHTTP2_FRAME_HDLEN)); session, data, NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN));
item = nghttp2_session_get_next_ob_item(session); item = nghttp2_session_get_next_ob_item(session);
CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type);