rice 4.7.1 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -1
- data/CMakeLists.txt +14 -22
- data/CMakePresets.json +203 -75
- data/FindRuby.cmake +358 -123
- data/bin/rice-doc.rb +56 -141
- data/include/rice/api.hpp +248 -0
- data/include/rice/rice.hpp +2237 -1657
- data/include/rice/stl.hpp +346 -443
- data/lib/rice/doc/config.rb +70 -0
- data/lib/rice/doc/cpp_reference.rb +1 -4
- data/lib/rice/doc/mkdocs.rb +58 -20
- data/lib/rice/doc/rice.rb +20 -0
- data/lib/rice/doc.rb +1 -0
- data/lib/rice/make_rice_headers.rb +7 -0
- data/lib/rice/native_registry.rb +2 -2
- data/lib/rice/rbs.rb +2 -2
- data/lib/rice/version.rb +1 -1
- data/lib/rubygems_plugin.rb +12 -9
- data/rice/Arg.hpp +12 -6
- data/rice/Arg.ipp +14 -7
- data/rice/Buffer.ipp +44 -40
- data/rice/Callback.hpp +1 -1
- data/rice/Callback.ipp +2 -7
- data/rice/Constructor.hpp +1 -1
- data/rice/Constructor.ipp +11 -11
- data/rice/Data_Object.ipp +15 -15
- data/rice/Data_Type.hpp +9 -10
- data/rice/Data_Type.ipp +22 -25
- data/rice/Director.hpp +1 -0
- data/rice/Enum.ipp +58 -39
- data/rice/Exception.hpp +4 -4
- data/rice/Exception.ipp +7 -7
- data/rice/NoGVL.hpp +13 -0
- data/rice/Reference.hpp +56 -0
- data/rice/Reference.ipp +96 -0
- data/rice/Return.hpp +4 -1
- data/rice/Return.ipp +0 -6
- data/rice/cpp_api/Array.hpp +41 -4
- data/rice/cpp_api/Array.ipp +105 -9
- data/rice/cpp_api/Class.hpp +2 -2
- data/rice/cpp_api/Class.ipp +4 -4
- data/rice/cpp_api/Hash.ipp +7 -4
- data/rice/cpp_api/Module.hpp +4 -4
- data/rice/cpp_api/Module.ipp +12 -10
- data/rice/cpp_api/Object.hpp +4 -4
- data/rice/cpp_api/Object.ipp +15 -12
- data/rice/cpp_api/String.hpp +2 -2
- data/rice/cpp_api/String.ipp +11 -8
- data/rice/cpp_api/Symbol.ipp +7 -7
- data/rice/cpp_api/shared_methods.hpp +5 -9
- data/rice/detail/InstanceRegistry.hpp +0 -2
- data/rice/detail/Native.hpp +31 -21
- data/rice/detail/Native.ipp +282 -130
- data/rice/detail/NativeAttributeGet.hpp +5 -7
- data/rice/detail/NativeAttributeGet.ipp +26 -26
- data/rice/detail/NativeAttributeSet.hpp +2 -4
- data/rice/detail/NativeAttributeSet.ipp +20 -16
- data/rice/detail/NativeCallback.hpp +77 -0
- data/rice/detail/NativeCallback.ipp +280 -0
- data/rice/detail/NativeFunction.hpp +11 -21
- data/rice/detail/NativeFunction.ipp +58 -119
- data/rice/detail/NativeInvoker.hpp +4 -4
- data/rice/detail/NativeInvoker.ipp +7 -7
- data/rice/detail/NativeIterator.hpp +2 -4
- data/rice/detail/NativeIterator.ipp +18 -14
- data/rice/detail/NativeMethod.hpp +10 -20
- data/rice/detail/NativeMethod.ipp +54 -114
- data/rice/detail/NativeProc.hpp +5 -7
- data/rice/detail/NativeProc.ipp +39 -28
- data/rice/detail/NativeRegistry.hpp +0 -1
- data/rice/detail/Parameter.hpp +15 -8
- data/rice/detail/Parameter.ipp +102 -43
- data/rice/detail/Proc.ipp +14 -28
- data/rice/detail/RubyType.ipp +2 -53
- data/rice/detail/Type.hpp +23 -7
- data/rice/detail/Type.ipp +73 -93
- data/rice/detail/TypeRegistry.ipp +5 -4
- data/rice/detail/Wrapper.hpp +1 -1
- data/rice/detail/Wrapper.ipp +18 -10
- data/rice/detail/from_ruby.hpp +8 -6
- data/rice/detail/from_ruby.ipp +306 -173
- data/rice/detail/ruby.hpp +23 -0
- data/rice/libc/file.hpp +4 -4
- data/rice/rice.hpp +6 -8
- data/rice/rice_api/Native.ipp +5 -1
- data/rice/rice_api/Parameter.ipp +1 -1
- data/rice/ruby_mark.hpp +2 -1
- data/rice/stl/complex.ipp +12 -8
- data/rice/stl/map.ipp +27 -22
- data/rice/stl/monostate.ipp +16 -12
- data/rice/stl/multimap.hpp +0 -2
- data/rice/stl/multimap.ipp +27 -22
- data/rice/stl/optional.ipp +27 -11
- data/rice/stl/pair.ipp +5 -5
- data/rice/stl/reference_wrapper.ipp +5 -4
- data/rice/stl/set.ipp +16 -16
- data/rice/stl/shared_ptr.hpp +0 -16
- data/rice/stl/shared_ptr.ipp +34 -190
- data/rice/stl/string.ipp +18 -18
- data/rice/stl/string_view.ipp +1 -1
- data/rice/stl/tuple.ipp +15 -36
- data/rice/stl/unique_ptr.ipp +18 -8
- data/rice/stl/unordered_map.ipp +20 -15
- data/rice/stl/variant.ipp +37 -21
- data/rice/stl/vector.ipp +41 -36
- data/rice/traits/function_traits.hpp +19 -19
- data/rice/traits/method_traits.hpp +4 -4
- data/rice/traits/rice_traits.hpp +162 -39
- data/rice.gemspec +1 -3
- data/test/test_Array.cpp +261 -3
- data/test/test_Attribute.cpp +6 -3
- data/test/test_Buffer.cpp +6 -42
- data/test/test_Callback.cpp +77 -23
- data/test/test_Data_Object.cpp +1 -1
- data/test/test_Data_Type.cpp +21 -22
- data/test/test_Director.cpp +2 -4
- data/test/test_Enum.cpp +34 -5
- data/test/test_File.cpp +9 -5
- data/test/test_From_Ruby.cpp +4 -3
- data/test/test_GVL.cpp +3 -3
- data/test/test_Hash.cpp +1 -1
- data/test/test_Iterator.cpp +54 -22
- data/test/test_Keep_Alive.cpp +1 -1
- data/test/test_Keep_Alive_No_Wrapper.cpp +1 -1
- data/test/test_Module.cpp +5 -5
- data/test/test_Overloads.cpp +345 -48
- data/test/test_Proc.cpp +54 -0
- data/test/test_Reference.cpp +181 -0
- data/test/test_Self.cpp +2 -2
- data/test/test_Stl_Set.cpp +6 -6
- data/test/test_Stl_SharedPtr.cpp +54 -30
- data/test/test_Stl_String_View.cpp +4 -2
- data/test/test_Stl_Tuple.cpp +1 -1
- data/test/test_Stl_Variant.cpp +6 -14
- data/test/test_Stl_Vector.cpp +61 -30
- data/test/test_String.cpp +4 -2
- data/test/test_Struct.cpp +1 -1
- data/test/test_Symbol.cpp +1 -1
- data/test/test_To_Ruby.cpp +1 -0
- data/test/test_Type.cpp +36 -35
- data/test/test_global_functions.cpp +1 -1
- data/test/unittest.cpp +1 -1
- data/test/unittest.hpp +5 -5
- metadata +10 -10
- data/rice/Function.hpp +0 -17
- data/rice/Function.ipp +0 -13
- data/rice/detail/MethodInfo.hpp +0 -48
- data/rice/detail/MethodInfo.ipp +0 -99
- data/rice/detail/NativeCallbackFFI.hpp +0 -55
- data/rice/detail/NativeCallbackFFI.ipp +0 -152
- data/rice/detail/NativeCallbackSimple.hpp +0 -30
- data/rice/detail/NativeCallbackSimple.ipp +0 -29
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
#include "unittest.hpp"
|
|
2
|
+
#include "embed_ruby.hpp"
|
|
3
|
+
#include <rice/rice.hpp>
|
|
4
|
+
|
|
5
|
+
using namespace Rice;
|
|
6
|
+
|
|
7
|
+
TESTSUITE(Reference);
|
|
8
|
+
|
|
9
|
+
SETUP(Reference)
|
|
10
|
+
{
|
|
11
|
+
embed_ruby();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
TEARDOWN(Reference)
|
|
15
|
+
{
|
|
16
|
+
rb_gc_start();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
namespace
|
|
20
|
+
{
|
|
21
|
+
void updateIntRef(int& ref)
|
|
22
|
+
{
|
|
23
|
+
ref = 42;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
int readIntRef(int& ref)
|
|
27
|
+
{
|
|
28
|
+
return ref;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
double readDoubleRef(double& ref)
|
|
32
|
+
{
|
|
33
|
+
return ref;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
bool readBoolRef(bool& ref)
|
|
37
|
+
{
|
|
38
|
+
return ref;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
char readCharRef(char& ref)
|
|
42
|
+
{
|
|
43
|
+
return ref;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
long readLongRef(long& ref)
|
|
47
|
+
{
|
|
48
|
+
return ref;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
long long readLongLongRef(long long& ref)
|
|
52
|
+
{
|
|
53
|
+
return ref;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
unsigned long long readUnsignedLongLongRef(unsigned long long& ref)
|
|
57
|
+
{
|
|
58
|
+
return ref;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
TESTCASE(pass_fundamental_to_reference)
|
|
63
|
+
{
|
|
64
|
+
Module m = define_module("Testing");
|
|
65
|
+
m.define_module_function("read_int_ref", &readIntRef);
|
|
66
|
+
|
|
67
|
+
std::string code = R"(read_int_ref(7))";
|
|
68
|
+
Object result = m.module_eval(code);
|
|
69
|
+
ASSERT_EQUAL(7, detail::From_Ruby<int>().convert(result));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
TESTCASE(pass_reference_object)
|
|
73
|
+
{
|
|
74
|
+
Module m = define_module("Testing");
|
|
75
|
+
m.define_module_function("read_int_ref", &readIntRef);
|
|
76
|
+
|
|
77
|
+
std::string code = R"(ref = Rice::Reference≺int≻.new(7)
|
|
78
|
+
read_int_ref(ref))";
|
|
79
|
+
|
|
80
|
+
Object result = m.module_eval(code);
|
|
81
|
+
ASSERT_EQUAL(7, detail::From_Ruby<int>().convert(result));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
TESTCASE(modify_reference_object)
|
|
85
|
+
{
|
|
86
|
+
Module m = define_module("Testing");
|
|
87
|
+
m.define_module_function("update_int_ref", &updateIntRef);
|
|
88
|
+
|
|
89
|
+
std::string code = R"(ref = Rice::Reference≺int≻.new(7)
|
|
90
|
+
update_int_ref(ref)
|
|
91
|
+
ref.value)";
|
|
92
|
+
|
|
93
|
+
Object result = m.module_eval(code);
|
|
94
|
+
ASSERT_EQUAL(42, detail::From_Ruby<int>().convert(result));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
TESTCASE(double_reference)
|
|
98
|
+
{
|
|
99
|
+
Module m = define_module("Testing");
|
|
100
|
+
m.define_module_function("read_double_ref", &readDoubleRef);
|
|
101
|
+
|
|
102
|
+
std::string code = R"(read_double_ref(2.5))";
|
|
103
|
+
Object result = m.module_eval(code);
|
|
104
|
+
ASSERT_EQUAL(2.5, detail::From_Ruby<double>().convert(result));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
TESTCASE(bool_reference)
|
|
108
|
+
{
|
|
109
|
+
Module m = define_module("Testing");
|
|
110
|
+
m.define_module_function("read_bool_ref", &readBoolRef);
|
|
111
|
+
|
|
112
|
+
std::string code = R"(read_bool_ref(true))";
|
|
113
|
+
Object result = m.module_eval(code);
|
|
114
|
+
ASSERT_EQUAL(Qtrue, result.value());
|
|
115
|
+
|
|
116
|
+
code = R"(read_bool_ref(false))";
|
|
117
|
+
result = m.module_eval(code);
|
|
118
|
+
ASSERT_EQUAL(Qfalse, result.value());
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
TESTCASE(reference_preserves_value)
|
|
122
|
+
{
|
|
123
|
+
Module m = define_module("Testing");
|
|
124
|
+
m.define_module_function("read_int_ref", &readIntRef);
|
|
125
|
+
|
|
126
|
+
std::string code = R"(read_int_ref(0))";
|
|
127
|
+
Object result = m.module_eval(code);
|
|
128
|
+
ASSERT_EQUAL(0, detail::From_Ruby<int>().convert(result));
|
|
129
|
+
|
|
130
|
+
code = R"(read_int_ref(-1))";
|
|
131
|
+
result = m.module_eval(code);
|
|
132
|
+
ASSERT_EQUAL(-1, detail::From_Ruby<int>().convert(result));
|
|
133
|
+
|
|
134
|
+
code = R"(read_int_ref(1000000))";
|
|
135
|
+
result = m.module_eval(code);
|
|
136
|
+
ASSERT_EQUAL(1000000, detail::From_Ruby<int>().convert(result));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
TESTCASE(char_reference)
|
|
140
|
+
{
|
|
141
|
+
Module m = define_module("Testing");
|
|
142
|
+
m.define_module_function("read_char_ref", &readCharRef);
|
|
143
|
+
|
|
144
|
+
std::string code = R"(read_char_ref(65))";
|
|
145
|
+
Object result = m.module_eval(code);
|
|
146
|
+
ASSERT_EQUAL('A', detail::From_Ruby<char>().convert(result));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
TESTCASE(long_reference)
|
|
150
|
+
{
|
|
151
|
+
Module m = define_module("Testing");
|
|
152
|
+
m.define_module_function("read_long_ref", &readLongRef);
|
|
153
|
+
|
|
154
|
+
std::string code = R"(read_long_ref(123456789))";
|
|
155
|
+
Object result = m.module_eval(code);
|
|
156
|
+
ASSERT_EQUAL(123456789, detail::From_Ruby<long>().convert(result));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
TESTCASE(long_long_reference)
|
|
160
|
+
{
|
|
161
|
+
Module m = define_module("Testing");
|
|
162
|
+
m.define_module_function("read_long_long_ref", &readLongLongRef);
|
|
163
|
+
|
|
164
|
+
std::string code = R"(read_long_long_ref(9223372036854775807))";
|
|
165
|
+
Object result = m.module_eval(code);
|
|
166
|
+
ASSERT_EQUAL(9223372036854775807LL, detail::From_Ruby<long long>().convert(result));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
TESTCASE(unsigned_long_long_reference)
|
|
170
|
+
{
|
|
171
|
+
// Special case: VALUE is unsigned long long on Windows x64, so we can't
|
|
172
|
+
// use Reference<unsigned long long>. Instead, the old pattern is used
|
|
173
|
+
// which stores the converted value directly.
|
|
174
|
+
Module m = define_module("Testing");
|
|
175
|
+
m.define_module_function("read_unsigned_long_long_ref", &readUnsignedLongLongRef);
|
|
176
|
+
|
|
177
|
+
std::string code = R"(read_unsigned_long_long_ref(73))";
|
|
178
|
+
Object result = m.module_eval(code);
|
|
179
|
+
ASSERT_EQUAL(73ULL, detail::From_Ruby<unsigned long long>().convert(result));
|
|
180
|
+
}
|
|
181
|
+
|
data/test/test_Self.cpp
CHANGED
|
@@ -39,12 +39,12 @@ namespace
|
|
|
39
39
|
destructorCalls++;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
SelfClass(const SelfClass&
|
|
42
|
+
SelfClass(const SelfClass&)
|
|
43
43
|
{
|
|
44
44
|
copyConstructorCalls++;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
SelfClass(SelfClass&&
|
|
47
|
+
SelfClass(SelfClass&&)
|
|
48
48
|
{
|
|
49
49
|
moveConstructorCalls++;
|
|
50
50
|
}
|
data/test/test_Stl_Set.cpp
CHANGED
|
@@ -349,7 +349,7 @@ TESTCASE(ToArray)
|
|
|
349
349
|
set.to_a)";
|
|
350
350
|
|
|
351
351
|
Array array = m.module_eval(code);
|
|
352
|
-
ASSERT_EQUAL(
|
|
352
|
+
ASSERT_EQUAL(3, array.size());
|
|
353
353
|
|
|
354
354
|
ASSERT_EQUAL("abc", detail::From_Ruby<std::string>().convert(array[0].value()));
|
|
355
355
|
ASSERT_EQUAL("def", detail::From_Ruby<std::string>().convert(array[1].value()));
|
|
@@ -507,11 +507,11 @@ namespace
|
|
|
507
507
|
static inline std::set<std::string> instance_{ "one", "two", "three" };
|
|
508
508
|
};
|
|
509
509
|
|
|
510
|
-
|
|
510
|
+
/* std::ostream& operator<<(std::ostream& stream, const std::set<std::string>& set)
|
|
511
511
|
{
|
|
512
|
-
stream <<
|
|
512
|
+
stream << set;
|
|
513
513
|
return stream;
|
|
514
|
-
}
|
|
514
|
+
}*/
|
|
515
515
|
|
|
516
516
|
void createFactoryClass()
|
|
517
517
|
{
|
|
@@ -645,7 +645,7 @@ TESTCASE(StringPointerSet)
|
|
|
645
645
|
|
|
646
646
|
Module m(rb_mKernel);
|
|
647
647
|
Data_Object<std::set<std::string*>> set = m.call("set_of_string_pointers");
|
|
648
|
-
ASSERT_EQUAL(
|
|
648
|
+
ASSERT_EQUAL(1u, set->size());
|
|
649
649
|
|
|
650
650
|
std::string expected = "Hello";
|
|
651
651
|
const std::string* actual = *set->begin();
|
|
@@ -682,7 +682,7 @@ TESTCASE(MyClass2PointerSet)
|
|
|
682
682
|
|
|
683
683
|
Module m(rb_mKernel);
|
|
684
684
|
Data_Object<std::set<MyClass2*>> result = m.call("set_of_myclass2_pointers");
|
|
685
|
-
ASSERT_EQUAL(
|
|
685
|
+
ASSERT_EQUAL(1u, result->size());
|
|
686
686
|
|
|
687
687
|
MyClass2* pMyClass = *result->begin();
|
|
688
688
|
ASSERT_EQUAL("Hello MyClass2", pMyClass->name);
|
data/test/test_Stl_SharedPtr.cpp
CHANGED
|
@@ -182,9 +182,9 @@ TESTCASE(ShareOwnership)
|
|
|
182
182
|
std::string code = R"(ary = Array.new
|
|
183
183
|
factory = Factory.new
|
|
184
184
|
10.times do |i|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
ary <<
|
|
185
|
+
ptr = factory.share
|
|
186
|
+
ptr.get.set_flag(i)
|
|
187
|
+
ary << ptr
|
|
188
188
|
end)";
|
|
189
189
|
|
|
190
190
|
ASSERT_EQUAL(0, Factory::instance_.use_count());
|
|
@@ -211,8 +211,8 @@ TESTCASE(ShareOwnership2)
|
|
|
211
211
|
// Create ruby objects that point to the same instance of MyClass
|
|
212
212
|
std::string code = R"(factory = Factory.new
|
|
213
213
|
10.times do |i|
|
|
214
|
-
|
|
215
|
-
|
|
214
|
+
ptr = factory.share
|
|
215
|
+
ptr.get.set_flag(i)
|
|
216
216
|
end)";
|
|
217
217
|
|
|
218
218
|
Factory factory;
|
|
@@ -222,9 +222,9 @@ TESTCASE(ShareOwnership2)
|
|
|
222
222
|
// Call some ruby code
|
|
223
223
|
Data_Object<Factory> wrapper(factory);
|
|
224
224
|
ASSERT_EQUAL(2, Factory::instance_.use_count());
|
|
225
|
-
wrapper.instance_eval("
|
|
225
|
+
wrapper.instance_eval("share_ref.get.set_flag(1)");
|
|
226
226
|
|
|
227
|
-
ASSERT_EQUAL(
|
|
227
|
+
ASSERT_EQUAL(2, Factory::instance_.use_count());
|
|
228
228
|
rb_gc_start();
|
|
229
229
|
ASSERT_EQUAL(2, Factory::instance_.use_count());
|
|
230
230
|
}
|
|
@@ -237,9 +237,9 @@ TESTCASE(PtrParameter)
|
|
|
237
237
|
Module m = define_module("TestingModule");
|
|
238
238
|
|
|
239
239
|
std::string code = R"(factory = Factory.new
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
extract_flag_shared_ptr(
|
|
240
|
+
ptr = factory.share
|
|
241
|
+
ptr.get.set_flag(8)
|
|
242
|
+
extract_flag_shared_ptr(ptr))";
|
|
243
243
|
|
|
244
244
|
Object result = m.module_eval(code);
|
|
245
245
|
ASSERT_EQUAL(8, detail::From_Ruby<int>().convert(result));
|
|
@@ -253,9 +253,9 @@ TESTCASE(RefParameter)
|
|
|
253
253
|
Module m = define_module("TestingModule");
|
|
254
254
|
|
|
255
255
|
std::string code = R"(factory = Factory.new
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
extract_flag_shared_ptr_ref(
|
|
256
|
+
ptr = factory.share
|
|
257
|
+
ptr.get.set_flag(9)
|
|
258
|
+
extract_flag_shared_ptr_ref(ptr))";
|
|
259
259
|
|
|
260
260
|
Object result = m.module_eval(code);
|
|
261
261
|
ASSERT_EQUAL(9, detail::From_Ruby<int>().convert(result));
|
|
@@ -269,8 +269,8 @@ TESTCASE(DefaultParameter)
|
|
|
269
269
|
Module m = define_module("TestingModule");
|
|
270
270
|
|
|
271
271
|
std::string code = R"(factory = Factory.new
|
|
272
|
-
|
|
273
|
-
|
|
272
|
+
ptr = factory.share
|
|
273
|
+
ptr.get.set_flag(7)
|
|
274
274
|
extract_flag_shared_ptr_with_default())";
|
|
275
275
|
|
|
276
276
|
Object result = m.module_eval(code);
|
|
@@ -286,8 +286,8 @@ TESTCASE(RefDefaultParameter)
|
|
|
286
286
|
Module m = define_module("TestingModule");
|
|
287
287
|
|
|
288
288
|
std::string code = R"(factory = Factory.new
|
|
289
|
-
|
|
290
|
-
|
|
289
|
+
ptr = factory.share
|
|
290
|
+
ptr.get.set_flag(7)
|
|
291
291
|
extract_flag_shared_ptr_ref_with_default())";
|
|
292
292
|
|
|
293
293
|
Object result = m.module_eval(code);
|
|
@@ -334,14 +334,14 @@ TESTCASE(Update)
|
|
|
334
334
|
|
|
335
335
|
// Create ruby objects that point to the same instance of MyClass
|
|
336
336
|
std::string code = R"(factory = Factory.new
|
|
337
|
-
|
|
338
|
-
|
|
337
|
+
ptr1 = factory.share
|
|
338
|
+
ptr1.get.set_flag(7)
|
|
339
339
|
|
|
340
|
-
|
|
341
|
-
|
|
340
|
+
myclass = MyClass.new
|
|
341
|
+
myclass.set_flag(14)
|
|
342
342
|
|
|
343
343
|
sink = Sink.new
|
|
344
|
-
sink.update_pointer(
|
|
344
|
+
sink.update_pointer(ptr1, myclass))";
|
|
345
345
|
|
|
346
346
|
Object result = m.instance_eval(code);
|
|
347
347
|
ASSERT_EQUAL(14, detail::From_Ruby<long>().convert(result.value()));
|
|
@@ -349,8 +349,10 @@ TESTCASE(Update)
|
|
|
349
349
|
|
|
350
350
|
TESTCASE(Klass)
|
|
351
351
|
{
|
|
352
|
+
define_shared_ptr<MyClass>();
|
|
352
353
|
detail::TypeMapper<std::shared_ptr<MyClass>> typeMapper;
|
|
353
|
-
|
|
354
|
+
Module aModule("Std");
|
|
355
|
+
Object expected = aModule.const_get("SharedPtr≺AnonymousNamespace꞉꞉MyClass≻");
|
|
354
356
|
VALUE actual = typeMapper.rubyKlass();
|
|
355
357
|
ASSERT_EQUAL(expected.value(), actual);
|
|
356
358
|
}
|
|
@@ -400,11 +402,23 @@ namespace
|
|
|
400
402
|
return shared;
|
|
401
403
|
}
|
|
402
404
|
|
|
405
|
+
const std::shared_ptr<int> createConstPointer(int value)
|
|
406
|
+
{
|
|
407
|
+
int* sharedInt = new int(value);
|
|
408
|
+
const std::shared_ptr<int> shared(sharedInt);
|
|
409
|
+
return shared;
|
|
410
|
+
}
|
|
411
|
+
|
|
403
412
|
int getPointerValue(std::shared_ptr<int> ptr)
|
|
404
413
|
{
|
|
405
414
|
return *ptr;
|
|
406
415
|
}
|
|
407
416
|
|
|
417
|
+
int getConstPointerValue(const std::shared_ptr<int>& ptr)
|
|
418
|
+
{
|
|
419
|
+
return *ptr;
|
|
420
|
+
}
|
|
421
|
+
|
|
408
422
|
int updatePointerValue(std::shared_ptr<int> ptr)
|
|
409
423
|
{
|
|
410
424
|
*ptr = *ptr + 1;
|
|
@@ -416,13 +430,27 @@ TESTCASE(PointerToInt)
|
|
|
416
430
|
{
|
|
417
431
|
Module m = define_module("SharedPtrInt").
|
|
418
432
|
define_module_function("create_pointer", &createPointer).
|
|
419
|
-
define_module_function("
|
|
433
|
+
define_module_function("create_const_pointer", &createConstPointer).
|
|
434
|
+
define_module_function("get_pointer_value", &getPointerValue).
|
|
435
|
+
define_module_function("get_const_pointer_value", &getConstPointerValue);
|
|
420
436
|
|
|
421
437
|
std::string code = R"(ptr = create_pointer(44)
|
|
422
438
|
get_pointer_value(ptr))";
|
|
423
439
|
|
|
424
440
|
Object result = m.instance_eval(code);
|
|
425
441
|
ASSERT_EQUAL(44, detail::From_Ruby<int>().convert(result.value()));
|
|
442
|
+
|
|
443
|
+
code = R"(ptr = create_const_pointer(45)
|
|
444
|
+
get_const_pointer_value(ptr))";
|
|
445
|
+
|
|
446
|
+
result = m.instance_eval(code);
|
|
447
|
+
ASSERT_EQUAL(45, detail::From_Ruby<int>().convert(result.value()));
|
|
448
|
+
|
|
449
|
+
code = R"(ptr = create_const_pointer(46)
|
|
450
|
+
get_pointer_value(ptr))";
|
|
451
|
+
|
|
452
|
+
result = m.instance_eval(code);
|
|
453
|
+
ASSERT_EQUAL(46, detail::From_Ruby<int>().convert(result.value()));
|
|
426
454
|
}
|
|
427
455
|
|
|
428
456
|
TESTCASE(CreatePointerToInt)
|
|
@@ -430,10 +458,8 @@ TESTCASE(CreatePointerToInt)
|
|
|
430
458
|
Module m = define_module("CreatePointerToInt").
|
|
431
459
|
define_module_function("get_pointer_value", &getPointerValue);
|
|
432
460
|
|
|
433
|
-
define_shared_ptr<int>("SharedPtrInt");
|
|
434
|
-
|
|
435
461
|
std::string code = R"(buffer = Rice::Buffer≺int≻.new(45)
|
|
436
|
-
ptr = Std::
|
|
462
|
+
ptr = Std::SharedPtr≺int≻.new(buffer.release)
|
|
437
463
|
get_pointer_value(ptr))";
|
|
438
464
|
|
|
439
465
|
Object result = m.instance_eval(code);
|
|
@@ -445,8 +471,6 @@ TESTCASE(UpdatePointerToInt)
|
|
|
445
471
|
Module m = define_module("UpdatePointerToInt").
|
|
446
472
|
define_module_function("update_pointer_value", &updatePointerValue);
|
|
447
473
|
|
|
448
|
-
define_shared_ptr<int>();
|
|
449
|
-
|
|
450
474
|
std::string code = R"(buffer = Rice::Buffer≺int≻.new(45)
|
|
451
475
|
ptr = Std::SharedPtr≺int≻.new(buffer.release)
|
|
452
476
|
update_pointer_value(ptr))";
|
|
@@ -461,7 +485,7 @@ TESTCASE(ReadPointerToInt)
|
|
|
461
485
|
define_module_function("create_pointer", &createPointer);
|
|
462
486
|
|
|
463
487
|
std::string code = R"(ptr = create_pointer(50)
|
|
464
|
-
ptr.buffer.to_ary(1))";
|
|
488
|
+
ptr.get.buffer.to_ary(1))";
|
|
465
489
|
|
|
466
490
|
Array array = m.instance_eval(code);
|
|
467
491
|
std::vector<int> actual = array.to_vector<int>();
|
|
@@ -93,11 +93,13 @@ TESTCASE(std_string_view_from_ruby_refefence)
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
namespace {
|
|
96
|
-
std::string_view testStringViewReturn(Object
|
|
96
|
+
std::string_view testStringViewReturn(Object)
|
|
97
|
+
{
|
|
97
98
|
return "test";
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
101
|
|
|
101
|
-
TESTCASE(use_string_view_in_wrapped_function)
|
|
102
|
+
TESTCASE(use_string_view_in_wrapped_function)
|
|
103
|
+
{
|
|
102
104
|
define_global_function("test_string_view_return", &testStringViewReturn);
|
|
103
105
|
}
|
data/test/test_Stl_Tuple.cpp
CHANGED
|
@@ -94,7 +94,7 @@ TESTCASE(TupleToRuby)
|
|
|
94
94
|
ASSERT_EQUAL(1i, detail::From_Ruby<std::complex<double>>().convert(result[1].value()));
|
|
95
95
|
|
|
96
96
|
std::vector<int> converted = detail::From_Ruby<std::vector<int>>().convert(result[2].value());
|
|
97
|
-
ASSERT_EQUAL(
|
|
97
|
+
ASSERT_EQUAL(3u, converted.size());
|
|
98
98
|
|
|
99
99
|
ASSERT_EQUAL(3.3, detail::From_Ruby<double>().convert(result[3].value()));
|
|
100
100
|
ASSERT_EQUAL(Qtrue, result[4].value());
|
data/test/test_Stl_Variant.cpp
CHANGED
|
@@ -21,12 +21,6 @@ namespace
|
|
|
21
21
|
int
|
|
22
22
|
>;
|
|
23
23
|
|
|
24
|
-
inline std::ostream& operator<<(std::ostream& stream, Intrinsic_Variant_T const& variant)
|
|
25
|
-
{
|
|
26
|
-
stream << "Variant(" << "index: " << variant.index() << ")";
|
|
27
|
-
return stream;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
24
|
class MyClass
|
|
31
25
|
{
|
|
32
26
|
public:
|
|
@@ -111,7 +105,6 @@ namespace
|
|
|
111
105
|
public:
|
|
112
106
|
MyClass1()
|
|
113
107
|
{
|
|
114
|
-
int a = 1;
|
|
115
108
|
}
|
|
116
109
|
|
|
117
110
|
std::string sayHello()
|
|
@@ -125,7 +118,6 @@ namespace
|
|
|
125
118
|
public:
|
|
126
119
|
MyClass2()
|
|
127
120
|
{
|
|
128
|
-
int a = 2;
|
|
129
121
|
}
|
|
130
122
|
|
|
131
123
|
std::string sayHello()
|
|
@@ -207,7 +199,7 @@ TESTCASE(IntrinsicReturns)
|
|
|
207
199
|
|
|
208
200
|
result = myClass.call("variant_vector");
|
|
209
201
|
std::vector<int> converted = detail::From_Ruby<std::vector<int>>().convert(result);
|
|
210
|
-
ASSERT_EQUAL(
|
|
202
|
+
ASSERT_EQUAL(3u, converted.size());
|
|
211
203
|
|
|
212
204
|
result = myClass.call("variant_double");
|
|
213
205
|
ASSERT_EQUAL(3.3, detail::From_Ruby<double>().convert(result));
|
|
@@ -334,9 +326,9 @@ TESTCASE(Roundtrip)
|
|
|
334
326
|
/* This test case runs successfully on MSVC but not g++. Having stepped through the code with
|
|
335
327
|
GDB, this sure seems due to a bug with g++. The issue is this variable in created operator():
|
|
336
328
|
|
|
337
|
-
|
|
329
|
+
Parameter_Ts nativeValues = this->getNativeValues(rubyValues, indices);
|
|
338
330
|
|
|
339
|
-
And is then passed to invokeNativeFunction as a const
|
|
331
|
+
And is then passed to invokeNativeFunction as a const Parameter_Ts& nativeArgs where Parameter_Ts& is
|
|
340
332
|
std::tuple with one element, a reference to a variant. So it doesn't change and the address
|
|
341
333
|
of the variable doesn't change. But for some reason g++ resets the
|
|
342
334
|
the std::variant index to 0 thus breaking the test. Maybe something to do with storing
|
|
@@ -416,19 +408,19 @@ TESTCASE(VariantWithTwoVectors)
|
|
|
416
408
|
my_class.variant_index(vector))";
|
|
417
409
|
|
|
418
410
|
Object result = m.module_eval(code);
|
|
419
|
-
ASSERT_EQUAL(
|
|
411
|
+
ASSERT_EQUAL(0u, detail::From_Ruby<size_t>().convert(result));
|
|
420
412
|
|
|
421
413
|
code = R"(vector = Std::Vector≺int≻.new
|
|
422
414
|
vector.push_back(4)
|
|
423
415
|
my_class = MyClass4.new
|
|
424
416
|
my_class.variant_index(vector))";
|
|
425
417
|
result = m.module_eval(code);
|
|
426
|
-
ASSERT_EQUAL(
|
|
418
|
+
ASSERT_EQUAL(1u, detail::From_Ruby<size_t>().convert(result));
|
|
427
419
|
|
|
428
420
|
code = R"(my_class = MyClass4.new
|
|
429
421
|
my_class.variant_index(["x", "y", "z"]))";
|
|
430
422
|
result = m.module_eval(code);
|
|
431
|
-
ASSERT_EQUAL(
|
|
423
|
+
ASSERT_EQUAL(0u, detail::From_Ruby<size_t>().convert(result));
|
|
432
424
|
|
|
433
425
|
code = R"(my_class = MyClass4.new
|
|
434
426
|
my_class.variant_index([5, 6]))";
|