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
@@ -0,0 +1,430 @@
1
+ namespace Rice::detail
2
+ {
3
+ template<>
4
+ struct Type<bool>
5
+ {
6
+ static bool verify()
7
+ {
8
+ return true;
9
+ }
10
+
11
+ static VALUE rubyKlass()
12
+ {
13
+ return rb_cTrueClass;
14
+ }
15
+ };
16
+
17
+ template<>
18
+ struct Type<char>
19
+ {
20
+ static bool verify()
21
+ {
22
+ return true;
23
+ }
24
+
25
+ static VALUE rubyKlass()
26
+ {
27
+ return rb_cString;
28
+ }
29
+ };
30
+
31
+ template<int N>
32
+ struct Type<char[N]>
33
+ {
34
+ static bool verify()
35
+ {
36
+ return true;
37
+ }
38
+
39
+ static VALUE rubyKlass()
40
+ {
41
+ return rb_cString;
42
+ }
43
+ };
44
+
45
+ template<>
46
+ struct Type<char*>
47
+ {
48
+ static bool verify()
49
+ {
50
+ return true;
51
+ }
52
+
53
+ static VALUE rubyKlass()
54
+ {
55
+ return rb_cString;
56
+ }
57
+ };
58
+
59
+ template<>
60
+ struct Type<signed char>
61
+ {
62
+ static bool verify()
63
+ {
64
+ return true;
65
+ }
66
+
67
+ static VALUE rubyKlass()
68
+ {
69
+ return rb_cString;
70
+ }
71
+ };
72
+
73
+ template<int N>
74
+ struct Type<signed char[N]>
75
+ {
76
+ static bool verify()
77
+ {
78
+ define_buffer<signed char>();
79
+ return true;
80
+ }
81
+
82
+ static VALUE rubyKlass()
83
+ {
84
+ return rb_cString;
85
+ }
86
+ };
87
+
88
+ template<>
89
+ struct Type<unsigned char>
90
+ {
91
+ static bool verify()
92
+ {
93
+ return true;
94
+ }
95
+
96
+ static VALUE rubyKlass()
97
+ {
98
+ return rb_cString;
99
+ }
100
+ };
101
+
102
+ template<int N>
103
+ struct Type<unsigned char[N]>
104
+ {
105
+ static bool verify()
106
+ {
107
+ define_buffer<unsigned char>();
108
+ return true;
109
+ }
110
+
111
+ static VALUE rubyKlass()
112
+ {
113
+ return rb_cString;
114
+ }
115
+ };
116
+
117
+ template<>
118
+ struct Type<short>
119
+ {
120
+ static bool verify()
121
+ {
122
+ return true;
123
+ }
124
+
125
+ static VALUE rubyKlass()
126
+ {
127
+ return rb_cInteger;
128
+ }
129
+ };
130
+
131
+ template<int N>
132
+ struct Type<short[N]>
133
+ {
134
+ static bool verify()
135
+ {
136
+ define_buffer<short>();
137
+ return true;
138
+ }
139
+
140
+ static VALUE rubyKlass()
141
+ {
142
+ return rb_cString;
143
+ }
144
+ };
145
+
146
+ template<>
147
+ struct Type<unsigned short>
148
+ {
149
+ static bool verify()
150
+ {
151
+ return true;
152
+ }
153
+
154
+ static VALUE rubyKlass()
155
+ {
156
+ return rb_cInteger;
157
+ }
158
+ };
159
+
160
+ template<int N>
161
+ struct Type<unsigned short[N]>
162
+ {
163
+ static bool verify()
164
+ {
165
+ define_buffer<unsigned short>();
166
+ return true;
167
+ }
168
+
169
+ static VALUE rubyKlass()
170
+ {
171
+ return rb_cString;
172
+ }
173
+ };
174
+
175
+ template<>
176
+ struct Type<int>
177
+ {
178
+ static bool verify()
179
+ {
180
+ return true;
181
+ }
182
+
183
+ static VALUE rubyKlass()
184
+ {
185
+ return rb_cInteger;
186
+ }
187
+ };
188
+
189
+ template<int N>
190
+ struct Type<int[N]>
191
+ {
192
+ static bool verify()
193
+ {
194
+ define_buffer<int>();
195
+ return true;
196
+ }
197
+
198
+ static VALUE rubyKlass()
199
+ {
200
+ return rb_cString;
201
+ }
202
+ };
203
+
204
+ template<>
205
+ struct Type<unsigned int>
206
+ {
207
+ static bool verify()
208
+ {
209
+ return true;
210
+ }
211
+
212
+ static VALUE rubyKlass()
213
+ {
214
+ return rb_cInteger;
215
+ }
216
+ };
217
+
218
+ template<int N>
219
+ struct Type<unsigned int[N]>
220
+ {
221
+ static bool verify()
222
+ {
223
+ define_buffer<unsigned int>();
224
+ return true;
225
+ }
226
+
227
+ static VALUE rubyKlass()
228
+ {
229
+ return rb_cString;
230
+ }
231
+ };
232
+
233
+ template<>
234
+ struct Type<long>
235
+ {
236
+ static bool verify()
237
+ {
238
+ return true;
239
+ }
240
+
241
+ static VALUE rubyKlass()
242
+ {
243
+ return rb_cInteger;
244
+ }
245
+ };
246
+
247
+ template<int N>
248
+ struct Type<long[N]>
249
+ {
250
+ static bool verify()
251
+ {
252
+ define_buffer<long>();
253
+ return true;
254
+ }
255
+
256
+ static VALUE rubyKlass()
257
+ {
258
+ return rb_cString;
259
+ }
260
+ };
261
+
262
+ template<>
263
+ struct Type<unsigned long>
264
+ {
265
+ static bool verify()
266
+ {
267
+ return true;
268
+ }
269
+
270
+ static VALUE rubyKlass()
271
+ {
272
+ return rb_cInteger;
273
+ }
274
+ };
275
+
276
+ template<int N>
277
+ struct Type<unsigned long[N]>
278
+ {
279
+ static bool verify()
280
+ {
281
+ define_buffer<unsigned long>();
282
+ return true;
283
+ }
284
+
285
+ static VALUE rubyKlass()
286
+ {
287
+ return rb_cString;
288
+ }
289
+ };
290
+
291
+ template<>
292
+ struct Type<long long>
293
+ {
294
+ static bool verify()
295
+ {
296
+ return true;
297
+ }
298
+
299
+ static VALUE rubyKlass()
300
+ {
301
+ return rb_cInteger;
302
+ }
303
+ };
304
+
305
+ template<int N>
306
+ struct Type<long long[N]>
307
+ {
308
+ static bool verify()
309
+ {
310
+ define_buffer<long long>();
311
+ return true;
312
+ }
313
+
314
+ static VALUE rubyKlass()
315
+ {
316
+ return rb_cString;
317
+ }
318
+ };
319
+
320
+ template<>
321
+ struct Type<unsigned long long>
322
+ {
323
+ static bool verify()
324
+ {
325
+ return true;
326
+ }
327
+
328
+ static VALUE rubyKlass()
329
+ {
330
+ return rb_cInteger;
331
+ }
332
+ };
333
+
334
+ template<int N>
335
+ struct Type<unsigned long long[N]>
336
+ {
337
+ static bool verify()
338
+ {
339
+ define_buffer<unsigned long long>();
340
+ return true;
341
+ }
342
+
343
+ static VALUE rubyKlass()
344
+ {
345
+ return rb_cString;
346
+ }
347
+ };
348
+
349
+ template<>
350
+ struct Type<float>
351
+ {
352
+ static bool verify()
353
+ {
354
+ return true;
355
+ }
356
+
357
+ static VALUE rubyKlass()
358
+ {
359
+ return rb_cFloat;
360
+ }
361
+ };
362
+
363
+ template<int N>
364
+ struct Type<float[N]>
365
+ {
366
+ static bool verify()
367
+ {
368
+ define_buffer<float>();
369
+ return true;
370
+ }
371
+
372
+ static VALUE rubyKlass()
373
+ {
374
+ return rb_cString;
375
+ }
376
+ };
377
+
378
+ template<>
379
+ struct Type<double>
380
+ {
381
+ static bool verify()
382
+ {
383
+ return true;
384
+ }
385
+
386
+ static VALUE rubyKlass()
387
+ {
388
+ return rb_cFloat;
389
+ }
390
+ };
391
+
392
+ template<int N>
393
+ struct Type<double[N]>
394
+ {
395
+ static bool verify()
396
+ {
397
+ define_buffer<double>();
398
+ return true;
399
+ }
400
+
401
+ static VALUE rubyKlass()
402
+ {
403
+ return rb_cString;
404
+ }
405
+ };
406
+
407
+ template<>
408
+ struct Type<void>
409
+ {
410
+ static bool verify()
411
+ {
412
+ return true;
413
+ }
414
+
415
+ static VALUE rubyKlass()
416
+ {
417
+ return rb_cNilClass;
418
+ }
419
+ };
420
+
421
+ template<>
422
+ struct Type<void*>
423
+ {
424
+ static bool verify()
425
+ {
426
+ Type<Pointer<void>>::verify();
427
+ return true;
428
+ }
429
+ };
430
+ }
@@ -63,6 +63,18 @@ namespace Rice::detail
63
63
  T* data_ = nullptr;
64
64
  };
65
65
 
66
+ template <typename T>
67
+ class Wrapper<T**> : public WrapperBase
68
+ {
69
+ public:
70
+ Wrapper(T** data, bool isOwner);
71
+ ~Wrapper();
72
+ void* get() override;
73
+
74
+ private:
75
+ T** data_ = nullptr;
76
+ };
77
+
66
78
  // ---- Helper Functions ---------
67
79
  template <typename T>
68
80
  void wrapConstructed(VALUE value, rb_data_type_t* rb_data_type, T* data, bool isOwner);
@@ -94,6 +94,33 @@ namespace Rice::detail
94
94
  return (void*)this->data_;
95
95
  }
96
96
 
97
+ // ---- Wrapper** -----
98
+ template <typename T>
99
+ inline Wrapper<T**>::Wrapper(T** data, bool isOwner) : data_(data)
100
+ {
101
+ this->isOwner_ = isOwner;
102
+ this->isConst_ = std::is_const_v<std::remove_pointer_t<std::remove_pointer_t<T>>>;
103
+ }
104
+
105
+ template <typename T>
106
+ inline Wrapper<T**>::~Wrapper()
107
+ {
108
+ Registries::instance.instances.remove(this->get());
109
+ if constexpr (std::is_destructible_v<T>)
110
+ {
111
+ if (this->isOwner_)
112
+ {
113
+ delete this->data_;
114
+ }
115
+ }
116
+ }
117
+
118
+ template <typename T>
119
+ inline void* Wrapper<T**>::get()
120
+ {
121
+ return (void*)this->data_;
122
+ }
123
+
97
124
  // ---- Helper Functions -------
98
125
  template <typename T>
99
126
  inline VALUE wrap(VALUE klass, rb_data_type_t* rb_data_type, T& data, bool isOwner)
@@ -112,6 +139,21 @@ namespace Rice::detail
112
139
  result = TypedData_Wrap_Struct(klass, rb_data_type, wrapper);
113
140
  }
114
141
 
142
+ // std::is_copy_constructible_v<std::vector<std::unique_ptr<T>>>> return true. Sigh.
143
+ else if constexpr (detail::is_std_vector_v<T>)
144
+ {
145
+ if constexpr (std::is_copy_constructible_v<typename T::value_type>)
146
+ {
147
+ wrapper = new Wrapper<T>(data);
148
+ result = TypedData_Wrap_Struct(klass, rb_data_type, wrapper);
149
+ }
150
+ else
151
+ {
152
+ wrapper = new Wrapper<T>(std::move(data));
153
+ result = TypedData_Wrap_Struct(klass, rb_data_type, wrapper);
154
+ }
155
+ }
156
+
115
157
  // Ruby is the owner so copy data
116
158
  else if constexpr (std::is_copy_constructible_v<T>)
117
159
  {
@@ -122,14 +164,15 @@ namespace Rice::detail
122
164
  // Ruby is the owner so move data
123
165
  else if constexpr (std::is_move_constructible_v<T>)
124
166
  {
125
- wrapper = new Wrapper<T>(std::forward<T>(data));
167
+ wrapper = new Wrapper<T>(std::move(data));
126
168
  result = TypedData_Wrap_Struct(klass, rb_data_type, wrapper);
127
169
  }
128
170
 
129
171
  else
130
172
  {
173
+ detail::TypeMapper<T> typeMapper;
131
174
  std::string message = "Rice was directed to take ownership of a C++ object but it does not have an accessible copy or move constructor. Type: " +
132
- typeName(typeid(T));
175
+ typeMapper.name();
133
176
  throw std::runtime_error(message);
134
177
  }
135
178