Analyser: Not holding onto references
Closed this issue · 4 comments
hsorby commented
When analysing a model the analyser does not hold onto object references that it later needs when generating code. This results in generated code that cannot be simulated.
agarny commented
No idea what you mean by this.
hsorby commented
I'll write a test to show the problem.
hsorby commented
Here is a test that will cause a segfault when trying to generate the implement code (implementationCode) :
TEST(Generator, modelOutOfScope)
{
auto analyser = libcellml::Analyser::create();
{
auto parser = libcellml::Parser::create();
auto model = parser->parseModel(fileContents("generator/ode_multiple_dependent_odes/model.cellml"));
EXPECT_EQ(size_t(0), parser->issueCount());
analyser->analyseModel(model);
}
EXPECT_EQ(size_t(0), analyser->errorCount());
auto analyserModel = analyser->model();
auto generator = libcellml::Generator::create();
generator->setModel(analyserModel);
auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON);
generator->setProfile(profile);
EXPECT_EQ(fileContents("generator/ode_multiple_dependent_odes/model.py"), generator->implementationCode());
}
agarny commented
Thanks, I am looking into it.