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/stl/string.ipp CHANGED
@@ -68,7 +68,7 @@ namespace Rice::detail
68
68
  public:
69
69
  To_Ruby() = default;
70
70
 
71
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
71
+ explicit To_Ruby(Arg* arg) : arg_(arg)
72
72
  {
73
73
  }
74
74
 
@@ -78,7 +78,7 @@ namespace Rice::detail
78
78
  }
79
79
 
80
80
  private:
81
- Return* returnInfo_ = nullptr;
81
+ Arg* arg_ = nullptr;
82
82
  };
83
83
 
84
84
  template<>
@@ -87,7 +87,7 @@ namespace Rice::detail
87
87
  public:
88
88
  To_Ruby() = default;
89
89
 
90
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
90
+ explicit To_Ruby(Arg* arg) : arg_(arg)
91
91
  {
92
92
  }
93
93
 
@@ -97,7 +97,7 @@ namespace Rice::detail
97
97
  }
98
98
 
99
99
  private:
100
- Return* returnInfo_ = nullptr;
100
+ Arg* arg_ = nullptr;
101
101
  };
102
102
 
103
103
  template<int N>
@@ -106,7 +106,7 @@ namespace Rice::detail
106
106
  public:
107
107
  To_Ruby() = default;
108
108
 
109
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
109
+ explicit To_Ruby(Arg* arg) : arg_(arg)
110
110
  {
111
111
  }
112
112
 
@@ -117,7 +117,7 @@ namespace Rice::detail
117
117
  return dataObject.value();
118
118
  }
119
119
  private:
120
- Return* returnInfo_ = nullptr;
120
+ Arg* arg_ = nullptr;
121
121
  };
122
122
 
123
123
  template<>
@@ -126,14 +126,14 @@ namespace Rice::detail
126
126
  public:
127
127
  To_Ruby() = default;
128
128
 
129
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
129
+ explicit To_Ruby(Arg* arg) : arg_(arg)
130
130
  {
131
131
  }
132
132
 
133
133
  VALUE convert(const std::string* value)
134
134
  {
135
- bool isOwner = this->returnInfo_ && this->returnInfo_->isOwner();
136
- bool isBuffer = this->returnInfo_ && this->returnInfo_->isBuffer();
135
+ bool isOwner = this->arg_ && this->arg_->isOwner();
136
+ bool isBuffer = dynamic_cast<ReturnBuffer*>(this->arg_) ? true : false;
137
137
 
138
138
  if (isBuffer)
139
139
  {
@@ -147,7 +147,7 @@ namespace Rice::detail
147
147
  }
148
148
 
149
149
  private:
150
- Return* returnInfo_ = nullptr;
150
+ Arg* arg_ = nullptr;
151
151
  };
152
152
 
153
153
  template<>
@@ -156,7 +156,7 @@ namespace Rice::detail
156
156
  public:
157
157
  To_Ruby() = default;
158
158
 
159
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
159
+ explicit To_Ruby(Arg* arg) : arg_(arg)
160
160
  {
161
161
  }
162
162
 
@@ -166,7 +166,7 @@ namespace Rice::detail
166
166
  }
167
167
 
168
168
  private:
169
- Return* returnInfo_ = nullptr;
169
+ Arg* arg_ = nullptr;
170
170
  };
171
171
 
172
172
  /*template<>
@@ -175,7 +175,7 @@ namespace Rice::detail
175
175
  public:
176
176
  To_Ruby() = default;
177
177
 
178
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
178
+ explicit To_Ruby(Arg* arg) : arg_(arg)
179
179
  {
180
180
  }
181
181
 
@@ -187,7 +187,7 @@ namespace Rice::detail
187
187
  }
188
188
 
189
189
  private:
190
- Return* returnInfo_ = nullptr;
190
+ Arg* arg_ = nullptr;
191
191
  };*/
192
192
 
193
193
  template<>
@@ -200,7 +200,7 @@ namespace Rice::detail
200
200
  {
201
201
  }
202
202
 
203
- Convertible is_convertible(VALUE value)
203
+ double is_convertible(VALUE value)
204
204
  {
205
205
  switch (rb_type(value))
206
206
  {
@@ -232,7 +232,7 @@ namespace Rice::detail
232
232
  {
233
233
  }
234
234
 
235
- Convertible is_convertible(VALUE value)
235
+ double is_convertible(VALUE value)
236
236
  {
237
237
  switch (rb_type(value))
238
238
  {
@@ -266,7 +266,7 @@ namespace Rice::detail
266
266
  {
267
267
  }
268
268
 
269
- Convertible is_convertible(VALUE value)
269
+ double is_convertible(VALUE value)
270
270
  {
271
271
  switch (rb_type(value))
272
272
  {
@@ -300,7 +300,7 @@ namespace Rice::detail
300
300
  {
301
301
  }
302
302
 
303
- Convertible is_convertible(VALUE value)
303
+ double is_convertible(VALUE value)
304
304
  {
305
305
  switch (rb_type(value))
306
306
  {
@@ -64,7 +64,7 @@ namespace Rice::detail
64
64
  {
65
65
  }
66
66
 
67
- Convertible is_convertible(VALUE value)
67
+ double is_convertible(VALUE value)
68
68
  {
69
69
  switch (rb_type(value))
70
70
  {
data/rice/stl/tuple.ipp CHANGED
@@ -8,7 +8,7 @@ namespace Rice::detail
8
8
  using Tuple_T = std::tuple<Types...>;
9
9
 
10
10
  template<std::size_t... I>
11
- constexpr static bool verifyTypes(std::index_sequence<I...>& indices)
11
+ constexpr static bool verifyTypes(std::index_sequence<I...>&)
12
12
  {
13
13
  return (Type<std::tuple_element_t<I, Tuple_T>>::verify() && ...);
14
14
  }
@@ -32,7 +32,7 @@ namespace Rice::detail
32
32
  public:
33
33
  To_Ruby() = default;
34
34
 
35
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
35
+ explicit To_Ruby(Arg* arg) : arg_(arg)
36
36
  {
37
37
  }
38
38
 
@@ -49,7 +49,7 @@ namespace Rice::detail
49
49
  }
50
50
 
51
51
  private:
52
- Return* returnInfo_ = nullptr;
52
+ Arg* arg_ = nullptr;
53
53
  };
54
54
 
55
55
  template<typename...Types>
@@ -58,7 +58,7 @@ namespace Rice::detail
58
58
  public:
59
59
  To_Ruby() = default;
60
60
 
61
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
61
+ explicit To_Ruby(Arg* arg) : arg_(arg)
62
62
  {
63
63
  }
64
64
 
@@ -66,7 +66,7 @@ namespace Rice::detail
66
66
  {
67
67
  Array result;
68
68
 
69
- bool isOwner = (this->returnInfo_ && this->returnInfo_->isOwner());
69
+ bool isOwner = (this->arg_ && this->arg_->isOwner());
70
70
 
71
71
  for_each_tuple(data, [&](auto& element)
72
72
  {
@@ -77,7 +77,7 @@ namespace Rice::detail
77
77
  }
78
78
 
79
79
  private:
80
- Return* returnInfo_ = nullptr;
80
+ Arg* arg_ = nullptr;
81
81
  };
82
82
 
83
83
  template<typename...Types>
@@ -86,35 +86,28 @@ namespace Rice::detail
86
86
  public:
87
87
  using Tuple_T = std::tuple<Types...>;
88
88
 
89
- template<std::size_t... I>
90
- constexpr static bool verifyTypes(Array& array, std::index_sequence<I...>& indices)
91
- {
92
- return (Type<std::tuple_element_t<I, Tuple_T>>::verify() && ...);
93
- }
94
-
95
89
  From_Ruby() = default;
96
90
 
97
- explicit From_Ruby(Arg* arg)
91
+ explicit From_Ruby(Arg* arg) : arg_(arg)
98
92
  {
99
93
  }
100
94
 
101
- Convertible is_convertible(VALUE value)
95
+ double is_convertible(VALUE value)
102
96
  {
103
- Convertible result = Convertible::None;
104
-
105
97
  // The ruby value must be an array of the correct size
106
98
  if (rb_type(value) != RUBY_T_ARRAY || Array(value).size() != std::tuple_size_v<Tuple_T>)
107
99
  {
108
- return result;
100
+ return Convertible::None;
109
101
  }
110
-
111
- // Now check that each tuple type is convertible
102
+
103
+ // Now check that each tuple type is convertible - use minimum score
104
+ double result = Convertible::Exact;
112
105
  Array array(value);
113
106
  int i = 0;
114
107
  for_each_tuple(this->fromRubys_,
115
108
  [&](auto& fromRuby)
116
109
  {
117
- result = result | fromRuby.is_convertible(array[i].value());
110
+ result = (std::min)(result, fromRuby.is_convertible(array[i].value()));
118
111
  i++;
119
112
  });
120
113
 
@@ -122,7 +115,7 @@ namespace Rice::detail
122
115
  }
123
116
 
124
117
  template <std::size_t... I>
125
- std::tuple<Types...> convertInternal(Array array, std::index_sequence<I...>& indices)
118
+ std::tuple<Types...> convertInternal(Array array, std::index_sequence<I...>&)
126
119
  {
127
120
  return std::forward_as_tuple(std::get<I>(this->fromRubys_).convert(array[I].value())...);
128
121
  }
@@ -135,23 +128,9 @@ namespace Rice::detail
135
128
  }
136
129
 
137
130
  private:
131
+ Arg* arg_ = nullptr;
138
132
  // Possible converters we could use for this variant
139
133
  using From_Ruby_Ts = std::tuple<From_Ruby<Types>...>;
140
134
  From_Ruby_Ts fromRubys_;
141
135
  };
142
-
143
- /* template<typename...Types>
144
- class From_Ruby<std::tuple<Types...>&> : public From_Ruby<std::tuple<Types...>>
145
- {
146
- public:
147
- std::tuple<Types...>& convert(VALUE value)
148
- {
149
- int index = this->figureIndex(value);
150
- this->converted_ = this->convertInternal(value, index);
151
- return this->converted_;
152
- }
153
-
154
- private:
155
- std::tuple<Types...> converted_;
156
- };*/
157
136
  }
@@ -32,7 +32,7 @@ namespace Rice::detail
32
32
  public:
33
33
  To_Ruby() = default;
34
34
 
35
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
35
+ explicit To_Ruby(Arg* arg) : arg_(arg)
36
36
  {
37
37
  }
38
38
 
@@ -49,7 +49,7 @@ namespace Rice::detail
49
49
  }
50
50
 
51
51
  private:
52
- Return* returnInfo_ = nullptr;
52
+ Arg* arg_ = nullptr;
53
53
  };
54
54
 
55
55
  template <typename T>
@@ -58,7 +58,7 @@ namespace Rice::detail
58
58
  public:
59
59
  To_Ruby() = default;
60
60
 
61
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
61
+ explicit To_Ruby(Arg* arg) : arg_(arg)
62
62
  {
63
63
  }
64
64
 
@@ -69,7 +69,7 @@ namespace Rice::detail
69
69
  }
70
70
 
71
71
  private:
72
- Return* returnInfo_ = nullptr;
72
+ Arg* arg_ = nullptr;
73
73
  };
74
74
 
75
75
  template <typename T>
@@ -84,14 +84,16 @@ namespace Rice::detail
84
84
 
85
85
  From_Ruby() = default;
86
86
 
87
- explicit From_Ruby(Arg* arg)
87
+ explicit From_Ruby(Arg* arg) : arg_(arg)
88
88
  {
89
89
  }
90
90
 
91
- Convertible is_convertible(VALUE value)
91
+ double is_convertible(VALUE value)
92
92
  {
93
93
  if (!is_same_smart_ptr(value))
94
+ {
94
95
  return Convertible::None;
96
+ }
95
97
 
96
98
  switch (rb_type(value))
97
99
  {
@@ -113,6 +115,9 @@ namespace Rice::detail
113
115
  }
114
116
  return std::move(wrapper->data());
115
117
  }
118
+
119
+ private:
120
+ Arg* arg_ = nullptr;
116
121
  };
117
122
 
118
123
  template <typename T>
@@ -127,14 +132,16 @@ namespace Rice::detail
127
132
 
128
133
  From_Ruby() = default;
129
134
 
130
- explicit From_Ruby(Arg* arg)
135
+ explicit From_Ruby(Arg* arg) : arg_(arg)
131
136
  {
132
137
  }
133
138
 
134
- Convertible is_convertible(VALUE value)
139
+ double is_convertible(VALUE value)
135
140
  {
136
141
  if (!is_same_smart_ptr(value))
142
+ {
137
143
  return Convertible::None;
144
+ }
138
145
 
139
146
  switch (rb_type(value))
140
147
  {
@@ -156,6 +163,9 @@ namespace Rice::detail
156
163
  }
157
164
  return wrapper->data();
158
165
  }
166
+
167
+ private:
168
+ Arg* arg_ = nullptr;
159
169
  };
160
170
 
161
171
  template<typename T>
@@ -107,7 +107,11 @@ namespace Rice
107
107
  {
108
108
  if constexpr (detail::is_comparable_v<Mapped_T>)
109
109
  {
110
- klass_.define_method("value?", [](T& unordered_map, Mapped_T& value) -> bool
110
+ klass_.define_method("==", [](T& unordered_map, T& other)->bool
111
+ {
112
+ return unordered_map == other;
113
+ })
114
+ .define_method("value?", [](T& unordered_map, Mapped_T& value) -> bool
111
115
  {
112
116
  auto it = std::find_if(unordered_map.begin(), unordered_map.end(),
113
117
  [&value](auto& pair)
@@ -117,10 +121,11 @@ namespace Rice
117
121
 
118
122
  return it != unordered_map.end();
119
123
  });
124
+ rb_define_alias(klass_, "eql?", "==");
120
125
  }
121
126
  else
122
127
  {
123
- klass_.define_method("value?", [](T& unordered_map, Mapped_T& value) -> bool
128
+ klass_.define_method("value?", [](T&, Mapped_T&) -> bool
124
129
  {
125
130
  return false;
126
131
  });
@@ -205,10 +210,10 @@ namespace Rice
205
210
  }
206
211
  else
207
212
  {
208
- klass_.define_method("to_s", [](const T& unordered_map)
209
- {
210
- return "[Not printable]";
211
- });
213
+ klass_.define_method("to_s", [](const T&)
214
+ {
215
+ return "[Not printable]";
216
+ });
212
217
  }
213
218
  }
214
219
 
@@ -299,7 +304,7 @@ namespace Rice
299
304
  {
300
305
  }
301
306
 
302
- Convertible is_convertible(VALUE value)
307
+ double is_convertible(VALUE value)
303
308
  {
304
309
  switch (rb_type(value))
305
310
  {
@@ -307,7 +312,7 @@ namespace Rice
307
312
  return Data_Type<std::unordered_map<T, U>>::is_descendant(value) ? Convertible::Exact : Convertible::None;
308
313
  break;
309
314
  case RUBY_T_HASH:
310
- return Convertible::Cast;
315
+ return Convertible::Exact;
311
316
  break;
312
317
  default:
313
318
  return Convertible::None;
@@ -333,7 +338,7 @@ namespace Rice
333
338
  }
334
339
  default:
335
340
  {
336
- throw Exception(rb_eTypeError, "wrong argument type %s (expected % s)",
341
+ throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
337
342
  detail::protect(rb_obj_classname, value), "std::unordered_map");
338
343
  }
339
344
  }
@@ -353,7 +358,7 @@ namespace Rice
353
358
  {
354
359
  }
355
360
 
356
- Convertible is_convertible(VALUE value)
361
+ double is_convertible(VALUE value)
357
362
  {
358
363
  switch (rb_type(value))
359
364
  {
@@ -361,7 +366,7 @@ namespace Rice
361
366
  return Data_Type<std::unordered_map<T, U>>::is_descendant(value) ? Convertible::Exact : Convertible::None;
362
367
  break;
363
368
  case RUBY_T_HASH:
364
- return Convertible::Cast;
369
+ return Convertible::Exact;
365
370
  break;
366
371
  default:
367
372
  return Convertible::None;
@@ -388,7 +393,7 @@ namespace Rice
388
393
  }
389
394
  default:
390
395
  {
391
- throw Exception(rb_eTypeError, "wrong argument type %s (expected % s)",
396
+ throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
392
397
  detail::protect(rb_obj_classname, value), "std::unordered_map");
393
398
  }
394
399
  }
@@ -409,7 +414,7 @@ namespace Rice
409
414
  {
410
415
  }
411
416
 
412
- Convertible is_convertible(VALUE value)
417
+ double is_convertible(VALUE value)
413
418
  {
414
419
  switch (rb_type(value))
415
420
  {
@@ -420,7 +425,7 @@ namespace Rice
420
425
  return Convertible::Exact;
421
426
  break;
422
427
  case RUBY_T_HASH:
423
- return Convertible::Cast;
428
+ return Convertible::Exact;
424
429
  break;
425
430
  default:
426
431
  return Convertible::None;
@@ -447,7 +452,7 @@ namespace Rice
447
452
  }
448
453
  default:
449
454
  {
450
- throw Exception(rb_eTypeError, "wrong argument type %s (expected % s)",
455
+ throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
451
456
  detail::protect(rb_obj_classname, value), "std::unordered_map");
452
457
  }
453
458
  }
data/rice/stl/variant.ipp CHANGED
@@ -8,7 +8,7 @@ namespace Rice::detail
8
8
  using Tuple_T = std::tuple<Types...>;
9
9
 
10
10
  template<std::size_t... I>
11
- constexpr static bool verifyTypes(std::index_sequence<I...>& indices)
11
+ constexpr static bool verifyTypes(std::index_sequence<I...>&)
12
12
  {
13
13
  return (Type<std::tuple_element_t<I, Tuple_T>>::verify() && ...);
14
14
  }
@@ -32,18 +32,23 @@ namespace Rice::detail
32
32
  public:
33
33
  To_Ruby() = default;
34
34
 
35
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
35
+ explicit To_Ruby(Arg* arg) : arg_(arg)
36
36
  {
37
37
  }
38
38
 
39
39
  template<typename U, typename V>
40
40
  VALUE convertElement(U& data, bool takeOwnership)
41
41
  {
42
- return To_Ruby<V>().convert(std::forward<V>(std::get<V>(data)));
42
+ Arg arg("arg1");
43
+ if (takeOwnership)
44
+ {
45
+ arg.takeOwnership();
46
+ }
47
+ return To_Ruby<V>(&arg).convert(std::forward<V>(std::get<V>(data)));
43
48
  }
44
49
 
45
50
  template<typename U, std::size_t... I>
46
- VALUE convertIterator(U& data, bool takeOwnership, std::index_sequence<I...>& indices)
51
+ VALUE convertIterator(U& data, bool takeOwnership, std::index_sequence<I...>&)
47
52
  {
48
53
  // Create a tuple of the variant types so we can look over the tuple's types
49
54
  using Tuple_T = std::tuple<Types...>;
@@ -101,7 +106,7 @@ namespace Rice::detail
101
106
  }
102
107
 
103
108
  private:
104
- Return* returnInfo_ = nullptr;
109
+ Arg* arg_ = nullptr;
105
110
  };
106
111
 
107
112
  template<typename...Types>
@@ -110,25 +115,31 @@ namespace Rice::detail
110
115
  public:
111
116
  To_Ruby() = default;
112
117
 
113
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
118
+ explicit To_Ruby(Arg* arg) : arg_(arg)
114
119
  {
115
120
  }
116
121
 
117
122
  template<typename U, typename V>
118
123
  VALUE convertElement(U& data, bool takeOwnership)
119
124
  {
125
+ Arg arg("arg1");
126
+ if (takeOwnership)
127
+ {
128
+ arg.takeOwnership();
129
+ }
130
+
120
131
  if constexpr (std::is_const_v<U>)
121
132
  {
122
- return To_Ruby<V>().convert(std::get<V>(data));
133
+ return To_Ruby<V>(&arg).convert(std::get<V>(data));
123
134
  }
124
135
  else
125
136
  {
126
- return To_Ruby<V>().convert(std::forward<V>(std::get<V>(data)));
137
+ return To_Ruby<V>(&arg).convert(std::forward<V>(std::get<V>(data)));
127
138
  }
128
139
  }
129
140
 
130
141
  template<typename U, std::size_t... I>
131
- VALUE convertIterator(U& data, bool takeOwnership, std::index_sequence<I...>& indices)
142
+ VALUE convertIterator(U& data, bool takeOwnership, std::index_sequence<I...>&)
132
143
  {
133
144
  // Create a tuple of the variant types so we can look over the tuple's types
134
145
  using Tuple_T = std::tuple<Types...>;
@@ -154,13 +165,13 @@ namespace Rice::detail
154
165
  template<typename U>
155
166
  VALUE convert(U& data)
156
167
  {
157
- bool isOwner = (this->returnInfo_ && this->returnInfo_->isOwner());
168
+ bool isOwner = (this->arg_ && this->arg_->isOwner());
158
169
  auto indices = std::make_index_sequence<std::variant_size_v<std::variant<Types...>>>{};
159
170
  return convertIterator(data, isOwner, indices);
160
171
  }
161
172
 
162
173
  private:
163
- Return* returnInfo_ = nullptr;
174
+ Arg* arg_ = nullptr;
164
175
  };
165
176
 
166
177
  template<typename...Types>
@@ -169,18 +180,18 @@ namespace Rice::detail
169
180
  public:
170
181
  From_Ruby() = default;
171
182
 
172
- explicit From_Ruby(Arg* arg)
183
+ explicit From_Ruby(Arg* arg) : arg_(arg)
173
184
  {
174
185
  }
175
186
 
176
- Convertible is_convertible(VALUE value)
187
+ double is_convertible(VALUE value)
177
188
  {
178
- Convertible result = Convertible::None;
189
+ double result = Convertible::None;
179
190
 
180
191
  for_each_tuple(this->fromRubys_,
181
192
  [&](auto& fromRuby)
182
193
  {
183
- result = result | fromRuby.is_convertible(value);
194
+ result = (std::max)(result, fromRuby.is_convertible(value));
184
195
  });
185
196
 
186
197
  return result;
@@ -192,17 +203,17 @@ namespace Rice::detail
192
203
  {
193
204
  int i = 0;
194
205
  int index = -1;
195
- Convertible foundConversion = Convertible::None;
206
+ double foundScore = Convertible::None;
196
207
 
197
208
  for_each_tuple(this->fromRubys_,
198
209
  [&](auto& fromRuby)
199
210
  {
200
- Convertible isConvertible = fromRuby.is_convertible(value);
211
+ double score = fromRuby.is_convertible(value);
201
212
 
202
- if (isConvertible > foundConversion)
213
+ if (score > foundScore)
203
214
  {
204
215
  index = i;
205
- foundConversion = isConvertible;
216
+ foundScore = score;
206
217
  }
207
218
  i++;
208
219
  });
@@ -240,7 +251,10 @@ namespace Rice::detail
240
251
  return convertInternal<I + 1>(value, index);
241
252
  }
242
253
  }
243
- rb_raise(rb_eArgError, "Could not find converter for variant");
254
+ else
255
+ {
256
+ rb_raise(rb_eArgError, "Could not find converter for variant");
257
+ }
244
258
  }
245
259
 
246
260
  std::variant<Types...> convert(VALUE value)
@@ -250,6 +264,7 @@ namespace Rice::detail
250
264
  }
251
265
 
252
266
  private:
267
+ Arg* arg_ = nullptr;
253
268
  // Possible converters we could use for this variant
254
269
  using From_Ruby_Ts = std::tuple<From_Ruby<Types>...>;
255
270
  From_Ruby_Ts fromRubys_;
@@ -261,7 +276,7 @@ namespace Rice::detail
261
276
  public:
262
277
  From_Ruby() = default;
263
278
 
264
- explicit From_Ruby(Arg* arg)
279
+ explicit From_Ruby(Arg* arg) : arg_(arg)
265
280
  {
266
281
  }
267
282
 
@@ -273,6 +288,7 @@ namespace Rice::detail
273
288
  }
274
289
 
275
290
  private:
291
+ Arg* arg_ = nullptr;
276
292
  std::variant<Types...> converted_;
277
293
  };
278
294
  }