Skip to content

Broken usage of pybind11 "keep_alive" annotation #5140

@StefanBruens

Description

@StefanBruens

What version of OR-Tools and what language are you using?
Version: main/v9.15
Language: Python

Which solver are you using (e.g. CP-SAT, Routing Solver, GLOP, BOP, Gurobi)
n/a

What operating system (Linux, Windows, ...) and version?

What did you do?
Compile it

What did you expect to see
no errors

What did you see instead?

[  762s]  2870 |     .def_property_readonly(
[  762s]       |     ~~~~~~~~~~~~~~~~~~~~~~^
[  762s]  2871 |         "tails",
[  762s]       |         ~~~~~~~~           
[  762s]  2872 |         [](operations_research::sat::CircuitConstraintProto* self) { return self->mutable_tails(); },
[  762s]       |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[  762s]  2873 |         py::return_value_policy::reference, py::keep_alive<0, 1>())
[  762s]       |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[  762s] /usr/include/pybind11/pybind11.h:2659:25: error: static assertion failed: def_property family does not currently support keep_alive. Use a py::cpp_function instead.

While this error message is specific to current pybind11 versions, the actual error is inside the or-tools code, and the generated code is also wrong with the bundled pybind11.

For details, see pybind/pybind11#5533

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