Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abort on R type error if debugging #860

Merged
merged 4 commits into from
Jun 8, 2018
Merged

Conversation

jackwasey
Copy link
Contributor

Following discussion in #857 , this PR prints an error to standard error, and aborts, allowing a debugger to examine state leading up to the error, instead of dropping out of R. The assert macro didn't seem like the right tool, as it would never give an informative error message. The glibc assert macro calls abort, so I used it here, while checking for absence ofNDEBUG. The default build process in R is done with -DNDEBUG so this should not alter behavior for anyone who hasn't explicitly used -UNDEBUG, and therefore this should not impact any packages built for CRAN in the usual way.

There is no obvious way for me to add an automated test for this code, since it requires compiling with and without the NDEBUG flag set.

Rf_type2char(TYPEOF(x)),
Rf_type2char(RTYPE));
abort();
#elif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#else instead of #elif?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes... whoops. But it worked with clang, so I missed it.

@codecov-io
Copy link

codecov-io commented Jun 5, 2018

Codecov Report

Merging #860 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff           @@
##           master    #860   +/-   ##
======================================
  Coverage    90.3%   90.3%           
======================================
  Files          70      70           
  Lines        3261    3261           
======================================
  Hits         2945    2945           
  Misses        316     316
Impacted Files Coverage Δ
inst/include/Rcpp/r_cast.h 100% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e3c8558...e614d53. Read the comment docs.

@@ -67,9 +67,17 @@ namespace Rcpp {
default:
const char* fmt = "Not compatible with requested type: "
"[type=%s; target=%s].";
#ifndef NDEBUG
fprintf(stderr,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should that not be REprintf() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't aware of REprintf, made the change.

I used the following to test:

Rcpp::cppFunction('void type_err(IntegerVector iv) {}')
type_err("a")

Which aborts with the appropriate error message if I add -UNDEBUG in CXXFLAGS before compilation, otherwise gives normal Rcpp behavior.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. REprintf() is one of those gems hidden away in WRE which "they" to nag you on submission. You know, like 'no stdout, no abort, ...' ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants