Skip to content

Commit d4ed0ad

Browse files
authored
Add nullability to SolveInterrupter in linear solver (#4958)
1 parent 8a4423e commit d4ed0ad

File tree

6 files changed

+14
-7
lines changed

6 files changed

+14
-7
lines changed

ortools/linear_solver/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,5 +598,6 @@ cc_library(
598598
":linear_solver_cc_proto",
599599
"//ortools/util:lazy_mutable_copy",
600600
"//ortools/util:solve_interrupter",
601+
"@abseil-cpp//absl/base:nullability",
601602
],
602603
)

ortools/linear_solver/linear_solver.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,6 @@ absl::string_view ToString(
516516
}
517517
LOG(FATAL) << "Unrecognized solver type: "
518518
<< static_cast<int>(optimization_problem_type);
519-
return "";
520519
}
521520

522521
bool AbslParseFlag(const absl::string_view text,

ortools/linear_solver/solve_mp_model.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <string>
1818
#include <utility>
1919

20+
#include "absl/base/nullability.h"
2021
#include "ortools/linear_solver/linear_solver.h"
2122
#include "ortools/linear_solver/linear_solver.pb.h"
2223
#include "ortools/util/lazy_mutable_copy.h"
@@ -26,8 +27,9 @@ namespace operations_research {
2627

2728
// TODO(b/311704821): this function should not delegate to MPSolver, also true
2829
// for the functions below.
29-
MPSolutionResponse SolveMPModel(LazyMutableCopy<MPModelRequest> request,
30-
const SolveInterrupter* interrupter) {
30+
MPSolutionResponse SolveMPModel(
31+
LazyMutableCopy<MPModelRequest> request,
32+
const SolveInterrupter* absl_nullable interrupter) {
3133
MPSolutionResponse response;
3234
if (interrupter != nullptr) {
3335
std::atomic<bool> atomic_bool = false;

ortools/linear_solver/solve_mp_model.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <string>
2222

23+
#include "absl/base/nullability.h"
2324
#include "ortools/linear_solver/linear_solver.pb.h"
2425
#include "ortools/util/lazy_mutable_copy.h"
2526
#include "ortools/util/solve_interrupter.h"
@@ -41,8 +42,9 @@ namespace operations_research {
4142
* Passing a non-null pointer with any other solver type immediately returns an
4243
* MPSOLVER_INCOMPATIBLE_OPTIONS error.
4344
*/
44-
MPSolutionResponse SolveMPModel(LazyMutableCopy<MPModelRequest> request,
45-
const SolveInterrupter* interrupter = nullptr);
45+
MPSolutionResponse SolveMPModel(
46+
LazyMutableCopy<MPModelRequest> request,
47+
const SolveInterrupter* absl_nullable interrupter = nullptr);
4648

4749
bool SolverTypeSupportsInterruption(MPModelRequest::SolverType solver);
4850

ortools/util/python/py_solve_interrupter_testing.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515

1616
#include <optional>
1717

18+
#include "absl/base/nullability.h"
1819
#include "ortools/util/python/py_solve_interrupter.h"
1920

2021
namespace operations_research {
2122

22-
std::optional<bool> IsInterrupted(const PySolveInterrupter* interrupter) {
23+
std::optional<bool> IsInterrupted(
24+
const PySolveInterrupter* absl_nullable interrupter) {
2325
if (interrupter == nullptr) {
2426
return std::nullopt;
2527
}

ortools/util/python/py_solve_interrupter_testing.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ namespace operations_research {
3131
//
3232
// The Clif/pybind11 wrapper will return a `bool | None` value, with None for
3333
// nullopt.
34-
std::optional<bool> IsInterrupted(const PySolveInterrupter* interrupter);
34+
std::optional<bool> IsInterrupted(
35+
const PySolveInterrupter* absl_nullable interrupter);
3536

3637
// Class that keeps a reference on a std::shared_ptr<PySolveInterrupter> to
3738
// test that the C++ object survive the cleanup of the Python reference.

0 commit comments

Comments
 (0)