Skip to content

Commit

Permalink
assert -> AWS_ASSERT (#46)
Browse files Browse the repository at this point in the history
* assert -> AWS_ASSERT, removed assert.h includes

* added assert.h to clang-tidy restrictions
  • Loading branch information
Justin Boswell authored May 13, 2019
1 parent 6ea40ab commit 34dd4e1
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 99 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ CheckOptions:
- key: google-runtime-int.TypeSufix
value: '_t'
- key: fuchsia-restrict-system-includes.Includes
value: '*,-stdint.h,-stdbool.h'
value: '*,-stdint.h,-stdbool.h,-assert.h'

...
2 changes: 1 addition & 1 deletion bin/elasticurl/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ static void s_on_client_connection_setup(struct aws_http_connection *connection,
request_options.stream_outgoing_body = s_stream_outgoing_body_fn;
}

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

Expand Down
14 changes: 7 additions & 7 deletions source/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,17 @@ static struct aws_http_connection *s_connection_new(
}

void aws_http_connection_close(struct aws_http_connection *connection) {
assert(connection);
AWS_ASSERT(connection);
connection->vtable->close(connection);
}

bool aws_http_connection_is_open(const struct aws_http_connection *connection) {
assert(connection);
AWS_ASSERT(connection);
return connection->vtable->is_open(connection);
}

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

(void)bootstrap;
assert(user_data);
AWS_ASSERT(user_data);
struct aws_http_server *server = user_data;
bool user_cb_invoked = false;

Expand Down Expand Up @@ -376,7 +376,7 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options
}

void aws_http_server_destroy(struct aws_http_server *server) {
assert(server);
AWS_ASSERT(server);

if (server->socket) {
AWS_LOGF_INFO(
Expand All @@ -400,7 +400,7 @@ static void s_client_bootstrap_on_channel_setup(
void *user_data) {

(void)bootstrap;
assert(user_data);
AWS_ASSERT(user_data);
struct aws_http_client_connection_impl_options *options = user_data;

if (error_code) {
Expand Down
30 changes: 15 additions & 15 deletions source/connection_h1.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ static void s_write_headers(struct aws_byte_buf *dst, const struct aws_http_head
wrote_all &= aws_byte_buf_write_u8(dst, '\r');
wrote_all &= aws_byte_buf_write_u8(dst, '\n');
}
assert(wrote_all);
AWS_ASSERT(wrote_all);
}

struct aws_http_stream *s_new_client_request_stream(const struct aws_http_request_options *options) {
Expand Down Expand Up @@ -446,7 +446,7 @@ struct aws_http_stream *s_new_client_request_stream(const struct aws_http_reques
wrote_all &= aws_byte_buf_write_u8(&stream->outgoing_head_buf, '\r');
wrote_all &= aws_byte_buf_write_u8(&stream->outgoing_head_buf, '\n');
(void)wrote_all;
assert(wrote_all);
AWS_ASSERT(wrote_all);

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

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

stream->outgoing_head_progress += transferring;

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

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

assert(incoming_stream->base.incoming_request_method_str.len == 0);
assert(incoming_stream->base.incoming_request_uri.len == 0);
AWS_ASSERT(incoming_stream->base.incoming_request_method_str.len == 0);
AWS_ASSERT(incoming_stream->base.incoming_request_uri.len == 0);

AWS_LOGF_TRACE(
AWS_LS_HTTP_STREAM,
Expand All @@ -981,7 +981,7 @@ static int s_decoder_on_request(

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

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

struct h1_connection *connection = user_data;
struct h1_stream *incoming_stream = connection->thread_data.incoming_stream;
assert(incoming_stream);
AWS_ASSERT(incoming_stream);

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

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

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

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

s_stream_complete(incoming_stream, AWS_ERROR_SUCCESS);

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

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

assert(aws_linked_list_empty(&connection->thread_data.stream_list));
assert(aws_linked_list_empty(&connection->synced_data.pending_stream_list));
AWS_ASSERT(aws_linked_list_empty(&connection->thread_data.stream_list));
AWS_ASSERT(aws_linked_list_empty(&connection->synced_data.pending_stream_list));

aws_http_decoder_destroy(connection->thread_data.incoming_stream_decoder);
aws_mutex_clean_up(&connection->synced_data.lock);
Expand Down Expand Up @@ -1366,7 +1366,7 @@ static int s_handler_process_write_message(
(void)handler;
(void)slot;
(void)message;
assert(false); /* Should not be called until websocket stuff comes along. */
AWS_ASSERT(false); /* Should not be called until websocket stuff comes along. */
return aws_raise_error(AWS_ERROR_UNIMPLEMENTED);
}

Expand All @@ -1378,7 +1378,7 @@ static int s_handler_increment_read_window(
(void)handler;
(void)slot;
(void)size;
assert(false); /* Should not be called until websocket stuff comes along. */
AWS_ASSERT(false); /* Should not be called until websocket stuff comes along. */
return aws_raise_error(AWS_ERROR_UNIMPLEMENTED);
}

Expand Down
14 changes: 6 additions & 8 deletions source/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#include <aws/common/string.h>
#include <aws/io/logging.h>

#include <assert.h>

AWS_STATIC_STRING_FROM_LITERAL(s_transfer_coding_chunked, "chunked");
AWS_STATIC_STRING_FROM_LITERAL(s_transfer_coding_compress, "compress");
AWS_STATIC_STRING_FROM_LITERAL(s_transfer_coding_x_compress, "x-compress");
Expand Down Expand Up @@ -83,7 +81,7 @@ static struct aws_byte_cursor s_trim_whitespace(struct aws_byte_cursor cursor) {
}

static bool s_scan_for_crlf(struct aws_http_decoder *decoder, struct aws_byte_cursor input, size_t *bytes_processed) {
assert(input.len > 0);
AWS_ASSERT(input.len > 0);

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

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

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

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

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

struct aws_http_decoder *aws_http_decoder_new(struct aws_http_decoder_params *params) {
assert(params);
AWS_ASSERT(params);

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

int aws_http_decode(struct aws_http_decoder *decoder, const void *data, size_t data_bytes, size_t *bytes_read) {
assert(decoder);
assert(data);
AWS_ASSERT(decoder);
AWS_ASSERT(data);

struct aws_byte_cursor input = aws_byte_cursor_from_array(data, data_bytes);
size_t total_bytes_processed = 0;
Expand Down
12 changes: 5 additions & 7 deletions source/hpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@
#include <aws/common/hash_table.h>
#include <aws/common/string.h>

#include <assert.h>

struct aws_huffman_symbol_coder *hpack_get_coder(void);

int aws_hpack_encode_integer(uint64_t integer, uint8_t prefix_size, struct aws_byte_buf *output) {
assert(prefix_size <= 8);
AWS_ASSERT(prefix_size <= 8);

const struct aws_byte_buf output_backup = *output;

Expand Down Expand Up @@ -78,8 +76,8 @@ int aws_hpack_encode_integer(uint64_t integer, uint8_t prefix_size, struct aws_b
}

int aws_hpack_decode_integer(struct aws_byte_cursor *to_decode, uint8_t prefix_size, uint64_t *integer) {
assert(prefix_size <= 8);
assert(integer);
AWS_ASSERT(prefix_size <= 8);
AWS_ASSERT(integer);

const struct aws_byte_cursor to_decode_backup = *to_decode;

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

uint8_t byte = 0;
if (!aws_byte_cursor_read_u8(to_decode, &byte)) {
assert(false); /* Look 8 lines up */
AWS_ASSERT(false); /* Look 8 lines up */
return aws_raise_error(AWS_ERROR_SHORT_BUFFER);
}
/* Cut the prefix */
Expand Down Expand Up @@ -273,7 +271,7 @@ struct aws_http_header *aws_hpack_get_header(struct aws_hpack_context *context,

/* Check dynamic table */
index -= s_static_header_table_size;
assert(index < context->dynamic_table.num_elements);
AWS_ASSERT(index < context->dynamic_table.num_elements);
return &context->dynamic_table
.buffer[(context->dynamic_table.index_0 + index) % context->dynamic_table.max_elements];
}
Expand Down
1 change: 0 additions & 1 deletion source/hpack_huffman_static.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include <aws/compression/huffman.h>

#include <assert.h>
static struct aws_huffman_code code_points[] = {
{ .pattern = 0x1ff8, .num_bits = 13 }, /* ' ' 0 */
{ .pattern = 0x7fffd8, .num_bits = 23 }, /* ' ' 1 */
Expand Down
1 change: 0 additions & 1 deletion source/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <aws/common/hash_table.h>
#include <aws/io/logging.h>

#include <assert.h>
#include <ctype.h>

#ifdef _MSC_VER
Expand Down
12 changes: 6 additions & 6 deletions source/request_response.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct aws_http_stream *aws_http_stream_new_client_request(const struct aws_http
}

void aws_http_stream_release(struct aws_http_stream *stream) {
assert(stream);
AWS_ASSERT(stream);

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

struct aws_http_connection *aws_http_stream_get_connection(const struct aws_http_stream *stream) {
assert(stream);
AWS_ASSERT(stream);
return stream->owning_connection;
}

int aws_http_stream_get_incoming_response_status(const struct aws_http_stream *stream, int *out_status) {
assert(stream);
AWS_ASSERT(stream);

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

assert(stream);
AWS_ASSERT(stream);

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

int aws_http_stream_get_incoming_request_uri(const struct aws_http_stream *stream, struct aws_byte_cursor *out_uri) {
assert(stream);
AWS_ASSERT(stream);

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

0 comments on commit 34dd4e1

Please sign in to comment.