<div dir="ltr">One thing you can do is start with a little test case and run multiple times it to see if the segfault is really coming from where you think it is. <div><br></div><div>/*  test.cpp */</div><div><div>#include <Rcpp.h></div>
<div>using namespace Rcpp;</div><div><br></div><div>// [[Rcpp::export]]</div><div>List entryexitclock( SEXP xts_obj_,int ent_col, int exit_col, double clock_limit, int init_pos) {</div><div>  // function takes in xts_obj_ (an xts object from R) and converts to a NumericMatrix</div>
<div>  Rcpp::NumericMatrix x(xts_obj_);</div><div>  // Get the index and call v</div><div>  DatetimeVector v(NumericVector(RObject(xts_obj_).attr("index")));</div><div>  // The dimensions of rtn_xts are extracted</div>
<div>  int nr = x.nrow();</div><div>  List l;</div><div>  return (l);</div><div>}</div></div><div><br></div><div>Then on the R side you can test it out</div><div><div>library(Rcpp)</div><div><div>library(xts)</div></div><div>
sourceCpp("test.cpp")</div></div><div><div><div>n <- 10000</div></div><div>k <- xts(as.numeric(1:n), Sys.time()+1:n)<br></div></div><div><div>res <- lapply(1:10000, function(z) entryexitclock(k, 12, 12, 60*60,0))</div>
</div><div><br></div><div>This code does not seem to segfault for me using R 2.15.3 on Ubuntu with Rcpp 0.10.4. Does it segfault for you?</div><div><br></div><div>If I were you I would keep adding code to the test example till it segfaults reliably. If you do this one line at a time you will have a good idea of which line is causing the segfault. Usually the "user error" becomes apparent :).  If you are unsure you could winnow down the test case to a small reproducible  test case that crashes reliably and then post it to the list.</div>
<div><br></div><div>Regards</div><div>Sameer</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Feb 20, 2014 at 9:50 AM, Hideyoshi Maeda <span dir="ltr"><<a href="mailto:hideyoshi.maeda@gmail.com" target="_blank">hideyoshi.maeda@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi I am trying to run a function I created in Rcpp, which is then sourced/compiled and executed in R.<br>
<br>
The function is called “entryexitclock”.<br>
<br>
and starts off as follows:<br>
<br>
#include <Rcpp.h><br>
using namespace Rcpp;<br>
<br>
// [[Rcpp::export]]<br>
List entryexitclock( SEXP xts_obj_,int ent_col, int exit_col, double clock_limit, int init_pos) {<br>
  // function takes in xts_obj_ (an xts object from R) and converts to a NumericMatrix<br>
  Rcpp::NumericMatrix x(xts_obj_);<br>
  // Get the index and call v<br>
  DatetimeVector v(NumericVector(RObject(xts_obj_).attr("index")));<br>
  // The dimensions of rtn_xts are extracted<br>
  int nr = x.nrow();<br>
<br>
There is more code but I’m starting to doubt if its related to the rest of the code. I have a feeling it might be my use of SEXP but I’m not sure...<br>
<br>
The compilation works fine, however “sometimes” the code works and sometimes the code doesn’t…<br>
<br>
The error when it doesn't is as follows:<br>
<br>
<br>
 *** caught segfault ***<br>
address 0x11a9783c8, cause 'memory not mapped'<br>
<br>
Traceback:<br>
 1: .Primitive(".Call")(<pointer: 0x1044dde70>, xts_obj_, ent_col,     exit_col, clock_limit, init_pos)<br>
 2: entryexitclock(k, 11, 12, 60 * 60, 0)<br>
<br>
Possible actions:<br>
1: abort (with core dump, if enabled)<br>
2: normal R exit<br>
3: exit R without saving workspace<br>
4: exit R saving workspace<br>
<br>
Any suggestions as to what I can do to make sure that this function works every time rather than just sometimes?<br>
<br>
HLM<br>
<br>
<br>
<br>
_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
</blockquote></div><br></div>