"...git@developer.sourcefind.cn:tianlh/lightgbm-dcu.git" did not exist on "ed958eb2eb4655d8f67dcd749fa4339ce4c245e1"
Unverified Commit 8c335352 authored by OMOTO Tsukasa's avatar OMOTO Tsukasa Committed by GitHub
Browse files

Fix user locale settings (#2980)

This reverts commit 6b68967d (#2891) and fixes #2979.
parent 44a91201
/*!
* Copyright (c) 2020 Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*/
#ifndef LIGHTGBM_LOCALE_CONTEXT_H_
#define LIGHTGBM_LOCALE_CONTEXT_H_
#include <clocale>
#include <locale>
/*!
* Class to override the program global locale during this object lifetime.
* After the object is destroyed, the locale is returned to its original state.
*
* @warn This is not thread-safe.
*/
class LocaleContext {
public:
/*!
* Override the current program global locale during this object lifetime.
*
* @param target_locale override the locale to this locale setting.
* @warn This is not thread-safe.
* @note This doesn't override cout, cerr, etc.
*/
explicit LocaleContext(const char* target_locale = "C") {
std::locale::global(std::locale(target_locale));
}
/*!
* Restores the old global locale.
*/
~LocaleContext() {
std::locale::global(_saved_global_locale);
}
private:
std::locale _saved_global_locale; //!< Stores global locale at initialization.
};
#endif // LIGHTGBM_LOCALE_CONTEXT_H_
......@@ -13,7 +13,6 @@
#include <LightGBM/objective_function.h>
#include <LightGBM/prediction_early_stop.h>
#include <LightGBM/utils/common.h>
#include <LightGBM/utils/locale_context.h>
#include <LightGBM/utils/log.h>
#include <LightGBM/utils/openmp_wrapper.h>
#include <LightGBM/utils/random.h>
......@@ -1237,7 +1236,6 @@ int LGBM_BoosterCreateFromModelfile(
int* out_num_iterations,
BoosterHandle* out) {
API_BEGIN();
LocaleContext withLocaleContext("C");
auto ret = std::unique_ptr<Booster>(new Booster(filename));
*out_num_iterations = ret->GetBoosting()->GetCurrentIteration();
*out = ret.release();
......@@ -1249,7 +1247,6 @@ int LGBM_BoosterLoadModelFromString(
int* out_num_iterations,
BoosterHandle* out) {
API_BEGIN();
LocaleContext withLocaleContext("C");
auto ret = std::unique_ptr<Booster>(new Booster(nullptr));
ret->LoadModelFromString(model_str);
*out_num_iterations = ret->GetBoosting()->GetCurrentIteration();
......@@ -1674,7 +1671,6 @@ int LGBM_BoosterSaveModel(BoosterHandle handle,
int num_iteration,
const char* filename) {
API_BEGIN();
LocaleContext withLocaleContext("C");
Booster* ref_booster = reinterpret_cast<Booster*>(handle);
ref_booster->SaveModelToFile(start_iteration, num_iteration, filename);
API_END();
......@@ -1687,7 +1683,6 @@ int LGBM_BoosterSaveModelToString(BoosterHandle handle,
int64_t* out_len,
char* out_str) {
API_BEGIN();
LocaleContext withLocaleContext("C");
Booster* ref_booster = reinterpret_cast<Booster*>(handle);
std::string model = ref_booster->SaveModelToString(start_iteration, num_iteration);
*out_len = static_cast<int64_t>(model.size()) + 1;
......@@ -1704,7 +1699,6 @@ int LGBM_BoosterDumpModel(BoosterHandle handle,
int64_t* out_len,
char* out_str) {
API_BEGIN();
LocaleContext withLocaleContext("C");
Booster* ref_booster = reinterpret_cast<Booster*>(handle);
std::string model = ref_booster->DumpModel(start_iteration, num_iteration);
*out_len = static_cast<int64_t>(model.size()) + 1;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment