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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +86 -26
- data/CMakeLists.txt +31 -0
- data/CMakePresets.json +75 -0
- data/COPYING +3 -2
- data/FindRuby.cmake +437 -0
- data/README.md +7 -2
- data/Rakefile +12 -5
- data/include/rice/rice.hpp +9522 -4426
- data/include/rice/stl.hpp +2831 -1198
- data/lib/make_rice_headers.rb +79 -0
- data/lib/mkmf-rice.rb +40 -94
- data/lib/rice/version.rb +3 -0
- data/lib/rice.rb +1 -0
- data/lib/rubygems/builder.rb +11 -0
- data/lib/rubygems/cmake_builder.rb +113 -0
- data/lib/rubygems_plugin.rb +9 -0
- data/rice/Address_Registration_Guard.hpp +72 -3
- data/rice/Arg.hpp +26 -6
- data/rice/Arg.ipp +35 -2
- data/rice/Buffer.hpp +123 -0
- data/rice/Buffer.ipp +599 -0
- data/rice/Callback.hpp +21 -0
- data/rice/Callback.ipp +13 -0
- data/rice/Constructor.hpp +4 -27
- data/rice/Constructor.ipp +79 -0
- data/rice/Data_Object.hpp +73 -3
- data/rice/Data_Object.ipp +388 -96
- data/rice/Data_Type.hpp +214 -3
- data/rice/Data_Type.ipp +144 -67
- data/rice/Director.hpp +0 -2
- data/rice/Enum.hpp +4 -7
- data/rice/Enum.ipp +102 -55
- data/rice/Exception.hpp +62 -2
- data/rice/Exception.ipp +7 -12
- data/rice/Init.hpp +8 -0
- data/rice/Init.ipp +8 -0
- data/rice/JumpException.hpp +44 -0
- data/rice/JumpException.ipp +48 -0
- data/rice/MemoryView.hpp +11 -0
- data/rice/MemoryView.ipp +3 -0
- data/rice/Return.hpp +7 -27
- data/rice/Return.ipp +13 -13
- data/rice/cpp_api/Array.hpp +209 -0
- data/rice/cpp_api/Array.ipp +304 -0
- data/rice/cpp_api/Builtin_Object.hpp +31 -0
- data/rice/cpp_api/Builtin_Object.ipp +37 -0
- data/rice/cpp_api/Class.hpp +70 -0
- data/rice/cpp_api/Class.ipp +97 -0
- data/rice/cpp_api/Encoding.hpp +32 -0
- data/rice/cpp_api/Encoding.ipp +59 -0
- data/rice/cpp_api/Hash.hpp +194 -0
- data/rice/cpp_api/Hash.ipp +257 -0
- data/rice/{Identifier.hpp → cpp_api/Identifier.hpp} +2 -6
- data/rice/{Identifier.ipp → cpp_api/Identifier.ipp} +4 -2
- data/rice/cpp_api/Module.hpp +72 -0
- data/rice/cpp_api/Module.ipp +101 -0
- data/rice/cpp_api/Object.hpp +272 -0
- data/rice/cpp_api/Object.ipp +235 -0
- data/rice/cpp_api/String.hpp +74 -0
- data/rice/cpp_api/String.ipp +120 -0
- data/rice/cpp_api/Struct.hpp +113 -0
- data/rice/cpp_api/Struct.ipp +92 -0
- data/rice/cpp_api/Symbol.hpp +46 -0
- data/rice/cpp_api/Symbol.ipp +93 -0
- data/rice/cpp_api/shared_methods.hpp +134 -0
- data/rice/detail/DefaultHandler.hpp +12 -0
- data/rice/detail/DefaultHandler.ipp +8 -0
- data/rice/detail/HandlerRegistry.hpp +5 -35
- data/rice/detail/HandlerRegistry.ipp +7 -11
- data/rice/detail/InstanceRegistry.hpp +1 -4
- data/rice/detail/MethodInfo.hpp +12 -10
- data/rice/detail/MethodInfo.ipp +26 -21
- data/rice/detail/Native.hpp +33 -0
- data/rice/detail/Native.ipp +157 -0
- data/rice/detail/NativeAttributeGet.hpp +52 -0
- data/rice/detail/NativeAttributeGet.ipp +57 -0
- data/rice/detail/NativeAttributeSet.hpp +44 -0
- data/rice/detail/NativeAttributeSet.ipp +88 -0
- data/rice/detail/NativeCallbackFFI.hpp +55 -0
- data/rice/detail/NativeCallbackFFI.ipp +151 -0
- data/rice/detail/NativeCallbackSimple.hpp +30 -0
- data/rice/detail/NativeCallbackSimple.ipp +29 -0
- data/rice/detail/NativeFunction.hpp +33 -23
- data/rice/detail/NativeFunction.ipp +309 -70
- data/rice/detail/NativeIterator.hpp +9 -11
- data/rice/detail/NativeIterator.ipp +33 -31
- data/rice/detail/NativeRegistry.hpp +24 -15
- data/rice/detail/NativeRegistry.ipp +23 -48
- data/rice/detail/Proc.hpp +4 -0
- data/rice/detail/Proc.ipp +85 -0
- data/rice/detail/Registries.hpp +0 -7
- data/rice/detail/Registries.ipp +0 -18
- data/rice/detail/RubyFunction.hpp +0 -3
- data/rice/detail/RubyFunction.ipp +4 -8
- data/rice/detail/RubyType.hpp +16 -0
- data/rice/detail/RubyType.ipp +232 -0
- data/rice/detail/Type.hpp +7 -6
- data/rice/detail/Type.ipp +192 -45
- data/rice/detail/TypeRegistry.hpp +15 -7
- data/rice/detail/TypeRegistry.ipp +105 -12
- data/rice/detail/Wrapper.hpp +68 -32
- data/rice/detail/Wrapper.ipp +121 -109
- data/rice/detail/cpp_protect.hpp +5 -6
- data/rice/detail/default_allocation_func.ipp +0 -2
- data/rice/detail/from_ruby.hpp +38 -3
- data/rice/detail/from_ruby.ipp +1321 -492
- data/rice/detail/ruby.hpp +18 -0
- data/rice/detail/to_ruby.hpp +41 -3
- data/rice/detail/to_ruby.ipp +1424 -194
- data/rice/global_function.hpp +0 -4
- data/rice/global_function.ipp +0 -1
- data/rice/libc/file.hpp +11 -0
- data/rice/libc/file.ipp +32 -0
- data/rice/rice.hpp +116 -26
- data/rice/ruby_mark.hpp +4 -3
- data/rice/stl/complex.hpp +6 -0
- data/rice/stl/complex.ipp +93 -0
- data/rice/stl/exception.hpp +11 -0
- data/rice/stl/exception.ipp +29 -0
- data/rice/stl/exception_ptr.hpp +6 -0
- data/rice/stl/exception_ptr.ipp +27 -0
- data/rice/stl/map.hpp +12 -0
- data/rice/stl/map.ipp +469 -0
- data/rice/stl/monostate.hpp +6 -0
- data/rice/stl/monostate.ipp +80 -0
- data/rice/stl/multimap.hpp +14 -0
- data/rice/stl/multimap.ipp +448 -0
- data/rice/stl/optional.hpp +6 -0
- data/rice/stl/optional.ipp +118 -0
- data/rice/stl/pair.hpp +13 -0
- data/rice/stl/pair.ipp +155 -0
- data/rice/stl/reference_wrapper.hpp +6 -0
- data/rice/stl/reference_wrapper.ipp +41 -0
- data/rice/stl/set.hpp +12 -0
- data/rice/stl/set.ipp +495 -0
- data/rice/stl/shared_ptr.hpp +28 -0
- data/rice/stl/shared_ptr.ipp +224 -0
- data/rice/stl/string.hpp +6 -0
- data/rice/stl/string.ipp +158 -0
- data/rice/stl/string_view.hpp +6 -0
- data/rice/stl/string_view.ipp +65 -0
- data/rice/stl/tuple.hpp +6 -0
- data/rice/stl/tuple.ipp +128 -0
- data/rice/stl/type_index.hpp +6 -0
- data/rice/stl/type_index.ipp +30 -0
- data/rice/stl/type_info.hpp +6 -0
- data/rice/stl/type_info.ipp +29 -0
- data/rice/stl/unique_ptr.hpp +22 -0
- data/rice/stl/unique_ptr.ipp +139 -0
- data/rice/stl/unordered_map.hpp +12 -0
- data/rice/stl/unordered_map.ipp +469 -0
- data/rice/stl/variant.hpp +6 -0
- data/rice/stl/variant.ipp +242 -0
- data/rice/stl/vector.hpp +12 -0
- data/rice/stl/vector.ipp +590 -0
- data/rice/stl.hpp +11 -3
- data/rice/traits/attribute_traits.hpp +26 -0
- data/rice/traits/function_traits.hpp +95 -0
- data/rice/traits/method_traits.hpp +47 -0
- data/rice/traits/rice_traits.hpp +160 -0
- data/rice.gemspec +85 -0
- data/test/embed_ruby.cpp +7 -1
- data/test/extconf.rb +2 -0
- data/test/test_Address_Registration_Guard.cpp +5 -0
- data/test/test_Array.cpp +18 -4
- data/test/test_Attribute.cpp +136 -21
- data/test/test_Buffer.cpp +285 -0
- data/test/test_Builtin_Object.cpp +5 -0
- data/test/test_Callback.cpp +230 -0
- data/test/test_Class.cpp +5 -31
- data/test/test_Constructor.cpp +69 -6
- data/test/test_Data_Object.cpp +97 -38
- data/test/test_Data_Type.cpp +470 -65
- data/test/test_Director.cpp +17 -8
- data/test/test_Enum.cpp +155 -40
- data/test/test_Exception.cpp +235 -0
- data/test/test_File.cpp +70 -0
- data/test/test_From_Ruby.cpp +609 -0
- data/test/test_Hash.cpp +5 -0
- data/test/test_Identifier.cpp +5 -0
- data/test/test_Inheritance.cpp +6 -1
- data/test/test_Iterator.cpp +6 -1
- data/test/test_Jump_Exception.cpp +23 -0
- data/test/test_Keep_Alive.cpp +13 -19
- data/test/test_Keep_Alive_No_Wrapper.cpp +5 -1
- data/test/test_Memory_Management.cpp +5 -0
- data/test/test_Module.cpp +128 -67
- data/test/test_Native_Registry.cpp +2 -34
- data/test/test_Object.cpp +5 -0
- data/test/test_Overloads.cpp +806 -0
- data/test/test_Ownership.cpp +160 -54
- data/test/test_Proc.cpp +44 -0
- data/test/test_Self.cpp +9 -4
- data/test/test_Stl_Exception.cpp +109 -0
- data/test/test_Stl_Map.cpp +54 -42
- data/test/test_Stl_Multimap.cpp +693 -0
- data/test/test_Stl_Optional.cpp +5 -0
- data/test/test_Stl_Pair.cpp +14 -9
- data/test/test_Stl_Reference_Wrapper.cpp +9 -2
- data/test/test_Stl_Set.cpp +790 -0
- data/test/test_Stl_SharedPtr.cpp +458 -0
- data/test/test_Stl_String.cpp +5 -0
- data/test/test_Stl_String_View.cpp +5 -0
- data/test/test_Stl_Tuple.cpp +116 -0
- data/test/test_Stl_Type.cpp +147 -0
- data/test/test_Stl_UniquePtr.cpp +202 -0
- data/test/test_Stl_Unordered_Map.cpp +43 -38
- data/test/test_Stl_Variant.cpp +217 -84
- data/test/test_Stl_Vector.cpp +306 -58
- data/test/test_String.cpp +5 -0
- data/test/test_Struct.cpp +5 -0
- data/test/test_Symbol.cpp +5 -0
- data/test/test_Template.cpp +192 -0
- data/test/test_To_Ruby.cpp +524 -0
- data/test/test_Tracking.cpp +1 -0
- data/test/test_Type.cpp +171 -0
- data/test/test_global_functions.cpp +67 -7
- data/test/unittest.cpp +8 -0
- metadata +127 -26
- data/lib/version.rb +0 -3
- data/rice/Address_Registration_Guard_defn.hpp +0 -79
- data/rice/Data_Object_defn.hpp +0 -84
- data/rice/Data_Type_defn.hpp +0 -190
- data/rice/Exception_defn.hpp +0 -68
- data/rice/HandlerRegistration.hpp +0 -15
- data/rice/detail/ExceptionHandler.hpp +0 -8
- data/rice/detail/ExceptionHandler.ipp +0 -28
- data/rice/detail/ExceptionHandler_defn.hpp +0 -77
- data/rice/detail/Jump_Tag.hpp +0 -21
- data/rice/detail/NativeAttribute.hpp +0 -64
- data/rice/detail/NativeAttribute.ipp +0 -112
- data/rice/detail/from_ruby_defn.hpp +0 -38
- data/rice/detail/to_ruby_defn.hpp +0 -48
- data/test/test_Jump_Tag.cpp +0 -17
- data/test/test_Stl_SmartPointer.cpp +0 -283
- 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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
-
|
60
|
-
|
68
|
+
{
|
69
|
+
return (Underlying_T)self;
|
70
|
+
})
|
61
71
|
.define_method("eql?", [](Enum_T& self, Enum_T& other)
|
62
|
-
|
63
|
-
|
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
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
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
|
-
|
106
|
-
|
116
|
+
}, Return().setValue());
|
117
|
+
|
118
|
+
// Add bitwise operators
|
119
|
+
klass.define_method("&", [](Enum_T& self, Enum_T& other) -> Underlying_T
|
107
120
|
{
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
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
|
-
|
115
|
-
|
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>
|
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
|
5
|
-
|
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
|
-
#
|
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
|
-
#
|
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
data/rice/Init.ipp
ADDED
@@ -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
|
data/rice/MemoryView.hpp
ADDED
data/rice/MemoryView.ipp
ADDED
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
|
-
|
14
|
-
Return&
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
5
|
+
inline Return::Return(): Arg("Return")
|
7
6
|
{
|
8
|
-
this->isOwner_ = true;
|
9
|
-
return *this;
|
10
7
|
}
|
11
8
|
|
12
|
-
inline
|
9
|
+
inline Return& Return::keepAlive()
|
13
10
|
{
|
14
|
-
|
11
|
+
Arg::keepAlive();
|
12
|
+
return *this;
|
15
13
|
}
|
16
14
|
|
17
15
|
inline Return& Return::setValue()
|
18
16
|
{
|
19
|
-
|
17
|
+
Arg::setValue();
|
20
18
|
return *this;
|
21
19
|
}
|
22
20
|
|
23
|
-
inline
|
21
|
+
inline Return& Return::setOpaque()
|
24
22
|
{
|
25
|
-
|
23
|
+
Arg::setOpaque();
|
24
|
+
return *this;
|
26
25
|
}
|
27
26
|
|
28
|
-
inline Return& Return::
|
27
|
+
inline Return& Return::takeOwnership()
|
29
28
|
{
|
30
|
-
|
29
|
+
Arg::takeOwnership();
|
31
30
|
return *this;
|
32
31
|
}
|
33
32
|
|
34
|
-
inline
|
33
|
+
inline Return& Return::setArray()
|
35
34
|
{
|
36
|
-
|
35
|
+
Arg::setArray();
|
36
|
+
return *this;
|
37
37
|
}
|
38
38
|
} // Rice
|