Treelite
c_api_error.cc
Go to the documentation of this file.
1 
8 #include <treelite/c_api_error.h>
9 #include <treelite/version.h>
10 #include <string>
11 #include <sstream>
12 
13 // Stringify an integer macro constant
14 #define STR_IMPL_(x) #x
15 #define STR(x) STR_IMPL_(x)
16 
17 namespace {
18 
19 struct TreeliteAPIErrorEntry {
20  std::string last_error;
21  std::string version_str;
22 };
23 
24 using TreeliteAPIErrorStore = treelite::ThreadLocalStore<TreeliteAPIErrorEntry>;
25 
26 } // anonymous namespace
27 
28 const char* TreeliteGetLastError() {
29  return TreeliteAPIErrorStore::Get()->last_error.c_str();
30 }
31 
32 void TreeliteAPISetLastError(const char* msg) {
33  TreeliteAPIErrorStore::Get()->last_error = msg;
34 }
35 
37  std::ostringstream oss;
38  oss << TREELITE_VER_MAJOR << "." << TREELITE_VER_MINOR << "." << TREELITE_VER_PATCH;
39  std::string& version_str = TreeliteAPIErrorStore::Get()->version_str;
40  version_str = oss.str();
41  return version_str.c_str();
42 }
43 
44 const char* TREELITE_VERSION = "TREELITE_VERSION_" STR(TREELITE_VER_MAJOR) "."
45  STR(TREELITE_VER_MINOR) "." STR(TREELITE_VER_PATCH);
const char * TreeliteGetLastError()
display last error; can be called by multiple threads Note. Each thread will get the last error occur...
Definition: c_api_error.cc:28
Helper class for thread-local storage.
Error handling for C API.
const char * TreeliteQueryTreeliteVersion()
Get the version string for the Treelite library.
Definition: c_api_error.cc:36
void TreeliteAPISetLastError(const char *msg)
Set the last error message needed by C API.
Definition: c_api_error.cc:32
A thread-local storage.
Definition: thread_local.h:17