summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrant K. Kyser <brantkyser@gmail.com>2013-01-05 06:00:21 -0600
committerBrant K. Kyser <brantkyser@gmail.com>2013-01-05 06:00:21 -0600
commita0685d2dc40f6cda9275392d15686c04dbd6e4d5 (patch)
tree49365cbab08f4e37d0ca0514120b827b62ebe12a
parent0fa284019acc83ccfbf054040b120fe4e702b3e0 (diff)
parentfade4f1b943b17ba454dfe12d4b407ed5e0f7efe (diff)
downloadswig-a0685d2dc40f6cda9275392d15686c04dbd6e4d5.tar.gz
Merge remote branch 'upstream/master'
-rw-r--r--.gitignore2
-rw-r--r--CHANGES.current7
-rw-r--r--Examples/test-suite/common.mk1
-rw-r--r--Examples/test-suite/director_smartptr.i63
-rw-r--r--Examples/test-suite/java/director_smartptr_runme.java48
-rw-r--r--Lib/java/boost_shared_ptr.i8
-rw-r--r--Source/Modules/java.cxx22
7 files changed, 142 insertions, 9 deletions
diff --git a/.gitignore b/.gitignore
index 5d2c7ce4e..7d6db8f9a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -77,4 +77,4 @@ Examples/test-suite/python/*/
Examples/test-suite/r/*/
Examples/test-suite/ruby/*/
Examples/test-suite/tcl/*/
-Examples/test-suite/uffi/*/ \ No newline at end of file
+Examples/test-suite/uffi/*/
diff --git a/CHANGES.current b/CHANGES.current
index a043d3348..515387120 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -5,6 +5,11 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 2.0.10 (in progress)
============================
+2013-01-04: wsfulton
+ [Java] Pull patch #2 from BrantKyser to fix SF Bug #1283 - fix smart pointers in conjuction
+ with directors.
+
2013-01-03: wsfulton
- Pull patch from BrantKyser to fix directors and nspace feature when multilevel namespaces are used.
+ [Java] Pull patch #1 from BrantKyser to fix SF Bug #1278 - fix directors and nspace feature when
+ multilevel namespaces are used.
diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk
index 0c790caf6..1cda06140 100644
--- a/Examples/test-suite/common.mk
+++ b/Examples/test-suite/common.mk
@@ -185,6 +185,7 @@ CPP_TEST_CASES += \
director_protected \
director_protected_overloaded \
director_redefined \
+ director_smartptr \
director_thread \
director_unroll \
director_using \
diff --git a/Examples/test-suite/director_smartptr.i b/Examples/test-suite/director_smartptr.i
new file mode 100644
index 000000000..0d78c2775
--- /dev/null
+++ b/Examples/test-suite/director_smartptr.i
@@ -0,0 +1,63 @@
+%module(directors="1") director_smartptr
+
+#ifdef SWIGJAVA
+SWIG_JAVABODY_PROXY(public, public, SWIGTYPE)
+SWIG_JAVABODY_TYPEWRAPPER(public, public, public, SWIGTYPE)
+#endif
+
+%{
+#include <boost/shared_ptr.hpp>
+#include <string>
+
+class FooBar {
+public:
+ FooBar() {}
+ FooBar(const FooBar&) {}
+ virtual ~FooBar() {}
+
+ std::string FooBarDo() { return "Bar::Foo2::Foo2Bar()"; }
+};
+
+class Foo {
+public:
+ virtual ~Foo() {}
+ virtual std::string ping() { return "Foo::ping()"; }
+ virtual std::string pong() { return "Foo::pong();" + ping(); }
+ virtual std::string fooBar(FooBar* fooBarPtr) { return fooBarPtr->FooBarDo(); }
+ virtual Foo makeFoo() { return Foo(); }
+ virtual FooBar makeFooBar() { return FooBar(); }
+
+ static Foo* get_self(Foo *self_) {return self_;}
+};
+
+%}
+
+%include <std_string.i>
+%include <boost_shared_ptr.i>
+
+%shared_ptr(Foo)
+
+%feature("director") Foo;
+
+class FooBar {
+public:
+ FooBar();
+ FooBar(const FooBar&);
+ virtual ~FooBar();
+
+ std::string FooBarDo();
+
+};
+
+class Foo
+{
+public:
+ virtual ~Foo();
+ virtual std::string ping();
+ virtual std::string pong();
+ virtual std::string fooBar(FooBar* fooBarPtr);
+ virtual Foo makeFoo();
+ virtual FooBar makeFooBar();
+
+ static Foo* get_self(Foo *self_);
+}; \ No newline at end of file
diff --git a/Examples/test-suite/java/director_smartptr_runme.java b/Examples/test-suite/java/director_smartptr_runme.java
new file mode 100644
index 000000000..8c4ddc5d3
--- /dev/null
+++ b/Examples/test-suite/java/director_smartptr_runme.java
@@ -0,0 +1,48 @@
+// Make sure that directors are connected and disconnected when used inconjunction with
+// being a smart pointer
+
+public class director_smartptr_runme {
+
+ static {
+ try {
+ System.loadLibrary("director_smartptr");
+ } catch (UnsatisfiedLinkError e) {
+ System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
+ System.exit(1);
+ }
+ }
+
+ public static void main(String argv[]) {
+ director_smartptr_MyBarFoo myBarFoo =
+ new director_smartptr_MyBarFoo();
+ }
+
+}
+
+class director_smartptr_MyBarFoo extends director_smartptr.Foo {
+
+ @Override
+ public String ping() {
+ return "director_smartptr_MyBarFoo.ping();";
+ }
+
+ @Override
+ public String pong() {
+ return "director_smartptr_MyBarFoo.pong();" + ping();
+ }
+
+ @Override
+ public String fooBar(director_smartptr.FooBar fooBar) {
+ return fooBar.FooBarDo();
+ }
+
+ @Override
+ public director_smartptr.Foo makeFoo() {
+ return new director_smartptr.Foo();
+ }
+
+ @Override
+ public director_smartptr.FooBar makeFooBar() {
+ return new director_smartptr.FooBar();
+ }
+} \ No newline at end of file
diff --git a/Lib/java/boost_shared_ptr.i b/Lib/java/boost_shared_ptr.i
index 31d7efdf9..e75236993 100644
--- a/Lib/java/boost_shared_ptr.i
+++ b/Lib/java/boost_shared_ptr.i
@@ -146,10 +146,10 @@
// Base proxy classes
%typemap(javabody) TYPE %{
private long swigCPtr;
- private boolean swigCMemOwnBase;
+ private boolean swigCMemOwn;
PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) {
- swigCMemOwnBase = cMemoryOwn;
+ swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
@@ -176,8 +176,8 @@
%typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized") TYPE {
if (swigCPtr != 0) {
- if (swigCMemOwnBase) {
- swigCMemOwnBase = false;
+ if (swigCMemOwn) {
+ swigCMemOwn = false;
$jnicall;
}
swigCPtr = 0;
diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx
index 971e60659..0b34d10e7 100644
--- a/Source/Modules/java.cxx
+++ b/Source/Modules/java.cxx
@@ -3381,6 +3381,7 @@ public:
String *swig_director_connect = Swig_name_member(getNSpace(), proxy_class_name, "director_connect");
String *swig_director_connect_jni = makeValidJniName(swig_director_connect);
String *sym_name = Getattr(n, "sym:name");
+ String *smartptr_feature = Getattr(n, "feature:smartptr");
Wrapper *code_wrap;
Printf(imclass_class_code, " public final static native void %s(%s obj, long cptr, boolean mem_own, boolean weak_global);\n",
@@ -3390,9 +3391,24 @@ public:
Printf(code_wrap->def,
"SWIGEXPORT void JNICALL Java_%s%s_%s(JNIEnv *jenv, jclass jcls, jobject jself, jlong objarg, jboolean jswig_mem_own, "
"jboolean jweak_global) {\n", jnipackage, jni_imclass_name, swig_director_connect_jni);
- Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", norm_name, norm_name);
- Printf(code_wrap->code, " (void)jcls;\n");
- Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast<SwigDirector_%s *>(obj);\n", sym_name, sym_name);
+
+ if (Len(smartptr_feature)) {
+ Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", smartptr_feature, smartptr_feature);
+ Printf(code_wrap->code, " (void)jcls;\n");
+ Printf(code_wrap->code, " // NOTE: Pulling the raw pointer out of the smart pointer as the following code does\n");
+ Printf(code_wrap->code, " // is generally a bad idea. However, in this case we keep a local instance of the\n");
+ Printf(code_wrap->code, " // smart pointer around while we are using the raw pointer, which should keep the\n");
+ Printf(code_wrap->code, " // raw pointer alive. This is done instead of using the smart pointer's dynamic cast\n");
+ Printf(code_wrap->code, " // feature since different smart pointer implementations have differently named dynamic\n");
+ Printf(code_wrap->code, " // cast mechanisms.\n");
+ Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast<SwigDirector_%s *>(obj->operator->());\n", sym_name, sym_name);
+ }
+ else {
+ Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", norm_name, norm_name);
+ Printf(code_wrap->code, " (void)jcls;\n");
+ Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast<SwigDirector_%s *>(obj);\n", sym_name, sym_name);
+ }
+
Printf(code_wrap->code, " if (director) {\n");
Printf(code_wrap->code, " director->swig_connect_director(jenv, jself, jenv->GetObjectClass(jself), "
"(jswig_mem_own == JNI_TRUE), (jweak_global == JNI_TRUE));\n");