summaryrefslogtreecommitdiff
path: root/Lib/java
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/java')
-rw-r--r--Lib/java/director.swg4
-rw-r--r--Lib/java/std_string.i6
2 files changed, 8 insertions, 2 deletions
diff --git a/Lib/java/director.swg b/Lib/java/director.swg
index 7f0fd3933..24460676f 100644
--- a/Lib/java/director.swg
+++ b/Lib/java/director.swg
@@ -383,6 +383,10 @@ namespace Swig {
class LocalRefGuard {
JNIEnv* jenv_;
jobject jobj_;
+
+ // non-copyable
+ LocalRefGuard(const LocalRefGuard &);
+ LocalRefGuard &operator=(const LocalRefGuard &);
public:
LocalRefGuard(JNIEnv* jenv, jobject jobj): jenv_(jenv), jobj_(jobj) {}
~LocalRefGuard() { if (jobj_) jenv_->DeleteLocalRef(jobj_); }
diff --git a/Lib/java/std_string.i b/Lib/java/std_string.i
index 5ad7d30bc..322d0da12 100644
--- a/Lib/java/std_string.i
+++ b/Lib/java/std_string.i
@@ -49,7 +49,8 @@ class string;
jenv->ReleaseStringUTFChars($input, $1_pstr); %}
%typemap(directorin,descriptor="Ljava/lang/String;") string
-%{ $input = jenv->NewStringUTF($1.c_str()); %}
+%{ $input = jenv->NewStringUTF($1.c_str());
+ Swig::LocalRefGuard refGuard_$input(jenv, $input); %}
%typemap(out) string
%{ $result = jenv->NewStringUTF($1.c_str()); %}
@@ -98,7 +99,8 @@ class string;
jenv->ReleaseStringUTFChars($input, $1_pstr); %}
%typemap(directorin,descriptor="Ljava/lang/String;") const string &
-%{ $input = jenv->NewStringUTF($1.c_str()); %}
+%{ $input = jenv->NewStringUTF($1.c_str());
+ Swig::LocalRefGuard refGuard_$input(jenv, $input); %}
%typemap(out) const string &
%{ $result = jenv->NewStringUTF($1->c_str()); %}