Skip to content
Prev 2653 / 10988 Next

[Rcpp-devel] wrap returned pointer to class

Hi!

To answer my question: The issue was with constness of the pointer (there are a lot of variations of const pointers, saying wif the address or the object is const, but never got right behind that declaration mess...). So what did it in the end was to declare a wrap function which wraps the type B* const&, i.e. a declaration and definition of

template <> SEXP wrap( B* const& )

in between of RcppCommon.h and Rcpp.h and another declaration of

  template <>
  SEXP wrap( B* const& mb ) {
    return XPtr<B>(mb, false);
  }

did the job. BTW, shouldn't this be a behavior which is enabled by default for all pointers?

Concerning the bug: Just try to wrap a function taking a char as its argument. On my platform this has size 1 (one byte), while const char* has size 5 (larger than 1 byte). The respective automatic const char* -> char conversion then fails. Declaring this:

  template <>
  char as(SEXP s) {
    std::string str = as<std::string>(s);
    char c;
    std::strcpy( &c, str.c_str() );
    return c;
  }

cures the problem for me.

Just as a side note: Is it thinkable to enhance Boost.Python to handle Python and R? If Rcpp and Boost.Python would be source compatible *all* stuff written for Boost.Python would become immediately available to R and vice versa...

Cheers,

Sebastian

Am 01.08.2011 um 18:26 schrieb Dirk Eddelbuettel: