Re: [Rd] Segmentation faults on SEXP conversion

From: <>
Date: Sun, 15 Nov 2009 20:25:27 -0500

On Sun, Nov 15, 2009 at 2:52 PM, Duncan Murdoch - <> wrote:
> On 15/11/2009 1:41 PM, wrote:
> The "character" type in R corresponds to STRSXP in C, which is a vector of
> CHARSXPs.  So you need an extra step to get to the C string:
> const char * omsg = CHAR(STRING_ELT(msg, 0));
> Duncan Murdoch

Thank you for the suggestion. I have replaced the code as suggested, but I had attempted this conversion earlier. Unfortunately, I still receive the same segmentation fault (and backtrace). The underlying problem no longer appears to relate to type conversion. The following code represents the entirety of the extension's R and C code (and NAMESPACE file), and still causes the segmentation fault:


export( "ptest" )


ptest <- function() { .Call("Rwrite", PACKAGE="tstlib");};


#include <R.h>
void Rwrite() { printf("[%i] %s",12,"Hi"); }


ptest <- function() { .Call("Rwrite", PACKAGE="tstlib");};


.onLoad <- function(libname, pkgname)
.onUnload <- function(libpath) {

    library.dynam.unload("forkex", libpath)   }

This is just about the most simple example I can think of, and don't really know why it would segfault (if I change the interface in ptest.R above from .Call to .C, no segfault occurs). The following is the output from `R CMD SHLIB ptest.c`:

gcc -m64 -std=gnu99 -I/usr/include/R -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -c ptest.c -o ptest.o
gcc -m64 -std=gnu99 -shared -L/usr/local/lib64 -o ./ptest.o -L/usr/lib64/R/lib -lR mailing list Received on Mon 16 Nov 2009 - 01:30:43 GMT

This archive was generated by hypermail 2.2.0 : Mon 16 Nov 2009 - 02:50:25 GMT