Handle UTF-8 paths correctly on Windows platform (#9443)
* Fix round-trip serialization with UTF-8 paths * Add compiler version check * Add comment to C API functions * Add Python tests * [CI] Updatre MacOS deployment target * Use std::filesystem instead of dmlc::TemporaryDirectory
This commit is contained in:
committed by
GitHub
parent
97fd5207dd
commit
7ce090e775
@@ -8,10 +8,11 @@
|
||||
#include <xgboost/learner.h>
|
||||
#include <xgboost/version_config.h>
|
||||
|
||||
#include <array> // for array
|
||||
#include <cstddef> // std::size_t
|
||||
#include <limits> // std::numeric_limits
|
||||
#include <string> // std::string
|
||||
#include <array> // for array
|
||||
#include <cstddef> // std::size_t
|
||||
#include <filesystem> // std::filesystem
|
||||
#include <limits> // std::numeric_limits
|
||||
#include <string> // std::string
|
||||
#include <vector>
|
||||
|
||||
#include "../../../src/c_api/c_api_error.h"
|
||||
@@ -162,7 +163,7 @@ TEST(CAPI, ConfigIO) {
|
||||
TEST(CAPI, JsonModelIO) {
|
||||
size_t constexpr kRows = 10;
|
||||
size_t constexpr kCols = 10;
|
||||
dmlc::TemporaryDirectory tempdir;
|
||||
auto tempdir = std::filesystem::temp_directory_path();
|
||||
|
||||
auto p_dmat = RandomDataGenerator(kRows, kCols, 0).GenerateDMatrix();
|
||||
std::vector<std::shared_ptr<DMatrix>> mat {p_dmat};
|
||||
@@ -178,19 +179,19 @@ TEST(CAPI, JsonModelIO) {
|
||||
learner->UpdateOneIter(0, p_dmat);
|
||||
BoosterHandle handle = learner.get();
|
||||
|
||||
std::string modelfile_0 = tempdir.path + "/model_0.json";
|
||||
XGBoosterSaveModel(handle, modelfile_0.c_str());
|
||||
XGBoosterLoadModel(handle, modelfile_0.c_str());
|
||||
auto modelfile_0 = tempdir / std::filesystem::u8path(u8"모델_0.json");
|
||||
XGBoosterSaveModel(handle, modelfile_0.u8string().c_str());
|
||||
XGBoosterLoadModel(handle, modelfile_0.u8string().c_str());
|
||||
|
||||
bst_ulong num_feature {0};
|
||||
ASSERT_EQ(XGBoosterGetNumFeature(handle, &num_feature), 0);
|
||||
ASSERT_EQ(num_feature, kCols);
|
||||
|
||||
std::string modelfile_1 = tempdir.path + "/model_1.json";
|
||||
XGBoosterSaveModel(handle, modelfile_1.c_str());
|
||||
auto modelfile_1 = tempdir / "model_1.json";
|
||||
XGBoosterSaveModel(handle, modelfile_1.u8string().c_str());
|
||||
|
||||
auto model_str_0 = common::LoadSequentialFile(modelfile_0);
|
||||
auto model_str_1 = common::LoadSequentialFile(modelfile_1);
|
||||
auto model_str_0 = common::LoadSequentialFile(modelfile_0.u8string());
|
||||
auto model_str_1 = common::LoadSequentialFile(modelfile_1.u8string());
|
||||
|
||||
ASSERT_EQ(model_str_0.front(), '{');
|
||||
ASSERT_EQ(model_str_0, model_str_1);
|
||||
|
||||
Reference in New Issue
Block a user