"src/git@developer.sourcefind.cn:tianlh/lightgbm-dcu.git" did not exist on "2e962c779f0d4f44da46c5be9851604b9acb5708"
Unverified Commit f3037c18 authored by Drew Miller's avatar Drew Miller Committed by GitHub
Browse files

allow inclusion in C programs (#4608)

* allow inclusion in C programs

* adding documentation to macro

* Support for ANSI C, _Thread_local where available.

* fix macro for docs
parent e95d5ab8
...@@ -15,9 +15,16 @@ ...@@ -15,9 +15,16 @@
#include <LightGBM/export.h> #include <LightGBM/export.h>
#ifdef __cplusplus
#include <cstdint> #include <cstdint>
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#else
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#endif
typedef void* DatasetHandle; /*!< \brief Handle of dataset. */ typedef void* DatasetHandle; /*!< \brief Handle of dataset. */
...@@ -79,7 +86,7 @@ LIGHTGBM_C_EXPORT int LGBM_SampleIndices(int32_t num_total_row, ...@@ -79,7 +86,7 @@ LIGHTGBM_C_EXPORT int LGBM_SampleIndices(int32_t num_total_row,
void* out, void* out,
int32_t* out_len); int32_t* out_len);
// --- start Dataset interface /* --- start Dataset interface */
/*! /*!
* \brief Load dataset from file (like LightGBM CLI version does). * \brief Load dataset from file (like LightGBM CLI version does).
...@@ -424,7 +431,7 @@ LIGHTGBM_C_EXPORT int LGBM_DatasetGetNumFeature(DatasetHandle handle, ...@@ -424,7 +431,7 @@ LIGHTGBM_C_EXPORT int LGBM_DatasetGetNumFeature(DatasetHandle handle,
LIGHTGBM_C_EXPORT int LGBM_DatasetAddFeaturesFrom(DatasetHandle target, LIGHTGBM_C_EXPORT int LGBM_DatasetAddFeaturesFrom(DatasetHandle target,
DatasetHandle source); DatasetHandle source);
// --- start Booster interfaces /* --- start Booster interfaces */
/*! /*!
* \brief Get boolean representing whether booster is fitting linear trees. * \brief Get boolean representing whether booster is fitting linear trees.
...@@ -1321,7 +1328,17 @@ LIGHTGBM_C_EXPORT int LGBM_NetworkInitWithFunctions(int num_machines, ...@@ -1321,7 +1328,17 @@ LIGHTGBM_C_EXPORT int LGBM_NetworkInitWithFunctions(int num_machines,
void* reduce_scatter_ext_fun, void* reduce_scatter_ext_fun,
void* allgather_ext_fun); void* allgather_ext_fun);
#if defined(_MSC_VER) #if !defined(__cplusplus) && (!defined(__STDC__) || (__STDC_VERSION__ < 199901L))
#define INLINE_FUNCTION /*!< \brief inline specifier no-op in C using standards before C99. */
#else
#define INLINE_FUNCTION inline /*!< \brief Inline specifier. */
#endif
#if !defined(__cplusplus) && (!defined(__STDC__) || (__STDC_VERSION__ < 201112L))
#define THREAD_LOCAL /*!< \brief Thread local specifier no-op in C using standards before C11. */
#elif !defined(__cplusplus)
#define THREAD_LOCAL _Thread_local /*!< \brief Thread local specifier. */
#elif defined(_MSC_VER)
#define THREAD_LOCAL __declspec(thread) /*!< \brief Thread local specifier. */ #define THREAD_LOCAL __declspec(thread) /*!< \brief Thread local specifier. */
#else #else
#define THREAD_LOCAL thread_local /*!< \brief Thread local specifier. */ #define THREAD_LOCAL thread_local /*!< \brief Thread local specifier. */
...@@ -1340,9 +1357,9 @@ static char* LastErrorMsg() { static THREAD_LOCAL char err_msg[512] = "Everythin ...@@ -1340,9 +1357,9 @@ static char* LastErrorMsg() { static THREAD_LOCAL char err_msg[512] = "Everythin
* \brief Set string message of the last error. * \brief Set string message of the last error.
* \param msg Error message * \param msg Error message
*/ */
inline void LGBM_SetLastError(const char* msg) { INLINE_FUNCTION void LGBM_SetLastError(const char* msg) {
const int err_buf_len = 512; const int err_buf_len = 512;
snprintf(LastErrorMsg(), err_buf_len, "%s", msg); snprintf(LastErrorMsg(), err_buf_len, "%s", msg);
} }
#endif // LIGHTGBM_C_API_H_ #endif /* LIGHTGBM_C_API_H_ */
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