diff --git a/SWIG/Examples/test-suite/li_cstring.i b/SWIG/Examples/test-suite/li_cstring.i index 40dbbcf8d..480ddf351 100644 --- a/SWIG/Examples/test-suite/li_cstring.i +++ b/SWIG/Examples/test-suite/li_cstring.i @@ -11,8 +11,13 @@ %cstring_mutable(char *out4, 32); %cstring_output_maxsize(char *out5, int max); %cstring_output_withsize(char *out6, int *size); +#ifdef __cplusplus %cstring_output_allocate(char **out7, delete [] $1); %cstring_output_allocate_size(char **out8, int *size, delete [] $1); +#else +%cstring_output_allocate(char **out7, free($1)); +%cstring_output_allocate_size(char **out8, int *size, free($1)); +#endif %inline %{ @@ -49,9 +54,10 @@ void test4(char *out4) { void test5(char *out5, int max) { int i; - for (i = strlen(out5); i < max; i++) { + for (i = 0; i < max; i++) { out5[i] = 'x'; } + out5[max]='\0'; } void test6(char *out6, int *size) { @@ -63,13 +69,21 @@ void test6(char *out6, int *size) { } void test7(char **out7) { +#ifdef __cplusplus *out7 = new char[64]; +#else + *out7 = malloc(64); +#endif strcat(*out7,"Hello world!"); } void test8(char **out8, int *sz) { int i; +#ifdef __cplusplus *out8 = new char[128]; +#else + *out8 = malloc(128); +#endif for (i = 0; i < 128; i++) { *out8[i] = (char) i; } diff --git a/SWIG/Examples/test-suite/python/Makefile.in b/SWIG/Examples/test-suite/python/Makefile.in index e1a43dc67..c68e4a858 100644 --- a/SWIG/Examples/test-suite/python/Makefile.in +++ b/SWIG/Examples/test-suite/python/Makefile.in @@ -24,6 +24,7 @@ CPP_TEST_CASES += \ input \ inplaceadd \ kwargs \ + li_cstring \ li_std_except \ li_std_vectora \ li_std_map \ @@ -39,6 +40,7 @@ CPP_TEST_CASES += \ C_TEST_CASES += \ file_test \ + li_cstring \ nondynamic # diff --git a/SWIG/Examples/test-suite/python/li_cstring_runme.py b/SWIG/Examples/test-suite/python/li_cstring_runme.py new file mode 100644 index 000000000..3c9a13f21 --- /dev/null +++ b/SWIG/Examples/test-suite/python/li_cstring_runme.py @@ -0,0 +1,5 @@ +from li_cstring import * + + +if test5(4) != 'xxxx': + raise RuntimeError