"R-package/vscode:/vscode.git/clone" did not exist on "97ca38d1db904c9daa88f3ded2259cc9f91edf04"
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 @@
#include <LightGBM/export.h>
#ifdef __cplusplus
#include <cstdint>
#include <cstdio>
#include <cstring>
#else
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#endif
typedef void* DatasetHandle; /*!< \brief Handle of dataset. */
......@@ -79,7 +86,7 @@ LIGHTGBM_C_EXPORT int LGBM_SampleIndices(int32_t num_total_row,
void* out,
int32_t* out_len);
// --- start Dataset interface
/* --- start Dataset interface */
/*!
* \brief Load dataset from file (like LightGBM CLI version does).
......@@ -424,7 +431,7 @@ LIGHTGBM_C_EXPORT int LGBM_DatasetGetNumFeature(DatasetHandle handle,
LIGHTGBM_C_EXPORT int LGBM_DatasetAddFeaturesFrom(DatasetHandle target,
DatasetHandle source);
// --- start Booster interfaces
/* --- start Booster interfaces */
/*!
* \brief Get boolean representing whether booster is fitting linear trees.
......@@ -1321,7 +1328,17 @@ LIGHTGBM_C_EXPORT int LGBM_NetworkInitWithFunctions(int num_machines,
void* reduce_scatter_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. */
#else
#define THREAD_LOCAL thread_local /*!< \brief Thread local specifier. */
......@@ -1340,9 +1357,9 @@ static char* LastErrorMsg() { static THREAD_LOCAL char err_msg[512] = "Everythin
* \brief Set string message of the last error.
* \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;
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