replace strdup - it is not portable
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10117 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
854f9a3ed3
commit
39ff2511cb
1 changed files with 22 additions and 11 deletions
|
|
@ -123,23 +123,24 @@ SWIG_AsCharPtrAndSize(SEXP obj, char** cptr, size_t* psize, int *alloc)
|
||||||
{
|
{
|
||||||
if (!cptr) return SWIG_TypeError;
|
if (!cptr) return SWIG_TypeError;
|
||||||
if (!Rf_isString(obj)) 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));
|
cstr = CHAR(STRING_ELT(obj, 0));
|
||||||
len = strlen(cstr);
|
len = strlen(cstr);
|
||||||
|
|
||||||
if (cptr) {
|
if (cptr) {
|
||||||
if (alloc) {
|
if (alloc) {
|
||||||
if (*alloc == SWIG_NEWOBJ)
|
if (*alloc == SWIG_NEWOBJ) {
|
||||||
{
|
*cptr = %new_copy_array(cstr, len + 1, char);
|
||||||
*cptr = %new_copy_array(cstr, len + 1, char);
|
*alloc = SWIG_NEWOBJ;
|
||||||
*alloc = SWIG_NEWOBJ;
|
} else {
|
||||||
}
|
*cptr = %reinterpret_cast(malloc(len+1), char *);
|
||||||
else {
|
*cptr = strcpy(*cptr, cstr);
|
||||||
*cptr = strdup(cstr);
|
*alloc = SWIG_OLDOBJ;
|
||||||
*alloc = SWIG_OLDOBJ;
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
*cptr = strdup(cstr);
|
*cptr = %reinterpret_cast(malloc(len+1), char *);
|
||||||
|
*cptr = strcpy(*cptr, cstr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (psize) *psize = len + 1;
|
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
|
# This is modified from the R header files
|
||||||
|
|
||||||
%fragment("SWIG_FromCharPtrAndSize","header")
|
%fragment("SWIG_FromCharPtrAndSize","header")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue