From 98618646f66639ddc841de388fdec216f5845f20 Mon Sep 17 00:00:00 2001 From: tqchen Date: Thu, 26 Mar 2015 16:43:01 -0700 Subject: [PATCH] bugfix booster.check --- R-package/R/utils.R | 8 ++++++-- R-package/src/xgboost_R.cpp | 3 +++ R-package/src/xgboost_R.h | 6 ++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/R-package/R/utils.R b/R-package/R/utils.R index 9674ae9be..3c1ffdd20 100644 --- a/R-package/R/utils.R +++ b/R-package/R/utils.R @@ -87,8 +87,12 @@ xgb.handleToBooster <- function(handle) # Check whether an xgb.Booster object is complete xgb.Booster.check <- function(bst, saveraw = TRUE) { - if (is.null(bst$handle)) { - bst$handle <- xgb.load(bst$raw) + isnull <- is.null(bst$handle) + if (!isnull) { + isnull <- .Call("XGCheckNullPtr_R", bst$handle, PACKAGE="xgboost") + } + if (isnull) { + bst$handle <- xgb.Booster(modelfile = bst$raw) } else { if (is.null(bst$raw) && saveraw) bst$raw <- xgb.save.raw(bst$handle) diff --git a/R-package/src/xgboost_R.cpp b/R-package/src/xgboost_R.cpp index 315b6c2c1..a2ca9536f 100644 --- a/R-package/src/xgboost_R.cpp +++ b/R-package/src/xgboost_R.cpp @@ -59,6 +59,9 @@ inline void _WrapperEnd(void) { } extern "C" { + SEXP XGCheckNullPtr_R(SEXP handle) { + return ScalarLogical(R_ExternalPtrAddr(handle) == NULL); + } void _DMatrixFinalizer(SEXP ext) { if (R_ExternalPtrAddr(ext) == NULL) return; XGDMatrixFree(R_ExternalPtrAddr(ext)); diff --git a/R-package/src/xgboost_R.h b/R-package/src/xgboost_R.h index a86e85ffa..61b84a80e 100644 --- a/R-package/src/xgboost_R.h +++ b/R-package/src/xgboost_R.h @@ -11,6 +11,12 @@ extern "C" { } extern "C" { + /*! + * \brief check whether a handle is NULL + * \param handle + * \return whether it is null ptr + */ + SEXP XGCheckNullPtr_R(SEXP handle); /*! * \brief load a data matrix * \param fname name of the content