Skip to content

Commit

Permalink
clang-format 18
Browse files Browse the repository at this point in the history
  • Loading branch information
graebm committed Jun 12, 2024
1 parent d83f8d7 commit a18aad2
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 57 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ on: [push]
jobs:
clang-format:

runs-on: ubuntu-20.04 # latest
runs-on: ubuntu-24.04 # latest

steps:
- name: Checkout Sources
uses: actions/checkout@v1
uses: actions/checkout@v4

- name: clang-format lint
uses: DoozyX/[email protected]
with:
# List of extensions to check
extensions: c,h
run: |
./format-check.py
47 changes: 47 additions & 0 deletions format-check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python3
import argparse
import os
from pathlib import Path
import re
from subprocess import list2cmdline, run
from tempfile import NamedTemporaryFile

CLANG_FORMAT_VERSION = '18.1.6'

INCLUDE_REGEX = re.compile(
r'^(include|source|tests|verification)/.*\.(c|h|inl)$')
EXCLUDE_REGEX = re.compile(r'^$')

arg_parser = argparse.ArgumentParser(description="Check with clang-format")
arg_parser.add_argument('-i', '--inplace-edit', action='store_true',
help="Edit files inplace")
args = arg_parser.parse_args()

os.chdir(Path(__file__).parent)

# create file containing list of all files to format
filepaths_file = NamedTemporaryFile(delete=False)
for dirpath, dirnames, filenames in os.walk('.'):
for filename in filenames:
# our regexes expect filepath to use forward slash
filepath = Path(dirpath, filename).as_posix()
if not INCLUDE_REGEX.match(filepath):
continue
if EXCLUDE_REGEX.match(filepath):
continue

filepaths_file.write(f"{filepath}\n".encode())
filepaths_file.close()

# use pipx to run clang-format from PyPI
# this is a simple way to run the same clang-format version regardless of OS
cmd = ['pipx', 'run', f'clang-format=={CLANG_FORMAT_VERSION}',
f'--files={filepaths_file.name}']
if args.inplace_edit:
cmd += ['-i']
else:
cmd += ['--Werror', '--dry-run']

print(f"{Path.cwd()}$ {list2cmdline(cmd)}")
if run(cmd).returncode:
exit(1)
24 changes: 0 additions & 24 deletions format-check.sh

This file was deleted.

5 changes: 4 additions & 1 deletion include/aws/http/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,10 @@ struct aws_http2_setting {
* Initializes aws_http_client_connection_options with default values.
*/
#define AWS_HTTP_CLIENT_CONNECTION_OPTIONS_INIT \
{ .self_size = sizeof(struct aws_http_client_connection_options), .initial_window_size = SIZE_MAX, }
{ \
.self_size = sizeof(struct aws_http_client_connection_options), \
.initial_window_size = SIZE_MAX, \
}

AWS_EXTERN_C_BEGIN

Expand Down
4 changes: 3 additions & 1 deletion include/aws/http/private/h2_frames.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ struct aws_h2err {
};

#define AWS_H2ERR_SUCCESS \
(struct aws_h2err) { .h2_code = 0, .aws_code = 0 }
(struct aws_h2err) { \
.h2_code = 0, .aws_code = 0 \
}

#define AWS_H2_PAYLOAD_MAX (0x00FFFFFF) /* must fit in 3 bytes */
#define AWS_H2_WINDOW_UPDATE_MAX (0x7FFFFFFF) /* cannot use high bit */
Expand Down
14 changes: 7 additions & 7 deletions include/aws/http/proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ typedef struct aws_string *(aws_http_proxy_negotiation_get_token_sync_fn)(void *
* Synchronous (for now) callback function to fetch a token used in modifying CONNECT request. Includes a (byte string)
* context intended to be used as part of a challenge-response flow.
*/
typedef struct aws_string *(aws_http_proxy_negotiation_get_challenge_token_sync_fn)(
void *user_data,
const struct aws_byte_cursor *challenge_context,
int *out_error_code);
typedef struct aws_string *(
aws_http_proxy_negotiation_get_challenge_token_sync_fn)(void *user_data,
const struct aws_byte_cursor *challenge_context,
int *out_error_code);

/**
* Proxy negotiation logic must call this function to indicate an unsuccessful outcome
Expand Down Expand Up @@ -307,9 +307,9 @@ struct aws_http_proxy_negotiator {

/*********************************************************************************************/

typedef struct aws_http_proxy_negotiator *(aws_http_proxy_strategy_create_negotiator_fn)(
struct aws_http_proxy_strategy *proxy_strategy,
struct aws_allocator *allocator);
typedef struct aws_http_proxy_negotiator *(
aws_http_proxy_strategy_create_negotiator_fn)(struct aws_http_proxy_strategy *proxy_strategy,
struct aws_allocator *allocator);

struct aws_http_proxy_strategy_vtable {
aws_http_proxy_strategy_create_negotiator_fn *create_negotiator;
Expand Down
4 changes: 3 additions & 1 deletion include/aws/http/request_response.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,9 @@ struct aws_http2_stream_write_data_options {
};

#define AWS_HTTP_REQUEST_HANDLER_OPTIONS_INIT \
{ .self_size = sizeof(struct aws_http_request_handler_options), }
{ \
.self_size = sizeof(struct aws_http_request_handler_options), \
}

AWS_EXTERN_C_BEGIN

Expand Down
13 changes: 9 additions & 4 deletions include/aws/http/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,18 @@ struct aws_http_server_options {
* Initializes aws_http_server_options with default values.
*/
#define AWS_HTTP_SERVER_OPTIONS_INIT \
{ .self_size = sizeof(struct aws_http_server_options), .initial_window_size = SIZE_MAX, }
{ \
.self_size = sizeof(struct aws_http_server_options), \
.initial_window_size = SIZE_MAX, \
}

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

typedef void(aws_http_on_server_connection_shutdown_fn)(
struct aws_http_connection *connection,
Expand Down Expand Up @@ -163,7 +166,9 @@ struct aws_http_server_connection_options {
* Initializes aws_http_server_connection_options with default values.
*/
#define AWS_HTTP_SERVER_CONNECTION_OPTIONS_INIT \
{ .self_size = sizeof(struct aws_http_server_connection_options), }
{ \
.self_size = sizeof(struct aws_http_server_connection_options), \
}

AWS_EXTERN_C_BEGIN

Expand Down
2 changes: 1 addition & 1 deletion source/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <ctype.h>

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

/* clang-format off */
static struct aws_error_info s_errors[] = {
Expand Down
10 changes: 5 additions & 5 deletions tests/test_h1_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1318,11 +1318,11 @@ static int s_can_parse_as_chunked_encoding(
}
}
long chunk_size = strtol((char *)chunk_ascii_hex, 0, 16);
long total_chunk_size_with_overhead = (long)
(match_cursor.ptr - request_cursor.ptr /* size of the chunk in ascii hex */
+ crlf_cursor.len /* size of the crlf */
+ chunk_size /* size of the payload */
+ crlf_cursor.len); /* size of the chunk terminating crlf */
long total_chunk_size_with_overhead =
(long)(match_cursor.ptr - request_cursor.ptr /* size of the chunk in ascii hex */
+ crlf_cursor.len /* size of the crlf */
+ chunk_size /* size of the payload */
+ crlf_cursor.len); /* size of the chunk terminating crlf */

/* 0 length chunk signals end of stream. Check for the terminatino string and exit with success */
if (0 == chunk_size) {
Expand Down
5 changes: 4 additions & 1 deletion tests/test_h2_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
static int s_test_##NAME(struct aws_allocator *allocator, void *ctx)

#define DEFINE_HEADER(NAME, VALUE) \
{ .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(NAME), .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(VALUE), }
{ \
.name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(NAME), \
.value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(VALUE), \
}

struct connection_user_data {
struct aws_allocator *allocator;
Expand Down
3 changes: 2 additions & 1 deletion tests/test_h2_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ static int s_fixture_clean_up(struct aws_allocator *allocator, int setup_res, vo

#define DEFINE_STATIC_HEADER(_key, _value, _behavior) \
{ \
.name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(_key), .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(_value), \
.name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(_key), \
.value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(_value), \
.compression = AWS_HTTP_HEADER_COMPRESSION_##_behavior, \
}

Expand Down
3 changes: 2 additions & 1 deletion tests/test_h2_headers.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ static int s_header_test_after(struct aws_allocator *allocator, int setup_res, v

#define DEFINE_STATIC_HEADER(_key, _value, _behavior) \
{ \
.name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(_key), .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(_value), \
.name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(_key), \
.value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(_value), \
.compression = AWS_HTTP_HEADER_COMPRESSION_##_behavior, \
}

Expand Down
5 changes: 4 additions & 1 deletion tests/test_localhost_integ.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ struct tester {
static struct tester s_tester;

#define DEFINE_HEADER(NAME, VALUE) \
{ .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(NAME), .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(VALUE), }
{ \
.name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(NAME), \
.value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(VALUE), \
}

enum {
TESTER_TIMEOUT_SEC = 60, /* Give enough time for non-sudo users to enter password */
Expand Down
5 changes: 4 additions & 1 deletion tests/test_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
AWS_TEST_CASE(NAME, s_test_##NAME); \
static int s_test_##NAME(struct aws_allocator *allocator, void *ctx)
#define DEFINE_HEADER(NAME, VALUE) \
{ .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(NAME), .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(VALUE), }
{ \
.name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(NAME), \
.value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(VALUE), \
}

TEST_CASE(message_sanity_check) {
(void)ctx;
Expand Down
5 changes: 4 additions & 1 deletion tests/test_stream_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
static int s_test_##NAME(struct aws_allocator *allocator, void *ctx)

#define DEFINE_HEADER(NAME, VALUE) \
{ .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(NAME), .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(VALUE), }
{ \
.name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(NAME), \
.value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(VALUE), \
}

struct sm_tester_options {
struct aws_allocator *alloc;
Expand Down
4 changes: 3 additions & 1 deletion tests/test_websocket_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ struct incoming_frame {
bool is_complete;
};

static struct tester_options { bool manual_window_update; } s_tester_options;
static struct tester_options {
bool manual_window_update;
} s_tester_options;

struct tester {
struct aws_allocator *alloc;
Expand Down

0 comments on commit a18aad2

Please sign in to comment.