Fix missing include in SWIG typemap

This commit is contained in:
Seth R Johnson 2017-05-09 14:36:14 -04:00
commit c1258323b1
4 changed files with 35 additions and 17 deletions

View file

@ -5,6 +5,12 @@
* pointers as arrays. * pointers as arrays.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
#ifndef __cplusplus
// C uses free/calloc/malloc
%include "swigfragments.swg"
%fragment("<stdlib.h>");
#endif
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* %array_functions(TYPE,NAME) * %array_functions(TYPE,NAME)
* *

View file

@ -68,7 +68,7 @@ static jbyteArray SWIG_JavaArrayOutCDATA(JNIEnv *jenv, char *result, jsize sz) {
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* %cdata(TYPE [, NAME]) * %cdata(TYPE [, NAME])
* *
* Convert raw C data to a binary string. * Convert raw C data to a binary string.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
@ -107,6 +107,8 @@ SWIGCDATA cdata_##NAME(TYPE *ptr, int nelements);
%cdata(void); %cdata(void);
%fragment("<string.h>");
/* Memory move function. Due to multi-argument typemaps this appears to be wrapped as /* Memory move function. Due to multi-argument typemaps this appears to be wrapped as
void memmove(void *data, const char *s); */ void memmove(void *data, const char *s); */
void memmove(void *data, const void *indata, int inlen); void memmove(void *data, const void *indata, int inlen);

View file

@ -5,6 +5,12 @@
* pointer objects. * pointer objects.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
#ifndef __cplusplus
// C uses free/calloc/malloc
%include "swigfragments.swg"
%fragment("<stdlib.h>");
#endif
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* %pointer_class(type,name) * %pointer_class(type,name)
* *

View file

@ -442,6 +442,10 @@ namespace std {
* Default char * and C array typemaps * Default char * and C array typemaps
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
%fragment("<string.h>", "runtime") %{
#include <string.h>
%}
/* Set up the typemap for handling new return strings */ /* Set up the typemap for handling new return strings */
#ifdef __cplusplus #ifdef __cplusplus
@ -453,7 +457,7 @@ namespace std {
/* Default typemap for handling char * members */ /* Default typemap for handling char * members */
#ifdef __cplusplus #ifdef __cplusplus
%typemap(memberin) char * { %typemap(memberin,fragment="<string.h>") char * {
delete [] $1; delete [] $1;
if ($input) { if ($input) {
$1 = ($1_type) (new char[strlen((const char *)$input)+1]); $1 = ($1_type) (new char[strlen((const char *)$input)+1]);
@ -462,7 +466,7 @@ namespace std {
$1 = 0; $1 = 0;
} }
} }
%typemap(memberin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG) const char * { %typemap(memberin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG,fragment="<string.h>") const char * {
if ($input) { if ($input) {
$1 = ($1_type) (new char[strlen((const char *)$input)+1]); $1 = ($1_type) (new char[strlen((const char *)$input)+1]);
strcpy((char *)$1, (const char *)$input); strcpy((char *)$1, (const char *)$input);
@ -470,7 +474,7 @@ namespace std {
$1 = 0; $1 = 0;
} }
} }
%typemap(globalin) char * { %typemap(globalin,fragment="<string.h>") char * {
delete [] $1; delete [] $1;
if ($input) { if ($input) {
$1 = ($1_type) (new char[strlen((const char *)$input)+1]); $1 = ($1_type) (new char[strlen((const char *)$input)+1]);
@ -479,7 +483,7 @@ namespace std {
$1 = 0; $1 = 0;
} }
} }
%typemap(globalin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG) const char * { %typemap(globalin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG,fragment="<string.h>") const char * {
if ($input) { if ($input) {
$1 = ($1_type) (new char[strlen((const char *)$input)+1]); $1 = ($1_type) (new char[strlen((const char *)$input)+1]);
strcpy((char *)$1, (const char *)$input); strcpy((char *)$1, (const char *)$input);
@ -488,7 +492,7 @@ namespace std {
} }
} }
#else #else
%typemap(memberin) char * { %typemap(memberin,fragment="<string.h>") char * {
free($1); free($1);
if ($input) { if ($input) {
$1 = ($1_type) malloc(strlen((const char *)$input)+1); $1 = ($1_type) malloc(strlen((const char *)$input)+1);
@ -497,7 +501,7 @@ namespace std {
$1 = 0; $1 = 0;
} }
} }
%typemap(memberin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG) const char * { %typemap(memberin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG,fragment="<string.h>") const char * {
if ($input) { if ($input) {
$1 = ($1_type) malloc(strlen((const char *)$input)+1); $1 = ($1_type) malloc(strlen((const char *)$input)+1);
strcpy((char *)$1, (const char *)$input); strcpy((char *)$1, (const char *)$input);
@ -505,7 +509,7 @@ namespace std {
$1 = 0; $1 = 0;
} }
} }
%typemap(globalin) char * { %typemap(globalin,fragment="<string.h>") char * {
free($1); free($1);
if ($input) { if ($input) {
$1 = ($1_type) malloc(strlen((const char *)$input)+1); $1 = ($1_type) malloc(strlen((const char *)$input)+1);
@ -514,7 +518,7 @@ namespace std {
$1 = 0; $1 = 0;
} }
} }
%typemap(globalin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG) const char * { %typemap(globalin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG,fragment="<string.h>") const char * {
if ($input) { if ($input) {
$1 = ($1_type) malloc(strlen((const char *)$input)+1); $1 = ($1_type) malloc(strlen((const char *)$input)+1);
strcpy((char *)$1, (const char *)$input); strcpy((char *)$1, (const char *)$input);
@ -527,7 +531,7 @@ namespace std {
/* Character array handling */ /* Character array handling */
%typemap(memberin) char [ANY] { %typemap(memberin,fragment="<string.h>") char [ANY] {
if($input) { if($input) {
strncpy((char*)$1, (const char *)$input, $1_dim0-1); strncpy((char*)$1, (const char *)$input, $1_dim0-1);
$1[$1_dim0-1] = 0; $1[$1_dim0-1] = 0;
@ -536,7 +540,7 @@ namespace std {
} }
} }
%typemap(globalin) char [ANY] { %typemap(globalin,fragment="<string.h>") char [ANY] {
if($input) { if($input) {
strncpy((char*)$1, (const char *)$input, $1_dim0-1); strncpy((char*)$1, (const char *)$input, $1_dim0-1);
$1[$1_dim0-1] = 0; $1[$1_dim0-1] = 0;
@ -545,25 +549,25 @@ namespace std {
} }
} }
%typemap(memberin) char [] { %typemap(memberin,fragment="<string.h>") char [] {
if ($input) strcpy((char *)$1, (const char *)$input); if ($input) strcpy((char *)$1, (const char *)$input);
else $1[0] = 0; else $1[0] = 0;
} }
%typemap(globalin) char [] { %typemap(globalin,fragment="<string.h>") char [] {
if ($input) strcpy((char *)$1, (const char *)$input); if ($input) strcpy((char *)$1, (const char *)$input);
else $1[0] = 0; else $1[0] = 0;
} }
/* memberin/globalin typemap for arrays. */ /* memberin/globalin typemap for arrays. */
%typemap(memberin) SWIGTYPE [ANY] { %typemap(memberin,fragment="<string.h>") SWIGTYPE [ANY] {
size_t ii; size_t ii;
$1_basetype *b = ($1_basetype *) $1; $1_basetype *b = ($1_basetype *) $1;
for (ii = 0; ii < (size_t)$1_size; ii++) b[ii] = *(($1_basetype *) $input + ii); for (ii = 0; ii < (size_t)$1_size; ii++) b[ii] = *(($1_basetype *) $input + ii);
} }
%typemap(globalin) SWIGTYPE [ANY] { %typemap(globalin,fragment="<string.h>") SWIGTYPE [ANY] {
size_t ii; size_t ii;
$1_basetype *b = ($1_basetype *) $1; $1_basetype *b = ($1_basetype *) $1;
for (ii = 0; ii < (size_t)$1_size; ii++) b[ii] = *(($1_basetype *) $input + ii); for (ii = 0; ii < (size_t)$1_size; ii++) b[ii] = *(($1_basetype *) $input + ii);
@ -571,7 +575,7 @@ namespace std {
/* memberin/globalin typemap for double arrays. */ /* memberin/globalin typemap for double arrays. */
%typemap(memberin) SWIGTYPE [ANY][ANY] { %typemap(memberin,fragment="<string.h>") SWIGTYPE [ANY][ANY] {
$basetype (*inp)[$1_dim1] = ($basetype (*)[$1_dim1])($input); $basetype (*inp)[$1_dim1] = ($basetype (*)[$1_dim1])($input);
$basetype (*dest)[$1_dim1] = ($basetype (*)[$1_dim1])($1); $basetype (*dest)[$1_dim1] = ($basetype (*)[$1_dim1])($1);
size_t ii = 0; size_t ii = 0;
@ -583,7 +587,7 @@ namespace std {
} }
} }
%typemap(globalin) SWIGTYPE [ANY][ANY] { %typemap(globalin,fragment="<string.h>") SWIGTYPE [ANY][ANY] {
$basetype (*inp)[$1_dim1] = ($basetype (*)[$1_dim1])($input); $basetype (*inp)[$1_dim1] = ($basetype (*)[$1_dim1])($input);
$basetype (*dest)[$1_dim1] = ($basetype (*)[$1_dim1])($1); $basetype (*dest)[$1_dim1] = ($basetype (*)[$1_dim1])($1);
size_t ii = 0; size_t ii = 0;