From bd2f6b7b5fbd04264bfdd7df3dfb9a83c0258881 Mon Sep 17 00:00:00 2001 From: bmcpt Date: Sat, 13 Aug 2022 14:51:41 +0530 Subject: [PATCH 1/5] add c wrapper functions --- include/dbcppp/CApi.h | 5 ++++ include/dbcppp/SignalMultiplexerValue.h | 2 +- src/libdbcppp/CApi.cpp | 29 ++++++++++++++++++-- src/libdbcppp/SignalMultiplexerValueImpl.cpp | 2 +- src/libdbcppp/SignalMultiplexerValueImpl.h | 2 +- tests/Catch2.cpp | 4 +-- 6 files changed, 37 insertions(+), 7 deletions(-) diff --git a/include/dbcppp/CApi.h b/include/dbcppp/CApi.h index 7203b061..827021b3 100644 --- a/include/dbcppp/CApi.h +++ b/include/dbcppp/CApi.h @@ -77,6 +77,11 @@ extern "C" typedef struct {} dbcppp_Attribute; typedef struct {} dbcppp_SignalType; typedef struct {} dbcppp_Signal; + typedef struct {} dbcppp_SignalMultiplexerValue; + typedef struct { + size_t from; + size_t to; + } dbcppp_ValueRange; typedef struct {} dbcppp_ValueEncodingDescription; DBCPPP_API const dbcppp_Attribute* dbcppp_AttributeCreate( diff --git a/include/dbcppp/SignalMultiplexerValue.h b/include/dbcppp/SignalMultiplexerValue.h index a76e9580..93687d90 100644 --- a/include/dbcppp/SignalMultiplexerValue.h +++ b/include/dbcppp/SignalMultiplexerValue.h @@ -27,7 +27,7 @@ namespace dbcppp virtual std::unique_ptr Clone() const = 0; virtual ~ISignalMultiplexerValue() = default; - virtual std::string SwitchName() const = 0; + virtual std::string& SwitchName() const = 0; virtual const Range& ValueRanges_Get(std::size_t i) const = 0; virtual uint64_t ValueRanges_Size() const = 0; diff --git a/src/libdbcppp/CApi.cpp b/src/libdbcppp/CApi.cpp index fccf68d7..c464ba14 100644 --- a/src/libdbcppp/CApi.cpp +++ b/src/libdbcppp/CApi.cpp @@ -54,7 +54,7 @@ extern "C" case IAttributeDefinition::EObjectType::Node: return dbcppp_EObjectType::dbcppp_ObjectType_Node; case IAttributeDefinition::EObjectType::Message: return dbcppp_EObjectType::dbcppp_ObjectType_Message; case IAttributeDefinition::EObjectType::Signal: return dbcppp_EObjectType::dbcppp_ObjectType_Signal; - default: return dbcppp_EObjectType::dbcppp_ObjectType_EnvironmentVariable; + default: return dbcppp_EObjectType::dbcppp_ObjectType_EnvironmentVariable; } } DBCPPP_API dbcppp_EAttributeValueType dbcppp_AttributeValueType(const dbcppp_Attribute* attribute) @@ -88,7 +88,7 @@ extern "C" auto ai = reinterpret_cast(attribute); return std::get(ai->Value()).c_str(); } - + DBCPPP_API dbcppp_AttributeDefinition* dbcppp_AttributeDefinitionCreate( const char* name , dbcppp_EObjectType object_type @@ -879,6 +879,31 @@ extern "C" auto sigi = reinterpret_cast(sig); return sigi->MultiplexerSwitchValue(); } + DBCPPP_API uint64_t dbcppp_SignalMultiplexerValues_Size(const dbcppp_Signal* sig) + { + auto sigi = reinterpret_cast(sig); + return sigi->SignalMultiplexerValues_Size(); + } + DBCPPP_API const dbcppp_SignalMultiplexerValue* dbcppp_SignalMultiplexerValues_Get(const dbcppp_Signal* sig, uint64_t i) + { + auto sigi = reinterpret_cast(sig); + return reinterpret_cast(&sigi->SignalMultiplexerValues_Get(i)); + } + DBCPPP_API const char* dbcppp_SignalMultiplexerValue_SwitchName(const dbcppp_SignalMultiplexerValue* mux_val, uint64_t i) + { + auto sigi = reinterpret_cast(mux_val); + return sigi->SwitchName().c_str(); + } + DBCPPP_API uint64_t dbcppp_ValueRanges_Size(const dbcppp_SignalMultiplexerValue* mux_val) + { + auto sigi = reinterpret_cast(mux_val); + return sigi->ValueRanges_Size(); + } + DBCPPP_API const dbcppp_ValueRange* dbcppp_ValueRanges_Get(const dbcppp_SignalMultiplexerValue* mux_val, uint64_t i) + { + auto sigi = reinterpret_cast(mux_val); + return reinterpret_cast(&sigi->ValueRanges_Get(i)); + } DBCPPP_API uint64_t dbcppp_SignalStartBit(const dbcppp_Signal* sig) { auto sigi = reinterpret_cast(sig); diff --git a/src/libdbcppp/SignalMultiplexerValueImpl.cpp b/src/libdbcppp/SignalMultiplexerValueImpl.cpp index 7e4f07f1..e0178522 100644 --- a/src/libdbcppp/SignalMultiplexerValueImpl.cpp +++ b/src/libdbcppp/SignalMultiplexerValueImpl.cpp @@ -25,7 +25,7 @@ std::unique_ptr SignalMultiplexerValueImpl::Clone() con return std::make_unique(*this); } -std::string SignalMultiplexerValueImpl::SwitchName() const +std::string& SignalMultiplexerValueImpl::SwitchName() const { return _switch_name; } diff --git a/src/libdbcppp/SignalMultiplexerValueImpl.h b/src/libdbcppp/SignalMultiplexerValueImpl.h index e4e609f6..3bc0de67 100644 --- a/src/libdbcppp/SignalMultiplexerValueImpl.h +++ b/src/libdbcppp/SignalMultiplexerValueImpl.h @@ -15,7 +15,7 @@ namespace dbcppp virtual std::unique_ptr Clone() const override; - virtual std::string SwitchName() const override; + virtual std::string& SwitchName() const override; virtual const Range& ValueRanges_Get(std::size_t i) const override; virtual uint64_t ValueRanges_Size() const override; diff --git a/tests/Catch2.cpp b/tests/Catch2.cpp index 7791d9b7..9aeea2cd 100644 --- a/tests/Catch2.cpp +++ b/tests/Catch2.cpp @@ -3751,7 +3751,7 @@ namespace Catch { // 32kb for the alternate stack seems to be sufficient. However, this value // is experimentally determined, so that's not guaranteed. - static constexpr std::size_t sigStackSize = 32768 >= MINSIGSTKSZ ? 32768 : MINSIGSTKSZ; + static std::size_t sigStackSize = 32768 >= MINSIGSTKSZ ? 32768 : MINSIGSTKSZ; static SignalDefs signalDefs[] = { { SIGINT, "SIGINT - Terminal interrupt signal" }, @@ -3807,7 +3807,7 @@ namespace Catch { bool FatalConditionHandler::isSet = false; struct sigaction FatalConditionHandler::oldSigActions[sizeof(signalDefs)/sizeof(SignalDefs)] = {}; stack_t FatalConditionHandler::oldSigStack = {}; - char FatalConditionHandler::altStackMem[sigStackSize] = {}; + char FatalConditionHandler::altStackMem[65536] = {}; } // namespace Catch From e39df0e8e713e44c3c4574c5c903235a716f24c5 Mon Sep 17 00:00:00 2001 From: bmcpt Date: Sat, 13 Aug 2022 15:33:44 +0530 Subject: [PATCH 2/5] add header declarations --- include/dbcppp/CApi.h | 9 +++++++-- include/dbcppp/SignalMultiplexerValue.h | 2 +- src/libdbcppp/SignalMultiplexerValueImpl.cpp | 2 +- src/libdbcppp/SignalMultiplexerValueImpl.h | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/dbcppp/CApi.h b/include/dbcppp/CApi.h index 827021b3..597d5fdc 100644 --- a/include/dbcppp/CApi.h +++ b/include/dbcppp/CApi.h @@ -79,8 +79,8 @@ extern "C" typedef struct {} dbcppp_Signal; typedef struct {} dbcppp_SignalMultiplexerValue; typedef struct { - size_t from; - size_t to; + uint64_t from; + uint64_t to; } dbcppp_ValueRange; typedef struct {} dbcppp_ValueEncodingDescription; @@ -240,6 +240,11 @@ extern "C" DBCPPP_API const char* dbcppp_SignalName(const dbcppp_Signal* sig); DBCPPP_API dbcppp_ESignalMultiplexer dbcppp_SignalMultiplexerIndicator(const dbcppp_Signal* sig); DBCPPP_API uint64_t dbcppp_SignalMultiplexerSwitchValue(const dbcppp_Signal* sig); + DBCPPP_API uint64_t dbcppp_SignalMultiplexerValues_Size(const dbcppp_Signal* sig); + DBCPPP_API const dbcppp_SignalMultiplexerValue* dbcppp_SignalMultiplexerValues_Get(const dbcppp_Signal* sig, uint64_t i); + DBCPPP_API const char* dbcppp_SignalMultiplexerValue_SwitchName(const dbcppp_SignalMultiplexerValue* mux_val, uint64_t i); + DBCPPP_API uint64_t dbcppp_ValueRanges_Size(const dbcppp_SignalMultiplexerValue* mux_val); + DBCPPP_API const dbcppp_ValueRange* dbcppp_ValueRanges_Get(const dbcppp_SignalMultiplexerValue* mux_val, uint64_t i); DBCPPP_API uint64_t dbcppp_SignalStartBit(const dbcppp_Signal* sig); DBCPPP_API uint64_t dbcppp_SignalBitSize(const dbcppp_Signal* sig); DBCPPP_API dbcppp_ESignalByteOrder dbcppp_SignalByteOrder(const dbcppp_Signal* sig); diff --git a/include/dbcppp/SignalMultiplexerValue.h b/include/dbcppp/SignalMultiplexerValue.h index 93687d90..5c69fa95 100644 --- a/include/dbcppp/SignalMultiplexerValue.h +++ b/include/dbcppp/SignalMultiplexerValue.h @@ -27,7 +27,7 @@ namespace dbcppp virtual std::unique_ptr Clone() const = 0; virtual ~ISignalMultiplexerValue() = default; - virtual std::string& SwitchName() const = 0; + virtual const std::string& SwitchName() const = 0; virtual const Range& ValueRanges_Get(std::size_t i) const = 0; virtual uint64_t ValueRanges_Size() const = 0; diff --git a/src/libdbcppp/SignalMultiplexerValueImpl.cpp b/src/libdbcppp/SignalMultiplexerValueImpl.cpp index e0178522..9c9a6013 100644 --- a/src/libdbcppp/SignalMultiplexerValueImpl.cpp +++ b/src/libdbcppp/SignalMultiplexerValueImpl.cpp @@ -25,7 +25,7 @@ std::unique_ptr SignalMultiplexerValueImpl::Clone() con return std::make_unique(*this); } -std::string& SignalMultiplexerValueImpl::SwitchName() const +const std::string& SignalMultiplexerValueImpl::SwitchName() const { return _switch_name; } diff --git a/src/libdbcppp/SignalMultiplexerValueImpl.h b/src/libdbcppp/SignalMultiplexerValueImpl.h index 3bc0de67..3ba9342b 100644 --- a/src/libdbcppp/SignalMultiplexerValueImpl.h +++ b/src/libdbcppp/SignalMultiplexerValueImpl.h @@ -15,7 +15,7 @@ namespace dbcppp virtual std::unique_ptr Clone() const override; - virtual std::string& SwitchName() const override; + virtual const std::string& SwitchName() const override; virtual const Range& ValueRanges_Get(std::size_t i) const override; virtual uint64_t ValueRanges_Size() const override; From f5742c9f686e10293b201e9099c67ef09a60c8a6 Mon Sep 17 00:00:00 2001 From: bmcpt Date: Sat, 13 Aug 2022 15:40:10 +0530 Subject: [PATCH 3/5] use MINSIGSTKSZ workaround from stackoverflow --- tests/Catch2.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/Catch2.cpp b/tests/Catch2.cpp index 9aeea2cd..50ef7abf 100644 --- a/tests/Catch2.cpp +++ b/tests/Catch2.cpp @@ -3742,6 +3742,10 @@ PVOID FatalConditionHandler::exceptionHandlerHandle = nullptr; #elif defined( CATCH_CONFIG_POSIX_SIGNALS ) +// https://stackoverflow.com/questions/71454588/minsigstksz-error-after-update-in-my-manjaro-linux +#undef MINSIGSTKSZ +#define MINSIGSTKSZ 65536 + namespace Catch { struct SignalDefs { @@ -3751,7 +3755,7 @@ namespace Catch { // 32kb for the alternate stack seems to be sufficient. However, this value // is experimentally determined, so that's not guaranteed. - static std::size_t sigStackSize = 32768 >= MINSIGSTKSZ ? 32768 : MINSIGSTKSZ; + static constexpr std::size_t sigStackSize = 32768 >= MINSIGSTKSZ ? 32768 : MINSIGSTKSZ; static SignalDefs signalDefs[] = { { SIGINT, "SIGINT - Terminal interrupt signal" }, @@ -3807,7 +3811,7 @@ namespace Catch { bool FatalConditionHandler::isSet = false; struct sigaction FatalConditionHandler::oldSigActions[sizeof(signalDefs)/sizeof(SignalDefs)] = {}; stack_t FatalConditionHandler::oldSigStack = {}; - char FatalConditionHandler::altStackMem[65536] = {}; + char FatalConditionHandler::altStackMem[sigStackSize] = {}; } // namespace Catch From 663ca9a2ead04a4662b31f5658845ae0b1e62a0f Mon Sep 17 00:00:00 2001 From: bmcpt Date: Wed, 17 Aug 2022 21:48:38 +0530 Subject: [PATCH 4/5] rename functions to make scoping nomenclature --- include/dbcppp/CApi.h | 4 ++-- src/libdbcppp/CApi.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/dbcppp/CApi.h b/include/dbcppp/CApi.h index 597d5fdc..18f70de6 100644 --- a/include/dbcppp/CApi.h +++ b/include/dbcppp/CApi.h @@ -243,8 +243,8 @@ extern "C" DBCPPP_API uint64_t dbcppp_SignalMultiplexerValues_Size(const dbcppp_Signal* sig); DBCPPP_API const dbcppp_SignalMultiplexerValue* dbcppp_SignalMultiplexerValues_Get(const dbcppp_Signal* sig, uint64_t i); DBCPPP_API const char* dbcppp_SignalMultiplexerValue_SwitchName(const dbcppp_SignalMultiplexerValue* mux_val, uint64_t i); - DBCPPP_API uint64_t dbcppp_ValueRanges_Size(const dbcppp_SignalMultiplexerValue* mux_val); - DBCPPP_API const dbcppp_ValueRange* dbcppp_ValueRanges_Get(const dbcppp_SignalMultiplexerValue* mux_val, uint64_t i); + DBCPPP_API uint64_t dbcppp_SignalMultiplexerValue_ValueRanges_Size(const dbcppp_SignalMultiplexerValue* mux_val); + DBCPPP_API const dbcppp_ValueRange* dbcppp_SignalMultiplexerValue_ValueRanges_Get(const dbcppp_SignalMultiplexerValue* mux_val, uint64_t i); DBCPPP_API uint64_t dbcppp_SignalStartBit(const dbcppp_Signal* sig); DBCPPP_API uint64_t dbcppp_SignalBitSize(const dbcppp_Signal* sig); DBCPPP_API dbcppp_ESignalByteOrder dbcppp_SignalByteOrder(const dbcppp_Signal* sig); diff --git a/src/libdbcppp/CApi.cpp b/src/libdbcppp/CApi.cpp index c464ba14..24e495de 100644 --- a/src/libdbcppp/CApi.cpp +++ b/src/libdbcppp/CApi.cpp @@ -894,12 +894,12 @@ extern "C" auto sigi = reinterpret_cast(mux_val); return sigi->SwitchName().c_str(); } - DBCPPP_API uint64_t dbcppp_ValueRanges_Size(const dbcppp_SignalMultiplexerValue* mux_val) + DBCPPP_API uint64_t dbcppp_SignalMultiplexerValue_ValueRanges_Size(const dbcppp_SignalMultiplexerValue* mux_val) { auto sigi = reinterpret_cast(mux_val); return sigi->ValueRanges_Size(); } - DBCPPP_API const dbcppp_ValueRange* dbcppp_ValueRanges_Get(const dbcppp_SignalMultiplexerValue* mux_val, uint64_t i) + DBCPPP_API const dbcppp_ValueRange* dbcppp_SignalMultiplexerValue_ValueRanges_Get(const dbcppp_SignalMultiplexerValue* mux_val, uint64_t i) { auto sigi = reinterpret_cast(mux_val); return reinterpret_cast(&sigi->ValueRanges_Get(i)); From 0ad29979d2eb30e2298316d6ff6c8f0c98496adf Mon Sep 17 00:00:00 2001 From: bmcpt Date: Wed, 17 Aug 2022 22:07:02 +0530 Subject: [PATCH 5/5] removed unnecessary arg --- include/dbcppp/CApi.h | 2 +- src/libdbcppp/CApi.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/dbcppp/CApi.h b/include/dbcppp/CApi.h index 18f70de6..24c22a0b 100644 --- a/include/dbcppp/CApi.h +++ b/include/dbcppp/CApi.h @@ -242,7 +242,7 @@ extern "C" DBCPPP_API uint64_t dbcppp_SignalMultiplexerSwitchValue(const dbcppp_Signal* sig); DBCPPP_API uint64_t dbcppp_SignalMultiplexerValues_Size(const dbcppp_Signal* sig); DBCPPP_API const dbcppp_SignalMultiplexerValue* dbcppp_SignalMultiplexerValues_Get(const dbcppp_Signal* sig, uint64_t i); - DBCPPP_API const char* dbcppp_SignalMultiplexerValue_SwitchName(const dbcppp_SignalMultiplexerValue* mux_val, uint64_t i); + DBCPPP_API const char* dbcppp_SignalMultiplexerValue_SwitchName(const dbcppp_SignalMultiplexerValue* mux_val); DBCPPP_API uint64_t dbcppp_SignalMultiplexerValue_ValueRanges_Size(const dbcppp_SignalMultiplexerValue* mux_val); DBCPPP_API const dbcppp_ValueRange* dbcppp_SignalMultiplexerValue_ValueRanges_Get(const dbcppp_SignalMultiplexerValue* mux_val, uint64_t i); DBCPPP_API uint64_t dbcppp_SignalStartBit(const dbcppp_Signal* sig); diff --git a/src/libdbcppp/CApi.cpp b/src/libdbcppp/CApi.cpp index 24e495de..2cf8a1bb 100644 --- a/src/libdbcppp/CApi.cpp +++ b/src/libdbcppp/CApi.cpp @@ -889,7 +889,7 @@ extern "C" auto sigi = reinterpret_cast(sig); return reinterpret_cast(&sigi->SignalMultiplexerValues_Get(i)); } - DBCPPP_API const char* dbcppp_SignalMultiplexerValue_SwitchName(const dbcppp_SignalMultiplexerValue* mux_val, uint64_t i) + DBCPPP_API const char* dbcppp_SignalMultiplexerValue_SwitchName(const dbcppp_SignalMultiplexerValue* mux_val) { auto sigi = reinterpret_cast(mux_val); return sigi->SwitchName().c_str();