From 39ff2511cb2aa1a46b41a9d39a108cf86c4a710b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 12 Nov 2007 22:14:22 +0000 Subject: [PATCH] replace strdup - it is not portable git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10117 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/r/rfragments.swg | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/Lib/r/rfragments.swg b/Lib/r/rfragments.swg index 5d8455cf3..dcc77b402 100644 --- a/Lib/r/rfragments.swg +++ b/Lib/r/rfragments.swg @@ -123,23 +123,24 @@ SWIG_AsCharPtrAndSize(SEXP obj, char** cptr, size_t* psize, int *alloc) { if (!cptr) return SWIG_TypeError; if (!Rf_isString(obj)) return SWIG_TypeError; - const char *cstr; int len; + const char *cstr; + int len; cstr = CHAR(STRING_ELT(obj, 0)); len = strlen(cstr); if (cptr) { if (alloc) { - if (*alloc == SWIG_NEWOBJ) - { - *cptr = %new_copy_array(cstr, len + 1, char); - *alloc = SWIG_NEWOBJ; - } - else { - *cptr = strdup(cstr); - *alloc = SWIG_OLDOBJ; - } + if (*alloc == SWIG_NEWOBJ) { + *cptr = %new_copy_array(cstr, len + 1, char); + *alloc = SWIG_NEWOBJ; + } else { + *cptr = %reinterpret_cast(malloc(len+1), char *); + *cptr = strcpy(*cptr, cstr); + *alloc = SWIG_OLDOBJ; + } } else { - *cptr = strdup(cstr); + *cptr = %reinterpret_cast(malloc(len+1), char *); + *cptr = strcpy(*cptr, cstr); } } if (psize) *psize = len + 1; @@ -147,6 +148,16 @@ SWIG_AsCharPtrAndSize(SEXP obj, char** cptr, size_t* psize, int *alloc) } } +%fragment("SWIG_strdup","header") +{ +SWIGINTERN char * +SWIG_strdup(const char *str) +{ + char *newstr = %reinterpret_cast(malloc(strlen(str)), char *); + return strcpy(newstr, str); +} +} + # This is modified from the R header files %fragment("SWIG_FromCharPtrAndSize","header")