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.
Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -0
  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/Rakefile +5 -4
  8. data/include/rice/rice.hpp +5436 -3201
  9. data/include/rice/stl.hpp +2355 -1269
  10. data/lib/make_rice_headers.rb +79 -0
  11. data/lib/mkmf-rice.rb +4 -0
  12. data/lib/rice/version.rb +3 -0
  13. data/lib/rice.rb +1 -0
  14. data/lib/rubygems/builder.rb +11 -0
  15. data/lib/rubygems/cmake_builder.rb +113 -0
  16. data/lib/rubygems_plugin.rb +9 -0
  17. data/rice/Arg.hpp +7 -1
  18. data/rice/Arg.ipp +11 -2
  19. data/rice/Buffer.hpp +123 -0
  20. data/rice/Buffer.ipp +599 -0
  21. data/rice/Constructor.ipp +3 -3
  22. data/rice/Data_Object.hpp +2 -3
  23. data/rice/Data_Object.ipp +188 -188
  24. data/rice/Data_Type.hpp +4 -5
  25. data/rice/Data_Type.ipp +42 -26
  26. data/rice/Enum.hpp +0 -1
  27. data/rice/Enum.ipp +26 -23
  28. data/rice/Init.hpp +8 -0
  29. data/rice/Init.ipp +8 -0
  30. data/rice/MemoryView.ipp +1 -41
  31. data/rice/Return.hpp +1 -1
  32. data/rice/Return.ipp +6 -0
  33. data/rice/cpp_api/Array.hpp +209 -0
  34. data/rice/cpp_api/Array.ipp +304 -0
  35. data/rice/cpp_api/Builtin_Object.hpp +31 -0
  36. data/rice/cpp_api/Builtin_Object.ipp +37 -0
  37. data/rice/cpp_api/Class.hpp +70 -0
  38. data/rice/cpp_api/Class.ipp +97 -0
  39. data/rice/cpp_api/Encoding.hpp +32 -0
  40. data/rice/cpp_api/Encoding.ipp +59 -0
  41. data/rice/cpp_api/Hash.hpp +194 -0
  42. data/rice/cpp_api/Hash.ipp +257 -0
  43. data/rice/cpp_api/Identifier.hpp +46 -0
  44. data/rice/cpp_api/Identifier.ipp +31 -0
  45. data/rice/cpp_api/Module.hpp +72 -0
  46. data/rice/cpp_api/Module.ipp +101 -0
  47. data/rice/cpp_api/Object.hpp +272 -0
  48. data/rice/cpp_api/Object.ipp +235 -0
  49. data/rice/cpp_api/String.hpp +74 -0
  50. data/rice/cpp_api/String.ipp +120 -0
  51. data/rice/cpp_api/Struct.hpp +113 -0
  52. data/rice/cpp_api/Struct.ipp +92 -0
  53. data/rice/cpp_api/Symbol.hpp +46 -0
  54. data/rice/cpp_api/Symbol.ipp +93 -0
  55. data/rice/cpp_api/shared_methods.hpp +134 -0
  56. data/rice/detail/MethodInfo.hpp +1 -9
  57. data/rice/detail/MethodInfo.ipp +5 -72
  58. data/rice/detail/Native.hpp +3 -2
  59. data/rice/detail/Native.ipp +32 -4
  60. data/rice/detail/NativeAttributeGet.hpp +3 -2
  61. data/rice/detail/NativeAttributeGet.ipp +8 -2
  62. data/rice/detail/NativeAttributeSet.hpp +3 -2
  63. data/rice/detail/NativeAttributeSet.ipp +8 -2
  64. data/rice/detail/NativeCallbackFFI.ipp +1 -1
  65. data/rice/detail/NativeFunction.hpp +17 -6
  66. data/rice/detail/NativeFunction.ipp +168 -64
  67. data/rice/detail/NativeIterator.hpp +3 -2
  68. data/rice/detail/NativeIterator.ipp +8 -2
  69. data/rice/detail/RubyType.hpp +2 -5
  70. data/rice/detail/RubyType.ipp +50 -5
  71. data/rice/detail/Type.hpp +3 -1
  72. data/rice/detail/Type.ipp +61 -31
  73. data/rice/detail/Wrapper.hpp +68 -33
  74. data/rice/detail/Wrapper.ipp +103 -113
  75. data/rice/detail/from_ruby.hpp +5 -4
  76. data/rice/detail/from_ruby.ipp +737 -365
  77. data/rice/detail/to_ruby.ipp +1092 -186
  78. data/rice/global_function.ipp +1 -1
  79. data/rice/libc/file.hpp +11 -0
  80. data/rice/libc/file.ipp +32 -0
  81. data/rice/rice.hpp +23 -16
  82. data/rice/stl/complex.hpp +6 -0
  83. data/rice/stl/complex.ipp +93 -0
  84. data/rice/stl/exception.hpp +11 -0
  85. data/rice/stl/exception.ipp +29 -0
  86. data/rice/stl/exception_ptr.hpp +6 -0
  87. data/rice/stl/exception_ptr.ipp +27 -0
  88. data/rice/stl/map.hpp +12 -0
  89. data/rice/stl/map.ipp +469 -0
  90. data/rice/stl/monostate.hpp +6 -0
  91. data/rice/stl/monostate.ipp +80 -0
  92. data/rice/stl/multimap.hpp +14 -0
  93. data/rice/stl/multimap.ipp +448 -0
  94. data/rice/stl/optional.hpp +6 -0
  95. data/rice/stl/optional.ipp +118 -0
  96. data/rice/stl/pair.hpp +13 -0
  97. data/rice/stl/pair.ipp +155 -0
  98. data/rice/stl/reference_wrapper.hpp +6 -0
  99. data/rice/stl/reference_wrapper.ipp +41 -0
  100. data/rice/stl/set.hpp +12 -0
  101. data/rice/stl/set.ipp +495 -0
  102. data/rice/stl/shared_ptr.hpp +28 -0
  103. data/rice/stl/shared_ptr.ipp +224 -0
  104. data/rice/stl/string.hpp +6 -0
  105. data/rice/stl/string.ipp +158 -0
  106. data/rice/stl/string_view.hpp +6 -0
  107. data/rice/stl/string_view.ipp +65 -0
  108. data/rice/stl/tuple.hpp +6 -0
  109. data/rice/stl/tuple.ipp +128 -0
  110. data/rice/stl/type_index.hpp +6 -0
  111. data/rice/stl/type_index.ipp +30 -0
  112. data/rice/stl/type_info.hpp +6 -0
  113. data/rice/stl/type_info.ipp +29 -0
  114. data/rice/stl/unique_ptr.hpp +22 -0
  115. data/rice/stl/unique_ptr.ipp +139 -0
  116. data/rice/stl/unordered_map.hpp +12 -0
  117. data/rice/stl/unordered_map.ipp +469 -0
  118. data/rice/stl/variant.hpp +6 -0
  119. data/rice/stl/variant.ipp +242 -0
  120. data/rice/stl/vector.hpp +12 -0
  121. data/rice/stl/vector.ipp +590 -0
  122. data/rice/stl.hpp +7 -3
  123. data/rice/traits/attribute_traits.hpp +26 -0
  124. data/rice/traits/function_traits.hpp +95 -0
  125. data/rice/traits/method_traits.hpp +47 -0
  126. data/rice/traits/rice_traits.hpp +160 -0
  127. data/rice.gemspec +85 -0
  128. data/test/embed_ruby.cpp +3 -0
  129. data/test/ruby/test_multiple_extensions_same_class.rb +14 -14
  130. data/test/test_Array.cpp +6 -3
  131. data/test/test_Attribute.cpp +34 -1
  132. data/test/test_Buffer.cpp +285 -0
  133. data/test/test_Callback.cpp +2 -3
  134. data/test/test_Data_Object.cpp +88 -34
  135. data/test/test_Data_Type.cpp +106 -65
  136. data/test/test_Director.cpp +7 -3
  137. data/test/test_Enum.cpp +5 -2
  138. data/test/test_File.cpp +1 -1
  139. data/test/test_From_Ruby.cpp +181 -114
  140. data/test/test_Iterator.cpp +1 -1
  141. data/test/{test_JumpException.cpp → test_Jump_Exception.cpp} +1 -0
  142. data/test/test_Keep_Alive.cpp +7 -18
  143. data/test/test_Keep_Alive_No_Wrapper.cpp +0 -1
  144. data/test/test_Module.cpp +13 -6
  145. data/test/test_Native_Registry.cpp +0 -1
  146. data/test/test_Overloads.cpp +180 -5
  147. data/test/test_Ownership.cpp +100 -57
  148. data/test/test_Proc.cpp +0 -1
  149. data/test/test_Self.cpp +4 -4
  150. data/test/test_Stl_Map.cpp +37 -39
  151. data/test/test_Stl_Multimap.cpp +693 -0
  152. data/test/test_Stl_Pair.cpp +8 -8
  153. data/test/test_Stl_Reference_Wrapper.cpp +4 -2
  154. data/test/test_Stl_Set.cpp +790 -0
  155. data/test/{test_Stl_SmartPointer.cpp → test_Stl_SharedPtr.cpp} +97 -127
  156. data/test/test_Stl_Tuple.cpp +116 -0
  157. data/test/test_Stl_Type.cpp +1 -1
  158. data/test/test_Stl_UniquePtr.cpp +202 -0
  159. data/test/test_Stl_Unordered_Map.cpp +28 -34
  160. data/test/test_Stl_Variant.cpp +217 -89
  161. data/test/test_Stl_Vector.cpp +209 -83
  162. data/test/test_To_Ruby.cpp +373 -1
  163. data/test/test_Type.cpp +85 -14
  164. data/test/test_global_functions.cpp +17 -4
  165. metadata +94 -10
  166. data/rice/detail/TupleIterator.hpp +0 -14
@@ -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
- Module(rb_mKernel).define_module_function(name, std::forward<Function_T>(func), args...);
5
+ Module(rb_mKernel).define_module_function(name, std::forward<Function_T>(func), args...);
6
6
  }
@@ -0,0 +1,11 @@
1
+ #ifndef Rice__libc__file__hpp_
2
+ #define Rice__libc__file__hpp_
3
+
4
+ namespace Rice::libc
5
+ {
6
+ extern Class rb_cLibcFile;
7
+ }
8
+
9
+ #include "file.ipp"
10
+
11
+ #endif // Rice__libc__file__hpp_
@@ -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,6 @@
1
+ #ifndef Rice__stl__complex__hpp_
2
+ #define Rice__stl__complex__hpp_
3
+
4
+ #include "complex.ipp"
5
+
6
+ #endif // Rice__stl__complex__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,11 @@
1
+ #ifndef Rice__stl__exception__hpp_
2
+ #define Rice__stl__exception__hpp_
3
+
4
+ namespace Rice::stl
5
+ {
6
+ extern Class rb_cStlException;
7
+ }
8
+
9
+ #include "exception.ipp"
10
+
11
+ #endif // Rice__stl__exception__hpp_
@@ -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,6 @@
1
+ #ifndef Rice__stl__exception_ptr__hpp_
2
+ #define Rice__stl__exception_ptr__hpp_
3
+
4
+ #include "exception_ptr.ipp"
5
+
6
+ #endif // Rice__stl__exception_ptr__hpp_
@@ -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
@@ -0,0 +1,12 @@
1
+ #ifndef Rice__stl__map__hpp_
2
+ #define Rice__stl__map__hpp_
3
+
4
+ namespace Rice
5
+ {
6
+ template<typename K, typename T>
7
+ Data_Type<std::map<K, T>> define_map(std::string name = "");
8
+ }
9
+
10
+ #include "map.ipp"
11
+
12
+ #endif // Rice__stl__map__hpp_