On Sun, Nov 15, 2009 at 2:52 PM, Duncan Murdoch - murdoch at stats.uwo.ca
<+nabble+miller_2555+1412c7fca2.murdoch#stats.uwo.ca at spamgourmet.com>
wrote:
On 15/11/2009 1:41 PM, nabble.30.miller_2555 at spamgourmet.com 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:
NAMESPACE:
---------------------------------------------------
useDynLib("tstlib")
export( "ptest" )
ptest.R:
---------------------------------------------------
ptest <- function() { .Call("Rwrite", PACKAGE="tstlib");};
ptest.c:
---------------------------------------------------
#include <R.h>
void Rwrite() { printf("[%i] %s",12,"Hi"); }
ptest.R:
---------------------------------------------------
ptest <- function() { .Call("Rwrite", PACKAGE="tstlib");};
zzz.R:
---------------------------------------------------
.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).