From bb41ef405f85175d1658cadd858796a02c0ea540 Mon Sep 17 00:00:00 2001 From: Andrea Sgattoni Date: Mon, 20 Nov 2023 16:56:37 +0100 Subject: [PATCH] hard crash if one Xpress function not found --- ortools/base/dynamic_library.h | 14 +++----------- ortools/xpress/environment.cc | 26 ++++++++++---------------- 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/ortools/base/dynamic_library.h b/ortools/base/dynamic_library.h index 2c36e185a29..7296785f60e 100644 --- a/ortools/base/dynamic_library.h +++ b/ortools/base/dynamic_library.h @@ -17,7 +17,6 @@ #include #include #include -#include #include "ortools/base/logging.h" @@ -31,7 +30,6 @@ #endif class DynamicLibrary { -static constexpr size_t kMaxFunctionsNotFound = 10; public: DynamicLibrary() : library_handle_(nullptr) {} @@ -59,10 +57,6 @@ static constexpr size_t kMaxFunctionsNotFound = 10; bool LibraryIsLoaded() const { return library_handle_ != nullptr; } - const std::vector& FunctionsNotFound() const { - return functions_not_found_; - } - template std::function GetFunction(const char* function_name) { #if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__) @@ -73,10 +67,9 @@ static constexpr size_t kMaxFunctionsNotFound = 10; const void* function_address = dlsym(library_handle_, function_name); #endif // MinGW. - // We don't really need the full list of missing functions, - // just a few are enough. - if (!function_address && functions_not_found_.size() < kMaxFunctionsNotFound) - functions_not_found_.push_back(function_name); + CHECK(function_address) + << "Error: could not find function " << std::string(function_name) + << " in " << library_name_; return TypeParser::CreateFunction(function_address); } @@ -100,7 +93,6 @@ static constexpr size_t kMaxFunctionsNotFound = 10; private: void* library_handle_ = nullptr; std::string library_name_; - std::vector functions_not_found_; template struct TypeParser {}; diff --git a/ortools/xpress/environment.cc b/ortools/xpress/environment.cc index c7aad2d8b43..681840b72cd 100644 --- a/ortools/xpress/environment.cc +++ b/ortools/xpress/environment.cc @@ -95,7 +95,7 @@ std::function XPRSlpoptimize = nullptr; std::function XPRSmipoptimize = nullptr; -absl::Status LoadXpressFunctions(DynamicLibrary* xpress_dynamic_library) { +void LoadXpressFunctions(DynamicLibrary* xpress_dynamic_library) { // This was generated with the parse_header_xpress.py script. // See the comment at the top of the script. @@ -158,15 +158,6 @@ absl::Status LoadXpressFunctions(DynamicLibrary* xpress_dynamic_library) { xpress_dynamic_library->GetFunction(&XPRSaddcbmessage, "XPRSaddcbmessage"); xpress_dynamic_library->GetFunction(&XPRSlpoptimize, "XPRSlpoptimize"); xpress_dynamic_library->GetFunction(&XPRSmipoptimize, "XPRSmipoptimize"); - - - auto notFound = xpress_dynamic_library->FunctionsNotFound(); - if (!notFound.empty()) { - return absl::NotFoundError(absl::StrCat("Could not find the following functions (list may not be exhaustive). [", - absl::StrJoin(notFound, "', '"), - "]. Please make sure that your XPRESS install is up-to-date (>= 9.0.0).")); - } - return absl::OkStatus(); } void printXpressBanner(bool error) { @@ -184,17 +175,18 @@ std::vector XpressDynamicLibraryPotentialPaths() { std::vector potential_paths; // Look for libraries pointed by XPRESSDIR first. - const char* xpress_home_from_env = getenv("XPRESSDIR"); - if (xpress_home_from_env != nullptr) { + const char* xpressdir_from_env = getenv("XPRESSDIR"); + if (xpressdir_from_env != nullptr) { + LOG(INFO) << "Environment variable XPRESSDIR = " << xpressdir_from_env; #if defined(_MSC_VER) // Windows potential_paths.push_back( - absl::StrCat(xpress_home_from_env, "\\bin\\xprs.dll")); + absl::StrCat(xpressdir_from_env, "\\bin\\xprs.dll")); #elif defined(__APPLE__) // OS X potential_paths.push_back( - absl::StrCat(xpress_home_from_env, "/lib/libxprs.dylib")); + absl::StrCat(xpressdir_from_env, "/lib/libxprs.dylib")); #elif defined(__GNUC__) // Linux potential_paths.push_back( - absl::StrCat(xpress_home_from_env, "/lib/libxprs.so")); + absl::StrCat(xpressdir_from_env, "/lib/libxprs.so")); #else LOG(ERROR) << "OS Not recognized by xpress/environment.cc." << " You won't be able to use Xpress."; @@ -244,7 +236,9 @@ absl::Status LoadXpressDynamicLibrary(std::string& xpresspath) { } if (xpress_library.LibraryIsLoaded()) { - xpress_load_status = LoadXpressFunctions(&xpress_library); + LOG(INFO) << "Loading all Xpress functions"; + LoadXpressFunctions(&xpress_library); + xpress_load_status = absl::OkStatus(); } else { xpress_load_status = absl::NotFoundError( absl::StrCat("Could not find the Xpress shared library. Looked in: [",