From plummer at iarc.fr  Mon Jun 13 15:09:55 2005
From: plummer at iarc.fr (Martyn Plummer)
Date: Mon, 13 Jun 2005 15:09:55 +0200
Subject: [Rd] memory allocation problem under linux
In-Reply-To: <1118657534.42ad5bfecb192@posta.studio.unibo.it>
References: <1118652187.42ad471bd917f@posta.studio.unibo.it>
	<Pine.LNX.4.61.0506130947360.23218@gannet.stats>
	<1118657534.42ad5bfecb192@posta.studio.unibo.it>
Message-ID: <1118668195.4032.9.camel@seurat>

On Mon, 2005-06-13 at 12:12 +0200, antonio.dinarzo at studio.unibo.it
wrote:
> Scrive Prof Brian Ripley <ripley at stats.ox.ac.uk>:
> 
> > You keep on sending similar messages -- this is at least the third.  You 
> > need to find out where the segfault is occurring using gdb, and you have 
> > not told us.
> 
> Sorry for the repeated post (in 2 different mailing lists).
> Tnx for your suggestion. Now I think I've found the problem. Try this:
> ////file foo.c
> #include <R.h>
> int **box;
> void foo(){
>   int i;
>   box =   (int**)R_alloc(1,   sizeof(int *));
> }
> /////////////
> Compiled with R CMD SHLIB foo.c
> In R:
> >dyn.load("foo.so")
> >.C("foo")
> *Segmentation fault*
> The problem disappears when the declaration of 'box' comes inside the function
> foo... Is this a bug?

It gives you a hint about what the problem is. Your global variable
"box" is conflicting with another symbol.  I tracked this down to the
ncurses library, to which R is linked under Linux, but not Windows. 

[martyn at seurat ~]$ nm /usr/lib/libncurses.so | grep box -
07a6d036 T box

This explains why your problem is platform-specific.  You should declare
"box" to be static.

M.



[Rd] memory allocation problem under linux
Martyn Plummer