Commit 0ae51f14 authored by Guolin Ke's avatar Guolin Ke
Browse files

change static std::string to static char[]. (refer to...

change static std::string to static char[]. (refer to https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables)
parent 7287af3e
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
#include <cstdint> #include <cstdint>
#include <exception> #include <exception>
#include <stdexcept> #include <stdexcept>
#include <cstring>
#include <string> #include <string>
/*! /*!
* To avoid type conversion on large data, most of our expose interface support both for float_32 and float_64. * To avoid type conversion on large data, most of our expose interface support both for float_32 and float_64.
* Except following: * Except following:
...@@ -472,11 +474,10 @@ SampleFromOneColumn(const std::vector<std::pair<int, double>>& data, const std:: ...@@ -472,11 +474,10 @@ SampleFromOneColumn(const std::vector<std::pair<int, double>>& data, const std::
// exception handle and error msg // exception handle and error msg
static char* LastErrorMsg() { static thread_local char err_msg[512] = "Everything is fine"; return err_msg; }
static std::string& LastErrorMsg() { static thread_local std::string err_msg("Everything is fine"); return err_msg; }
inline void LGBM_SetLastError(const char* msg) { inline void LGBM_SetLastError(const char* msg) {
LastErrorMsg() = msg; std::strcpy(LastErrorMsg(), msg);
} }
inline int LGBM_APIHandleException(const std::exception& ex) { inline int LGBM_APIHandleException(const std::exception& ex) {
......
...@@ -201,7 +201,7 @@ private: ...@@ -201,7 +201,7 @@ private:
using namespace LightGBM; using namespace LightGBM;
DllExport const char* LGBM_GetLastError() { DllExport const char* LGBM_GetLastError() {
return LastErrorMsg().c_str(); return LastErrorMsg();
} }
DllExport int LGBM_CreateDatasetFromFile(const char* filename, DllExport int LGBM_CreateDatasetFromFile(const char* filename,
......
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