From a0e21e82ca112624ed2ab588424dec022e1e6a5a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 28 Apr 2012 14:29:23 +0000 Subject: [PATCH] char **STRING_ARRAY typemaps fixed to handle null pointers git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13021 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++ .../java/java_lib_various_runme.java | 5 ++ Lib/java/various.i | 48 +++++++++++-------- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index a2ebf35f9..f3cb1de21 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -11,3 +11,7 @@ Version 2.0.6 (in progress) 2012-04-28: wsfulton [Python] Fix compilation errors when wrapping STL containers on Mac OSX 64 bit. +2012-04-28: wsfulton + [Java] Patch 3521811 from Leo Davis - char **STRING_ARRAY typemaps fixed to handle + null pointers. + diff --git a/Examples/test-suite/java/java_lib_various_runme.java b/Examples/test-suite/java/java_lib_various_runme.java index ab54aced8..203a30ec2 100644 --- a/Examples/test-suite/java/java_lib_various_runme.java +++ b/Examples/test-suite/java/java_lib_various_runme.java @@ -45,6 +45,11 @@ public class java_lib_various_runme { if ( !langs[i].equals(newLangs[i]) ) throw new RuntimeException("Languages verify failed " + i + " " + langs[i] + "|" + newLangs[i]); + // STRING_ARRAY null + java_lib_various.setLanguages(null); + if (java_lib_various.getLanguages() != null) + throw new RuntimeException("languages should be null"); + // STRING_RET test { String stringOutArray[] = { "" }; diff --git a/Lib/java/various.i b/Lib/java/various.i index 9e7cf29ca..71569ca32 100644 --- a/Lib/java/various.i +++ b/Lib/java/various.i @@ -23,7 +23,8 @@ %typemap(jtype) char **STRING_ARRAY "String[]" %typemap(jstype) char **STRING_ARRAY "String[]" %typemap(in) char **STRING_ARRAY (jint size) { - int i = 0; + int i = 0; + if ($input) { size = JCALL1(GetArrayLength, jenv, $input); #ifdef __cplusplus $1 = new char*[size+1]; @@ -31,51 +32,56 @@ $1 = (char **)calloc(size+1, sizeof(char *)); #endif for (i = 0; i