rice 4.3.3 → 4.6.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 +86 -26
- data/CMakeLists.txt +31 -0
- data/CMakePresets.json +75 -0
- data/COPYING +3 -2
- data/FindRuby.cmake +437 -0
- data/README.md +7 -2
- data/Rakefile +12 -5
- data/include/rice/rice.hpp +9522 -4426
- data/include/rice/stl.hpp +2831 -1198
- data/lib/make_rice_headers.rb +79 -0
- data/lib/mkmf-rice.rb +40 -94
- data/lib/rice/version.rb +3 -0
- data/lib/rice.rb +1 -0
- data/lib/rubygems/builder.rb +11 -0
- data/lib/rubygems/cmake_builder.rb +113 -0
- data/lib/rubygems_plugin.rb +9 -0
- data/rice/Address_Registration_Guard.hpp +72 -3
- data/rice/Arg.hpp +26 -6
- data/rice/Arg.ipp +35 -2
- data/rice/Buffer.hpp +123 -0
- data/rice/Buffer.ipp +599 -0
- data/rice/Callback.hpp +21 -0
- data/rice/Callback.ipp +13 -0
- data/rice/Constructor.hpp +4 -27
- data/rice/Constructor.ipp +79 -0
- data/rice/Data_Object.hpp +73 -3
- data/rice/Data_Object.ipp +388 -96
- data/rice/Data_Type.hpp +214 -3
- data/rice/Data_Type.ipp +144 -67
- data/rice/Director.hpp +0 -2
- data/rice/Enum.hpp +4 -7
- data/rice/Enum.ipp +102 -55
- data/rice/Exception.hpp +62 -2
- data/rice/Exception.ipp +7 -12
- data/rice/Init.hpp +8 -0
- data/rice/Init.ipp +8 -0
- data/rice/JumpException.hpp +44 -0
- data/rice/JumpException.ipp +48 -0
- data/rice/MemoryView.hpp +11 -0
- data/rice/MemoryView.ipp +3 -0
- data/rice/Return.hpp +7 -27
- data/rice/Return.ipp +13 -13
- data/rice/cpp_api/Array.hpp +209 -0
- data/rice/cpp_api/Array.ipp +304 -0
- data/rice/cpp_api/Builtin_Object.hpp +31 -0
- data/rice/cpp_api/Builtin_Object.ipp +37 -0
- data/rice/cpp_api/Class.hpp +70 -0
- data/rice/cpp_api/Class.ipp +97 -0
- data/rice/cpp_api/Encoding.hpp +32 -0
- data/rice/cpp_api/Encoding.ipp +59 -0
- data/rice/cpp_api/Hash.hpp +194 -0
- data/rice/cpp_api/Hash.ipp +257 -0
- data/rice/{Identifier.hpp → cpp_api/Identifier.hpp} +2 -6
- data/rice/{Identifier.ipp → cpp_api/Identifier.ipp} +4 -2
- data/rice/cpp_api/Module.hpp +72 -0
- data/rice/cpp_api/Module.ipp +101 -0
- data/rice/cpp_api/Object.hpp +272 -0
- data/rice/cpp_api/Object.ipp +235 -0
- data/rice/cpp_api/String.hpp +74 -0
- data/rice/cpp_api/String.ipp +120 -0
- data/rice/cpp_api/Struct.hpp +113 -0
- data/rice/cpp_api/Struct.ipp +92 -0
- data/rice/cpp_api/Symbol.hpp +46 -0
- data/rice/cpp_api/Symbol.ipp +93 -0
- data/rice/cpp_api/shared_methods.hpp +134 -0
- data/rice/detail/DefaultHandler.hpp +12 -0
- data/rice/detail/DefaultHandler.ipp +8 -0
- data/rice/detail/HandlerRegistry.hpp +5 -35
- data/rice/detail/HandlerRegistry.ipp +7 -11
- data/rice/detail/InstanceRegistry.hpp +1 -4
- data/rice/detail/MethodInfo.hpp +12 -10
- data/rice/detail/MethodInfo.ipp +26 -21
- data/rice/detail/Native.hpp +33 -0
- data/rice/detail/Native.ipp +157 -0
- data/rice/detail/NativeAttributeGet.hpp +52 -0
- data/rice/detail/NativeAttributeGet.ipp +57 -0
- data/rice/detail/NativeAttributeSet.hpp +44 -0
- data/rice/detail/NativeAttributeSet.ipp +88 -0
- data/rice/detail/NativeCallbackFFI.hpp +55 -0
- data/rice/detail/NativeCallbackFFI.ipp +151 -0
- data/rice/detail/NativeCallbackSimple.hpp +30 -0
- data/rice/detail/NativeCallbackSimple.ipp +29 -0
- data/rice/detail/NativeFunction.hpp +33 -23
- data/rice/detail/NativeFunction.ipp +309 -70
- data/rice/detail/NativeIterator.hpp +9 -11
- data/rice/detail/NativeIterator.ipp +33 -31
- data/rice/detail/NativeRegistry.hpp +24 -15
- data/rice/detail/NativeRegistry.ipp +23 -48
- data/rice/detail/Proc.hpp +4 -0
- data/rice/detail/Proc.ipp +85 -0
- data/rice/detail/Registries.hpp +0 -7
- data/rice/detail/Registries.ipp +0 -18
- data/rice/detail/RubyFunction.hpp +0 -3
- data/rice/detail/RubyFunction.ipp +4 -8
- data/rice/detail/RubyType.hpp +16 -0
- data/rice/detail/RubyType.ipp +232 -0
- data/rice/detail/Type.hpp +7 -6
- data/rice/detail/Type.ipp +192 -45
- data/rice/detail/TypeRegistry.hpp +15 -7
- data/rice/detail/TypeRegistry.ipp +105 -12
- data/rice/detail/Wrapper.hpp +68 -32
- data/rice/detail/Wrapper.ipp +121 -109
- data/rice/detail/cpp_protect.hpp +5 -6
- data/rice/detail/default_allocation_func.ipp +0 -2
- data/rice/detail/from_ruby.hpp +38 -3
- data/rice/detail/from_ruby.ipp +1321 -492
- data/rice/detail/ruby.hpp +18 -0
- data/rice/detail/to_ruby.hpp +41 -3
- data/rice/detail/to_ruby.ipp +1424 -194
- data/rice/global_function.hpp +0 -4
- data/rice/global_function.ipp +0 -1
- data/rice/libc/file.hpp +11 -0
- data/rice/libc/file.ipp +32 -0
- data/rice/rice.hpp +116 -26
- data/rice/ruby_mark.hpp +4 -3
- data/rice/stl/complex.hpp +6 -0
- data/rice/stl/complex.ipp +93 -0
- data/rice/stl/exception.hpp +11 -0
- data/rice/stl/exception.ipp +29 -0
- data/rice/stl/exception_ptr.hpp +6 -0
- data/rice/stl/exception_ptr.ipp +27 -0
- data/rice/stl/map.hpp +12 -0
- data/rice/stl/map.ipp +469 -0
- data/rice/stl/monostate.hpp +6 -0
- data/rice/stl/monostate.ipp +80 -0
- data/rice/stl/multimap.hpp +14 -0
- data/rice/stl/multimap.ipp +448 -0
- data/rice/stl/optional.hpp +6 -0
- data/rice/stl/optional.ipp +118 -0
- data/rice/stl/pair.hpp +13 -0
- data/rice/stl/pair.ipp +155 -0
- data/rice/stl/reference_wrapper.hpp +6 -0
- data/rice/stl/reference_wrapper.ipp +41 -0
- data/rice/stl/set.hpp +12 -0
- data/rice/stl/set.ipp +495 -0
- data/rice/stl/shared_ptr.hpp +28 -0
- data/rice/stl/shared_ptr.ipp +224 -0
- data/rice/stl/string.hpp +6 -0
- data/rice/stl/string.ipp +158 -0
- data/rice/stl/string_view.hpp +6 -0
- data/rice/stl/string_view.ipp +65 -0
- data/rice/stl/tuple.hpp +6 -0
- data/rice/stl/tuple.ipp +128 -0
- data/rice/stl/type_index.hpp +6 -0
- data/rice/stl/type_index.ipp +30 -0
- data/rice/stl/type_info.hpp +6 -0
- data/rice/stl/type_info.ipp +29 -0
- data/rice/stl/unique_ptr.hpp +22 -0
- data/rice/stl/unique_ptr.ipp +139 -0
- data/rice/stl/unordered_map.hpp +12 -0
- data/rice/stl/unordered_map.ipp +469 -0
- data/rice/stl/variant.hpp +6 -0
- data/rice/stl/variant.ipp +242 -0
- data/rice/stl/vector.hpp +12 -0
- data/rice/stl/vector.ipp +590 -0
- data/rice/stl.hpp +11 -3
- data/rice/traits/attribute_traits.hpp +26 -0
- data/rice/traits/function_traits.hpp +95 -0
- data/rice/traits/method_traits.hpp +47 -0
- data/rice/traits/rice_traits.hpp +160 -0
- data/rice.gemspec +85 -0
- data/test/embed_ruby.cpp +7 -1
- data/test/extconf.rb +2 -0
- data/test/test_Address_Registration_Guard.cpp +5 -0
- data/test/test_Array.cpp +18 -4
- data/test/test_Attribute.cpp +136 -21
- data/test/test_Buffer.cpp +285 -0
- data/test/test_Builtin_Object.cpp +5 -0
- data/test/test_Callback.cpp +230 -0
- data/test/test_Class.cpp +5 -31
- data/test/test_Constructor.cpp +69 -6
- data/test/test_Data_Object.cpp +97 -38
- data/test/test_Data_Type.cpp +470 -65
- data/test/test_Director.cpp +17 -8
- data/test/test_Enum.cpp +155 -40
- data/test/test_Exception.cpp +235 -0
- data/test/test_File.cpp +70 -0
- data/test/test_From_Ruby.cpp +609 -0
- data/test/test_Hash.cpp +5 -0
- data/test/test_Identifier.cpp +5 -0
- data/test/test_Inheritance.cpp +6 -1
- data/test/test_Iterator.cpp +6 -1
- data/test/test_Jump_Exception.cpp +23 -0
- data/test/test_Keep_Alive.cpp +13 -19
- data/test/test_Keep_Alive_No_Wrapper.cpp +5 -1
- data/test/test_Memory_Management.cpp +5 -0
- data/test/test_Module.cpp +128 -67
- data/test/test_Native_Registry.cpp +2 -34
- data/test/test_Object.cpp +5 -0
- data/test/test_Overloads.cpp +806 -0
- data/test/test_Ownership.cpp +160 -54
- data/test/test_Proc.cpp +44 -0
- data/test/test_Self.cpp +9 -4
- data/test/test_Stl_Exception.cpp +109 -0
- data/test/test_Stl_Map.cpp +54 -42
- data/test/test_Stl_Multimap.cpp +693 -0
- data/test/test_Stl_Optional.cpp +5 -0
- data/test/test_Stl_Pair.cpp +14 -9
- data/test/test_Stl_Reference_Wrapper.cpp +9 -2
- data/test/test_Stl_Set.cpp +790 -0
- data/test/test_Stl_SharedPtr.cpp +458 -0
- data/test/test_Stl_String.cpp +5 -0
- data/test/test_Stl_String_View.cpp +5 -0
- data/test/test_Stl_Tuple.cpp +116 -0
- data/test/test_Stl_Type.cpp +147 -0
- data/test/test_Stl_UniquePtr.cpp +202 -0
- data/test/test_Stl_Unordered_Map.cpp +43 -38
- data/test/test_Stl_Variant.cpp +217 -84
- data/test/test_Stl_Vector.cpp +306 -58
- data/test/test_String.cpp +5 -0
- data/test/test_Struct.cpp +5 -0
- data/test/test_Symbol.cpp +5 -0
- data/test/test_Template.cpp +192 -0
- data/test/test_To_Ruby.cpp +524 -0
- data/test/test_Tracking.cpp +1 -0
- data/test/test_Type.cpp +171 -0
- data/test/test_global_functions.cpp +67 -7
- data/test/unittest.cpp +8 -0
- metadata +127 -26
- data/lib/version.rb +0 -3
- data/rice/Address_Registration_Guard_defn.hpp +0 -79
- data/rice/Data_Object_defn.hpp +0 -84
- data/rice/Data_Type_defn.hpp +0 -190
- data/rice/Exception_defn.hpp +0 -68
- data/rice/HandlerRegistration.hpp +0 -15
- data/rice/detail/ExceptionHandler.hpp +0 -8
- data/rice/detail/ExceptionHandler.ipp +0 -28
- data/rice/detail/ExceptionHandler_defn.hpp +0 -77
- data/rice/detail/Jump_Tag.hpp +0 -21
- data/rice/detail/NativeAttribute.hpp +0 -64
- data/rice/detail/NativeAttribute.ipp +0 -112
- data/rice/detail/from_ruby_defn.hpp +0 -38
- data/rice/detail/to_ruby_defn.hpp +0 -48
- data/test/test_Jump_Tag.cpp +0 -17
- data/test/test_Stl_SmartPointer.cpp +0 -283
- data/test/test_To_From_Ruby.cpp +0 -399
data/test/test_Ownership.cpp
CHANGED
@@ -10,12 +10,11 @@ TESTSUITE(Ownership);
|
|
10
10
|
|
11
11
|
namespace
|
12
12
|
{
|
13
|
-
class
|
13
|
+
class MyCopyableClass
|
14
14
|
{
|
15
15
|
public:
|
16
16
|
static inline int constructorCalls = 0;
|
17
17
|
static inline int copyConstructorCalls = 0;
|
18
|
-
static inline int moveConstructorCalls = 0;
|
19
18
|
static inline int destructorCalls = 0;
|
20
19
|
static inline int methodCalls = 0;
|
21
20
|
|
@@ -23,7 +22,6 @@ namespace
|
|
23
22
|
{
|
24
23
|
constructorCalls = 0;
|
25
24
|
copyConstructorCalls = 0;
|
26
|
-
moveConstructorCalls = 0;
|
27
25
|
destructorCalls = 0;
|
28
26
|
methodCalls = 0;
|
29
27
|
}
|
@@ -32,22 +30,68 @@ namespace
|
|
32
30
|
int flag = 0;
|
33
31
|
|
34
32
|
public:
|
35
|
-
|
33
|
+
MyCopyableClass()
|
36
34
|
{
|
37
35
|
constructorCalls++;
|
38
36
|
}
|
39
37
|
|
40
|
-
~
|
38
|
+
~MyCopyableClass()
|
41
39
|
{
|
42
40
|
destructorCalls++;
|
43
41
|
}
|
44
42
|
|
45
|
-
|
43
|
+
MyCopyableClass(const MyCopyableClass& other): flag(other.flag)
|
46
44
|
{
|
47
45
|
copyConstructorCalls++;
|
48
46
|
}
|
49
47
|
|
50
|
-
|
48
|
+
MyCopyableClass(MyCopyableClass&& other) = delete;
|
49
|
+
|
50
|
+
int32_t process()
|
51
|
+
{
|
52
|
+
methodCalls++;
|
53
|
+
return methodCalls;
|
54
|
+
}
|
55
|
+
|
56
|
+
void setFlag(int value)
|
57
|
+
{
|
58
|
+
this->flag = value;
|
59
|
+
}
|
60
|
+
};
|
61
|
+
|
62
|
+
class MyMovableClass
|
63
|
+
{
|
64
|
+
public:
|
65
|
+
static inline int constructorCalls = 0;
|
66
|
+
static inline int moveConstructorCalls = 0;
|
67
|
+
static inline int destructorCalls = 0;
|
68
|
+
static inline int methodCalls = 0;
|
69
|
+
|
70
|
+
static void reset()
|
71
|
+
{
|
72
|
+
constructorCalls = 0;
|
73
|
+
moveConstructorCalls = 0;
|
74
|
+
destructorCalls = 0;
|
75
|
+
methodCalls = 0;
|
76
|
+
}
|
77
|
+
|
78
|
+
public:
|
79
|
+
int flag = 0;
|
80
|
+
|
81
|
+
public:
|
82
|
+
MyMovableClass()
|
83
|
+
{
|
84
|
+
constructorCalls++;
|
85
|
+
}
|
86
|
+
|
87
|
+
~MyMovableClass()
|
88
|
+
{
|
89
|
+
destructorCalls++;
|
90
|
+
}
|
91
|
+
|
92
|
+
MyMovableClass(const MyMovableClass& other) = delete;
|
93
|
+
|
94
|
+
MyMovableClass(MyMovableClass&& other) : flag(other.flag)
|
51
95
|
{
|
52
96
|
moveConstructorCalls++;
|
53
97
|
}
|
@@ -74,42 +118,47 @@ namespace
|
|
74
118
|
}
|
75
119
|
|
76
120
|
public:
|
77
|
-
|
121
|
+
MyCopyableClass* transferPointerToRuby()
|
78
122
|
{
|
79
|
-
return new
|
123
|
+
return new MyCopyableClass();
|
80
124
|
}
|
81
125
|
|
82
|
-
|
126
|
+
MyCopyableClass* keepPointer()
|
83
127
|
{
|
84
128
|
return this->instance();
|
85
129
|
}
|
86
130
|
|
87
|
-
|
131
|
+
MyCopyableClass& keepReference()
|
88
132
|
{
|
89
133
|
return *this->instance();
|
90
134
|
}
|
91
135
|
|
92
|
-
|
136
|
+
MyCopyableClass value()
|
137
|
+
{
|
138
|
+
return MyCopyableClass();
|
139
|
+
}
|
140
|
+
|
141
|
+
MyMovableClass moveValue()
|
93
142
|
{
|
94
|
-
return
|
143
|
+
return MyMovableClass();
|
95
144
|
}
|
96
145
|
|
97
|
-
|
146
|
+
void transferPointerToCpp(MyCopyableClass* myClass)
|
98
147
|
{
|
99
|
-
|
148
|
+
delete myClass;
|
100
149
|
}
|
101
150
|
|
102
|
-
|
151
|
+
MyCopyableClass* instance()
|
103
152
|
{
|
104
153
|
if (!instance_)
|
105
154
|
{
|
106
|
-
instance_ = new
|
155
|
+
instance_ = new MyCopyableClass();
|
107
156
|
}
|
108
157
|
return instance_;
|
109
158
|
}
|
110
159
|
|
111
160
|
public:
|
112
|
-
static inline
|
161
|
+
static inline MyCopyableClass* instance_ = nullptr;
|
113
162
|
};
|
114
163
|
}
|
115
164
|
|
@@ -117,30 +166,42 @@ SETUP(Ownership)
|
|
117
166
|
{
|
118
167
|
embed_ruby();
|
119
168
|
|
120
|
-
define_class<
|
121
|
-
|
122
|
-
define_method("
|
169
|
+
define_class<MyCopyableClass>("MyCopyableClass").
|
170
|
+
define_constructor(Constructor<MyCopyableClass>()).
|
171
|
+
define_method("process", &MyCopyableClass::process).
|
172
|
+
define_method("set_flag", &MyCopyableClass::setFlag);
|
173
|
+
|
174
|
+
define_class<MyMovableClass>("MyMovableClass").
|
175
|
+
define_constructor(Constructor<MyMovableClass>()).
|
176
|
+
define_method("process", &MyMovableClass::process).
|
177
|
+
define_method("set_flag", &MyMovableClass::setFlag);
|
123
178
|
|
124
179
|
define_class<Factory>("Factory").
|
125
180
|
define_constructor(Constructor<Factory>()).
|
126
181
|
define_method("value", &Factory::value).
|
127
182
|
define_method("move_value", &Factory::moveValue).
|
128
|
-
define_method("
|
183
|
+
define_method("transfer_pointer_to_ruby", &Factory::transferPointerToRuby, Return().takeOwnership()).
|
184
|
+
define_method("transfer_pointer_to_cpp", &Factory::transferPointerToCpp, Arg("myClass").takeOwnership()).
|
129
185
|
define_method("keep_pointer", &Factory::keepPointer).
|
130
186
|
define_method("copy_reference", &Factory::keepReference, Return().takeOwnership()).
|
131
187
|
define_method("keep_reference", &Factory::keepReference);
|
132
188
|
}
|
133
189
|
|
134
|
-
|
190
|
+
TEARDOWN(Ownership)
|
191
|
+
{
|
192
|
+
rb_gc_start();
|
193
|
+
}
|
194
|
+
|
195
|
+
TESTCASE(TransferPointerToRuby)
|
135
196
|
{
|
136
197
|
Factory::reset();
|
137
|
-
|
198
|
+
MyCopyableClass::reset();
|
138
199
|
|
139
200
|
Module m = define_module("TestingModule");
|
140
201
|
|
141
202
|
std::string code = R"(factory = Factory.new
|
142
203
|
10.times do |i|
|
143
|
-
my_class = factory.
|
204
|
+
my_class = factory.transfer_pointer_to_ruby
|
144
205
|
my_class.set_flag(i)
|
145
206
|
my_class = nil
|
146
207
|
end)";
|
@@ -148,17 +209,33 @@ TESTCASE(TransferPointer)
|
|
148
209
|
m.module_eval(code);
|
149
210
|
rb_gc_start();
|
150
211
|
|
151
|
-
ASSERT_EQUAL(10,
|
152
|
-
ASSERT_EQUAL(0,
|
153
|
-
ASSERT_EQUAL(
|
154
|
-
ASSERT_EQUAL(10, MyClass::destructorCalls);
|
212
|
+
ASSERT_EQUAL(10, MyCopyableClass::constructorCalls);
|
213
|
+
ASSERT_EQUAL(0, MyCopyableClass::copyConstructorCalls);
|
214
|
+
ASSERT_EQUAL(10, MyCopyableClass::destructorCalls);
|
155
215
|
ASSERT(!Factory::instance_);
|
156
216
|
}
|
157
217
|
|
218
|
+
TESTCASE(TransferPointerToCpp)
|
219
|
+
{
|
220
|
+
Factory::reset();
|
221
|
+
MyCopyableClass::reset();
|
222
|
+
|
223
|
+
Module m = define_module("TestingModule");
|
224
|
+
|
225
|
+
std::string code = R"(myClass = MyCopyableClass.new
|
226
|
+
factory = Factory.new
|
227
|
+
factory.transfer_pointer_to_cpp(myClass))";
|
228
|
+
|
229
|
+
m.module_eval(code);
|
230
|
+
rb_gc_start();
|
231
|
+
|
232
|
+
ASSERT(true);
|
233
|
+
}
|
234
|
+
|
158
235
|
TESTCASE(KeepPointer)
|
159
236
|
{
|
160
237
|
Factory::reset();
|
161
|
-
|
238
|
+
MyCopyableClass::reset();
|
162
239
|
|
163
240
|
Module m = define_module("TestingModule");
|
164
241
|
|
@@ -172,17 +249,16 @@ TESTCASE(KeepPointer)
|
|
172
249
|
m.module_eval(code);
|
173
250
|
rb_gc_start();
|
174
251
|
|
175
|
-
ASSERT_EQUAL(1,
|
176
|
-
ASSERT_EQUAL(0,
|
177
|
-
ASSERT_EQUAL(0,
|
178
|
-
ASSERT_EQUAL(0, MyClass::destructorCalls);
|
252
|
+
ASSERT_EQUAL(1, MyCopyableClass::constructorCalls);
|
253
|
+
ASSERT_EQUAL(0, MyCopyableClass::copyConstructorCalls);
|
254
|
+
ASSERT_EQUAL(0, MyCopyableClass::destructorCalls);
|
179
255
|
ASSERT_EQUAL(9, Factory::instance_->flag);
|
180
256
|
}
|
181
257
|
|
182
258
|
TESTCASE(KeepReference)
|
183
259
|
{
|
184
260
|
Factory::reset();
|
185
|
-
|
261
|
+
MyCopyableClass::reset();
|
186
262
|
|
187
263
|
Module m = define_module("TestingModule");
|
188
264
|
|
@@ -196,17 +272,16 @@ TESTCASE(KeepReference)
|
|
196
272
|
m.module_eval(code);
|
197
273
|
rb_gc_start();
|
198
274
|
|
199
|
-
ASSERT_EQUAL(1,
|
200
|
-
ASSERT_EQUAL(0,
|
201
|
-
ASSERT_EQUAL(0,
|
202
|
-
ASSERT_EQUAL(0, MyClass::destructorCalls);
|
275
|
+
ASSERT_EQUAL(1, MyCopyableClass::constructorCalls);
|
276
|
+
ASSERT_EQUAL(0, MyCopyableClass::copyConstructorCalls);
|
277
|
+
ASSERT_EQUAL(0, MyCopyableClass::destructorCalls);
|
203
278
|
ASSERT_EQUAL(9, Factory::instance_->flag);
|
204
279
|
}
|
205
280
|
|
206
281
|
TESTCASE(CopyReference)
|
207
282
|
{
|
208
283
|
Factory::reset();
|
209
|
-
|
284
|
+
MyCopyableClass::reset();
|
210
285
|
|
211
286
|
Module m = define_module("TestingModule");
|
212
287
|
|
@@ -220,17 +295,16 @@ TESTCASE(CopyReference)
|
|
220
295
|
m.module_eval(code);
|
221
296
|
rb_gc_start();
|
222
297
|
|
223
|
-
ASSERT_EQUAL(1,
|
224
|
-
ASSERT_EQUAL(
|
225
|
-
ASSERT_EQUAL(10,
|
226
|
-
ASSERT_EQUAL(10, MyClass::destructorCalls);
|
298
|
+
ASSERT_EQUAL(1, MyCopyableClass::constructorCalls);
|
299
|
+
ASSERT_EQUAL(10, MyCopyableClass::copyConstructorCalls);
|
300
|
+
ASSERT_EQUAL(10, MyCopyableClass::destructorCalls);
|
227
301
|
ASSERT_EQUAL(0, Factory::instance_->flag);
|
228
302
|
}
|
229
303
|
|
230
304
|
TESTCASE(TransferValue)
|
231
305
|
{
|
232
306
|
Factory::reset();
|
233
|
-
|
307
|
+
MyCopyableClass::reset();
|
234
308
|
|
235
309
|
Module m = define_module("TestingModule");
|
236
310
|
|
@@ -243,17 +317,16 @@ TESTCASE(TransferValue)
|
|
243
317
|
m.module_eval(code);
|
244
318
|
rb_gc_start();
|
245
319
|
|
246
|
-
ASSERT_EQUAL(10,
|
247
|
-
ASSERT_EQUAL(
|
248
|
-
ASSERT_EQUAL(
|
249
|
-
ASSERT_EQUAL(20, MyClass::destructorCalls);
|
320
|
+
ASSERT_EQUAL(10, MyCopyableClass::constructorCalls);
|
321
|
+
ASSERT_EQUAL(10, MyCopyableClass::copyConstructorCalls);
|
322
|
+
ASSERT_EQUAL(20, MyCopyableClass::destructorCalls);
|
250
323
|
ASSERT(!Factory::instance_);
|
251
324
|
}
|
252
325
|
|
253
326
|
TESTCASE(MoveValue)
|
254
327
|
{
|
255
328
|
Factory::reset();
|
256
|
-
|
329
|
+
MyCopyableClass::reset();
|
257
330
|
|
258
331
|
Module m = define_module("TestingModule");
|
259
332
|
|
@@ -266,9 +339,42 @@ TESTCASE(MoveValue)
|
|
266
339
|
m.module_eval(code);
|
267
340
|
rb_gc_start();
|
268
341
|
|
269
|
-
ASSERT_EQUAL(10,
|
270
|
-
ASSERT_EQUAL(
|
271
|
-
ASSERT_EQUAL(20,
|
272
|
-
ASSERT_EQUAL(30, MyClass::destructorCalls);
|
342
|
+
ASSERT_EQUAL(10, MyMovableClass::constructorCalls);
|
343
|
+
ASSERT_EQUAL(10, MyMovableClass::moveConstructorCalls);
|
344
|
+
ASSERT_EQUAL(20, MyMovableClass::destructorCalls);
|
273
345
|
ASSERT(!Factory::instance_);
|
274
346
|
}
|
347
|
+
|
348
|
+
namespace
|
349
|
+
{
|
350
|
+
class MyClassNotCopyable
|
351
|
+
{
|
352
|
+
public:
|
353
|
+
MyClassNotCopyable() = default;
|
354
|
+
MyClassNotCopyable(const MyClassNotCopyable& other) = delete;
|
355
|
+
MyClassNotCopyable(MyClassNotCopyable&& other) = delete;
|
356
|
+
int value;
|
357
|
+
};
|
358
|
+
}
|
359
|
+
|
360
|
+
TESTCASE(NotCopyable)
|
361
|
+
{
|
362
|
+
Class c = define_class<MyClassNotCopyable>("MyClassNotCopyable")
|
363
|
+
.define_constructor(Constructor<MyClassNotCopyable>())
|
364
|
+
.define_attr("value", &MyClassNotCopyable::value);
|
365
|
+
|
366
|
+
MyClassNotCopyable instance;
|
367
|
+
|
368
|
+
#ifdef _MSC_VER
|
369
|
+
const char* expected = "Rice was directed to take ownership of a C++ object but it does not have an accessible copy or move constructor. Type: class `anonymous namespace'::MyClassNotCopyable";
|
370
|
+
#else
|
371
|
+
const char* expected = "Rice was directed to take ownership of a C++ object but it does not have an accessible copy or move constructor. Type: (anonymous namespace)::MyClassNotCopyable";
|
372
|
+
#endif
|
373
|
+
|
374
|
+
// Trying to take ownership should fail
|
375
|
+
ASSERT_EXCEPTION_CHECK(
|
376
|
+
std::runtime_error,
|
377
|
+
Data_Object<MyClassNotCopyable>(instance, true),
|
378
|
+
ASSERT_EQUAL(expected, ex.what())
|
379
|
+
);
|
380
|
+
}
|
data/test/test_Proc.cpp
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
#include <functional>
|
2
|
+
|
3
|
+
#include "unittest.hpp"
|
4
|
+
#include "embed_ruby.hpp"
|
5
|
+
#include <rice/rice.hpp>
|
6
|
+
|
7
|
+
using namespace Rice;
|
8
|
+
|
9
|
+
TESTSUITE(Proc);
|
10
|
+
|
11
|
+
SETUP(Proc)
|
12
|
+
{
|
13
|
+
embed_ruby();
|
14
|
+
}
|
15
|
+
|
16
|
+
TEARDOWN(Proc)
|
17
|
+
{
|
18
|
+
rb_gc_start();
|
19
|
+
}
|
20
|
+
|
21
|
+
namespace
|
22
|
+
{
|
23
|
+
int square(int i)
|
24
|
+
{
|
25
|
+
return i * i;
|
26
|
+
}
|
27
|
+
|
28
|
+
auto squareProc()
|
29
|
+
{
|
30
|
+
return square;
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
TESTCASE(SquareProc)
|
35
|
+
{
|
36
|
+
Module m = define_module("TestingModuleMakeProc");
|
37
|
+
m.define_module_function("square_proc", squareProc);
|
38
|
+
|
39
|
+
std::string code = R"(proc = square_proc
|
40
|
+
proc.call(9))";
|
41
|
+
|
42
|
+
Object result = m.module_eval(code);
|
43
|
+
ASSERT_EQUAL(81, detail::From_Ruby<int>().convert(result));
|
44
|
+
}
|
data/test/test_Self.cpp
CHANGED
@@ -89,6 +89,11 @@ SETUP(Self)
|
|
89
89
|
});
|
90
90
|
}
|
91
91
|
|
92
|
+
TEARDOWN(Self)
|
93
|
+
{
|
94
|
+
rb_gc_start();
|
95
|
+
}
|
96
|
+
|
92
97
|
TESTCASE(SelfPointer)
|
93
98
|
{
|
94
99
|
SelfClass::reset();
|
@@ -141,8 +146,8 @@ TESTCASE(SelfValue)
|
|
141
146
|
ASSERT((pointer1 != pointer2));
|
142
147
|
|
143
148
|
ASSERT_EQUAL(1, SelfClass::constructorCalls);
|
144
|
-
ASSERT_EQUAL(
|
145
|
-
ASSERT_EQUAL(
|
149
|
+
ASSERT_EQUAL(2, SelfClass::copyConstructorCalls);
|
150
|
+
ASSERT_EQUAL(0, SelfClass::moveConstructorCalls);
|
146
151
|
ASSERT_EQUAL(1, SelfClass::destructorCalls);
|
147
152
|
}
|
148
153
|
|
@@ -198,7 +203,7 @@ TESTCASE(SelfValueLambda)
|
|
198
203
|
ASSERT((pointer1 != pointer2));
|
199
204
|
|
200
205
|
ASSERT_EQUAL(1, SelfClass::constructorCalls);
|
201
|
-
ASSERT_EQUAL(
|
202
|
-
ASSERT_EQUAL(
|
206
|
+
ASSERT_EQUAL(2, SelfClass::copyConstructorCalls);
|
207
|
+
ASSERT_EQUAL(0, SelfClass::moveConstructorCalls);
|
203
208
|
ASSERT_EQUAL(1, SelfClass::destructorCalls);
|
204
209
|
}
|
@@ -0,0 +1,109 @@
|
|
1
|
+
#include <complex>
|
2
|
+
#include <memory>
|
3
|
+
|
4
|
+
#include "unittest.hpp"
|
5
|
+
#include "embed_ruby.hpp"
|
6
|
+
#include <rice/rice.hpp>
|
7
|
+
#include <rice/stl.hpp>
|
8
|
+
|
9
|
+
using namespace Rice;
|
10
|
+
|
11
|
+
TESTSUITE(StlException);
|
12
|
+
|
13
|
+
SETUP(StlException)
|
14
|
+
{
|
15
|
+
embed_ruby();
|
16
|
+
}
|
17
|
+
|
18
|
+
TEARDOWN(StlException)
|
19
|
+
{
|
20
|
+
rb_gc_start();
|
21
|
+
}
|
22
|
+
|
23
|
+
namespace
|
24
|
+
{
|
25
|
+
class MyException: public std::exception
|
26
|
+
{
|
27
|
+
};
|
28
|
+
|
29
|
+
void raiseMyException()
|
30
|
+
{
|
31
|
+
throw MyException();
|
32
|
+
}
|
33
|
+
|
34
|
+
}
|
35
|
+
|
36
|
+
TESTCASE(StlExceptionCreate)
|
37
|
+
{
|
38
|
+
Class MyExceptionKlass = define_class<MyException, std::exception>("MyException");
|
39
|
+
|
40
|
+
auto handler = [MyExceptionKlass]()
|
41
|
+
{
|
42
|
+
try
|
43
|
+
{
|
44
|
+
throw;
|
45
|
+
}
|
46
|
+
catch (const MyException& exception)
|
47
|
+
{
|
48
|
+
Data_Object<MyException> wrapper(exception, true);
|
49
|
+
rb_exc_raise(wrapper.value());
|
50
|
+
}
|
51
|
+
};
|
52
|
+
detail::Registries::instance.handlers.set(handler);
|
53
|
+
|
54
|
+
Module m = define_module("Testing");
|
55
|
+
m.define_singleton_function("raise_my_exception", &raiseMyException);
|
56
|
+
|
57
|
+
std::string code = R"(begin
|
58
|
+
raise_my_exception
|
59
|
+
rescue MyException => exception
|
60
|
+
$!
|
61
|
+
end)";
|
62
|
+
|
63
|
+
Object object = m.instance_eval(code);
|
64
|
+
ASSERT_EQUAL(MyExceptionKlass.value(), object.class_of().value());
|
65
|
+
}
|
66
|
+
|
67
|
+
namespace
|
68
|
+
{
|
69
|
+
std::exception_ptr createExceptionPtr()
|
70
|
+
{
|
71
|
+
std::exception_ptr eptr;
|
72
|
+
|
73
|
+
try
|
74
|
+
{
|
75
|
+
[[maybe_unused]]
|
76
|
+
char ch = std::string().at(1); // this generates a std::out_of_range
|
77
|
+
}
|
78
|
+
catch (...)
|
79
|
+
{
|
80
|
+
eptr = std::current_exception(); // capture
|
81
|
+
}
|
82
|
+
|
83
|
+
return eptr;
|
84
|
+
}
|
85
|
+
|
86
|
+
void handleExceptionPtr(std::exception_ptr eptr)
|
87
|
+
{
|
88
|
+
std::rethrow_exception(eptr);
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
TESTCASE(StlExceptionPtr)
|
93
|
+
{
|
94
|
+
Module m = define_module("TestingModule");
|
95
|
+
m.define_module_function("create_exception_ptr", createExceptionPtr).
|
96
|
+
define_module_function("handle_exception_ptr", handleExceptionPtr);
|
97
|
+
|
98
|
+
Data_Object<std::exception_ptr> exception = m.call("create_exception_ptr");
|
99
|
+
VALUE value = exception.value();
|
100
|
+
std::exception_ptr* ptr = exception.get();
|
101
|
+
ASSERT((value != Qnil));
|
102
|
+
ASSERT((ptr != nullptr));
|
103
|
+
|
104
|
+
ASSERT_EXCEPTION_CHECK(
|
105
|
+
Exception,
|
106
|
+
m.call("handle_exception_ptr", exception),
|
107
|
+
ASSERT_EQUAL(rb_eIndexError, ex.class_of())
|
108
|
+
);
|
109
|
+
}
|