summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcelo Matus <mmatus@acms.arizona.edu>2004-12-13 20:22:19 +0000
committerMarcelo Matus <mmatus@acms.arizona.edu>2004-12-13 20:22:19 +0000
commitcca7ef61ea15c1d9a7a448fa20332b8876707678 (patch)
treece2f36c0eeb06cb91238c128509ed8fab5a45f6e
parent6ad970ab239fc69d9957f7a2d03fd6ee3331e281 (diff)
downloadswig-cca7ef61ea15c1d9a7a448fa20332b8876707678.tar.gz
fix directorout typemap for const std::string&. Adding warning about the new typemap, which is not thread safe
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6872 626c5289-ae23-0410-ae9c-e8d60b6d4f22
-rw-r--r--SWIG/Examples/test-suite/common.mk1
-rw-r--r--SWIG/Examples/test-suite/director_string.i36
-rw-r--r--SWIG/Examples/test-suite/python/director_string_runme.py12
-rw-r--r--SWIG/Examples/test-suite/ruby/director_string_runme.rb18
-rw-r--r--SWIG/Lib/python/pyptrtypes.swg4
-rw-r--r--SWIG/Lib/ruby/std_string.i4
-rw-r--r--SWIG/Source/Include/swigwarn.h3
7 files changed, 73 insertions, 5 deletions
diff --git a/SWIG/Examples/test-suite/common.mk b/SWIG/Examples/test-suite/common.mk
index 2e5a969a1..1aba24d7c 100644
--- a/SWIG/Examples/test-suite/common.mk
+++ b/SWIG/Examples/test-suite/common.mk
@@ -119,6 +119,7 @@ CPP_TEST_CASES += \
director_nested \
director_protected \
director_redefined \
+ director_string \
director_unroll \
director_wombat \
dynamic_cast \
diff --git a/SWIG/Examples/test-suite/director_string.i b/SWIG/Examples/test-suite/director_string.i
new file mode 100644
index 000000000..feaaee33e
--- /dev/null
+++ b/SWIG/Examples/test-suite/director_string.i
@@ -0,0 +1,36 @@
+%module(directors="1") director_string;
+%include stl.i
+%include std_vector.i
+%include std_string.i
+
+// Using thread unsafe wrapping
+%warnfilter(470) A;
+
+%{
+#include <vector>
+#include <string>
+%}
+
+%feature("director") A;
+%inline %{
+
+struct A
+{
+ A(const std::string& first)
+ : m_strings(1, first)
+ {}
+
+ virtual ~A() {}
+
+ virtual const std::string& get_first() const
+ { return get(0); }
+
+ virtual const std::string& get(int n) const
+ { return m_strings.at(n); }
+
+ std::vector<std::string> m_strings;
+ };
+
+ %}
+
+%template(StringVector) std::vector<std::string>;
diff --git a/SWIG/Examples/test-suite/python/director_string_runme.py b/SWIG/Examples/test-suite/python/director_string_runme.py
new file mode 100644
index 000000000..e3ef78114
--- /dev/null
+++ b/SWIG/Examples/test-suite/python/director_string_runme.py
@@ -0,0 +1,12 @@
+from director_string import *
+
+class B(A):
+ def __init__(self,string):
+ A.__init__(self,string)
+
+
+
+b = B("hello")
+
+b.get(0)
+b.get_first()
diff --git a/SWIG/Examples/test-suite/ruby/director_string_runme.rb b/SWIG/Examples/test-suite/ruby/director_string_runme.rb
new file mode 100644
index 000000000..e9a6279ef
--- /dev/null
+++ b/SWIG/Examples/test-suite/ruby/director_string_runme.rb
@@ -0,0 +1,18 @@
+require 'director_string'
+require 'test/unit'
+
+
+include Director_string
+
+
+class B < A
+
+ def initialize(some_string)
+ super(some_string)
+ end
+end
+
+
+b = B.new("hello")
+b.get_first
+b.get(0) \ No newline at end of file
diff --git a/SWIG/Lib/python/pyptrtypes.swg b/SWIG/Lib/python/pyptrtypes.swg
index c3106f6ae..d98c20d54 100644
--- a/SWIG/Lib/python/pyptrtypes.swg
+++ b/SWIG/Lib/python/pyptrtypes.swg
@@ -77,12 +77,12 @@
$result = *ptr;
if (res == SWIG_NEWOBJ) delete ptr;
}
- %typemap(directorout,fragment=pyfrag) const __VA_ARGS__& ($*1_ltype temp) {
+%typemap(directorout,fragment=pyfrag,warning="470:Using thread unsafe wrapping, consider using a lvalue return type.") const __VA_ARGS__& {
__VA_ARGS__ *ptr = 0;
int res = asptr_meth($input, &ptr);
if (!res || !ptr)
throw Swig::DirectorTypeMismatchException("Error converting Python object using asptr_meth");
- temp = *ptr;
+ static $*1_ltype temp = *ptr;
$result = &temp;
if (res == SWIG_NEWOBJ) delete ptr;
}
diff --git a/SWIG/Lib/ruby/std_string.i b/SWIG/Lib/ruby/std_string.i
index a9d47bf25..5f635d7d5 100644
--- a/SWIG/Lib/ruby/std_string.i
+++ b/SWIG/Lib/ruby/std_string.i
@@ -69,9 +69,9 @@ namespace std {
throw Swig::DirectorTypeMismatchException("string expected");
}
- %typemap(directorout) const string & (std::string temp) {
+ %typemap(directorout,warning="470:Using thread unsafe wrapping, consider using a lvalue return type.") const string & {
if (TYPE($input) == T_STRING) {
- temp = std::string(StringValuePtr($input));
+ static std::string temp = std::string(StringValuePtr($input));
$result = &temp;
} else {
throw Swig::DirectorTypeMismatchException("string expected");
diff --git a/SWIG/Source/Include/swigwarn.h b/SWIG/Source/Include/swigwarn.h
index 0e039fedf..fe8d99c72 100644
--- a/SWIG/Source/Include/swigwarn.h
+++ b/SWIG/Source/Include/swigwarn.h
@@ -146,7 +146,8 @@
#define WARN_TYPEMAP_VAR_UNDEF 466
#define WARN_TYPEMAP_TYPECHECK 467
#define WARN_TYPEMAP_THROW 468
-#define WARN_TYPEMAP_DIRECTORIN_UNDEF 469
+#define WARN_TYPEMAP_DIRECTORIN_UNDEF 469
+#define WARN_TYPEMAP_THREAD_UNSAFE 470
/* -- General code generation -- */