cellml / libcellml

Repository for libCellML development.
https://libcellml.org
Apache License 2.0
17 stars 21 forks source link

Analyser: Not holding onto references #1183

Closed hsorby closed 1 year ago

hsorby commented 1 year ago

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 1 year ago

No idea what you mean by this.

hsorby commented 1 year ago

I'll write a test to show the problem.

hsorby commented 1 year ago

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 1 year ago

Thanks, I am looking into it.