diff --git a/engine/3rdparty/zlib/include/refl/detail/container.inl b/engine/3rdparty/zlib/include/refl/detail/container.inl index 423713a..13af2b7 100644 --- a/engine/3rdparty/zlib/include/refl/detail/container.inl +++ b/engine/3rdparty/zlib/include/refl/detail/container.inl @@ -14,7 +14,15 @@ namespace refl { void destruct() { cls->Destruct((void*)ptr); } - Any malloc_any() { + void try_free(const Any& any, int size) { + if (any.cls == cls->parent && any.Size() > size) { + free((void*)any.ptr); + } + } + Any try_malloc(void* memory, int size) { + if (cls->parent->size <= size) { + return { memory, cls->parent }; + } void* ptr = malloc(cls->parent->size); return { ptr, cls->parent }; } diff --git a/engine/3rdparty/zlib/include/refl/detail/uclass.inl b/engine/3rdparty/zlib/include/refl/detail/uclass.inl index 0d40cc6..082019a 100644 --- a/engine/3rdparty/zlib/include/refl/detail/uclass.inl +++ b/engine/3rdparty/zlib/include/refl/detail/uclass.inl @@ -154,7 +154,7 @@ namespace refl { template class UClass_Pair : public UClass { using UClass::UClass; - using MyUClass = UClass_Tuple; + using MyUClass = UClass_Pair; using MyPair = std::pair; public: std::array Fields; diff --git a/engine/3rdparty/zlib/include/yaml/serialize/text.inl b/engine/3rdparty/zlib/include/yaml/serialize/text.inl index 3060657..f5f6d1c 100644 --- a/engine/3rdparty/zlib/include/yaml/serialize/text.inl +++ b/engine/3rdparty/zlib/include/yaml/serialize/text.inl @@ -95,13 +95,14 @@ namespace YAML if (res.IsSequence() && any.IsContainer()) { auto docker = any.ToContainer(); docker.construct(); - Any any = docker.malloc_any(); + char memory[STACK_MEMORY_SIZE]; + Any any = docker.try_malloc(&memory, STACK_MEMORY_SIZE); for (std::size_t i = 0; i < res.size(); i++) { Unserialize(res[i], any); docker.insert(any); any.Destruct(); } - free((void*)any.ptr); + docker.try_free(any, STACK_MEMORY_SIZE); return true; } if (res.IsSequence() && any.IsArray()) { diff --git a/engine/3rdparty/zlib/include/yaml/serialize/type.h b/engine/3rdparty/zlib/include/yaml/serialize/type.h index 5e94ad0..59d75ce 100644 --- a/engine/3rdparty/zlib/include/yaml/serialize/type.h +++ b/engine/3rdparty/zlib/include/yaml/serialize/type.h @@ -20,5 +20,5 @@ namespace YAML { static_cast(t) } -> std::convertible_to; }; #pragma endregion ToString - +#define STACK_MEMORY_SIZE 128 } \ No newline at end of file diff --git a/engine/3rdparty/zlib/test/yaml/main.cpp b/engine/3rdparty/zlib/test/yaml/main.cpp index 6dd03a6..f0e3c36 100644 --- a/engine/3rdparty/zlib/test/yaml/main.cpp +++ b/engine/3rdparty/zlib/test/yaml/main.cpp @@ -24,20 +24,21 @@ void testMeta() { auto rmb2 = YAML::Text_Unserialize(rmb1); if (rmb2) { MetaBundle aa = rmb2.value(); - std::cout << "success!" << std::endl; + std::cout << "success!\n" << YAML::Text_Serialize(aa) << std::endl; } } void testTuple() { std::map table; - table.insert(std::make_pair(111,"hello")); - table.insert(std::make_pair(222, "world")); + table.insert(std::make_pair(111,"hello\nworld!!")); + table.insert(std::make_pair(222, "yaml\n????")); + table.insert(std::make_pair(333, YAML::Text_Serialize(table))); using T = std::map; string rtable = YAML::Text_Serialize(table); std::cout << rtable << std::endl; auto table2 = YAML::Text_Unserialize>(rtable); if (table2) { std::map aa = table2.value(); - std::cout << "success!" << std::endl; + std::cout << "success!\n" << YAML::Text_Serialize(aa) << std::endl; } } using size_impl = size_t(*)(const void*);