[R] R_alloc problem (Mac OSX)

Dan Kelley Dan.Kelley at Dal.Ca
Mon Mar 13 20:09:58 CET 2006

Hello.  I'm having difficulties getting R_alloc() to work.

The test platform is a 64-bit Mac running R 2.2.1 installed via  
a .dmg file obtained from the R site.  Details are given below, in a  
level of detail that I hope is appropriate.  My eye was particularly  
drawn to line #2 in the gdb 'where' output, but line #1 seems  
sensible so I may just be displaying my ignorance by drawing  
attention to this.

Q: Can anyone advise as to how I should proceed?

$ R --version
R 2.2.1 (2005-12-20).
Copyright (C) 2005 R Development Core Team

$ gcc -g -o test5 test5.c -I/library/Frameworks/R.framework/Versions/ 
2.2/Resources/include/ -L/library/Frameworks/R.framework/Versions/2.2/ 
Resources/lib/ -lR -lm
/usr/bin/ld: warning multiple definitions of symbol _signgam
(lgamma.lo) definition of _signgam
(gamma9.o) definition of _signgam

$ gdb test5
GNU gdb 6.1-20040303 (Apple version gdb-413) (Wed May 18 10:17:02 GMT  
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and  
you are
welcome to change it and/or distribute copies of it under certain  
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for  
This GDB was configured as "powerpc-apple-darwin"...Reading symbols  
for shared libraries .... done

(gdb) run
Starting program: /Users/kelley/src/R-from-fortran/test5
Reading symbols for shared libraries .........+ done
about to call R_alloc(1,4)

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x0000000c
GetNewPage (node_class=1) at ../../../../R-2.2.1/src/main/memory.c:622
622     ../../../../R-2.2.1/src/main/memory.c: No such file or  
         in ../../../../R-2.2.1/src/main/memory.c
(gdb) where
#0  GetNewPage (node_class=1) at ../../../../R-2.2.1/src/main/ 
#1  0x00293d38 in Rf_allocVector (type=9, length=4) at ../../../../ 
#2  0x002932e8 in R_alloc (nelem=25167368, eltsize=1996)  
at ../../../../R-2.2.1/src/main/memory.c:1604
#3  0x00002ad0 in main () at test5.c:8
(gdb) list
617     in ../../../../R-2.2.1/src/main/memory.c
(gdb) file test5
Load new symbol table from "/Users/kelley/src/R-from-fortran/test5"?  
(y or n) y
Reading symbols from /Users/kelley/src/R-from-fortran/test5...done.
(gdb) list
1       #include <stdio.h>
2       #include <R.h>
3       int main()
4       {
5               int *t;
6               long int n = 1;
7               printf("about to call R_alloc(%d,%d)\n",n,sizeof(int));
8               t = (int *) R_alloc(n, sizeof(int));
9               printf("done\n");
10              return(0);
(gdb) src/R-from-fortran/

Dan E. Kelley, Associate Professor                phone:(902)494-1694
Oceanography Department, Dalhousie University       fax:(902)494-2885
Halifax, Nova Scotia                         mailto:Dan.Kelley at Dal.CA
Canada B3H 4J1   http://www.phys.ocean.dal.ca/~kelley/Kelley_Dan.html

More information about the R-help mailing list