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
data/rice/Enum.ipp CHANGED
@@ -1,7 +1,3 @@
1
- #include "detail/TypeRegistry.hpp"
2
- #include "Data_Object.hpp"
3
- #include "cpp_api/String.hpp"
4
-
5
1
  #include <stdexcept>
6
2
 
7
3
  namespace Rice
@@ -32,57 +28,72 @@ namespace Rice
32
28
  // First we need a constructor
33
29
  klass.define_constructor(Constructor<Enum_T>());
34
30
 
35
- // Instance methods
36
- klass.define_method("to_s", [](Enum_T& self)
37
- {
38
- // We have to return string because we don't know if std::string support has
39
- // been included by the user
40
- return String(valuesToNames_[self]);
41
- })
42
- .define_method("to_i", [](Enum_T& self) -> Underlying_T
43
- {
44
- return (Underlying_T)self;
45
- })
31
+ klass.define_method("to_s", [](Enum_T& self) -> String
32
+ {
33
+ return String(valuesToNames_[self]);
34
+ })
35
+ .define_method("to_int", [](Enum_T& self) -> Underlying_T
36
+ {
37
+ return (Underlying_T)(self);
38
+ })
39
+ .define_method("coerce", [](Enum_T& self, Underlying_T& other) -> Array
40
+ {
41
+ /* Other will be a numeric value that matches the underlying type of the enum, for example an int.
42
+ Convert that to the enum type and then create new Ruby object to wrap it. This then enables code
43
+ like this:
44
+
45
+ Colors::Red | Colors:Blue | Colors:Green
46
+
47
+ Colors::Red | Colors:Blue returns an integer. Then this method converts the integer back into an Enum
48
+ instance so that Colors:Blue | Colors:Green works. */
49
+ Enum_T otherEnum = (Enum_T)other;
50
+
51
+ Array result;
52
+ result.push(self);
53
+ result.push(otherEnum);
54
+ return result;
55
+ })
46
56
  .define_method("inspect", [](Enum_T& self)
47
- {
48
- std::stringstream result;
49
- VALUE rubyKlass = Enum<Enum_T>::klass().value();
50
- result << "#<" << detail::protect(rb_class2name, rubyKlass)
51
- << "::" << Enum<Enum_T>::valuesToNames_[self] << ">";
52
-
53
- // We have to return string because we don't know if std::string support has
54
- // been included by the user
55
- return String(result.str());
56
- })
57
+ {
58
+ std::stringstream result;
59
+ VALUE rubyKlass = Enum<Enum_T>::klass().value();
60
+ result << "#<" << detail::protect(rb_class2name, rubyKlass)
61
+ << "::" << Enum<Enum_T>::valuesToNames_[self] << ">";
62
+
63
+ // We have to return string because we don't know if std::string support has
64
+ // been included by the user
65
+ return String(result.str());
66
+ })
57
67
  .define_method("hash", [](Enum_T& self) -> Underlying_T
58
- {
59
- return (Underlying_T)self;
60
- })
68
+ {
69
+ return (Underlying_T)self;
70
+ })
61
71
  .define_method("eql?", [](Enum_T& self, Enum_T& other)
62
- {
63
- return self == other;
64
- });
72
+ {
73
+ return self == other;
74
+ });
65
75
 
66
76
  // Add aliases
67
77
  rb_define_alias(klass, "===", "eql?");
78
+ rb_define_alias(klass, "to_i", "to_int");
68
79
 
69
80
  // Add comparable support
70
81
  klass.include_module(rb_mComparable)
71
82
  .define_method("<=>", [](Enum_T& self, Enum_T& other)
72
- {
73
- if (self == other)
74
- {
75
- return 0;
76
- }
77
- else if (self < other)
78
83
  {
79
- return -1;
80
- }
81
- else
82
- {
83
- return 1;
84
- }
85
- });
84
+ if (self == other)
85
+ {
86
+ return 0;
87
+ }
88
+ else if (self < other)
89
+ {
90
+ return -1;
91
+ }
92
+ else
93
+ {
94
+ return 1;
95
+ }
96
+ });
86
97
 
87
98
  // Add enumerable support
88
99
  klass.include_module(rb_mEnumerable)
@@ -91,7 +102,7 @@ namespace Rice
91
102
  if (!rb_block_given_p())
92
103
  {
93
104
  return rb_enumeratorize_with_size(ruby_klass, Identifier("each").to_sym(),
94
- 0, nullptr, 0);
105
+ 0, nullptr, 0);
95
106
  }
96
107
 
97
108
  for (auto& pair : valuesToNames_)
@@ -102,22 +113,58 @@ namespace Rice
102
113
  }
103
114
 
104
115
  return ruby_klass;
105
- }, Return().setValue())
106
- .define_singleton_method("from_int", [](VALUE ruby_klass, int32_t value) -> Object
116
+ }, Return().setValue());
117
+
118
+ // Add bitwise operators
119
+ klass.define_method("&", [](Enum_T& self, Enum_T& other) -> Underlying_T
107
120
  {
108
- auto iter = Enum<Enum_T>::valuesToNames_.find((Enum_T)value);
109
- if (iter == Enum<Enum_T>::valuesToNames_.end())
110
- {
111
- throw std::runtime_error("Unknown enum value: " + std::to_string(value));
112
- }
121
+ return (Underlying_T)self & (Underlying_T)other;
122
+ })
123
+ .define_method("|", [](Enum_T& self, Enum_T& other) -> Underlying_T
124
+ {
125
+ return (Underlying_T)self | (Underlying_T)other;
126
+ })
127
+ .define_method("^", [](Enum_T& self, Enum_T& other) -> Underlying_T
128
+ {
129
+ return (Underlying_T)self ^ (Underlying_T)other;
130
+ })
131
+ .define_method("~", [](Enum_T& self) -> Underlying_T
132
+ {
133
+ return ~(Underlying_T)self;
134
+ });
113
135
 
114
- std::string name = iter->second;
115
- return Object(ruby_klass).const_get(name);
136
+ // Add shift operators
137
+ klass.define_method("<<", [](Enum_T& self, int shift) -> Underlying_T
138
+ {
139
+ return (Underlying_T)self << shift;
140
+ })
141
+ .define_method(">>", [](Enum_T& self, int shift) -> Underlying_T
142
+ {
143
+ return (Underlying_T)self >> shift;
116
144
  });
145
+
146
+ // Add conversions from int
147
+ klass.define_singleton_method("from_int", [](VALUE ruby_klass, int32_t value) -> Object
148
+ {
149
+ auto iter = Enum<Enum_T>::valuesToNames_.find((Enum_T)value);
150
+ if (iter == Enum<Enum_T>::valuesToNames_.end())
151
+ {
152
+ throw std::runtime_error("Unknown enum value: " + std::to_string(value));
153
+ }
154
+
155
+ std::string name = iter->second;
156
+ return Object(ruby_klass).const_get(name);
157
+ });
158
+ }
159
+
160
+ template<typename Enum_T>
161
+ Enum<Enum_T> define_enum(char const* name)
162
+ {
163
+ return define_enum_under<Enum_T>(name, rb_cObject);
117
164
  }
118
165
 
119
166
  template<typename Enum_T>
120
- Enum<Enum_T> define_enum(char const* name, Module module)
167
+ Enum<Enum_T> define_enum_under(char const* name, Module module)
121
168
  {
122
169
  if (detail::Registries::instance.types.isDefined<Enum_T>())
123
170
  {
data/rice/Exception.hpp CHANGED
@@ -1,7 +1,67 @@
1
1
  #ifndef Rice__Exception__hpp_
2
2
  #define Rice__Exception__hpp_
3
3
 
4
- #include "Exception_defn.hpp"
5
- #include "Exception.ipp"
4
+ #include <stdexcept>
5
+
6
+ namespace Rice
7
+ {
8
+ //! A placeholder for Ruby exceptions.
9
+ /*! You can use this to safely throw a Ruby exception using C++ syntax:
10
+ * \code
11
+ * VALUE foo(VALUE self) {
12
+ * RUBY_TRY {
13
+ * throw Rice::Exception(rb_eMyException, "uh oh!");
14
+ * RUBY_CATCH
15
+ * }
16
+ * \endcode
17
+ */
18
+ class Exception
19
+ : public std::exception
20
+ {
21
+ public:
22
+ //! Construct a Exception with a Ruby exception instance
23
+ explicit Exception(VALUE exception);
24
+
25
+ //! Construct a Exception with printf-style formatting.
26
+ /*! \param exc either an exception object or a class that inherits
27
+ * from Exception.
28
+ * \param fmt a printf-style format string
29
+ * \param ... the arguments to the format string.
30
+ */
31
+ template <typename... Arg_Ts>
32
+ Exception(const Exception& other, char const* fmt, Arg_Ts&&...args);
33
+
34
+ //! Construct a Exception with printf-style formatting.
35
+ /*! \param exc either an exception object or a class that inherits
36
+ * from Exception.
37
+ * \param fmt a printf-style format string
38
+ * \param ... the arguments to the format string.
39
+ */
40
+ template <typename... Arg_Ts>
41
+ Exception(const VALUE exceptionType, char const* fmt, Arg_Ts&&...args);
42
+
43
+ //! Destructor
44
+ virtual ~Exception() noexcept = default;
45
+
46
+ //! Get message as a char const *.
47
+ /*! If message is a non-string object, then this function will attempt
48
+ * to throw an exception (which it can't do because of the no-throw
49
+ * specification).
50
+ * \return the underlying C pointer of the underlying message object.
51
+ */
52
+ virtual char const* what() const noexcept override;
53
+
54
+ //! Returns the Ruby exception class
55
+ VALUE class_of() const;
56
+
57
+ //! Returns an instance of a Ruby exception
58
+ VALUE value() const;
59
+
60
+ private:
61
+ // TODO: Do we need to tell the Ruby gc about an exception instance?
62
+ mutable VALUE exception_ = Qnil;
63
+ mutable std::string message_;
64
+ };
65
+ } // namespace Rice
6
66
 
7
67
  #endif // Rice__Exception__hpp_
data/rice/Exception.ipp CHANGED
@@ -1,7 +1,3 @@
1
- #ifndef Rice__Exception__ipp_
2
- #define Rice__Exception__ipp_
3
-
4
- #include "detail/from_ruby.hpp"
5
1
 
6
2
  namespace Rice
7
3
  {
@@ -18,10 +14,10 @@ namespace Rice
18
14
  template <typename... Arg_Ts>
19
15
  inline Exception::Exception(const VALUE exceptionClass, char const* fmt, Arg_Ts&&...args)
20
16
  {
21
- #ifdef __GNUC__
22
- #pragma GCC diagnostic push
23
- #pragma GCC diagnostic ignored "-Wformat-security"
24
- #endif
17
+ #if defined(__GNUC__) || defined(__clang__)
18
+ #pragma GCC diagnostic push
19
+ #pragma GCC diagnostic ignored "-Wformat-security"
20
+ #endif
25
21
 
26
22
  size_t size = std::snprintf(nullptr, 0, fmt, std::forward<Arg_Ts>(args)...);
27
23
  this->message_ = std::string(size, '\0');
@@ -31,9 +27,9 @@ namespace Rice
31
27
  // will add a null character internally at n + 1
32
28
  std::snprintf(&this->message_[0], size + 1, fmt, std::forward<Arg_Ts>(args)...);
33
29
 
34
- #ifdef __GNUC__
35
- #pragma GCC diagnostic pop
36
- #endif
30
+ #if defined(__GNUC__) || defined(__clang__)
31
+ #pragma GCC diagnostic pop
32
+ #endif
37
33
 
38
34
  // Now create the Ruby exception
39
35
  this->exception_ = detail::protect(rb_exc_new2, exceptionClass, this->message_.c_str());
@@ -61,4 +57,3 @@ namespace Rice
61
57
  return this->exception_;
62
58
  }
63
59
  }
64
- #endif // Rice__Exception__ipp_
data/rice/Init.hpp ADDED
@@ -0,0 +1,8 @@
1
+ #ifndef Rice__Init__hpp_
2
+ #define Rice__Init__hpp_
3
+
4
+ namespace Rice
5
+ {
6
+ void init();
7
+ }
8
+ #endif // Rice__Init__hpp_
data/rice/Init.ipp ADDED
@@ -0,0 +1,8 @@
1
+ namespace Rice
2
+ {
3
+ inline void init()
4
+ {
5
+ detail::define_ruby_types();
6
+ define_fundamental_buffer_types();
7
+ };
8
+ }
@@ -0,0 +1,44 @@
1
+ #ifndef Rice__JumpException__hpp_
2
+ #define Rice__JumpException__hpp_
3
+
4
+ namespace Rice
5
+ {
6
+ //! A placeholder for Ruby longjmp data.
7
+ /*! When a Ruby exception is caught, the tag used for the longjmp is stored in
8
+ * a Jump_Tag, then later passed to rb_jump_tag() when there is no more
9
+ * C++ code to pass over.
10
+ */
11
+ class JumpException : public std::exception
12
+ {
13
+ public:
14
+ // Copied from vm_core.h
15
+ enum ruby_tag_type {
16
+ RUBY_TAG_NONE = 0x0,
17
+ RUBY_TAG_RETURN = 0x1,
18
+ RUBY_TAG_BREAK = 0x2,
19
+ RUBY_TAG_NEXT = 0x3,
20
+ RUBY_TAG_RETRY = 0x4,
21
+ RUBY_TAG_REDO = 0x5,
22
+ RUBY_TAG_RAISE = 0x6,
23
+ RUBY_TAG_THROW = 0x7,
24
+ RUBY_TAG_FATAL = 0x8,
25
+ RUBY_TAG_MASK = 0xf
26
+ };
27
+
28
+ public:
29
+ JumpException(ruby_tag_type tag);
30
+ virtual const char* what() const noexcept override;
31
+
32
+ public:
33
+ //! The tag being held.
34
+ ruby_tag_type tag;
35
+
36
+ private:
37
+ void createMessage();
38
+
39
+ private:
40
+ std::string message_;
41
+ };
42
+ } // namespace Rice
43
+
44
+ #endif // Rice__JumpException__hpp_
@@ -0,0 +1,48 @@
1
+ namespace Rice
2
+ {
3
+ inline JumpException::JumpException(ruby_tag_type tag) : tag(tag)
4
+ {
5
+ this->createMessage();
6
+ }
7
+
8
+ inline const char* JumpException::what() const noexcept
9
+ {
10
+ return this->message_.c_str();
11
+ }
12
+
13
+ inline void JumpException::createMessage()
14
+ {
15
+ switch (this->tag)
16
+ {
17
+ case RUBY_TAG_NONE:
18
+ this->message_ = "No error";
19
+ break;
20
+ case RUBY_TAG_RETURN:
21
+ this->message_ = "Unexpected return";
22
+ break;
23
+ case RUBY_TAG_NEXT:
24
+ this->message_ = "Unexpected next";
25
+ break;
26
+ case RUBY_TAG_BREAK:
27
+ this->message_ = "Unexpected break";
28
+ break;
29
+ case RUBY_TAG_REDO:
30
+ this->message_ = "Unexpected redo";
31
+ break;
32
+ case RUBY_TAG_RETRY:
33
+ this->message_ = "Retry outside of rescue clause";
34
+ break;
35
+ case RUBY_TAG_THROW:
36
+ this->message_ = "Unexpected throw";
37
+ case RUBY_TAG_RAISE:
38
+ this->message_ = "Ruby exception was thrown";
39
+ break;
40
+ case RUBY_TAG_FATAL:
41
+ this->message_ = "Fatal error";
42
+ break;
43
+ case RUBY_TAG_MASK:
44
+ this->message_ = "Mask error";
45
+ break;
46
+ }
47
+ }
48
+ } // namespace Rice
@@ -0,0 +1,11 @@
1
+ #ifndef Rice__MemoryView__hpp_
2
+ #define Rice__MemoryView__hpp_
3
+
4
+ namespace Rice
5
+ {
6
+ class MemoryView
7
+ {
8
+ };
9
+ }
10
+
11
+ #endif // Rice__MemoryView__hpp_
@@ -0,0 +1,3 @@
1
+ namespace Rice
2
+ {
3
+ }
data/rice/Return.hpp CHANGED
@@ -1,40 +1,20 @@
1
1
  #ifndef Rice__Return__hpp_
2
2
  #define Rice__Return__hpp_
3
3
 
4
- #include <any>
5
-
6
4
  namespace Rice
7
5
  {
8
6
  //! Helper for defining Return argument of a method
9
7
 
10
- class Return
8
+ class Return: public Arg
11
9
  {
12
10
  public:
13
- //! Specifies Ruby should take ownership of the returned value
14
- Return& takeOwnership();
15
-
16
- //! Does Ruby own the returned value?
17
- bool isOwner();
18
-
19
- //! Specifies the returned value is a Ruby value
20
- Return& setValue();
21
-
22
- //! Is the returned value a Ruby value?
23
- bool isValue() const;
24
-
25
- //! Tell the returned object to keep alive the receving object
26
- Return& keepAlive();
27
-
28
- //! Is the returned value being kept alive?
29
- bool isKeepAlive() const;
30
-
31
- private:
32
- bool isKeepAlive_ = false;
33
- bool isOwner_ = false;
34
- bool isValue_ = false;
11
+ Return();
12
+ Return& keepAlive() override;
13
+ Return& setValue() override;
14
+ Return& setOpaque() override;
15
+ Return& takeOwnership() override;
16
+ Return& setArray() override;
35
17
  };
36
18
  } // Rice
37
19
 
38
- #include "Return.ipp"
39
-
40
20
  #endif // Rice__Return__hpp_
data/rice/Return.ipp CHANGED
@@ -1,38 +1,38 @@
1
1
  #include <any>
2
- #include <string>
3
2
 
4
3
  namespace Rice
5
4
  {
6
- inline Return& Return::takeOwnership()
5
+ inline Return::Return(): Arg("Return")
7
6
  {
8
- this->isOwner_ = true;
9
- return *this;
10
7
  }
11
8
 
12
- inline bool Return::isOwner()
9
+ inline Return& Return::keepAlive()
13
10
  {
14
- return this->isOwner_;
11
+ Arg::keepAlive();
12
+ return *this;
15
13
  }
16
14
 
17
15
  inline Return& Return::setValue()
18
16
  {
19
- this->isValue_ = true;
17
+ Arg::setValue();
20
18
  return *this;
21
19
  }
22
20
 
23
- inline bool Return::isValue() const
21
+ inline Return& Return::setOpaque()
24
22
  {
25
- return this->isValue_;
23
+ Arg::setOpaque();
24
+ return *this;
26
25
  }
27
26
 
28
- inline Return& Return::keepAlive()
27
+ inline Return& Return::takeOwnership()
29
28
  {
30
- this->isKeepAlive_ = true;
29
+ Arg::takeOwnership();
31
30
  return *this;
32
31
  }
33
32
 
34
- inline bool Return::isKeepAlive() const
33
+ inline Return& Return::setArray()
35
34
  {
36
- return this->isKeepAlive_;
35
+ Arg::setArray();
36
+ return *this;
37
37
  }
38
38
  } // Rice