change call for R to use mkCharLen where it exists (R versions >=

2.7.0).  This is necessary because later versions of R (>= 2.8.0)
depreciate creation of strings through vectors because this does not
allow R to use character caches


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12014 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Joseph Wang 2010-05-09 15:39:31 +00:00
commit 3d5d3a5bdb

View file

@ -162,9 +162,20 @@ SWIG_FromCharPtrAndSize(const char* carray, size_t size)
{
SEXP t, c;
if (!carray) return R_NilValue;
/* See R internals document 1.10.
MkCharLen was introduced in 2.7.0. Use that instead of hand
creating vector.
Starting in 2.8.0 creating strings via vectors was deprecated in
order to allow for use of CHARSXP caches. */
Rf_protect(t = Rf_allocVector(STRSXP, 1));
#if R_VERSION >= R_Version(2,7,0)
c = Rf_mkCharLen(carray, size);
#else
c = Rf_allocVector(CHARSXP, size);
strncpy((char *)CHAR(c), carray, size);
#endif
SET_STRING_ELT(t, 0, c);
Rf_unprotect(1);
return t;