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

Enhance is check for module object #381

Merged
merged 1 commit into from
Oct 15, 2015
Merged

Enhance is check for module object #381

merged 1 commit into from
Oct 15, 2015

Conversation

tqchen
Copy link
Contributor

@tqchen tqchen commented Oct 9, 2015

fix to #380

@eddelbuettel
Copy link
Member

That probably requires a reverse-dependency check but I am traveling right now and may not get to it for some time.

@tqchen
Copy link
Contributor Author

tqchen commented Oct 9, 2015

please take your time. we have applied a local specialization patch to our package for now. Thanks

@thirdwing
Copy link
Member

BTW, maybe you can add a simple test in https://github.com/RcppCore/Rcpp/tree/master/inst/unitTests/testRcppModule/src

@eddelbuettel
Copy link
Member

+1 for adding unit test support to this (or any, really) pull request.

@kevinushey
Copy link
Contributor

This does not seem like the right change. I think the only reason you're getting punted into the module method is because you haven't let Rcpp understand how to handle as / wrap.

Please read https://cran.r-project.org/web/packages/Rcpp/vignettes/Rcpp-extending.pdf for more information on how you can let Rcpp::as<T> and Rcpp::wrap understand how to interact with custom classes; I am guessing your problem will go away if you do this.

(I could be wrong -- but my understanding is that if you have the appropriate architecture set up, the as / wrap will dispatch / use your methods, and you're trying to use that plainly on your own user-defined class. The module methods there are basically fallback methods.)

@thirdwing
Copy link
Member

A very simple example to make things clear. Just use our RcppModuleWorld.

check_module is nothing but Rcpp::is<RcppModuleWorld>(x).

> m <- new(RcppModuleWorld)
> m
C++ object <0x2858180> of class 'RcppModuleWorld' <0x306a480>
> check_module(m)
[1] TRUE
> check_module(1)
Error: expecting an external pointer

If other things pass into this function, we will get a warning, since env.get(".cppclass") return a NULL.

@tqchen thought we need to check whether it is NULL. If it is NULL, we should return FALSE, not a warning.

@tqchen
Copy link
Contributor Author

tqchen commented Oct 9, 2015

I think @thirdwing explains my point. Ideally it would be great Rcpp::is<RcppModuleWorld> only return true or false. So we can use it to check parameters.

For example, we can use this to check if input parameter is a certain type, and give more friendly error message to the user.

void dosomething(Rcpp::List param_list) {
  for (size_t i = 0; i < param_list.size(); ++i) {
    if (!Rcpp::is<RcppModuleClassA>(param_list[i]))
        throw Rcpp::exception("The input  is expected to be list of RcppModuleClassA")
  }
}

@kevinushey
Copy link
Contributor

Thanks, it indeed looks like the RCPP_EXPOSED_CLASS is responsible for exposing as / wrap methods, hence where the dispatch is coming from. The PR looks fine to me, then.

@eddelbuettel
Copy link
Member

Agreed -- will merge now and launch a full reverse-dependency test. We can always revert should something bubble up (which we have no reason to expect).

eddelbuettel added a commit that referenced this pull request Oct 15, 2015
Enhance is check for module object
@eddelbuettel eddelbuettel merged commit 87cb728 into RcppCore:master Oct 15, 2015
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