summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2025-06-17 14:41:12 +0200
committerClaudius "keldu" Holeksa <mail@keldu.de>2025-06-17 14:41:12 +0200
commit4a85d662012360fecffc9b0e58a582204f631957 (patch)
tree5e87d8d385742824d9ffe1ef76d01e3257a0e80e
parent76409ba8c1a57c9be68baf2d2c480673eb186eda (diff)
Rewriting parts to avoid infinite recursion in flat index call
-rw-r--r--modules/codec/c++/data.hpp32
-rw-r--r--modules/codec/c++/data_raw.hpp4
-rw-r--r--modules/codec/c++/schema_meta.hpp2
-rw-r--r--modules/codec/tests/SConscript2
-rw-r--r--modules/codec/tests/codec.cpp3
-rw-r--r--modules/codec/tests/data_raw.cpp1
-rw-r--r--modules/core/tests/SConscript4
7 files changed, 37 insertions, 11 deletions
diff --git a/modules/codec/c++/data.hpp b/modules/codec/c++/data.hpp
index 4b34bfa..61bc9ea 100644
--- a/modules/codec/c++/data.hpp
+++ b/modules/codec/c++/data.hpp
@@ -318,17 +318,27 @@ private:
public:
constexpr data() = default;
- constexpr data(data<MetaSchema, encode::Native>){}
+ constexpr data(data<MetaSchema, encode::Native>){
+ }
+
constexpr data(const std::array<data<T, encode::Native>, ct_multiply<uint64_t,D...>::value>& value__):
value_{value__}
- {}
+ {
+ }
+
+ SAW_DEFAULT_COPY(data);
+ SAW_DEFAULT_MOVE(data);
+ template<size_t dim_i = 0>
constexpr data<T, encode::Native>& at(data<schema::UInt64, encode::Native> i) {
- return value_.at(this->get_flat_index({{i}}));
+ static_assert(sizeof...(D) == 1u);
+ return value_.at(i.get());
}
+ template<size_t dim_i = 0>
constexpr const data<T, encode::Native>& at(data<schema::UInt64, encode::Native> i) const {
- return value_.at(this->get_flat_index({{i}}));
+ static_assert(sizeof...(D) == 1u);
+ return value_.at(i.get());
}
constexpr data<T, encode::Native>& at(const data<schema::FixedArray<schema::UInt64, sizeof...(D)>>& i){
@@ -356,8 +366,8 @@ private:
constexpr static std::array<uint64_t, sizeof...(D)> dims_{D...};
for(uint64_t iter = 0; iter < sizeof...(D); ++iter){
- assert(i.at({iter}).get() < dims_.at(iter));
- s += i.at({iter}).get() * stride;
+ assert(i.at(data<schema::UInt64>{iter}).get() < dims_.at(iter));
+ s += i.at(data<schema::UInt64>{iter}).get() * stride;
stride *= dims_.at(iter);
}
@@ -628,7 +638,10 @@ class data<schema::Array<T,Dim>, encode::Native> {
uint64_t s = 1;
for(uint64_t iter = 0; iter < Dim; ++iter){
- s *= dims_.at({iter}).get();
+
+ auto& dim_iter = dims_.at(data<schema::UInt64>{iter});
+
+ s *= dim_iter.get();
}
return s;
@@ -649,7 +662,8 @@ class data<schema::Array<T,Dim>, encode::Native> {
dims_{init__},
value_{}
{
- value_.resize(get_full_size());
+ uint64_t f_s = get_full_size();
+ value_.resize(f_s);
}
template<size_t i = 0>
@@ -693,7 +707,7 @@ class data<schema::Array<T,Dim>, encode::Native> {
i_arr.at(0u) = i;
return at(i_arr);
}
-
+
const data<T, encode::Native>& at(data<schema::UInt64, encode::Native> i) const {
data<schema::FixedArray<schema::UInt64,Dim>, encode::Native> i_arr;
i_arr.at(0u) = i;
diff --git a/modules/codec/c++/data_raw.hpp b/modules/codec/c++/data_raw.hpp
index 2236d05..acfb3d8 100644
--- a/modules/codec/c++/data_raw.hpp
+++ b/modules/codec/c++/data_raw.hpp
@@ -124,7 +124,7 @@ public:
};
template<typename T, uint64_t N>
-class data<schema::Ref<schema::Primitive<T,N>>, encode::NativeRaw> {
+class data<schema::Ref<schema::Primitive<T,N>>, encode::NativeRaw> final {
public:
using ReferencedSchema = schema::Primitive<T,N>;
using Schema = schema::Ref<ReferencedSchema>;
@@ -404,7 +404,7 @@ public:
};
template<typename T, size_t Dim>
-class data<schema::Array<T,Dim>, encode::NativeRaw> {
+class data<schema::Array<T,Dim>, encode::NativeRaw> final {
public:
using Schema = schema::Array<T,Dim>;
using MetaSchema = typename meta_schema<Schema>::MetaSchema;
diff --git a/modules/codec/c++/schema_meta.hpp b/modules/codec/c++/schema_meta.hpp
index 659250c..ff66bbb 100644
--- a/modules/codec/c++/schema_meta.hpp
+++ b/modules/codec/c++/schema_meta.hpp
@@ -74,12 +74,14 @@ struct meta_schema<schema::String> {
*/
template<typename T, uint64_t Dim>
struct meta_schema<schema::Array<T,Dim>> {
+ // TODO Technically this should be a FixedArray of the inner meta schema, except when the inner meta schema is Void
using MetaSchema = schema::FixedArray<schema::UInt64,Dim>;
using Schema = schema::Array<T,Dim>;
};
template<typename T, uint64_t... Dim>
struct meta_schema<schema::FixedArray<T,Dim...>> {
+ // TODO Technically this should be a FixedArray of the inner meta schema, except when the inner meta schema is Void
using MetaSchema = schema::Void;
using Schema = schema::FixedArray<T,Dim...>;
};
diff --git a/modules/codec/tests/SConscript b/modules/codec/tests/SConscript
index f8ffc92..ebaf45f 100644
--- a/modules/codec/tests/SConscript
+++ b/modules/codec/tests/SConscript
@@ -13,6 +13,8 @@ dir_path = Dir('.').abspath
test_cases_env = env.Clone();
test_cases_env.Append(LIBS=['forstio-test']);
+# test_cases_env.Append(CCFLAGS=['-fsanitize=address','-g']);
+# test_cases_env.Append(LINKFLAGS=['-fsanitize=address']);
test_cases_env.sources = sorted(glob.glob(dir_path + "/*.cpp"))
test_cases_env.headers = sorted(glob.glob(dir_path + "/*.hpp"))
diff --git a/modules/codec/tests/codec.cpp b/modules/codec/tests/codec.cpp
index ef45b4e..27bc454 100644
--- a/modules/codec/tests/codec.cpp
+++ b/modules/codec/tests/codec.cpp
@@ -53,11 +53,14 @@ using TestInterface = Interface<
}
SAW_TEST("One Dimensional Array") {
using namespace saw;
+ std::cout<<"foo "<<std::endl;
data<schema::OneDimArray, encode::Native> arr{{{500u}}};
+ std::cout<<"foo2 "<<std::endl;
int bar = 0;
+ std::cout<<"arr_size "<<arr.size().get()<<std::endl;
for(data<schema::UInt64, encode::Native> i = 0; i < arr.size(); ++i){
arr.at(i).set(bar++);
}
diff --git a/modules/codec/tests/data_raw.cpp b/modules/codec/tests/data_raw.cpp
index 26c2721..930758d 100644
--- a/modules/codec/tests/data_raw.cpp
+++ b/modules/codec/tests/data_raw.cpp
@@ -23,6 +23,7 @@ SAW_TEST("Data NativeRaw/Array of Primitives"){
a.set(5);
b.set(6);
+ d.set(23);
// Check if it's a reference being manipulated
SAW_EXPECT(a.get() == 5, "'a' has unexpected value.");
diff --git a/modules/core/tests/SConscript b/modules/core/tests/SConscript
index b14b75d..b35f238 100644
--- a/modules/core/tests/SConscript
+++ b/modules/core/tests/SConscript
@@ -12,6 +12,10 @@ dir_path = Dir('.').abspath
# Environment for base library
test_cases_env = env.Clone();
+test_cases_env.Append(CCFLAGS=['-g']);
+# test_cases_env.Append(CCFLAGS=['-fsanitize=address','-g']);
+# test_cases_env.Append(LINKFLAGS=['-fsanitize=address']);
+
test_cases_env.sources = sorted(glob.glob(dir_path + "/*.cpp"))
test_cases_env.headers = sorted(glob.glob(dir_path + "/*.hpp"))