File tree Expand file tree Collapse file tree 4 files changed +64
-1
lines changed Expand file tree Collapse file tree 4 files changed +64
-1
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,9 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
8
8
Version 4.0.1 (21 Aug 2019)
9
9
===========================
10
10
11
+ 2019-09-09: vadz
12
+ [Ruby] Add std::auto_ptr<> typemaps.
13
+
11
14
2019-08-20: TekuConcept
12
15
[Javascript] #1535 Add %native support to Javascript.
13
16
Original file line number Diff line number Diff line change 12
12
#endif
13
13
%}
14
14
15
- #if defined(SWIGCSHARP) || defined(SWIGJAVA) || defined(SWIGPYTHON)
15
+ #if defined(SWIGCSHARP) || defined(SWIGJAVA) || defined(SWIGPYTHON) || defined(SWIGRUBY)
16
16
17
17
%include " std_auto_ptr.i"
18
18
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'swig_assert'
4
+
5
+ require 'li_std_auto_ptr'
6
+
7
+ k1 = Li_std_auto_ptr ::makeKlassAutoPtr ( "first" )
8
+ k2 = Li_std_auto_ptr ::makeKlassAutoPtr ( "second" )
9
+ swig_assert_equal_simple ( Li_std_auto_ptr ::Klass ::getTotal_count ( ) , 2 )
10
+
11
+ k1 = nil
12
+ GC . start
13
+
14
+ # GC can need a few runs to actually collect the object.
15
+ 100 . times do ||
16
+ next if Li_std_auto_ptr ::Klass ::getTotal_count ( ) == 2
17
+
18
+ swig_assert_equal_simple ( Li_std_auto_ptr ::Klass ::getTotal_count ( ) , 1 )
19
+ break
20
+ end
21
+
22
+ swig_assert_equal_simple ( k2 . getLabel ( ) , "second" )
23
+
24
+ if Li_std_auto_ptr ::Klass ::getTotal_count ( ) != 1
25
+ STDERR . puts "GC failed to collect the first object, count still #{ Li_std_auto_ptr ::Klass ::getTotal_count ( ) } "
26
+
27
+ # Skip the rest of the test as it's not going to work correctly anyhow.
28
+ exit
29
+ end
30
+
31
+ k2 = nil
32
+ GC . start
33
+
34
+ 100 . times do ||
35
+ next if Li_std_auto_ptr ::Klass ::getTotal_count ( ) == 1
36
+
37
+ swig_assert_equal_simple ( Li_std_auto_ptr ::Klass ::getTotal_count ( ) , 0 )
38
+ break
39
+ end
40
+
41
+ if Li_std_auto_ptr ::Klass ::getTotal_count ( ) != 0
42
+ STDERR . puts "GC failed to collect the second object, count still #{ Li_std_auto_ptr ::Klass ::getTotal_count ( ) } "
43
+ end
Original file line number Diff line number Diff line change
1
+ /*
2
+ The typemaps here allow to handle functions returning std::auto_ptr<>,
3
+ which is the most common use of this type. If you have functions taking it
4
+ as parameter, these typemaps can't be used for them and you need to do
5
+ something else (e.g. use shared_ptr<> which SWIG supports fully).
6
+ */
7
+
8
+ %define %auto_ptr(TYPE)
9
+ %typemap (out) std::auto_ptr<TYPE > %{
10
+ %set_output (SWIG_NewPointerObj ($1 .release (), $descriptor (TYPE *), SWIG_POINTER_OWN | %newpointer_flags));
11
+ %}
12
+ %template () std::auto_ptr<TYPE >;
13
+ %enddef
14
+
15
+ namespace std {
16
+ template <class T > class auto_ptr {};
17
+ }
You can’t perform that action at this time.
0 commit comments