rice 4.6.1 → 4.7.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 (185) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -0
  3. data/CMakeLists.txt +0 -4
  4. data/Rakefile +2 -8
  5. data/bin/rice-doc.rb +212 -0
  6. data/bin/rice-rbs.rb +93 -0
  7. data/include/rice/rice.hpp +4972 -4015
  8. data/include/rice/stl.hpp +822 -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 +101 -82
  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 +2 -2
  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 +34 -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 -2
  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 +27 -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 +5 -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 +11 -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 +0 -55
  138. data/test/test_Data_Type.cpp +19 -30
  139. data/test/test_Enum.cpp +4 -46
  140. data/test/test_From_Ruby.cpp +88 -81
  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 +3 -3
  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_Tuple.cpp +1 -1
  152. data/test/test_Stl_UniquePtr.cpp +8 -0
  153. data/test/test_Stl_Unordered_Map.cpp +9 -9
  154. data/test/test_Stl_Variant.cpp +9 -3
  155. data/test/test_Stl_Vector.cpp +118 -13
  156. data/test/test_To_Ruby.cpp +35 -28
  157. data/test/test_Type.cpp +256 -53
  158. data/test/unittest.hpp +35 -0
  159. metadata +66 -34
  160. data/rice/Init.hpp +0 -8
  161. data/rice/Init.ipp +0 -8
  162. data/rice/detail/RubyFunction.hpp +0 -31
  163. data/rice/detail/RubyFunction.ipp +0 -77
  164. data/sample/callbacks/extconf.rb +0 -5
  165. data/sample/callbacks/sample_callbacks.cpp +0 -35
  166. data/sample/callbacks/test.rb +0 -28
  167. data/sample/enum/extconf.rb +0 -5
  168. data/sample/enum/sample_enum.cpp +0 -40
  169. data/sample/enum/test.rb +0 -8
  170. data/sample/inheritance/animals.cpp +0 -82
  171. data/sample/inheritance/extconf.rb +0 -5
  172. data/sample/inheritance/test.rb +0 -7
  173. data/sample/map/extconf.rb +0 -5
  174. data/sample/map/map.cpp +0 -73
  175. data/sample/map/test.rb +0 -7
  176. data/test/ext/t1/Foo.hpp +0 -10
  177. data/test/ext/t1/extconf.rb +0 -4
  178. data/test/ext/t1/t1.cpp +0 -13
  179. data/test/ext/t2/extconf.rb +0 -4
  180. data/test/ext/t2/t2.cpp +0 -11
  181. data/test/ruby/test_callbacks_sample.rb +0 -28
  182. data/test/ruby/test_multiple_extensions.rb +0 -18
  183. data/test/ruby/test_multiple_extensions_same_class.rb +0 -14
  184. data/test/ruby/test_multiple_extensions_with_inheritance.rb +0 -20
  185. /data/test/{test_Stl_Type.cpp → test_Stl_Type_Info.cpp} +0 -0
data/test/test_Buffer.cpp CHANGED
@@ -43,6 +43,28 @@ TESTCASE(Char)
43
43
  ASSERT_EQUAL(9, (int)buffer.size());
44
44
  }
45
45
 
46
+ TESTCASE(CharMethods)
47
+ {
48
+ define_buffer<char>();
49
+ std::vector<detail::Native*> natives = detail::Registries::instance.natives.lookup(Data_Type<Buffer<char>>::klass());
50
+ ASSERT_EQUAL((size_t)12, natives.size());
51
+
52
+ define_buffer<char>();
53
+ natives = detail::Registries::instance.natives.lookup(Data_Type<Buffer<char>>::klass());
54
+ ASSERT_EQUAL((size_t)12, natives.size());
55
+ }
56
+
57
+ TESTCASE(CharPointerMethods)
58
+ {
59
+ define_buffer<char*>();
60
+ std::vector<detail::Native*> natives = detail::Registries::instance.natives.lookup(Data_Type<Buffer<char*>>::klass());
61
+ ASSERT_EQUAL((size_t)12, natives.size());
62
+
63
+ define_buffer<char*>();
64
+ natives = detail::Registries::instance.natives.lookup(Data_Type<Buffer<char*>>::klass());
65
+ ASSERT_EQUAL((size_t)12, natives.size());
66
+ }
67
+
46
68
  TESTCASE(CharArray)
47
69
  {
48
70
  define_buffer<char>();
@@ -64,6 +86,31 @@ TESTCASE(CharArray)
64
86
  ASSERT_EQUAL(data[7], 1);
65
87
  }
66
88
 
89
+ TESTCASE(ConstChar)
90
+ {
91
+ define_buffer<const char>();
92
+
93
+ Module m = define_module("BufferTesting");
94
+
95
+ std::string code = R"(Rice::Buffer≺char const≻.new("my string"))";
96
+ Object object = m.instance_eval(code);
97
+ ASSERT_EQUAL("Rice::Buffer≺char const≻", object.class_name().c_str());
98
+
99
+ String bytes = object.call("bytes");
100
+ ASSERT_EQUAL(std::string("my string"), bytes.str());
101
+
102
+ Array array = object.call("to_ary");
103
+ ASSERT_EQUAL("109, 121, 32, 115, 116, 114, 105, 110, 103", array.join(", ").c_str());
104
+
105
+ Object size = object.call("size");
106
+ ASSERT_EQUAL(9, detail::From_Ruby<int>().convert(size));
107
+
108
+ Data_Object<Buffer<const char>> dataObject(object);
109
+ Buffer<const char> buffer = std::move(*dataObject);
110
+ ASSERT_EQUAL(std::string("my string"), std::string(buffer.ptr(), buffer.size()));
111
+ ASSERT_EQUAL(9, (int)buffer.size());
112
+ }
113
+
67
114
  TESTCASE(signed_char_pointer)
68
115
  {
69
116
  define_buffer<signed char>();
@@ -162,14 +209,17 @@ TESTCASE(float_array_array)
162
209
 
163
210
  ASSERT_EQUAL(3, (int)buffer.size());
164
211
 
165
- const Buffer<float>& bufferInner1 = buffer[0];
166
- ASSERT_EQUAL(2, (int)bufferInner1.size());
212
+ float* values = buffer[0];
213
+ ASSERT_IN_DELTA(1.1, values[0], 0.1);
214
+ ASSERT_IN_DELTA(2.2, values[1], 0.1);
167
215
 
168
- const Buffer<float>& bufferInner2 = buffer[1];
169
- ASSERT_EQUAL(2, (int)bufferInner2.size());
216
+ values = buffer[1];
217
+ ASSERT_IN_DELTA(3.3, values[0], 0.1);
218
+ ASSERT_IN_DELTA(4.4, values[1], 0.1);
170
219
 
171
- const Buffer<float>& bufferInner3 = buffer[2];
172
- ASSERT_EQUAL(2, (int)bufferInner3.size());
220
+ values = buffer[2];
221
+ ASSERT_IN_DELTA(5.5, values[0], 0.1);
222
+ ASSERT_IN_DELTA(6.6, values[1], 0.1);
173
223
  }
174
224
 
175
225
  TESTCASE(wrong_type)
@@ -186,6 +236,43 @@ TESTCASE(wrong_type)
186
236
  );
187
237
  }
188
238
 
239
+ namespace
240
+ {
241
+ static double Speeds[] = { 44.0, 55.0, 66.0 };
242
+ static double* SpeedsPtr[] = { new double(44.0), new double(55.0), new double(66.0) };
243
+
244
+ double* speeds()
245
+ {
246
+ return Speeds;
247
+ }
248
+
249
+ double** speedsPtr()
250
+ {
251
+ return SpeedsPtr;
252
+ }
253
+ }
254
+
255
+ TESTCASE(pointer_of_doubles)
256
+ {
257
+ Module m = define_module("Testing").
258
+ define_module_function("speeds", &speeds, Return().setBuffer()).
259
+ define_module_function("speeds_ptr", &speedsPtr, Return().setBuffer());
260
+
261
+ std::string code = R"(buffer = Rice::Buffer≺double≻.new(speeds, 3)
262
+ buffer[2])";
263
+
264
+ Object result = m.module_eval(code);
265
+ ASSERT_EQUAL(66.0, detail::From_Ruby<double>().convert(result));
266
+
267
+ code = R"(buffer_outer = Rice::Buffer≺double∗≻.new(speeds_ptr, 3)
268
+ data = buffer_outer[2]
269
+ buffer_inner = Rice::Buffer≺double≻.new(data, 1)
270
+ buffer_inner[0])";
271
+
272
+ result = m.module_eval(code);
273
+ ASSERT_EQUAL(66.0, detail::From_Ruby<double>().convert(result));
274
+ }
275
+
189
276
  namespace
190
277
  {
191
278
  void updateRef(int& ref)
@@ -206,21 +293,21 @@ TESTCASE(update_reference)
206
293
  m.define_module_function("update_reference", &updateRef);
207
294
 
208
295
  std::string code = R"(buffer = Rice::Buffer≺int≻.new(0)
209
- update_reference(buffer)
296
+ update_reference(buffer.data)
210
297
  buffer.to_ary(1).first)";
211
298
 
212
299
  Object result = m.module_eval(code);
213
300
  ASSERT_EQUAL(4, detail::From_Ruby<int>().convert(result));
214
301
 
215
302
  code = R"(buffer = Rice::Buffer≺int≻.new(0)
216
- update_reference(buffer)
303
+ update_reference(buffer.data)
217
304
  buffer[0])";
218
305
 
219
306
  result = m.module_eval(code);
220
307
  ASSERT_EQUAL(4, detail::From_Ruby<int>().convert(result));
221
308
 
222
309
  code = R"(buffer = Rice::Buffer≺int≻.new(0)
223
- update_reference(buffer)
310
+ update_reference(buffer.data)
224
311
  buffer[1])";
225
312
 
226
313
  ASSERT_EXCEPTION_CHECK(
@@ -237,21 +324,21 @@ TESTCASE(update_ptr)
237
324
  m.define_module_function("update_pointer", &updatePtr);
238
325
 
239
326
  std::string code = R"(buffer = Rice::Buffer≺int≻.new(0)
240
- update_pointer(buffer)
327
+ update_pointer(buffer.data)
241
328
  buffer.to_ary(1).first)";
242
329
 
243
330
  Object result = m.module_eval(code);
244
331
  ASSERT_EQUAL(5, detail::From_Ruby<int>().convert(result));
245
332
 
246
333
  code = R"(buffer = Rice::Buffer≺int≻.new(0)
247
- update_pointer(buffer)
334
+ update_pointer(buffer.data)
248
335
  buffer[0])";
249
336
 
250
337
  result = m.module_eval(code);
251
338
  ASSERT_EQUAL(5, detail::From_Ruby<int>().convert(result));
252
339
 
253
340
  code = R"(buffer = Rice::Buffer≺int≻.new(0)
254
- update_pointer(buffer)
341
+ update_pointer(buffer.data)
255
342
  buffer[1])";
256
343
 
257
344
  ASSERT_EXCEPTION_CHECK(
@@ -284,6 +371,21 @@ TESTCASE(update_buffer)
284
371
  );
285
372
  }
286
373
 
374
+ TESTCASE(update_buffer_ptr)
375
+ {
376
+ define_buffer<int*>();
377
+
378
+ Module m = define_module("Testing");
379
+
380
+ std::string code = R"(buffer = Rice::Buffer≺int∗≻.new([[0, 1], [2, 3]])
381
+ inner = Rice::Buffer≺int≻.new(buffer[1], 2)
382
+ inner[1] = 9
383
+ inner[1])";
384
+
385
+ Object result = m.module_eval(code);
386
+ ASSERT_EQUAL(9, detail::From_Ruby<int>().convert(result));
387
+ }
388
+
287
389
  TESTCASE(to_s)
288
390
  {
289
391
  define_buffer<unsigned char>();
@@ -301,40 +403,214 @@ TESTCASE(to_s)
301
403
 
302
404
  namespace
303
405
  {
304
- class MyClass
406
+ class MyClassBuf
305
407
  {
306
408
  public:
307
- MyClass(int id) : id(id)
409
+ MyClassBuf(int id) : id(id)
308
410
  {
309
411
  }
310
412
 
311
- MyClass& operator=(const MyClass&) = delete;
413
+ // MyClassBuf& operator=(const MyClassBuf&) = delete;
312
414
 
313
415
  int id;
314
416
  };
417
+
418
+ static MyClassBuf myClassBufs[] = { 1,2,3 };
419
+ static MyClassBuf* myClassBufsPtr[] = { new MyClassBuf(1), new MyClassBuf(2), new MyClassBuf(3) };
420
+
421
+ MyClassBuf* classBufs()
422
+ {
423
+ return myClassBufs;
424
+ }
425
+
426
+ MyClassBuf** classBufsPtr()
427
+ {
428
+ return myClassBufsPtr;
429
+ }
430
+
431
+ size_t sumIds(const MyClassBuf* myClasses, size_t count)
432
+ {
433
+ int result = 0;
434
+ for (size_t i = 0; i < count; i++)
435
+ {
436
+ const MyClassBuf& myClass = myClasses[i];
437
+ result += myClass.id;
438
+ }
439
+ return result;
440
+ }
441
+
442
+ size_t sumIds(const MyClassBuf** myClasses, size_t count)
443
+ {
444
+ int result = 0;
445
+ for (size_t i = 0; i < count; i++)
446
+ {
447
+ const MyClassBuf* myClass = myClasses[i];
448
+ result += myClass->id;
449
+ }
450
+ return result;
451
+ }
315
452
  }
316
453
 
317
454
  TESTCASE(array_of_objects)
318
455
  {
319
- define_buffer<MyClass*>();
456
+ define_buffer<MyClassBuf>();
457
+
458
+ define_class<MyClassBuf>("MyClassBuf").
459
+ define_constructor(Constructor<MyClassBuf, int>()).
460
+ define_attr("id", &MyClassBuf::id);
461
+
462
+ std::string code = R"(array = [MyClassBuf.new(0), MyClassBuf.new(1)]
463
+ buffer = Rice::Buffer≺AnonymousNamespace꞉꞉MyClassBuf≻.new(array)
464
+ buffer[1].id)";
465
+
466
+ Module m = define_module("Testing");
467
+ Object result = m.module_eval(code);
468
+ ASSERT_EQUAL(1, detail::From_Ruby<int>().convert(result));
469
+ }
470
+
471
+ TESTCASE(update_array_of_objects)
472
+ {
473
+ define_buffer<MyClassBuf>();
320
474
 
321
- define_class<MyClass>("MyClass").
322
- define_constructor(Constructor<MyClass, int>()).
323
- define_attr("id", &MyClass::id);
475
+ define_class<MyClassBuf>("MyClassBuf").
476
+ define_constructor(Constructor<MyClassBuf, int>()).
477
+ define_attr("id", &MyClassBuf::id);
324
478
 
325
- std::string code = R"(array = [MyClass.new(0), MyClass.new(1)]
326
- buffer = Rice::Buffer≺AnonymousNamespace꞉꞉MyClass∗≻.new(array)
479
+ std::string code = R"(array = [MyClassBuf.new(0), MyClassBuf.new(1)]
480
+ buffer = Rice::Buffer≺AnonymousNamespace꞉꞉MyClassBuf≻.new(array)
481
+ buffer[1] = MyClassBuf.new(8)
482
+ buffer[1].id)";
483
+
484
+ Module m = define_module("Testing");
485
+ Object result = m.module_eval(code);
486
+ ASSERT_EQUAL(8, detail::From_Ruby<int>().convert(result));
487
+ }
488
+
489
+ TESTCASE(pointer_of_objects)
490
+ {
491
+ define_buffer<MyClassBuf>();
492
+ define_buffer<MyClassBuf*>();
493
+
494
+ Module m = define_module("Testing").
495
+ define_module_function("class_buffs", &classBufs).
496
+ define_module_function("class_buffs_ptr", &classBufsPtr);
497
+
498
+ define_class<MyClassBuf>("MyClassBuf").
499
+ define_constructor(Constructor<MyClassBuf, int>()).
500
+ define_attr("id", &MyClassBuf::id);
501
+
502
+ std::string code = R"(buffer = Rice::Buffer≺AnonymousNamespace꞉꞉MyClassBuf≻.new(class_buffs, 3)
503
+ buffer[1].id)";
504
+
505
+ Object result = m.module_eval(code);
506
+ ASSERT_EQUAL(2, detail::From_Ruby<int>().convert(result));
507
+
508
+ code = R"(buffer = Rice::Buffer≺AnonymousNamespace꞉꞉MyClassBuf∗≻.new(class_buffs_ptr, 3)
509
+ buffer[2].id)";
510
+
511
+ result = m.module_eval(code);
512
+ ASSERT_EQUAL(3, detail::From_Ruby<int>().convert(result));
513
+ }
514
+
515
+ TESTCASE(update_pointer_of_objects)
516
+ {
517
+ define_buffer<MyClassBuf*>();
518
+
519
+ Module m = define_module("Testing").
520
+ define_module_function("class_buffs", &classBufs).
521
+ define_module_function("class_buffs_ptr", &classBufsPtr);
522
+
523
+ define_class<MyClassBuf>("MyClassBuf").
524
+ define_constructor(Constructor<MyClassBuf, int>()).
525
+ define_attr("id", &MyClassBuf::id);
526
+
527
+ std::string code = R"(buffer = Rice::Buffer≺AnonymousNamespace꞉꞉MyClassBuf∗≻.new(class_buffs_ptr, 3)
528
+ inner = Rice::Buffer≺AnonymousNamespace꞉꞉MyClassBuf≻.new(buffer[2], 1)
529
+ inner[0] = MyClassBuf.new(7)
530
+ inner[0].id)";
531
+
532
+ Object result = m.module_eval(code);
533
+ ASSERT_EQUAL(7, detail::From_Ruby<int>().convert(result));
534
+
535
+ code = R"(buffer = Rice::Buffer≺AnonymousNamespace꞉꞉MyClassBuf∗≻.new(class_buffs_ptr, 3)
536
+ buffer[2] = MyClassBuf.new(9)
537
+ buffer[2].id)";
538
+
539
+ result = m.module_eval(code);
540
+ ASSERT_EQUAL(9, detail::From_Ruby<int>().convert(result));
541
+ }
542
+
543
+ TESTCASE(array_of_const_objects)
544
+ {
545
+ define_buffer<const MyClassBuf*>();
546
+
547
+ define_class<MyClassBuf>("MyClassBuf").
548
+ define_constructor(Constructor<MyClassBuf, int>()).
549
+ define_attr("id", &MyClassBuf::id);
550
+
551
+ std::string code = R"(array = [MyClassBuf.new(0), MyClassBuf.new(1)]
552
+ buffer = Rice::Buffer≺AnonymousNamespace꞉꞉MyClassBuf∗≻.new(array)
327
553
  buffer[1].id)";
328
554
 
329
555
  Module m = define_module("Testing");
330
556
  Object result = m.module_eval(code);
331
557
  ASSERT_EQUAL(1, detail::From_Ruby<int>().convert(result));
332
558
 
333
- code = R"(array = [MyClass.new(0), MyClass.new(1)]
334
- buffer = Rice::Buffer≺AnonymousNamespace꞉꞉MyClass∗≻.new(array)
335
- buffer[1] = MyClass.new(2)
336
- buffer[1].id)";
559
+ code = R"(array = [MyClassBuf.new(0), MyClassBuf.new(1)]
560
+ buffer = Rice::Buffer≺AnonymousNamespace꞉꞉MyClassBuf∗≻.new(array)
561
+ my_class = buffer[1]
562
+ my_class.id)";
337
563
 
338
564
  result = m.module_eval(code);
339
- ASSERT_EQUAL(2, detail::From_Ruby<int>().convert(result));
565
+ ASSERT_EQUAL(1, detail::From_Ruby<int>().convert(result));
566
+ }
567
+
568
+ TESTCASE(array_of_objects_ptr)
569
+ {
570
+ define_buffer<MyClassBuf*>();
571
+
572
+ define_class<MyClassBuf>("MyClassBuf").
573
+ define_constructor(Constructor<MyClassBuf, int>()).
574
+ define_attr("id", &MyClassBuf::id);
575
+
576
+ std::string code = R"(array = [MyClassBuf.new(0), MyClassBuf.new(1)]
577
+ buffer = Rice::Buffer≺AnonymousNamespace꞉꞉MyClassBuf∗≻.new(array)
578
+ buffer[1].id)";
579
+
580
+ Module m = define_module("Testing");
581
+ Object result = m.module_eval(code);
582
+ ASSERT_EQUAL(1, detail::From_Ruby<int>().convert(result));
583
+
584
+ code = R"(array = [MyClassBuf.new(0), MyClassBuf.new(1)]
585
+ buffer = Rice::Buffer≺AnonymousNamespace꞉꞉MyClassBuf∗≻.new(array)
586
+ my_class = buffer[1]
587
+ my_class.id)";
588
+
589
+ result = m.module_eval(code);
590
+ ASSERT_EQUAL(1, detail::From_Ruby<int>().convert(result));
591
+ }
592
+
593
+ TESTCASE(pass_objects)
594
+ {
595
+ Module m = define_module("Testing");
596
+ m.define_module_function<size_t(*)(const MyClassBuf*, size_t)>("sum_ids", &sumIds, Arg("myClasses").setBuffer());
597
+ m.define_module_function<size_t(*)(const MyClassBuf**, size_t)>("sum_ids_ptr", &sumIds);
598
+
599
+ define_class_under<MyClassBuf>(m, "MyClassBuf").
600
+ define_constructor(Constructor<MyClassBuf, int>()).
601
+ define_attr("id", &MyClassBuf::id);
602
+
603
+ std::string code = R"(array = [MyClassBuf.new(5), MyClassBuf.new(7)]
604
+ buffer = Rice::Buffer≺AnonymousNamespace꞉꞉MyClassBuf≻.new(array)
605
+ sum_ids(buffer.data, buffer.size))";
606
+
607
+ Object result = m.module_eval(code);
608
+ ASSERT_EQUAL(12, detail::From_Ruby<int>().convert(result));
609
+
610
+ code = R"(array = [MyClassBuf.new(5), MyClassBuf.new(7)]
611
+ buffer = Rice::Buffer≺AnonymousNamespace꞉꞉MyClassBuf∗≻.new(array)
612
+ sum_ids_ptr(buffer.data, buffer.size))";
613
+
614
+ result = m.module_eval(code);
615
+ ASSERT_EQUAL(12, detail::From_Ruby<int>().convert(result));
340
616
  }
@@ -47,12 +47,11 @@ TESTCASE(LambdaCallBack)
47
47
  ASSERT_EQUAL(globalCallback, nullptr);
48
48
 
49
49
  std::string code = R"(callback = lambda do |an_int, a_double, a_bool, a_string|
50
- values = [an_int, a_double, a_bool, a_string]
51
- values.map {|value| value.to_s}.join(" - ")
50
+ values = [an_int, a_double, a_bool, a_string]
51
+ values.map {|value| value.to_s}.join(" - ")
52
52
  end
53
53
  register_callback(callback))";
54
54
 
55
-
56
55
  m.module_eval(code);
57
56
  ASSERT((globalCallback != nullptr));
58
57
 
data/test/test_Class.cpp CHANGED
@@ -41,12 +41,12 @@ TESTCASE(include_module)
41
41
  ASSERT_EQUAL(&c, &c2);
42
42
  Array ancestors(c.ancestors());
43
43
  Array expected_ancestors;
44
- expected_ancestors.push(c);
45
- expected_ancestors.push(Module(rb_mEnumerable));
46
- expected_ancestors.push(Module(rb_cObject));
47
- expected_ancestors.push(Module(rb_mKernel));
44
+ expected_ancestors.push(c, false);
45
+ expected_ancestors.push(Module(rb_mEnumerable), false);
46
+ expected_ancestors.push(Module(rb_cObject), false);
47
+ expected_ancestors.push(Module(rb_mKernel), false);
48
48
  #ifdef RUBY_VM
49
- expected_ancestors.push(Module(rb_cBasicObject));
49
+ expected_ancestors.push(Module(rb_cBasicObject), false);
50
50
  #endif
51
51
  ASSERT_EQUAL(expected_ancestors, ancestors);
52
52
  }
@@ -25,17 +25,6 @@ namespace
25
25
  int x;
26
26
  };
27
27
 
28
- static MyDataType myDataTypes[] = { 1,2,3 };
29
- MyDataType* dataTypes()
30
- {
31
- return myDataTypes;
32
- }
33
-
34
- int dataTypesCount()
35
- {
36
- return sizeof(myDataTypes)/sizeof(MyDataType);
37
- }
38
-
39
28
  struct Bar
40
29
  {
41
30
  };
@@ -203,50 +192,6 @@ TESTCASE(data_object_from_ruby_copy)
203
192
  ASSERT_EQUAL(myDataType->x, detail::From_Ruby<MyDataType>().convert(wrapped_foo).x);
204
193
  }
205
194
 
206
- TESTCASE(data_object_return_array)
207
- {
208
- define_buffer<MyDataType>();
209
-
210
- Module m = define_module("DataObjectTest").
211
- define_module_function("data_types", &dataTypes, Return().setArray()).
212
- define_module_function("data_types_count", &dataTypesCount);
213
-
214
- std::string code = R"(buffer = data_types
215
- count = data_types_count
216
- buffer.to_ary(count))";
217
-
218
- Array dataTypes = m.module_eval(code);
219
- ASSERT_EQUAL(3, dataTypes.size());
220
-
221
- std::vector<MyDataType> vector = dataTypes.to_vector<MyDataType>();
222
- ASSERT_EQUAL(1, vector[0].x);
223
- ASSERT_EQUAL(2, vector[1].x);
224
- ASSERT_EQUAL(3, vector[2].x);
225
- }
226
-
227
- TESTCASE(data_object_update_buffer)
228
- {
229
- define_buffer<MyDataType>();
230
-
231
- Class c = define_class<MyDataType>("MyDataType")
232
- .define_constructor(Constructor<MyDataType, int>());
233
-
234
- Module m = define_module("DataObjectTest").
235
- define_module_function("data_types", &dataTypes, Return().setArray()).
236
- define_module_function("data_types_count", &dataTypesCount);
237
-
238
- std::string code = R"(buffer = data_types
239
- my_data_type = MyDataType.new(100)
240
- buffer.size = 3
241
- buffer[2] = my_data_type
242
- buffer)";
243
-
244
- Object result = m.module_eval(code);
245
- Data_Object<Buffer<MyDataType>> dataObject(result);
246
- Buffer<MyDataType>* buffer = dataObject.get();
247
- MyDataType myDataType = buffer->operator[](2);
248
- ASSERT_EQUAL(100, myDataType.x);
249
- }
250
195
 
251
196
  TESTCASE(data_object_ruby_custom_mark)
252
197
  {