rice 4.0.3 → 4.1.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 +30 -0
- data/Rakefile +1 -1
- data/include/rice/rice.hpp +2597 -1771
- data/include/rice/stl.hpp +1580 -271
- data/lib/mkmf-rice.rb +5 -2
- data/lib/version.rb +1 -1
- data/rice/Arg.hpp +6 -6
- data/rice/Arg.ipp +8 -9
- data/rice/Constructor.hpp +2 -2
- data/rice/Data_Object.ipp +69 -15
- data/rice/Data_Object_defn.hpp +1 -15
- data/rice/Data_Type.ipp +56 -86
- data/rice/Data_Type_defn.hpp +14 -17
- data/rice/Director.hpp +0 -1
- data/rice/Enum.ipp +31 -22
- data/rice/Exception.ipp +2 -3
- data/rice/Exception_defn.hpp +5 -5
- data/rice/HandlerRegistration.hpp +15 -0
- data/rice/Return.hpp +5 -4
- data/rice/Return.ipp +8 -3
- data/rice/detail/ExceptionHandler.hpp +8 -0
- data/rice/detail/ExceptionHandler.ipp +28 -0
- data/rice/detail/{Exception_Handler_defn.hpp → ExceptionHandler_defn.hpp} +17 -21
- data/rice/detail/HandlerRegistry.hpp +51 -0
- data/rice/detail/HandlerRegistry.ipp +20 -0
- data/rice/detail/InstanceRegistry.hpp +34 -0
- data/rice/detail/InstanceRegistry.ipp +50 -0
- data/rice/detail/MethodInfo.ipp +1 -1
- data/rice/detail/NativeAttribute.hpp +26 -15
- data/rice/detail/NativeAttribute.ipp +76 -47
- data/rice/detail/NativeFunction.hpp +60 -13
- data/rice/detail/NativeFunction.ipp +103 -85
- data/rice/detail/NativeIterator.hpp +49 -0
- data/rice/detail/NativeIterator.ipp +102 -0
- data/rice/detail/NativeRegistry.hpp +31 -0
- data/rice/detail/{method_data.ipp → NativeRegistry.ipp} +20 -16
- data/rice/detail/Registries.hpp +26 -0
- data/rice/detail/Registries.ipp +23 -0
- data/rice/detail/RubyFunction.hpp +6 -11
- data/rice/detail/RubyFunction.ipp +10 -22
- data/rice/detail/Type.hpp +1 -1
- data/rice/detail/Type.ipp +3 -2
- data/rice/detail/TypeRegistry.hpp +8 -11
- data/rice/detail/TypeRegistry.ipp +3 -28
- data/rice/detail/Wrapper.hpp +0 -2
- data/rice/detail/Wrapper.ipp +73 -23
- data/rice/detail/cpp_protect.hpp +93 -0
- data/rice/detail/default_allocation_func.ipp +1 -1
- data/rice/detail/from_ruby.ipp +206 -2
- data/rice/detail/to_ruby.ipp +39 -5
- data/rice/detail/to_ruby_defn.hpp +1 -1
- data/rice/forward_declares.ipp +6 -0
- data/rice/global_function.hpp +0 -4
- data/rice/global_function.ipp +0 -6
- data/rice/rice.hpp +29 -24
- data/rice/stl.hpp +6 -1
- data/test/embed_ruby.cpp +0 -14
- data/test/test_Array.cpp +20 -24
- data/test/test_Class.cpp +8 -47
- data/test/test_Constructor.cpp +0 -2
- data/test/test_Data_Object.cpp +25 -11
- data/test/test_Data_Type.cpp +124 -28
- data/test/test_Director.cpp +12 -13
- data/test/test_Enum.cpp +65 -26
- data/test/test_Inheritance.cpp +9 -9
- data/test/test_Iterator.cpp +134 -5
- data/test/test_Keep_Alive.cpp +7 -7
- data/test/test_Memory_Management.cpp +1 -1
- data/test/test_Module.cpp +25 -62
- data/test/test_Object.cpp +66 -3
- data/test/test_Ownership.cpp +12 -13
- data/test/test_Self.cpp +12 -13
- data/test/test_Stl_Map.cpp +696 -0
- data/test/test_Stl_Optional.cpp +3 -3
- data/test/test_Stl_Pair.cpp +38 -2
- data/test/test_Stl_Reference_Wrapper.cpp +102 -0
- data/test/test_Stl_SmartPointer.cpp +5 -5
- data/test/test_Stl_Unordered_Map.cpp +697 -0
- data/test/test_Stl_Variant.cpp +301 -0
- data/test/test_Stl_Vector.cpp +200 -41
- data/test/test_Struct.cpp +3 -3
- data/test/test_To_From_Ruby.cpp +6 -0
- data/test/test_Tracking.cpp +239 -0
- data/test/unittest.hpp +13 -4
- metadata +23 -13
- data/rice/detail/Exception_Handler.hpp +0 -8
- data/rice/detail/Exception_Handler.ipp +0 -28
- data/rice/detail/Iterator.hpp +0 -23
- data/rice/detail/Iterator.ipp +0 -47
- data/rice/detail/function_traits.hpp +0 -124
- data/rice/detail/method_data.hpp +0 -29
- data/rice/detail/rice_traits.hpp +0 -116
- data/rice/ruby_try_catch.hpp +0 -86
data/test/test_Stl_Optional.cpp
CHANGED
@@ -53,7 +53,7 @@ SETUP(Optional)
|
|
53
53
|
TESTCASE(OptionalReturn)
|
54
54
|
{
|
55
55
|
Module m = define_module("Testing");
|
56
|
-
Object myClass = m.
|
56
|
+
Object myClass = m.module_eval("MyClass.new");
|
57
57
|
|
58
58
|
Object result = myClass.call("optional_return", true);
|
59
59
|
ASSERT_EQUAL("Here is a value", detail::From_Ruby<std::string>().convert(result));
|
@@ -65,7 +65,7 @@ TESTCASE(OptionalReturn)
|
|
65
65
|
TESTCASE(OptionalArgument)
|
66
66
|
{
|
67
67
|
Module m = define_module("Testing");
|
68
|
-
Object myClass = m.
|
68
|
+
Object myClass = m.module_eval("MyClass.new");
|
69
69
|
|
70
70
|
Object result = myClass.call("optional_argument", 77);
|
71
71
|
ASSERT_EQUAL(77, detail::From_Ruby<int32_t>().convert(result));
|
@@ -77,7 +77,7 @@ TESTCASE(OptionalArgument)
|
|
77
77
|
TESTCASE(OptionalAttribute)
|
78
78
|
{
|
79
79
|
Module m = define_module("Testing");
|
80
|
-
Object myClass = m.
|
80
|
+
Object myClass = m.module_eval("MyClass.new");
|
81
81
|
|
82
82
|
Object result = myClass.call("optional_attr");
|
83
83
|
ASSERT_EQUAL(Qnil, result.value());
|
data/test/test_Stl_Pair.cpp
CHANGED
@@ -41,6 +41,32 @@ TESTCASE(CreatePair)
|
|
41
41
|
ASSERT_EQUAL("A second value", detail::From_Ruby<std::string>().convert(result));
|
42
42
|
}
|
43
43
|
|
44
|
+
TESTCASE(CreatePairConst)
|
45
|
+
{
|
46
|
+
Module m = define_module("Testing");
|
47
|
+
|
48
|
+
Class c = define_pair<std::pair<const std::string, const std::string>>("ConstStringPair");
|
49
|
+
Object pair = c.call("new", "pair1", "pair2");
|
50
|
+
|
51
|
+
Object result = pair.call("first");
|
52
|
+
ASSERT_EQUAL("pair1", detail::From_Ruby<std::string>().convert(result));
|
53
|
+
|
54
|
+
result = pair.call("second");
|
55
|
+
ASSERT_EQUAL("pair2", detail::From_Ruby<std::string>().convert(result));
|
56
|
+
|
57
|
+
ASSERT_EXCEPTION_CHECK(
|
58
|
+
Exception,
|
59
|
+
pair.call("first=", "A second value"),
|
60
|
+
ASSERT_EQUAL("Cannot set pair.first since it is a constant", ex.what())
|
61
|
+
);
|
62
|
+
|
63
|
+
ASSERT_EXCEPTION_CHECK(
|
64
|
+
Exception,
|
65
|
+
pair.call("second=", "A second value"),
|
66
|
+
ASSERT_EQUAL("Cannot set pair.second since it is a constant", ex.what())
|
67
|
+
);
|
68
|
+
}
|
69
|
+
|
44
70
|
namespace
|
45
71
|
{
|
46
72
|
class SomeClass
|
@@ -63,7 +89,6 @@ namespace
|
|
63
89
|
|
64
90
|
// This test passes everywhere except for Ruby 2.7 on Windows
|
65
91
|
// and I don't know why. Throws a "bad any_cast" from MethodData::data
|
66
|
-
#ifndef _WIN32
|
67
92
|
TESTCASE(AutoRegister)
|
68
93
|
{
|
69
94
|
Module m = define_module("Testing");
|
@@ -98,8 +123,19 @@ TESTCASE(AutoRegister)
|
|
98
123
|
|
99
124
|
result = newPair.call("second");
|
100
125
|
ASSERT_EQUAL(3.2, detail::From_Ruby<double>().convert(result));
|
126
|
+
|
127
|
+
// Now register the pair again
|
128
|
+
define_pair<std::pair<std::string, double>>("SomePair");
|
129
|
+
std::string code = R"(pair = SomePair.new('string', 2.0))";
|
130
|
+
result = m.module_eval(code);
|
131
|
+
ASSERT(result.is_instance_of(pair.class_of()));
|
132
|
+
|
133
|
+
// And again in the module
|
134
|
+
define_pair_under<std::pair<std::string, double>>(m, "SomePair2");
|
135
|
+
code = R"(pair = Testing::SomePair2.new('string', 3.0))";
|
136
|
+
result = m.module_eval(code);
|
137
|
+
ASSERT(result.is_instance_of(pair.class_of()));
|
101
138
|
}
|
102
|
-
#endif
|
103
139
|
|
104
140
|
namespace
|
105
141
|
{
|
@@ -0,0 +1,102 @@
|
|
1
|
+
#include "unittest.hpp"
|
2
|
+
#include "embed_ruby.hpp"
|
3
|
+
#include <rice/rice.hpp>
|
4
|
+
#include <rice/stl.hpp>
|
5
|
+
|
6
|
+
#include <functional>
|
7
|
+
|
8
|
+
using namespace Rice;
|
9
|
+
|
10
|
+
TESTSUITE(ReferenceWrapper);
|
11
|
+
|
12
|
+
namespace
|
13
|
+
{
|
14
|
+
class MyClass
|
15
|
+
{
|
16
|
+
public:
|
17
|
+
int reference_wrapper_argument(std::reference_wrapper<int32_t> ref)
|
18
|
+
{
|
19
|
+
return ref.get();
|
20
|
+
}
|
21
|
+
|
22
|
+
std::reference_wrapper<std::string> reference_wrapper_return()
|
23
|
+
{
|
24
|
+
return reference_wrapper_;
|
25
|
+
}
|
26
|
+
|
27
|
+
std::string say_hello()
|
28
|
+
{
|
29
|
+
return "My ref wrapper class";
|
30
|
+
}
|
31
|
+
|
32
|
+
std::string string_ = "A ref wrapped string";
|
33
|
+
std::reference_wrapper<std::string> reference_wrapper_ = std::ref(string_);
|
34
|
+
};
|
35
|
+
|
36
|
+
std::reference_wrapper<MyClass> roundtrip_class(std::reference_wrapper<MyClass> instance)
|
37
|
+
{
|
38
|
+
return instance;
|
39
|
+
}
|
40
|
+
|
41
|
+
std::variant<std::reference_wrapper<MyClass>> roundtrip_class_in_variant(std::variant<std::reference_wrapper<MyClass>> instance)
|
42
|
+
{
|
43
|
+
return instance;
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
void makeReferenceWrapperClass()
|
48
|
+
{
|
49
|
+
define_class<MyClass>("MyClass").
|
50
|
+
define_constructor(Constructor<MyClass>()).
|
51
|
+
define_method("reference_wrapper_argument", &MyClass::reference_wrapper_argument).
|
52
|
+
define_method("reference_wrapper_return", &MyClass::reference_wrapper_return);
|
53
|
+
|
54
|
+
define_global_function("roundtrip_class", &roundtrip_class);
|
55
|
+
define_global_function("roundtrip_class_in_variant", &roundtrip_class_in_variant);
|
56
|
+
}
|
57
|
+
|
58
|
+
SETUP(ReferenceWrapper)
|
59
|
+
{
|
60
|
+
embed_ruby();
|
61
|
+
makeReferenceWrapperClass();
|
62
|
+
}
|
63
|
+
|
64
|
+
TESTCASE(Return)
|
65
|
+
{
|
66
|
+
Module m = define_module("Testing");
|
67
|
+
Object myClass = m.module_eval("MyClass.new");
|
68
|
+
|
69
|
+
Object result = myClass.call("reference_wrapper_return");
|
70
|
+
ASSERT_EQUAL("A ref wrapped string", detail::From_Ruby<std::string>().convert(result));
|
71
|
+
}
|
72
|
+
|
73
|
+
TESTCASE(Argument)
|
74
|
+
{
|
75
|
+
Module m = define_module("Testing");
|
76
|
+
Object myClass = m.module_eval("MyClass.new");
|
77
|
+
|
78
|
+
Object result = myClass.call("reference_wrapper_argument", 77);
|
79
|
+
ASSERT_EQUAL(77, detail::From_Ruby<int32_t>().convert(result));
|
80
|
+
}
|
81
|
+
|
82
|
+
TESTCASE(RoundTrip)
|
83
|
+
{
|
84
|
+
Module m = define_module("Testing");
|
85
|
+
Object myClass = m.module_eval("MyClass.new");
|
86
|
+
|
87
|
+
Object result = myClass.call("roundtrip_class", myClass);
|
88
|
+
Data_Object<MyClass> finish(result);
|
89
|
+
|
90
|
+
ASSERT_EQUAL(Data_Object<MyClass>::from_ruby(myClass), Data_Object<MyClass>::from_ruby(result));
|
91
|
+
}
|
92
|
+
|
93
|
+
TESTCASE(RoundTripInVariant)
|
94
|
+
{
|
95
|
+
Module m = define_module("Testing");
|
96
|
+
Object myClass = m.module_eval("MyClass.new");
|
97
|
+
|
98
|
+
Object result = myClass.call("roundtrip_class_in_variant", myClass);
|
99
|
+
Data_Object<MyClass> finish(result);
|
100
|
+
|
101
|
+
ASSERT_EQUAL(Data_Object<MyClass>::from_ruby(myClass), Data_Object<MyClass>::from_ruby(result));
|
102
|
+
}
|
@@ -124,7 +124,7 @@ TESTCASE(TransferOwnership)
|
|
124
124
|
my_class = nil
|
125
125
|
end)";
|
126
126
|
|
127
|
-
m.
|
127
|
+
m.module_eval(code);
|
128
128
|
rb_gc_start();
|
129
129
|
|
130
130
|
ASSERT_EQUAL(10, MyClass::constructorCalls);
|
@@ -147,7 +147,7 @@ TESTCASE(ShareOwnership)
|
|
147
147
|
my_class.set_flag(i)
|
148
148
|
end)";
|
149
149
|
|
150
|
-
m.
|
150
|
+
m.module_eval(code);
|
151
151
|
rb_gc_start();
|
152
152
|
|
153
153
|
ASSERT_EQUAL(1, MyClass::constructorCalls);
|
@@ -168,7 +168,7 @@ TESTCASE(UniquePtrRefParameter)
|
|
168
168
|
my_class.set_flag(7)
|
169
169
|
extract_flag_unique_ptr_ref(my_class))";
|
170
170
|
|
171
|
-
Object result = m.
|
171
|
+
Object result = m.module_eval(code);
|
172
172
|
}
|
173
173
|
|
174
174
|
TESTCASE(SharedPtrParameter)
|
@@ -182,7 +182,7 @@ TESTCASE(SharedPtrParameter)
|
|
182
182
|
my_class.set_flag(7)
|
183
183
|
extract_flag_shared_ptr(my_class))";
|
184
184
|
|
185
|
-
Object result = m.
|
185
|
+
Object result = m.module_eval(code);
|
186
186
|
}
|
187
187
|
|
188
188
|
TESTCASE(SharedPtrRefParameter)
|
@@ -196,5 +196,5 @@ TESTCASE(SharedPtrRefParameter)
|
|
196
196
|
my_class.set_flag(7)
|
197
197
|
extract_flag_shared_ptr_ref(my_class))";
|
198
198
|
|
199
|
-
Object result = m.
|
199
|
+
Object result = m.module_eval(code);
|
200
200
|
}
|