Skip to content

Commit 34dd4e1

Browse files
author
Justin Boswell
authored
assert -> AWS_ASSERT (#46)
* assert -> AWS_ASSERT, removed assert.h includes * added assert.h to clang-tidy restrictions
1 parent 6ea40ab commit 34dd4e1

13 files changed

+93
-99
lines changed

.clang-tidy

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ CheckOptions:
1010
- key: google-runtime-int.TypeSufix
1111
value: '_t'
1212
- key: fuchsia-restrict-system-includes.Includes
13-
value: '*,-stdint.h,-stdbool.h'
13+
value: '*,-stdint.h,-stdbool.h,-assert.h'
1414

1515
...

bin/elasticurl/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ static void s_on_client_connection_setup(struct aws_http_connection *connection,
378378
request_options.stream_outgoing_body = s_stream_outgoing_body_fn;
379379
}
380380

381-
assert(app_ctx->header_line_count <= 10);
381+
AWS_ASSERT(app_ctx->header_line_count <= 10);
382382
for (size_t i = 0; i < app_ctx->header_line_count; ++i) {
383383
char *delimiter = memchr(app_ctx->header_lines[i], ':', strlen(app_ctx->header_lines[i]));
384384

source/connection.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,17 @@ static struct aws_http_connection *s_connection_new(
168168
}
169169

170170
void aws_http_connection_close(struct aws_http_connection *connection) {
171-
assert(connection);
171+
AWS_ASSERT(connection);
172172
connection->vtable->close(connection);
173173
}
174174

175175
bool aws_http_connection_is_open(const struct aws_http_connection *connection) {
176-
assert(connection);
176+
AWS_ASSERT(connection);
177177
return connection->vtable->is_open(connection);
178178
}
179179

180180
void aws_http_connection_release(struct aws_http_connection *connection) {
181-
assert(connection);
181+
AWS_ASSERT(connection);
182182
size_t prev_refcount = aws_atomic_fetch_sub(&connection->refcount, 1);
183183
if (prev_refcount == 1) {
184184
AWS_LOGF_TRACE(
@@ -192,7 +192,7 @@ void aws_http_connection_release(struct aws_http_connection *connection) {
192192
/* When the channel's refcount reaches 0, it destroys its slots/handlers, which will destroy the connection */
193193
aws_channel_release_hold(connection->channel_slot->channel);
194194
} else {
195-
assert(prev_refcount != 0);
195+
AWS_ASSERT(prev_refcount != 0);
196196
AWS_LOGF_TRACE(
197197
AWS_LS_HTTP_CONNECTION,
198198
"id=%p: Connection refcount released, %zu remaining.",
@@ -210,7 +210,7 @@ static void s_server_bootstrap_on_accept_channel_setup(
210210
void *user_data) {
211211

212212
(void)bootstrap;
213-
assert(user_data);
213+
AWS_ASSERT(user_data);
214214
struct aws_http_server *server = user_data;
215215
bool user_cb_invoked = false;
216216

@@ -376,7 +376,7 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options
376376
}
377377

378378
void aws_http_server_destroy(struct aws_http_server *server) {
379-
assert(server);
379+
AWS_ASSERT(server);
380380

381381
if (server->socket) {
382382
AWS_LOGF_INFO(
@@ -400,7 +400,7 @@ static void s_client_bootstrap_on_channel_setup(
400400
void *user_data) {
401401

402402
(void)bootstrap;
403-
assert(user_data);
403+
AWS_ASSERT(user_data);
404404
struct aws_http_client_connection_impl_options *options = user_data;
405405

406406
if (error_code) {

source/connection_h1.c

+15-15
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ static void s_write_headers(struct aws_byte_buf *dst, const struct aws_http_head
350350
wrote_all &= aws_byte_buf_write_u8(dst, '\r');
351351
wrote_all &= aws_byte_buf_write_u8(dst, '\n');
352352
}
353-
assert(wrote_all);
353+
AWS_ASSERT(wrote_all);
354354
}
355355

356356
struct aws_http_stream *s_new_client_request_stream(const struct aws_http_request_options *options) {
@@ -446,7 +446,7 @@ struct aws_http_stream *s_new_client_request_stream(const struct aws_http_reques
446446
wrote_all &= aws_byte_buf_write_u8(&stream->outgoing_head_buf, '\r');
447447
wrote_all &= aws_byte_buf_write_u8(&stream->outgoing_head_buf, '\n');
448448
(void)wrote_all;
449-
assert(wrote_all);
449+
AWS_ASSERT(wrote_all);
450450

451451
/* Insert new stream into pending list, and schedule outgoing_stream_task if it's not already running. */
452452
bool is_shutting_down = false;
@@ -634,7 +634,7 @@ static void s_stream_write_outgoing_data(struct h1_stream *stream, struct aws_io
634634

635635
bool success = aws_byte_buf_write(dst, src->buffer + src_progress, transferring);
636636
(void)success;
637-
assert(success);
637+
AWS_ASSERT(success);
638638

639639
stream->outgoing_head_progress += transferring;
640640

@@ -785,7 +785,7 @@ static struct h1_stream *s_update_outgoing_stream_ptr(struct h1_connection *conn
785785
/* If it's also done receiving data, then it's complete! */
786786
if (current->is_incoming_message_done) {
787787
/* Only 1st stream in list could finish receiving before it finished sending */
788-
assert(&current->node == aws_linked_list_begin(&connection->thread_data.stream_list));
788+
AWS_ASSERT(&current->node == aws_linked_list_begin(&connection->thread_data.stream_list));
789789

790790
/* This removes stream from list */
791791
s_stream_complete(current, AWS_ERROR_SUCCESS);
@@ -969,8 +969,8 @@ static int s_decoder_on_request(
969969
struct h1_connection *connection = user_data;
970970
struct h1_stream *incoming_stream = connection->thread_data.incoming_stream;
971971

972-
assert(incoming_stream->base.incoming_request_method_str.len == 0);
973-
assert(incoming_stream->base.incoming_request_uri.len == 0);
972+
AWS_ASSERT(incoming_stream->base.incoming_request_method_str.len == 0);
973+
AWS_ASSERT(incoming_stream->base.incoming_request_uri.len == 0);
974974

975975
AWS_LOGF_TRACE(
976976
AWS_LS_HTTP_STREAM,
@@ -981,7 +981,7 @@ static int s_decoder_on_request(
981981

982982
/* Copy strings to internal buffer */
983983
struct aws_byte_buf *storage_buf = &incoming_stream->incoming_storage_buf;
984-
assert(storage_buf->capacity == 0);
984+
AWS_ASSERT(storage_buf->capacity == 0);
985985

986986
size_t storage_size = 0;
987987
int err = aws_add_size_checked(uri->len, method_str->len, &storage_size);
@@ -1098,7 +1098,7 @@ static int s_decoder_on_body(const struct aws_byte_cursor *data, bool finished,
10981098

10991099
struct h1_connection *connection = user_data;
11001100
struct h1_stream *incoming_stream = connection->thread_data.incoming_stream;
1101-
assert(incoming_stream);
1101+
AWS_ASSERT(incoming_stream);
11021102

11031103
int err = s_mark_head_done(incoming_stream);
11041104
if (err) {
@@ -1117,7 +1117,7 @@ static int s_decoder_on_body(const struct aws_byte_cursor *data, bool finished,
11171117
/* If user reduced window_update_size, reduce how much the connection will update its window. */
11181118
if (window_update_size < data->len) {
11191119
size_t reduce = data->len - window_update_size;
1120-
assert(reduce <= connection->thread_data.incoming_message_window_update);
1120+
AWS_ASSERT(reduce <= connection->thread_data.incoming_message_window_update);
11211121
connection->thread_data.incoming_message_window_update -= reduce;
11221122

11231123
AWS_LOGF_DEBUG(
@@ -1139,7 +1139,7 @@ static int s_decoder_on_body(const struct aws_byte_cursor *data, bool finished,
11391139
static int s_decoder_on_done(void *user_data) {
11401140
struct h1_connection *connection = user_data;
11411141
struct h1_stream *incoming_stream = connection->thread_data.incoming_stream;
1142-
assert(incoming_stream);
1142+
AWS_ASSERT(incoming_stream);
11431143

11441144
/* Ensure head was marked done */
11451145
int err = s_mark_head_done(incoming_stream);
@@ -1150,7 +1150,7 @@ static int s_decoder_on_done(void *user_data) {
11501150
incoming_stream->is_incoming_message_done = true;
11511151

11521152
if (incoming_stream->outgoing_state == STREAM_OUTGOING_STATE_DONE) {
1153-
assert(&incoming_stream->node == aws_linked_list_begin(&connection->thread_data.stream_list));
1153+
AWS_ASSERT(&incoming_stream->node == aws_linked_list_begin(&connection->thread_data.stream_list));
11541154

11551155
s_stream_complete(incoming_stream, AWS_ERROR_SUCCESS);
11561156

@@ -1260,8 +1260,8 @@ static void s_handler_destroy(struct aws_channel_handler *handler) {
12601260

12611261
AWS_LOGF_TRACE(AWS_LS_HTTP_CONNECTION, "id=%p: Destroying connection.", (void *)&connection->base);
12621262

1263-
assert(aws_linked_list_empty(&connection->thread_data.stream_list));
1264-
assert(aws_linked_list_empty(&connection->synced_data.pending_stream_list));
1263+
AWS_ASSERT(aws_linked_list_empty(&connection->thread_data.stream_list));
1264+
AWS_ASSERT(aws_linked_list_empty(&connection->synced_data.pending_stream_list));
12651265

12661266
aws_http_decoder_destroy(connection->thread_data.incoming_stream_decoder);
12671267
aws_mutex_clean_up(&connection->synced_data.lock);
@@ -1366,7 +1366,7 @@ static int s_handler_process_write_message(
13661366
(void)handler;
13671367
(void)slot;
13681368
(void)message;
1369-
assert(false); /* Should not be called until websocket stuff comes along. */
1369+
AWS_ASSERT(false); /* Should not be called until websocket stuff comes along. */
13701370
return aws_raise_error(AWS_ERROR_UNIMPLEMENTED);
13711371
}
13721372

@@ -1378,7 +1378,7 @@ static int s_handler_increment_read_window(
13781378
(void)handler;
13791379
(void)slot;
13801380
(void)size;
1381-
assert(false); /* Should not be called until websocket stuff comes along. */
1381+
AWS_ASSERT(false); /* Should not be called until websocket stuff comes along. */
13821382
return aws_raise_error(AWS_ERROR_UNIMPLEMENTED);
13831383
}
13841384

source/decode.c

+6-8
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
#include <aws/common/string.h>
1919
#include <aws/io/logging.h>
2020

21-
#include <assert.h>
22-
2321
AWS_STATIC_STRING_FROM_LITERAL(s_transfer_coding_chunked, "chunked");
2422
AWS_STATIC_STRING_FROM_LITERAL(s_transfer_coding_compress, "compress");
2523
AWS_STATIC_STRING_FROM_LITERAL(s_transfer_coding_x_compress, "x-compress");
@@ -83,7 +81,7 @@ static struct aws_byte_cursor s_trim_whitespace(struct aws_byte_cursor cursor) {
8381
}
8482

8583
static bool s_scan_for_crlf(struct aws_http_decoder *decoder, struct aws_byte_cursor input, size_t *bytes_processed) {
86-
assert(input.len > 0);
84+
AWS_ASSERT(input.len > 0);
8785

8886
/* In a loop, scan for "\n", then look one char back for "\r" */
8987
uint8_t *ptr = input.ptr;
@@ -235,7 +233,7 @@ static int s_state_getline(struct aws_http_decoder *decoder, struct aws_byte_cur
235233

236234
/* Backup so "\r\n" is not included. */
237235
/* RFC-7230 section 3 Message Format */
238-
assert(line.len >= 2);
236+
AWS_ASSERT(line.len >= 2);
239237
line.len -= 2;
240238

241239
return decoder->process_line(decoder, line);
@@ -381,7 +379,7 @@ static int s_linestate_chunk_terminator(struct aws_http_decoder *decoder, struct
381379

382380
static int s_state_chunk(struct aws_http_decoder *decoder, struct aws_byte_cursor input, size_t *bytes_processed) {
383381
size_t processed_bytes = 0;
384-
assert(decoder->chunk_processed < decoder->chunk_size);
382+
AWS_ASSERT(decoder->chunk_processed < decoder->chunk_size);
385383

386384
if ((decoder->chunk_processed + input.len) > decoder->chunk_size) {
387385
processed_bytes = decoder->chunk_size - decoder->chunk_processed;
@@ -735,7 +733,7 @@ static int s_linestate_response(struct aws_http_decoder *decoder, struct aws_byt
735733
}
736734

737735
struct aws_http_decoder *aws_http_decoder_new(struct aws_http_decoder_params *params) {
738-
assert(params);
736+
AWS_ASSERT(params);
739737

740738
struct aws_http_decoder *decoder = aws_mem_acquire(params->alloc, sizeof(struct aws_http_decoder));
741739
if (!decoder) {
@@ -761,8 +759,8 @@ void aws_http_decoder_destroy(struct aws_http_decoder *decoder) {
761759
}
762760

763761
int aws_http_decode(struct aws_http_decoder *decoder, const void *data, size_t data_bytes, size_t *bytes_read) {
764-
assert(decoder);
765-
assert(data);
762+
AWS_ASSERT(decoder);
763+
AWS_ASSERT(data);
766764

767765
struct aws_byte_cursor input = aws_byte_cursor_from_array(data, data_bytes);
768766
size_t total_bytes_processed = 0;

source/hpack.c

+5-7
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@
2323
#include <aws/common/hash_table.h>
2424
#include <aws/common/string.h>
2525

26-
#include <assert.h>
27-
2826
struct aws_huffman_symbol_coder *hpack_get_coder(void);
2927

3028
int aws_hpack_encode_integer(uint64_t integer, uint8_t prefix_size, struct aws_byte_buf *output) {
31-
assert(prefix_size <= 8);
29+
AWS_ASSERT(prefix_size <= 8);
3230

3331
const struct aws_byte_buf output_backup = *output;
3432

@@ -78,8 +76,8 @@ int aws_hpack_encode_integer(uint64_t integer, uint8_t prefix_size, struct aws_b
7876
}
7977

8078
int aws_hpack_decode_integer(struct aws_byte_cursor *to_decode, uint8_t prefix_size, uint64_t *integer) {
81-
assert(prefix_size <= 8);
82-
assert(integer);
79+
AWS_ASSERT(prefix_size <= 8);
80+
AWS_ASSERT(integer);
8381

8482
const struct aws_byte_cursor to_decode_backup = *to_decode;
8583

@@ -91,7 +89,7 @@ int aws_hpack_decode_integer(struct aws_byte_cursor *to_decode, uint8_t prefix_s
9189

9290
uint8_t byte = 0;
9391
if (!aws_byte_cursor_read_u8(to_decode, &byte)) {
94-
assert(false); /* Look 8 lines up */
92+
AWS_ASSERT(false); /* Look 8 lines up */
9593
return aws_raise_error(AWS_ERROR_SHORT_BUFFER);
9694
}
9795
/* Cut the prefix */
@@ -273,7 +271,7 @@ struct aws_http_header *aws_hpack_get_header(struct aws_hpack_context *context,
273271

274272
/* Check dynamic table */
275273
index -= s_static_header_table_size;
276-
assert(index < context->dynamic_table.num_elements);
274+
AWS_ASSERT(index < context->dynamic_table.num_elements);
277275
return &context->dynamic_table
278276
.buffer[(context->dynamic_table.index_0 + index) % context->dynamic_table.max_elements];
279277
}

source/hpack_huffman_static.c

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
#include <aws/compression/huffman.h>
2020

21-
#include <assert.h>
2221
static struct aws_huffman_code code_points[] = {
2322
{ .pattern = 0x1ff8, .num_bits = 13 }, /* ' ' 0 */
2423
{ .pattern = 0x7fffd8, .num_bits = 23 }, /* ' ' 1 */

source/http.c

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <aws/common/hash_table.h>
2020
#include <aws/io/logging.h>
2121

22-
#include <assert.h>
2322
#include <ctype.h>
2423

2524
#ifdef _MSC_VER

source/request_response.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct aws_http_stream *aws_http_stream_new_client_request(const struct aws_http
4141
}
4242

4343
void aws_http_stream_release(struct aws_http_stream *stream) {
44-
assert(stream);
44+
AWS_ASSERT(stream);
4545

4646
size_t prev_refcount = aws_atomic_fetch_sub(&stream->refcount, 1);
4747
if (prev_refcount == 1) {
@@ -53,19 +53,19 @@ void aws_http_stream_release(struct aws_http_stream *stream) {
5353
/* Connection needed to outlive stream, but it's free to go now */
5454
aws_http_connection_release(owning_connection);
5555
} else {
56-
assert(prev_refcount != 0);
56+
AWS_ASSERT(prev_refcount != 0);
5757
AWS_LOGF_TRACE(
5858
AWS_LS_HTTP_STREAM, "id=%p: Stream refcount released, %zu remaining.", (void *)stream, prev_refcount - 1);
5959
}
6060
}
6161

6262
struct aws_http_connection *aws_http_stream_get_connection(const struct aws_http_stream *stream) {
63-
assert(stream);
63+
AWS_ASSERT(stream);
6464
return stream->owning_connection;
6565
}
6666

6767
int aws_http_stream_get_incoming_response_status(const struct aws_http_stream *stream, int *out_status) {
68-
assert(stream);
68+
AWS_ASSERT(stream);
6969

7070
if (stream->incoming_response_status == (int)AWS_HTTP_STATUS_UNKNOWN) {
7171
AWS_LOGF_ERROR(AWS_LS_HTTP_STREAM, "id=%p: Status code not yet received.", (void *)stream);
@@ -80,7 +80,7 @@ int aws_http_stream_get_incoming_request_method(
8080
const struct aws_http_stream *stream,
8181
struct aws_byte_cursor *out_method) {
8282

83-
assert(stream);
83+
AWS_ASSERT(stream);
8484

8585
if (!stream->incoming_request_method_str.ptr) {
8686
AWS_LOGF_ERROR(AWS_LS_HTTP_STREAM, "id=%p: Request method not yet received.", (void *)stream);
@@ -92,7 +92,7 @@ int aws_http_stream_get_incoming_request_method(
9292
}
9393

9494
int aws_http_stream_get_incoming_request_uri(const struct aws_http_stream *stream, struct aws_byte_cursor *out_uri) {
95-
assert(stream);
95+
AWS_ASSERT(stream);
9696

9797
if (!stream->incoming_request_uri.ptr) {
9898
AWS_LOGF_ERROR(AWS_LS_HTTP_STREAM, "id=%p: Request URI not yet received.", (void *)stream);

0 commit comments

Comments
 (0)