[struct_pack][fix] fix windows ci, fix compatible in windows (#771)

* fix msvc

* fix OOM in msvc

* fix

* fix ce in vs2019
This commit is contained in:
saipubw 2024-09-12 16:41:19 +08:00 committed by GitHub
parent 8d0ad687ac
commit b4eb280442
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 44 additions and 101 deletions

View File

@ -22,10 +22,6 @@ endif()
foreach(child ${children})
get_filename_component(subdir_name ${child} NAME)
string(TOUPPER ${subdir_name} subdir_name)
if((${subdir_name} STREQUAL "STRUCT_PACK" OR ${subdir_name} STREQUAL "STRUCT_PB") AND (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC"))
message(STATUS "skip ${subdir_name}")
continue()
endif()
if (BUILD_${subdir_name})
message(STATUS "BUILD_${subdir_name}: ${BUILD_${subdir_name}}")

View File

@ -11,7 +11,10 @@
#endif
#include "user_reflect_macro.hpp"
namespace struct_pack {
template <typename T, uint64_t version>
struct compatible;
}
namespace ylt::reflection {
template <typename T>
using remove_cvref_t = std::remove_cv_t<std::remove_reference_t<T>>;
@ -25,9 +28,7 @@ concept expected = requires(Type e) {
e.has_value();
e.error();
requires std::is_same_v<void, typename remove_cvref_t<Type>::value_type> ||
requires(Type e) {
e.value();
};
requires(Type e) { e.value(); };
};
#else
template <typename T, typename = void>
@ -71,9 +72,8 @@ constexpr bool optional = !expected<T> && optional_impl<T>::value;
namespace internal {
#if __cpp_concepts >= 201907L
template <typename Type>
concept tuple_size = requires(Type tuple) {
std::tuple_size<remove_cvref_t<Type>>::value;
};
concept tuple_size =
requires(Type tuple) { std::tuple_size<remove_cvref_t<Type>>::value; };
#else
template <typename T, typename = void>
struct tuple_size_impl : std::false_type {};
@ -87,14 +87,12 @@ template <typename T>
constexpr bool tuple_size = tuple_size_impl<T>::value;
#endif
template <typename T, uint64_t version = 0>
struct compatible;
template <typename Type>
constexpr inline bool is_compatible_v = false;
template <typename Type, uint64_t version>
constexpr inline bool is_compatible_v<compatible<Type, version>> = true;
constexpr inline bool is_compatible_v<struct_pack::compatible<Type, version>> =
true;
struct UniversalVectorType {
template <typename T>

View File

@ -3,7 +3,7 @@
// modified based on:
// https://github.com/getml/reflect-cpp/blob/main/include/rfl/internal/bind_fake_object_to_tuple.hpp
// thanks for alxn4's greate idea!
// thanks for alxn4's great idea!
namespace ylt::reflection {
namespace internal {

View File

@ -398,6 +398,8 @@ template <
typename = std::enable_if_t<struct_pack::detail::deserialize_view<View>>>
#endif
[[nodiscard]] auto deserialize(const View &v) {
static_assert(sizeof...(Args) > 0,
"the correct code is struct_pack::deserialize<Type...>();");
expected<detail::get_args_type<Args...>, struct_pack::err_code> ret;
auto errc = deserialize_to(ret.value(), v);
if SP_UNLIKELY (errc) {
@ -408,6 +410,8 @@ template <
template <typename... Args>
[[nodiscard]] auto deserialize(const char *data, size_t size) {
static_assert(sizeof...(Args) > 0,
"the correct code is struct_pack::deserialize<Type...>();");
expected<detail::get_args_type<Args...>, struct_pack::err_code> ret;
if (auto errc = deserialize_to(ret.value(), data, size); errc) {
ret = unexpected<struct_pack::err_code>{errc};
@ -421,6 +425,8 @@ template <typename... Args, typename Reader,
typename = std::enable_if_t<struct_pack::reader_t<Reader>>>
#endif
[[nodiscard]] auto deserialize(Reader &v) {
static_assert(sizeof...(Args) > 0,
"the correct code is struct_pack::deserialize<Type...>();");
expected<detail::get_args_type<Args...>, struct_pack::err_code> ret;
auto errc = deserialize_to(ret.value(), v);
if SP_UNLIKELY (errc) {
@ -435,6 +441,8 @@ template <typename... Args, struct_pack::detail::deserialize_view View>
template <typename... Args, typename View>
#endif
[[nodiscard]] auto deserialize(const View &v, size_t &consume_len) {
static_assert(sizeof...(Args) > 0,
"the correct code is struct_pack::deserialize<Type...>();");
expected<detail::get_args_type<Args...>, struct_pack::err_code> ret;
auto errc = deserialize_to(ret.value(), v, consume_len);
if SP_UNLIKELY (errc) {
@ -446,6 +454,8 @@ template <typename... Args, typename View>
template <typename... Args>
[[nodiscard]] auto deserialize(const char *data, size_t size,
size_t &consume_len) {
static_assert(sizeof...(Args) > 0,
"the correct code is struct_pack::deserialize<Type...>();");
expected<detail::get_args_type<Args...>, struct_pack::err_code> ret;
auto errc = deserialize_to(ret.value(), data, size, consume_len);
if SP_UNLIKELY (errc) {
@ -463,6 +473,8 @@ template <
typename = std::enable_if_t<struct_pack::detail::deserialize_view<View>>>
#endif
[[nodiscard]] auto deserialize(const View &v) {
static_assert(sizeof...(Args) > 0,
"the correct code is struct_pack::deserialize<Type...>();");
expected<detail::get_args_type<Args...>, struct_pack::err_code> ret;
auto errc = deserialize_to<conf>(ret.value(), v);
if SP_UNLIKELY (errc) {
@ -487,6 +499,8 @@ template <uint64_t conf, typename... Args, typename Reader,
typename = std::enable_if_t<struct_pack::reader_t<Reader>>>
#endif
[[nodiscard]] auto deserialize(Reader &v) {
static_assert(sizeof...(Args) > 0,
"the correct code is struct_pack::deserialize<Type...>();");
expected<detail::get_args_type<Args...>, struct_pack::err_code> ret;
auto errc = deserialize_to<conf>(ret.value(), v);
if SP_UNLIKELY (errc) {
@ -502,6 +516,8 @@ template <uint64_t conf, typename... Args,
template <uint64_t conf, typename... Args, typename View>
#endif
[[nodiscard]] auto deserialize(const View &v, size_t &consume_len) {
static_assert(sizeof...(Args) > 0,
"the correct code is struct_pack::deserialize<Type...>();");
expected<detail::get_args_type<Args...>, struct_pack::err_code> ret;
auto errc = deserialize_to<conf>(ret.value(), v, consume_len);
if SP_UNLIKELY (errc) {
@ -513,6 +529,8 @@ template <uint64_t conf, typename... Args, typename View>
template <uint64_t conf, typename... Args>
[[nodiscard]] auto deserialize(const char *data, size_t size,
size_t &consume_len) {
static_assert(sizeof...(Args) > 0,
"the correct code is struct_pack::deserialize<Type...>();");
expected<detail::get_args_type<Args...>, struct_pack::err_code> ret;
auto errc = deserialize_to<conf>(ret.value(), data, size, consume_len);
if SP_UNLIKELY (errc) {
@ -527,6 +545,8 @@ template <typename... Args, struct_pack::detail::deserialize_view View>
template <typename... Args, typename View>
#endif
[[nodiscard]] auto deserialize_with_offset(const View &v, size_t &offset) {
static_assert(sizeof...(Args) > 0,
"the correct code is struct_pack::deserialize<Type...>();");
expected<detail::get_args_type<Args...>, struct_pack::err_code> ret;
auto errc = deserialize_to_with_offset(ret.value(), v, offset);
if SP_UNLIKELY (errc) {
@ -538,6 +558,8 @@ template <typename... Args, typename View>
template <typename... Args>
[[nodiscard]] auto deserialize_with_offset(const char *data, size_t size,
size_t &offset) {
static_assert(sizeof...(Args) > 0,
"the correct code is struct_pack::deserialize<Type...>();");
expected<detail::get_args_type<Args...>, struct_pack::err_code> ret;
auto errc = deserialize_to_with_offset(ret.value(), data, size, offset);
if SP_UNLIKELY (errc) {

View File

@ -3,6 +3,7 @@
#include "doctest.h"
#include "ylt/struct_pack.hpp"
#include "ylt/struct_pack/type_calculate.hpp"
// struct_pack support 255 member max
struct many_members {
int a1;
std::string b1;
@ -128,6 +129,8 @@ struct many_members {
std::string b61;
int a62;
std::string b62;
#ifndef _MSC_VER
// too many variable may cause msvc OOM, disable least variables
int a63;
std::string b63;
int a64;
@ -259,6 +262,7 @@ struct many_members {
int a127;
std::string b127;
int a128;
#endif
};
struct many_members2 : public many_members {};
STRUCT_PACK_REFL(many_members2, a1, b1, a2, b2, a3, b3, a4, b4, a5, b5, a6, b6,
@ -270,9 +274,13 @@ STRUCT_PACK_REFL(many_members2, a1, b1, a2, b2, a3, b3, a4, b4, a5, b5, a6, b6,
a38, b38, a39, b39, a40, b40, a41, b41, a42, b42, a43, b43,
a44, b44, a45, b45, a46, b46, a47, b47, a48, b48, a49, b49,
a50, b50, a51, b51, a52, b52, a53, b53, a54, b54, a55, b55,
a56, b56, a57, b57, a58, b58, a59, b59, a60, b60, a61, b61,
a62, b62);
a56, b56, a57, b57, a58, b58, a59, b59, a60, b60);
TEST_CASE("test many members") {
CHECK(struct_pack::get_type_literal<many_members>().size() == 384);
CHECK(struct_pack::get_type_literal<many_members2>().size() == 188);
int size = 384;
#ifdef _MSC_VER
size = 188;
#endif
CHECK(struct_pack::get_type_literal<many_members>().size() == size);
CHECK(struct_pack::get_type_literal<many_members2>().size() == 182);
}

View File

@ -1,14 +0,0 @@
#include <iostream>
#include <string>
using namespace std;
string i1 = "else if constexpr (Count == ";
string j = " ){ return visitor(";
string l = ");}";
int main() {
std::string list = "_SPG0(o)";
for (int i = 2; i <= 256; ++i) {
list += ",_SPG" + to_string(i - 1) + "(o)";
cout << i1 + to_string(i) + j + list + l << endl;
}
return 0;
}

View File

@ -1,67 +0,0 @@
#
# Copyright (c) 2023, Alibaba Group Holding Limited;
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
set -e
echo "test yaLanTingLibs install"
rm -rf tmp
mkdir tmp
cd tmp
echo "copy test code"
prj_list="struct_pack struct_pb coro_rpc easylog"
for lib in $prj_list
do
mkdir "$lib"
echo " copy $lib"
cp -r ../src/"$lib"/tests "$lib"/
done
cp -r ../thirdparty/doctest .
cp -r ../src/struct_pb/conformance struct_pb/
echo "add CMakeLists.txt"
prj_file=CMakeLists.txt
(
cat << EOF
cmake_minimum_required(VERSION 3.15)
project(yaLanTingLibs_install_tests
VERSION 1.0.0
LANGUAGES CXX
)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
enable_testing()
find_package(Threads REQUIRED)
find_package(OpenSSL)
find_package(yalantinglibs REQUIRED)
add_compile_definitions(ASYNC_SIMPLE_HAS_NOT_AIO)
#############################
# doctest
#############################
add_library(doctest INTERFACE)
target_include_directories(doctest INTERFACE doctest)
EOF
) > $prj_file
for lib in $prj_list
do
echo "add_subdirectory($lib/tests)" >> $prj_file
done
echo "add_subdirectory(struct_pb/conformance)" >> $prj_file
# workaround
cp -r ../src/struct_pack/benchmark struct_pack/
echo "target_include_directories(test_struct_pb PUBLIC struct_pack/benchmark)" >> $prj_file
echo "build tests"
cmake -B build -S . -DCMAKE_PREFIX_PATH="$(pwd)/../installed"
cmake --build build -j
echo "run tests"
cd build && ctest