Skip to content

User propagator - C++ API #5507

@imarmanis

Description

@imarmanis

Hi, I'm looking for a working example for the user propagator in C++.
I have tried the following, but the call to fixed leads to a segmentation fault (without any other output).
The version I'm using is 4.8.12.

#include "z3++.h"

using namespace z3;

std::function<void(unsigned, expr const &)> my_fixed = [](unsigned, expr const&) {std::cout << "Fixed\n";};

class MyPropagator : public user_propagator_base
{
    public:
        void push() { std::cout << "Push\n"; }
        void pop(unsigned n) { std::cout << "Pop\n"; }
        user_propagator_base *fresh(Z3_context ctx) { std::cout << "Fresh\n"; return nullptr; }
        MyPropagator(solver *s) : user_propagator_base(s) { fixed(my_fixed); }
};

int main()
{
    context c;
    solver s(c, (struct z3::solver::simple) {});
    MyPropagator p(&s);
    return 0;
}

It seems that, compared to the python api, a call to Z3_solver_propagate_init is missing from the constructor
of user_propagator_base.
Adding that, I no longer get the segmentation fault but other problems appear when I
actually use the propagator, so I'm unsure if that was actually the problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions