Re: [R] segmetation fault and abort trap

From: Elizabeth Lawson <>
Date: Thu 29 Dec 2005 - 09:23:45 EST

I fixed the problem that I was having with the segmentation error and can load it with dyn.load.    

  I have one more problem now that I don't understand. I am using the .C in a for loop   for( i in 1:ncol(L.D)){
  new[,i]<-.C("mycode",as.double(L.D[,i]))   }    

  It crashes at different places each time I try to run it. So I tried   i<-1
  then running
new[,i]<-.C("mycode",as.double(L.D[,i]))   repeatedly.    

  It works for 3-6 times then will crash with the error   abort trap    

  What does this mean?
  Why does it work sometimes and not others?    

  Any suggestions?    


  Elizabeth Lawson
"Kort, Eric" <> wrote:   

Elizabeth Lawson Wrote:
> Hey,
> I don;t know if anyone has come across this error before...

More times than I care to remember.

> I am running R on the terminal of my MAC OS X 10.3.4 and I have
> C code and compiled it using
> R CMD SHLIB mycode.c
> There were no problems in compiling so I now have mycode.o and

A segmentation fault occurs when you try to access memory you didn't allocate for your use (see below). In other words, you are trying to use memory outside the segment allocated to your program (which, if allowed, could result in corrupting memory being used by other programs--which brings back unhappy memories of days gone by when an error in one program could crash the whole system). So these kinds of problems will not show up at compile time...only when you actually run the program.

> I used dyn.load("") and again, no problems. But when I try
> use the code .C("mycode",x) I get the error Segmentation fault and R
> down. Any ideas as to where my problem could be?

When I run into a segmentation fault, it is usually because I am trying to access an element of an array that is beyond what I have allocated, as in...

int main()
int *a;
a = (int*) malloc(3*sizeof(int));
printf("Fasten your seatbelts...\n");
a[4000] = 12;

One less obvious way this can happen is forgetting to initialize your arrays to the proper length before passing a reference to them to your C function.

If you still are having trouble, you could post a small snippet of code that recreates the error for us to examine.


This email message, including any attachments, is for the so...{{dropped}} mailing list PLEASE do read the posting guide! Received on Thu Dec 29 09:32:47 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:41:42 EST