Skip to content

Commit 079ccfd

Browse files
authored
clang-format 18 (#469)
see: awslabs/aws-c-common#1113
1 parent d83f8d7 commit 079ccfd

17 files changed

+106
-57
lines changed

.github/workflows/clang-format.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ on: [push]
55
jobs:
66
clang-format:
77

8-
runs-on: ubuntu-20.04 # latest
8+
runs-on: ubuntu-24.04 # latest
99

1010
steps:
1111
- name: Checkout Sources
12-
uses: actions/checkout@v1
12+
uses: actions/checkout@v4
1313

1414
- name: clang-format lint
15-
uses: DoozyX/clang-format-lint-action@v0.3.1
16-
with:
17-
# List of extensions to check
18-
extensions: c,h
15+
run: |
16+
./format-check.py

format-check.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python3
2+
import argparse
3+
import os
4+
from pathlib import Path
5+
import re
6+
from subprocess import list2cmdline, run
7+
from tempfile import NamedTemporaryFile
8+
9+
CLANG_FORMAT_VERSION = '18.1.6'
10+
11+
INCLUDE_REGEX = re.compile(
12+
r'^(include|source|tests|verification)/.*\.(c|h|inl)$')
13+
EXCLUDE_REGEX = re.compile(r'^$')
14+
15+
arg_parser = argparse.ArgumentParser(description="Check with clang-format")
16+
arg_parser.add_argument('-i', '--inplace-edit', action='store_true',
17+
help="Edit files inplace")
18+
args = arg_parser.parse_args()
19+
20+
os.chdir(Path(__file__).parent)
21+
22+
# create file containing list of all files to format
23+
filepaths_file = NamedTemporaryFile(delete=False)
24+
for dirpath, dirnames, filenames in os.walk('.'):
25+
for filename in filenames:
26+
# our regexes expect filepath to use forward slash
27+
filepath = Path(dirpath, filename).as_posix()
28+
if not INCLUDE_REGEX.match(filepath):
29+
continue
30+
if EXCLUDE_REGEX.match(filepath):
31+
continue
32+
33+
filepaths_file.write(f"{filepath}\n".encode())
34+
filepaths_file.close()
35+
36+
# use pipx to run clang-format from PyPI
37+
# this is a simple way to run the same clang-format version regardless of OS
38+
cmd = ['pipx', 'run', f'clang-format=={CLANG_FORMAT_VERSION}',
39+
f'--files={filepaths_file.name}']
40+
if args.inplace_edit:
41+
cmd += ['-i']
42+
else:
43+
cmd += ['--Werror', '--dry-run']
44+
45+
print(f"{Path.cwd()}$ {list2cmdline(cmd)}")
46+
if run(cmd).returncode:
47+
exit(1)

format-check.sh

Lines changed: 0 additions & 24 deletions
This file was deleted.

include/aws/http/connection.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,10 @@ struct aws_http2_setting {
455455
* Initializes aws_http_client_connection_options with default values.
456456
*/
457457
#define AWS_HTTP_CLIENT_CONNECTION_OPTIONS_INIT \
458-
{ .self_size = sizeof(struct aws_http_client_connection_options), .initial_window_size = SIZE_MAX, }
458+
{ \
459+
.self_size = sizeof(struct aws_http_client_connection_options), \
460+
.initial_window_size = SIZE_MAX, \
461+
}
459462

460463
AWS_EXTERN_C_BEGIN
461464

include/aws/http/private/h2_frames.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ struct aws_h2err {
5050
};
5151

5252
#define AWS_H2ERR_SUCCESS \
53-
(struct aws_h2err) { .h2_code = 0, .aws_code = 0 }
53+
(struct aws_h2err) { \
54+
.h2_code = 0, .aws_code = 0 \
55+
}
5456

5557
#define AWS_H2_PAYLOAD_MAX (0x00FFFFFF) /* must fit in 3 bytes */
5658
#define AWS_H2_WINDOW_UPDATE_MAX (0x7FFFFFFF) /* cannot use high bit */

include/aws/http/proxy.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ typedef struct aws_string *(aws_http_proxy_negotiation_get_token_sync_fn)(void *
161161
* Synchronous (for now) callback function to fetch a token used in modifying CONNECT request. Includes a (byte string)
162162
* context intended to be used as part of a challenge-response flow.
163163
*/
164-
typedef struct aws_string *(aws_http_proxy_negotiation_get_challenge_token_sync_fn)(
165-
void *user_data,
166-
const struct aws_byte_cursor *challenge_context,
167-
int *out_error_code);
164+
typedef struct aws_string *(
165+
aws_http_proxy_negotiation_get_challenge_token_sync_fn)(void *user_data,
166+
const struct aws_byte_cursor *challenge_context,
167+
int *out_error_code);
168168

169169
/**
170170
* Proxy negotiation logic must call this function to indicate an unsuccessful outcome
@@ -307,9 +307,9 @@ struct aws_http_proxy_negotiator {
307307

308308
/*********************************************************************************************/
309309

310-
typedef struct aws_http_proxy_negotiator *(aws_http_proxy_strategy_create_negotiator_fn)(
311-
struct aws_http_proxy_strategy *proxy_strategy,
312-
struct aws_allocator *allocator);
310+
typedef struct aws_http_proxy_negotiator *(
311+
aws_http_proxy_strategy_create_negotiator_fn)(struct aws_http_proxy_strategy *proxy_strategy,
312+
struct aws_allocator *allocator);
313313

314314
struct aws_http_proxy_strategy_vtable {
315315
aws_http_proxy_strategy_create_negotiator_fn *create_negotiator;

include/aws/http/request_response.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,9 @@ struct aws_http2_stream_write_data_options {
501501
};
502502

503503
#define AWS_HTTP_REQUEST_HANDLER_OPTIONS_INIT \
504-
{ .self_size = sizeof(struct aws_http_request_handler_options), }
504+
{ \
505+
.self_size = sizeof(struct aws_http_request_handler_options), \
506+
}
505507

506508
AWS_EXTERN_C_BEGIN
507509

include/aws/http/server.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,18 @@ struct aws_http_server_options {
112112
* Initializes aws_http_server_options with default values.
113113
*/
114114
#define AWS_HTTP_SERVER_OPTIONS_INIT \
115-
{ .self_size = sizeof(struct aws_http_server_options), .initial_window_size = SIZE_MAX, }
115+
{ \
116+
.self_size = sizeof(struct aws_http_server_options), \
117+
.initial_window_size = SIZE_MAX, \
118+
}
116119

117120
/**
118121
* Invoked at the start of an incoming request.
119122
* To process the request, the user must create a request handler stream and return it to the connection.
120123
* If NULL is returned, the request will not be processed and the last error will be reported as the reason for failure.
121124
*/
122-
typedef struct aws_http_stream *(
123-
aws_http_on_incoming_request_fn)(struct aws_http_connection *connection, void *user_data);
125+
typedef struct aws_http_stream *(aws_http_on_incoming_request_fn)(struct aws_http_connection *connection,
126+
void *user_data);
124127

125128
typedef void(aws_http_on_server_connection_shutdown_fn)(
126129
struct aws_http_connection *connection,
@@ -163,7 +166,9 @@ struct aws_http_server_connection_options {
163166
* Initializes aws_http_server_connection_options with default values.
164167
*/
165168
#define AWS_HTTP_SERVER_CONNECTION_OPTIONS_INIT \
166-
{ .self_size = sizeof(struct aws_http_server_connection_options), }
169+
{ \
170+
.self_size = sizeof(struct aws_http_server_connection_options), \
171+
}
167172

168173
AWS_EXTERN_C_BEGIN
169174

source/http.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#include <ctype.h>
1414

15-
#define AWS_DEFINE_ERROR_INFO_HTTP(CODE, STR) [(CODE)-0x0800] = AWS_DEFINE_ERROR_INFO(CODE, STR, "aws-c-http")
15+
#define AWS_DEFINE_ERROR_INFO_HTTP(CODE, STR) [(CODE) - 0x0800] = AWS_DEFINE_ERROR_INFO(CODE, STR, "aws-c-http")
1616

1717
/* clang-format off */
1818
static struct aws_error_info s_errors[] = {

tests/test_h1_client.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,11 +1318,11 @@ static int s_can_parse_as_chunked_encoding(
13181318
}
13191319
}
13201320
long chunk_size = strtol((char *)chunk_ascii_hex, 0, 16);
1321-
long total_chunk_size_with_overhead = (long)
1322-
(match_cursor.ptr - request_cursor.ptr /* size of the chunk in ascii hex */
1323-
+ crlf_cursor.len /* size of the crlf */
1324-
+ chunk_size /* size of the payload */
1325-
+ crlf_cursor.len); /* size of the chunk terminating crlf */
1321+
long total_chunk_size_with_overhead =
1322+
(long)(match_cursor.ptr - request_cursor.ptr /* size of the chunk in ascii hex */
1323+
+ crlf_cursor.len /* size of the crlf */
1324+
+ chunk_size /* size of the payload */
1325+
+ crlf_cursor.len); /* size of the chunk terminating crlf */
13261326

13271327
/* 0 length chunk signals end of stream. Check for the terminatino string and exit with success */
13281328
if (0 == chunk_size) {

0 commit comments

Comments
 (0)