rice 4.3.3 → 4.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +63 -26
- data/README.md +7 -2
- data/Rakefile +7 -1
- data/include/rice/rice.hpp +7291 -4430
- data/include/rice/stl.hpp +769 -222
- data/lib/mkmf-rice.rb +37 -95
- data/rice/Address_Registration_Guard.hpp +72 -3
- data/rice/Arg.hpp +19 -5
- data/rice/Arg.ipp +24 -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 +74 -3
- data/rice/Data_Object.ipp +324 -32
- data/rice/Data_Type.hpp +215 -3
- data/rice/Data_Type.ipp +125 -64
- data/rice/Director.hpp +0 -2
- data/rice/Enum.hpp +4 -6
- data/rice/Enum.ipp +101 -57
- data/rice/Exception.hpp +62 -2
- data/rice/Exception.ipp +7 -12
- data/rice/JumpException.hpp +44 -0
- data/rice/JumpException.ipp +48 -0
- data/rice/MemoryView.hpp +11 -0
- data/rice/MemoryView.ipp +43 -0
- data/rice/Return.hpp +6 -26
- data/rice/Return.ipp +10 -16
- 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 +15 -5
- data/rice/detail/MethodInfo.ipp +78 -6
- data/rice/detail/Native.hpp +32 -0
- data/rice/detail/Native.ipp +129 -0
- data/rice/detail/NativeAttributeGet.hpp +51 -0
- data/rice/detail/NativeAttributeGet.ipp +51 -0
- data/rice/detail/NativeAttributeSet.hpp +43 -0
- data/rice/detail/NativeAttributeSet.ipp +82 -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 +20 -21
- data/rice/detail/NativeFunction.ipp +199 -64
- data/rice/detail/NativeIterator.hpp +8 -11
- data/rice/detail/NativeIterator.ipp +27 -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 +19 -0
- data/rice/detail/RubyType.ipp +187 -0
- data/rice/detail/TupleIterator.hpp +14 -0
- data/rice/detail/Type.hpp +5 -6
- data/rice/detail/Type.ipp +150 -33
- data/rice/detail/TypeRegistry.hpp +15 -7
- data/rice/detail/TypeRegistry.ipp +105 -12
- data/rice/detail/Wrapper.hpp +6 -5
- data/rice/detail/Wrapper.ipp +45 -23
- data/rice/detail/cpp_protect.hpp +5 -6
- data/rice/detail/default_allocation_func.ipp +0 -2
- data/rice/detail/from_ruby.hpp +37 -3
- data/rice/detail/from_ruby.ipp +911 -454
- data/rice/detail/ruby.hpp +18 -0
- data/rice/detail/to_ruby.hpp +41 -3
- data/rice/detail/to_ruby.ipp +437 -113
- data/rice/global_function.hpp +0 -4
- data/rice/global_function.ipp +1 -2
- data/rice/rice.hpp +105 -22
- data/rice/ruby_mark.hpp +4 -3
- data/rice/stl.hpp +4 -0
- data/test/embed_ruby.cpp +4 -1
- data/test/extconf.rb +2 -0
- data/test/ruby/test_multiple_extensions_same_class.rb +14 -14
- data/test/test_Address_Registration_Guard.cpp +5 -0
- data/test/test_Array.cpp +12 -1
- data/test/test_Attribute.cpp +103 -21
- data/test/test_Builtin_Object.cpp +5 -0
- data/test/test_Callback.cpp +231 -0
- data/test/test_Class.cpp +5 -31
- data/test/test_Constructor.cpp +69 -6
- data/test/test_Data_Object.cpp +9 -4
- data/test/test_Data_Type.cpp +428 -64
- data/test/test_Director.cpp +10 -5
- data/test/test_Enum.cpp +152 -40
- data/test/test_Exception.cpp +235 -0
- data/test/test_File.cpp +70 -0
- data/test/test_From_Ruby.cpp +542 -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 +5 -0
- data/test/test_JumpException.cpp +22 -0
- data/test/test_Keep_Alive.cpp +6 -1
- data/test/test_Keep_Alive_No_Wrapper.cpp +5 -0
- data/test/test_Memory_Management.cpp +5 -0
- data/test/test_Module.cpp +118 -64
- data/test/test_Native_Registry.cpp +2 -33
- data/test/test_Object.cpp +5 -0
- data/test/test_Overloads.cpp +631 -0
- data/test/test_Ownership.cpp +67 -4
- data/test/test_Proc.cpp +45 -0
- data/test/test_Self.cpp +5 -0
- data/test/test_Stl_Exception.cpp +109 -0
- data/test/test_Stl_Map.cpp +22 -8
- data/test/test_Stl_Optional.cpp +5 -0
- data/test/test_Stl_Pair.cpp +7 -2
- data/test/test_Stl_Reference_Wrapper.cpp +5 -0
- data/test/test_Stl_SmartPointer.cpp +210 -5
- data/test/test_Stl_String.cpp +5 -0
- data/test/test_Stl_String_View.cpp +5 -0
- data/test/test_Stl_Type.cpp +147 -0
- data/test/test_Stl_Unordered_Map.cpp +18 -7
- data/test/test_Stl_Variant.cpp +5 -0
- data/test/test_Stl_Vector.cpp +130 -8
- 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 +152 -0
- data/test/test_Tracking.cpp +1 -0
- data/test/test_Type.cpp +100 -0
- data/test/test_global_functions.cpp +53 -6
- data/test/unittest.cpp +8 -0
- metadata +37 -20
- 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/Identifier.hpp +0 -50
- data/rice/Identifier.ipp +0 -29
- 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_To_From_Ruby.cpp +0 -399
data/test/test_Module.cpp
CHANGED
@@ -13,6 +13,11 @@ SETUP(Module)
|
|
13
13
|
embed_ruby();
|
14
14
|
}
|
15
15
|
|
16
|
+
TEARDOWN(Module)
|
17
|
+
{
|
18
|
+
rb_gc_start();
|
19
|
+
}
|
20
|
+
|
16
21
|
TESTCASE(FromConstant)
|
17
22
|
{
|
18
23
|
Module m(rb_mEnumerable);
|
@@ -27,59 +32,51 @@ TESTCASE(FromName)
|
|
27
32
|
|
28
33
|
namespace
|
29
34
|
{
|
35
|
+
class MyClass
|
36
|
+
{
|
37
|
+
public:
|
38
|
+
MyClass() = default;
|
39
|
+
};
|
30
40
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
}
|
35
|
-
|
36
|
-
void handle_silly_exception(Quite_Silly_Exception const & ex)
|
37
|
-
{
|
38
|
-
throw Exception(rb_eRuntimeError, "SILLY");
|
39
|
-
}
|
40
|
-
|
41
|
-
void throw_silly_exception(Object self)
|
42
|
-
{
|
43
|
-
throw Quite_Silly_Exception();
|
44
|
-
}
|
45
|
-
|
46
|
-
} // namespace
|
47
|
-
|
48
|
-
TESTCASE(add_handler)
|
49
|
-
{
|
50
|
-
register_handler<Quite_Silly_Exception>(handle_silly_exception);
|
41
|
+
bool some_function()
|
42
|
+
{
|
43
|
+
return true;
|
44
|
+
}
|
51
45
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
Exception ex(exc);
|
57
|
-
ASSERT_EQUAL(String("SILLY"), String(ex.what()));
|
58
|
-
}
|
46
|
+
Object some_method(Object o)
|
47
|
+
{
|
48
|
+
return o;
|
49
|
+
}
|
59
50
|
|
60
|
-
|
61
|
-
{
|
51
|
+
int function_int(int i)
|
52
|
+
{
|
53
|
+
return i;
|
54
|
+
}
|
62
55
|
|
63
|
-
|
64
|
-
{
|
65
|
-
|
66
|
-
}
|
56
|
+
int method_int(Object object, int i)
|
57
|
+
{
|
58
|
+
return i;
|
59
|
+
}
|
67
60
|
|
68
|
-
|
69
|
-
{
|
70
|
-
|
71
|
-
}
|
61
|
+
bool method_lvalue(MyClass& myClass)
|
62
|
+
{
|
63
|
+
return true;
|
64
|
+
}
|
72
65
|
|
73
|
-
|
74
|
-
{
|
75
|
-
|
76
|
-
}
|
66
|
+
bool method_rvalue(MyClass&& myClass)
|
67
|
+
{
|
68
|
+
return true;
|
69
|
+
}
|
77
70
|
|
78
|
-
|
79
|
-
{
|
80
|
-
|
81
|
-
}
|
71
|
+
void method_lvalue_return_void(int a, MyClass& myClass)
|
72
|
+
{
|
73
|
+
// Do nothing
|
74
|
+
}
|
82
75
|
|
76
|
+
void method_rvalue_return_void(int b, MyClass&& myClass)
|
77
|
+
{
|
78
|
+
// Do nothing
|
79
|
+
}
|
83
80
|
} // namespace
|
84
81
|
|
85
82
|
TESTCASE(define_method)
|
@@ -180,14 +177,18 @@ TESTCASE(method_int_passed_no_args)
|
|
180
177
|
{
|
181
178
|
Module m(anonymous_module());
|
182
179
|
m.define_method("foo", method_int);
|
180
|
+
|
183
181
|
ASSERT_EXCEPTION_CHECK(
|
184
182
|
Exception,
|
185
183
|
m.module_eval("o = Object.new; o.extend(self); o.foo"),
|
186
|
-
ASSERT_EQUAL(
|
187
|
-
Object(rb_eArgError),
|
188
|
-
Object(CLASS_OF(ex.value()))
|
189
|
-
)
|
184
|
+
ASSERT_EQUAL(Object(rb_eArgError), Object(CLASS_OF(ex.value())))
|
190
185
|
);
|
186
|
+
|
187
|
+
ASSERT_EXCEPTION_CHECK(
|
188
|
+
Exception,
|
189
|
+
m.module_eval("o = Object.new; o.extend(self); o.foo"),
|
190
|
+
ASSERT_EQUAL("wrong number of arguments (given 0, expected 1)", ex.what())
|
191
|
+
);
|
191
192
|
}
|
192
193
|
|
193
194
|
TESTCASE(define_singleton_method_int_foo)
|
@@ -263,22 +264,28 @@ TESTCASE(default_arguments_still_throws_argument_error)
|
|
263
264
|
m.define_function("foo", &defaults_method_one, Arg("arg1"), Arg("arg2") = 3, Arg("arg3") = true);
|
264
265
|
|
265
266
|
ASSERT_EXCEPTION_CHECK(
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
Object(CLASS_OF(ex.value()))
|
271
|
-
)
|
272
|
-
);
|
267
|
+
Exception,
|
268
|
+
m.module_eval("o = Object.new; o.extend(self); o.foo()"),
|
269
|
+
ASSERT_EQUAL(Object(rb_eArgError), Object(CLASS_OF(ex.value())))
|
270
|
+
);
|
273
271
|
|
274
272
|
ASSERT_EXCEPTION_CHECK(
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
273
|
+
Exception,
|
274
|
+
m.module_eval("o = Object.new; o.extend(self); o.foo()"),
|
275
|
+
ASSERT_EQUAL("wrong number of arguments (given 0, expected 1..3)", ex.what())
|
276
|
+
);
|
277
|
+
|
278
|
+
ASSERT_EXCEPTION_CHECK(
|
279
|
+
Exception,
|
280
|
+
m.module_eval("o = Object.new; o.extend(self); o.foo(3, 4, false, 17)"),
|
281
|
+
ASSERT_EQUAL(Object(rb_eArgError), Object(CLASS_OF(ex.value())))
|
282
|
+
);
|
283
|
+
|
284
|
+
ASSERT_EXCEPTION_CHECK(
|
285
|
+
Exception,
|
286
|
+
m.module_eval("o = Object.new; o.extend(self); o.foo(3, 4, false, 17)"),
|
287
|
+
ASSERT_EQUAL("wrong number of arguments (given 4, expected 1..3)", ex.what())
|
288
|
+
);
|
282
289
|
}
|
283
290
|
|
284
291
|
namespace {
|
@@ -515,4 +522,51 @@ TESTCASE(references)
|
|
515
522
|
ASSERT_EQUAL(boolValue, true);
|
516
523
|
ASSERT_EQUAL(floatValue, 43.0);
|
517
524
|
ASSERT_EQUAL(doubleValue, 44.0);
|
518
|
-
}
|
525
|
+
}
|
526
|
+
|
527
|
+
TESTCASE(lvalue_function)
|
528
|
+
{
|
529
|
+
Module m(anonymous_module());
|
530
|
+
Class c = define_class<MyClass>("MyClass").
|
531
|
+
define_constructor(Constructor<MyClass>());
|
532
|
+
|
533
|
+
m.define_module_function("method_lvalue", &method_lvalue);
|
534
|
+
m.define_module_function("method_lvalue_return_void", &method_lvalue_return_void);
|
535
|
+
|
536
|
+
Object result = m.module_eval(R"(o = MyClass.new
|
537
|
+
method_lvalue_return_void(1, o)
|
538
|
+
method_lvalue(o))");
|
539
|
+
|
540
|
+
ASSERT_EQUAL(Qtrue, result.value());
|
541
|
+
}
|
542
|
+
|
543
|
+
TESTCASE(rvalue_function)
|
544
|
+
{
|
545
|
+
Module m(anonymous_module());
|
546
|
+
Class c = define_class<MyClass>("MyClass").
|
547
|
+
define_constructor(Constructor<MyClass>());
|
548
|
+
|
549
|
+
m.define_module_function("method_rvalue", &method_rvalue);
|
550
|
+
m.define_module_function("method_rvalue_return_void", &method_rvalue_return_void);
|
551
|
+
|
552
|
+
Object result = m.module_eval(R"(o = MyClass.new
|
553
|
+
method_rvalue_return_void(1, o)
|
554
|
+
method_rvalue(o))");
|
555
|
+
|
556
|
+
ASSERT_EQUAL(Qtrue, result.value());
|
557
|
+
}
|
558
|
+
|
559
|
+
namespace {
|
560
|
+
namespace Constants {
|
561
|
+
#define MY_PI 314
|
562
|
+
}
|
563
|
+
}
|
564
|
+
|
565
|
+
TESTCASE(constants)
|
566
|
+
{
|
567
|
+
Module m = anonymous_module().
|
568
|
+
define_constant("MY_PI", MY_PI);
|
569
|
+
|
570
|
+
Object result = m.module_eval(R"(MY_PI)");
|
571
|
+
ASSERT_EQUAL(314, detail::From_Ruby<int>().convert(result.value()));
|
572
|
+
}
|
@@ -13,38 +13,7 @@ SETUP(NativeRegistry)
|
|
13
13
|
embed_ruby();
|
14
14
|
}
|
15
15
|
|
16
|
-
|
16
|
+
TEARDOWN(NativeRegistry)
|
17
17
|
{
|
18
|
-
|
19
|
-
int scale = 1000;
|
20
|
-
|
21
|
-
for (int i = 0; i < std::size(classes); i++)
|
22
|
-
{
|
23
|
-
Class cls(anonymous_class());
|
24
|
-
|
25
|
-
for (int j = 0; j < scale; j++)
|
26
|
-
{
|
27
|
-
cls.define_function("int" + std::to_string(j), []() { return 1; });
|
28
|
-
cls.define_function("long" + std::to_string(j), []() { return 1L; });
|
29
|
-
cls.define_function("double" + std::to_string(j), []() { return 1.0; });
|
30
|
-
cls.define_function("float" + std::to_string(j), []() { return 1.0f; });
|
31
|
-
cls.define_function("bool" + std::to_string(j), []() { return true; });
|
32
|
-
}
|
33
|
-
|
34
|
-
classes[i] = cls;
|
35
|
-
}
|
36
|
-
|
37
|
-
for (auto& cls : classes)
|
38
|
-
{
|
39
|
-
auto obj = cls.call("new");
|
40
|
-
|
41
|
-
for (int j = 0; j < scale; j++)
|
42
|
-
{
|
43
|
-
obj.call("int" + std::to_string(j));
|
44
|
-
obj.call("long" + std::to_string(j));
|
45
|
-
obj.call("double" + std::to_string(j));
|
46
|
-
obj.call("float" + std::to_string(j));
|
47
|
-
obj.call("bool" + std::to_string(j));
|
48
|
-
}
|
49
|
-
}
|
18
|
+
rb_gc_start();
|
50
19
|
}
|