diff --git a/include/simdjson/arm64/bitmanipulation.h b/include/simdjson/arm64/bitmanipulation.h index cdb2b3ba1..b56e1a0ea 100644 --- a/include/simdjson/arm64/bitmanipulation.h +++ b/include/simdjson/arm64/bitmanipulation.h @@ -52,7 +52,7 @@ simdjson_really_inline bool add_overflow(uint64_t value1, uint64_t value2, uint6 return *result < value1; #else return __builtin_uaddll_overflow(value1, value2, - (unsigned long long *)result); + reinterpret_cast(result)); #endif } diff --git a/include/simdjson/dom/document-inl.h b/include/simdjson/dom/document-inl.h index ca347e4d8..3ba7c38f8 100644 --- a/include/simdjson/dom/document-inl.h +++ b/include/simdjson/dom/document-inl.h @@ -68,7 +68,7 @@ inline bool document::dump_raw_tape(std::ostream &os) const noexcept { os << "string \""; std::memcpy(&string_length, string_buf.get() + payload, sizeof(uint32_t)); os << internal::escape_json_string(std::string_view( - (const char *)(string_buf.get() + payload + sizeof(uint32_t)), + reinterpret_cast(string_buf.get() + payload + sizeof(uint32_t)), string_length )); os << '"'; diff --git a/include/simdjson/dom/parser-inl.h b/include/simdjson/dom/parser-inl.h index 946ce0ee2..17aedb740 100644 --- a/include/simdjson/dom/parser-inl.h +++ b/include/simdjson/dom/parser-inl.h @@ -84,7 +84,7 @@ inline simdjson_result parser::load_many(const std::string &pat auto _error = read_file(path).get(len); if (_error) { return _error; } if(batch_size < MINIMAL_BATCH_SIZE) { batch_size = MINIMAL_BATCH_SIZE; } - return document_stream(*this, (const uint8_t*)loaded_bytes.get(), len, batch_size); + return document_stream(*this, reinterpret_cast(loaded_bytes.get()), len, batch_size); } inline simdjson_result parser::parse(const uint8_t *buf, size_t len, bool realloc_if_needed) & noexcept { @@ -93,9 +93,9 @@ inline simdjson_result parser::parse(const uint8_t *buf, size_t len, bo std::unique_ptr tmp_buf; if (realloc_if_needed) { - tmp_buf.reset((uint8_t *)internal::allocate_padded_buffer(len)); + tmp_buf.reset(reinterpret_cast( internal::allocate_padded_buffer(len) )); if (tmp_buf.get() == nullptr) { return MEMALLOC; } - std::memcpy((void *)tmp_buf.get(), buf, len); + std::memcpy(static_cast(tmp_buf.get()), buf, len); } _error = implementation->parse(realloc_if_needed ? tmp_buf.get() : buf, len, doc); if (_error) { return _error; } @@ -103,7 +103,7 @@ inline simdjson_result parser::parse(const uint8_t *buf, size_t len, bo return doc.root(); } simdjson_really_inline simdjson_result parser::parse(const char *buf, size_t len, bool realloc_if_needed) & noexcept { - return parse((const uint8_t *)buf, len, realloc_if_needed); + return parse(reinterpret_cast(buf), len, realloc_if_needed); } simdjson_really_inline simdjson_result parser::parse(const std::string &s) & noexcept { return parse(s.data(), s.length(), s.capacity() - s.length() < SIMDJSON_PADDING); @@ -117,7 +117,7 @@ inline simdjson_result parser::parse_many(const uint8_t *buf, s return document_stream(*this, buf, len, batch_size); } inline simdjson_result parser::parse_many(const char *buf, size_t len, size_t batch_size) noexcept { - return parse_many((const uint8_t *)buf, len, batch_size); + return parse_many(reinterpret_cast(buf), len, batch_size); } inline simdjson_result parser::parse_many(const std::string &s, size_t batch_size) noexcept { return parse_many(s.data(), s.length(), batch_size); diff --git a/include/simdjson/fallback/numberparsing.h b/include/simdjson/fallback/numberparsing.h index 47677a7bb..4513f0f4d 100644 --- a/include/simdjson/fallback/numberparsing.h +++ b/include/simdjson/fallback/numberparsing.h @@ -20,7 +20,7 @@ static simdjson_really_inline uint32_t parse_eight_digits_unrolled(const char *c return uint32_t((val & 0x0000FFFF0000FFFF) * 42949672960001 >> 32); } static simdjson_really_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars) { - return parse_eight_digits_unrolled((const char *)chars); + return parse_eight_digits_unrolled(reinterpret_cast(chars)); } } // unnamed namespace diff --git a/include/simdjson/generic/jsoncharutils.h b/include/simdjson/generic/jsoncharutils.h index 91ff4052e..25cb2acc5 100644 --- a/include/simdjson/generic/jsoncharutils.h +++ b/include/simdjson/generic/jsoncharutils.h @@ -103,7 +103,7 @@ simdjson_really_inline value128 full_multiplication(uint64_t value1, uint64_t va answer.low = _umul128(value1, value2, &answer.high); // _umul128 not available on ARM64 #endif // _M_ARM64 #else // defined(SIMDJSON_REGULAR_VISUAL_STUDIO) || defined(SIMDJSON_IS_32BITS) - __uint128_t r = ((__uint128_t)value1) * value2; + __uint128_t r = (static_cast<__uint128_t>(value1)) * value2; answer.low = uint64_t(r); answer.high = uint64_t(r >> 64); #endif diff --git a/include/simdjson/generic/numberparsing.h b/include/simdjson/generic/numberparsing.h index 48b67f4f9..8779ea87a 100644 --- a/include/simdjson/generic/numberparsing.h +++ b/include/simdjson/generic/numberparsing.h @@ -29,7 +29,7 @@ simdjson_really_inline double to_double(uint64_t mantissa, uint64_t real_exponen double d; mantissa &= ~(1ULL << 52); mantissa |= real_exponent << 52; - mantissa |= (((uint64_t)negative) << 63); + mantissa |= ((static_cast(negative)) << 63); std::memcpy(&d, &mantissa, sizeof(d)); return d; } @@ -292,7 +292,7 @@ simdjson_really_inline bool compute_float_64(int64_t power, uint64_t i, bool neg // The string parsing itself always succeeds. We know that there is at least // one digit. static bool parse_float_fallback(const uint8_t *ptr, double *outDouble) { - *outDouble = simdjson::internal::from_chars((const char *)ptr); + *outDouble = simdjson::internal::from_chars(reinterpret_cast(ptr)); // We do not accept infinite values. // Detecting finite values in a portable manner is ridiculously hard, ideally diff --git a/include/simdjson/generic/ondemand/parser-inl.h b/include/simdjson/generic/ondemand/parser-inl.h index 7b03ec68e..1ffc62091 100644 --- a/include/simdjson/generic/ondemand/parser-inl.h +++ b/include/simdjson/generic/ondemand/parser-inl.h @@ -28,8 +28,8 @@ simdjson_warn_unused simdjson_really_inline simdjson_result parser::it } // Run stage 1. - SIMDJSON_TRY( dom_parser->stage1((const uint8_t *)buf.data(), buf.size(), false) ); - return document::start({ (const uint8_t *)buf.data(), this }); + SIMDJSON_TRY( dom_parser->stage1(reinterpret_cast(buf.data()), buf.size(), false) ); + return document::start({ reinterpret_cast(buf.data()), this }); } simdjson_warn_unused simdjson_really_inline simdjson_result parser::iterate(const simdjson_result &result) & noexcept { @@ -46,8 +46,8 @@ simdjson_warn_unused simdjson_really_inline simdjson_result parse } // Run stage 1. - SIMDJSON_TRY( dom_parser->stage1((const uint8_t *)buf.data(), buf.size(), false) ); - return json_iterator((const uint8_t *)buf.data(), this); + SIMDJSON_TRY( dom_parser->stage1(reinterpret_cast(buf.data()), buf.size(), false) ); + return json_iterator(reinterpret_cast(buf.data()), this); } } // namespace ondemand diff --git a/include/simdjson/generic/ondemand/raw_json_string-inl.h b/include/simdjson/generic/ondemand/raw_json_string-inl.h index 7b3a0e1fb..2635c3089 100644 --- a/include/simdjson/generic/ondemand/raw_json_string-inl.h +++ b/include/simdjson/generic/ondemand/raw_json_string-inl.h @@ -4,11 +4,11 @@ namespace ondemand { simdjson_really_inline raw_json_string::raw_json_string(const uint8_t * _buf) noexcept : buf{_buf} {} -simdjson_really_inline const char * raw_json_string::raw() const noexcept { return (const char *)buf; } +simdjson_really_inline const char * raw_json_string::raw() const noexcept { return reinterpret_cast(buf); } simdjson_really_inline simdjson_warn_unused simdjson_result raw_json_string::unescape(uint8_t *&dst) const noexcept { uint8_t *end = stringparsing::parse_string(buf, dst); if (!end) { return STRING_ERROR; } - std::string_view result((const char *)dst, end-dst); + std::string_view result(reinterpret_cast(dst), end-dst); dst = end; return result; } diff --git a/include/simdjson/haswell/bitmanipulation.h b/include/simdjson/haswell/bitmanipulation.h index 076e4b317..85ba1b1f3 100644 --- a/include/simdjson/haswell/bitmanipulation.h +++ b/include/simdjson/haswell/bitmanipulation.h @@ -50,7 +50,7 @@ simdjson_really_inline bool add_overflow(uint64_t value1, uint64_t value2, reinterpret_cast(result)); #else return __builtin_uaddll_overflow(value1, value2, - (unsigned long long *)result); + reinterpret_cast(result)); #endif } diff --git a/include/simdjson/haswell/simd.h b/include/simdjson/haswell/simd.h index 7994f27bb..dfb388517 100644 --- a/include/simdjson/haswell/simd.h +++ b/include/simdjson/haswell/simd.h @@ -28,9 +28,9 @@ namespace simd { simdjson_really_inline Child operator&(const Child other) const { return _mm256_and_si256(*this, other); } simdjson_really_inline Child operator^(const Child other) const { return _mm256_xor_si256(*this, other); } simdjson_really_inline Child bit_andnot(const Child other) const { return _mm256_andnot_si256(other, *this); } - simdjson_really_inline Child& operator|=(const Child other) { auto this_cast = (Child*)this; *this_cast = *this_cast | other; return *this_cast; } - simdjson_really_inline Child& operator&=(const Child other) { auto this_cast = (Child*)this; *this_cast = *this_cast & other; return *this_cast; } - simdjson_really_inline Child& operator^=(const Child other) { auto this_cast = (Child*)this; *this_cast = *this_cast ^ other; return *this_cast; } + simdjson_really_inline Child& operator|=(const Child other) { auto this_cast = static_cast(this); *this_cast = *this_cast | other; return *this_cast; } + simdjson_really_inline Child& operator&=(const Child other) { auto this_cast = static_cast(this); *this_cast = *this_cast & other; return *this_cast; } + simdjson_really_inline Child& operator^=(const Child other) { auto this_cast = static_cast(this); *this_cast = *this_cast ^ other; return *this_cast; } }; // Forward-declared so they can be used by splat and friends. @@ -99,8 +99,8 @@ namespace simd { // Addition/subtraction are the same for signed and unsigned simdjson_really_inline simd8 operator+(const simd8 other) const { return _mm256_add_epi8(*this, other); } simdjson_really_inline simd8 operator-(const simd8 other) const { return _mm256_sub_epi8(*this, other); } - simdjson_really_inline simd8& operator+=(const simd8 other) { *this = *this + other; return *(simd8*)this; } - simdjson_really_inline simd8& operator-=(const simd8 other) { *this = *this - other; return *(simd8*)this; } + simdjson_really_inline simd8& operator+=(const simd8 other) { *this = *this + other; return *static_cast*>(this); } + simdjson_really_inline simd8& operator-=(const simd8 other) { *this = *this - other; return *static_cast*>(this); } // Override to distinguish from bool version simdjson_really_inline simd8 operator~() const { return *this ^ 0xFFu; } @@ -148,9 +148,9 @@ namespace simd { // then load the corresponding mask // could be done with _mm256_loadu2_m128i but many standard libraries omit this intrinsic. __m256i v256 = _mm256_castsi128_si256( - _mm_loadu_si128((const __m128i *)(pshufb_combine_table + pop1 * 8))); + _mm_loadu_si128(reinterpret_cast(pshufb_combine_table + pop1 * 8))); __m256i compactmask = _mm256_insertf128_si256(v256, - _mm_loadu_si128((const __m128i *)(pshufb_combine_table + pop3 * 8)), 1); + _mm_loadu_si128(reinterpret_cast(pshufb_combine_table + pop3 * 8)), 1); __m256i almostthere = _mm256_shuffle_epi8(pruned, compactmask); // We just need to write out the result. // This is the tricky bit that is hard to do @@ -159,9 +159,9 @@ namespace simd { // the two 128-bit lanes with an offset. __m128i v128; v128 = _mm256_castsi256_si128(almostthere); - _mm_storeu_si128( (__m128i *)output, v128); + _mm_storeu_si128( reinterpret_cast<__m128i *>(output), v128); v128 = _mm256_extractf128_si256(almostthere, 1); - _mm_storeu_si128( (__m128i *)(output + 16 - count_ones(mask & 0xFFFF)), v128); + _mm_storeu_si128( reinterpret_cast<__m128i *>(output + 16 - count_ones(mask & 0xFFFF)), v128); } template diff --git a/include/simdjson/haswell/stringparsing.h b/include/simdjson/haswell/stringparsing.h index 026c0c2d9..0141c780d 100644 --- a/include/simdjson/haswell/stringparsing.h +++ b/include/simdjson/haswell/stringparsing.h @@ -34,8 +34,8 @@ simdjson_really_inline backslash_and_quote backslash_and_quote::copy_and_find(co // store to dest unconditionally - we can overwrite the bits we don't like later v.store(dst); return { - (uint32_t)(v == '\\').to_bitmask(), // bs_bits - (uint32_t)(v == '"').to_bitmask(), // quote_bits + static_cast((v == '\\').to_bitmask()), // bs_bits + static_cast((v == '"').to_bitmask()), // quote_bits }; } diff --git a/include/simdjson/internal/jsonformatutils.h b/include/simdjson/internal/jsonformatutils.h index dcb7dc42f..c87c6445b 100644 --- a/include/simdjson/internal/jsonformatutils.h +++ b/include/simdjson/internal/jsonformatutils.h @@ -46,7 +46,7 @@ inline std::ostream& operator<<(std::ostream& out, const escape_json_string &une out << "\\\\"; break; default: - if ((unsigned char)unescaped.str[i] <= 0x1F) { + if (static_cast(unescaped.str[i]) <= 0x1F) { // TODO can this be done once at the beginning, or will it mess up << char? std::ios::fmtflags f(out.flags()); out << "\\u" << std::hex << std::setw(4) << std::setfill('0') << int(unescaped.str[i]); diff --git a/include/simdjson/padded_string-inl.h b/include/simdjson/padded_string-inl.h index 04afc9169..9b4074766 100644 --- a/include/simdjson/padded_string-inl.h +++ b/include/simdjson/padded_string-inl.h @@ -134,7 +134,7 @@ inline simdjson_result padded_string::load(const std::string &fil } // Allocate the padded_string - size_t len = (size_t) llen; + size_t len = static_cast(llen); padded_string s(len); if (s.data() == nullptr) { std::fclose(fp); diff --git a/include/simdjson/ppc64/bitmanipulation.h b/include/simdjson/ppc64/bitmanipulation.h index 983a8df13..aa3663f17 100644 --- a/include/simdjson/ppc64/bitmanipulation.h +++ b/include/simdjson/ppc64/bitmanipulation.h @@ -59,7 +59,7 @@ simdjson_really_inline bool add_overflow(uint64_t value1, uint64_t value2, return *result < value1; #else return __builtin_uaddll_overflow(value1, value2, - (unsigned long long *)result); + reinterpret_cast(result)); #endif } diff --git a/include/simdjson/westmere/bitmanipulation.h b/include/simdjson/westmere/bitmanipulation.h index 888ccf45e..4e5c1f022 100644 --- a/include/simdjson/westmere/bitmanipulation.h +++ b/include/simdjson/westmere/bitmanipulation.h @@ -59,7 +59,7 @@ simdjson_really_inline bool add_overflow(uint64_t value1, uint64_t value2, reinterpret_cast(result)); #else return __builtin_uaddll_overflow(value1, value2, - (unsigned long long *)result); + reinterpret_cast(result)); #endif } diff --git a/include/simdjson/westmere/simd.h b/include/simdjson/westmere/simd.h index 26a6cd3be..f997f97da 100644 --- a/include/simdjson/westmere/simd.h +++ b/include/simdjson/westmere/simd.h @@ -27,9 +27,9 @@ namespace simd { simdjson_really_inline Child operator&(const Child other) const { return _mm_and_si128(*this, other); } simdjson_really_inline Child operator^(const Child other) const { return _mm_xor_si128(*this, other); } simdjson_really_inline Child bit_andnot(const Child other) const { return _mm_andnot_si128(other, *this); } - simdjson_really_inline Child& operator|=(const Child other) { auto this_cast = (Child*)this; *this_cast = *this_cast | other; return *this_cast; } - simdjson_really_inline Child& operator&=(const Child other) { auto this_cast = (Child*)this; *this_cast = *this_cast & other; return *this_cast; } - simdjson_really_inline Child& operator^=(const Child other) { auto this_cast = (Child*)this; *this_cast = *this_cast ^ other; return *this_cast; } + simdjson_really_inline Child& operator|=(const Child other) { auto this_cast = static_cast(this); *this_cast = *this_cast | other; return *this_cast; } + simdjson_really_inline Child& operator&=(const Child other) { auto this_cast = static_cast(this); *this_cast = *this_cast & other; return *this_cast; } + simdjson_really_inline Child& operator^=(const Child other) { auto this_cast = static_cast(this); *this_cast = *this_cast ^ other; return *this_cast; } }; // Forward-declared so they can be used by splat and friends. @@ -99,8 +99,8 @@ namespace simd { // Addition/subtraction are the same for signed and unsigned simdjson_really_inline simd8 operator+(const simd8 other) const { return _mm_add_epi8(*this, other); } simdjson_really_inline simd8 operator-(const simd8 other) const { return _mm_sub_epi8(*this, other); } - simdjson_really_inline simd8& operator+=(const simd8 other) { *this = *this + other; return *(simd8*)this; } - simdjson_really_inline simd8& operator-=(const simd8 other) { *this = *this - other; return *(simd8*)this; } + simdjson_really_inline simd8& operator+=(const simd8 other) { *this = *this + other; return *static_cast*>(this); } + simdjson_really_inline simd8& operator-=(const simd8 other) { *this = *this - other; return *static_cast*>(this); } // Perform a lookup assuming the value is between 0 and 16 (undefined behavior for out of range values) template @@ -141,9 +141,9 @@ namespace simd { // it fills in with the bytes from the second 8 bytes + some filling // at the end. __m128i compactmask = - _mm_loadu_si128((const __m128i *)(pshufb_combine_table + pop1 * 8)); + _mm_loadu_si128(reinterpret_cast(pshufb_combine_table + pop1 * 8)); __m128i answer = _mm_shuffle_epi8(pruned, compactmask); - _mm_storeu_si128(( __m128i *)(output), answer); + _mm_storeu_si128(reinterpret_cast<__m128i *>(output), answer); } template diff --git a/src/fallback/dom_parser_implementation.cpp b/src/fallback/dom_parser_implementation.cpp index a03749637..784d25d2e 100644 --- a/src/fallback/dom_parser_implementation.cpp +++ b/src/fallback/dom_parser_implementation.cpp @@ -247,7 +247,7 @@ simdjson_warn_unused error_code implementation::minify(const uint8_t *buf, size_ // credit: based on code from Google Fuchsia (Apache Licensed) simdjson_warn_unused bool implementation::validate_utf8(const char *buf, size_t len) const noexcept { - const uint8_t *data = (const uint8_t *)buf; + const uint8_t *data = reinterpret_cast(buf); uint64_t pos = 0; uint32_t code_point = 0; while (pos < len) { @@ -336,4 +336,4 @@ simdjson_warn_unused error_code dom_parser_implementation::parse(const uint8_t * } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson -#include "simdjson/fallback/end.h" \ No newline at end of file +#include "simdjson/fallback/end.h" diff --git a/src/generic/stage1/buf_block_reader.h b/src/generic/stage1/buf_block_reader.h index b598e1b53..9a1b975b8 100644 --- a/src/generic/stage1/buf_block_reader.h +++ b/src/generic/stage1/buf_block_reader.h @@ -30,7 +30,7 @@ private: // Routines to print masks and text for debugging bitmask operations simdjson_unused static char * format_input_text_64(const uint8_t *text) { - static char *buf = (char*)malloc(sizeof(simd8x64) + 1); + static char *buf = reinterpret_cast(malloc(sizeof(simd8x64) + 1)); for (size_t i=0; i); i++) { buf[i] = int8_t(text[i]) < ' ' ? '_' : int8_t(text[i]); } @@ -40,8 +40,8 @@ simdjson_unused static char * format_input_text_64(const uint8_t *text) { // Routines to print masks and text for debugging bitmask operations simdjson_unused static char * format_input_text(const simd8x64& in) { - static char *buf = (char*)malloc(sizeof(simd8x64) + 1); - in.store((uint8_t*)buf); + static char *buf = reinterpret_cast(malloc(sizeof(simd8x64) + 1)); + in.store(reinterpret_cast(buf)); for (size_t i=0; i); i++) { if (buf[i] < ' ') { buf[i] = '_'; } } @@ -50,7 +50,7 @@ simdjson_unused static char * format_input_text(const simd8x64& in) { } simdjson_unused static char * format_mask(uint64_t mask) { - static char *buf = (char*)malloc(64 + 1); + static char *buf = reinterpret_cast(malloc(64 + 1)); for (size_t i=0; i<64; i++) { buf[i] = (mask & (size_t(1) << i)) ? 'X' : ' '; } diff --git a/src/generic/stage1/utf8_validator.h b/src/generic/stage1/utf8_validator.h index abd3c4a41..581efd01f 100644 --- a/src/generic/stage1/utf8_validator.h +++ b/src/generic/stage1/utf8_validator.h @@ -25,7 +25,7 @@ bool generic_validate_utf8(const uint8_t * input, size_t length) { } bool generic_validate_utf8(const char * input, size_t length) { - return generic_validate_utf8((const uint8_t *)input,length); + return generic_validate_utf8(reinterpret_cast(input),length); } } // namespace stage1 diff --git a/src/generic/stage2/logger.h b/src/generic/stage2/logger.h index 47d4ca303..a8a1c0743 100644 --- a/src/generic/stage2/logger.h +++ b/src/generic/stage2/logger.h @@ -51,7 +51,7 @@ namespace logger { printf("| %*s%s%-*s ", log_depth*2, "", title_prefix, LOG_EVENT_LEN - log_depth*2 - int(strlen(title_prefix)), title); auto current_index = structurals.at_beginning() ? nullptr : structurals.next_structural-1; auto next_index = structurals.next_structural; - auto current = current_index ? &structurals.buf[*current_index] : (const uint8_t*)" "; + auto current = current_index ? &structurals.buf[*current_index] : reinterpret_cast(" "); auto next = &structurals.buf[*next_index]; { // Print the next N characters in the buffer. diff --git a/src/implementation.cpp b/src/implementation.cpp index d3b70c173..4301b3246 100644 --- a/src/implementation.cpp +++ b/src/implementation.cpp @@ -147,7 +147,7 @@ SIMDJSON_DLLIMPORTEXPORT const internal::available_implementation_list available SIMDJSON_DLLIMPORTEXPORT internal::atomic_ptr active_implementation{&internal::detect_best_supported_implementation_on_first_use_singleton}; simdjson_warn_unused error_code minify(const char *buf, size_t len, char *dst, size_t &dst_len) noexcept { - return active_implementation->minify((const uint8_t *)buf, len, (uint8_t *)dst, dst_len); + return active_implementation->minify(reinterpret_cast(buf), len, reinterpret_cast(dst), dst_len); } simdjson_warn_unused bool validate_utf8(const char *buf, size_t len) noexcept { return active_implementation->validate_utf8(buf, len);