rice 4.6.1 → 4.7.1

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 (187) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +38 -0
  3. data/CMakeLists.txt +0 -4
  4. data/Rakefile +2 -8
  5. data/bin/rice-doc.rb +211 -0
  6. data/bin/rice-rbs.rb +92 -0
  7. data/include/rice/rice.hpp +4694 -3704
  8. data/include/rice/stl.hpp +840 -294
  9. data/lib/rice/doc/cpp_reference.rb +166 -0
  10. data/lib/rice/doc/doxygen.rb +294 -0
  11. data/lib/rice/doc/mkdocs.rb +298 -0
  12. data/lib/rice/doc/rice.rb +29 -0
  13. data/lib/rice/doc/ruby.rb +37 -0
  14. data/lib/rice/doc.rb +5 -0
  15. data/lib/{make_rice_headers.rb → rice/make_rice_headers.rb} +3 -0
  16. data/lib/rice/native.rb +18 -0
  17. data/lib/rice/native_registry.rb +21 -0
  18. data/lib/rice/parameter.rb +7 -0
  19. data/lib/rice/rbs.rb +104 -0
  20. data/lib/rice/version.rb +1 -1
  21. data/lib/rice.rb +4 -0
  22. data/lib/rubygems/cmake_builder.rb +24 -27
  23. data/rice/Arg.hpp +4 -4
  24. data/rice/Arg.ipp +4 -4
  25. data/rice/Buffer.hpp +32 -28
  26. data/rice/Buffer.ipp +306 -178
  27. data/rice/Data_Object.ipp +136 -88
  28. data/rice/Data_Type.hpp +5 -7
  29. data/rice/Data_Type.ipp +48 -29
  30. data/rice/Enum.ipp +15 -21
  31. data/rice/Function.hpp +17 -0
  32. data/rice/Function.ipp +13 -0
  33. data/rice/Pointer.hpp +15 -0
  34. data/rice/Pointer.ipp +49 -0
  35. data/rice/Return.hpp +1 -1
  36. data/rice/Return.ipp +2 -2
  37. data/rice/api.hpp +30 -0
  38. data/rice/cpp_api/Array.hpp +4 -4
  39. data/rice/cpp_api/Array.ipp +50 -5
  40. data/rice/cpp_api/Class.hpp +0 -5
  41. data/rice/cpp_api/Class.ipp +19 -0
  42. data/rice/cpp_api/Hash.ipp +20 -0
  43. data/rice/cpp_api/Module.hpp +6 -3
  44. data/rice/cpp_api/Module.ipp +49 -11
  45. data/rice/cpp_api/Object.ipp +31 -2
  46. data/rice/cpp_api/String.hpp +1 -2
  47. data/rice/cpp_api/String.ipp +21 -1
  48. data/rice/cpp_api/Struct.ipp +5 -0
  49. data/rice/cpp_api/Symbol.ipp +43 -0
  50. data/rice/cpp_api/shared_methods.hpp +12 -12
  51. data/rice/detail/MethodInfo.hpp +4 -2
  52. data/rice/detail/MethodInfo.ipp +19 -3
  53. data/rice/detail/ModuleRegistry.hpp +18 -0
  54. data/rice/detail/ModuleRegistry.ipp +25 -0
  55. data/rice/detail/Native.hpp +45 -2
  56. data/rice/detail/Native.ipp +196 -6
  57. data/rice/detail/NativeAttributeGet.hpp +9 -4
  58. data/rice/detail/NativeAttributeGet.ipp +65 -11
  59. data/rice/detail/NativeAttributeSet.hpp +4 -0
  60. data/rice/detail/NativeAttributeSet.ipp +30 -2
  61. data/rice/detail/NativeCallbackFFI.ipp +2 -2
  62. data/rice/detail/NativeCallbackSimple.ipp +1 -1
  63. data/rice/detail/NativeFunction.hpp +11 -49
  64. data/rice/detail/NativeFunction.ipp +82 -379
  65. data/rice/detail/NativeInvoker.hpp +74 -0
  66. data/rice/detail/NativeInvoker.ipp +197 -0
  67. data/rice/detail/NativeIterator.hpp +4 -0
  68. data/rice/detail/NativeIterator.ipp +19 -0
  69. data/rice/detail/NativeMethod.hpp +97 -0
  70. data/rice/detail/NativeMethod.ipp +332 -0
  71. data/rice/detail/NativeProc.hpp +51 -0
  72. data/rice/detail/NativeProc.ipp +133 -0
  73. data/rice/detail/NativeRegistry.hpp +8 -0
  74. data/rice/detail/NativeRegistry.ipp +26 -0
  75. data/rice/detail/Parameter.hpp +47 -0
  76. data/rice/detail/Parameter.ipp +105 -0
  77. data/rice/detail/Proc.ipp +14 -13
  78. data/rice/detail/Registries.hpp +1 -0
  79. data/rice/detail/RubyType.hpp +0 -2
  80. data/rice/detail/RubyType.ipp +15 -33
  81. data/rice/detail/Type.hpp +44 -8
  82. data/rice/detail/Type.ipp +151 -49
  83. data/rice/detail/TypeRegistry.hpp +3 -0
  84. data/rice/detail/TypeRegistry.ipp +17 -27
  85. data/rice/detail/Types.ipp +430 -0
  86. data/rice/detail/Wrapper.hpp +12 -0
  87. data/rice/detail/Wrapper.ipp +45 -2
  88. data/rice/detail/from_ruby.ipp +567 -1073
  89. data/rice/detail/ruby.hpp +1 -0
  90. data/rice/detail/to_ruby.ipp +4 -635
  91. data/rice/libc/file.ipp +3 -6
  92. data/rice/rice.hpp +22 -12
  93. data/rice/rice_api/Arg.hpp +7 -0
  94. data/rice/rice_api/Arg.ipp +9 -0
  95. data/rice/rice_api/ModuleRegistry.hpp +7 -0
  96. data/rice/rice_api/ModuleRegistry.ipp +10 -0
  97. data/rice/rice_api/Native.hpp +7 -0
  98. data/rice/rice_api/Native.ipp +52 -0
  99. data/rice/rice_api/NativeRegistry.hpp +7 -0
  100. data/rice/rice_api/NativeRegistry.ipp +21 -0
  101. data/rice/rice_api/Parameter.hpp +7 -0
  102. data/rice/rice_api/Parameter.ipp +11 -0
  103. data/rice/rice_api/Registries.hpp +6 -0
  104. data/rice/rice_api/Registries.ipp +12 -0
  105. data/rice/rice_api/TypeRegistry.hpp +7 -0
  106. data/rice/rice_api/TypeRegistry.ipp +10 -0
  107. data/rice/stl/complex.ipp +35 -0
  108. data/rice/stl/exception.ipp +20 -7
  109. data/rice/stl/filesystem.hpp +6 -0
  110. data/rice/stl/filesystem.ipp +34 -0
  111. data/rice/stl/map.ipp +13 -21
  112. data/rice/stl/monostate.ipp +37 -1
  113. data/rice/stl/multimap.ipp +17 -24
  114. data/rice/stl/optional.ipp +47 -2
  115. data/rice/stl/pair.ipp +23 -58
  116. data/rice/stl/reference_wrapper.ipp +22 -1
  117. data/rice/stl/set.ipp +17 -9
  118. data/rice/stl/shared_ptr.ipp +44 -17
  119. data/rice/stl/string.ipp +175 -7
  120. data/rice/stl/string_view.ipp +23 -0
  121. data/rice/stl/tuple.ipp +38 -9
  122. data/rice/stl/unique_ptr.ipp +46 -2
  123. data/rice/stl/unordered_map.ipp +13 -21
  124. data/rice/stl/variant.ipp +47 -11
  125. data/rice/stl/vector.ipp +183 -104
  126. data/rice/stl.hpp +1 -0
  127. data/rice/traits/function_traits.hpp +2 -2
  128. data/rice/traits/method_traits.hpp +5 -16
  129. data/rice/traits/rice_traits.hpp +24 -4
  130. data/rice.gemspec +10 -22
  131. data/test/embed_ruby.cpp +0 -3
  132. data/test/test_Array.cpp +38 -38
  133. data/test/test_Attribute.cpp +187 -2
  134. data/test/test_Buffer.cpp +302 -26
  135. data/test/test_Callback.cpp +2 -3
  136. data/test/test_Class.cpp +5 -5
  137. data/test/test_Data_Object.cpp +1 -56
  138. data/test/test_Data_Type.cpp +20 -30
  139. data/test/test_Enum.cpp +4 -46
  140. data/test/test_From_Ruby.cpp +89 -82
  141. data/test/test_GVL.cpp +109 -0
  142. data/test/test_Iterator.cpp +1 -1
  143. data/test/test_Keep_Alive_No_Wrapper.cpp +5 -3
  144. data/test/test_Module.cpp +8 -9
  145. data/test/test_Object.cpp +1 -1
  146. data/test/test_Overloads.cpp +58 -10
  147. data/test/test_Stl_Map.cpp +8 -8
  148. data/test/test_Stl_Multimap.cpp +4 -4
  149. data/test/test_Stl_Pair.cpp +5 -3
  150. data/test/test_Stl_SharedPtr.cpp +24 -12
  151. data/test/test_Stl_String_View.cpp +10 -0
  152. data/test/test_Stl_Tuple.cpp +1 -1
  153. data/test/test_Stl_UniquePtr.cpp +8 -0
  154. data/test/test_Stl_Unordered_Map.cpp +9 -9
  155. data/test/test_Stl_Variant.cpp +9 -3
  156. data/test/test_Stl_Vector.cpp +118 -13
  157. data/test/test_Symbol.cpp +12 -0
  158. data/test/test_To_Ruby.cpp +35 -28
  159. data/test/test_Type.cpp +256 -53
  160. data/test/unittest.hpp +35 -0
  161. metadata +52 -34
  162. data/rice/Init.hpp +0 -8
  163. data/rice/Init.ipp +0 -8
  164. data/rice/detail/RubyFunction.hpp +0 -31
  165. data/rice/detail/RubyFunction.ipp +0 -77
  166. data/sample/callbacks/extconf.rb +0 -5
  167. data/sample/callbacks/sample_callbacks.cpp +0 -35
  168. data/sample/callbacks/test.rb +0 -28
  169. data/sample/enum/extconf.rb +0 -5
  170. data/sample/enum/sample_enum.cpp +0 -40
  171. data/sample/enum/test.rb +0 -8
  172. data/sample/inheritance/animals.cpp +0 -82
  173. data/sample/inheritance/extconf.rb +0 -5
  174. data/sample/inheritance/test.rb +0 -7
  175. data/sample/map/extconf.rb +0 -5
  176. data/sample/map/map.cpp +0 -73
  177. data/sample/map/test.rb +0 -7
  178. data/test/ext/t1/Foo.hpp +0 -10
  179. data/test/ext/t1/extconf.rb +0 -4
  180. data/test/ext/t1/t1.cpp +0 -13
  181. data/test/ext/t2/extconf.rb +0 -4
  182. data/test/ext/t2/t2.cpp +0 -11
  183. data/test/ruby/test_callbacks_sample.rb +0 -28
  184. data/test/ruby/test_multiple_extensions.rb +0 -18
  185. data/test/ruby/test_multiple_extensions_same_class.rb +0 -14
  186. data/test/ruby/test_multiple_extensions_with_inheritance.rb +0 -20
  187. /data/test/{test_Stl_Type.cpp → test_Stl_Type_Info.cpp} +0 -0
data/test/test_GVL.cpp ADDED
@@ -0,0 +1,109 @@
1
+ #include "unittest.hpp"
2
+ #include "embed_ruby.hpp"
3
+ #include <rice/rice.hpp>
4
+
5
+ #include <chrono>
6
+ #include <thread>
7
+
8
+ using namespace Rice;
9
+
10
+ TESTSUITE(GVL);
11
+
12
+ SETUP(GVL)
13
+ {
14
+ embed_ruby();
15
+ }
16
+
17
+ TEARDOWN(GVL)
18
+ {
19
+ rb_gc_start();
20
+ }
21
+
22
+ namespace
23
+ {
24
+ int slowFunction1()
25
+ {
26
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
27
+ return 83;
28
+ }
29
+
30
+ void slowFunction2()
31
+ {
32
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
33
+ }
34
+
35
+ void functionException()
36
+ {
37
+ throw std::runtime_error("This is an exception from functionException");
38
+ }
39
+
40
+ class Task
41
+ {
42
+ public:
43
+ Task(int id) : id_(id)
44
+ {
45
+ }
46
+
47
+ int run(bool arg1)
48
+ {
49
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
50
+ return this->id_;
51
+ }
52
+
53
+ private:
54
+ int id_;
55
+ };
56
+ }
57
+
58
+ TESTCASE(Function)
59
+ {
60
+ int result = detail::no_gvl(&slowFunction1);
61
+ ASSERT_EQUAL(83, result);
62
+ }
63
+
64
+ TESTCASE(FunctionViaRuby)
65
+ {
66
+ Module m = define_module("Testing");
67
+ m.define_module_function("slow_function_1", &slowFunction1, Function().setNoGvl());
68
+
69
+ std::string code = R"(slow_function_1)";
70
+ Object result = m.module_eval(code);
71
+ ASSERT_EQUAL(83, detail::From_Ruby<int>().convert(result));
72
+ }
73
+
74
+ TESTCASE(FunctionNoReturn)
75
+ {
76
+ detail::no_gvl(&slowFunction2);
77
+ ASSERT_EQUAL(true, true);
78
+ }
79
+
80
+ TESTCASE(FunctionWithException)
81
+ {
82
+ ASSERT_EXCEPTION_CHECK(
83
+ std::runtime_error,
84
+ detail::no_gvl(&functionException),
85
+ ASSERT_EQUAL("This is an exception from functionException", ex.what())
86
+ );
87
+ }
88
+
89
+ TESTCASE(MemberFunction)
90
+ {
91
+ Task task(84);
92
+ int result = detail::no_gvl(&Task::run, task, false);
93
+ ASSERT_EQUAL(84, result);
94
+ }
95
+
96
+ TESTCASE(MemberFunctionNoGvl)
97
+ {
98
+ Module m = define_module("Testing");
99
+
100
+ Class task = define_class_under<Task>(m, "Task")
101
+ .define_constructor(Constructor<Task, int>())
102
+ .define_method("run", &Task::run, Function().setNoGvl());
103
+
104
+ std::string code = R"(task = Task.new(85)
105
+ task.run(true))";
106
+
107
+ Object result = m.module_eval(code);
108
+ ASSERT_EQUAL(85, detail::From_Ruby<int>().convert(result));
109
+ }
@@ -350,7 +350,7 @@ TESTCASE(IterateNoCopy)
350
350
  Data_Object<ContainerValues> wrapper(container);
351
351
  Array a = wrapper.instance_eval("self.to_a");
352
352
 
353
- ASSERT_EQUAL(container.data_.size(), a.size());
353
+ ASSERT_EQUAL(container.data_.size(), (size_t)a.size());
354
354
 
355
355
  for (size_t i = 0; i < container.data_.size(); i++)
356
356
  {
@@ -37,10 +37,12 @@ namespace
37
37
  pets_.clear();
38
38
  }
39
39
 
40
- Object getPets(void) {
40
+ Object getPets(void)
41
+ {
41
42
  Array pets;
42
- for(auto p: pets_) {
43
- pets.push(p);
43
+ for(auto p: pets_)
44
+ {
45
+ pets.push(p, false);
44
46
  }
45
47
  return pets;
46
48
  }
data/test/test_Module.cpp CHANGED
@@ -1,4 +1,4 @@
1
- #include "unittest.hpp"
1
+ #include "unittest.hpp"
2
2
  #include "embed_ruby.hpp"
3
3
 
4
4
  #include <rice/rice.hpp>
@@ -11,7 +11,6 @@ TESTSUITE(Module);
11
11
  SETUP(Module)
12
12
  {
13
13
  embed_ruby();
14
- define_fundamental_buffer_types();
15
14
  }
16
15
 
17
16
  TEARDOWN(Module)
@@ -208,8 +207,8 @@ TESTCASE(include_module)
208
207
  ASSERT_EQUAL(&m, &m2);
209
208
  Array ancestors(m.ancestors());
210
209
  Array expected_ancestors;
211
- expected_ancestors.push(m);
212
- expected_ancestors.push(Module(rb_mEnumerable));
210
+ expected_ancestors.push(m, false);
211
+ expected_ancestors.push(Module(rb_mEnumerable), false);
213
212
  ASSERT_EQUAL(expected_ancestors, ancestors);
214
213
  }
215
214
 
@@ -467,7 +466,7 @@ TESTCASE(define_method_works_with_pointers)
467
466
 
468
467
  int anInt = 3;
469
468
  Buffer<int> buffer(&anInt, 1);
470
- m.call("bar", std::move(buffer), "testing");
469
+ m.call("bar", buffer.ptr(), "testing");
471
470
 
472
471
  ASSERT_EQUAL(3, with_pointers_x);
473
472
  ASSERT_EQUAL("testing", with_pointers_str);
@@ -503,10 +502,10 @@ TESTCASE(pointers)
503
502
 
504
503
  Module m = define_module("TestingModule");
505
504
  std::string code = R"(int_buffer = Rice::Buffer≺int≻.new(32)
506
- bool_buffer = Rice::Buffer≺bool≻.new(true)
507
- double_buffer = Rice::Buffer≺float≻.new(33.0)
508
- float_buffer = Rice::Buffer≺double≻.new(34.0)
509
- with_pointers(int_buffer, bool_buffer, double_buffer, float_buffer))";
505
+ bool_buffer = Rice::Buffer≺bool≻.new(true)
506
+ double_buffer = Rice::Buffer≺float≻.new(33.0)
507
+ float_buffer = Rice::Buffer≺double≻.new(34.0)
508
+ with_pointers(int_buffer.data, bool_buffer.data, double_buffer.data, float_buffer.data))";
510
509
 
511
510
  m.module_eval(code);
512
511
 
data/test/test_Object.cpp CHANGED
@@ -194,7 +194,7 @@ TESTCASE(call_with_keywords)
194
194
  Hash keywords;
195
195
  keywords[":exception"] = false;
196
196
  Object result = m.call_kw("keywords_test", "charlie", keywords);
197
- ASSERT_EQUAL("charlie", detail::From_Ruby<const char*>().convert(result.value()));
197
+ ASSERT_EQUAL("charlie", detail::From_Ruby<char*>().convert(result.value()));
198
198
 
199
199
  keywords[":exception"] = true;
200
200
 
@@ -1,4 +1,4 @@
1
- #include "unittest.hpp"
1
+ #include "unittest.hpp"
2
2
  #include "embed_ruby.hpp"
3
3
  #include <rice/rice.hpp>
4
4
  #include <rice/stl.hpp>
@@ -647,13 +647,13 @@ TESTCASE(int_conversion_6)
647
647
  Class c = define_class<MyClass3>("MyClass3").
648
648
  define_constructor(Constructor<MyClass3>()).
649
649
  define_method<std::string(MyClass3::*)(unsigned char)>("run", &MyClass3::run).
650
- define_method<std::string(MyClass3::*)(unsigned char*)>("run", &MyClass3::run);
650
+ define_method<std::string(MyClass3::*)(unsigned char*)>("run", &MyClass3::run, Arg("value").setBuffer());
651
651
 
652
652
  Module m = define_module("Testing");
653
653
 
654
654
  std::string code = R"(my_class = MyClass3.new
655
- buffer = Rice::Buffer≺unsigned char≻.new("54")
656
- my_class.run(buffer))";
655
+ buffer = Rice::Buffer≺unsigned char≻.new("54")
656
+ my_class.run(buffer.data))";
657
657
  String result = m.module_eval(code);
658
658
  ASSERT_EQUAL("run<unsigned char*>", result.str());
659
659
  }
@@ -707,8 +707,8 @@ TESTCASE(NonConstRef)
707
707
  Module m = define_module("Testing");
708
708
 
709
709
  std::string code = R"(my_class4 = MyClass4.new
710
- my_class5 = MyClass5.new(my_class4)
711
- my_class5.result)";
710
+ my_class5 = MyClass5.new(my_class4)
711
+ my_class5.result)";
712
712
  String result = m.module_eval(code);
713
713
  ASSERT_EQUAL("non-const ref", result.str());
714
714
  }
@@ -726,8 +726,8 @@ TESTCASE(ConstRef)
726
726
  Module m = define_module("Testing");
727
727
 
728
728
  std::string code = R"(my_class4 = MyClass4.const_instance
729
- my_class5 = MyClass5.new(my_class4)
730
- my_class5.result)";
729
+ my_class5 = MyClass5.new(my_class4)
730
+ my_class5.result)";
731
731
  String result = m.module_eval(code);
732
732
  ASSERT_EQUAL("const ref", result.str());
733
733
  }
@@ -799,8 +799,56 @@ TESTCASE(ConstPointer)
799
799
  Module m = define_module("Testing");
800
800
 
801
801
  std::string code = R"(my_class6 = MyClass6.const_instance
802
- my_class7 = MyClass7.new(my_class6)
803
- my_class7.result)";
802
+ my_class7 = MyClass7.new(my_class6)
803
+ my_class7.result)";
804
804
  String result = m.module_eval(code);
805
805
  ASSERT_EQUAL("const pointer", result.str());
806
806
  }
807
+
808
+ namespace
809
+ {
810
+ std::string pointer(const MyClass6* data)
811
+ {
812
+ return "pointer";
813
+ }
814
+
815
+ std::string pointer(MyClass6* data)
816
+ {
817
+ return "pointerBuffer";
818
+ }
819
+ }
820
+
821
+ TESTCASE(PointerNotBuffer)
822
+ {
823
+ Module m = define_module("Testing");
824
+
825
+ define_class<MyClass6>("MyClass").
826
+ define_constructor(Constructor<MyClass6>());
827
+
828
+ m.define_module_function<std::string(*)(const MyClass6*)>("pointer", pointer).
829
+ define_module_function<std::string(*)(MyClass6*)>("pointer", pointer, Arg("data").setBuffer());
830
+
831
+ std::string code = R"(my_class6 = MyClass6.new
832
+ pointer(my_class6))";
833
+
834
+ String result = m.module_eval(code);
835
+ ASSERT_EQUAL("pointer", result.str());
836
+ }
837
+
838
+ TESTCASE(PointerBuffer)
839
+ {
840
+ Module m = define_module("Testing");
841
+
842
+ define_class<MyClass6>("MyClass").
843
+ define_constructor(Constructor<MyClass6>());
844
+
845
+ m.define_function<std::string(*)(const MyClass6*)>("pointer", pointer).
846
+ define_function<std::string(*)(MyClass6*)>("pointer", pointer, Arg("data").setBuffer());
847
+
848
+ std::string code = R"(my_class6 = MyClass6.new
849
+ buffer = Rice::Buffer≺AnonymousNamespace꞉꞉MyClass6≻.new(my_class6)
850
+ pointer(buffer.data))";
851
+
852
+ String result = m.module_eval(code);
853
+ ASSERT_EQUAL("pointerBuffer", result.str());
854
+ }
@@ -220,7 +220,7 @@ TESTCASE(keysAndValues)
220
220
  ASSERT_EQUAL(expected_values[2], values->operator[](2));
221
221
  }
222
222
 
223
- TESTCASE(Copy)
223
+ TESTCASE(CLone)
224
224
  {
225
225
  Module m = define_module("Testing");
226
226
 
@@ -231,15 +231,15 @@ TESTCASE(Copy)
231
231
  object.call("[]=", "two", 22.2);
232
232
  std::map<std::string, double>& map = detail::From_Ruby<std::map<std::string, double>&>().convert(object);
233
233
 
234
- Object result = object.call("copy");
235
- std::map<std::string, double>& mapCopy = detail::From_Ruby<std::map<std::string, double>&>().convert(result);
234
+ Object result = object.call("clone");
235
+ std::map<std::string, double>& mapClone = detail::From_Ruby<std::map<std::string, double>&>().convert(result);
236
236
 
237
- ASSERT_EQUAL(map.size(), mapCopy.size());
238
- ASSERT_EQUAL(map["one"], mapCopy["one"]);
239
- ASSERT_EQUAL(map["two"], mapCopy["two"]);
237
+ ASSERT_EQUAL(map.size(), mapClone.size());
238
+ ASSERT_EQUAL(map["one"], mapClone["one"]);
239
+ ASSERT_EQUAL(map["two"], mapClone["two"]);
240
240
 
241
- mapCopy["three"] = 33.3;
242
- ASSERT_NOT_EQUAL(map.size(), mapCopy.size());
241
+ mapClone["three"] = 33.3;
242
+ ASSERT_NOT_EQUAL(map.size(), mapClone.size());
243
243
  }
244
244
 
245
245
  TESTCASE(Iterate)
@@ -218,7 +218,7 @@ TESTCASE(keysAndValues)
218
218
  ASSERT_EQUAL(expected_values[2], values->operator[](2));
219
219
  }
220
220
 
221
- TESTCASE(Copy)
221
+ TESTCASE(Clone)
222
222
  {
223
223
  Module m = define_module("Testing");
224
224
 
@@ -229,10 +229,10 @@ TESTCASE(Copy)
229
229
  object.call("insert", "two", 22.2);
230
230
  std::multimap<std::string, double>& multimap = detail::From_Ruby<std::multimap<std::string, double>&>().convert(object);
231
231
 
232
- Object result = object.call("copy");
233
- std::multimap<std::string, double>& multimapCopy = detail::From_Ruby<std::multimap<std::string, double>&>().convert(result);
232
+ Object result = object.call("clone");
233
+ std::multimap<std::string, double>& multimapClone = detail::From_Ruby<std::multimap<std::string, double>&>().convert(result);
234
234
 
235
- ASSERT_EQUAL(multimap, multimapCopy);
235
+ ASSERT_EQUAL(multimap, multimapClone);
236
236
  }
237
237
 
238
238
  TESTCASE(Iterate)
@@ -1,4 +1,4 @@
1
- #include <utility>
1
+ #include <utility>
2
2
 
3
3
  #include "unittest.hpp"
4
4
  #include "embed_ruby.hpp"
@@ -59,17 +59,19 @@ TESTCASE(CreatePairConst)
59
59
  result = pair.call("second");
60
60
  ASSERT_EQUAL("pair2", detail::From_Ruby<std::string>().convert(result));
61
61
 
62
+ #ifdef _MSC_VER
62
63
  ASSERT_EXCEPTION_CHECK(
63
64
  Exception,
64
65
  pair.call("first=", "A second value"),
65
- ASSERT_EQUAL("Cannot set pair.first since it is a constant", ex.what())
66
+ ASSERT_EQUAL("undefined method 'first=' for an instance of Std::ConstStringPair", ex.what())
66
67
  );
67
68
 
68
69
  ASSERT_EXCEPTION_CHECK(
69
70
  Exception,
70
71
  pair.call("second=", "A second value"),
71
- ASSERT_EQUAL("Cannot set pair.second since it is a constant", ex.what())
72
+ ASSERT_EQUAL("undefined method 'second=' for an instance of Std::ConstStringPair", ex.what())
72
73
  );
74
+ #endif
73
75
  }
74
76
 
75
77
  namespace
@@ -1,4 +1,4 @@
1
- #include "unittest.hpp"
1
+ #include "unittest.hpp"
2
2
  #include "embed_ruby.hpp"
3
3
  #include <rice/rice.hpp>
4
4
  #include <rice/stl.hpp>
@@ -347,13 +347,30 @@ TESTCASE(Update)
347
347
  ASSERT_EQUAL(14, detail::From_Ruby<long>().convert(result.value()));
348
348
  }
349
349
 
350
+ TESTCASE(Klass)
351
+ {
352
+ detail::TypeMapper<std::shared_ptr<MyClass>> typeMapper;
353
+ Object expected = Object(rb_cObject).const_get("MyClass");
354
+ VALUE actual = typeMapper.rubyKlass();
355
+ ASSERT_EQUAL(expected.value(), actual);
356
+ }
357
+
358
+ TESTCASE(KlassSharedPtr)
359
+ {
360
+ define_shared_ptr<MyClass>();
361
+ detail::TypeMapper<std::shared_ptr<MyClass>> typeMapper;
362
+
363
+ Module stdModule("Std");
364
+ Object expected = stdModule.const_get("SharedPtr≺AnonymousNamespace꞉꞉MyClass≻");
365
+ VALUE actual = typeMapper.rubyKlass();
366
+ ASSERT_EQUAL(expected.value(), actual);
367
+ }
368
+
350
369
  TESTCASE(Void)
351
370
  {
352
371
  MyClass::reset();
353
372
  Factory::reset();
354
373
 
355
- detail::Type<Buffer<void>>::verify();
356
-
357
374
  Module m = define_module("TestingModule");
358
375
 
359
376
  // Create ruby objects that point to the same instance of MyClass
@@ -397,8 +414,6 @@ namespace
397
414
 
398
415
  TESTCASE(PointerToInt)
399
416
  {
400
- detail::Type<Buffer<int>>::verify();
401
-
402
417
  Module m = define_module("SharedPtrInt").
403
418
  define_module_function("create_pointer", &createPointer).
404
419
  define_module_function("get_pointer_value", &getPointerValue);
@@ -418,7 +433,7 @@ TESTCASE(CreatePointerToInt)
418
433
  define_shared_ptr<int>("SharedPtrInt");
419
434
 
420
435
  std::string code = R"(buffer = Rice::Buffer≺int≻.new(45)
421
- ptr = Std::SharedPtrInt.new(buffer)
436
+ ptr = Std::SharedPtrInt.new(buffer.release)
422
437
  get_pointer_value(ptr))";
423
438
 
424
439
  Object result = m.instance_eval(code);
@@ -433,7 +448,7 @@ TESTCASE(UpdatePointerToInt)
433
448
  define_shared_ptr<int>();
434
449
 
435
450
  std::string code = R"(buffer = Rice::Buffer≺int≻.new(45)
436
- ptr = Std::SharedPtr≺int≻.new(buffer)
451
+ ptr = Std::SharedPtr≺int≻.new(buffer.release)
437
452
  update_pointer_value(ptr))";
438
453
 
439
454
  Object result = m.instance_eval(code);
@@ -442,14 +457,11 @@ TESTCASE(UpdatePointerToInt)
442
457
 
443
458
  TESTCASE(ReadPointerToInt)
444
459
  {
445
- detail::Type<Buffer<int>>::verify();
446
-
447
460
  Module m = define_module("ReadPointerToInt").
448
- define_module_function("create_pointer", &createPointer);
461
+ define_module_function("create_pointer", &createPointer);
449
462
 
450
463
  std::string code = R"(ptr = create_pointer(50)
451
- buffer = Rice::Buffer≺int≻.new(ptr)
452
- buffer.to_ary(1))";
464
+ ptr.buffer.to_ary(1))";
453
465
 
454
466
  Array array = m.instance_eval(code);
455
467
  std::vector<int> actual = array.to_vector<int>();
@@ -91,3 +91,13 @@ TESTCASE(std_string_view_from_ruby_refefence)
91
91
  string.instance_eval("self[1] = 'a'");
92
92
  //ASSERT_EQUAL("tast", view);
93
93
  }
94
+
95
+ namespace {
96
+ std::string_view testStringViewReturn(Object self) {
97
+ return "test";
98
+ }
99
+ }
100
+
101
+ TESTCASE(use_string_view_in_wrapped_function) {
102
+ define_global_function("test_string_view_return", &testStringViewReturn);
103
+ }
@@ -54,7 +54,7 @@ namespace
54
54
  ASSERT_EQUAL(3, complex.imag());
55
55
 
56
56
  std::vector<int> vec = std::get<2>(tuple);
57
- ASSERT_EQUAL(3, vec.size());
57
+ ASSERT_EQUAL((size_t)3, vec.size());
58
58
  ASSERT_EQUAL(3, vec[0]);
59
59
  ASSERT_EQUAL(4, vec[1]);
60
60
  ASSERT_EQUAL(5, vec[2]);
@@ -199,4 +199,12 @@ TESTCASE(Update)
199
199
 
200
200
  Object result = m.instance_eval(code);
201
201
  ASSERT_EQUAL(11, detail::From_Ruby<long>().convert(result.value()));
202
+ }
203
+
204
+ TESTCASE(Klass)
205
+ {
206
+ detail::TypeMapper<std::unique_ptr<MyClass>> typeMapper;
207
+ Object expected = Object(rb_cObject).const_get("MyClass");
208
+ VALUE actual = typeMapper.rubyKlass();
209
+ ASSERT_EQUAL(expected.value(), actual);
202
210
  }
@@ -1,4 +1,4 @@
1
- #include <complex>
1
+ #include <complex>
2
2
  #include <memory>
3
3
 
4
4
  #include "unittest.hpp"
@@ -216,7 +216,7 @@ TESTCASE(KeysAndValues)
216
216
  ASSERT_EQUAL(3, values->operator[](2));
217
217
  }
218
218
 
219
- TESTCASE(Copy)
219
+ TESTCASE(Clone)
220
220
  {
221
221
  Module m = define_module("Testing");
222
222
 
@@ -227,15 +227,15 @@ TESTCASE(Copy)
227
227
  object.call("[]=", "two", 22.2);
228
228
  std::unordered_map<std::string, double>& unordered_map = detail::From_Ruby<std::unordered_map<std::string, double>&>().convert(object);
229
229
 
230
- Object result = object.call("copy");
231
- std::unordered_map<std::string, double>& unordered_mapCopy = detail::From_Ruby<std::unordered_map<std::string, double>&>().convert(result);
230
+ Object result = object.call("clone");
231
+ std::unordered_map<std::string, double>& unordered_mapClone = detail::From_Ruby<std::unordered_map<std::string, double>&>().convert(result);
232
232
 
233
- ASSERT_EQUAL(unordered_map.size(), unordered_mapCopy.size());
234
- ASSERT_EQUAL(unordered_map["one"], unordered_mapCopy["one"]);
235
- ASSERT_EQUAL(unordered_map["two"], unordered_mapCopy["two"]);
233
+ ASSERT_EQUAL(unordered_map.size(), unordered_mapClone.size());
234
+ ASSERT_EQUAL(unordered_map["one"], unordered_mapClone["one"]);
235
+ ASSERT_EQUAL(unordered_map["two"], unordered_mapClone["two"]);
236
236
 
237
- unordered_mapCopy["three"] = 33.3;
238
- ASSERT_NOT_EQUAL(unordered_map.size(), unordered_mapCopy.size());
237
+ unordered_mapClone["three"] = 33.3;
238
+ ASSERT_NOT_EQUAL(unordered_map.size(), unordered_mapClone.size());
239
239
  }
240
240
 
241
241
  TESTCASE(Iterate)
@@ -380,6 +380,14 @@ TESTCASE(RoundtripConstRef)
380
380
  ASSERT_EQUAL(Qnil, instance2.value());
381
381
  }
382
382
 
383
+ TESTCASE(Klass)
384
+ {
385
+ detail::TypeMapper<Variant_T> typeMapper;
386
+ Object expected = Object(rb_cObject).const_get("Object");
387
+ VALUE actual = typeMapper.rubyKlass();
388
+ ASSERT_EQUAL(expected.value(), actual);
389
+ }
390
+
383
391
  namespace
384
392
  {
385
393
  class MyClass4
@@ -456,8 +464,6 @@ namespace
456
464
 
457
465
  TESTCASE(Buffer)
458
466
  {
459
- define_buffer<int>();
460
- define_buffer<float>();
461
467
  using namespace std::complex_literals;
462
468
 
463
469
  define_class<MyClass5>("MyClass5").
@@ -476,4 +482,4 @@ TESTCASE(Buffer)
476
482
  myclass.buffer(1).to_ary(1).first)";
477
483
  result = m.module_eval(code);
478
484
  ASSERT_EQUAL(11.0, detail::From_Ruby<float>().convert(result));
479
- }
485
+ }