mllg / checkmate

Fast and versatile argument checks
https://mllg.github.io/checkmate/
Other
261 stars 30 forks source link

C version of qassert doesn't really work with Rcpp #180

Closed mattfidler closed 4 years ago

mattfidler commented 4 years ago

This is because the default is to use Rf_error to signal errors. This causes a longjump and is unsafe with Rcpp; Could you provide a C++ capable interface by returning the error in some way?

mllg commented 4 years ago

I could return a SEXP: TRUE/LogicalVector(1) if everything is fine or a StringVector(1) with the error message.

Would this help?

mattfidler commented 4 years ago

Yes. If you do this I will add a pull request of how to use this with Rcpp. It won't add the Rcpp dependency but would be in the header. Is that OK?

mllg commented 4 years ago

Yes. If you do this I will add a pull request of how to use this with Rcpp. It won't add the Rcpp dependency but would be in the header. Is that OK?

Not sure if I understand this. In which header?

mattfidler commented 4 years ago

which header?

checkmate.h

In there a simple directive of

#if defined(__cplusplus)
#else
#endif

would allow qassert to work safely with Rcpp and C code using the same interface.

mattfidler commented 4 years ago

Well, looking at your code, it would be in checkmate_stub.c instead of the header.

mllg commented 4 years ago

Would #183 work for you?

mattfidler commented 4 years ago

Yes. Let me know when it arrives on CRAN so I can take out my hack :)