Fix so that it works for 2.6 and 2.5

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10059 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Joseph Wang 2007-10-28 18:21:44 +00:00
commit 3b9574953c
3 changed files with 20 additions and 5 deletions

View file

@ -156,11 +156,13 @@ SWIG_FromCharPtrAndSize(const char* carray, size_t size)
{
SEXP t, c;
if (!carray) return R_NilValue;
RVERSION26(return Rf_mkCharEnc(carray, size));
RVERSIONPRE26(
PROTECT(t = allocVector(STRSXP, 1));
c = allocString(size);
strncpy(CHAR(c), carray, size);
SET_STRING_ELT(t, 0, c);
UNPROTECT(1);
UNPROTECT(1);)
return t;
}
}

View file

@ -6,10 +6,23 @@ extern "C" {
#endif
#include <Rdefines.h>
#include <Rversion.h>
#include <stdlib.h>
#undef length
#define SWIGR 1
#if R_VERSION >= R_Version(2,6,0)
#warning "R Swig currently fails on runtime for 2.6 and higher."
#warning "Contact maintainer if you would like to help fix"
#define VMAXTYPE void *
#define RVERSION26(x) x
#define RVERSIONPRE26(x)
#else
#define VMAXTYPE char *
#define RVERSION26(x)
#define RVERSIONPRE26(x) x
#endif
/*
This is mainly a way to avoid having lots of local variables that may
conflict with those in the routine.