rice 4.6.1 → 4.7.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 +31 -0
- data/CMakeLists.txt +0 -4
- data/Rakefile +2 -8
- data/bin/rice-doc.rb +212 -0
- data/bin/rice-rbs.rb +93 -0
- data/include/rice/rice.hpp +4972 -4015
- data/include/rice/stl.hpp +822 -294
- data/lib/rice/doc/cpp_reference.rb +166 -0
- data/lib/rice/doc/doxygen.rb +294 -0
- data/lib/rice/doc/mkdocs.rb +298 -0
- data/lib/rice/doc/rice.rb +29 -0
- data/lib/rice/doc/ruby.rb +37 -0
- data/lib/rice/doc.rb +5 -0
- data/lib/{make_rice_headers.rb → rice/make_rice_headers.rb} +3 -0
- data/lib/rice/native.rb +18 -0
- data/lib/rice/native_registry.rb +21 -0
- data/lib/rice/parameter.rb +7 -0
- data/lib/rice/rbs.rb +104 -0
- data/lib/rice/version.rb +1 -1
- data/lib/rice.rb +4 -0
- data/lib/rubygems/cmake_builder.rb +24 -27
- data/rice/Arg.hpp +4 -4
- data/rice/Arg.ipp +4 -4
- data/rice/Buffer.hpp +32 -28
- data/rice/Buffer.ipp +306 -178
- data/rice/Data_Object.ipp +101 -82
- data/rice/Data_Type.hpp +5 -7
- data/rice/Data_Type.ipp +48 -29
- data/rice/Enum.ipp +15 -21
- data/rice/Function.hpp +17 -0
- data/rice/Function.ipp +13 -0
- data/rice/Pointer.hpp +15 -0
- data/rice/Pointer.ipp +49 -0
- data/rice/Return.hpp +1 -1
- data/rice/Return.ipp +2 -2
- data/rice/api.hpp +30 -0
- data/rice/cpp_api/Array.hpp +2 -2
- data/rice/cpp_api/Array.ipp +50 -5
- data/rice/cpp_api/Class.hpp +0 -5
- data/rice/cpp_api/Class.ipp +19 -0
- data/rice/cpp_api/Hash.ipp +20 -0
- data/rice/cpp_api/Module.hpp +6 -3
- data/rice/cpp_api/Module.ipp +49 -11
- data/rice/cpp_api/Object.ipp +31 -2
- data/rice/cpp_api/String.hpp +1 -2
- data/rice/cpp_api/String.ipp +21 -1
- data/rice/cpp_api/Struct.ipp +5 -0
- data/rice/cpp_api/Symbol.ipp +34 -0
- data/rice/cpp_api/shared_methods.hpp +12 -12
- data/rice/detail/MethodInfo.hpp +4 -2
- data/rice/detail/MethodInfo.ipp +19 -3
- data/rice/detail/ModuleRegistry.hpp +18 -0
- data/rice/detail/ModuleRegistry.ipp +25 -0
- data/rice/detail/Native.hpp +45 -2
- data/rice/detail/Native.ipp +196 -2
- data/rice/detail/NativeAttributeGet.hpp +9 -4
- data/rice/detail/NativeAttributeGet.ipp +65 -11
- data/rice/detail/NativeAttributeSet.hpp +4 -0
- data/rice/detail/NativeAttributeSet.ipp +30 -2
- data/rice/detail/NativeCallbackFFI.ipp +2 -2
- data/rice/detail/NativeCallbackSimple.ipp +1 -1
- data/rice/detail/NativeFunction.hpp +11 -49
- data/rice/detail/NativeFunction.ipp +82 -379
- data/rice/detail/NativeInvoker.hpp +74 -0
- data/rice/detail/NativeInvoker.ipp +197 -0
- data/rice/detail/NativeIterator.hpp +4 -0
- data/rice/detail/NativeIterator.ipp +19 -0
- data/rice/detail/NativeMethod.hpp +97 -0
- data/rice/detail/NativeMethod.ipp +332 -0
- data/rice/detail/NativeProc.hpp +51 -0
- data/rice/detail/NativeProc.ipp +133 -0
- data/rice/detail/NativeRegistry.hpp +8 -0
- data/rice/detail/NativeRegistry.ipp +27 -0
- data/rice/detail/Parameter.hpp +47 -0
- data/rice/detail/Parameter.ipp +105 -0
- data/rice/detail/Proc.ipp +14 -13
- data/rice/detail/Registries.hpp +1 -0
- data/rice/detail/RubyType.hpp +0 -2
- data/rice/detail/RubyType.ipp +15 -33
- data/rice/detail/Type.hpp +44 -8
- data/rice/detail/Type.ipp +151 -49
- data/rice/detail/TypeRegistry.hpp +3 -0
- data/rice/detail/TypeRegistry.ipp +17 -27
- data/rice/detail/Types.ipp +430 -0
- data/rice/detail/Wrapper.hpp +12 -0
- data/rice/detail/Wrapper.ipp +45 -2
- data/rice/detail/from_ruby.ipp +567 -1073
- data/rice/detail/ruby.hpp +1 -0
- data/rice/detail/to_ruby.ipp +4 -635
- data/rice/libc/file.ipp +3 -6
- data/rice/rice.hpp +22 -12
- data/rice/rice_api/Arg.hpp +7 -0
- data/rice/rice_api/Arg.ipp +9 -0
- data/rice/rice_api/ModuleRegistry.hpp +7 -0
- data/rice/rice_api/ModuleRegistry.ipp +10 -0
- data/rice/rice_api/Native.hpp +7 -0
- data/rice/rice_api/Native.ipp +52 -0
- data/rice/rice_api/NativeRegistry.hpp +7 -0
- data/rice/rice_api/NativeRegistry.ipp +21 -0
- data/rice/rice_api/Parameter.hpp +7 -0
- data/rice/rice_api/Parameter.ipp +11 -0
- data/rice/rice_api/Registries.hpp +6 -0
- data/rice/rice_api/Registries.ipp +12 -0
- data/rice/rice_api/TypeRegistry.hpp +7 -0
- data/rice/rice_api/TypeRegistry.ipp +10 -0
- data/rice/stl/complex.ipp +35 -0
- data/rice/stl/exception.ipp +20 -7
- data/rice/stl/filesystem.hpp +6 -0
- data/rice/stl/filesystem.ipp +34 -0
- data/rice/stl/map.ipp +13 -21
- data/rice/stl/monostate.ipp +37 -1
- data/rice/stl/multimap.ipp +17 -24
- data/rice/stl/optional.ipp +47 -2
- data/rice/stl/pair.ipp +23 -58
- data/rice/stl/reference_wrapper.ipp +22 -1
- data/rice/stl/set.ipp +17 -9
- data/rice/stl/shared_ptr.ipp +44 -17
- data/rice/stl/string.ipp +175 -7
- data/rice/stl/string_view.ipp +5 -0
- data/rice/stl/tuple.ipp +38 -9
- data/rice/stl/unique_ptr.ipp +46 -2
- data/rice/stl/unordered_map.ipp +13 -21
- data/rice/stl/variant.ipp +47 -11
- data/rice/stl/vector.ipp +183 -104
- data/rice/stl.hpp +1 -0
- data/rice/traits/function_traits.hpp +2 -2
- data/rice/traits/method_traits.hpp +5 -16
- data/rice/traits/rice_traits.hpp +24 -4
- data/rice.gemspec +11 -22
- data/test/embed_ruby.cpp +0 -3
- data/test/test_Array.cpp +38 -38
- data/test/test_Attribute.cpp +187 -2
- data/test/test_Buffer.cpp +302 -26
- data/test/test_Callback.cpp +2 -3
- data/test/test_Class.cpp +5 -5
- data/test/test_Data_Object.cpp +0 -55
- data/test/test_Data_Type.cpp +19 -30
- data/test/test_Enum.cpp +4 -46
- data/test/test_From_Ruby.cpp +88 -81
- data/test/test_GVL.cpp +109 -0
- data/test/test_Iterator.cpp +1 -1
- data/test/test_Keep_Alive_No_Wrapper.cpp +5 -3
- data/test/test_Module.cpp +8 -9
- data/test/test_Object.cpp +1 -1
- data/test/test_Overloads.cpp +3 -3
- data/test/test_Stl_Map.cpp +8 -8
- data/test/test_Stl_Multimap.cpp +4 -4
- data/test/test_Stl_Pair.cpp +5 -3
- data/test/test_Stl_SharedPtr.cpp +24 -12
- data/test/test_Stl_Tuple.cpp +1 -1
- data/test/test_Stl_UniquePtr.cpp +8 -0
- data/test/test_Stl_Unordered_Map.cpp +9 -9
- data/test/test_Stl_Variant.cpp +9 -3
- data/test/test_Stl_Vector.cpp +118 -13
- data/test/test_To_Ruby.cpp +35 -28
- data/test/test_Type.cpp +256 -53
- data/test/unittest.hpp +35 -0
- metadata +66 -34
- data/rice/Init.hpp +0 -8
- data/rice/Init.ipp +0 -8
- data/rice/detail/RubyFunction.hpp +0 -31
- data/rice/detail/RubyFunction.ipp +0 -77
- data/sample/callbacks/extconf.rb +0 -5
- data/sample/callbacks/sample_callbacks.cpp +0 -35
- data/sample/callbacks/test.rb +0 -28
- data/sample/enum/extconf.rb +0 -5
- data/sample/enum/sample_enum.cpp +0 -40
- data/sample/enum/test.rb +0 -8
- data/sample/inheritance/animals.cpp +0 -82
- data/sample/inheritance/extconf.rb +0 -5
- data/sample/inheritance/test.rb +0 -7
- data/sample/map/extconf.rb +0 -5
- data/sample/map/map.cpp +0 -73
- data/sample/map/test.rb +0 -7
- data/test/ext/t1/Foo.hpp +0 -10
- data/test/ext/t1/extconf.rb +0 -4
- data/test/ext/t1/t1.cpp +0 -13
- data/test/ext/t2/extconf.rb +0 -4
- data/test/ext/t2/t2.cpp +0 -11
- data/test/ruby/test_callbacks_sample.rb +0 -28
- data/test/ruby/test_multiple_extensions.rb +0 -18
- data/test/ruby/test_multiple_extensions_same_class.rb +0 -14
- data/test/ruby/test_multiple_extensions_with_inheritance.rb +0 -20
- /data/test/{test_Stl_Type.cpp → test_Stl_Type_Info.cpp} +0 -0
data/test/test_GVL.cpp
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
#include "unittest.hpp"
|
|
2
|
+
#include "embed_ruby.hpp"
|
|
3
|
+
#include <rice/rice.hpp>
|
|
4
|
+
|
|
5
|
+
#include <chrono>
|
|
6
|
+
#include <thread>
|
|
7
|
+
|
|
8
|
+
using namespace Rice;
|
|
9
|
+
|
|
10
|
+
TESTSUITE(GVL);
|
|
11
|
+
|
|
12
|
+
SETUP(GVL)
|
|
13
|
+
{
|
|
14
|
+
embed_ruby();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
TEARDOWN(GVL)
|
|
18
|
+
{
|
|
19
|
+
rb_gc_start();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
namespace
|
|
23
|
+
{
|
|
24
|
+
int slowFunction1()
|
|
25
|
+
{
|
|
26
|
+
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
27
|
+
return 83;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
void slowFunction2()
|
|
31
|
+
{
|
|
32
|
+
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
void functionException()
|
|
36
|
+
{
|
|
37
|
+
throw std::runtime_error("This is an exception from functionException");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
class Task
|
|
41
|
+
{
|
|
42
|
+
public:
|
|
43
|
+
Task(int id) : id_(id)
|
|
44
|
+
{
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
int run(bool arg1)
|
|
48
|
+
{
|
|
49
|
+
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
50
|
+
return this->id_;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private:
|
|
54
|
+
int id_;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
TESTCASE(Function)
|
|
59
|
+
{
|
|
60
|
+
int result = detail::no_gvl(&slowFunction1);
|
|
61
|
+
ASSERT_EQUAL(83, result);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
TESTCASE(FunctionViaRuby)
|
|
65
|
+
{
|
|
66
|
+
Module m = define_module("Testing");
|
|
67
|
+
m.define_module_function("slow_function_1", &slowFunction1, Function().setNoGvl());
|
|
68
|
+
|
|
69
|
+
std::string code = R"(slow_function_1)";
|
|
70
|
+
Object result = m.module_eval(code);
|
|
71
|
+
ASSERT_EQUAL(83, detail::From_Ruby<int>().convert(result));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
TESTCASE(FunctionNoReturn)
|
|
75
|
+
{
|
|
76
|
+
detail::no_gvl(&slowFunction2);
|
|
77
|
+
ASSERT_EQUAL(true, true);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
TESTCASE(FunctionWithException)
|
|
81
|
+
{
|
|
82
|
+
ASSERT_EXCEPTION_CHECK(
|
|
83
|
+
std::runtime_error,
|
|
84
|
+
detail::no_gvl(&functionException),
|
|
85
|
+
ASSERT_EQUAL("This is an exception from functionException", ex.what())
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
TESTCASE(MemberFunction)
|
|
90
|
+
{
|
|
91
|
+
Task task(84);
|
|
92
|
+
int result = detail::no_gvl(&Task::run, task, false);
|
|
93
|
+
ASSERT_EQUAL(84, result);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
TESTCASE(MemberFunctionNoGvl)
|
|
97
|
+
{
|
|
98
|
+
Module m = define_module("Testing");
|
|
99
|
+
|
|
100
|
+
Class task = define_class_under<Task>(m, "Task")
|
|
101
|
+
.define_constructor(Constructor<Task, int>())
|
|
102
|
+
.define_method("run", &Task::run, Function().setNoGvl());
|
|
103
|
+
|
|
104
|
+
std::string code = R"(task = Task.new(85)
|
|
105
|
+
task.run(true))";
|
|
106
|
+
|
|
107
|
+
Object result = m.module_eval(code);
|
|
108
|
+
ASSERT_EQUAL(85, detail::From_Ruby<int>().convert(result));
|
|
109
|
+
}
|
data/test/test_Iterator.cpp
CHANGED
|
@@ -350,7 +350,7 @@ TESTCASE(IterateNoCopy)
|
|
|
350
350
|
Data_Object<ContainerValues> wrapper(container);
|
|
351
351
|
Array a = wrapper.instance_eval("self.to_a");
|
|
352
352
|
|
|
353
|
-
ASSERT_EQUAL(container.data_.size(), a.size());
|
|
353
|
+
ASSERT_EQUAL(container.data_.size(), (size_t)a.size());
|
|
354
354
|
|
|
355
355
|
for (size_t i = 0; i < container.data_.size(); i++)
|
|
356
356
|
{
|
data/test/test_Module.cpp
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
#include "unittest.hpp"
|
|
2
2
|
#include "embed_ruby.hpp"
|
|
3
3
|
|
|
4
4
|
#include <rice/rice.hpp>
|
|
@@ -11,7 +11,6 @@ TESTSUITE(Module);
|
|
|
11
11
|
SETUP(Module)
|
|
12
12
|
{
|
|
13
13
|
embed_ruby();
|
|
14
|
-
define_fundamental_buffer_types();
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
TEARDOWN(Module)
|
|
@@ -208,8 +207,8 @@ TESTCASE(include_module)
|
|
|
208
207
|
ASSERT_EQUAL(&m, &m2);
|
|
209
208
|
Array ancestors(m.ancestors());
|
|
210
209
|
Array expected_ancestors;
|
|
211
|
-
expected_ancestors.push(m);
|
|
212
|
-
expected_ancestors.push(Module(rb_mEnumerable));
|
|
210
|
+
expected_ancestors.push(m, false);
|
|
211
|
+
expected_ancestors.push(Module(rb_mEnumerable), false);
|
|
213
212
|
ASSERT_EQUAL(expected_ancestors, ancestors);
|
|
214
213
|
}
|
|
215
214
|
|
|
@@ -467,7 +466,7 @@ TESTCASE(define_method_works_with_pointers)
|
|
|
467
466
|
|
|
468
467
|
int anInt = 3;
|
|
469
468
|
Buffer<int> buffer(&anInt, 1);
|
|
470
|
-
m.call("bar",
|
|
469
|
+
m.call("bar", buffer.ptr(), "testing");
|
|
471
470
|
|
|
472
471
|
ASSERT_EQUAL(3, with_pointers_x);
|
|
473
472
|
ASSERT_EQUAL("testing", with_pointers_str);
|
|
@@ -503,10 +502,10 @@ TESTCASE(pointers)
|
|
|
503
502
|
|
|
504
503
|
Module m = define_module("TestingModule");
|
|
505
504
|
std::string code = R"(int_buffer = Rice::Buffer≺int≻.new(32)
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
505
|
+
bool_buffer = Rice::Buffer≺bool≻.new(true)
|
|
506
|
+
double_buffer = Rice::Buffer≺float≻.new(33.0)
|
|
507
|
+
float_buffer = Rice::Buffer≺double≻.new(34.0)
|
|
508
|
+
with_pointers(int_buffer.data, bool_buffer.data, double_buffer.data, float_buffer.data))";
|
|
510
509
|
|
|
511
510
|
m.module_eval(code);
|
|
512
511
|
|
data/test/test_Object.cpp
CHANGED
|
@@ -194,7 +194,7 @@ TESTCASE(call_with_keywords)
|
|
|
194
194
|
Hash keywords;
|
|
195
195
|
keywords[":exception"] = false;
|
|
196
196
|
Object result = m.call_kw("keywords_test", "charlie", keywords);
|
|
197
|
-
ASSERT_EQUAL("charlie", detail::From_Ruby<
|
|
197
|
+
ASSERT_EQUAL("charlie", detail::From_Ruby<char*>().convert(result.value()));
|
|
198
198
|
|
|
199
199
|
keywords[":exception"] = true;
|
|
200
200
|
|
data/test/test_Overloads.cpp
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
#include "unittest.hpp"
|
|
2
2
|
#include "embed_ruby.hpp"
|
|
3
3
|
#include <rice/rice.hpp>
|
|
4
4
|
#include <rice/stl.hpp>
|
|
@@ -652,8 +652,8 @@ TESTCASE(int_conversion_6)
|
|
|
652
652
|
Module m = define_module("Testing");
|
|
653
653
|
|
|
654
654
|
std::string code = R"(my_class = MyClass3.new
|
|
655
|
-
|
|
656
|
-
|
|
655
|
+
buffer = Rice::Buffer≺unsigned char≻.new("54")
|
|
656
|
+
my_class.run(buffer.data))";
|
|
657
657
|
String result = m.module_eval(code);
|
|
658
658
|
ASSERT_EQUAL("run<unsigned char*>", result.str());
|
|
659
659
|
}
|
data/test/test_Stl_Map.cpp
CHANGED
|
@@ -220,7 +220,7 @@ TESTCASE(keysAndValues)
|
|
|
220
220
|
ASSERT_EQUAL(expected_values[2], values->operator[](2));
|
|
221
221
|
}
|
|
222
222
|
|
|
223
|
-
TESTCASE(
|
|
223
|
+
TESTCASE(CLone)
|
|
224
224
|
{
|
|
225
225
|
Module m = define_module("Testing");
|
|
226
226
|
|
|
@@ -231,15 +231,15 @@ TESTCASE(Copy)
|
|
|
231
231
|
object.call("[]=", "two", 22.2);
|
|
232
232
|
std::map<std::string, double>& map = detail::From_Ruby<std::map<std::string, double>&>().convert(object);
|
|
233
233
|
|
|
234
|
-
Object result = object.call("
|
|
235
|
-
std::map<std::string, double>&
|
|
234
|
+
Object result = object.call("clone");
|
|
235
|
+
std::map<std::string, double>& mapClone = detail::From_Ruby<std::map<std::string, double>&>().convert(result);
|
|
236
236
|
|
|
237
|
-
ASSERT_EQUAL(map.size(),
|
|
238
|
-
ASSERT_EQUAL(map["one"],
|
|
239
|
-
ASSERT_EQUAL(map["two"],
|
|
237
|
+
ASSERT_EQUAL(map.size(), mapClone.size());
|
|
238
|
+
ASSERT_EQUAL(map["one"], mapClone["one"]);
|
|
239
|
+
ASSERT_EQUAL(map["two"], mapClone["two"]);
|
|
240
240
|
|
|
241
|
-
|
|
242
|
-
ASSERT_NOT_EQUAL(map.size(),
|
|
241
|
+
mapClone["three"] = 33.3;
|
|
242
|
+
ASSERT_NOT_EQUAL(map.size(), mapClone.size());
|
|
243
243
|
}
|
|
244
244
|
|
|
245
245
|
TESTCASE(Iterate)
|
data/test/test_Stl_Multimap.cpp
CHANGED
|
@@ -218,7 +218,7 @@ TESTCASE(keysAndValues)
|
|
|
218
218
|
ASSERT_EQUAL(expected_values[2], values->operator[](2));
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
-
TESTCASE(
|
|
221
|
+
TESTCASE(Clone)
|
|
222
222
|
{
|
|
223
223
|
Module m = define_module("Testing");
|
|
224
224
|
|
|
@@ -229,10 +229,10 @@ TESTCASE(Copy)
|
|
|
229
229
|
object.call("insert", "two", 22.2);
|
|
230
230
|
std::multimap<std::string, double>& multimap = detail::From_Ruby<std::multimap<std::string, double>&>().convert(object);
|
|
231
231
|
|
|
232
|
-
Object result = object.call("
|
|
233
|
-
std::multimap<std::string, double>&
|
|
232
|
+
Object result = object.call("clone");
|
|
233
|
+
std::multimap<std::string, double>& multimapClone = detail::From_Ruby<std::multimap<std::string, double>&>().convert(result);
|
|
234
234
|
|
|
235
|
-
ASSERT_EQUAL(multimap,
|
|
235
|
+
ASSERT_EQUAL(multimap, multimapClone);
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
TESTCASE(Iterate)
|
data/test/test_Stl_Pair.cpp
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
#include <utility>
|
|
2
2
|
|
|
3
3
|
#include "unittest.hpp"
|
|
4
4
|
#include "embed_ruby.hpp"
|
|
@@ -59,17 +59,19 @@ TESTCASE(CreatePairConst)
|
|
|
59
59
|
result = pair.call("second");
|
|
60
60
|
ASSERT_EQUAL("pair2", detail::From_Ruby<std::string>().convert(result));
|
|
61
61
|
|
|
62
|
+
#ifdef _MSC_VER
|
|
62
63
|
ASSERT_EXCEPTION_CHECK(
|
|
63
64
|
Exception,
|
|
64
65
|
pair.call("first=", "A second value"),
|
|
65
|
-
ASSERT_EQUAL("
|
|
66
|
+
ASSERT_EQUAL("undefined method 'first=' for an instance of Std::ConstStringPair", ex.what())
|
|
66
67
|
);
|
|
67
68
|
|
|
68
69
|
ASSERT_EXCEPTION_CHECK(
|
|
69
70
|
Exception,
|
|
70
71
|
pair.call("second=", "A second value"),
|
|
71
|
-
ASSERT_EQUAL("
|
|
72
|
+
ASSERT_EQUAL("undefined method 'second=' for an instance of Std::ConstStringPair", ex.what())
|
|
72
73
|
);
|
|
74
|
+
#endif
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
namespace
|
data/test/test_Stl_SharedPtr.cpp
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
#include "unittest.hpp"
|
|
2
2
|
#include "embed_ruby.hpp"
|
|
3
3
|
#include <rice/rice.hpp>
|
|
4
4
|
#include <rice/stl.hpp>
|
|
@@ -347,13 +347,30 @@ TESTCASE(Update)
|
|
|
347
347
|
ASSERT_EQUAL(14, detail::From_Ruby<long>().convert(result.value()));
|
|
348
348
|
}
|
|
349
349
|
|
|
350
|
+
TESTCASE(Klass)
|
|
351
|
+
{
|
|
352
|
+
detail::TypeMapper<std::shared_ptr<MyClass>> typeMapper;
|
|
353
|
+
Object expected = Object(rb_cObject).const_get("MyClass");
|
|
354
|
+
VALUE actual = typeMapper.rubyKlass();
|
|
355
|
+
ASSERT_EQUAL(expected.value(), actual);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
TESTCASE(KlassSharedPtr)
|
|
359
|
+
{
|
|
360
|
+
define_shared_ptr<MyClass>();
|
|
361
|
+
detail::TypeMapper<std::shared_ptr<MyClass>> typeMapper;
|
|
362
|
+
|
|
363
|
+
Module stdModule("Std");
|
|
364
|
+
Object expected = stdModule.const_get("SharedPtr≺AnonymousNamespace꞉꞉MyClass≻");
|
|
365
|
+
VALUE actual = typeMapper.rubyKlass();
|
|
366
|
+
ASSERT_EQUAL(expected.value(), actual);
|
|
367
|
+
}
|
|
368
|
+
|
|
350
369
|
TESTCASE(Void)
|
|
351
370
|
{
|
|
352
371
|
MyClass::reset();
|
|
353
372
|
Factory::reset();
|
|
354
373
|
|
|
355
|
-
detail::Type<Buffer<void>>::verify();
|
|
356
|
-
|
|
357
374
|
Module m = define_module("TestingModule");
|
|
358
375
|
|
|
359
376
|
// Create ruby objects that point to the same instance of MyClass
|
|
@@ -397,8 +414,6 @@ namespace
|
|
|
397
414
|
|
|
398
415
|
TESTCASE(PointerToInt)
|
|
399
416
|
{
|
|
400
|
-
detail::Type<Buffer<int>>::verify();
|
|
401
|
-
|
|
402
417
|
Module m = define_module("SharedPtrInt").
|
|
403
418
|
define_module_function("create_pointer", &createPointer).
|
|
404
419
|
define_module_function("get_pointer_value", &getPointerValue);
|
|
@@ -418,7 +433,7 @@ TESTCASE(CreatePointerToInt)
|
|
|
418
433
|
define_shared_ptr<int>("SharedPtrInt");
|
|
419
434
|
|
|
420
435
|
std::string code = R"(buffer = Rice::Buffer≺int≻.new(45)
|
|
421
|
-
ptr = Std::SharedPtrInt.new(buffer)
|
|
436
|
+
ptr = Std::SharedPtrInt.new(buffer.release)
|
|
422
437
|
get_pointer_value(ptr))";
|
|
423
438
|
|
|
424
439
|
Object result = m.instance_eval(code);
|
|
@@ -433,7 +448,7 @@ TESTCASE(UpdatePointerToInt)
|
|
|
433
448
|
define_shared_ptr<int>();
|
|
434
449
|
|
|
435
450
|
std::string code = R"(buffer = Rice::Buffer≺int≻.new(45)
|
|
436
|
-
ptr = Std::SharedPtr≺int≻.new(buffer)
|
|
451
|
+
ptr = Std::SharedPtr≺int≻.new(buffer.release)
|
|
437
452
|
update_pointer_value(ptr))";
|
|
438
453
|
|
|
439
454
|
Object result = m.instance_eval(code);
|
|
@@ -442,14 +457,11 @@ TESTCASE(UpdatePointerToInt)
|
|
|
442
457
|
|
|
443
458
|
TESTCASE(ReadPointerToInt)
|
|
444
459
|
{
|
|
445
|
-
detail::Type<Buffer<int>>::verify();
|
|
446
|
-
|
|
447
460
|
Module m = define_module("ReadPointerToInt").
|
|
448
|
-
|
|
461
|
+
define_module_function("create_pointer", &createPointer);
|
|
449
462
|
|
|
450
463
|
std::string code = R"(ptr = create_pointer(50)
|
|
451
|
-
|
|
452
|
-
buffer.to_ary(1))";
|
|
464
|
+
ptr.buffer.to_ary(1))";
|
|
453
465
|
|
|
454
466
|
Array array = m.instance_eval(code);
|
|
455
467
|
std::vector<int> actual = array.to_vector<int>();
|
data/test/test_Stl_Tuple.cpp
CHANGED
data/test/test_Stl_UniquePtr.cpp
CHANGED
|
@@ -199,4 +199,12 @@ TESTCASE(Update)
|
|
|
199
199
|
|
|
200
200
|
Object result = m.instance_eval(code);
|
|
201
201
|
ASSERT_EQUAL(11, detail::From_Ruby<long>().convert(result.value()));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
TESTCASE(Klass)
|
|
205
|
+
{
|
|
206
|
+
detail::TypeMapper<std::unique_ptr<MyClass>> typeMapper;
|
|
207
|
+
Object expected = Object(rb_cObject).const_get("MyClass");
|
|
208
|
+
VALUE actual = typeMapper.rubyKlass();
|
|
209
|
+
ASSERT_EQUAL(expected.value(), actual);
|
|
202
210
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
#include <complex>
|
|
2
2
|
#include <memory>
|
|
3
3
|
|
|
4
4
|
#include "unittest.hpp"
|
|
@@ -216,7 +216,7 @@ TESTCASE(KeysAndValues)
|
|
|
216
216
|
ASSERT_EQUAL(3, values->operator[](2));
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
-
TESTCASE(
|
|
219
|
+
TESTCASE(Clone)
|
|
220
220
|
{
|
|
221
221
|
Module m = define_module("Testing");
|
|
222
222
|
|
|
@@ -227,15 +227,15 @@ TESTCASE(Copy)
|
|
|
227
227
|
object.call("[]=", "two", 22.2);
|
|
228
228
|
std::unordered_map<std::string, double>& unordered_map = detail::From_Ruby<std::unordered_map<std::string, double>&>().convert(object);
|
|
229
229
|
|
|
230
|
-
Object result = object.call("
|
|
231
|
-
std::unordered_map<std::string, double>&
|
|
230
|
+
Object result = object.call("clone");
|
|
231
|
+
std::unordered_map<std::string, double>& unordered_mapClone = detail::From_Ruby<std::unordered_map<std::string, double>&>().convert(result);
|
|
232
232
|
|
|
233
|
-
ASSERT_EQUAL(unordered_map.size(),
|
|
234
|
-
ASSERT_EQUAL(unordered_map["one"],
|
|
235
|
-
ASSERT_EQUAL(unordered_map["two"],
|
|
233
|
+
ASSERT_EQUAL(unordered_map.size(), unordered_mapClone.size());
|
|
234
|
+
ASSERT_EQUAL(unordered_map["one"], unordered_mapClone["one"]);
|
|
235
|
+
ASSERT_EQUAL(unordered_map["two"], unordered_mapClone["two"]);
|
|
236
236
|
|
|
237
|
-
|
|
238
|
-
ASSERT_NOT_EQUAL(unordered_map.size(),
|
|
237
|
+
unordered_mapClone["three"] = 33.3;
|
|
238
|
+
ASSERT_NOT_EQUAL(unordered_map.size(), unordered_mapClone.size());
|
|
239
239
|
}
|
|
240
240
|
|
|
241
241
|
TESTCASE(Iterate)
|
data/test/test_Stl_Variant.cpp
CHANGED
|
@@ -380,6 +380,14 @@ TESTCASE(RoundtripConstRef)
|
|
|
380
380
|
ASSERT_EQUAL(Qnil, instance2.value());
|
|
381
381
|
}
|
|
382
382
|
|
|
383
|
+
TESTCASE(Klass)
|
|
384
|
+
{
|
|
385
|
+
detail::TypeMapper<Variant_T> typeMapper;
|
|
386
|
+
Object expected = Object(rb_cObject).const_get("Object");
|
|
387
|
+
VALUE actual = typeMapper.rubyKlass();
|
|
388
|
+
ASSERT_EQUAL(expected.value(), actual);
|
|
389
|
+
}
|
|
390
|
+
|
|
383
391
|
namespace
|
|
384
392
|
{
|
|
385
393
|
class MyClass4
|
|
@@ -456,8 +464,6 @@ namespace
|
|
|
456
464
|
|
|
457
465
|
TESTCASE(Buffer)
|
|
458
466
|
{
|
|
459
|
-
define_buffer<int>();
|
|
460
|
-
define_buffer<float>();
|
|
461
467
|
using namespace std::complex_literals;
|
|
462
468
|
|
|
463
469
|
define_class<MyClass5>("MyClass5").
|
|
@@ -476,4 +482,4 @@ TESTCASE(Buffer)
|
|
|
476
482
|
myclass.buffer(1).to_ary(1).first)";
|
|
477
483
|
result = m.module_eval(code);
|
|
478
484
|
ASSERT_EQUAL(11.0, detail::From_Ruby<float>().convert(result));
|
|
479
|
-
}
|
|
485
|
+
}
|
data/test/test_Stl_Vector.cpp
CHANGED
|
@@ -18,7 +18,7 @@ TEARDOWN(Vector)
|
|
|
18
18
|
{
|
|
19
19
|
rb_gc_start();
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
/*
|
|
22
22
|
namespace
|
|
23
23
|
{
|
|
24
24
|
class MyClass
|
|
@@ -65,6 +65,22 @@ TESTCASE(StringVector)
|
|
|
65
65
|
result = vec.call("last");
|
|
66
66
|
ASSERT_EQUAL("four", detail::From_Ruby<std::string>().convert(result));
|
|
67
67
|
}
|
|
68
|
+
*/
|
|
69
|
+
TESTCASE(StringVectorData)
|
|
70
|
+
{
|
|
71
|
+
Module m = define_module("Testing");
|
|
72
|
+
define_vector<std::string>();
|
|
73
|
+
|
|
74
|
+
std::string code = R"(vec = Std::Vector≺string≻.new
|
|
75
|
+
vec.push("Hello")
|
|
76
|
+
vec.push("World")
|
|
77
|
+
buffer = Rice::Buffer≺string≻.new(vec.data, vec.size())
|
|
78
|
+
[buffer[0], buffer[1]])";
|
|
79
|
+
Array array = m.module_eval(code);
|
|
80
|
+
ASSERT_EQUAL(2, array.size());
|
|
81
|
+
ASSERT_EQUAL("Hello", detail::From_Ruby<std::string>().convert(array[0].value()).c_str());
|
|
82
|
+
ASSERT_EQUAL("World", detail::From_Ruby<std::string>().convert(array[1].value()).c_str());
|
|
83
|
+
}
|
|
68
84
|
|
|
69
85
|
TESTCASE(Constructors)
|
|
70
86
|
{
|
|
@@ -171,6 +187,7 @@ TESTCASE(BoolVector)
|
|
|
171
187
|
ASSERT_EQUAL(Qtrue, result.value());
|
|
172
188
|
|
|
173
189
|
result = vec.call("[]=", 1, false);
|
|
190
|
+
result = vec.call("[]", 1);
|
|
174
191
|
ASSERT_EQUAL(Qfalse, result.value());
|
|
175
192
|
|
|
176
193
|
std::string code = R"(array = self.each.to_a
|
|
@@ -224,10 +241,30 @@ TESTCASE(Indexing)
|
|
|
224
241
|
ASSERT_EQUAL(0, detail::From_Ruby<int32_t>().convert(result));
|
|
225
242
|
|
|
226
243
|
result = vec.call("[]", -4);
|
|
227
|
-
ASSERT_EQUAL(
|
|
244
|
+
ASSERT_EQUAL(Qnil, result.value());
|
|
228
245
|
|
|
229
246
|
result = vec.call("[]", -7);
|
|
230
|
-
ASSERT_EQUAL(
|
|
247
|
+
ASSERT_EQUAL(Qnil, result.value());
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
TESTCASE(IndexingEmptyVector)
|
|
251
|
+
{
|
|
252
|
+
Module m = define_module("Testing");
|
|
253
|
+
|
|
254
|
+
Class c = define_vector<std::int32_t>("IntVector");
|
|
255
|
+
Object vec = c.call("new");
|
|
256
|
+
|
|
257
|
+
Object result = vec.call("size");
|
|
258
|
+
ASSERT_EQUAL(0, detail::From_Ruby<int32_t>().convert(result));
|
|
259
|
+
|
|
260
|
+
result = vec.call("[]", 0);
|
|
261
|
+
ASSERT_EQUAL(Qnil, result.value());
|
|
262
|
+
|
|
263
|
+
result = vec.call("[]", 1);
|
|
264
|
+
ASSERT_EQUAL(Qnil, result.value());
|
|
265
|
+
|
|
266
|
+
result = vec.call("[]", -1);
|
|
267
|
+
ASSERT_EQUAL(Qnil, result.value());
|
|
231
268
|
}
|
|
232
269
|
|
|
233
270
|
TESTCASE(Slice)
|
|
@@ -312,8 +349,7 @@ TESTCASE(Update)
|
|
|
312
349
|
Object result = vec.call("size");
|
|
313
350
|
ASSERT_EQUAL(2, detail::From_Ruby<int32_t>().convert(result));
|
|
314
351
|
|
|
315
|
-
|
|
316
|
-
ASSERT_EQUAL("new 2", detail::From_Ruby<std::string>().convert(result));
|
|
352
|
+
vec.call("[]=", 1, "new 2");
|
|
317
353
|
|
|
318
354
|
result = vec.call("[]", 1);
|
|
319
355
|
ASSERT_EQUAL("new 2", detail::From_Ruby<std::string>().convert(result));
|
|
@@ -346,21 +382,35 @@ TESTCASE(Modify)
|
|
|
346
382
|
result = vec.call("to_s");
|
|
347
383
|
ASSERT_EQUAL("[11, 33, 22]", detail::From_Ruby<std::string>().convert(result));
|
|
348
384
|
|
|
385
|
+
result = vec.call("insert", -2, 34);
|
|
386
|
+
|
|
387
|
+
result = vec.call("size");
|
|
388
|
+
ASSERT_EQUAL(4, detail::From_Ruby<int32_t>().convert(result));
|
|
389
|
+
|
|
390
|
+
result = vec.call("to_s");
|
|
391
|
+
ASSERT_EQUAL("[11, 33, 34, 22]", detail::From_Ruby<std::string>().convert(result));
|
|
392
|
+
|
|
349
393
|
result = vec.call("delete", 11);
|
|
350
394
|
ASSERT_EQUAL(11, detail::From_Ruby<int64_t>().convert(result));
|
|
351
395
|
|
|
352
396
|
result = vec.call("size");
|
|
353
|
-
ASSERT_EQUAL(
|
|
397
|
+
ASSERT_EQUAL(3, detail::From_Ruby<int32_t>().convert(result));
|
|
354
398
|
|
|
355
399
|
result = vec.call("delete_at", 0);
|
|
356
400
|
ASSERT_EQUAL(33, detail::From_Ruby<int64_t>().convert(result));
|
|
357
401
|
|
|
358
402
|
result = vec.call("size");
|
|
359
|
-
ASSERT_EQUAL(
|
|
403
|
+
ASSERT_EQUAL(2, detail::From_Ruby<int32_t>().convert(result));
|
|
360
404
|
|
|
361
405
|
result = vec.call("pop");
|
|
362
406
|
ASSERT_EQUAL(22, detail::From_Ruby<int64_t>().convert(result));
|
|
363
407
|
|
|
408
|
+
result = vec.call("size");
|
|
409
|
+
ASSERT_EQUAL(1, detail::From_Ruby<int32_t>().convert(result));
|
|
410
|
+
|
|
411
|
+
result = vec.call("pop");
|
|
412
|
+
ASSERT_EQUAL(34, detail::From_Ruby<int32_t>().convert(result));
|
|
413
|
+
|
|
364
414
|
result = vec.call("size");
|
|
365
415
|
ASSERT_EQUAL(0, detail::From_Ruby<int32_t>().convert(result));
|
|
366
416
|
|
|
@@ -390,6 +440,44 @@ TESTCASE(Clone)
|
|
|
390
440
|
ASSERT_NOT_EQUAL(vec.size(), vecClone.size());
|
|
391
441
|
}
|
|
392
442
|
|
|
443
|
+
|
|
444
|
+
namespace
|
|
445
|
+
{
|
|
446
|
+
class SomeClass
|
|
447
|
+
{
|
|
448
|
+
public:
|
|
449
|
+
SomeClass(int value) : value(value)
|
|
450
|
+
{
|
|
451
|
+
}
|
|
452
|
+
int value;
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
std::vector<std::unique_ptr<SomeClass>> uniqueVector()
|
|
456
|
+
{
|
|
457
|
+
std::vector<std::unique_ptr<SomeClass>> result;
|
|
458
|
+
result.push_back(std::make_unique<SomeClass>(1));
|
|
459
|
+
result.push_back(std::make_unique<SomeClass>(2));
|
|
460
|
+
return result;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
TESTCASE(UniqueVector)
|
|
465
|
+
{
|
|
466
|
+
Module m(anonymous_module());
|
|
467
|
+
|
|
468
|
+
Class c = define_class<SomeClass>("SomeClass").
|
|
469
|
+
define_constructor(Constructor<SomeClass, int>()).
|
|
470
|
+
define_attr("value", &SomeClass::value);
|
|
471
|
+
|
|
472
|
+
m.define_module_function("unique_vector", &uniqueVector);
|
|
473
|
+
|
|
474
|
+
std::string code = R"(vector = unique_vector
|
|
475
|
+
vector.size)";
|
|
476
|
+
|
|
477
|
+
Object result = m.module_eval(code);
|
|
478
|
+
ASSERT_EQUAL(2, detail::From_Ruby<int32_t>().convert(result));
|
|
479
|
+
}
|
|
480
|
+
|
|
393
481
|
namespace
|
|
394
482
|
{
|
|
395
483
|
class NotComparable
|
|
@@ -637,9 +725,9 @@ TESTCASE(AutoRegisterParameter)
|
|
|
637
725
|
define_global_function("pass_complex_vector", &passComplexVector);
|
|
638
726
|
|
|
639
727
|
std::string code = R"(vector = Std::Vector≺complex≺double≻≻.new
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
728
|
+
vector << Complex(4.0, 4.0)
|
|
729
|
+
vector << Complex(5.0, 5.0)
|
|
730
|
+
pass_complex_vector(vector))";
|
|
643
731
|
|
|
644
732
|
Module m = define_module("Testing");
|
|
645
733
|
Object vec = m.module_eval(code);
|
|
@@ -653,6 +741,24 @@ TESTCASE(AutoRegisterParameter)
|
|
|
653
741
|
ASSERT_EQUAL(complexes[1], std::complex<double>(5, 5));
|
|
654
742
|
}
|
|
655
743
|
|
|
744
|
+
TESTCASE(AutoRegisterException)
|
|
745
|
+
{
|
|
746
|
+
std::string code = R"(
|
|
747
|
+
begin
|
|
748
|
+
Std::Vector≺complex≺double≻≻.new('!!!!')
|
|
749
|
+
rescue => e
|
|
750
|
+
name = e.class.name
|
|
751
|
+
"#{e.class.name} #{e.message} #{(e.backtrace || []).join("\n")}" # shoud not raise 'incompatible character encodings: BINARY (ASCII-8BIT) and UTF-8' ?
|
|
752
|
+
end
|
|
753
|
+
"reachable! - #{name}"
|
|
754
|
+
)";
|
|
755
|
+
|
|
756
|
+
Module m = define_module("Testing");
|
|
757
|
+
Object result = m.module_eval(code);
|
|
758
|
+
std::string actual = detail::From_Ruby<std::string>().convert(result);
|
|
759
|
+
ASSERT_EQUAL("reachable! - ArgumentError", actual);
|
|
760
|
+
}
|
|
761
|
+
|
|
656
762
|
namespace
|
|
657
763
|
{
|
|
658
764
|
std::vector<std::string> defaultVector(std::vector<std::string> strings = {"one", "two", "three"})
|
|
@@ -1005,9 +1111,8 @@ TESTCASE(StringPointerVector)
|
|
|
1005
1111
|
ASSERT_EQUAL(expected, *actual);
|
|
1006
1112
|
|
|
1007
1113
|
std::string code = R"(vec = vector_of_string_pointers
|
|
1008
|
-
outer_buffer = vec.data
|
|
1009
|
-
|
|
1010
|
-
inner_buffer = inner_buffers[1]
|
|
1114
|
+
outer_buffer = vec.data.buffer
|
|
1115
|
+
inner_buffer = Rice::Buffer≺string≻.new(outer_buffer[1])
|
|
1011
1116
|
inner_buffer.to_ary(1))";
|
|
1012
1117
|
Array array = m.module_eval(code);
|
|
1013
1118
|
ASSERT_EQUAL(1, array.size());
|