From ea2175db82d7926ac12046ee095cc28408a7ccd4 Mon Sep 17 00:00:00 2001 From: Federico Terraneo Date: Thu, 9 May 2024 15:19:53 +0200 Subject: [PATCH 1/3] Try to load ModelicaError/ModelicaWarning from tools that export the symbol --- Projects/Sources/errorhandling.cpp | 6 ++++++ Projects/Sources/importer.h | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Projects/Sources/errorhandling.cpp b/Projects/Sources/errorhandling.cpp index 6af00b45..2563b6df 100644 --- a/Projects/Sources/errorhandling.cpp +++ b/Projects/Sources/errorhandling.cpp @@ -34,6 +34,9 @@ void errorMessage(char *errorMsg){ #else // Workaround code for Windows, will be removed when a proper solution to // call ModelicaUtilities functions from DLLs is finally delivered + if(ModelicaErrorPtr == nullptr) + ModelicaErrorPtr = tryImportSymbol("ModelicaError"); + if(ModelicaErrorPtr) // The pointer to ModelicaError has already been initialized by a previous // call to setState_xx @@ -58,6 +61,9 @@ void warningMessage(char *warningMsg){ #else // Workaround code for Windows, will be removed when a proper solution to // call ModelicaUtilities functions from DLLs is finally delivered + if(ModelicaWarningPtr == nullptr) + ModelicaWarningPtr = tryImportSymbol("ModelicaWarning"); + if(ModelicaWarningPtr) // The pointer to ModelicaError has already been initialized by a previous // call to setState_xx diff --git a/Projects/Sources/importer.h b/Projects/Sources/importer.h index 444e10e8..a7b00fe3 100644 --- a/Projects/Sources/importer.h +++ b/Projects/Sources/importer.h @@ -15,7 +15,7 @@ #include template -T importSymbol(const char *funcName) +T tryImportSymbol(const char *funcName) { /* TODO: we should do caching */ @@ -54,6 +54,16 @@ T importSymbol(const char *funcName) if(pfn) return pfn; } + /* not found */ + return NULL; +} + +template +T importSymbol(const char *funcName) +{ + T result = tryImportSymbol(funcName); + if(result) return result; + fprintf(stderr, "Can't get handle to %s in all loaded modules.\n", funcName); exit(1); } From 66fdd9a6ccaa7cba056f7448e96ef7479c9307b8 Mon Sep 17 00:00:00 2001 From: Federico Terraneo Date: Mon, 13 May 2024 17:20:58 +0200 Subject: [PATCH 2/3] Fix whitespace --- Projects/Sources/errorhandling.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Projects/Sources/errorhandling.cpp b/Projects/Sources/errorhandling.cpp index 2563b6df..84a3a4c3 100644 --- a/Projects/Sources/errorhandling.cpp +++ b/Projects/Sources/errorhandling.cpp @@ -40,7 +40,7 @@ void errorMessage(char *errorMsg){ if(ModelicaErrorPtr) // The pointer to ModelicaError has already been initialized by a previous // call to setState_xx - ModelicaErrorPtr(msg.c_str()); + ModelicaErrorPtr(msg.c_str()); else { // The pointer to ModelicaError is not yet initialized, so all we can do @@ -67,7 +67,7 @@ void warningMessage(char *warningMsg){ if(ModelicaWarningPtr) // The pointer to ModelicaError has already been initialized by a previous // call to setState_xx - ModelicaWarningPtr(msg.c_str()); + ModelicaWarningPtr(msg.c_str()); else { // The pointer to ModelicaError is not yet initialized, so all we can do From 675bed5a39be37b1611c0e871d8ea7bc195575c8 Mon Sep 17 00:00:00 2001 From: Federico Terraneo Date: Mon, 13 May 2024 17:32:46 +0200 Subject: [PATCH 3/3] Fix for older compilers --- Projects/Sources/importer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Projects/Sources/importer.h b/Projects/Sources/importer.h index a7b00fe3..2c1e0deb 100644 --- a/Projects/Sources/importer.h +++ b/Projects/Sources/importer.h @@ -61,7 +61,7 @@ T tryImportSymbol(const char *funcName) template T importSymbol(const char *funcName) { - T result = tryImportSymbol(funcName); + T result = tryImportSymbol(funcName); if(result) return result; fprintf(stderr, "Can't get handle to %s in all loaded modules.\n", funcName);