rice 4.5.0 → 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 +23 -0
- data/CMakeLists.txt +31 -0
- data/CMakePresets.json +75 -0
- data/COPYING +3 -2
- data/FindRuby.cmake +437 -0
- data/Rakefile +5 -4
- data/include/rice/rice.hpp +5436 -3201
- data/include/rice/stl.hpp +2355 -1269
- data/lib/make_rice_headers.rb +79 -0
- data/lib/mkmf-rice.rb +4 -0
- 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/Arg.hpp +7 -1
- data/rice/Arg.ipp +11 -2
- data/rice/Buffer.hpp +123 -0
- data/rice/Buffer.ipp +599 -0
- data/rice/Constructor.ipp +3 -3
- data/rice/Data_Object.hpp +2 -3
- data/rice/Data_Object.ipp +188 -188
- data/rice/Data_Type.hpp +4 -5
- data/rice/Data_Type.ipp +42 -26
- data/rice/Enum.hpp +0 -1
- data/rice/Enum.ipp +26 -23
- data/rice/Init.hpp +8 -0
- data/rice/Init.ipp +8 -0
- data/rice/MemoryView.ipp +1 -41
- data/rice/Return.hpp +1 -1
- data/rice/Return.ipp +6 -0
- 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/cpp_api/Identifier.hpp +46 -0
- data/rice/cpp_api/Identifier.ipp +31 -0
- 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/MethodInfo.hpp +1 -9
- data/rice/detail/MethodInfo.ipp +5 -72
- data/rice/detail/Native.hpp +3 -2
- data/rice/detail/Native.ipp +32 -4
- data/rice/detail/NativeAttributeGet.hpp +3 -2
- data/rice/detail/NativeAttributeGet.ipp +8 -2
- data/rice/detail/NativeAttributeSet.hpp +3 -2
- data/rice/detail/NativeAttributeSet.ipp +8 -2
- data/rice/detail/NativeCallbackFFI.ipp +1 -1
- data/rice/detail/NativeFunction.hpp +17 -6
- data/rice/detail/NativeFunction.ipp +168 -64
- data/rice/detail/NativeIterator.hpp +3 -2
- data/rice/detail/NativeIterator.ipp +8 -2
- data/rice/detail/RubyType.hpp +2 -5
- data/rice/detail/RubyType.ipp +50 -5
- data/rice/detail/Type.hpp +3 -1
- data/rice/detail/Type.ipp +61 -31
- data/rice/detail/Wrapper.hpp +68 -33
- data/rice/detail/Wrapper.ipp +103 -113
- data/rice/detail/from_ruby.hpp +5 -4
- data/rice/detail/from_ruby.ipp +737 -365
- data/rice/detail/to_ruby.ipp +1092 -186
- data/rice/global_function.ipp +1 -1
- data/rice/libc/file.hpp +11 -0
- data/rice/libc/file.ipp +32 -0
- data/rice/rice.hpp +23 -16
- 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 +7 -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 +3 -0
- data/test/ruby/test_multiple_extensions_same_class.rb +14 -14
- data/test/test_Array.cpp +6 -3
- data/test/test_Attribute.cpp +34 -1
- data/test/test_Buffer.cpp +285 -0
- data/test/test_Callback.cpp +2 -3
- data/test/test_Data_Object.cpp +88 -34
- data/test/test_Data_Type.cpp +106 -65
- data/test/test_Director.cpp +7 -3
- data/test/test_Enum.cpp +5 -2
- data/test/test_File.cpp +1 -1
- data/test/test_From_Ruby.cpp +181 -114
- data/test/test_Iterator.cpp +1 -1
- data/test/{test_JumpException.cpp → test_Jump_Exception.cpp} +1 -0
- data/test/test_Keep_Alive.cpp +7 -18
- data/test/test_Keep_Alive_No_Wrapper.cpp +0 -1
- data/test/test_Module.cpp +13 -6
- data/test/test_Native_Registry.cpp +0 -1
- data/test/test_Overloads.cpp +180 -5
- data/test/test_Ownership.cpp +100 -57
- data/test/test_Proc.cpp +0 -1
- data/test/test_Self.cpp +4 -4
- data/test/test_Stl_Map.cpp +37 -39
- data/test/test_Stl_Multimap.cpp +693 -0
- data/test/test_Stl_Pair.cpp +8 -8
- data/test/test_Stl_Reference_Wrapper.cpp +4 -2
- data/test/test_Stl_Set.cpp +790 -0
- data/test/{test_Stl_SmartPointer.cpp → test_Stl_SharedPtr.cpp} +97 -127
- data/test/test_Stl_Tuple.cpp +116 -0
- data/test/test_Stl_Type.cpp +1 -1
- data/test/test_Stl_UniquePtr.cpp +202 -0
- data/test/test_Stl_Unordered_Map.cpp +28 -34
- data/test/test_Stl_Variant.cpp +217 -89
- data/test/test_Stl_Vector.cpp +209 -83
- data/test/test_To_Ruby.cpp +373 -1
- data/test/test_Type.cpp +85 -14
- data/test/test_global_functions.cpp +17 -4
- metadata +94 -10
- data/rice/detail/TupleIterator.hpp +0 -14
data/rice/global_function.ipp
CHANGED
@@ -2,5 +2,5 @@
|
|
2
2
|
template<typename Function_T, typename...Arg_Ts>
|
3
3
|
void Rice::define_global_function(char const * name, Function_T&& func, Arg_Ts const& ...args)
|
4
4
|
{
|
5
|
-
|
5
|
+
Module(rb_mKernel).define_module_function(name, std::forward<Function_T>(func), args...);
|
6
6
|
}
|
data/rice/libc/file.hpp
ADDED
data/rice/libc/file.ipp
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#include <exception>
|
2
|
+
|
3
|
+
// Libraries sometime inherit custom exception objects from std::exception,
|
4
|
+
// so define it for Ruby if necessary
|
5
|
+
namespace Rice::libc
|
6
|
+
{
|
7
|
+
inline Class rb_cLibcFile;
|
8
|
+
|
9
|
+
inline void define_libc_file()
|
10
|
+
{
|
11
|
+
Module rb_mRice = define_module("Rice");
|
12
|
+
Module rb_mLibc = define_module_under(rb_mRice, "libc");
|
13
|
+
rb_cLibcFile = define_class_under<FILE>(rb_mLibc, "File");
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
namespace Rice::detail
|
18
|
+
{
|
19
|
+
template<>
|
20
|
+
struct Type<FILE>
|
21
|
+
{
|
22
|
+
static bool verify()
|
23
|
+
{
|
24
|
+
if (!Data_Type<FILE>::is_defined())
|
25
|
+
{
|
26
|
+
libc::define_libc_file();
|
27
|
+
}
|
28
|
+
|
29
|
+
return true;
|
30
|
+
}
|
31
|
+
};
|
32
|
+
}
|
data/rice/rice.hpp
CHANGED
@@ -21,15 +21,19 @@
|
|
21
21
|
#include "traits/method_traits.hpp"
|
22
22
|
#include "traits/attribute_traits.hpp"
|
23
23
|
|
24
|
-
// Helpers
|
25
|
-
#include "detail/TupleIterator.hpp"
|
26
|
-
|
27
24
|
// Code for C++ to call Ruby
|
28
25
|
#include "Exception.hpp"
|
29
26
|
#include "JumpException.hpp"
|
30
27
|
#include "JumpException.ipp"
|
31
28
|
#include "detail/RubyFunction.hpp"
|
32
29
|
#include "detail/RubyFunction.ipp"
|
30
|
+
#include "detail/to_ruby.hpp"
|
31
|
+
|
32
|
+
// Code for Ruby to call C++
|
33
|
+
#include "Arg.hpp"
|
34
|
+
#include "Return.hpp"
|
35
|
+
#include "detail/MethodInfo.hpp"
|
36
|
+
#include "detail/from_ruby.hpp"
|
33
37
|
|
34
38
|
// C++ API declarations
|
35
39
|
#include "detail/Type.hpp"
|
@@ -43,13 +47,19 @@
|
|
43
47
|
#include "cpp_api/Array.hpp"
|
44
48
|
#include "cpp_api/Hash.hpp"
|
45
49
|
|
50
|
+
#include "cpp_api/Module.hpp"
|
51
|
+
#include "cpp_api/Class.hpp"
|
52
|
+
|
53
|
+
#include "detail/Native.hpp"
|
54
|
+
#include "detail/NativeAttributeGet.hpp"
|
55
|
+
#include "detail/NativeAttributeSet.hpp"
|
56
|
+
#include "Data_Type.hpp"
|
57
|
+
#include "Data_Object.hpp"
|
58
|
+
|
46
59
|
// Type Conversion declarations
|
47
60
|
#include "detail/RubyType.hpp"
|
48
61
|
#include "detail/RubyType.ipp"
|
49
62
|
#include "detail/Wrapper.hpp"
|
50
|
-
#include "detail/to_ruby.hpp"
|
51
|
-
#include "detail/from_ruby.hpp"
|
52
|
-
#include "detail/Native.hpp"
|
53
63
|
|
54
64
|
// Registries
|
55
65
|
#include "detail/TypeRegistry.hpp"
|
@@ -60,10 +70,11 @@
|
|
60
70
|
#include "detail/Registries.hpp"
|
61
71
|
|
62
72
|
// To / From Ruby
|
63
|
-
#include "Arg.hpp"
|
64
73
|
#include "Arg.ipp"
|
65
|
-
#include "Return.hpp"
|
66
74
|
#include "Return.ipp"
|
75
|
+
#include "Constructor.hpp"
|
76
|
+
#include "Buffer.hpp"
|
77
|
+
#include "Buffer.ipp"
|
67
78
|
#include "detail/to_ruby.ipp"
|
68
79
|
#include "detail/from_ruby.ipp"
|
69
80
|
#include "detail/Proc.hpp"
|
@@ -82,12 +93,9 @@
|
|
82
93
|
#include "Exception.ipp"
|
83
94
|
#include "detail/cpp_protect.hpp"
|
84
95
|
#include "detail/Wrapper.ipp"
|
85
|
-
#include "detail/MethodInfo.hpp"
|
86
96
|
#include "detail/MethodInfo.ipp"
|
87
97
|
#include "detail/Native.ipp"
|
88
|
-
#include "detail/NativeAttributeGet.hpp"
|
89
98
|
#include "detail/NativeAttributeGet.ipp"
|
90
|
-
#include "detail/NativeAttributeSet.hpp"
|
91
99
|
#include "detail/NativeAttributeSet.ipp"
|
92
100
|
#include "detail/NativeFunction.hpp"
|
93
101
|
#include "detail/NativeFunction.ipp"
|
@@ -108,9 +116,7 @@
|
|
108
116
|
#include "cpp_api/Hash.ipp"
|
109
117
|
#include "cpp_api/Symbol.ipp"
|
110
118
|
|
111
|
-
#include "cpp_api/Module.hpp"
|
112
119
|
#include "cpp_api/Module.ipp"
|
113
|
-
#include "cpp_api/Class.hpp"
|
114
120
|
#include "cpp_api/Class.ipp"
|
115
121
|
#include "cpp_api/Struct.hpp"
|
116
122
|
#include "cpp_api/Struct.ipp"
|
@@ -124,14 +130,11 @@
|
|
124
130
|
#include "ruby_mark.hpp"
|
125
131
|
#include "detail/default_allocation_func.hpp"
|
126
132
|
#include "Director.hpp"
|
127
|
-
#include "Data_Type.hpp"
|
128
133
|
#include "Data_Type.ipp"
|
129
134
|
#include "detail/default_allocation_func.ipp"
|
130
|
-
#include "Constructor.hpp"
|
131
135
|
#include "Constructor.ipp"
|
132
136
|
#include "Callback.hpp"
|
133
137
|
#include "Callback.ipp"
|
134
|
-
#include "Data_Object.hpp"
|
135
138
|
#include "Data_Object.ipp"
|
136
139
|
#include "Enum.hpp"
|
137
140
|
#include "Enum.ipp"
|
@@ -144,4 +147,8 @@
|
|
144
147
|
// For now include libc support - maybe should be separate header file someday
|
145
148
|
#include "libc/file.hpp"
|
146
149
|
|
150
|
+
// Initialize Rice
|
151
|
+
#include "Init.hpp"
|
152
|
+
#include "Init.ipp"
|
153
|
+
|
147
154
|
#endif // Rice__hpp_
|
@@ -0,0 +1,93 @@
|
|
1
|
+
#include <complex>
|
2
|
+
|
3
|
+
namespace Rice::detail
|
4
|
+
{
|
5
|
+
template<typename T>
|
6
|
+
struct Type<std::complex<T>>
|
7
|
+
{
|
8
|
+
static bool verify()
|
9
|
+
{
|
10
|
+
return true;
|
11
|
+
}
|
12
|
+
};
|
13
|
+
|
14
|
+
template<typename T>
|
15
|
+
class To_Ruby<std::complex<T>>
|
16
|
+
{
|
17
|
+
public:
|
18
|
+
VALUE convert(const std::complex<T>& data)
|
19
|
+
{
|
20
|
+
std::vector<VALUE> args(2);
|
21
|
+
args[0] = To_Ruby<T>().convert(data.real());
|
22
|
+
args[1] = To_Ruby<T>().convert(data.imag());
|
23
|
+
return protect(rb_funcallv, rb_mKernel, rb_intern("Complex"), (int)args.size(), (const VALUE*)args.data());
|
24
|
+
}
|
25
|
+
};
|
26
|
+
|
27
|
+
template<typename T>
|
28
|
+
class To_Ruby<std::complex<T>&>
|
29
|
+
{
|
30
|
+
public:
|
31
|
+
VALUE convert(const std::complex<T>& data)
|
32
|
+
{
|
33
|
+
std::vector<VALUE> args(2);
|
34
|
+
args[0] = To_Ruby<T>().convert(data.real());
|
35
|
+
args[1] = To_Ruby<T>().convert(data.imag());
|
36
|
+
return protect(rb_funcallv, rb_mKernel, rb_intern("Complex"), (int)args.size(), (const VALUE*)args.data());
|
37
|
+
}
|
38
|
+
};
|
39
|
+
|
40
|
+
template<typename T>
|
41
|
+
class From_Ruby<std::complex<T>>
|
42
|
+
{
|
43
|
+
public:
|
44
|
+
Convertible is_convertible(VALUE value)
|
45
|
+
{
|
46
|
+
switch (rb_type(value))
|
47
|
+
{
|
48
|
+
case RUBY_T_COMPLEX:
|
49
|
+
return Convertible::Exact;
|
50
|
+
break;
|
51
|
+
default:
|
52
|
+
return Convertible::None;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
std::complex<T> convert(VALUE value)
|
57
|
+
{
|
58
|
+
VALUE real = protect(rb_funcallv, value, rb_intern("real"), 0, (const VALUE*)nullptr);
|
59
|
+
VALUE imaginary = protect(rb_funcallv, value, rb_intern("imaginary"), 0, (const VALUE*)nullptr);
|
60
|
+
|
61
|
+
return std::complex<T>(From_Ruby<T>().convert(real), From_Ruby<T>().convert(imaginary));
|
62
|
+
}
|
63
|
+
};
|
64
|
+
|
65
|
+
template<typename T>
|
66
|
+
class From_Ruby<std::complex<T>&>
|
67
|
+
{
|
68
|
+
public:
|
69
|
+
Convertible is_convertible(VALUE value)
|
70
|
+
{
|
71
|
+
switch (rb_type(value))
|
72
|
+
{
|
73
|
+
case RUBY_T_COMPLEX:
|
74
|
+
return Convertible::Exact;
|
75
|
+
break;
|
76
|
+
default:
|
77
|
+
return Convertible::None;
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
std::complex<T>& convert(VALUE value)
|
82
|
+
{
|
83
|
+
VALUE real = protect(rb_funcallv, value, rb_intern("real"), 0, (const VALUE*)nullptr);
|
84
|
+
VALUE imaginary = protect(rb_funcallv, value, rb_intern("imaginary"), 0, (const VALUE*)nullptr);
|
85
|
+
this->converted_ = std::complex<T>(From_Ruby<T>().convert(real), From_Ruby<T>().convert(imaginary));
|
86
|
+
|
87
|
+
return this->converted_;
|
88
|
+
}
|
89
|
+
|
90
|
+
private:
|
91
|
+
std::complex<T> converted_;
|
92
|
+
};
|
93
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#include <exception>
|
2
|
+
|
3
|
+
// Libraries sometime inherit custom exception objects from std::exception,
|
4
|
+
// so define it for Ruby if necessary
|
5
|
+
namespace Rice::stl
|
6
|
+
{
|
7
|
+
inline Class rb_cStlException;
|
8
|
+
|
9
|
+
inline void define_stl_exception()
|
10
|
+
{
|
11
|
+
Module rb_mStd = define_module("Std");
|
12
|
+
rb_cStlException = define_class_under<std::exception>(rb_mStd, "Exception", rb_eStandardError).
|
13
|
+
define_constructor(Constructor<std::exception>()).
|
14
|
+
define_method("message", &std::exception::what);
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
namespace Rice::detail
|
19
|
+
{
|
20
|
+
template<>
|
21
|
+
struct Type<std::exception>
|
22
|
+
{
|
23
|
+
static bool verify()
|
24
|
+
{
|
25
|
+
Rice::stl::define_stl_exception();
|
26
|
+
return true;
|
27
|
+
}
|
28
|
+
};
|
29
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#include <exception>
|
2
|
+
|
3
|
+
namespace Rice::stl
|
4
|
+
{
|
5
|
+
inline Data_Type<std::exception_ptr> define_exception_ptr()
|
6
|
+
{
|
7
|
+
Module rb_mStd = define_module("Std");
|
8
|
+
return define_class_under<std::exception_ptr>(rb_mStd, "ExceptionPtr");
|
9
|
+
}
|
10
|
+
}
|
11
|
+
|
12
|
+
namespace Rice::detail
|
13
|
+
{
|
14
|
+
template<>
|
15
|
+
struct Type<std::exception_ptr>
|
16
|
+
{
|
17
|
+
static bool verify()
|
18
|
+
{
|
19
|
+
if (!Data_Type<std::exception_ptr>::is_defined())
|
20
|
+
{
|
21
|
+
stl::define_exception_ptr();
|
22
|
+
}
|
23
|
+
|
24
|
+
return true;
|
25
|
+
}
|
26
|
+
};
|
27
|
+
}
|
data/rice/stl/map.hpp
ADDED