Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow inclusion in C programs #4608

Merged
merged 8 commits into from
Oct 5, 2021
27 changes: 22 additions & 5 deletions include/LightGBM/c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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. */
Expand All @@ -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_ */