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_Data_Type.cpp
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#include <assert.h>
|
1
|
+
#include <assert.h>
|
2
2
|
|
3
3
|
#include "unittest.hpp"
|
4
4
|
#include "embed_ruby.hpp"
|
@@ -14,13 +14,11 @@ SETUP(Data_Type)
|
|
14
14
|
embed_ruby();
|
15
15
|
}
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
* to see what we're talking about.
|
23
|
-
*/
|
17
|
+
TEARDOWN(Data_Type)
|
18
|
+
{
|
19
|
+
Rice::detail::Registries::instance.types.clearUnverifiedTypes();
|
20
|
+
rb_gc_start();
|
21
|
+
}
|
24
22
|
|
25
23
|
namespace
|
26
24
|
{
|
@@ -79,7 +77,7 @@ namespace
|
|
79
77
|
std::to_string(f) + ", " + s + ", " + std::string(c) + ")";
|
80
78
|
}
|
81
79
|
};
|
82
|
-
}
|
80
|
+
}
|
83
81
|
|
84
82
|
TESTCASE(methods_with_member_pointers)
|
85
83
|
{
|
@@ -110,6 +108,59 @@ TESTCASE(methods_with_member_pointers)
|
|
110
108
|
ASSERT_EQUAL("multiple_args(81, 1, 7.000000, a string, a char)", detail::From_Ruby<std::string>().convert(result.value()));
|
111
109
|
}
|
112
110
|
|
111
|
+
namespace
|
112
|
+
{
|
113
|
+
class MyClassOriginal
|
114
|
+
{
|
115
|
+
|
116
|
+
};
|
117
|
+
|
118
|
+
namespace InnerNamespace
|
119
|
+
{
|
120
|
+
class MyClassOriginal
|
121
|
+
{
|
122
|
+
};
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
TESTCASE(define_class_twice)
|
127
|
+
{
|
128
|
+
Module module(rb_cObject);
|
129
|
+
|
130
|
+
Class c1 = define_class<MyClassOriginal>("MyClassOriginal");
|
131
|
+
bool result = module.const_defined("MyClassOriginal");
|
132
|
+
ASSERT(result);
|
133
|
+
String name = c1.name();
|
134
|
+
ASSERT_EQUAL("MyClassOriginal", name.str());
|
135
|
+
|
136
|
+
Class c2 = define_class<MyClassOriginal>("MyClassDuplicate");
|
137
|
+
result = c2.is_equal(c1);
|
138
|
+
ASSERT(result);
|
139
|
+
|
140
|
+
result = module.const_defined("MyClassDuplicate");
|
141
|
+
name = c2.name();
|
142
|
+
ASSERT_EQUAL("MyClassOriginal", name.str());
|
143
|
+
}
|
144
|
+
|
145
|
+
TESTCASE(define_class_twice_under)
|
146
|
+
{
|
147
|
+
Module inner = define_module("InnerNamespace");
|
148
|
+
|
149
|
+
Class c1 = define_class_under<InnerNamespace::MyClassOriginal>(inner, "MyClassOriginal");
|
150
|
+
bool result = inner.const_defined("MyClassOriginal");
|
151
|
+
ASSERT(result);
|
152
|
+
String name = c1.name();
|
153
|
+
ASSERT_EQUAL("InnerNamespace::MyClassOriginal", name.str());
|
154
|
+
|
155
|
+
Class c2 = define_class_under<InnerNamespace::MyClassOriginal>(inner, "MyClassDuplicate");
|
156
|
+
result = c2.is_equal(c1);
|
157
|
+
ASSERT(result);
|
158
|
+
|
159
|
+
result = inner.const_defined("MyClassDuplicate");
|
160
|
+
name = c2.name();
|
161
|
+
ASSERT_EQUAL("InnerNamespace::MyClassOriginal", name.str());
|
162
|
+
}
|
163
|
+
|
113
164
|
TESTCASE(incorrect_number_of_args)
|
114
165
|
{
|
115
166
|
Class c =
|
@@ -366,6 +417,57 @@ TESTCASE(define_singleton_method_returning_reference)
|
|
366
417
|
ASSERT_EQUAL(result, String("foo"));
|
367
418
|
}
|
368
419
|
|
420
|
+
namespace
|
421
|
+
{
|
422
|
+
class RValue
|
423
|
+
{
|
424
|
+
public:
|
425
|
+
RValue() {}
|
426
|
+
|
427
|
+
RValue(RValue&& other) = default;
|
428
|
+
|
429
|
+
// Move assignment operator.
|
430
|
+
RValue& operator=(RValue&& other) noexcept
|
431
|
+
{
|
432
|
+
return *this;
|
433
|
+
}
|
434
|
+
|
435
|
+
bool takesRValue(RValue&& rvalue)
|
436
|
+
{
|
437
|
+
return true;
|
438
|
+
}
|
439
|
+
};
|
440
|
+
}
|
441
|
+
|
442
|
+
TESTCASE(rvalue_parameter)
|
443
|
+
{
|
444
|
+
Class c = define_class<RValue>("RValue")
|
445
|
+
.define_constructor(Constructor<RValue>())
|
446
|
+
.define_method("takes_r_value", &RValue::takesRValue);
|
447
|
+
|
448
|
+
Module m(anonymous_module());
|
449
|
+
std::string code = R"(rvalue = RValue.new
|
450
|
+
rvalue.takes_r_value(rvalue))";
|
451
|
+
|
452
|
+
Object result = m.module_eval(code);
|
453
|
+
ASSERT_EQUAL(Qtrue, result.value());
|
454
|
+
}
|
455
|
+
|
456
|
+
TESTCASE(move_assignment)
|
457
|
+
{
|
458
|
+
Class c = define_class<RValue>("RValue")
|
459
|
+
.define_constructor(Constructor<RValue>())
|
460
|
+
.define_method<RValue&(RValue::*)(RValue && other) noexcept>("=", &RValue::operator=);
|
461
|
+
|
462
|
+
Module m(anonymous_module());
|
463
|
+
std::string code = R"(object1 = RValue.new
|
464
|
+
object2 = RValue.new
|
465
|
+
object1 = object2)";
|
466
|
+
|
467
|
+
Object result = m.module_eval(code);
|
468
|
+
ASSERT_EQUAL(c, result.class_of());
|
469
|
+
}
|
470
|
+
|
369
471
|
namespace
|
370
472
|
{
|
371
473
|
struct MyStruct
|
@@ -401,115 +503,418 @@ TESTCASE(null_ptrs)
|
|
401
503
|
|
402
504
|
namespace
|
403
505
|
{
|
404
|
-
class
|
506
|
+
class Helper
|
405
507
|
{
|
508
|
+
public:
|
509
|
+
|
510
|
+
Helper(int value) : value_(value)
|
511
|
+
{
|
512
|
+
}
|
513
|
+
|
514
|
+
int value()
|
515
|
+
{
|
516
|
+
return this->value_;
|
517
|
+
}
|
518
|
+
|
519
|
+
private:
|
520
|
+
int value_;
|
406
521
|
};
|
407
522
|
|
408
|
-
|
523
|
+
class MyClass2
|
524
|
+
{
|
525
|
+
public:
|
526
|
+
Helper* passThrough(Helper* helper)
|
527
|
+
{
|
528
|
+
return helper;
|
529
|
+
}
|
530
|
+
|
531
|
+
const Helper* passThroughConst(const Helper* helper)
|
532
|
+
{
|
533
|
+
return helper;
|
534
|
+
}
|
535
|
+
|
536
|
+
Helper* passThrough(void* helper)
|
537
|
+
{
|
538
|
+
return static_cast<Helper*>(helper);
|
539
|
+
}
|
540
|
+
|
541
|
+
void* returnVoidHelper()
|
542
|
+
{
|
543
|
+
if (!this->helper_)
|
544
|
+
this->helper_ = new Helper(4);
|
545
|
+
|
546
|
+
return static_cast<void*>(this->helper_);
|
547
|
+
}
|
548
|
+
|
549
|
+
bool checkVoidHelper(void* helper)
|
550
|
+
{
|
551
|
+
return helper == this->helper_;
|
552
|
+
}
|
553
|
+
|
554
|
+
private:
|
555
|
+
Helper* helper_ = nullptr;
|
556
|
+
};
|
557
|
+
} // namespace
|
558
|
+
|
559
|
+
TESTCASE(pointers)
|
560
|
+
{
|
561
|
+
Class helperClass = define_class<Helper>("Helper")
|
562
|
+
.define_constructor(Constructor<Helper, int>())
|
563
|
+
.define_method("value", &Helper::value);
|
564
|
+
|
565
|
+
Class myClass = define_class<MyClass2>("MyClass2")
|
566
|
+
.define_constructor(Constructor<MyClass2>())
|
567
|
+
.define_method<Helper*(MyClass2::*)(Helper*)>("pass_through", &MyClass2::passThrough)
|
568
|
+
.define_method<const Helper*(MyClass2::*)(const Helper*)>("pass_through_const", &MyClass2::passThroughConst)
|
569
|
+
.define_method<Helper*(MyClass2::*)(void*)>("pass_through_void", &MyClass2::passThrough)
|
570
|
+
.define_method<void*(MyClass2::*)()>("return_void_helper", &MyClass2::returnVoidHelper)
|
571
|
+
.define_method<bool(MyClass2::*)(void*)>("check_void_helper", &MyClass2::checkVoidHelper);
|
572
|
+
|
573
|
+
Object helper = helperClass.call("new", 5);
|
574
|
+
Object object = myClass.call("new");
|
575
|
+
|
576
|
+
Object result = object.call("pass_through", nullptr);
|
577
|
+
ASSERT_EQUAL(Qnil, result.value());
|
578
|
+
|
579
|
+
result = object.call("pass_through", helper);
|
580
|
+
Object value = result.call("value");
|
581
|
+
ASSERT_EQUAL(5, detail::From_Ruby<int>().convert(value));
|
582
|
+
|
583
|
+
result = object.call("pass_through_const", helper);
|
584
|
+
value = result.call("value");
|
585
|
+
ASSERT_EQUAL(5, detail::From_Ruby<int>().convert(value));
|
586
|
+
|
587
|
+
result = object.call("pass_through_void", nullptr);
|
588
|
+
ASSERT_EQUAL(Qnil, result.value());
|
589
|
+
|
590
|
+
result = object.call("pass_through_void", helper);
|
591
|
+
value = result.call("value");
|
592
|
+
ASSERT_EQUAL(5, detail::From_Ruby<int>().convert(value));
|
593
|
+
|
594
|
+
helper = object.call("return_void_helper");
|
595
|
+
result = object.call("check_void_helper", helper);
|
596
|
+
ASSERT_EQUAL(Qtrue, result.value());
|
597
|
+
}
|
598
|
+
|
599
|
+
namespace
|
600
|
+
{
|
601
|
+
class BigObject
|
602
|
+
{
|
603
|
+
public:
|
604
|
+
BigObject(int value): value(value)
|
605
|
+
{
|
606
|
+
}
|
607
|
+
|
608
|
+
public:
|
609
|
+
int value;
|
610
|
+
};
|
611
|
+
|
612
|
+
class Processor
|
613
|
+
{
|
614
|
+
public:
|
615
|
+
BigObject** createBigObjects(size_t size)
|
616
|
+
{
|
617
|
+
BigObject** result = new BigObject*[size];
|
618
|
+
|
619
|
+
for (size_t i = 0; i < size; ++i)
|
620
|
+
{
|
621
|
+
result[i] = new BigObject(i + 5);
|
622
|
+
}
|
623
|
+
return result;
|
624
|
+
}
|
625
|
+
|
626
|
+
int sumBigObjects(BigObject** bigObjects, size_t size)
|
627
|
+
{
|
628
|
+
int result = 0;
|
629
|
+
|
630
|
+
for (size_t i = 0; i < size; i++)
|
631
|
+
{
|
632
|
+
result += bigObjects[i]->value;
|
633
|
+
}
|
634
|
+
return result;
|
635
|
+
}
|
636
|
+
|
637
|
+
int sumBigObjectsConst(const BigObject** bigObjects, size_t size)
|
638
|
+
{
|
639
|
+
int result = 0;
|
640
|
+
|
641
|
+
for (size_t i = 0; i < size; i++)
|
642
|
+
{
|
643
|
+
result += bigObjects[i]->value;
|
644
|
+
}
|
645
|
+
return result;
|
646
|
+
}
|
647
|
+
|
648
|
+
private:
|
649
|
+
BigObject** bigObjects_ = nullptr;
|
650
|
+
};
|
651
|
+
|
652
|
+
}
|
653
|
+
|
654
|
+
TESTCASE(pointerToPointer)
|
655
|
+
{
|
656
|
+
define_buffer<BigObject*>();
|
657
|
+
|
658
|
+
Module m = define_module("DataTypePointerToPointer");
|
659
|
+
|
660
|
+
Class BigObjectClass = define_class<BigObject>("BigObject")
|
661
|
+
.define_attr("value", &BigObject::value);
|
662
|
+
|
663
|
+
Class ProcessorClass = define_class<Processor>("ProcessorClass")
|
664
|
+
.define_constructor(Constructor<Processor>())
|
665
|
+
.define_method("create", &Processor::createBigObjects)
|
666
|
+
.define_method("sum", &Processor::sumBigObjects,
|
667
|
+
Arg("bigObjects").setArray(), Arg("size"))
|
668
|
+
.define_method("sum_const", &Processor::sumBigObjectsConst,
|
669
|
+
Arg("bigObjects").setArray(), Arg("size"));
|
670
|
+
|
671
|
+
std::string code = R"(count = 2
|
672
|
+
processor = ProcessorClass.new
|
673
|
+
big_objects = processor.create(count)
|
674
|
+
processor.sum(big_objects, count))";
|
675
|
+
|
676
|
+
Object result = m.module_eval(code);
|
677
|
+
ASSERT_EQUAL(11, detail::From_Ruby<int>().convert(result));
|
678
|
+
|
679
|
+
code = R"(count = 2
|
680
|
+
processor = ProcessorClass.new
|
681
|
+
big_objects = processor.create(count)
|
682
|
+
processor.sum_const(big_objects, count))";
|
683
|
+
|
684
|
+
result = m.module_eval(code);
|
685
|
+
ASSERT_EQUAL(11, detail::From_Ruby<int>().convert(result));
|
686
|
+
}
|
687
|
+
|
688
|
+
namespace
|
689
|
+
{
|
690
|
+
class UnknownClass
|
691
|
+
{
|
692
|
+
};
|
693
|
+
|
694
|
+
void undefinedArg(UnknownClass unknownClass)
|
695
|
+
{
|
696
|
+
}
|
697
|
+
|
698
|
+
void undefinedArg(UnknownClass& unknownClass)
|
699
|
+
{
|
700
|
+
}
|
701
|
+
|
702
|
+
void undefinedArg(UnknownClass* unknownClass)
|
409
703
|
{
|
410
704
|
}
|
411
705
|
|
412
|
-
|
706
|
+
UnknownClass undefinedReturn()
|
413
707
|
{
|
414
|
-
return
|
708
|
+
return UnknownClass();
|
415
709
|
}
|
416
710
|
}
|
417
711
|
|
418
712
|
TESTCASE(not_defined)
|
419
713
|
{
|
714
|
+
Module m = define_module("TestingDataTypeNotDefined");
|
715
|
+
|
420
716
|
#ifdef _MSC_VER
|
421
|
-
const char* message = "
|
717
|
+
const char* message = "The following types are not registered with Rice:\n class `anonymous namespace'::UnknownClass\n";
|
422
718
|
#else
|
423
|
-
const char* message = "
|
719
|
+
const char* message = "The following types are not registered with Rice:\n (anonymous namespace)::UnknownClass\n";
|
424
720
|
#endif
|
425
|
-
|
426
|
-
|
721
|
+
|
722
|
+
m.define_module_function("undefined_return", &undefinedReturn);
|
723
|
+
|
724
|
+
ASSERT_EXCEPTION_CHECK(
|
427
725
|
std::invalid_argument,
|
428
|
-
|
726
|
+
Rice::detail::Registries::instance.types.validateTypes(),
|
429
727
|
ASSERT_EQUAL(message, ex.what())
|
430
728
|
);
|
431
729
|
|
730
|
+
#ifdef _MSC_VER
|
731
|
+
message = "Type is not registered with Rice: class `anonymous namespace'::UnknownClass";
|
732
|
+
#else
|
733
|
+
message = "Type is not registered with Rice: (anonymous namespace)::UnknownClass";
|
734
|
+
#endif
|
735
|
+
|
432
736
|
ASSERT_EXCEPTION_CHECK(
|
433
|
-
|
434
|
-
|
737
|
+
Rice::Exception,
|
738
|
+
m.call("undefined_return"),
|
435
739
|
ASSERT_EQUAL(message, ex.what())
|
436
740
|
);
|
741
|
+
|
742
|
+
#ifdef _MSC_VER
|
743
|
+
message = "Type is not defined with Rice: class `anonymous namespace'::UnknownClass";
|
744
|
+
#else
|
745
|
+
message = "Type is not defined with Rice: (anonymous namespace)::UnknownClass";
|
746
|
+
#endif
|
747
|
+
|
748
|
+
m.define_module_function<void(*)(UnknownClass)>("undefined_arg_value", &undefinedArg);
|
749
|
+
|
750
|
+
ASSERT_EXCEPTION_CHECK(
|
751
|
+
Rice::Exception,
|
752
|
+
m.call("undefined_arg_value", nullptr),
|
753
|
+
ASSERT_EQUAL(message, ex.what())
|
754
|
+
);
|
755
|
+
|
756
|
+
m.define_module_function<void(*)(UnknownClass&)>("undefined_arg_reference", &undefinedArg);
|
757
|
+
|
758
|
+
ASSERT_EXCEPTION_CHECK(
|
759
|
+
Rice::Exception,
|
760
|
+
m.call("undefined_arg_reference", nullptr),
|
761
|
+
ASSERT_EQUAL(message, ex.what())
|
762
|
+
);
|
763
|
+
|
764
|
+
m.define_module_function<void(*)(UnknownClass*)>("undefined_arg_pointer", &undefinedArg);
|
765
|
+
|
766
|
+
// This actually works because we pass a nullptr
|
767
|
+
m.call("undefined_arg_pointer", nullptr);
|
437
768
|
}
|
438
769
|
|
439
|
-
namespace
|
770
|
+
namespace RangesTest
|
440
771
|
{
|
441
|
-
class
|
772
|
+
class RangeCustom
|
442
773
|
{
|
443
774
|
public:
|
444
|
-
|
775
|
+
RangeCustom(int x, int y) : x(x), y(y)
|
445
776
|
{
|
446
|
-
return this->capacity_;
|
447
777
|
}
|
448
778
|
|
449
|
-
|
779
|
+
RangeCustom(const RangeCustom& other) = default;
|
780
|
+
|
781
|
+
int x;
|
782
|
+
int y;
|
783
|
+
};
|
784
|
+
|
785
|
+
int sumRangesArray(int size, RangeCustom ranges[])
|
786
|
+
{
|
787
|
+
int result = 0;
|
788
|
+
for (int i = 0; i < size; i++)
|
450
789
|
{
|
451
|
-
|
790
|
+
const RangeCustom& range = ranges[i];
|
791
|
+
result += range.x + range.y;
|
452
792
|
}
|
453
793
|
|
454
|
-
|
455
|
-
|
456
|
-
|
794
|
+
return result;
|
795
|
+
}
|
796
|
+
|
797
|
+
int sumRanges(int size, const RangeCustom* ranges)
|
798
|
+
{
|
799
|
+
int result = 0;
|
800
|
+
for (int i = 0; i < size; i++)
|
801
|
+
{
|
802
|
+
const RangeCustom& range = ranges[i];
|
803
|
+
result += range.x + range.y;
|
804
|
+
}
|
805
|
+
|
806
|
+
return result;
|
807
|
+
}
|
808
|
+
|
809
|
+
int sumRanges(int size, const RangeCustom** ranges)
|
810
|
+
{
|
811
|
+
int result = 0;
|
812
|
+
for (int i = 0; i < size; i++)
|
813
|
+
{
|
814
|
+
const RangeCustom* range = ranges[i];
|
815
|
+
result += range->x + range->y;
|
816
|
+
}
|
817
|
+
|
818
|
+
return result;
|
819
|
+
}
|
457
820
|
}
|
458
821
|
|
459
|
-
TESTCASE(
|
822
|
+
TESTCASE(array_of_ranges)
|
460
823
|
{
|
461
|
-
|
462
|
-
.define_constructor(Constructor<Container>())
|
463
|
-
.define_method<size_t(Container::*)()>("capacity", &Container::capacity)
|
464
|
-
.define_method<void(Container::*)(size_t)>("capacity=", &Container::capacity);
|
824
|
+
define_buffer<RangesTest::RangeCustom>();
|
465
825
|
|
466
|
-
|
467
|
-
Module m = define_module("Testing");
|
826
|
+
Module m = define_module("CustomRanges");
|
468
827
|
|
469
|
-
|
470
|
-
|
471
|
-
|
828
|
+
Class c = define_class_under<RangesTest::RangeCustom>(m, "RangeCustom")
|
829
|
+
.define_constructor(Constructor<RangesTest::RangeCustom, int, int>())
|
830
|
+
.define_attr("x", &RangesTest::RangeCustom::x)
|
831
|
+
.define_attr("y", &RangesTest::RangeCustom::y);
|
832
|
+
|
833
|
+
m.define_module_function("sum_ranges_array", RangesTest::sumRangesArray,
|
834
|
+
Arg("size"), Arg("ranges[]").setArray());
|
835
|
+
|
836
|
+
std::string code = R"(range1 = RangeCustom.new(1, 2)
|
837
|
+
range2 = RangeCustom.new(3, 4)
|
838
|
+
range3 = RangeCustom.new(5, 6)
|
839
|
+
|
840
|
+
buffer = Rice::Buffer≺RangesTest꞉꞉RangeCustom≻.new([range1, range2, range3])
|
841
|
+
sum_ranges_array(buffer.size, buffer))";
|
472
842
|
|
473
843
|
Object result = m.module_eval(code);
|
474
|
-
ASSERT_EQUAL(
|
844
|
+
ASSERT_EQUAL(21, detail::From_Ruby<int>().convert(result));
|
475
845
|
}
|
476
846
|
|
477
|
-
TESTCASE(
|
847
|
+
TESTCASE(pointer_of_ranges)
|
478
848
|
{
|
479
|
-
|
480
|
-
using Setter_T = void(Container::*)(size_t);
|
849
|
+
define_buffer<RangesTest::RangeCustom>();
|
481
850
|
|
482
|
-
|
483
|
-
.define_constructor(Constructor<Container>())
|
484
|
-
.define_method("capacity", (Getter_T)&Container::capacity)
|
485
|
-
.define_method("capacity=", (Setter_T)&Container::capacity);
|
851
|
+
Module m = define_module("CustomRanges");
|
486
852
|
|
487
|
-
|
853
|
+
Class c = define_class_under<RangesTest::RangeCustom>(m, "RangeCustom")
|
854
|
+
.define_constructor(Constructor<RangesTest::RangeCustom, int, int>())
|
855
|
+
.define_attr("x", &RangesTest::RangeCustom::x)
|
856
|
+
.define_attr("y", &RangesTest::RangeCustom::y);
|
857
|
+
|
858
|
+
m.define_module_function<int(*)(int, const RangesTest::RangeCustom*)>("sum_ranges", RangesTest::sumRanges,
|
859
|
+
Arg("size"), Arg("ranges*").setArray());
|
488
860
|
|
489
|
-
std::string code = R"(
|
490
|
-
|
491
|
-
|
861
|
+
std::string code = R"(range1 = RangeCustom.new(1, 2)
|
862
|
+
range2 = RangeCustom.new(3, 4)
|
863
|
+
range3 = RangeCustom.new(5, 6)
|
864
|
+
|
865
|
+
buffer = Rice::Buffer≺RangesTest꞉꞉RangeCustom≻.new([range1, range2, range3])
|
866
|
+
sum_ranges(buffer.size, buffer))";
|
492
867
|
|
493
868
|
Object result = m.module_eval(code);
|
494
|
-
ASSERT_EQUAL(
|
869
|
+
ASSERT_EQUAL(21, detail::From_Ruby<int>().convert(result));
|
495
870
|
}
|
496
871
|
|
497
|
-
TESTCASE(
|
872
|
+
TESTCASE(pointer_of_ranges_wrong)
|
498
873
|
{
|
499
|
-
|
500
|
-
typedef void (Container::* Setter_T)(size_t);
|
874
|
+
define_buffer<RangesTest::RangeCustom>();
|
501
875
|
|
502
|
-
|
503
|
-
.define_constructor(Constructor<Container>())
|
504
|
-
.define_method("capacity", (Getter_T)&Container::capacity)
|
505
|
-
.define_method("capacity=", (Setter_T)&Container::capacity);
|
876
|
+
Module m = define_module("CustomRanges");
|
506
877
|
|
507
|
-
|
878
|
+
Class c = define_class_under<RangesTest::RangeCustom>(m, "RangeCustom")
|
879
|
+
.define_constructor(Constructor<RangesTest::RangeCustom, int, int>())
|
880
|
+
.define_attr("x", &RangesTest::RangeCustom::x)
|
881
|
+
.define_attr("y", &RangesTest::RangeCustom::y);
|
882
|
+
|
883
|
+
m.define_module_function<int(*)(int, const RangesTest::RangeCustom*)>("sum_ranges_wrong", RangesTest::sumRanges);
|
508
884
|
|
509
|
-
std::string code = R"(
|
510
|
-
|
511
|
-
|
885
|
+
std::string code = R"(range1 = RangeCustom.new(1, 2)
|
886
|
+
range2 = RangeCustom.new(3, 4)
|
887
|
+
range3 = RangeCustom.new(5, 6)
|
888
|
+
|
889
|
+
buffer = Rice::Buffer≺RangesTest꞉꞉RangeCustom≻.new([range1, range2, range3])
|
890
|
+
sum_ranges_wrong(buffer.size, buffer))";
|
891
|
+
|
892
|
+
ASSERT_EXCEPTION_CHECK(
|
893
|
+
Rice::Exception,
|
894
|
+
m.module_eval(code),
|
895
|
+
ASSERT_EQUAL("wrong argument type Rice::Buffer≺RangesTest꞉꞉RangeCustom≻ (expected CustomRanges::RangeCustom)", ex.what())
|
896
|
+
);
|
897
|
+
}
|
898
|
+
|
899
|
+
TESTCASE(pointer_of_pointer_ranges)
|
900
|
+
{
|
901
|
+
define_buffer<RangesTest::RangeCustom*>();
|
902
|
+
|
903
|
+
Module m = define_module("CustomRanges");
|
904
|
+
|
905
|
+
Class c = define_class_under<RangesTest::RangeCustom>(m, "RangeCustom")
|
906
|
+
.define_constructor(Constructor<RangesTest::RangeCustom, int, int>())
|
907
|
+
.define_attr("x", &RangesTest::RangeCustom::x)
|
908
|
+
.define_attr("y", &RangesTest::RangeCustom::y);
|
909
|
+
|
910
|
+
m.define_module_function<int(*)(int, const RangesTest::RangeCustom**)>("sum_ranges", RangesTest::sumRanges);
|
911
|
+
|
912
|
+
std::string code = R"(range1 = RangeCustom.new(1, 2)
|
913
|
+
range2 = RangeCustom.new(3, 4)
|
914
|
+
range3 = RangeCustom.new(5, 6)
|
915
|
+
buffer = Rice::Buffer≺RangesTest꞉꞉RangeCustom≻.new([range1, range2, range3])
|
916
|
+
sum_ranges(buffer.size, buffer))";
|
512
917
|
|
513
918
|
Object result = m.module_eval(code);
|
514
|
-
ASSERT_EQUAL(
|
515
|
-
}
|
919
|
+
ASSERT_EQUAL(21, detail::From_Ruby<int>().convert(result));
|
920
|
+
}
|
data/test/test_Director.cpp
CHANGED
@@ -8,6 +8,16 @@ using namespace Rice;
|
|
8
8
|
|
9
9
|
TESTSUITE(Director);
|
10
10
|
|
11
|
+
SETUP(Director)
|
12
|
+
{
|
13
|
+
embed_ruby();
|
14
|
+
}
|
15
|
+
|
16
|
+
TEARDOWN(Director)
|
17
|
+
{
|
18
|
+
rb_gc_start();
|
19
|
+
}
|
20
|
+
|
11
21
|
namespace {
|
12
22
|
/**
|
13
23
|
* Abstract base class
|
@@ -93,11 +103,6 @@ namespace {
|
|
93
103
|
};
|
94
104
|
};
|
95
105
|
|
96
|
-
SETUP(Director)
|
97
|
-
{
|
98
|
-
embed_ruby();
|
99
|
-
}
|
100
|
-
|
101
106
|
TESTCASE(exposes_worker_as_instantiatable_class)
|
102
107
|
{
|
103
108
|
define_class<Worker>("Worker")
|
@@ -191,11 +196,15 @@ TESTCASE(polymorphic_calls_head_down_the_call_chain)
|
|
191
196
|
|
192
197
|
namespace {
|
193
198
|
|
194
|
-
class CallsSelf
|
199
|
+
class CallsSelf
|
200
|
+
{
|
195
201
|
public:
|
196
|
-
virtual ~CallsSelf()
|
202
|
+
virtual ~CallsSelf()
|
203
|
+
{
|
204
|
+
}
|
197
205
|
|
198
|
-
int doIt(int in)
|
206
|
+
int doIt(int in)
|
207
|
+
{
|
199
208
|
return doItImpl(in);
|
200
209
|
}
|
201
210
|
|