dump function is now memory safe
This commit is contained in:
parent
359889e3d6
commit
70df227689
@ -3,6 +3,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <sstream>
|
||||||
#include "xgboost_R.h"
|
#include "xgboost_R.h"
|
||||||
#include "wrapper/xgboost_wrapper.h"
|
#include "wrapper/xgboost_wrapper.h"
|
||||||
#include "src/utils/utils.h"
|
#include "src/utils/utils.h"
|
||||||
@ -280,11 +281,10 @@ extern "C" {
|
|||||||
asInteger(with_stats),
|
asInteger(with_stats),
|
||||||
&olen);
|
&olen);
|
||||||
SEXP out = PROTECT(allocVector(STRSXP, olen));
|
SEXP out = PROTECT(allocVector(STRSXP, olen));
|
||||||
char buffer [2000];
|
|
||||||
for (size_t i = 0; i < olen; ++i) {
|
for (size_t i = 0; i < olen; ++i) {
|
||||||
memset(buffer, 0, sizeof buffer);
|
stringstream stream;
|
||||||
sprintf (buffer, "booster[%u]:\n%s", static_cast<unsigned>(i), res[i]);
|
stream << "booster["<<i<<"]\n" << res[i];
|
||||||
SET_STRING_ELT(out, i, mkChar(buffer));
|
SET_STRING_ELT(out, i, mkChar(stream.str().c_str()));
|
||||||
}
|
}
|
||||||
_WrapperEnd();
|
_WrapperEnd();
|
||||||
UNPROTECT(1);
|
UNPROTECT(1);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user