From 8911590c3811e6c3de9a6dc55d6d0f22a9e620b8 Mon Sep 17 00:00:00 2001 From: Jeffrey H Peterson Date: Mon, 27 Nov 2023 12:46:29 -0700 Subject: [PATCH 1/2] Add error check after 'eosCreateTables()' in the 'eosSafeLoad()' function --- eospac-wrapper/eospac_wrapper.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/eospac-wrapper/eospac_wrapper.cpp b/eospac-wrapper/eospac_wrapper.cpp index 67643ac107..707852cc0e 100644 --- a/eospac-wrapper/eospac_wrapper.cpp +++ b/eospac-wrapper/eospac_wrapper.cpp @@ -132,6 +132,25 @@ EOS_INTEGER eosSafeLoad(int ntables, int matid, EOS_INTEGER tableType[], eos_CreateTables(NTABLES, tableType, MATID.data(), tableHandle, &errorCode); + if (errorCode != EOS_OK) { + if (eospacWarn != Verbosity::Quiet) { + for (int i = 0; i < ntables; i++) { + eos_GetErrorCode(&tableHandle[i], &tableHandleErrorCode); + eos_GetErrorMessage(&tableHandleErrorCode, errorMessage); + std::cerr << "eos_CreateTables ERROR " << tableHandleErrorCode; + if (table_names.size() > 0) { + std::cerr << " for table names\n\t{"; + for (auto &name : table_names) { + std::cerr << name << ", "; + } + std::cerr << "}"; + } + std::cerr << ":\n\t" << errorMessage << std::endl; + } + } + return errorCode; + } + if (invert_at_setup) { EOS_REAL values[] = {1.}; for (int i = 0; i < ntables; i++) { From 8a84a5ab4044e761941f0752fb7cba608c72eb43 Mon Sep 17 00:00:00 2001 From: Jeffrey H Peterson Date: Mon, 27 Nov 2023 14:52:25 -0700 Subject: [PATCH 2/2] Redo logic for when comment table exists but to ignore when comment length is zero or negative --- eospac-wrapper/eospac_wrapper.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/eospac-wrapper/eospac_wrapper.cpp b/eospac-wrapper/eospac_wrapper.cpp index 707852cc0e..3a2fdb8ee8 100644 --- a/eospac-wrapper/eospac_wrapper.cpp +++ b/eospac-wrapper/eospac_wrapper.cpp @@ -77,24 +77,26 @@ void eosGetMetadata(int matid, SesameMetadata &metadata, Verbosity eospacWarn) { EOS_INTEGER errorCode = eosSafeLoad(1, matid, commentsType, commentsHandle, {"EOS_Comments"}, eospacWarn); EOS_INTEGER eospacComments = commentsHandle[0]; + bool commentTableCreated = (errorCode == EOS_OK); - if (errorCode == EOS_OK) { - std::vector comments; - EOS_REAL commentLen; + EOS_REAL commentLen = -1; + if (commentTableCreated) { EOS_INTEGER commentItem = EOS_Cmnt_Len; eosSafeTableInfo(commentsHandle, 1, &commentItem, &commentLen, eospacWarn); + } + if (commentLen > 0) { + std::vector comments; comments.resize(static_cast(commentLen)); metadata.comments.resize(comments.size()); - if (comments.size() > 0) + if (comments.size() > 0) { eosSafeTableCmnts(&eospacComments, comments.data(), eospacWarn); + } for (size_t i = 0; i < comments.size(); i++) { metadata.comments[i] = comments[i]; } metadata.name = getName(metadata.comments); - - eosSafeDestroy(1, commentsHandle, eospacWarn); } else { std::string matid_str = std::to_string(matid); if (eospacWarn != Verbosity::Quiet) { @@ -104,6 +106,12 @@ void eosGetMetadata(int matid, SesameMetadata &metadata, Verbosity eospacWarn) { metadata.name = "No name for matid " + matid_str; metadata.comments = "Comment unavailable for matid " + matid_str; } + + // Note: table could be created even if the commentLen is nonsense, so we + // need to separate this block from the above logic + if (commentTableCreated) { + eosSafeDestroy(1, commentsHandle, eospacWarn); + } } EOS_INTEGER eosSafeLoad(int ntables, int matid, EOS_INTEGER tableType[],