Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve exception safety with smart pointers #533

Closed
elfring opened this issue May 17, 2024 · 4 comments
Closed

Improve exception safety with smart pointers #533

elfring opened this issue May 17, 2024 · 4 comments

Comments

@elfring
Copy link

elfring commented May 17, 2024

Would you like to wrap any pointers with the class template “std::unique_ptr”?

@sjunges
Copy link
Contributor

sjunges commented May 21, 2024

Not any, but we do of course welcome increased memory safety.

@elfring
Copy link
Author

elfring commented May 22, 2024

@sjunges
Copy link
Contributor

sjunges commented May 22, 2024

We welcome pull requests that improve the code quality. Integrating CI based on clang-tidy is not a priority right now.

@sjunges sjunges closed this as completed May 22, 2024
@elfring
Copy link
Author

elfring commented May 23, 2024

🔮 Will a special data representation trigger another bit of collateral evolution?

storm::gspn::GSPN* GspnParser::parse(std::string const& filename, std::string const& constantDefinitions) {
#ifdef STORM_HAVE_XERCES
// initialize xercesc
try {
xercesc::XMLPlatformUtils::Initialize();
} catch (xercesc::XMLException const& toCatch) {
// Error occurred during the initialization process. Abort parsing since it is not possible.
STORM_LOG_THROW(false, storm::exceptions::UnexpectedException, "Failed to initialize xercesc\n");
}
auto parser = new xercesc::XercesDOMParser();
parser->setValidationScheme(xercesc::XercesDOMParser::Val_Always);
parser->setDoNamespaces(false);
parser->setDoSchema(false);
parser->setLoadExternalDTD(false);
parser->setIncludeIgnorableWhitespace(false);
auto errHandler = (xercesc::ErrorHandler*)new xercesc::HandlerBase();
parser->setErrorHandler(errHandler);
// parse file
try {
parser->parse(filename.c_str());
} catch (xercesc::XMLException const& toCatch) {
auto message = xercesc::XMLString::transcode(toCatch.getMessage());
// Error occurred while parsing the file. Abort constructing the gspn since the input file is not valid
// or the parser run into a problem.
STORM_LOG_THROW(false, storm::exceptions::UnexpectedException, message);
xercesc::XMLString::release(&message);
} catch (const xercesc::DOMException& toCatch) {
auto message = xercesc::XMLString::transcode(toCatch.msg);
// Error occurred while parsing the file. Abort constructing the gspn since the input file is not valid
// or the parser run into a problem.
STORM_LOG_THROW(false, storm::exceptions::UnexpectedException, message);
xercesc::XMLString::release(&message);
} catch (...) {
// Error occurred while parsing the file. Abort constructing the gspn since the input file is not valid
// or the parser run into a problem.
STORM_LOG_THROW(false, storm::exceptions::UnexpectedException, "Failed to parse pnml file.\n");
}
// build gspn by traversing the DOM object
parser->getDocument()->normalizeDocument();
xercesc::DOMElement* elementRoot = parser->getDocument()->getDocumentElement();
if (storm::adapters::XMLtoString(elementRoot->getTagName()) == "pnml") {
STORM_LOG_WARN_COND(constantDefinitions == "", "Constant definitions for pnml files are currently not supported.");
PnmlParser p;
return p.parse(elementRoot);
} else if (storm::adapters::XMLtoString(elementRoot->getTagName()) == "project") {
GreatSpnEditorProjectParser p(constantDefinitions);
return p.parse(elementRoot);
} else {
// If the top-level node is not a "pnml" or "" node, then throw an exception.
STORM_LOG_THROW(false, storm::exceptions::UnexpectedException, "Failed to identify the root element.\n");
}
// clean up
delete parser;
delete errHandler;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants