diff options
Diffstat (limited to 'Examples/test-suite/namespace_typemap.i')
-rw-r--r-- | Examples/test-suite/namespace_typemap.i | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/Examples/test-suite/namespace_typemap.i b/Examples/test-suite/namespace_typemap.i index 9c74715f0..8636f432c 100644 --- a/Examples/test-suite/namespace_typemap.i +++ b/Examples/test-suite/namespace_typemap.i @@ -2,6 +2,7 @@ %module namespace_typemap %{ +#include <string.h> namespace test { /* A minimalistic string class */ class string_class { @@ -15,7 +16,7 @@ namespace test { strcpy(data,s); } ~string_class() { - if (data) delete [] data; + delete [] data; } char *c_str() { return data; @@ -84,7 +85,9 @@ namespace test { class string_class; #ifdef SWIGPYTHON %typemap(in) string_class * { - $1 = new string_class(SWIG_Python_str_AsChar($input)); + PyObject *bytes = NULL; + $1 = new string_class(SWIG_PyUnicode_AsUTF8AndSize($input, NULL, &bytes)); + Py_XDECREF(bytes); } %typemap(freearg) string_class * { delete $1; @@ -119,6 +122,18 @@ namespace test { delete $1; } #endif +#ifdef SWIGJAVASCRIPT + %fragment("SWIG_AsCharPtrAndSize"); + %typemap(in) string_class * { + char *data; + SWIG_AsCharPtrAndSize($input, &data, NULL, NULL); + $1 = new string_class(data); + free(data); + } + %typemap(freearg) string_class * { + delete $1; + } +#endif } %inline %{ |