rice 4.3.3 → 4.6.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 (237) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +86 -26
  3. data/CMakeLists.txt +31 -0
  4. data/CMakePresets.json +75 -0
  5. data/COPYING +3 -2
  6. data/FindRuby.cmake +437 -0
  7. data/README.md +7 -2
  8. data/Rakefile +12 -5
  9. data/include/rice/rice.hpp +9522 -4426
  10. data/include/rice/stl.hpp +2831 -1198
  11. data/lib/make_rice_headers.rb +79 -0
  12. data/lib/mkmf-rice.rb +40 -94
  13. data/lib/rice/version.rb +3 -0
  14. data/lib/rice.rb +1 -0
  15. data/lib/rubygems/builder.rb +11 -0
  16. data/lib/rubygems/cmake_builder.rb +113 -0
  17. data/lib/rubygems_plugin.rb +9 -0
  18. data/rice/Address_Registration_Guard.hpp +72 -3
  19. data/rice/Arg.hpp +26 -6
  20. data/rice/Arg.ipp +35 -2
  21. data/rice/Buffer.hpp +123 -0
  22. data/rice/Buffer.ipp +599 -0
  23. data/rice/Callback.hpp +21 -0
  24. data/rice/Callback.ipp +13 -0
  25. data/rice/Constructor.hpp +4 -27
  26. data/rice/Constructor.ipp +79 -0
  27. data/rice/Data_Object.hpp +73 -3
  28. data/rice/Data_Object.ipp +388 -96
  29. data/rice/Data_Type.hpp +214 -3
  30. data/rice/Data_Type.ipp +144 -67
  31. data/rice/Director.hpp +0 -2
  32. data/rice/Enum.hpp +4 -7
  33. data/rice/Enum.ipp +102 -55
  34. data/rice/Exception.hpp +62 -2
  35. data/rice/Exception.ipp +7 -12
  36. data/rice/Init.hpp +8 -0
  37. data/rice/Init.ipp +8 -0
  38. data/rice/JumpException.hpp +44 -0
  39. data/rice/JumpException.ipp +48 -0
  40. data/rice/MemoryView.hpp +11 -0
  41. data/rice/MemoryView.ipp +3 -0
  42. data/rice/Return.hpp +7 -27
  43. data/rice/Return.ipp +13 -13
  44. data/rice/cpp_api/Array.hpp +209 -0
  45. data/rice/cpp_api/Array.ipp +304 -0
  46. data/rice/cpp_api/Builtin_Object.hpp +31 -0
  47. data/rice/cpp_api/Builtin_Object.ipp +37 -0
  48. data/rice/cpp_api/Class.hpp +70 -0
  49. data/rice/cpp_api/Class.ipp +97 -0
  50. data/rice/cpp_api/Encoding.hpp +32 -0
  51. data/rice/cpp_api/Encoding.ipp +59 -0
  52. data/rice/cpp_api/Hash.hpp +194 -0
  53. data/rice/cpp_api/Hash.ipp +257 -0
  54. data/rice/{Identifier.hpp → cpp_api/Identifier.hpp} +2 -6
  55. data/rice/{Identifier.ipp → cpp_api/Identifier.ipp} +4 -2
  56. data/rice/cpp_api/Module.hpp +72 -0
  57. data/rice/cpp_api/Module.ipp +101 -0
  58. data/rice/cpp_api/Object.hpp +272 -0
  59. data/rice/cpp_api/Object.ipp +235 -0
  60. data/rice/cpp_api/String.hpp +74 -0
  61. data/rice/cpp_api/String.ipp +120 -0
  62. data/rice/cpp_api/Struct.hpp +113 -0
  63. data/rice/cpp_api/Struct.ipp +92 -0
  64. data/rice/cpp_api/Symbol.hpp +46 -0
  65. data/rice/cpp_api/Symbol.ipp +93 -0
  66. data/rice/cpp_api/shared_methods.hpp +134 -0
  67. data/rice/detail/DefaultHandler.hpp +12 -0
  68. data/rice/detail/DefaultHandler.ipp +8 -0
  69. data/rice/detail/HandlerRegistry.hpp +5 -35
  70. data/rice/detail/HandlerRegistry.ipp +7 -11
  71. data/rice/detail/InstanceRegistry.hpp +1 -4
  72. data/rice/detail/MethodInfo.hpp +12 -10
  73. data/rice/detail/MethodInfo.ipp +26 -21
  74. data/rice/detail/Native.hpp +33 -0
  75. data/rice/detail/Native.ipp +157 -0
  76. data/rice/detail/NativeAttributeGet.hpp +52 -0
  77. data/rice/detail/NativeAttributeGet.ipp +57 -0
  78. data/rice/detail/NativeAttributeSet.hpp +44 -0
  79. data/rice/detail/NativeAttributeSet.ipp +88 -0
  80. data/rice/detail/NativeCallbackFFI.hpp +55 -0
  81. data/rice/detail/NativeCallbackFFI.ipp +151 -0
  82. data/rice/detail/NativeCallbackSimple.hpp +30 -0
  83. data/rice/detail/NativeCallbackSimple.ipp +29 -0
  84. data/rice/detail/NativeFunction.hpp +33 -23
  85. data/rice/detail/NativeFunction.ipp +309 -70
  86. data/rice/detail/NativeIterator.hpp +9 -11
  87. data/rice/detail/NativeIterator.ipp +33 -31
  88. data/rice/detail/NativeRegistry.hpp +24 -15
  89. data/rice/detail/NativeRegistry.ipp +23 -48
  90. data/rice/detail/Proc.hpp +4 -0
  91. data/rice/detail/Proc.ipp +85 -0
  92. data/rice/detail/Registries.hpp +0 -7
  93. data/rice/detail/Registries.ipp +0 -18
  94. data/rice/detail/RubyFunction.hpp +0 -3
  95. data/rice/detail/RubyFunction.ipp +4 -8
  96. data/rice/detail/RubyType.hpp +16 -0
  97. data/rice/detail/RubyType.ipp +232 -0
  98. data/rice/detail/Type.hpp +7 -6
  99. data/rice/detail/Type.ipp +192 -45
  100. data/rice/detail/TypeRegistry.hpp +15 -7
  101. data/rice/detail/TypeRegistry.ipp +105 -12
  102. data/rice/detail/Wrapper.hpp +68 -32
  103. data/rice/detail/Wrapper.ipp +121 -109
  104. data/rice/detail/cpp_protect.hpp +5 -6
  105. data/rice/detail/default_allocation_func.ipp +0 -2
  106. data/rice/detail/from_ruby.hpp +38 -3
  107. data/rice/detail/from_ruby.ipp +1321 -492
  108. data/rice/detail/ruby.hpp +18 -0
  109. data/rice/detail/to_ruby.hpp +41 -3
  110. data/rice/detail/to_ruby.ipp +1424 -194
  111. data/rice/global_function.hpp +0 -4
  112. data/rice/global_function.ipp +0 -1
  113. data/rice/libc/file.hpp +11 -0
  114. data/rice/libc/file.ipp +32 -0
  115. data/rice/rice.hpp +116 -26
  116. data/rice/ruby_mark.hpp +4 -3
  117. data/rice/stl/complex.hpp +6 -0
  118. data/rice/stl/complex.ipp +93 -0
  119. data/rice/stl/exception.hpp +11 -0
  120. data/rice/stl/exception.ipp +29 -0
  121. data/rice/stl/exception_ptr.hpp +6 -0
  122. data/rice/stl/exception_ptr.ipp +27 -0
  123. data/rice/stl/map.hpp +12 -0
  124. data/rice/stl/map.ipp +469 -0
  125. data/rice/stl/monostate.hpp +6 -0
  126. data/rice/stl/monostate.ipp +80 -0
  127. data/rice/stl/multimap.hpp +14 -0
  128. data/rice/stl/multimap.ipp +448 -0
  129. data/rice/stl/optional.hpp +6 -0
  130. data/rice/stl/optional.ipp +118 -0
  131. data/rice/stl/pair.hpp +13 -0
  132. data/rice/stl/pair.ipp +155 -0
  133. data/rice/stl/reference_wrapper.hpp +6 -0
  134. data/rice/stl/reference_wrapper.ipp +41 -0
  135. data/rice/stl/set.hpp +12 -0
  136. data/rice/stl/set.ipp +495 -0
  137. data/rice/stl/shared_ptr.hpp +28 -0
  138. data/rice/stl/shared_ptr.ipp +224 -0
  139. data/rice/stl/string.hpp +6 -0
  140. data/rice/stl/string.ipp +158 -0
  141. data/rice/stl/string_view.hpp +6 -0
  142. data/rice/stl/string_view.ipp +65 -0
  143. data/rice/stl/tuple.hpp +6 -0
  144. data/rice/stl/tuple.ipp +128 -0
  145. data/rice/stl/type_index.hpp +6 -0
  146. data/rice/stl/type_index.ipp +30 -0
  147. data/rice/stl/type_info.hpp +6 -0
  148. data/rice/stl/type_info.ipp +29 -0
  149. data/rice/stl/unique_ptr.hpp +22 -0
  150. data/rice/stl/unique_ptr.ipp +139 -0
  151. data/rice/stl/unordered_map.hpp +12 -0
  152. data/rice/stl/unordered_map.ipp +469 -0
  153. data/rice/stl/variant.hpp +6 -0
  154. data/rice/stl/variant.ipp +242 -0
  155. data/rice/stl/vector.hpp +12 -0
  156. data/rice/stl/vector.ipp +590 -0
  157. data/rice/stl.hpp +11 -3
  158. data/rice/traits/attribute_traits.hpp +26 -0
  159. data/rice/traits/function_traits.hpp +95 -0
  160. data/rice/traits/method_traits.hpp +47 -0
  161. data/rice/traits/rice_traits.hpp +160 -0
  162. data/rice.gemspec +85 -0
  163. data/test/embed_ruby.cpp +7 -1
  164. data/test/extconf.rb +2 -0
  165. data/test/test_Address_Registration_Guard.cpp +5 -0
  166. data/test/test_Array.cpp +18 -4
  167. data/test/test_Attribute.cpp +136 -21
  168. data/test/test_Buffer.cpp +285 -0
  169. data/test/test_Builtin_Object.cpp +5 -0
  170. data/test/test_Callback.cpp +230 -0
  171. data/test/test_Class.cpp +5 -31
  172. data/test/test_Constructor.cpp +69 -6
  173. data/test/test_Data_Object.cpp +97 -38
  174. data/test/test_Data_Type.cpp +470 -65
  175. data/test/test_Director.cpp +17 -8
  176. data/test/test_Enum.cpp +155 -40
  177. data/test/test_Exception.cpp +235 -0
  178. data/test/test_File.cpp +70 -0
  179. data/test/test_From_Ruby.cpp +609 -0
  180. data/test/test_Hash.cpp +5 -0
  181. data/test/test_Identifier.cpp +5 -0
  182. data/test/test_Inheritance.cpp +6 -1
  183. data/test/test_Iterator.cpp +6 -1
  184. data/test/test_Jump_Exception.cpp +23 -0
  185. data/test/test_Keep_Alive.cpp +13 -19
  186. data/test/test_Keep_Alive_No_Wrapper.cpp +5 -1
  187. data/test/test_Memory_Management.cpp +5 -0
  188. data/test/test_Module.cpp +128 -67
  189. data/test/test_Native_Registry.cpp +2 -34
  190. data/test/test_Object.cpp +5 -0
  191. data/test/test_Overloads.cpp +806 -0
  192. data/test/test_Ownership.cpp +160 -54
  193. data/test/test_Proc.cpp +44 -0
  194. data/test/test_Self.cpp +9 -4
  195. data/test/test_Stl_Exception.cpp +109 -0
  196. data/test/test_Stl_Map.cpp +54 -42
  197. data/test/test_Stl_Multimap.cpp +693 -0
  198. data/test/test_Stl_Optional.cpp +5 -0
  199. data/test/test_Stl_Pair.cpp +14 -9
  200. data/test/test_Stl_Reference_Wrapper.cpp +9 -2
  201. data/test/test_Stl_Set.cpp +790 -0
  202. data/test/test_Stl_SharedPtr.cpp +458 -0
  203. data/test/test_Stl_String.cpp +5 -0
  204. data/test/test_Stl_String_View.cpp +5 -0
  205. data/test/test_Stl_Tuple.cpp +116 -0
  206. data/test/test_Stl_Type.cpp +147 -0
  207. data/test/test_Stl_UniquePtr.cpp +202 -0
  208. data/test/test_Stl_Unordered_Map.cpp +43 -38
  209. data/test/test_Stl_Variant.cpp +217 -84
  210. data/test/test_Stl_Vector.cpp +306 -58
  211. data/test/test_String.cpp +5 -0
  212. data/test/test_Struct.cpp +5 -0
  213. data/test/test_Symbol.cpp +5 -0
  214. data/test/test_Template.cpp +192 -0
  215. data/test/test_To_Ruby.cpp +524 -0
  216. data/test/test_Tracking.cpp +1 -0
  217. data/test/test_Type.cpp +171 -0
  218. data/test/test_global_functions.cpp +67 -7
  219. data/test/unittest.cpp +8 -0
  220. metadata +127 -26
  221. data/lib/version.rb +0 -3
  222. data/rice/Address_Registration_Guard_defn.hpp +0 -79
  223. data/rice/Data_Object_defn.hpp +0 -84
  224. data/rice/Data_Type_defn.hpp +0 -190
  225. data/rice/Exception_defn.hpp +0 -68
  226. data/rice/HandlerRegistration.hpp +0 -15
  227. data/rice/detail/ExceptionHandler.hpp +0 -8
  228. data/rice/detail/ExceptionHandler.ipp +0 -28
  229. data/rice/detail/ExceptionHandler_defn.hpp +0 -77
  230. data/rice/detail/Jump_Tag.hpp +0 -21
  231. data/rice/detail/NativeAttribute.hpp +0 -64
  232. data/rice/detail/NativeAttribute.ipp +0 -112
  233. data/rice/detail/from_ruby_defn.hpp +0 -38
  234. data/rice/detail/to_ruby_defn.hpp +0 -48
  235. data/test/test_Jump_Tag.cpp +0 -17
  236. data/test/test_Stl_SmartPointer.cpp +0 -283
  237. data/test/test_To_From_Ruby.cpp +0 -399
@@ -0,0 +1,95 @@
1
+ #ifndef Rice__detail__function_traits__hpp_
2
+ #define Rice__detail__function_traits__hpp_
3
+
4
+ #include <tuple>
5
+
6
+ namespace Rice::detail
7
+ {
8
+ // Base class
9
+ template<typename Function_T>
10
+ struct function_traits;
11
+
12
+ template<typename Return_T, typename Class_T, typename...Arg_Ts>
13
+ struct function_traits<Return_T(Class_T, Arg_Ts...)>
14
+ {
15
+ using arg_types = std::tuple<Arg_Ts...>;
16
+
17
+ static constexpr std::size_t arity = sizeof...(Arg_Ts);
18
+
19
+ template<std::size_t N>
20
+ using nth_arg = typename std::tuple_element<N, arg_types>::type;
21
+
22
+ using return_type = Return_T;
23
+ using class_type = Class_T;
24
+ };
25
+
26
+ // Functors and lambdas with operator()
27
+ template<typename Function_T>
28
+ struct function_traits : public function_traits<decltype(&Function_T::operator())>
29
+ {
30
+ private:
31
+ using functor_t = function_traits<decltype(&Function_T::operator())>;
32
+
33
+ public:
34
+ using arg_types = typename functor_t::arg_types;
35
+ static constexpr std::size_t arity = functor_t::arity - 1;
36
+ using class_type = std::nullptr_t;
37
+ };
38
+
39
+ // C functions and static member functions passed by pointer
40
+ template<typename Return_T, typename ...Arg_Ts>
41
+ struct function_traits<Return_T(*)(Arg_Ts...)> : public function_traits<Return_T(std::nullptr_t, Arg_Ts...)>
42
+ {
43
+ using Function_T = Return_T(*)(Arg_Ts...);
44
+ };
45
+
46
+ // C functions passed by pointer that take one or more defined parameter than a variable
47
+ // number of parameters (the second ...)
48
+ template<typename Return_T, typename ...Arg_Ts>
49
+ struct function_traits<Return_T(*)(Arg_Ts..., ...)> : public function_traits<Return_T(std::nullptr_t, Arg_Ts...)>
50
+ {
51
+ };
52
+
53
+ // C Functions or static member functions passed by reference
54
+ template<typename Return_T, typename ...Arg_Ts>
55
+ struct function_traits<Return_T(&)(Arg_Ts...)> : public function_traits<Return_T(std::nullptr_t, Arg_Ts...)>
56
+ {
57
+ };
58
+
59
+ // Member Functions on C++ classes
60
+ template<typename Return_T, typename Class_T, typename...Arg_Ts>
61
+ struct function_traits<Return_T(Class_T::*)(Arg_Ts...)> : public function_traits<Return_T(Class_T*, Arg_Ts...)>
62
+ {
63
+ };
64
+
65
+ // const member Functions on C++ classes
66
+ template<typename Return_T, typename Class_T, typename...Arg_Ts>
67
+ struct function_traits<Return_T(Class_T::*)(Arg_Ts...) const> : public function_traits<Return_T(Class_T*, Arg_Ts...)>
68
+ {
69
+ };
70
+
71
+ // noexcept member Functions on C++ classes
72
+ template<typename Return_T, typename Class_T, typename...Arg_Ts>
73
+ struct function_traits<Return_T(Class_T::*)(Arg_Ts...) noexcept> : public function_traits<Return_T(Class_T*, Arg_Ts...)>
74
+ {
75
+ };
76
+
77
+
78
+ // const noexcept member Functions on C++ classes
79
+ template<typename Return_T, typename Class_T, typename...Arg_Ts>
80
+ struct function_traits<Return_T(Class_T::*)(Arg_Ts...) const noexcept> : public function_traits<Return_T(Class_T*, Arg_Ts...)>
81
+ {
82
+ };
83
+
84
+ /*// Functors and lambdas
85
+ template<class Function_T>
86
+ struct function_traits<Function_T&> : public function_traits<Function_T>
87
+ {
88
+ };
89
+
90
+ template<class Function_T>
91
+ struct function_traits<Function_T&&> : public function_traits<Function_T>
92
+ {
93
+ };*/
94
+ }
95
+ #endif // Rice__detail__function_traits__hpp_
@@ -0,0 +1,47 @@
1
+ #ifndef Rice__detail__method_traits__hpp_
2
+ #define Rice__detail__method_traits__hpp_
3
+
4
+ #include <tuple>
5
+
6
+ namespace Rice::detail
7
+ {
8
+ // Declare struct
9
+ template<typename Function_T, bool IsMethod, typename = void>
10
+ struct method_traits;
11
+
12
+ // Functions that do not have a self parameter:
13
+ // doSomething(int a)
14
+ template<typename Function_T, bool IsMethod>
15
+ struct method_traits<Function_T, IsMethod, std::enable_if_t<!IsMethod>>
16
+ {
17
+ using Return_T = typename function_traits<Function_T>::return_type;
18
+ using Class_T = std::nullptr_t;
19
+ using Arg_Ts = typename function_traits<Function_T>::arg_types;
20
+ static constexpr std::size_t arity = std::tuple_size_v<Arg_Ts>;
21
+ };
22
+
23
+ /* Functions that have a self parameter and thus we treat them as free standing
24
+ "methods" versus member functions.
25
+
26
+ doSomething(VALUE self, int a) */
27
+ template<typename Function_T, bool IsMethod>
28
+ struct method_traits<Function_T, IsMethod, std::enable_if_t<IsMethod && std::is_same_v<typename function_traits<Function_T>::class_type, std::nullptr_t>>>
29
+ {
30
+ using Return_T = typename function_traits<Function_T>::return_type;
31
+ using Class_T = typename function_traits<Function_T>::template nth_arg<0>;
32
+ using Arg_Ts = typename tuple_shift<typename function_traits<Function_T>::arg_types>::type;
33
+ static constexpr std::size_t arity = std::tuple_size_v<Arg_Ts>;
34
+ };
35
+
36
+ // Member functions that have an implied self parameter of an object instance
37
+ // foo.doSomething(int a)
38
+ template<typename Function_T, bool IsMethod>
39
+ struct method_traits<Function_T, IsMethod, std::enable_if_t<IsMethod && !std::is_same_v<typename function_traits<Function_T>::class_type, std::nullptr_t>>>
40
+ {
41
+ using Return_T = typename function_traits<Function_T>::return_type;
42
+ using Class_T = typename function_traits<Function_T>::class_type;
43
+ using Arg_Ts = typename function_traits<Function_T>::arg_types;
44
+ static constexpr std::size_t arity = std::tuple_size_v<Arg_Ts>;
45
+ };
46
+ }
47
+ #endif // Rice__detail__method_traits__hpp_
@@ -0,0 +1,160 @@
1
+ #ifndef Rice__detail__traits__hpp_
2
+ #define Rice__detail__traits__hpp_
3
+
4
+ #include <ostream>
5
+ #include <type_traits>
6
+ #include <variant>
7
+ #include <vector>
8
+
9
+ namespace Rice
10
+ {
11
+ namespace detail
12
+ {
13
+ // Get the base_type of T - without pointer, reference, const or volatile. We call remove_pointer_t twice
14
+ // for T**
15
+ template<typename T>
16
+ using intrinsic_type = typename std::remove_cv_t<std::remove_pointer_t<std::remove_pointer_t<std::remove_reference_t<T>>>>;
17
+
18
+ template<typename T>
19
+ constexpr bool is_const_any_v = std::is_const_v<std::remove_pointer_t<std::remove_pointer_t<std::remove_reference_t<T>>>>;
20
+
21
+ // Recursively remove const/volatile
22
+ template<typename T>
23
+ struct remove_cv_recursive
24
+ {
25
+ using type = T;
26
+ };
27
+
28
+ template<typename T>
29
+ struct remove_cv_recursive<T const volatile>
30
+ {
31
+ using type = typename remove_cv_recursive<T>::type;
32
+ };
33
+
34
+ template<typename T>
35
+ struct remove_cv_recursive<T volatile>
36
+ {
37
+ using type = typename remove_cv_recursive<T>::type;
38
+ };
39
+
40
+ template<typename T>
41
+ struct remove_cv_recursive<T const>
42
+ {
43
+ using type = typename remove_cv_recursive<T>::type;
44
+ };
45
+
46
+ template<typename T>
47
+ struct remove_cv_recursive<T&>
48
+ {
49
+ using type = typename remove_cv_recursive<T>::type&;
50
+ };
51
+
52
+ /* template<typename T>
53
+ struct remove_cv_recursive<T&&>
54
+ {
55
+ using type = typename remove_cv_recursive<T>::type&&;
56
+ };*/
57
+
58
+ template<typename T>
59
+ struct remove_cv_recursive<T*>
60
+ {
61
+ using type = typename remove_cv_recursive<T>::type*;
62
+ };
63
+
64
+ template<typename T>
65
+ using remove_cv_recursive_t = typename remove_cv_recursive<T>::type;
66
+
67
+ // Does the Type work with ostreams? This is used to implement #to_s
68
+ template<typename T, typename = void>
69
+ struct is_ostreamable : std::false_type {};
70
+
71
+ template<typename T>
72
+ struct is_ostreamable<T, std::void_t<decltype(std::declval<std::ostream&>() << std::declval<const T>())>> : std::true_type {};
73
+
74
+ template<typename T>
75
+ constexpr bool is_ostreamable_v = is_ostreamable<T>::value;
76
+
77
+ // Is the type comparable?
78
+ template<typename T, typename SFINAE = void>
79
+ struct is_comparable : std::false_type {};
80
+
81
+ template<typename T>
82
+ struct is_comparable<T, std::void_t<
83
+ // Does the class implement operator== and does it return a boolean value?
84
+ decltype(std::declval<T>() == std::declval<T>() && true)
85
+ >> : std::true_type {};
86
+
87
+ template<typename T>
88
+ constexpr bool is_comparable_v = is_comparable<T>::value;
89
+
90
+ template <typename U, typename V>
91
+ struct is_comparable<std::pair<U, V>>
92
+ {
93
+ static const bool value = is_comparable_v<U> && is_comparable_v<V>;
94
+ };
95
+
96
+ template <typename T>
97
+ struct is_comparable<std::vector<T>>
98
+ {
99
+ static const bool value = is_comparable_v<T>;
100
+ };
101
+
102
+ // -- Tuple Helpers ---
103
+ template<typename T>
104
+ struct tuple_shift;
105
+
106
+ template<typename T, typename...Arg_Ts>
107
+ struct tuple_shift<std::tuple<T, Arg_Ts...>>
108
+ {
109
+ using type = std::tuple<Arg_Ts...>;
110
+ };
111
+
112
+ template<template<typename, typename...> typename T, typename...Arg_Ts>
113
+ struct tuple_map;
114
+
115
+ template<template<typename, typename...> typename T, typename...Arg_Ts>
116
+ struct tuple_map<T, std::tuple<Arg_Ts...>>
117
+ {
118
+ using type = std::tuple<T<remove_cv_recursive_t<Arg_Ts>>...>;
119
+ };
120
+
121
+ template<typename...Arg_Ts>
122
+ struct tuple_to_variant;
123
+
124
+ template<typename...Arg_Ts>
125
+ struct tuple_to_variant<std::tuple<Arg_Ts...>>
126
+ {
127
+ using type = std::variant<Arg_Ts...>;
128
+ };
129
+
130
+ template<class T>
131
+ struct is_pointer_pointer : std::false_type {};
132
+
133
+ template<class T>
134
+ struct is_pointer_pointer<T**> : std::true_type {};
135
+
136
+ template<class T>
137
+ struct is_pointer_pointer<T** const> : std::true_type {};
138
+
139
+ template<class T>
140
+ struct is_pointer_pointer<T* const * const> : std::true_type {};
141
+
142
+ template<class T>
143
+ struct is_pointer_pointer<const T* const* const> : std::true_type {};
144
+
145
+ template<class T>
146
+ constexpr bool is_pointer_pointer_v = is_pointer_pointer<T>::value;
147
+
148
+ // See https://www.cppstories.com/2022/tuple-iteration-apply/
149
+ template <typename Tuple_T, typename Function_T>
150
+ void for_each_tuple(Tuple_T&& tuple, Function_T&& callable)
151
+ {
152
+ std::apply([&callable](auto&& ...args)
153
+ {
154
+ (callable(std::forward<decltype(args)>(args)), ...);
155
+ }, std::forward<Tuple_T>(tuple));
156
+ }
157
+ } // detail
158
+ } // Rice
159
+
160
+ #endif // Rice__detail__traits__hpp_
data/rice.gemspec ADDED
@@ -0,0 +1,85 @@
1
+ $:.unshift File.expand_path(File.dirname(__FILE__))
2
+ require 'lib/rice/version'
3
+
4
+ $spec = Gem::Specification.new do |s|
5
+ s.name = 'rice'
6
+ s.version = Rice::VERSION
7
+ s.license = "MIT"
8
+ s.summary = 'Ruby Interface for C++ Extensions'
9
+ s.homepage = 'https://github.com/ruby-rice/rice'
10
+ s.authors = ['Paul Brannan', 'Jason Roelofs', 'Charlie Savage']
11
+ s.email = ['curlypaul924@gmail.com', 'jasongroelofs@gmail.com', 'cfis@savagexi.com']
12
+
13
+ s.description = <<-END
14
+ Rice is a C++ interface to Ruby's C API. It provides a type-safe and
15
+ exception-safe interface in order to make embedding Ruby and writing
16
+ Ruby extensions with C++ easier.
17
+ END
18
+
19
+ s.metadata = {
20
+ "bug_tracker_uri" => "https://github.com/ruby-rice/rice/issues",
21
+ "changelog_uri" => "https://github.com/ruby-rice/rice/blob/master/CHANGELOG.md",
22
+ "documentation_uri" => "https://ruby-rice.github.io",
23
+ "source_code_uri" => "https://github.com/ruby-rice/rice",
24
+ }
25
+
26
+ s.test_files = Dir['test/ruby/*.rb']
27
+ s.extra_rdoc_files = ['README.md']
28
+ s.require_paths = ['lib']
29
+
30
+ s.files = Dir[
31
+ # Documentation
32
+ 'CHANGELOG.md',
33
+ 'CONTRIBUTORS.md',
34
+ 'COPYING',
35
+ 'README.md',
36
+
37
+ # Ruby files
38
+ 'Gemfile',
39
+ 'Rakefile',
40
+ 'rice.gemspec',
41
+
42
+ # CMake Files
43
+ 'CMakeLists.txt',
44
+ 'CMakePresets.json',
45
+ 'FindRuby.cmake',
46
+
47
+ # rice.hpp
48
+ 'include/rice/rice.hpp',
49
+ 'include/rice/stl.hpp',
50
+
51
+ # Source files
52
+ 'rice/**/*.?pp',
53
+
54
+ # Ruby files
55
+ 'lib/**/*.rb',
56
+
57
+ # Samples
58
+ 'sample/enum/extconf.rb',
59
+ 'sample/enum/*.?pp',
60
+ 'sample/enum/*.rb',
61
+ 'sample/map/extconf.rb',
62
+ 'sample/map/*.?pp',
63
+ 'sample/map/*.rb',
64
+ 'sample/inheritance/extconf.rb',
65
+ 'sample/inheritance/*.?pp',
66
+ 'sample/inheritance/*.rb',
67
+ 'sample/callbacks/extconf.rb',
68
+ 'sample/callbacks/*.?pp',
69
+ 'sample/callbacks/*.rb',
70
+
71
+ # Test source files
72
+ 'test/*.?pp',
73
+ 'test/extconf.rb',
74
+ 'test/ext/t1/extconf.rb',
75
+ 'test/ext/t1/*.*pp',
76
+ 'test/ext/t2/extconf.rb',
77
+ 'test/ext/t2/*.*pp'
78
+ ]
79
+
80
+ s.required_ruby_version = ">= 3.1"
81
+
82
+ s.add_development_dependency "bundler"
83
+ s.add_development_dependency "rake"
84
+ s.add_development_dependency "minitest"
85
+ end
data/test/embed_ruby.cpp CHANGED
@@ -7,20 +7,26 @@ void embed_ruby()
7
7
 
8
8
  if (!initialized__)
9
9
  {
10
+ RUBY_INIT_STACK;
11
+
10
12
  int argc = 0;
11
13
  char* argv = nullptr;
12
14
  char** pArgv = &argv;
13
15
 
14
16
  ruby_sysinit(&argc, &pArgv);
17
+
15
18
  ruby_init();
16
19
  ruby_init_loadpath();
17
20
 
18
- #if RUBY_API_VERSION_MAJOR == 3 && RUBY_API_VERSION_MINOR >= 3
21
+ #if RUBY_API_VERSION_MAJOR == 3 && RUBY_API_VERSION_MINOR >= 1
19
22
  // Force the prelude / builtins
20
23
  const char* opts[] = { "ruby", "-e;" };
21
24
  ruby_options(2, (char**)opts);
22
25
  #endif
23
26
 
24
27
  initialized__ = true;
28
+
29
+ // Initialize Rice
30
+ Rice::init();
25
31
  }
26
32
  }
data/test/extconf.rb CHANGED
@@ -2,6 +2,8 @@ require 'bundler/setup'
2
2
  require 'mkmf-rice'
3
3
  require 'rbconfig'
4
4
 
5
+ abort "libffi not found" unless have_libffi
6
+
5
7
  # Totally hack mkmf to make a unittest executable instead of a shared library
6
8
  target_exe = "unittest#{RbConfig::CONFIG['EXEEXT']}"
7
9
  $cleanfiles << target_exe
@@ -11,6 +11,11 @@ SETUP(Address_Registration_Guard)
11
11
  embed_ruby();
12
12
  }
13
13
 
14
+ TEARDOWN(Address_Registration_Guard)
15
+ {
16
+ rb_gc_start();
17
+ }
18
+
14
19
  TESTCASE(register_address)
15
20
  {
16
21
  VALUE v = Qnil;
data/test/test_Array.cpp CHANGED
@@ -24,13 +24,24 @@ SETUP(Array)
24
24
  embed_ruby();
25
25
  }
26
26
 
27
- TESTCASE(default_construct)
27
+ TEARDOWN(Array)
28
+ {
29
+ rb_gc_start();
30
+ }
31
+
32
+ TESTCASE(construct_default)
28
33
  {
29
34
  Array a;
30
35
  ASSERT_EQUAL(T_ARRAY, rb_type(a));
31
36
  ASSERT_EQUAL(0, RARRAY_LEN(a.value()));
32
37
  }
33
38
 
39
+ TESTCASE(construct_capacity)
40
+ {
41
+ Array a((long)10);
42
+ ASSERT_EQUAL(0, RARRAY_LEN(a.value()));
43
+ }
44
+
34
45
  TESTCASE(construct_from_vector_of_int)
35
46
  {
36
47
  std::vector<int> v;
@@ -265,12 +276,15 @@ TESTCASE(assign_int)
265
276
  * Issue 59 - Copy constructor compilation problem.
266
277
  */
267
278
 
268
- namespace {
269
- void testArrayArg(Object self, Array string) {
279
+ namespace
280
+ {
281
+ void testArrayArg(Object self, Array string)
282
+ {
270
283
  }
271
284
  }
272
285
 
273
- TESTCASE(use_array_in_wrapped_function) {
286
+ TESTCASE(use_array_in_wrapped_function)
287
+ {
274
288
  define_global_function("test_array_arg", &testArrayArg);
275
289
  }
276
290