[Rcpp-devel] Segfaults when declaring Vector types
Patrick Ye
ye.patrick at gmail.com
Thu Apr 14 10:27:36 CEST 2011
Hi all,
I'm completely new to R and Rcpp, and I thought I'd just make a simple
program to see how Rcpp works. Here is the code:
<code>
#include <Rcpp.h>
#include <cstdio>
#include <cstdlib>
#include <iostream>
RcppExport void get_weights(int num_of_numbers, double* numbers);
RcppExport void get_weights(int num_of_numbers, double* numbers)
{
std::cerr << "--------" << num_of_numbers << "--------------\n";
Rcpp::NumericVector vec(1);
}
int main(int argc, char* argv[])
{
int num_of_numbers = argc - 1;
double* numbers = new double[num_of_numbers];
for(int i = 1; i < argc; ++i)
{
numbers[i-1] = atof(argv[i]);
std::cerr << numbers[i-1] << "\n";
}
get_weights(num_of_numbers, numbers);
return 0;
}
</code>
I can compile and link this code without any problems. However, when I run
it, I get a segfault in
get_weights. I traced the segfault using gdb, and the problem sees to come
from this:
<code>
(gdb) run 1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 7
Starting program: /home/patricky/tmp/stl 1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4
5 6 7
[Thread debugging using libthread_db enabled]
1
2
3
4
5
6
7
1
2
3
4
5
6
7
1
2
3
4
5
6
7
--------21--------------
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6c3ed70 in ?? () from /usr/lib64/R/lib/libR.so
(gdb) up
#1 0x00007ffff6c4049b in Rf_allocVector () from /usr/lib64/R/lib/libR.so
(gdb)
#2 0x0000000000401814 in Vector (this=0x7fffffffdf80, size=@0x7fffffffdf9c)
at
/usr/share/lib/R/x86_64-pc-linux-gnu-library/2.12/Rcpp/include/Rcpp/vector/Vector.h:130
130 RObject::setSEXP( Rf_allocVector( RTYPE, size) ) ;
</code>
I've rather stumped at this problem, and would appreciate any help that you
guys can provide.
Thanks a lot.
Patrick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20110414/1ec1e7f7/attachment.htm>
More information about the Rcpp-devel
mailing list