Skip to content

Memory error in assigning int literal to NumericVector #146

@kevinushey

Description

@kevinushey

Ie:

#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
NumericVector test() {
  NumericVector m(1);
  m = 1;
  return m;
}

/*** R
gctorture(TRUE)
test()
gctorture(FALSE)
*/

produces the exception:

Error in test() : unimplemented type 'double' in 'coerceToReal'

I very strongly suspect this is the same error reported a long time back in http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2011-June/002545.html.

Definitely, this code is an example of something you shouldn't do, but Rcpp tries to be helpful and make it work anyway.

I imagine the bug is due to the code here, in vector/Vector.h:

// anything else
template <typename T>
inline void assign_object( const T& x, traits::false_type ) {
    Storage::set__( r_cast<RTYPE>( wrap(x) ) ) ;

Because the wrap(x)-ed object is not protected, it gets cleaned up before r_cast does its work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions