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
SortIncludes: false
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false

View File

@ -26,8 +26,7 @@ Coding style
We use clang-format to format source code consistently. The
clang-format configuration file .clang-format is located at the root
directory. Since clang-format produces slightly different results
between versions, we currently use clang-format which comes with
clang-3.9.
between versions, we currently use clang-format 4.0.
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.
@ -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
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.,
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.
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->bad = 0;
context->hd_table_bufsize_max = NGHTTP2_HD_DEFAULT_MAX_BUFFER_SIZE;
rv = hd_ringbuf_init(&context->hd_table, context->hd_table_bufsize_max /
NGHTTP2_HD_ENTRY_OVERHEAD,
mem);
rv = hd_ringbuf_init(
&context->hd_table,
context->hd_table_bufsize_max / NGHTTP2_HD_ENTRY_OVERHEAD, mem);
if (rv != 0) {
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->frame.hd.length / NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH + 1;
iframe->iv = nghttp2_mem_malloc(mem, sizeof(nghttp2_settings_entry) *
iframe->max_niv);
iframe->iv = nghttp2_mem_malloc(
mem, sizeof(nghttp2_settings_entry) * iframe->max_niv);
if (!iframe->iv) {
return NGHTTP2_ERR_NOMEM;
@ -6054,9 +6054,10 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in,
/* Use promised stream ID for PUSH_PROMISE */
rv = nghttp2_session_add_rst_stream(
session, iframe->frame.hd.type == NGHTTP2_PUSH_PROMISE
? iframe->frame.push_promise.promised_stream_id
: iframe->frame.hd.stream_id,
session,
iframe->frame.hd.type == NGHTTP2_PUSH_PROMISE
? iframe->frame.push_promise.promised_stream_id
: iframe->frame.hd.stream_id,
NGHTTP2_INTERNAL_ERROR);
if (nghttp2_is_fatal(rv)) {
return rv;

View File

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

View File

@ -1859,8 +1859,9 @@ int main(int argc, char **argv) {
{"encoder-header-table-size", required_argument, &flag, 8},
{nullptr, 0, nullptr, 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:",
long_options, &option_index);
auto c =
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) {
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,
const HeaderRefs &headers, uint32_t flags) {
copy_headers_to_nva_internal(nva, headers, NGHTTP2_NV_FLAG_NO_COPY_NAME |
NGHTTP2_NV_FLAG_NO_COPY_VALUE,
flags);
copy_headers_to_nva_internal(
nva, headers,
NGHTTP2_NV_FLAG_NO_COPY_NAME | NGHTTP2_NV_FLAG_NO_COPY_VALUE, flags);
}
void build_http1_headers_from_headers(DefaultMemchunks *buf,
@ -1624,9 +1624,9 @@ StringRef path_join(BlockAllocator &balloc, const StringRef &base_path,
const StringRef &base_query, const StringRef &rel_path,
const StringRef &rel_query) {
auto res = make_byte_ref(
balloc, std::max(static_cast<size_t>(1), base_path.size()) +
rel_path.size() + 1 +
std::max(base_query.size(), rel_query.size()) + 1);
balloc,
std::max(static_cast<size_t>(1), base_path.size()) + rel_path.size() + 1 +
std::max(base_query.size(), rel_query.size()) + 1);
auto p = res.base;
if (rel_path.empty()) {

View File

@ -2791,8 +2791,9 @@ int main(int argc, char **argv) {
{"encoder-header-table-size", required_argument, &flag, 14},
{nullptr, 0, nullptr, 0}};
int option_index = 0;
int c = getopt_long(argc, argv, "M:Oab:c:d:m:np:r:hH:vst:uw:yW:",
long_options, &option_index);
int c =
getopt_long(argc, argv, "M:Oab:c:d:m:np:r:hH:vst:uw:yW:", long_options,
&option_index);
if (c == -1) {
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) {
auto http2session = static_cast<Http2Session *>(user_data);
if (LOG_ENABLED(INFO)) {
SSLOG(INFO, http2session) << "Stream stream_id=" << stream_id
<< " is being closed with error code "
<< error_code;
SSLOG(INFO, http2session)
<< "Stream stream_id=" << stream_id
<< " is being closed with error code " << error_code;
}
auto sd = static_cast<StreamData *>(
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);
if (LOG_ENABLED(INFO)) {
SSLOG(INFO, http2session) << "HTTP upgrade success. stream_id="
<< frame->hd.stream_id;
SSLOG(INFO, http2session)
<< "HTTP upgrade success. stream_id=" << frame->hd.stream_id;
}
} else {
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 (LOG_ENABLED(INFO)) {
DLOG(INFO, downstream) << "Too many header field num="
<< resp.fs.num_fields() + 1;
DLOG(INFO, downstream)
<< "Too many header field num=" << resp.fs.num_fields() + 1;
}
return -1;
}

View File

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

View File

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

View File

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

View File

@ -538,8 +538,8 @@ int MemcachedConnection::parse_packet() {
if (LOG_ENABLED(INFO)) {
if (parse_state_.status_code) {
MCLOG(INFO, this) << "response returned error status: "
<< parse_state_.status_code;
MCLOG(INFO, this)
<< "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 {
// For tunneling, issue RST_STREAM to finish the stream.
if (LOG_ENABLED(INFO)) {
ULOG(INFO, upstream) << "RST_STREAM to tunneled stream stream_id="
<< stream_id;
ULOG(INFO, upstream)
<< "RST_STREAM to tunneled stream stream_id=" << stream_id;
}
upstream->rst_stream(
downstream, infer_upstream_rst_stream_status_code(

View File

@ -857,8 +857,9 @@ 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_verify(ssl_ctx, SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE |
SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
SSL_CTX_set_verify(ssl_ctx,
SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE |
SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
verify_callback);
}
SSL_CTX_set_tlsext_servername_callback(ssl_ctx, servername_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_session_cache_mode(ssl_ctx, SSL_SESS_CACHE_CLIENT |
SSL_SESS_CACHE_NO_INTERNAL_STORE);
SSL_CTX_set_session_cache_mode(
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);
if (nghttp2::tls::ssl_ctx_set_proto_versions(

View File

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

View File

@ -6484,8 +6484,8 @@ void test_nghttp2_session_flow_control_data_recv(void) {
nghttp2_frame_pack_frame_hd(data, &hd);
CU_ASSERT(NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN ==
nghttp2_session_mem_recv(session, data, NGHTTP2_MAX_PAYLOADLEN +
NGHTTP2_FRAME_HDLEN));
nghttp2_session_mem_recv(
session, data, NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN));
item = nghttp2_session_get_next_ob_item(session);
/* 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,
the subsequent flow control gets confused. */
CU_ASSERT(NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN ==
nghttp2_session_mem_recv(session, data, NGHTTP2_MAX_PAYLOADLEN +
NGHTTP2_FRAME_HDLEN));
nghttp2_session_mem_recv(
session, data, NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN));
item = nghttp2_session_get_next_ob_item(session);
CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type);