[R-package] remove pre-allocated call_state in C++ calls #4244
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is another step towards #3016.
As of #4155 and #4163, the R package use
.Call()
to call routines from the C++ library. Currently, an integer calledcall_state
is initialized on the R side before each such call, its value is manipulated during the call, and its value is returned by each call. Initializing this integer and passing it around is unnecessary, because nothing is done with it on the R side after the call completes. All uses of.Call()
in the R package (except in calls toLGBM_GetLastError_R
) modify their inputs by reference and do not return anything.This PR proposes simplifying the R package and removing unnecessary memory usage and computation by removing the
call_state
concept. Instead, the functions defined in https://github.com/microsoft/LightGBM/blob/b27dcfa48f76e77c9e5033dcdefc1f3a76d99c8b/R-package/src/lightgbm_R.h are converted to return aSEXP
(R's built-in type for passing data between R and C). This is initialized on the C++ side.Notes for Reviewers
If you want to learn more about the R
SEXP
object, see https://cran.r-project.org/doc/manuals/r-release/R-ints.html#SEXPs.