rice 4.7.1 → 4.8.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 (153) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -1
  3. data/CMakeLists.txt +14 -22
  4. data/CMakePresets.json +203 -75
  5. data/FindRuby.cmake +358 -123
  6. data/bin/rice-doc.rb +56 -141
  7. data/include/rice/api.hpp +248 -0
  8. data/include/rice/rice.hpp +2237 -1657
  9. data/include/rice/stl.hpp +346 -443
  10. data/lib/rice/doc/config.rb +70 -0
  11. data/lib/rice/doc/cpp_reference.rb +1 -4
  12. data/lib/rice/doc/mkdocs.rb +58 -20
  13. data/lib/rice/doc/rice.rb +20 -0
  14. data/lib/rice/doc.rb +1 -0
  15. data/lib/rice/make_rice_headers.rb +7 -0
  16. data/lib/rice/native_registry.rb +2 -2
  17. data/lib/rice/rbs.rb +2 -2
  18. data/lib/rice/version.rb +1 -1
  19. data/lib/rubygems_plugin.rb +12 -9
  20. data/rice/Arg.hpp +12 -6
  21. data/rice/Arg.ipp +14 -7
  22. data/rice/Buffer.ipp +44 -40
  23. data/rice/Callback.hpp +1 -1
  24. data/rice/Callback.ipp +2 -7
  25. data/rice/Constructor.hpp +1 -1
  26. data/rice/Constructor.ipp +11 -11
  27. data/rice/Data_Object.ipp +15 -15
  28. data/rice/Data_Type.hpp +9 -10
  29. data/rice/Data_Type.ipp +22 -25
  30. data/rice/Director.hpp +1 -0
  31. data/rice/Enum.ipp +58 -39
  32. data/rice/Exception.hpp +4 -4
  33. data/rice/Exception.ipp +7 -7
  34. data/rice/NoGVL.hpp +13 -0
  35. data/rice/Reference.hpp +56 -0
  36. data/rice/Reference.ipp +96 -0
  37. data/rice/Return.hpp +4 -1
  38. data/rice/Return.ipp +0 -6
  39. data/rice/cpp_api/Array.hpp +41 -4
  40. data/rice/cpp_api/Array.ipp +105 -9
  41. data/rice/cpp_api/Class.hpp +2 -2
  42. data/rice/cpp_api/Class.ipp +4 -4
  43. data/rice/cpp_api/Hash.ipp +7 -4
  44. data/rice/cpp_api/Module.hpp +4 -4
  45. data/rice/cpp_api/Module.ipp +12 -10
  46. data/rice/cpp_api/Object.hpp +4 -4
  47. data/rice/cpp_api/Object.ipp +15 -12
  48. data/rice/cpp_api/String.hpp +2 -2
  49. data/rice/cpp_api/String.ipp +11 -8
  50. data/rice/cpp_api/Symbol.ipp +7 -7
  51. data/rice/cpp_api/shared_methods.hpp +5 -9
  52. data/rice/detail/InstanceRegistry.hpp +0 -2
  53. data/rice/detail/Native.hpp +31 -21
  54. data/rice/detail/Native.ipp +282 -130
  55. data/rice/detail/NativeAttributeGet.hpp +5 -7
  56. data/rice/detail/NativeAttributeGet.ipp +26 -26
  57. data/rice/detail/NativeAttributeSet.hpp +2 -4
  58. data/rice/detail/NativeAttributeSet.ipp +20 -16
  59. data/rice/detail/NativeCallback.hpp +77 -0
  60. data/rice/detail/NativeCallback.ipp +280 -0
  61. data/rice/detail/NativeFunction.hpp +11 -21
  62. data/rice/detail/NativeFunction.ipp +58 -119
  63. data/rice/detail/NativeInvoker.hpp +4 -4
  64. data/rice/detail/NativeInvoker.ipp +7 -7
  65. data/rice/detail/NativeIterator.hpp +2 -4
  66. data/rice/detail/NativeIterator.ipp +18 -14
  67. data/rice/detail/NativeMethod.hpp +10 -20
  68. data/rice/detail/NativeMethod.ipp +54 -114
  69. data/rice/detail/NativeProc.hpp +5 -7
  70. data/rice/detail/NativeProc.ipp +39 -28
  71. data/rice/detail/NativeRegistry.hpp +0 -1
  72. data/rice/detail/Parameter.hpp +15 -8
  73. data/rice/detail/Parameter.ipp +102 -43
  74. data/rice/detail/Proc.ipp +14 -28
  75. data/rice/detail/RubyType.ipp +2 -53
  76. data/rice/detail/Type.hpp +23 -7
  77. data/rice/detail/Type.ipp +73 -93
  78. data/rice/detail/TypeRegistry.ipp +5 -4
  79. data/rice/detail/Wrapper.hpp +1 -1
  80. data/rice/detail/Wrapper.ipp +18 -10
  81. data/rice/detail/from_ruby.hpp +8 -6
  82. data/rice/detail/from_ruby.ipp +306 -173
  83. data/rice/detail/ruby.hpp +23 -0
  84. data/rice/libc/file.hpp +4 -4
  85. data/rice/rice.hpp +6 -8
  86. data/rice/rice_api/Native.ipp +5 -1
  87. data/rice/rice_api/Parameter.ipp +1 -1
  88. data/rice/ruby_mark.hpp +2 -1
  89. data/rice/stl/complex.ipp +12 -8
  90. data/rice/stl/map.ipp +27 -22
  91. data/rice/stl/monostate.ipp +16 -12
  92. data/rice/stl/multimap.hpp +0 -2
  93. data/rice/stl/multimap.ipp +27 -22
  94. data/rice/stl/optional.ipp +27 -11
  95. data/rice/stl/pair.ipp +5 -5
  96. data/rice/stl/reference_wrapper.ipp +5 -4
  97. data/rice/stl/set.ipp +16 -16
  98. data/rice/stl/shared_ptr.hpp +0 -16
  99. data/rice/stl/shared_ptr.ipp +34 -190
  100. data/rice/stl/string.ipp +18 -18
  101. data/rice/stl/string_view.ipp +1 -1
  102. data/rice/stl/tuple.ipp +15 -36
  103. data/rice/stl/unique_ptr.ipp +18 -8
  104. data/rice/stl/unordered_map.ipp +20 -15
  105. data/rice/stl/variant.ipp +37 -21
  106. data/rice/stl/vector.ipp +41 -36
  107. data/rice/traits/function_traits.hpp +19 -19
  108. data/rice/traits/method_traits.hpp +4 -4
  109. data/rice/traits/rice_traits.hpp +162 -39
  110. data/rice.gemspec +1 -3
  111. data/test/test_Array.cpp +261 -3
  112. data/test/test_Attribute.cpp +6 -3
  113. data/test/test_Buffer.cpp +6 -42
  114. data/test/test_Callback.cpp +77 -23
  115. data/test/test_Data_Object.cpp +1 -1
  116. data/test/test_Data_Type.cpp +21 -22
  117. data/test/test_Director.cpp +2 -4
  118. data/test/test_Enum.cpp +34 -5
  119. data/test/test_File.cpp +9 -5
  120. data/test/test_From_Ruby.cpp +4 -3
  121. data/test/test_GVL.cpp +3 -3
  122. data/test/test_Hash.cpp +1 -1
  123. data/test/test_Iterator.cpp +54 -22
  124. data/test/test_Keep_Alive.cpp +1 -1
  125. data/test/test_Keep_Alive_No_Wrapper.cpp +1 -1
  126. data/test/test_Module.cpp +5 -5
  127. data/test/test_Overloads.cpp +345 -48
  128. data/test/test_Proc.cpp +54 -0
  129. data/test/test_Reference.cpp +181 -0
  130. data/test/test_Self.cpp +2 -2
  131. data/test/test_Stl_Set.cpp +6 -6
  132. data/test/test_Stl_SharedPtr.cpp +54 -30
  133. data/test/test_Stl_String_View.cpp +4 -2
  134. data/test/test_Stl_Tuple.cpp +1 -1
  135. data/test/test_Stl_Variant.cpp +6 -14
  136. data/test/test_Stl_Vector.cpp +61 -30
  137. data/test/test_String.cpp +4 -2
  138. data/test/test_Struct.cpp +1 -1
  139. data/test/test_Symbol.cpp +1 -1
  140. data/test/test_To_Ruby.cpp +1 -0
  141. data/test/test_Type.cpp +36 -35
  142. data/test/test_global_functions.cpp +1 -1
  143. data/test/unittest.cpp +1 -1
  144. data/test/unittest.hpp +5 -5
  145. metadata +10 -10
  146. data/rice/Function.hpp +0 -17
  147. data/rice/Function.ipp +0 -13
  148. data/rice/detail/MethodInfo.hpp +0 -48
  149. data/rice/detail/MethodInfo.ipp +0 -99
  150. data/rice/detail/NativeCallbackFFI.hpp +0 -55
  151. data/rice/detail/NativeCallbackFFI.ipp +0 -152
  152. data/rice/detail/NativeCallbackSimple.hpp +0 -30
  153. data/rice/detail/NativeCallbackSimple.ipp +0 -29
data/rice/Buffer.ipp CHANGED
@@ -102,11 +102,11 @@ namespace Rice
102
102
  }
103
103
  default:
104
104
  {
105
- if (RubyType_T::Exact.find(valueType) != RubyType_T::Exact.end() ||
106
- RubyType_T::Castable.find(valueType) != RubyType_T::Castable.end() ||
107
- RubyType_T::Narrowable.find(valueType) != RubyType_T::Narrowable.end())
105
+ if (detail::From_Ruby<detail::remove_cv_recursive_t<T>>().is_convertible(value))
108
106
  {
109
- T data = detail::protect(RubyType_T::fromRuby, value);
107
+ // The Ruby method may return a different type - for example Ruby floats
108
+ // are converted to double and not float - so we need a typecast.
109
+ T data = (T)detail::protect(RubyType_T::fromRuby, value);
110
110
  this->m_size = 1;
111
111
  this->m_buffer = new T[this->m_size]();
112
112
  memcpy((void*)this->m_buffer, &data, sizeof(T));
@@ -115,9 +115,9 @@ namespace Rice
115
115
  }
116
116
  else
117
117
  {
118
- detail::TypeMapper<T> typeMapper;
119
- std::string typeName = typeMapper.name();
120
- throw Exception(rb_eTypeError, "wrong argument type %s (expected % s*)",
118
+ detail::TypeIndexParser typeIndexParser(typeid(T), std::is_fundamental_v<detail::intrinsic_type<T>>);
119
+ std::string typeName = typeIndexParser.name();
120
+ throw Exception(rb_eTypeError, "wrong argument type %s (expected %s*)",
121
121
  detail::protect(rb_obj_classname, value), typeName.c_str());
122
122
  }
123
123
  }
@@ -137,8 +137,8 @@ namespace Rice
137
137
  this->m_size = array.size();
138
138
 
139
139
  // Use operator new[] to allocate memory but not call constructors.
140
- size_t size = sizeof(T) * this->m_size;
141
- this->m_buffer = static_cast<T*>(operator new[](size));
140
+ size_t memsize = sizeof(T) * this->m_size;
141
+ this->m_buffer = static_cast<T*>(operator new[](memsize));
142
142
 
143
143
  detail::From_Ruby<Intrinsic_T> fromRuby;
144
144
 
@@ -147,7 +147,7 @@ namespace Rice
147
147
  // Construct objects in allocated memory using move or copy construction
148
148
  if constexpr (std::is_move_constructible_v<T>)
149
149
  {
150
- new (&this->m_buffer[i]) T(std::move(fromRuby.convert(array[i].value())));
150
+ new (&this->m_buffer[i]) T(std::move(fromRuby.convert(array[(long)i].value())));
151
151
  }
152
152
  else if constexpr (std::is_copy_constructible_v<T>)
153
153
  {
@@ -155,8 +155,9 @@ namespace Rice
155
155
  }
156
156
  else
157
157
  {
158
+ detail::TypeIndexParser typeIndexParser(typeid(Intrinsic_T), std::is_fundamental_v<Intrinsic_T>);
158
159
  throw Exception(rb_eTypeError, "Cannot construct object of type %s - type is not move or copy constructible",
159
- detail::TypeMapper<Intrinsic_T>().name().c_str());
160
+ typeIndexParser.name().c_str());
160
161
  }
161
162
  }
162
163
  break;
@@ -196,9 +197,9 @@ namespace Rice
196
197
  }
197
198
  default:
198
199
  {
199
- detail::TypeMapper<T> typeMapper;
200
- std::string typeName = typeMapper.name();
201
- throw Exception(rb_eTypeError, "wrong argument type %s (expected % s*)",
200
+ detail::TypeIndexParser typeIndexParser(typeid(T), std::is_fundamental_v<detail::intrinsic_type<T>>);
201
+ std::string typeName = typeIndexParser.name();
202
+ throw Exception(rb_eTypeError, "wrong argument type %s (expected %s*)",
202
203
  detail::protect(rb_obj_classname, value), typeName.c_str());
203
204
  }
204
205
  }
@@ -267,8 +268,8 @@ namespace Rice
267
268
  template<typename T>
268
269
  inline VALUE Buffer<T, std::enable_if_t<!std::is_pointer_v<T> && !std::is_void_v<T>>>::toString() const
269
270
  {
270
- detail::TypeMapper<T*> typeMapper;
271
- std::string description = "Buffer<type: " + typeMapper.simplifiedName() + ", size: " + std::to_string(this->m_size) + ">";
271
+ detail::TypeIndexParser typeIndexParser(typeid(T*), std::is_fundamental_v<detail::intrinsic_type<T>>);
272
+ std::string description = "Buffer<type: " + typeIndexParser.simplifiedName() + ", size: " + std::to_string(this->m_size) + ">";
272
273
 
273
274
  // We can't use To_Ruby because To_Ruby depends on Buffer - ie a circular reference
274
275
  return detail::protect(rb_utf8_str_new_cstr, description.c_str());
@@ -345,7 +346,7 @@ namespace Rice
345
346
  }
346
347
 
347
348
  template<typename T>
348
- inline Buffer<T*, std::enable_if_t<!detail::is_wrapped_v<T>>>::Buffer(T** pointer, size_t size) : m_buffer(pointer), m_size(size)
349
+ inline Buffer<T*, std::enable_if_t<!detail::is_wrapped_v<T>>>::Buffer(T** pointer, size_t size) : m_size(size), m_buffer(pointer)
349
350
  {
350
351
  }
351
352
 
@@ -373,7 +374,7 @@ namespace Rice
373
374
  for (size_t i = 0; i < this->m_size; i++)
374
375
  {
375
376
  // Check the inner value is also an array
376
- Array inner(outer[i].value());
377
+ Array inner(outer[(long)i].value());
377
378
 
378
379
  // Allocate inner buffer
379
380
  this->m_buffer[i] = new T[inner.size()]();
@@ -383,13 +384,16 @@ namespace Rice
383
384
  String packed = inner.pack<Intrinsic_T>();
384
385
  memcpy((void*)this->m_buffer[i], RSTRING_PTR(packed.value()), RSTRING_LEN(packed.value()));
385
386
  }
387
+ // This is for std::string, should be a 1 length array
386
388
  else
387
389
  {
388
390
  detail::From_Ruby<Intrinsic_T*> fromRuby;
389
- for (int i = 0; i < inner.size(); i++)
391
+ if (inner.size() != 1)
390
392
  {
391
- this->m_buffer[0] = fromRuby.convert(inner[i].value());
393
+ throw Exception(rb_eTypeError, "Expected inner array size 1 for type %s* but got %ld",
394
+ detail::TypeIndexParser(typeid(T)).name().c_str(), inner.size());
392
395
  }
396
+ this->m_buffer[i] = fromRuby.convert(inner[0].value());
393
397
  }
394
398
  }
395
399
 
@@ -409,9 +413,9 @@ namespace Rice
409
413
  }
410
414
  default:
411
415
  {
412
- detail::TypeMapper<T> typeMapper;
413
- std::string typeName = typeMapper.name();
414
- throw Exception(rb_eTypeError, "wrong argument type %s (expected % s*)",
416
+ detail::TypeIndexParser typeIndexParser(typeid(T), std::is_fundamental_v<detail::intrinsic_type<T>>);
417
+ std::string typeName = typeIndexParser.name();
418
+ throw Exception(rb_eTypeError, "wrong argument type %s (expected %s*)",
415
419
  detail::protect(rb_obj_classname, value), typeName.c_str());
416
420
  }
417
421
  }
@@ -495,8 +499,8 @@ namespace Rice
495
499
  template<typename T>
496
500
  inline VALUE Buffer<T*, std::enable_if_t<!detail::is_wrapped_v<T>>>::toString() const
497
501
  {
498
- detail::TypeMapper<T*> typeMapper;
499
- std::string description = "Buffer<type: " + typeMapper.simplifiedName() + ", size: " + std::to_string(this->m_size) + ">";
502
+ detail::TypeIndexParser typeIndexParser(typeid(T*), std::is_fundamental_v<detail::intrinsic_type<T>>);
503
+ std::string description = "Buffer<type: " + typeIndexParser.simplifiedName() + ", size: " + std::to_string(this->m_size) + ">";
500
504
 
501
505
  // We can't use To_Ruby because To_Ruby depends on Buffer - ie a circular reference
502
506
  return detail::protect(rb_utf8_str_new_cstr, description.c_str());
@@ -559,7 +563,7 @@ namespace Rice
559
563
  }
560
564
 
561
565
  template<typename T>
562
- inline Buffer<T*, std::enable_if_t<detail::is_wrapped_v<T>>>::Buffer(T** pointer, size_t size) : m_buffer(pointer), m_size(size)
566
+ inline Buffer<T*, std::enable_if_t<detail::is_wrapped_v<T>>>::Buffer(T** pointer, size_t size) : m_size(size), m_buffer(pointer)
563
567
  {
564
568
  }
565
569
 
@@ -584,7 +588,7 @@ namespace Rice
584
588
 
585
589
  for (size_t i = 0; i < this->m_size; i++)
586
590
  {
587
- this->m_buffer[i] = fromRuby.convert(array[i].value());
591
+ this->m_buffer[i] = fromRuby.convert(array[(long)i].value());
588
592
  }
589
593
 
590
594
  this->m_owner = true;
@@ -602,9 +606,9 @@ namespace Rice
602
606
  }
603
607
  default:
604
608
  {
605
- detail::TypeMapper<T> typeMapper;
606
- std::string typeName = typeMapper.name();
607
- throw Exception(rb_eTypeError, "wrong argument type %s (expected % s*)",
609
+ detail::TypeIndexParser typeIndexParser(typeid(T), std::is_fundamental_v<detail::intrinsic_type<T>>);
610
+ std::string typeName = typeIndexParser.name();
611
+ throw Exception(rb_eTypeError, "wrong argument type %s (expected %s*)",
608
612
  detail::protect(rb_obj_classname, value), typeName.c_str());
609
613
  }
610
614
  }
@@ -687,8 +691,8 @@ namespace Rice
687
691
  template<typename T>
688
692
  inline VALUE Buffer<T*, std::enable_if_t<detail::is_wrapped_v<T>>>::toString() const
689
693
  {
690
- detail::TypeMapper<T*> typeMapper;
691
- std::string description = "Buffer<type: " + typeMapper.simplifiedName() + ", size: " + std::to_string(this->m_size) + ">";
694
+ detail::TypeIndexParser typeIndexParser(typeid(T*), std::is_fundamental_v<detail::intrinsic_type<T>>);
695
+ std::string description = "Buffer<type: " + typeIndexParser.simplifiedName() + ", size: " + std::to_string(this->m_size) + ">";
692
696
 
693
697
  // We can't use To_Ruby because To_Ruby depends on Buffer - ie a circular reference
694
698
  return detail::protect(rb_utf8_str_new_cstr, description.c_str());
@@ -750,7 +754,7 @@ namespace Rice
750
754
  }
751
755
 
752
756
  template<typename T>
753
- inline Buffer<T, std::enable_if_t<std::is_void_v<T>>>::Buffer(VALUE value, size_t size)
757
+ inline Buffer<T, std::enable_if_t<std::is_void_v<T>>>::Buffer(VALUE value, size_t)
754
758
  {
755
759
  ruby_value_type valueType = rb_type(value);
756
760
 
@@ -767,9 +771,9 @@ namespace Rice
767
771
  }
768
772
  default:
769
773
  {
770
- detail::TypeMapper<void> typeMapper;
771
- std::string typeName = typeMapper.name();
772
- throw Exception(rb_eTypeError, "wrong argument type %s (expected % s*)",
774
+ detail::TypeIndexParser typeIndexParser(typeid(T), std::is_fundamental_v<detail::intrinsic_type<T>>);
775
+ std::string typeName = typeIndexParser.name();
776
+ throw Exception(rb_eTypeError, "wrong argument type %s (expected %s*)",
773
777
  detail::protect(rb_obj_classname, value), typeName.c_str());
774
778
  }
775
779
  }
@@ -863,8 +867,8 @@ namespace Rice
863
867
  define_method("size", &Buffer_T::size).
864
868
  template define_method<VALUE(Buffer_T::*)(size_t) const>("bytes", &Buffer_T::bytes, Return().setValue()).
865
869
  template define_method<VALUE(Buffer_T::*)() const>("bytes", &Buffer_T::bytes, Return().setValue()).
866
- define_method("data", &Buffer_T::ptr, Return().setBuffer()).
867
- define_method("release", &Buffer_T::release, Return().setBuffer());
870
+ define_method("data", &Buffer_T::ptr, ReturnBuffer()).
871
+ define_method("release", &Buffer_T::release, ReturnBuffer());
868
872
  }
869
873
  else
870
874
  {
@@ -878,8 +882,8 @@ namespace Rice
878
882
  template define_method<Array(Buffer_T::*)(size_t) const>("to_ary", &Buffer_T::toArray, Return().setValue()).
879
883
  template define_method<Array(Buffer_T::*)() const>("to_ary", &Buffer_T::toArray, Return().setValue()).
880
884
  define_method("[]", &Buffer_T::operator[], Arg("index")).
881
- define_method("data", &Buffer_T::ptr, Return().setBuffer()).
882
- define_method("release", &Buffer_T::release, Return().setBuffer());
885
+ define_method("data", &Buffer_T::ptr, ReturnBuffer()).
886
+ define_method("release", &Buffer_T::release, ReturnBuffer());
883
887
 
884
888
  if constexpr (!std::is_pointer_v<T> && !std::is_void_v<T> && !std::is_const_v<T> && std::is_copy_assignable_v<T>)
885
889
  {
data/rice/Callback.hpp CHANGED
@@ -16,6 +16,6 @@ namespace Rice
16
16
  * \return nothing
17
17
  */
18
18
  template<typename Callback_T, typename...Arg_Ts>
19
- void define_callback(const Arg_Ts&...args);
19
+ void define_callback(Arg_Ts&&...args);
20
20
  }
21
21
  #endif // Rice__Callback__hpp_
data/rice/Callback.ipp CHANGED
@@ -1,13 +1,8 @@
1
1
  namespace Rice
2
2
  {
3
3
  template<typename Callback_T, typename...Arg_Ts>
4
- void define_callback(const Arg_Ts&...args)
4
+ inline void define_callback(Arg_Ts&&...args)
5
5
  {
6
- MethodInfo* methodInfo = new MethodInfo(detail::function_traits<Callback_T>::arity, args...);
7
- #ifdef HAVE_LIBFFI
8
- detail::NativeCallbackFFI<Callback_T>::setMethodInfo(methodInfo);
9
- #else
10
- detail::NativeCallbackSimple<Callback_T>::setMethodInfo(methodInfo);
11
- #endif
6
+ detail::NativeCallback<Callback_T>::define(std::forward<Arg_Ts>(args)...);
12
7
  }
13
8
  }
data/rice/Constructor.hpp CHANGED
@@ -16,7 +16,7 @@ namespace Rice
16
16
  *
17
17
  * For more information, see Rice::Data_Type::define_constructor.
18
18
  */
19
- template<typename T, typename...Arg_Ts>
19
+ template<typename T, typename...Parameter_Ts>
20
20
  class Constructor;
21
21
  }
22
22
  #endif // Rice__Constructor__hpp_
data/rice/Constructor.ipp CHANGED
@@ -1,16 +1,16 @@
1
1
  namespace Rice
2
2
  {
3
- template<typename T, typename...Arg_Ts>
3
+ template<typename T, typename...Parameter_Ts>
4
4
  class Constructor
5
5
  {
6
6
  public:
7
- static constexpr std::size_t arity = sizeof...(Arg_Ts);
7
+ static constexpr std::size_t arity = sizeof...(Parameter_Ts);
8
8
 
9
9
  static constexpr bool isCopyConstructor()
10
10
  {
11
11
  if constexpr (arity == 1)
12
12
  {
13
- using Arg_Types = std::tuple<Arg_Ts...>;
13
+ using Arg_Types = std::tuple<Parameter_Ts...>;
14
14
  using First_Arg_T = std::tuple_element_t<0, Arg_Types>;
15
15
  return (arity == 1 &&
16
16
  std::is_lvalue_reference_v<First_Arg_T> &&
@@ -26,7 +26,7 @@ namespace Rice
26
26
  {
27
27
  if constexpr (arity == 1)
28
28
  {
29
- using Arg_Types = std::tuple<Arg_Ts...>;
29
+ using Arg_Types = std::tuple<Parameter_Ts...>;
30
30
  using First_Arg_T = std::tuple_element_t<0, Arg_Types>;
31
31
  return (arity == 1 &&
32
32
  std::is_rvalue_reference_v<First_Arg_T> &&
@@ -38,25 +38,25 @@ namespace Rice
38
38
  }
39
39
  }
40
40
 
41
- static void initialize(VALUE self, Arg_Ts...args)
41
+ static void initialize(VALUE self, Parameter_Ts...args)
42
42
  {
43
43
  // Call C++ constructor
44
44
  T* data = new T(args...);
45
- detail::wrapConstructed<T>(self, Data_Type<T>::ruby_data_type(), data, true);
45
+ detail::wrapConstructed<T>(self, Data_Type<T>::ruby_data_type(), data);
46
46
  }
47
47
 
48
48
  static void initialize_copy(VALUE self, const T& other)
49
49
  {
50
50
  // Call C++ copy constructor
51
51
  T* data = new T(other);
52
- detail::wrapConstructed<T>(self, Data_Type<T>::ruby_data_type(), data, true);
52
+ detail::wrapConstructed<T>(self, Data_Type<T>::ruby_data_type(), data);
53
53
  }
54
54
 
55
55
  };
56
56
 
57
57
  //! Special-case Constructor used when defining Directors.
58
- template<typename T, typename...Arg_Ts>
59
- class Constructor<T, Object, Arg_Ts...>
58
+ template<typename T, typename...Parameter_Ts>
59
+ class Constructor<T, Object, Parameter_Ts...>
60
60
  {
61
61
  public:
62
62
  static constexpr bool isCopyConstructor()
@@ -69,11 +69,11 @@ namespace Rice
69
69
  return false;
70
70
  }
71
71
 
72
- static void initialize(Object self, Arg_Ts...args)
72
+ static void initialize(Object self, Parameter_Ts...args)
73
73
  {
74
74
  // Call C++ constructor
75
75
  T* data = new T(self, args...);
76
- detail::wrapConstructed<T>(self.value(), Data_Type<T>::ruby_data_type(), data, true);
76
+ detail::wrapConstructed<T>(self.value(), Data_Type<T>::ruby_data_type(), data);
77
77
  }
78
78
  };
79
79
  }
data/rice/Data_Object.ipp CHANGED
@@ -14,9 +14,9 @@ namespace Rice
14
14
  }
15
15
  else
16
16
  {
17
- detail::TypeMapper<T> typeMapper;
17
+ detail::TypeIndexParser typeIndexParser(typeid(T), std::is_fundamental_v<detail::intrinsic_type<T>>);
18
18
  return Exception(rb_eTypeError, "Wrong argument type. Expected %s. Received %s.",
19
- typeMapper.simplifiedName().c_str(),
19
+ typeIndexParser.simplifiedName().c_str(),
20
20
  detail::protect(rb_obj_classname, value));
21
21
  }
22
22
  }
@@ -228,7 +228,7 @@ namespace Rice::detail
228
228
  VALUE convert(U* data)
229
229
  {
230
230
  bool isOwner = this->arg_ && this->arg_->isOwner();
231
- bool isBuffer = this->arg_ && this->arg_->isBuffer();
231
+ bool isBuffer = dynamic_cast<ReturnBuffer*>(this->arg_) ? true : false;
232
232
 
233
233
  if (data == nullptr)
234
234
  {
@@ -273,7 +273,7 @@ namespace Rice::detail
273
273
  VALUE convert(U* data)
274
274
  {
275
275
  bool isOwner = this->arg_ && this->arg_->isOwner();
276
- bool isBuffer = this->arg_ && this->arg_->isBuffer();
276
+ bool isBuffer = dynamic_cast<ReturnBuffer*>(this->arg_) ? true : false;
277
277
 
278
278
  if (data == nullptr)
279
279
  {
@@ -361,7 +361,7 @@ namespace Rice::detail
361
361
  {
362
362
  }
363
363
 
364
- Convertible is_convertible(VALUE value)
364
+ double is_convertible(VALUE value)
365
365
  {
366
366
  switch (rb_type(value))
367
367
  {
@@ -412,7 +412,7 @@ namespace Rice::detail
412
412
  {
413
413
  }
414
414
 
415
- Convertible is_convertible(VALUE value)
415
+ double is_convertible(VALUE value)
416
416
  {
417
417
  switch (rb_type(value))
418
418
  {
@@ -455,7 +455,7 @@ namespace Rice::detail
455
455
  {
456
456
  }
457
457
 
458
- Convertible is_convertible(VALUE value)
458
+ double is_convertible(VALUE value)
459
459
  {
460
460
  switch (rb_type(value))
461
461
  {
@@ -501,9 +501,9 @@ namespace Rice::detail
501
501
  {
502
502
  }
503
503
 
504
- Convertible is_convertible(VALUE value)
504
+ double is_convertible(VALUE value)
505
505
  {
506
- bool isBuffer = this->arg_->isBuffer();
506
+ bool isBuffer = dynamic_cast<ArgBuffer*>(this->arg_) ? true : false;
507
507
 
508
508
  switch (rb_type(value))
509
509
  {
@@ -528,7 +528,7 @@ namespace Rice::detail
528
528
  T* convert(VALUE value)
529
529
  {
530
530
  bool isOwner = this->arg_ && this->arg_->isOwner();
531
- bool isBuffer = this->arg_ && this->arg_->isBuffer();
531
+ bool isBuffer = dynamic_cast<ArgBuffer*>(this->arg_) ? true : false;
532
532
 
533
533
  switch (rb_type(value))
534
534
  {
@@ -584,7 +584,7 @@ namespace Rice::detail
584
584
  {
585
585
  }
586
586
 
587
- Convertible is_convertible(VALUE value)
587
+ double is_convertible(VALUE value)
588
588
  {
589
589
  switch (rb_type(value))
590
590
  {
@@ -633,9 +633,9 @@ namespace Rice::detail
633
633
  {
634
634
  }
635
635
 
636
- Convertible is_convertible(VALUE value)
636
+ double is_convertible(VALUE value)
637
637
  {
638
- bool isBuffer = this->arg_ && this->arg_->isBuffer();
638
+ bool isBuffer = dynamic_cast<ArgBuffer*>(this->arg_) ? true : false;
639
639
 
640
640
  switch (rb_type(value))
641
641
  {
@@ -656,7 +656,7 @@ namespace Rice::detail
656
656
  T** convert(VALUE value)
657
657
  {
658
658
  bool isOwner = this->arg_ && this->arg_->isOwner();
659
- bool isBuffer = this->arg_ && this->arg_->isBuffer();
659
+ bool isBuffer = dynamic_cast<ArgBuffer*>(this->arg_) ? true : false;
660
660
 
661
661
  switch (rb_type(value))
662
662
  {
@@ -707,7 +707,7 @@ namespace Rice::detail
707
707
  "Please include rice/stl.hpp header for STL support");
708
708
 
709
709
  public:
710
- Convertible is_convertible(VALUE value)
710
+ double is_convertible(VALUE value)
711
711
  {
712
712
  switch (rb_type(value))
713
713
  {
data/rice/Data_Type.hpp CHANGED
@@ -90,8 +90,7 @@ namespace Rice
90
90
  * library to die at run time when it tries to convert the base
91
91
  * type into the Director proxy type.
92
92
  *
93
- * This method takes no methodInfo, just needs the type of the
94
- * Director proxy class.
93
+ * This method needs the type of the Director proxy class.
95
94
  *
96
95
  * For example:
97
96
  * \code
@@ -134,11 +133,11 @@ namespace Rice
134
133
  template<typename Iterator_Func_T>
135
134
  Data_Type<T>& define_iterator(Iterator_Func_T begin, Iterator_Func_T end, std::string name = "each");
136
135
 
137
- template <typename Attribute_T>
138
- Data_Type<T>& define_attr(std::string name, Attribute_T attribute, AttrAccess access = AttrAccess::ReadWrite, Return returnInfo = Return());
136
+ template <typename Attribute_T, typename...Arg_Ts>
137
+ Data_Type<T>& define_attr(std::string name, Attribute_T attribute, AttrAccess access = AttrAccess::ReadWrite, const Arg_Ts&...args);
139
138
 
140
- template <typename Attribute_T>
141
- Data_Type<T>& define_singleton_attr(std::string name, Attribute_T attribute, AttrAccess access = AttrAccess::ReadWrite, Return returnInfo = Return());
139
+ template <typename Attribute_T, typename...Arg_Ts>
140
+ Data_Type<T>& define_singleton_attr(std::string name, Attribute_T attribute, AttrAccess access = AttrAccess::ReadWrite, const Arg_Ts&...args);
142
141
 
143
142
  #include "cpp_api/shared_methods.hpp"
144
143
  protected:
@@ -161,11 +160,11 @@ namespace Rice
161
160
  template<typename T_, typename Base_T>
162
161
  friend Rice::Data_Type<T_> define_class(char const * name);
163
162
 
164
- template<typename Method_T>
165
- void wrap_native_method(VALUE klass, std::string name, Method_T&& function, MethodInfo* methodInfo);
163
+ template<typename Method_T, typename...Arg_Ts>
164
+ void wrap_native_method(VALUE klass, std::string name, Method_T&& function, const Arg_Ts&...args);
166
165
 
167
- template <typename Attribute_T>
168
- Data_Type<T>& define_attr_internal(VALUE klass, std::string name, Attribute_T attribute, AttrAccess access, Return returnInfo);
166
+ template <typename Attribute_T, typename...Arg_Ts>
167
+ Data_Type<T>& define_attr_internal(VALUE klass, std::string name, Attribute_T attribute, AttrAccess access, const Arg_Ts&...args);
169
168
 
170
169
  private:
171
170
  template<typename T_>
data/rice/Data_Type.ipp CHANGED
@@ -20,13 +20,13 @@ namespace Rice
20
20
  }
21
21
 
22
22
  template<typename T>
23
- inline size_t ruby_size_internal(const T* data)
23
+ inline size_t ruby_size_internal(const T*)
24
24
  {
25
25
  return sizeof(T);
26
26
  }
27
27
 
28
28
  template<>
29
- inline size_t ruby_size_internal(const void* data)
29
+ inline size_t ruby_size_internal(const void*)
30
30
  {
31
31
  return sizeof(void*);
32
32
  }
@@ -37,8 +37,8 @@ namespace Rice
37
37
  {
38
38
  if (is_bound())
39
39
  {
40
- detail::TypeMapper<T> typeMapper;
41
- std::string message = "Type " + typeMapper.name() + " is already bound to a different type";
40
+ detail::TypeIndexParser typeIndexParser(typeid(T), std::is_fundamental_v<detail::intrinsic_type<T>>);
41
+ std::string message = "Type " + typeIndexParser.name() + " is already bound to a different type";
42
42
  throw std::runtime_error(message.c_str());
43
43
  }
44
44
 
@@ -69,10 +69,10 @@ namespace Rice
69
69
 
70
70
  // Add a method to get the source C++ class name from Ruby
71
71
  Data_Type<T> dataType;
72
- dataType.define_singleton_method("cpp_class", [](VALUE klass) -> VALUE
72
+ dataType.define_singleton_method("cpp_class", [](VALUE) -> VALUE
73
73
  {
74
- detail::TypeMapper<T> typeMapper;
75
- std::string cppClassName = typeMapper.simplifiedName();
74
+ detail::TypeIndexParser typeIndexParser(typeid(T), std::is_fundamental_v<detail::intrinsic_type<T>>);
75
+ std::string cppClassName = typeIndexParser.simplifiedName();
76
76
  Return returnInfo;
77
77
  returnInfo.takeOwnership();
78
78
  return detail::To_Ruby<char*>(&returnInfo).convert(cppClassName.c_str());
@@ -148,7 +148,7 @@ namespace Rice
148
148
 
149
149
  template<typename T>
150
150
  template<typename Constructor_T, typename...Rice_Arg_Ts>
151
- inline Data_Type<T>& Data_Type<T>::define_constructor(Constructor_T constructor, Rice_Arg_Ts const& ...args)
151
+ inline Data_Type<T>& Data_Type<T>::define_constructor(Constructor_T, Rice_Arg_Ts const& ...args)
152
152
  {
153
153
  check_is_bound();
154
154
 
@@ -187,9 +187,6 @@ namespace Rice
187
187
  template<typename Function_T>
188
188
  inline Data_Type<T>& Data_Type<T>::define(Function_T func)
189
189
  {
190
- // The passed in this pointer is an RValue, so we need to keep it alive by
191
- // assigning it to a const lvalue
192
- const auto& dummy = *this;
193
190
  func(*this);
194
191
  return *this;
195
192
  }
@@ -233,8 +230,8 @@ namespace Rice
233
230
  {
234
231
  if (!is_bound())
235
232
  {
236
- detail::TypeMapper<T> typeMapper;
237
- std::string message = "Type is not defined with Rice: " + typeMapper.name();
233
+ detail::TypeIndexParser typeIndexParser(typeid(T), std::is_fundamental_v<detail::intrinsic_type<T>>);
234
+ std::string message = "Type is not defined with Rice: " + typeIndexParser.name();
238
235
  throw std::invalid_argument(message.c_str());
239
236
  }
240
237
  }
@@ -330,30 +327,30 @@ namespace Rice
330
327
  }
331
328
 
332
329
  template <typename T>
333
- template <typename Attribute_T>
334
- inline Data_Type<T>& Data_Type<T>::define_attr(std::string name, Attribute_T attribute, AttrAccess access, Return returnInfo)
330
+ template <typename Attribute_T, typename...Arg_Ts>
331
+ inline Data_Type<T>& Data_Type<T>::define_attr(std::string name, Attribute_T attribute, AttrAccess access, const Arg_Ts&...args)
335
332
  {
336
- return this->define_attr_internal<Attribute_T>(this->klass_, name, std::forward<Attribute_T>(attribute), access, returnInfo);
333
+ return this->define_attr_internal<Attribute_T>(this->klass_, name, std::forward<Attribute_T>(attribute), access, args...);
337
334
  }
338
335
 
339
336
  template <typename T>
340
- template <typename Attribute_T>
341
- inline Data_Type<T>& Data_Type<T>::define_singleton_attr(std::string name, Attribute_T attribute, AttrAccess access, Return returnInfo)
337
+ template <typename Attribute_T, typename...Arg_Ts>
338
+ inline Data_Type<T>& Data_Type<T>::define_singleton_attr(std::string name, Attribute_T attribute, AttrAccess access, const Arg_Ts&...args)
342
339
  {
343
340
  VALUE singleton = detail::protect(rb_singleton_class, this->value());
344
- return this->define_attr_internal<Attribute_T>(singleton, name, std::forward<Attribute_T>(attribute), access, returnInfo);
341
+ return this->define_attr_internal<Attribute_T>(singleton, name, std::forward<Attribute_T>(attribute), access, args...);
345
342
  }
346
343
 
347
344
  template <typename T>
348
- template <typename Attribute_T>
349
- inline Data_Type<T>& Data_Type<T>::define_attr_internal(VALUE klass, std::string name, Attribute_T attribute, AttrAccess access, Return returnInfo)
345
+ template <typename Attribute_T, typename...Arg_Ts>
346
+ inline Data_Type<T>& Data_Type<T>::define_attr_internal(VALUE klass, std::string name, Attribute_T attribute, AttrAccess access, const Arg_Ts&...args)
350
347
  {
351
348
  using Attr_T = typename detail::attribute_traits<Attribute_T>::attr_type;
352
349
 
353
350
  // Define attribute getter
354
351
  if (access == AttrAccess::ReadWrite || access == AttrAccess::Read)
355
352
  {
356
- detail::NativeAttributeGet<Attribute_T>::define(klass, name, std::forward<Attribute_T>(attribute), returnInfo);
353
+ detail::NativeAttributeGet<Attribute_T>::define(klass, name, std::forward<Attribute_T>(attribute), args...);
357
354
  }
358
355
 
359
356
  // Define attribute setter
@@ -391,9 +388,9 @@ namespace Rice
391
388
  }
392
389
 
393
390
  template <typename T>
394
- template<typename Method_T>
395
- inline void Data_Type<T>::wrap_native_method(VALUE klass, std::string name, Method_T&& method, MethodInfo* methodInfo)
391
+ template<typename Method_T, typename ...Arg_Ts>
392
+ inline void Data_Type<T>::wrap_native_method(VALUE klass, std::string name, Method_T&& method, const Arg_Ts&...args)
396
393
  {
397
- Module::wrap_native_method<T, Method_T>(klass, name, std::forward<Method_T>(method), methodInfo);
394
+ Module::wrap_native_method<T, Method_T>(klass, name, std::forward<Method_T>(method), args...);
398
395
  }
399
396
  }
data/rice/Director.hpp CHANGED
@@ -23,6 +23,7 @@ namespace Rice
23
23
  /*! If a Ruby script calls 'super' on a method that's otherwise a pure virtual
24
24
  * method, use this method to throw an exception in this case.
25
25
  */
26
+ [[noreturn]]
26
27
  void raisePureVirtual() const
27
28
  {
28
29
  rb_raise(rb_eNotImpError, "Cannot call super() into a pure-virtual C++ method");