Skip to content

return *this from the free-getter, member-setter property() overload - #1520

Open
kevinushey wants to merge 1 commit into
masterfrom
bugfix/module-property-return
Open

kevinushey wants to merge 1 commit into
masterfrom
bugfix/module-property-return

Conversation

@kevinushey

Copy link
Copy Markdown
Contributor

Fixes #1519.

The class_<T>::property() overload taking a free-function getter (PROP (*)(Class*)) and a member-function setter fell off the end without returning *this. That is undefined behavior; with Apple clang it compiles to a trap, so any module using the overload aborts the R session as soon as it is loaded. See #1519 for the reprex.

Changes:

  • inst/include/Rcpp/module/Module_Add_Property.h: add the missing return *this;.
  • inst/tinytest/cpp/Module.cpp: add a ModuleProperties class that exposes one property per property() overload (member, const member and free-function getters, combined with member and free-function setters). Only two of the nine overloads were exercised before.
  • inst/tinytest/test_module.R: set and read each read-write property, check that the read-only ones read the same value and reject assignment.

Verification:

Checklist

  • Code compiles correctly
  • R CMD check still passes all tests (module test files run locally as above; the change is a one-line header fix plus tests)
  • Preferably, new tests were added which fail without the change (without the fix, loading the test module traps)
  • Document the changes by file in ChangeLog

@eddelbuettel eddelbuettel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

Nice 'lines of tests and documentation' / 'lines of new code' ration too :)

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.

module property with a free-function getter and member setter crashes at module load

2 participants