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.
Files changed (237) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +86 -26
  3. data/CMakeLists.txt +31 -0
  4. data/CMakePresets.json +75 -0
  5. data/COPYING +3 -2
  6. data/FindRuby.cmake +437 -0
  7. data/README.md +7 -2
  8. data/Rakefile +12 -5
  9. data/include/rice/rice.hpp +9522 -4426
  10. data/include/rice/stl.hpp +2831 -1198
  11. data/lib/make_rice_headers.rb +79 -0
  12. data/lib/mkmf-rice.rb +40 -94
  13. data/lib/rice/version.rb +3 -0
  14. data/lib/rice.rb +1 -0
  15. data/lib/rubygems/builder.rb +11 -0
  16. data/lib/rubygems/cmake_builder.rb +113 -0
  17. data/lib/rubygems_plugin.rb +9 -0
  18. data/rice/Address_Registration_Guard.hpp +72 -3
  19. data/rice/Arg.hpp +26 -6
  20. data/rice/Arg.ipp +35 -2
  21. data/rice/Buffer.hpp +123 -0
  22. data/rice/Buffer.ipp +599 -0
  23. data/rice/Callback.hpp +21 -0
  24. data/rice/Callback.ipp +13 -0
  25. data/rice/Constructor.hpp +4 -27
  26. data/rice/Constructor.ipp +79 -0
  27. data/rice/Data_Object.hpp +73 -3
  28. data/rice/Data_Object.ipp +388 -96
  29. data/rice/Data_Type.hpp +214 -3
  30. data/rice/Data_Type.ipp +144 -67
  31. data/rice/Director.hpp +0 -2
  32. data/rice/Enum.hpp +4 -7
  33. data/rice/Enum.ipp +102 -55
  34. data/rice/Exception.hpp +62 -2
  35. data/rice/Exception.ipp +7 -12
  36. data/rice/Init.hpp +8 -0
  37. data/rice/Init.ipp +8 -0
  38. data/rice/JumpException.hpp +44 -0
  39. data/rice/JumpException.ipp +48 -0
  40. data/rice/MemoryView.hpp +11 -0
  41. data/rice/MemoryView.ipp +3 -0
  42. data/rice/Return.hpp +7 -27
  43. data/rice/Return.ipp +13 -13
  44. data/rice/cpp_api/Array.hpp +209 -0
  45. data/rice/cpp_api/Array.ipp +304 -0
  46. data/rice/cpp_api/Builtin_Object.hpp +31 -0
  47. data/rice/cpp_api/Builtin_Object.ipp +37 -0
  48. data/rice/cpp_api/Class.hpp +70 -0
  49. data/rice/cpp_api/Class.ipp +97 -0
  50. data/rice/cpp_api/Encoding.hpp +32 -0
  51. data/rice/cpp_api/Encoding.ipp +59 -0
  52. data/rice/cpp_api/Hash.hpp +194 -0
  53. data/rice/cpp_api/Hash.ipp +257 -0
  54. data/rice/{Identifier.hpp → cpp_api/Identifier.hpp} +2 -6
  55. data/rice/{Identifier.ipp → cpp_api/Identifier.ipp} +4 -2
  56. data/rice/cpp_api/Module.hpp +72 -0
  57. data/rice/cpp_api/Module.ipp +101 -0
  58. data/rice/cpp_api/Object.hpp +272 -0
  59. data/rice/cpp_api/Object.ipp +235 -0
  60. data/rice/cpp_api/String.hpp +74 -0
  61. data/rice/cpp_api/String.ipp +120 -0
  62. data/rice/cpp_api/Struct.hpp +113 -0
  63. data/rice/cpp_api/Struct.ipp +92 -0
  64. data/rice/cpp_api/Symbol.hpp +46 -0
  65. data/rice/cpp_api/Symbol.ipp +93 -0
  66. data/rice/cpp_api/shared_methods.hpp +134 -0
  67. data/rice/detail/DefaultHandler.hpp +12 -0
  68. data/rice/detail/DefaultHandler.ipp +8 -0
  69. data/rice/detail/HandlerRegistry.hpp +5 -35
  70. data/rice/detail/HandlerRegistry.ipp +7 -11
  71. data/rice/detail/InstanceRegistry.hpp +1 -4
  72. data/rice/detail/MethodInfo.hpp +12 -10
  73. data/rice/detail/MethodInfo.ipp +26 -21
  74. data/rice/detail/Native.hpp +33 -0
  75. data/rice/detail/Native.ipp +157 -0
  76. data/rice/detail/NativeAttributeGet.hpp +52 -0
  77. data/rice/detail/NativeAttributeGet.ipp +57 -0
  78. data/rice/detail/NativeAttributeSet.hpp +44 -0
  79. data/rice/detail/NativeAttributeSet.ipp +88 -0
  80. data/rice/detail/NativeCallbackFFI.hpp +55 -0
  81. data/rice/detail/NativeCallbackFFI.ipp +151 -0
  82. data/rice/detail/NativeCallbackSimple.hpp +30 -0
  83. data/rice/detail/NativeCallbackSimple.ipp +29 -0
  84. data/rice/detail/NativeFunction.hpp +33 -23
  85. data/rice/detail/NativeFunction.ipp +309 -70
  86. data/rice/detail/NativeIterator.hpp +9 -11
  87. data/rice/detail/NativeIterator.ipp +33 -31
  88. data/rice/detail/NativeRegistry.hpp +24 -15
  89. data/rice/detail/NativeRegistry.ipp +23 -48
  90. data/rice/detail/Proc.hpp +4 -0
  91. data/rice/detail/Proc.ipp +85 -0
  92. data/rice/detail/Registries.hpp +0 -7
  93. data/rice/detail/Registries.ipp +0 -18
  94. data/rice/detail/RubyFunction.hpp +0 -3
  95. data/rice/detail/RubyFunction.ipp +4 -8
  96. data/rice/detail/RubyType.hpp +16 -0
  97. data/rice/detail/RubyType.ipp +232 -0
  98. data/rice/detail/Type.hpp +7 -6
  99. data/rice/detail/Type.ipp +192 -45
  100. data/rice/detail/TypeRegistry.hpp +15 -7
  101. data/rice/detail/TypeRegistry.ipp +105 -12
  102. data/rice/detail/Wrapper.hpp +68 -32
  103. data/rice/detail/Wrapper.ipp +121 -109
  104. data/rice/detail/cpp_protect.hpp +5 -6
  105. data/rice/detail/default_allocation_func.ipp +0 -2
  106. data/rice/detail/from_ruby.hpp +38 -3
  107. data/rice/detail/from_ruby.ipp +1321 -492
  108. data/rice/detail/ruby.hpp +18 -0
  109. data/rice/detail/to_ruby.hpp +41 -3
  110. data/rice/detail/to_ruby.ipp +1424 -194
  111. data/rice/global_function.hpp +0 -4
  112. data/rice/global_function.ipp +0 -1
  113. data/rice/libc/file.hpp +11 -0
  114. data/rice/libc/file.ipp +32 -0
  115. data/rice/rice.hpp +116 -26
  116. data/rice/ruby_mark.hpp +4 -3
  117. data/rice/stl/complex.hpp +6 -0
  118. data/rice/stl/complex.ipp +93 -0
  119. data/rice/stl/exception.hpp +11 -0
  120. data/rice/stl/exception.ipp +29 -0
  121. data/rice/stl/exception_ptr.hpp +6 -0
  122. data/rice/stl/exception_ptr.ipp +27 -0
  123. data/rice/stl/map.hpp +12 -0
  124. data/rice/stl/map.ipp +469 -0
  125. data/rice/stl/monostate.hpp +6 -0
  126. data/rice/stl/monostate.ipp +80 -0
  127. data/rice/stl/multimap.hpp +14 -0
  128. data/rice/stl/multimap.ipp +448 -0
  129. data/rice/stl/optional.hpp +6 -0
  130. data/rice/stl/optional.ipp +118 -0
  131. data/rice/stl/pair.hpp +13 -0
  132. data/rice/stl/pair.ipp +155 -0
  133. data/rice/stl/reference_wrapper.hpp +6 -0
  134. data/rice/stl/reference_wrapper.ipp +41 -0
  135. data/rice/stl/set.hpp +12 -0
  136. data/rice/stl/set.ipp +495 -0
  137. data/rice/stl/shared_ptr.hpp +28 -0
  138. data/rice/stl/shared_ptr.ipp +224 -0
  139. data/rice/stl/string.hpp +6 -0
  140. data/rice/stl/string.ipp +158 -0
  141. data/rice/stl/string_view.hpp +6 -0
  142. data/rice/stl/string_view.ipp +65 -0
  143. data/rice/stl/tuple.hpp +6 -0
  144. data/rice/stl/tuple.ipp +128 -0
  145. data/rice/stl/type_index.hpp +6 -0
  146. data/rice/stl/type_index.ipp +30 -0
  147. data/rice/stl/type_info.hpp +6 -0
  148. data/rice/stl/type_info.ipp +29 -0
  149. data/rice/stl/unique_ptr.hpp +22 -0
  150. data/rice/stl/unique_ptr.ipp +139 -0
  151. data/rice/stl/unordered_map.hpp +12 -0
  152. data/rice/stl/unordered_map.ipp +469 -0
  153. data/rice/stl/variant.hpp +6 -0
  154. data/rice/stl/variant.ipp +242 -0
  155. data/rice/stl/vector.hpp +12 -0
  156. data/rice/stl/vector.ipp +590 -0
  157. data/rice/stl.hpp +11 -3
  158. data/rice/traits/attribute_traits.hpp +26 -0
  159. data/rice/traits/function_traits.hpp +95 -0
  160. data/rice/traits/method_traits.hpp +47 -0
  161. data/rice/traits/rice_traits.hpp +160 -0
  162. data/rice.gemspec +85 -0
  163. data/test/embed_ruby.cpp +7 -1
  164. data/test/extconf.rb +2 -0
  165. data/test/test_Address_Registration_Guard.cpp +5 -0
  166. data/test/test_Array.cpp +18 -4
  167. data/test/test_Attribute.cpp +136 -21
  168. data/test/test_Buffer.cpp +285 -0
  169. data/test/test_Builtin_Object.cpp +5 -0
  170. data/test/test_Callback.cpp +230 -0
  171. data/test/test_Class.cpp +5 -31
  172. data/test/test_Constructor.cpp +69 -6
  173. data/test/test_Data_Object.cpp +97 -38
  174. data/test/test_Data_Type.cpp +470 -65
  175. data/test/test_Director.cpp +17 -8
  176. data/test/test_Enum.cpp +155 -40
  177. data/test/test_Exception.cpp +235 -0
  178. data/test/test_File.cpp +70 -0
  179. data/test/test_From_Ruby.cpp +609 -0
  180. data/test/test_Hash.cpp +5 -0
  181. data/test/test_Identifier.cpp +5 -0
  182. data/test/test_Inheritance.cpp +6 -1
  183. data/test/test_Iterator.cpp +6 -1
  184. data/test/test_Jump_Exception.cpp +23 -0
  185. data/test/test_Keep_Alive.cpp +13 -19
  186. data/test/test_Keep_Alive_No_Wrapper.cpp +5 -1
  187. data/test/test_Memory_Management.cpp +5 -0
  188. data/test/test_Module.cpp +128 -67
  189. data/test/test_Native_Registry.cpp +2 -34
  190. data/test/test_Object.cpp +5 -0
  191. data/test/test_Overloads.cpp +806 -0
  192. data/test/test_Ownership.cpp +160 -54
  193. data/test/test_Proc.cpp +44 -0
  194. data/test/test_Self.cpp +9 -4
  195. data/test/test_Stl_Exception.cpp +109 -0
  196. data/test/test_Stl_Map.cpp +54 -42
  197. data/test/test_Stl_Multimap.cpp +693 -0
  198. data/test/test_Stl_Optional.cpp +5 -0
  199. data/test/test_Stl_Pair.cpp +14 -9
  200. data/test/test_Stl_Reference_Wrapper.cpp +9 -2
  201. data/test/test_Stl_Set.cpp +790 -0
  202. data/test/test_Stl_SharedPtr.cpp +458 -0
  203. data/test/test_Stl_String.cpp +5 -0
  204. data/test/test_Stl_String_View.cpp +5 -0
  205. data/test/test_Stl_Tuple.cpp +116 -0
  206. data/test/test_Stl_Type.cpp +147 -0
  207. data/test/test_Stl_UniquePtr.cpp +202 -0
  208. data/test/test_Stl_Unordered_Map.cpp +43 -38
  209. data/test/test_Stl_Variant.cpp +217 -84
  210. data/test/test_Stl_Vector.cpp +306 -58
  211. data/test/test_String.cpp +5 -0
  212. data/test/test_Struct.cpp +5 -0
  213. data/test/test_Symbol.cpp +5 -0
  214. data/test/test_Template.cpp +192 -0
  215. data/test/test_To_Ruby.cpp +524 -0
  216. data/test/test_Tracking.cpp +1 -0
  217. data/test/test_Type.cpp +171 -0
  218. data/test/test_global_functions.cpp +67 -7
  219. data/test/unittest.cpp +8 -0
  220. metadata +127 -26
  221. data/lib/version.rb +0 -3
  222. data/rice/Address_Registration_Guard_defn.hpp +0 -79
  223. data/rice/Data_Object_defn.hpp +0 -84
  224. data/rice/Data_Type_defn.hpp +0 -190
  225. data/rice/Exception_defn.hpp +0 -68
  226. data/rice/HandlerRegistration.hpp +0 -15
  227. data/rice/detail/ExceptionHandler.hpp +0 -8
  228. data/rice/detail/ExceptionHandler.ipp +0 -28
  229. data/rice/detail/ExceptionHandler_defn.hpp +0 -77
  230. data/rice/detail/Jump_Tag.hpp +0 -21
  231. data/rice/detail/NativeAttribute.hpp +0 -64
  232. data/rice/detail/NativeAttribute.ipp +0 -112
  233. data/rice/detail/from_ruby_defn.hpp +0 -38
  234. data/rice/detail/to_ruby_defn.hpp +0 -48
  235. data/test/test_Jump_Tag.cpp +0 -17
  236. data/test/test_Stl_SmartPointer.cpp +0 -283
  237. data/test/test_To_From_Ruby.cpp +0 -399
@@ -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
- * The tests here are for the feature of taking an instance
19
- * of a Ruby-subclass of a Rice wrapped class and passing
20
- * that instance back into the Rice wrapper. While that
21
- * might be confusing, the test code is pretty straight foward
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
- } // namespace
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 SomeClass
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
- void undefinedArg(SomeClass& someClass)
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
- SomeClass undefinedReturn()
706
+ UnknownClass undefinedReturn()
413
707
  {
414
- return SomeClass();
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 = "Type is not defined with Rice: class `anonymous namespace'::SomeClass";
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 = "Type is not defined with Rice: (anonymous namespace)::SomeClass";
719
+ const char* message = "The following types are not registered with Rice:\n (anonymous namespace)::UnknownClass\n";
424
720
  #endif
425
-
426
- ASSERT_EXCEPTION_CHECK(
721
+
722
+ m.define_module_function("undefined_return", &undefinedReturn);
723
+
724
+ ASSERT_EXCEPTION_CHECK(
427
725
  std::invalid_argument,
428
- define_global_function("undefined_arg", &undefinedArg),
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
- std::invalid_argument,
434
- define_global_function("undefined_return", &undefinedReturn),
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 Container
772
+ class RangeCustom
442
773
  {
443
774
  public:
444
- size_t capacity()
775
+ RangeCustom(int x, int y) : x(x), y(y)
445
776
  {
446
- return this->capacity_;
447
777
  }
448
778
 
449
- void capacity(size_t value)
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
- this->capacity_ = value;
790
+ const RangeCustom& range = ranges[i];
791
+ result += range.x + range.y;
452
792
  }
453
793
 
454
- private:
455
- size_t capacity_;
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(OverloadsWithTemplateParameter)
822
+ TESTCASE(array_of_ranges)
460
823
  {
461
- Class c = define_class<Container>("Container")
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
- std::string code = R"(container = Container.new
470
- container.capacity = 5
471
- container.capacity)";
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(5, detail::From_Ruby<int>().convert(result.value()));
844
+ ASSERT_EQUAL(21, detail::From_Ruby<int>().convert(result));
475
845
  }
476
846
 
477
- TESTCASE(OverloadsWithUsing)
847
+ TESTCASE(pointer_of_ranges)
478
848
  {
479
- using Getter_T = size_t(Container::*)();
480
- using Setter_T = void(Container::*)(size_t);
849
+ define_buffer<RangesTest::RangeCustom>();
481
850
 
482
- Class c = define_class<Container>("Container")
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
- Module m = define_module("Testing");
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"(container = Container.new
490
- container.capacity = 6
491
- container.capacity)";
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(6, detail::From_Ruby<int>().convert(result.value()));
869
+ ASSERT_EQUAL(21, detail::From_Ruby<int>().convert(result));
495
870
  }
496
871
 
497
- TESTCASE(OverloadsWithTypedef)
872
+ TESTCASE(pointer_of_ranges_wrong)
498
873
  {
499
- typedef size_t(Container::* Getter_T)();
500
- typedef void (Container::* Setter_T)(size_t);
874
+ define_buffer<RangesTest::RangeCustom>();
501
875
 
502
- Class c = define_class<Container>("Container")
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
- Module m = define_module("Testing");
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"(container = Container.new
510
- container.capacity = 7
511
- container.capacity)";
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(7, detail::From_Ruby<int>().convert(result.value()));
515
- }
919
+ ASSERT_EQUAL(21, detail::From_Ruby<int>().convert(result));
920
+ }
@@ -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