rice 4.3.3 → 4.5.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 (151) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +63 -26
  3. data/README.md +7 -2
  4. data/Rakefile +7 -1
  5. data/include/rice/rice.hpp +7291 -4430
  6. data/include/rice/stl.hpp +769 -222
  7. data/lib/mkmf-rice.rb +37 -95
  8. data/rice/Address_Registration_Guard.hpp +72 -3
  9. data/rice/Arg.hpp +19 -5
  10. data/rice/Arg.ipp +24 -0
  11. data/rice/Callback.hpp +21 -0
  12. data/rice/Callback.ipp +13 -0
  13. data/rice/Constructor.hpp +4 -27
  14. data/rice/Constructor.ipp +79 -0
  15. data/rice/Data_Object.hpp +74 -3
  16. data/rice/Data_Object.ipp +324 -32
  17. data/rice/Data_Type.hpp +215 -3
  18. data/rice/Data_Type.ipp +125 -64
  19. data/rice/Director.hpp +0 -2
  20. data/rice/Enum.hpp +4 -6
  21. data/rice/Enum.ipp +101 -57
  22. data/rice/Exception.hpp +62 -2
  23. data/rice/Exception.ipp +7 -12
  24. data/rice/JumpException.hpp +44 -0
  25. data/rice/JumpException.ipp +48 -0
  26. data/rice/MemoryView.hpp +11 -0
  27. data/rice/MemoryView.ipp +43 -0
  28. data/rice/Return.hpp +6 -26
  29. data/rice/Return.ipp +10 -16
  30. data/rice/detail/DefaultHandler.hpp +12 -0
  31. data/rice/detail/DefaultHandler.ipp +8 -0
  32. data/rice/detail/HandlerRegistry.hpp +5 -35
  33. data/rice/detail/HandlerRegistry.ipp +7 -11
  34. data/rice/detail/InstanceRegistry.hpp +1 -4
  35. data/rice/detail/MethodInfo.hpp +15 -5
  36. data/rice/detail/MethodInfo.ipp +78 -6
  37. data/rice/detail/Native.hpp +32 -0
  38. data/rice/detail/Native.ipp +129 -0
  39. data/rice/detail/NativeAttributeGet.hpp +51 -0
  40. data/rice/detail/NativeAttributeGet.ipp +51 -0
  41. data/rice/detail/NativeAttributeSet.hpp +43 -0
  42. data/rice/detail/NativeAttributeSet.ipp +82 -0
  43. data/rice/detail/NativeCallbackFFI.hpp +55 -0
  44. data/rice/detail/NativeCallbackFFI.ipp +151 -0
  45. data/rice/detail/NativeCallbackSimple.hpp +30 -0
  46. data/rice/detail/NativeCallbackSimple.ipp +29 -0
  47. data/rice/detail/NativeFunction.hpp +20 -21
  48. data/rice/detail/NativeFunction.ipp +199 -64
  49. data/rice/detail/NativeIterator.hpp +8 -11
  50. data/rice/detail/NativeIterator.ipp +27 -31
  51. data/rice/detail/NativeRegistry.hpp +24 -15
  52. data/rice/detail/NativeRegistry.ipp +23 -48
  53. data/rice/detail/Proc.hpp +4 -0
  54. data/rice/detail/Proc.ipp +85 -0
  55. data/rice/detail/Registries.hpp +0 -7
  56. data/rice/detail/Registries.ipp +0 -18
  57. data/rice/detail/RubyFunction.hpp +0 -3
  58. data/rice/detail/RubyFunction.ipp +4 -8
  59. data/rice/detail/RubyType.hpp +19 -0
  60. data/rice/detail/RubyType.ipp +187 -0
  61. data/rice/detail/TupleIterator.hpp +14 -0
  62. data/rice/detail/Type.hpp +5 -6
  63. data/rice/detail/Type.ipp +150 -33
  64. data/rice/detail/TypeRegistry.hpp +15 -7
  65. data/rice/detail/TypeRegistry.ipp +105 -12
  66. data/rice/detail/Wrapper.hpp +6 -5
  67. data/rice/detail/Wrapper.ipp +45 -23
  68. data/rice/detail/cpp_protect.hpp +5 -6
  69. data/rice/detail/default_allocation_func.ipp +0 -2
  70. data/rice/detail/from_ruby.hpp +37 -3
  71. data/rice/detail/from_ruby.ipp +911 -454
  72. data/rice/detail/ruby.hpp +18 -0
  73. data/rice/detail/to_ruby.hpp +41 -3
  74. data/rice/detail/to_ruby.ipp +437 -113
  75. data/rice/global_function.hpp +0 -4
  76. data/rice/global_function.ipp +1 -2
  77. data/rice/rice.hpp +105 -22
  78. data/rice/ruby_mark.hpp +4 -3
  79. data/rice/stl.hpp +4 -0
  80. data/test/embed_ruby.cpp +4 -1
  81. data/test/extconf.rb +2 -0
  82. data/test/ruby/test_multiple_extensions_same_class.rb +14 -14
  83. data/test/test_Address_Registration_Guard.cpp +5 -0
  84. data/test/test_Array.cpp +12 -1
  85. data/test/test_Attribute.cpp +103 -21
  86. data/test/test_Builtin_Object.cpp +5 -0
  87. data/test/test_Callback.cpp +231 -0
  88. data/test/test_Class.cpp +5 -31
  89. data/test/test_Constructor.cpp +69 -6
  90. data/test/test_Data_Object.cpp +9 -4
  91. data/test/test_Data_Type.cpp +428 -64
  92. data/test/test_Director.cpp +10 -5
  93. data/test/test_Enum.cpp +152 -40
  94. data/test/test_Exception.cpp +235 -0
  95. data/test/test_File.cpp +70 -0
  96. data/test/test_From_Ruby.cpp +542 -0
  97. data/test/test_Hash.cpp +5 -0
  98. data/test/test_Identifier.cpp +5 -0
  99. data/test/test_Inheritance.cpp +6 -1
  100. data/test/test_Iterator.cpp +5 -0
  101. data/test/test_JumpException.cpp +22 -0
  102. data/test/test_Keep_Alive.cpp +6 -1
  103. data/test/test_Keep_Alive_No_Wrapper.cpp +5 -0
  104. data/test/test_Memory_Management.cpp +5 -0
  105. data/test/test_Module.cpp +118 -64
  106. data/test/test_Native_Registry.cpp +2 -33
  107. data/test/test_Object.cpp +5 -0
  108. data/test/test_Overloads.cpp +631 -0
  109. data/test/test_Ownership.cpp +67 -4
  110. data/test/test_Proc.cpp +45 -0
  111. data/test/test_Self.cpp +5 -0
  112. data/test/test_Stl_Exception.cpp +109 -0
  113. data/test/test_Stl_Map.cpp +22 -8
  114. data/test/test_Stl_Optional.cpp +5 -0
  115. data/test/test_Stl_Pair.cpp +7 -2
  116. data/test/test_Stl_Reference_Wrapper.cpp +5 -0
  117. data/test/test_Stl_SmartPointer.cpp +210 -5
  118. data/test/test_Stl_String.cpp +5 -0
  119. data/test/test_Stl_String_View.cpp +5 -0
  120. data/test/test_Stl_Type.cpp +147 -0
  121. data/test/test_Stl_Unordered_Map.cpp +18 -7
  122. data/test/test_Stl_Variant.cpp +5 -0
  123. data/test/test_Stl_Vector.cpp +130 -8
  124. data/test/test_String.cpp +5 -0
  125. data/test/test_Struct.cpp +5 -0
  126. data/test/test_Symbol.cpp +5 -0
  127. data/test/test_Template.cpp +192 -0
  128. data/test/test_To_Ruby.cpp +152 -0
  129. data/test/test_Tracking.cpp +1 -0
  130. data/test/test_Type.cpp +100 -0
  131. data/test/test_global_functions.cpp +53 -6
  132. data/test/unittest.cpp +8 -0
  133. metadata +37 -20
  134. data/lib/version.rb +0 -3
  135. data/rice/Address_Registration_Guard_defn.hpp +0 -79
  136. data/rice/Data_Object_defn.hpp +0 -84
  137. data/rice/Data_Type_defn.hpp +0 -190
  138. data/rice/Exception_defn.hpp +0 -68
  139. data/rice/HandlerRegistration.hpp +0 -15
  140. data/rice/Identifier.hpp +0 -50
  141. data/rice/Identifier.ipp +0 -29
  142. data/rice/detail/ExceptionHandler.hpp +0 -8
  143. data/rice/detail/ExceptionHandler.ipp +0 -28
  144. data/rice/detail/ExceptionHandler_defn.hpp +0 -77
  145. data/rice/detail/Jump_Tag.hpp +0 -21
  146. data/rice/detail/NativeAttribute.hpp +0 -64
  147. data/rice/detail/NativeAttribute.ipp +0 -112
  148. data/rice/detail/from_ruby_defn.hpp +0 -38
  149. data/rice/detail/to_ruby_defn.hpp +0 -48
  150. data/test/test_Jump_Tag.cpp +0 -17
  151. data/test/test_To_From_Ruby.cpp +0 -399
@@ -60,6 +60,15 @@ namespace
60
60
  class Factory
61
61
  {
62
62
  public:
63
+ static void reset()
64
+ {
65
+ Factory::instance_.reset();
66
+ }
67
+
68
+ ~Factory()
69
+ {
70
+ }
71
+
63
72
  std::unique_ptr<MyClass> transfer()
64
73
  {
65
74
  return std::make_unique<MyClass>();
@@ -87,6 +96,43 @@ namespace
87
96
  static inline std::shared_ptr<MyClass> instance_;
88
97
  };
89
98
 
99
+ class Sink
100
+ {
101
+ public:
102
+ int takeOwnership(std::unique_ptr<MyClass> ptr)
103
+ {
104
+ return ptr->flag;
105
+ }
106
+
107
+ long shareOwnership(std::shared_ptr<MyClass> ptr)
108
+ {
109
+ return ptr.use_count();
110
+ }
111
+
112
+ int updatePointer(std::unique_ptr<MyClass>& ptr, MyClass* myClass)
113
+ {
114
+ ptr.reset(myClass);
115
+ return ptr->flag;
116
+ }
117
+
118
+ int updatePointer(std::shared_ptr<MyClass>& ptr, MyClass* myClass)
119
+ {
120
+ ptr.reset(myClass);
121
+ return ptr->flag;
122
+ }
123
+
124
+ std::shared_ptr<void> makeVoidShared(MyClass* myClass)
125
+ {
126
+ return std::shared_ptr<void>(myClass);
127
+ }
128
+
129
+ int handleVoid(std::shared_ptr<void>& ptr)
130
+ {
131
+ MyClass* myClass = static_cast<MyClass*>(ptr.get());
132
+ return myClass->flag;
133
+ }
134
+ };
135
+
90
136
  int extractFlagUniquePtrRef(std::unique_ptr<MyClass>& myClass)
91
137
  {
92
138
  return myClass->flag;
@@ -107,7 +153,12 @@ SETUP(SmartPointer)
107
153
  {
108
154
  embed_ruby();
109
155
 
156
+ #if RUBY_API_VERSION_MAJOR == 3 && RUBY_API_VERSION_MINOR >= 2
157
+ rb_eval_string("GC.stress = true");
158
+ #endif
159
+
110
160
  define_class<MyClass>("MyClass").
161
+ define_constructor(Constructor<MyClass>()).
111
162
  define_method("set_flag", &MyClass::setFlag);
112
163
 
113
164
  define_class<Factory>("Factory").
@@ -116,6 +167,21 @@ SETUP(SmartPointer)
116
167
  define_method("share", &Factory::share).
117
168
  define_method("share_ref", &Factory::share_ref);
118
169
 
170
+ define_class<Sink>("Sink").
171
+ define_constructor(Constructor<Sink>()).
172
+ define_method("take_ownership", &Sink::takeOwnership).
173
+ define_method("share_ownership", &Sink::shareOwnership).
174
+ define_method<int(Sink::*)(std::unique_ptr<MyClass>&, MyClass*)>("update_pointer", &Sink::updatePointer,
175
+ Arg("ptr"), Arg("myClass").takeOwnership()).
176
+ define_method<int(Sink::*)(std::shared_ptr<MyClass>&, MyClass*)>("update_pointer", &Sink::updatePointer,
177
+ Arg("ptr"), Arg("myClass").takeOwnership()).
178
+ define_method("make_void_shared", &Sink::makeVoidShared,
179
+ Arg("myClass").takeOwnership()).
180
+ define_method<int(Sink::*)(std::shared_ptr<void>&)>("handle_void", &Sink::handleVoid);
181
+
182
+ // Needed for shared_ptr<void>
183
+ define_class<void>("Void");
184
+
119
185
  define_global_function("extract_flag_unique_ptr_ref", &extractFlagUniquePtrRef);
120
186
  define_global_function("extract_flag_shared_ptr", &extractFlagSharedPtr);
121
187
  define_global_function("extract_flag_shared_ptr_ref", &extractFlagSharedPtrRef);
@@ -126,9 +192,18 @@ SETUP(SmartPointer)
126
192
  Arg("myClass") = std::make_shared<MyClass>());
127
193
  }
128
194
 
129
- TESTCASE(TransferOwnership)
195
+ TEARDOWN(SmartPointer)
196
+ {
197
+ rb_gc_start();
198
+ #if RUBY_API_VERSION_MAJOR == 3 && RUBY_API_VERSION_MINOR >= 2
199
+ rb_eval_string("GC.stress = false");
200
+ #endif
201
+ }
202
+
203
+ TESTCASE(takeOwnership)
130
204
  {
131
205
  MyClass::reset();
206
+ Factory::reset();
132
207
 
133
208
  Module m = define_module("TestingModule");
134
209
 
@@ -152,17 +227,19 @@ TESTCASE(TransferOwnership)
152
227
  TESTCASE(ShareOwnership)
153
228
  {
154
229
  MyClass::reset();
230
+ Factory::reset();
155
231
 
156
232
  Module m = define_module("TestingModule");
157
233
 
158
234
  // Create ruby objects that point to the same instance of MyClass
159
- std::string code = R"(factory = Factory.new
235
+ std::string code = R"(ary = Array.new
236
+ factory = Factory.new
160
237
  10.times do |i|
161
238
  my_class = factory.share
162
239
  my_class.set_flag(i)
240
+ ary << my_class
163
241
  end)";
164
242
 
165
-
166
243
  ASSERT_EQUAL(0, Factory::instance_.use_count());
167
244
  m.module_eval(code);
168
245
 
@@ -177,10 +254,10 @@ TESTCASE(ShareOwnership)
177
254
  ASSERT_EQUAL(9, Factory::instance_->flag);
178
255
  }
179
256
 
180
-
181
257
  TESTCASE(ShareOwnership2)
182
258
  {
183
259
  MyClass::reset();
260
+ Factory::reset();
184
261
 
185
262
  Module m = define_module("TestingModule");
186
263
 
@@ -208,6 +285,7 @@ TESTCASE(ShareOwnership2)
208
285
  TESTCASE(UniquePtrRefParameter)
209
286
  {
210
287
  MyClass::reset();
288
+ Factory::reset();
211
289
 
212
290
  Module m = define_module("TestingModule");
213
291
 
@@ -223,6 +301,7 @@ TESTCASE(UniquePtrRefParameter)
223
301
  TESTCASE(SharedPtrParameter)
224
302
  {
225
303
  MyClass::reset();
304
+ Factory::reset();
226
305
 
227
306
  Module m = define_module("TestingModule");
228
307
 
@@ -238,6 +317,7 @@ TESTCASE(SharedPtrParameter)
238
317
  TESTCASE(SharedPtrRefParameter)
239
318
  {
240
319
  MyClass::reset();
320
+ Factory::reset();
241
321
 
242
322
  Module m = define_module("TestingModule");
243
323
 
@@ -253,6 +333,7 @@ TESTCASE(SharedPtrRefParameter)
253
333
  TESTCASE(SharedPtrDefaultParameter)
254
334
  {
255
335
  MyClass::reset();
336
+ Factory::reset();
256
337
 
257
338
  Module m = define_module("TestingModule");
258
339
 
@@ -269,6 +350,7 @@ TESTCASE(SharedPtrDefaultParameter)
269
350
  TESTCASE(SharedPtrRefDefaultParameter)
270
351
  {
271
352
  MyClass::reset();
353
+ Factory::reset();
272
354
 
273
355
  Module m = define_module("TestingModule");
274
356
 
@@ -278,6 +360,129 @@ TESTCASE(SharedPtrRefDefaultParameter)
278
360
  extract_flag_shared_ptr_ref_with_default())";
279
361
 
280
362
  Object result = m.module_eval(code);
363
+ rb_gc_start();
364
+
281
365
  // The default value kicks in and ignores any previous pointer
282
366
  ASSERT_EQUAL(0, detail::From_Ruby<int>().convert(result));
283
- }
367
+
368
+ ASSERT_EQUAL(1, MyClass::constructorCalls);
369
+ ASSERT_EQUAL(0, MyClass::copyConstructorCalls);
370
+ ASSERT_EQUAL(0, MyClass::moveConstructorCalls);
371
+ // ASSERT_EQUAL(1, MyClass::destructorCalls);
372
+ }
373
+
374
+ TESTCASE(UniquePtrRoundTrip)
375
+ {
376
+ MyClass::reset();
377
+ Factory::reset();
378
+
379
+ Module m = define_module("TestingModule");
380
+
381
+ // Create ruby objects that point to the same instance of MyClass
382
+ std::string code = R"(factory = Factory.new
383
+ my_class = factory.transfer
384
+ my_class.set_flag(5)
385
+
386
+ sink = Sink.new
387
+ sink.take_ownership(my_class))";
388
+
389
+ Object result = m.instance_eval(code);
390
+ ASSERT_EQUAL(5, detail::From_Ruby<int>().convert(result.value()));
391
+
392
+ ASSERT_EQUAL(1, MyClass::constructorCalls);
393
+ ASSERT_EQUAL(0, MyClass::copyConstructorCalls);
394
+ ASSERT_EQUAL(0, MyClass::moveConstructorCalls);
395
+ // ASSERT_EQUAL(1, MyClass::destructorCalls);
396
+ }
397
+
398
+ TESTCASE(UniquePtrUpdate)
399
+ {
400
+ MyClass::reset();
401
+ Factory::reset();
402
+
403
+ Module m = define_module("TestingModule");
404
+
405
+ // Create ruby objects that point to the same instance of MyClass
406
+ std::string code = R"(factory = Factory.new
407
+ my_class1 = factory.transfer
408
+ my_class1.set_flag(5)
409
+
410
+ my_class2 = MyClass.new
411
+ my_class2.set_flag(11)
412
+
413
+ sink = Sink.new
414
+ sink.update_pointer(my_class1, my_class2))";
415
+
416
+ Object result = m.instance_eval(code);
417
+ ASSERT_EQUAL(11, detail::From_Ruby<long>().convert(result.value()));
418
+ }
419
+
420
+ TESTCASE(SharedPtrRoundTrip)
421
+ {
422
+ MyClass::reset();
423
+ Factory::reset();
424
+
425
+ Module m = define_module("TestingModule");
426
+
427
+ // Create ruby objects that point to the same instance of MyClass
428
+ std::string code = R"(factory = Factory.new
429
+ my_class = factory.share
430
+
431
+ sink = Sink.new
432
+ sink.share_ownership(my_class))";
433
+
434
+ Object result = m.instance_eval(code);
435
+ ASSERT_EQUAL(3, detail::From_Ruby<long>().convert(result.value()));
436
+
437
+ ASSERT_EQUAL(1, MyClass::constructorCalls);
438
+ ASSERT_EQUAL(0, MyClass::copyConstructorCalls);
439
+ ASSERT_EQUAL(0, MyClass::moveConstructorCalls);
440
+ // ASSERT_EQUAL(0, MyClass::destructorCalls);
441
+ }
442
+
443
+ TESTCASE(SharedPtrUpdate)
444
+ {
445
+ MyClass::reset();
446
+ Factory::reset();
447
+
448
+ Module m = define_module("TestingModule");
449
+
450
+ // Create ruby objects that point to the same instance of MyClass
451
+ std::string code = R"(factory = Factory.new
452
+ my_class1 = factory.share
453
+ my_class1.set_flag(7)
454
+
455
+ my_class2 = MyClass.new
456
+ my_class2.set_flag(14)
457
+
458
+ sink = Sink.new
459
+ sink.update_pointer(my_class1, my_class2))";
460
+
461
+ Object result = m.instance_eval(code);
462
+ ASSERT_EQUAL(14, detail::From_Ruby<long>().convert(result.value()));
463
+ }
464
+
465
+ TESTCASE(SharedPtrVoid)
466
+ {
467
+ MyClass::reset();
468
+ Factory::reset();
469
+
470
+ Module m = define_module("TestingModule");
471
+
472
+ // Create ruby objects that point to the same instance of MyClass
473
+ std::string code = R"(my_class = MyClass.new
474
+ my_class.set_flag(9)
475
+ sink = Sink.new
476
+ void_ptr = sink.make_void_shared(my_class)
477
+ sink.handle_void(void_ptr))";
478
+
479
+ Object result = m.instance_eval(code);
480
+ ASSERT_EQUAL(9, detail::From_Ruby<long>().convert(result.value()));
481
+
482
+ rb_gc_start();
483
+
484
+ ASSERT_EQUAL(1, MyClass::constructorCalls);
485
+ ASSERT_EQUAL(0, MyClass::copyConstructorCalls);
486
+ ASSERT_EQUAL(0, MyClass::moveConstructorCalls);
487
+ // ASSERT_EQUAL(1, MyClass::destructorCalls);
488
+ }
@@ -15,6 +15,11 @@ SETUP(StlString)
15
15
  embed_ruby();
16
16
  }
17
17
 
18
+ TEARDOWN(StlString)
19
+ {
20
+ rb_gc_start();
21
+ }
22
+
18
23
  TESTCASE(std_string_to_ruby)
19
24
  {
20
25
  ASSERT(rb_equal(String("").value(), detail::to_ruby(std::string(""))));
@@ -15,6 +15,11 @@ SETUP(StlStringView)
15
15
  embed_ruby();
16
16
  }
17
17
 
18
+ TEARDOWN(StlStringView)
19
+ {
20
+ rb_gc_start();
21
+ }
22
+
18
23
  TESTCASE(std_string_view_to_ruby)
19
24
  {
20
25
  ASSERT(rb_equal(String("").value(), detail::to_ruby(std::string_view(""))));
@@ -0,0 +1,147 @@
1
+ #include "unittest.hpp"
2
+ #include "embed_ruby.hpp"
3
+
4
+ #include <rice/rice.hpp>
5
+ #include <rice/stl.hpp>
6
+
7
+ using namespace Rice;
8
+
9
+ TESTSUITE(TypeInfo);
10
+
11
+ SETUP(TypeInfo)
12
+ {
13
+ embed_ruby();
14
+ }
15
+
16
+ TEARDOWN(TypeInfo)
17
+ {
18
+ rb_gc_start();
19
+ }
20
+
21
+ namespace
22
+ {
23
+ const std::type_info& typeInfo(int value)
24
+ {
25
+ return typeid(value);
26
+ }
27
+
28
+ const std::string typeInfoName(const std::type_info& value)
29
+ {
30
+ return value.name();
31
+ }
32
+
33
+ const std::type_index typeIndex(const std::type_info& value)
34
+ {
35
+ return std::type_index(value);
36
+ }
37
+ }
38
+
39
+ TESTCASE(TypeInfoName)
40
+ {
41
+ Module m = define_module("TestingModule");
42
+ m.define_module_function("get_type_info", typeInfo);
43
+
44
+ std::string code = R"(int = 5
45
+ type_info = get_type_info(5)
46
+ type_info.name)";
47
+
48
+ #ifdef _MSC_VER
49
+ const char* expected = "int";
50
+ #else
51
+ const char* expected = "i";
52
+ #endif
53
+
54
+ String result = m.module_eval(code);
55
+ ASSERT_EQUAL(expected, result.c_str());
56
+ }
57
+
58
+ TESTCASE(TypeInfoHash)
59
+ {
60
+ Module m = define_module("TestingModule");
61
+ m.define_module_function("get_type_info", typeInfo);
62
+
63
+ std::string code = R"(int = 5
64
+ type_info = get_type_info(5)
65
+ type_info.hash)";
66
+
67
+ Object result = m.module_eval(code);
68
+ size_t hash = detail::From_Ruby<size_t>().convert(result);
69
+ ASSERT((hash > 0));
70
+ }
71
+
72
+ TESTCASE(TypeInfoParameter)
73
+ {
74
+ Module m = define_module("TestingModule");
75
+ m.define_module_function("get_type_info", typeInfo).
76
+ define_module_function("get_type_info_name", typeInfoName);
77
+
78
+ std::string code = R"(int = 5
79
+ type_info = get_type_info(5)
80
+ get_type_info_name(type_info))";
81
+
82
+ #ifdef _MSC_VER
83
+ const char* expected = "int";
84
+ #else
85
+ const char* expected = "i";
86
+ #endif
87
+
88
+ String result = m.module_eval(code);
89
+ ASSERT_EQUAL(expected, result.c_str());
90
+ }
91
+
92
+ TESTCASE(TypeIndexCreate)
93
+ {
94
+ Module m = define_module("TestingModule");
95
+ m.define_module_function("get_type_info", typeInfo).
96
+ define_module_function("get_type_index", typeIndex);
97
+
98
+ std::string code = R"(int = 5
99
+ type_info = get_type_info(5)
100
+ Rice::Std::TypeIndex.new(type_info))";
101
+
102
+ #ifdef _MSC_VER
103
+ const char* expected = "int";
104
+ #else
105
+ const char* expected = "i";
106
+ #endif
107
+
108
+ Data_Object<std::type_index> result = m.module_eval(code);
109
+ ASSERT_EQUAL(expected, result->name());
110
+ }
111
+
112
+ TESTCASE(TypeIndexName)
113
+ {
114
+ Module m = define_module("TestingModule");
115
+ m.define_module_function("get_type_info", typeInfo).
116
+ define_module_function("get_type_index", typeIndex);
117
+
118
+ std::string code = R"(int = 5
119
+ type_info = get_type_info(5)
120
+ type_index = get_type_index(type_info)
121
+ type_index.name)";
122
+
123
+ #ifdef _MSC_VER
124
+ const char* expected = "int";
125
+ #else
126
+ const char* expected = "i";
127
+ #endif
128
+
129
+ String result = m.module_eval(code);
130
+ ASSERT_EQUAL(expected, result.str());
131
+ }
132
+
133
+ TESTCASE(TypeIndexHash)
134
+ {
135
+ Module m = define_module("TestingModule");
136
+ m.define_module_function("get_type_info", typeInfo).
137
+ define_module_function("get_type_index", typeIndex);
138
+
139
+ std::string code = R"(int = 5
140
+ type_info = get_type_info(5)
141
+ type_index = get_type_index(type_info)
142
+ type_index.hash)";
143
+
144
+ Object result = m.module_eval(code);
145
+ size_t hash = detail::From_Ruby<size_t>().convert(result);
146
+ ASSERT((hash > 0));
147
+ }
@@ -1,4 +1,4 @@
1
- #include <complex>
1
+ #include <complex>
2
2
  #include <memory>
3
3
 
4
4
  #include "unittest.hpp"
@@ -15,6 +15,11 @@ SETUP(UnorderedMap)
15
15
  embed_ruby();
16
16
  }
17
17
 
18
+ TEARDOWN(UnorderedMap)
19
+ {
20
+ rb_gc_start();
21
+ }
22
+
18
23
  namespace
19
24
  {
20
25
 
@@ -438,7 +443,7 @@ TESTCASE(AutoRegisterReturn)
438
443
 
439
444
  Module m = define_module("Testing");
440
445
  Object unordered_map = m.module_eval("return_complex_unordered_map");
441
- ASSERT_EQUAL("Rice::Std::Unordered_map__basic_string__char_char_traits__char___allocator__char_____complex__double___hash__basic_string__char_char_traits__char___allocator__char_______equal_to__basic_string__char_char_traits__char___allocator__char_______allocator__pair__basic_string__char_char_traits__char___allocator__char____Const_complex__double________",
446
+ ASSERT_EQUAL(u8"Rice::Std::UnorderedMap≺string≺char≻‚ complex≺double≻≻",
442
447
  unordered_map.class_name().str());
443
448
 
444
449
  std::string code = R"(unordered_map = return_complex_unordered_map
@@ -465,16 +470,16 @@ TESTCASE(AutoRegisterParameter)
465
470
  {
466
471
  define_global_function("pass_complex_unordered_map", &passComplexUnorderedMap);
467
472
 
468
- std::string code = R"(unordered_map = Rice::Std::Unordered_map__basic_string__char_char_traits__char___allocator__char_____complex__double___hash__basic_string__char_char_traits__char___allocator__char_______equal_to__basic_string__char_char_traits__char___allocator__char_______allocator__pair__basic_string__char_char_traits__char___allocator__char____Const_complex__double________.new
469
- unordered_map["four"] = Complex(4.0, 4.0)
470
- unordered_map["five"] = Complex(5.0, 5.0)
471
- pass_complex_unordered_map(unordered_map))";
473
+ std::string code = u8R"(unordered_map = Rice::Std::UnorderedMap≺string≺char≻‚ complex≺double≻≻.new
474
+ unordered_map["four"] = Complex(4.0, 4.0)
475
+ unordered_map["five"] = Complex(5.0, 5.0)
476
+ pass_complex_unordered_map(unordered_map))";
472
477
 
473
478
  Module m = define_module("Testing");
474
479
  Object unordered_map = m.module_eval(code);
475
480
 
476
481
  Object result = unordered_map.call("size");
477
- ASSERT_EQUAL("Rice::Std::Unordered_map__basic_string__char_char_traits__char___allocator__char_____complex__double___hash__basic_string__char_char_traits__char___allocator__char_______equal_to__basic_string__char_char_traits__char___allocator__char_______allocator__pair__basic_string__char_char_traits__char___allocator__char____Const_complex__double________",
482
+ ASSERT_EQUAL(u8"Rice::Std::UnorderedMap≺string≺char≻‚ complex≺double≻≻",
478
483
  unordered_map.class_name().str());
479
484
  ASSERT_EQUAL(2, detail::From_Ruby<int32_t>().convert(result));
480
485
 
@@ -653,6 +658,12 @@ TESTCASE(HashToUnorderedMapWrongTypes)
653
658
  "two" => 79.0,
654
659
  "three" => 1000.0}))";
655
660
 
661
+ ASSERT_EXCEPTION_CHECK(
662
+ Exception,
663
+ m.module_eval(code),
664
+ ASSERT_EQUAL(rb_eTypeError, ex.class_of())
665
+ );
666
+
656
667
  ASSERT_EXCEPTION_CHECK(
657
668
  Exception,
658
669
  m.module_eval(code),
@@ -289,6 +289,11 @@ SETUP(Variant)
289
289
  makeClassVariant();
290
290
  }
291
291
 
292
+ TEARDOWN(Variant)
293
+ {
294
+ rb_gc_start();
295
+ }
296
+
292
297
  TESTCASE(ClassReturns)
293
298
  {
294
299
  Module m = define_module("Testing");