From 2626e6ae2ff95fd367a0fac45db71cdfd6808491 Mon Sep 17 00:00:00 2001 From: Andrea Sgattoni Date: Mon, 23 Sep 2024 11:35:31 +0200 Subject: [PATCH] test --- CMakeLists.txt | 3 +- fix_locale_bug.patch | 96 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 fix_locale_bug.patch diff --git a/CMakeLists.txt b/CMakeLists.txt index 026a6a6..b80de37 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ if (NOT DEFINED ortools_REF) message(FATAL_ERROR "ortools_REF is not defined") endif () find_package(Python3 REQUIRED COMPONENTS Interpreter Development.Module) -message("found PYTHON interpreter ${Python_EXECUTABLE} = " ${Python_EXECUTABLE}) +message("found Python3 interpreter = ${Python3_EXECUTABLE}") FetchContent_Declare(ortools GIT_REPOSITORY ${ortools_REPO} GIT_TAG ${ortools_REF} @@ -23,6 +23,7 @@ FetchContent_Declare(ortools ${CMAKE_CURRENT_SOURCE_DIR}/ortools ${CMAKE_CURRENT_SOURCE_DIR}/cmake_patches . && ${Python3_EXECUTABLE} patch.py + && git apply ${CMAKE_CURRENT_SOURCE_DIR}/fix_locale_bug.patch OVERRIDE_FIND_PACKAGE ON ) message("BUILD_DEPS: " ${BUILD_DEPS}) diff --git a/fix_locale_bug.patch b/fix_locale_bug.patch new file mode 100644 index 0000000..a74b49f --- /dev/null +++ b/fix_locale_bug.patch @@ -0,0 +1,96 @@ +Index: ortools/linear_solver/xpress_interface.cc +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +diff --git a/ortools/linear_solver/xpress_interface.cc b/ortools/linear_solver/xpress_interface.cc +--- a/ortools/linear_solver/xpress_interface.cc (revision ed94162b910fa58896db99191378d3b71a5313af) ++++ b/ortools/linear_solver/xpress_interface.cc (date 1727081541820) +@@ -22,6 +22,7 @@ + #include + #include + ++#include "absl/strings/numbers.h" + #include "absl/strings/str_format.h" + #include "ortools/base/logging.h" + #include "ortools/base/timer.h" +@@ -227,7 +228,7 @@ + : xprsprob_(xprsprob), + event_(event), + num_nodes_(num_nodes), +- variable_values_(0) {}; ++ variable_values_(0){}; + + // Implementation of the interface. + MPCallbackEvent Event() override { return event_; }; +@@ -260,7 +261,7 @@ + // Wraps the MPCallback in order to catch and store exceptions + class MPCallbackWrapper { + public: +- explicit MPCallbackWrapper(MPCallback* callback) : callback_(callback) {}; ++ explicit MPCallbackWrapper(MPCallback* callback) : callback_(callback){}; + MPCallback* GetCallback() const { return callback_; } + // Since our (C++) call-back functions are called from the XPRESS (C) code, + // exceptions thrown in our call-back code are not caught by XPRESS. +@@ -2106,29 +2107,21 @@ + } + } + +-const char* stringToCharPtr(std::string& var) { return var.c_str(); } +- +-// Save the existing locale, use the "C" locale to ensure that +-// string -> double conversion is done ignoring the locale. +-struct ScopedLocale { +- ScopedLocale() { +- oldLocale = std::setlocale(LC_NUMERIC, nullptr); +- auto newLocale = std::setlocale(LC_NUMERIC, "C"); +- CHECK_EQ(std::string(newLocale), "C"); +- } +- ~ScopedLocale() { std::setlocale(LC_NUMERIC, oldLocale); } ++bool stringToCharPtr(const std::string& var, const char** out) { ++ *out = var.c_str(); ++ return true; ++} + +- private: +- const char* oldLocale; +-}; +- +-#define setParamIfPossible_MACRO(target_map, setter, converter) \ ++#define setParamIfPossible_MACRO(target_map, setter, converter, type) \ + { \ + auto matchingParamIter = (target_map).find(paramAndValuePair.first); \ + if (matchingParamIter != (target_map).end()) { \ +- const auto convertedValue = converter(paramAndValuePair.second); \ +- VLOG(1) << "Setting parameter " << paramAndValuePair.first \ +- << " to value " << convertedValue << std::endl; \ ++ type convertedValue; \ ++ bool ret = converter(paramAndValuePair.second, &convertedValue); \ ++ if (ret) { \ ++ VLOG(1) << "Setting parameter " << paramAndValuePair.first \ ++ << " to value " << convertedValue << std::endl; \ ++ } \ + setter(mLp, matchingParamIter->second, convertedValue); \ + continue; \ + } \ +@@ -2153,14 +2146,15 @@ + } + } + +- ScopedLocale locale; + for (auto& paramAndValuePair : paramAndValuePairList) { +- setParamIfPossible_MACRO(mapIntegerControls_, XPRSsetintcontrol, std::stoi); +- setParamIfPossible_MACRO(mapDoubleControls_, XPRSsetdblcontrol, std::stod); ++ setParamIfPossible_MACRO(mapIntegerControls_, XPRSsetintcontrol, ++ absl::SimpleAtoi, int); ++ setParamIfPossible_MACRO(mapDoubleControls_, XPRSsetdblcontrol, ++ absl::SimpleAtod, double); + setParamIfPossible_MACRO(mapStringControls_, XPRSsetstrcontrol, +- stringToCharPtr); ++ stringToCharPtr, const char*); + setParamIfPossible_MACRO(mapInteger64Controls_, XPRSsetintcontrol64, +- std::stoll); ++ absl::SimpleAtoi, int64_t); + LOG(ERROR) << "Unknown parameter " << paramName << " : function " + << __FUNCTION__ << std::endl; + return false;