Skip to content

Commit

Permalink
Merge pull request #322 from lanl/jhp/eospac_comment
Browse files Browse the repository at this point in the history
Add error check after 'eosCreateTables()' in the 'eosSafeLoad()' function
  • Loading branch information
Yurlungur authored Nov 28, 2023
2 parents b08627a + 8a84a5a commit b598d4e
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions eospac-wrapper/eospac_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<EOS_CHAR> 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<EOS_CHAR> comments;
comments.resize(static_cast<int>(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) {
Expand All @@ -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[],
Expand Down Expand Up @@ -132,6 +140,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++) {
Expand Down

0 comments on commit b598d4e

Please sign in to comment.