Skip to content

Commit

Permalink
refactor: use the corrent cast operation (apache#1062)
Browse files Browse the repository at this point in the history
  • Loading branch information
levy5307 authored Feb 28, 2022
1 parent a9ace87 commit d60c17c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/aio/test/aio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ TEST(core, aio)
tasks.clear();
std::unique_ptr<dsn_file_buffer_t[]> buffers(new dsn_file_buffer_t[100]);
for (int i = 0; i < 10; i++) {
buffers[i].buffer = reinterpret_cast<void *>(const_cast<char *>(buffer));
buffers[i].buffer = static_cast<void *>(const_cast<char *>(buffer));
buffers[i].size = len;
}
for (int i = 0; i < 10; i++) {
Expand Down
14 changes: 7 additions & 7 deletions src/http/http_message_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ http_message_parser::http_message_parser()
memset(&_parser_setting, 0, sizeof(_parser_setting));

_parser_setting.on_message_begin = [](http_parser *parser) -> int {
auto &msg = reinterpret_cast<parser_context *>(parser->data)->parser->_current_message;
auto &msg = static_cast<parser_context *>(parser->data)->parser->_current_message;

// initialize http message
// msg->buffers[0] = header
Expand All @@ -87,15 +87,15 @@ http_message_parser::http_message_parser()
};

_parser_setting.on_url = [](http_parser *parser, const char *at, size_t length) -> int {
http_message_parser *msg_parser = reinterpret_cast<parser_context *>(parser->data)->parser;
http_message_parser *msg_parser = static_cast<parser_context *>(parser->data)->parser;
msg_parser->_stage = HTTP_ON_URL;
msg_parser->_url.append(at, length);
return 0;
};

_parser_setting.on_header_field =
[](http_parser *parser, const char *at, size_t length) -> int {
http_message_parser *msg_parser = reinterpret_cast<parser_context *>(parser->data)->parser;
http_message_parser *msg_parser = static_cast<parser_context *>(parser->data)->parser;
msg_parser->_stage = HTTP_ON_HEADER_FIELD;
if (strncmp(at, "Content-Type", length) == 0) {
msg_parser->_is_field_content_type = true;
Expand All @@ -105,7 +105,7 @@ http_message_parser::http_message_parser()

_parser_setting.on_header_value =
[](http_parser *parser, const char *at, size_t length) -> int {
http_message_parser *msg_parser = reinterpret_cast<parser_context *>(parser->data)->parser;
http_message_parser *msg_parser = static_cast<parser_context *>(parser->data)->parser;
msg_parser->_stage = HTTP_ON_HEADER_VALUE;
if (msg_parser->_is_field_content_type) {
auto &msg = msg_parser->_current_message;
Expand All @@ -117,7 +117,7 @@ http_message_parser::http_message_parser()
};

_parser_setting.on_headers_complete = [](http_parser *parser) -> int {
http_message_parser *msg_parser = reinterpret_cast<parser_context *>(parser->data)->parser;
http_message_parser *msg_parser = static_cast<parser_context *>(parser->data)->parser;
msg_parser->_stage = HTTP_ON_HEADERS_COMPLETE;

auto &msg = msg_parser->_current_message;
Expand All @@ -140,7 +140,7 @@ http_message_parser::http_message_parser()
};

_parser_setting.on_message_complete = [](http_parser *parser) -> int {
auto message_parser = reinterpret_cast<parser_context *>(parser->data)->parser;
auto message_parser = static_cast<parser_context *>(parser->data)->parser;
message_parser->_received_messages.emplace(std::move(message_parser->_current_message));
message_parser->_stage = HTTP_ON_MESSAGE_COMPLETE;
return 0;
Expand All @@ -160,7 +160,7 @@ message_ex *http_message_parser::get_message_on_receive(message_reader *reader,
_parser.data = &ctx;

_parser_setting.on_body = [](http_parser *parser, const char *at, size_t length) -> int {
auto data = reinterpret_cast<parser_context *>(parser->data);
auto data = static_cast<parser_context *>(parser->data);
auto &msg = data->parser->_current_message;
blob read_buf = data->reader->_buffer;

Expand Down
6 changes: 3 additions & 3 deletions src/meta/meta_state_service_simple.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class meta_state_service_simple : public meta_state_service
writer.write(static_cast<int>(op));
write(writer, head, tail...);
auto shared_blob = writer.get_buffer();
reinterpret_cast<log_header *>((char *)shared_blob.data())->size =
reinterpret_cast<log_header *>(const_cast<char *>(shared_blob.data()))->size =
shared_blob.length() - sizeof(log_header);
return shared_blob;
}
Expand Down Expand Up @@ -266,5 +266,5 @@ class meta_state_service_simple : public meta_state_service

dsn::task_tracker _tracker;
};
}
}
} // namespace dist
} // namespace dsn
3 changes: 1 addition & 2 deletions src/replica/log_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,7 @@ aio_task_ptr log_file::commit_log_blocks(log_appender &pending,

for (int i = 0; i < block.data().size(); i++) {
auto &blk = block.data()[i];
buffer_vector[buffer_idx].buffer =
reinterpret_cast<void *>(const_cast<char *>(blk.data()));
buffer_vector[buffer_idx].buffer = static_cast<void *>(const_cast<char *>(blk.data()));
buffer_vector[buffer_idx].size = blk.length();

// skip block header
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/rpc/thrift_message_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ void thrift_message_parser::prepare_on_send(message_ex *msg)
// now let's set the total length
blob header_bb = header_writer.get_buffer();
blob end_bb = end_writer.get_buffer();
int32_t *total_length = reinterpret_cast<int32_t *>((void *)header_bb.data());
int32_t *total_length = reinterpret_cast<int32_t *>(const_cast<char *>(header_bb.data()));
*total_length = endian::hton(header_bb.length() + header->body_length + end_bb.length());

unsigned int dsn_size = sizeof(message_header) + header->body_length;
Expand Down

0 comments on commit d60c17c

Please sign in to comment.