You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Somewhat related to a recent post on R-devel, some users will still try to use Rf_error() in C++ code using Rcpp. However, (as is documented) C++ destructors won't run when a longjmp occurs in cases like this. For example:
#include <Rcpp.h>
using namespace Rcpp;
struct A {
A() { Rprintf("A()\n"); }
~A() { Rprintf("~A()\n"); }
};
// [[Rcpp::export]]
SEXP uhoh() {
A a;
Rf_error("Oops!");
}
/*** R
uhoh()
*/
In this example, ~A() is never printed.
We could consider masking the definition of Rf_error() in these contexts. For example, something like:
#define Rf_error(...) \
static_assert(false, "Use of Rf_error() in C++ contexts is unwise: consider using Rcpp::stop() instead.");
There might also be a way to provide our own definition of Rf_error() that "masks" the version provided by R, but I wasn't able to find something immediately obvious.
The text was updated successfully, but these errors were encountered:
Tough. It is a clear issue, and one that is a little tricky to explain / document.
I am little burned out from the recent transition dances for Rcpp, BH, and the still-ongoing one for RcppArmadillo. But if you want to drive a test across 2600 reverse depends, and then tangle with all packages that still call Rf_error ...
Is it worth it? Dunno. Should we maybe consider implementing Rf_error() in terms of Rcpp::stop() ?
Somewhat related to a recent post on R-devel, some users will still try to use
Rf_error()
in C++ code using Rcpp. However, (as is documented) C++ destructors won't run when a longjmp occurs in cases like this. For example:In this example,
~A()
is never printed.We could consider masking the definition of
Rf_error()
in these contexts. For example, something like:There might also be a way to provide our own definition of
Rf_error()
that "masks" the version provided by R, but I wasn't able to find something immediately obvious.The text was updated successfully, but these errors were encountered: