This commit is contained in:
Tianqi Chen 2015-07-06 20:07:04 -07:00
parent fd26f45208
commit 46342d4633
2 changed files with 8 additions and 6 deletions

View File

@ -11,7 +11,7 @@
#ifdef _MSC_VER #ifdef _MSC_VER
#include <windows.h> #include <windows.h>
#include <process.h> #include <process.h>
#include "../xgboost/utils.h" #include "./utils.h"
namespace xgboost { namespace xgboost {
namespace utils { namespace utils {
/*! \brief simple semaphore used for synchronization */ /*! \brief simple semaphore used for synchronization */

View File

@ -134,9 +134,11 @@ using namespace xgboost::wrapper;
* \brief every function starts with API_BEGIN(); and finishes with API_END(); * \brief every function starts with API_BEGIN(); and finishes with API_END();
* \param Finalize optionally put in a finalizer * \param Finalize optionally put in a finalizer
*/ */
#define API_END(Finalize) } catch(std::exception &e) { \ #define API_END_FINALIZE(Finalize) } catch(std::exception &e) { \
Finalize; return XGBHandleException(e); \ Finalize; return XGBHandleException(e); \
} return 0; } return 0;
/*! \brief API End with no finalization */
#define API_END() API_END_FINALIZE(;)
// do not use threadlocal on OSX since it is not always available // do not use threadlocal on OSX since it is not always available
#ifndef DISABLE_THREAD_LOCAL #ifndef DISABLE_THREAD_LOCAL
@ -217,7 +219,7 @@ int XGDMatrixCreateFromCSR(const bst_ulong *indptr,
} }
mat.info.info.num_row = nindptr - 1; mat.info.info.num_row = nindptr - 1;
*out = p_mat; *out = p_mat;
API_END(delete p_mat); API_END_FINALIZE(delete p_mat);
} }
int XGDMatrixCreateFromCSC(const bst_ulong *col_ptr, int XGDMatrixCreateFromCSC(const bst_ulong *col_ptr,
@ -258,7 +260,7 @@ int XGDMatrixCreateFromCSC(const bst_ulong *col_ptr,
mat.info.info.num_row = mat.row_ptr_.size() - 1; mat.info.info.num_row = mat.row_ptr_.size() - 1;
mat.info.info.num_col = static_cast<size_t>(ncol); mat.info.info.num_col = static_cast<size_t>(ncol);
*out = p_mat; *out = p_mat;
API_END(delete p_mat); API_END_FINALIZE(delete p_mat);
} }
int XGDMatrixCreateFromMat(const float *data, int XGDMatrixCreateFromMat(const float *data,
@ -289,7 +291,7 @@ int XGDMatrixCreateFromMat(const float *data,
mat.row_ptr_.push_back(mat.row_ptr_.back() + nelem); mat.row_ptr_.push_back(mat.row_ptr_.back() + nelem);
} }
*out = p_mat; *out = p_mat;
API_END(delete p_mat); API_END_FINALIZE(delete p_mat);
} }
int XGDMatrixSliceDMatrix(DMatrixHandle handle, int XGDMatrixSliceDMatrix(DMatrixHandle handle,
@ -340,7 +342,7 @@ int XGDMatrixSliceDMatrix(DMatrixHandle handle,
} }
} }
*out = p_ret; *out = p_ret;
API_END(delete p_ret); API_END_FINALIZE(delete p_ret);
} }
int XGDMatrixFree(DMatrixHandle handle) { int XGDMatrixFree(DMatrixHandle handle) {