#924 std::wstring not included in primtypes.swg

closed
5
2008-05-30
2008-05-28
Haoyu Bai
No

This problem was firstly reported by Jose Luna on swig-user mailing list, the thread can be seen at there:

http://www.nabble.com/std::vector-of-wstring-objects---Python-td17373833.html

This test demonstrates the problem:

Swig Directives:
%include "stl.i"
%include "std_wstring.i"
%include "std_vector.i"
namespace std {
%template(vector_str) vector<string>;
%template(vector_wstr) vector<wstring>;
};

Python Code:
v = vector_str()
v.push_back("test1")
v.push_back("test2")
print [i for i in v]

v = vector_wstr()
v.push_back(u"test1")
v.push_back(u"test2")
print [i for i in v]
print v[0], type(v[0])

Output:
['test1', 'test2']
[<Swig Object of type 'std::wstring *' at 0x81f0ee0>, <Swig Object of type 'std::wstring *' at 0x81f3ef8>]
swig/python detected a memory leak of type 'std::wstring *', no destructor found.
swig/python detected a memory leak of type 'std::wstring *', no destructor found.
test1 <type 'unicode'>

(or segfault on my computer)

After digging into SWIG's source, I found this is caused by the lack of std::wstring in primtypes.swg.

This patch made the above test work:

Index: Lib/typemaps/primtypes.swg

--- Lib/typemaps/primtypes.swg (revision 10503)
+++ Lib/typemaps/primtypes.swg (working copy)
@@ -283,6 +283,7 @@
_apply_macro(Macro, std::size_t, Arg2);
_apply_macro(Macro, std::ptrdiff_t, Arg2);
_apply_macro(Macro, std::string, Arg2);
+_apply_macro(Macro, std::wstring, Arg2);
_apply_macro(Macro, std::complex<float>, Arg2);
_apply_macro(Macro, std::complex<double>, Arg2);
%enddef

Discussion

  • Haoyu Bai

    Haoyu Bai - 2008-05-30

    Logged In: YES
    user_id=2044815
    Originator: YES

    Fixed in SVN rev.10508. Thanks Jose Luna for reporting this!

     
  • Haoyu Bai

    Haoyu Bai - 2008-05-30
    • status: open --> closed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks