Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ortools/sat/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ add_custom_command(
OUTPUT proto_builder_pybind11.h
COMMAND gen_proto_builder_pybind11 > proto_builder_pybind11.h
COMMENT "Generate C++ proto_builder_pybind11.h"
DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/gen_proto_builder_pybind11
VERBATIM)

pybind11_add_module(cp_model_helper_pybind11 MODULE cp_model_helper.cc proto_builder_pybind11.h)
Expand Down
12 changes: 6 additions & 6 deletions ortools/sat/python/cp_model_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1754,8 +1754,8 @@ PYBIND11_MODULE(cp_model_helper, m) {
.def(py::init<std::shared_ptr<CpModelProto>, int>())
.def(py::init<std::shared_ptr<CpModelProto>>()) // new variable.
.def_property_readonly(
"proto", &IntVar::proto, py::return_value_policy::reference,
py::keep_alive<1, 0>(),
"proto", py::cpp_function(&IntVar::proto, py::return_value_policy::reference,
py::keep_alive<1, 0>()),
"Returns the IntegerVariableProto of this variable.")
.def_property_readonly("model_proto", &IntVar::model_proto,
"Returns the CP model protobuf")
Expand Down Expand Up @@ -2000,9 +2000,9 @@ PYBIND11_MODULE(cp_model_helper, m) {
"Returns the index of the constraint in the model protobuf.")
.def_property_readonly("model_proto", &Constraint::model_proto,
"Returns the model protobuf.")
.def_property_readonly("proto", &Constraint::proto,
.def_property_readonly("proto", py::cpp_function(&Constraint::proto,
py::return_value_policy::reference,
py::keep_alive<1, 0>(),
py::keep_alive<1, 0>()),
"Returns the ConstraintProto of this constraint.")
.def_property("name", &Constraint::name, &Constraint::SetName,
"The name of the constraint.")
Expand Down Expand Up @@ -2118,8 +2118,8 @@ intervals into the schedule.
.def_property_readonly("model_proto", &IntervalVar::model_proto,
"Returns the model protobuf.")
.def_property_readonly(
"proto", &IntervalVar::proto, py::return_value_policy::reference,
py::keep_alive<1, 0>(), "Returns the interval constraint protobuf.")
"proto", py::cpp_function(&IntervalVar::proto, py::return_value_policy::reference,
py::keep_alive<1, 0>()), "Returns the interval constraint protobuf.")
.def_property("name", &IntervalVar::name, &IntervalVar::SetName,
"The name of the interval variable.")
.def(
Expand Down
4 changes: 2 additions & 2 deletions ortools/sat/python/wrappers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ class Generator {
.def_property_readonly(
"$0",
[]($1 self) { return self->mutable_$2(); },
py::return_value_policy::reference, py::keep_alive<0, 1>()))",
py::return_value_policy::reference_internal))",
field.name(), current_context_.self_mutable_name, field.name());
// We'll need to generate the wrapping for
// `google::protobuf::RepeatedPtrField<$3>`.
Expand All @@ -357,7 +357,7 @@ class Generator {
.def_property_readonly(
"$0",
[]($1 self) { return self->mutable_$0(); },
py::return_value_policy::reference, py::keep_alive<0, 1>()))",
py::return_value_policy::reference_internal))",
field.name(),
current_context_.self_mutable_name);
// We'll need to generate the wrapping for
Expand Down