Skip to content

Commit

Permalink
fix: in aarch64 c++ string_view will cause gibberish's bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
helintongh committed Jul 14, 2023
1 parent 8a0b054 commit 8a788c2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cmake/build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ else ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -std=c++20")
endif ()

if (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64")
message(STATUS "Build in aarch64")
add_definitions(-DCINATRA_AARCH64)
endif ()

# --------------------- Gcc
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcoroutines")
Expand Down
26 changes: 25 additions & 1 deletion include/cinatra/request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,11 @@ class request {
throw std::invalid_argument("not support the value type");
}
}

#ifndef CINATRA_AARCH64
std::string_view get_query_value(std::string_view key) {
#elif CINATRA_AARCH64
std::string get_query_value(std::string_view key) {
#endif
if (restful_params_.empty()) {
auto url = get_url();
url = url.length() > 1 && url.back() == '/'
Expand All @@ -692,22 +695,43 @@ class request {
if (code_utils::is_url_encode(itf->second)) {
auto ret = utf8_character_params_.emplace(
map_key, code_utils::get_string_by_urldecode(itf->second));
#if CINATRA_AARCH64
return std::string(ret.first->second.data(),
ret.first->second.size());
#else
return std::string_view(ret.first->second.data(),
ret.first->second.size());
#endif
}
#if CINATRA_AARCH64
return std::string(itf->second);
#else
return itf->second;
#endif
}
if (code_utils::is_url_encode(it->second)) {
auto ret = utf8_character_params_.emplace(
map_key, code_utils::get_string_by_urldecode(it->second));
#if CINATRA_AARCH64
return std::string(ret.first->second.data(), ret.first->second.size());
#else
return std::string_view(ret.first->second.data(),
ret.first->second.size());
#endif
}
#if CINATRA_AARCH64
return std::string(it->second);
#else
return it->second;
#endif
}
else {
const std::string &result(matches_[restful_params_.at(std::string(key))]);
#if CINATRA_AARCH64
return std::string(result.data(), result.size());
#else
return std::string_view(result.data(), result.size());
#endif
}
}

Expand Down

0 comments on commit 8a788c2

Please sign in to comment.