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/test/test_Keep_Alive.cpp
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
#include "unittest.hpp"
|
2
2
|
#include "embed_ruby.hpp"
|
3
3
|
#include <rice/rice.hpp>
|
4
|
-
#include <rice/stl.hpp>
|
5
4
|
|
6
5
|
using namespace Rice;
|
7
6
|
|
@@ -60,6 +59,11 @@ SETUP(Keep_Alive)
|
|
60
59
|
embed_ruby();
|
61
60
|
}
|
62
61
|
|
62
|
+
TEARDOWN(Keep_Alive)
|
63
|
+
{
|
64
|
+
rb_gc_start();
|
65
|
+
}
|
66
|
+
|
63
67
|
TESTCASE(test_arg)
|
64
68
|
{
|
65
69
|
define_class<Listener>("Listener")
|
@@ -107,7 +111,10 @@ namespace
|
|
107
111
|
{
|
108
112
|
}
|
109
113
|
|
110
|
-
|
114
|
+
uint32_t index()
|
115
|
+
{
|
116
|
+
return this->index_;
|
117
|
+
}
|
111
118
|
|
112
119
|
private:
|
113
120
|
Connection& connection_;
|
@@ -121,20 +128,7 @@ namespace
|
|
121
128
|
{
|
122
129
|
return Column(*this, index);
|
123
130
|
}
|
124
|
-
|
125
|
-
std::string getName(uint32_t index)
|
126
|
-
{
|
127
|
-
return this->prefix_ + std::to_string(index);
|
128
|
-
}
|
129
|
-
|
130
|
-
private:
|
131
|
-
std::string prefix_ = "column_";
|
132
131
|
};
|
133
|
-
|
134
|
-
std::string Column::name()
|
135
|
-
{
|
136
|
-
return this->connection_.getName(this->index_);
|
137
|
-
}
|
138
132
|
}
|
139
133
|
|
140
134
|
Object getColumn(Module& m, uint32_t index)
|
@@ -146,7 +140,7 @@ Object getColumn(Module& m, uint32_t index)
|
|
146
140
|
TESTCASE(test_return)
|
147
141
|
{
|
148
142
|
define_class<Column>("Column")
|
149
|
-
.define_method("
|
143
|
+
.define_method("index", &Column::index);
|
150
144
|
|
151
145
|
define_class<Connection>("Connection")
|
152
146
|
.define_constructor(Constructor<Connection>())
|
@@ -156,6 +150,6 @@ TESTCASE(test_return)
|
|
156
150
|
|
157
151
|
Object column = getColumn(m, 3);
|
158
152
|
rb_gc_start();
|
159
|
-
|
160
|
-
ASSERT_EQUAL(
|
161
|
-
}
|
153
|
+
Object index = column.call("index");
|
154
|
+
ASSERT_EQUAL(3, detail::From_Ruby<int>().convert(index));
|
155
|
+
}
|
@@ -1,7 +1,6 @@
|
|
1
1
|
#include "unittest.hpp"
|
2
2
|
#include "embed_ruby.hpp"
|
3
3
|
#include <rice/rice.hpp>
|
4
|
-
#include <rice/stl.hpp>
|
5
4
|
|
6
5
|
using namespace Rice;
|
7
6
|
|
@@ -56,6 +55,11 @@ SETUP(Keep_Alive_No_Wrapper)
|
|
56
55
|
embed_ruby();
|
57
56
|
}
|
58
57
|
|
58
|
+
TEARDOWN(Keep_Alive_No_Wrapper)
|
59
|
+
{
|
60
|
+
rb_gc_start();
|
61
|
+
}
|
62
|
+
|
59
63
|
TESTCASE(test_keep_alive_no_wrapper)
|
60
64
|
{
|
61
65
|
define_class<Animal>("Animal")
|
data/test/test_Module.cpp
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#include "unittest.hpp"
|
1
|
+
#include "unittest.hpp"
|
2
2
|
#include "embed_ruby.hpp"
|
3
3
|
|
4
4
|
#include <rice/rice.hpp>
|
@@ -11,6 +11,12 @@ TESTSUITE(Module);
|
|
11
11
|
SETUP(Module)
|
12
12
|
{
|
13
13
|
embed_ruby();
|
14
|
+
define_fundamental_buffer_types();
|
15
|
+
}
|
16
|
+
|
17
|
+
TEARDOWN(Module)
|
18
|
+
{
|
19
|
+
rb_gc_start();
|
14
20
|
}
|
15
21
|
|
16
22
|
TESTCASE(FromConstant)
|
@@ -27,59 +33,51 @@ TESTCASE(FromName)
|
|
27
33
|
|
28
34
|
namespace
|
29
35
|
{
|
36
|
+
class MyClass
|
37
|
+
{
|
38
|
+
public:
|
39
|
+
MyClass() = default;
|
40
|
+
};
|
30
41
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
}
|
35
|
-
|
36
|
-
void handle_silly_exception(Quite_Silly_Exception const & ex)
|
37
|
-
{
|
38
|
-
throw Exception(rb_eRuntimeError, "SILLY");
|
39
|
-
}
|
40
|
-
|
41
|
-
void throw_silly_exception(Object self)
|
42
|
-
{
|
43
|
-
throw Quite_Silly_Exception();
|
44
|
-
}
|
45
|
-
|
46
|
-
} // namespace
|
47
|
-
|
48
|
-
TESTCASE(add_handler)
|
49
|
-
{
|
50
|
-
register_handler<Quite_Silly_Exception>(handle_silly_exception);
|
42
|
+
bool some_function()
|
43
|
+
{
|
44
|
+
return true;
|
45
|
+
}
|
51
46
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
Exception ex(exc);
|
57
|
-
ASSERT_EQUAL(String("SILLY"), String(ex.what()));
|
58
|
-
}
|
47
|
+
Object some_method(Object o)
|
48
|
+
{
|
49
|
+
return o;
|
50
|
+
}
|
59
51
|
|
60
|
-
|
61
|
-
{
|
52
|
+
int function_int(int i)
|
53
|
+
{
|
54
|
+
return i;
|
55
|
+
}
|
62
56
|
|
63
|
-
|
64
|
-
{
|
65
|
-
|
66
|
-
}
|
57
|
+
int method_int(Object object, int i)
|
58
|
+
{
|
59
|
+
return i;
|
60
|
+
}
|
67
61
|
|
68
|
-
|
69
|
-
{
|
70
|
-
|
71
|
-
}
|
62
|
+
bool method_lvalue(MyClass& myClass)
|
63
|
+
{
|
64
|
+
return true;
|
65
|
+
}
|
72
66
|
|
73
|
-
|
74
|
-
{
|
75
|
-
|
76
|
-
}
|
67
|
+
bool method_rvalue(MyClass&& myClass)
|
68
|
+
{
|
69
|
+
return true;
|
70
|
+
}
|
77
71
|
|
78
|
-
|
79
|
-
{
|
80
|
-
|
81
|
-
}
|
72
|
+
void method_lvalue_return_void(int a, MyClass& myClass)
|
73
|
+
{
|
74
|
+
// Do nothing
|
75
|
+
}
|
82
76
|
|
77
|
+
void method_rvalue_return_void(int b, MyClass&& myClass)
|
78
|
+
{
|
79
|
+
// Do nothing
|
80
|
+
}
|
83
81
|
} // namespace
|
84
82
|
|
85
83
|
TESTCASE(define_method)
|
@@ -180,14 +178,18 @@ TESTCASE(method_int_passed_no_args)
|
|
180
178
|
{
|
181
179
|
Module m(anonymous_module());
|
182
180
|
m.define_method("foo", method_int);
|
181
|
+
|
183
182
|
ASSERT_EXCEPTION_CHECK(
|
184
183
|
Exception,
|
185
184
|
m.module_eval("o = Object.new; o.extend(self); o.foo"),
|
186
|
-
ASSERT_EQUAL(
|
187
|
-
Object(rb_eArgError),
|
188
|
-
Object(CLASS_OF(ex.value()))
|
189
|
-
)
|
185
|
+
ASSERT_EQUAL(Object(rb_eArgError), Object(CLASS_OF(ex.value())))
|
190
186
|
);
|
187
|
+
|
188
|
+
ASSERT_EXCEPTION_CHECK(
|
189
|
+
Exception,
|
190
|
+
m.module_eval("o = Object.new; o.extend(self); o.foo"),
|
191
|
+
ASSERT_EQUAL("Missing argument. Name: arg_0. Index: 0.", ex.what())
|
192
|
+
);
|
191
193
|
}
|
192
194
|
|
193
195
|
TESTCASE(define_singleton_method_int_foo)
|
@@ -263,22 +265,28 @@ TESTCASE(default_arguments_still_throws_argument_error)
|
|
263
265
|
m.define_function("foo", &defaults_method_one, Arg("arg1"), Arg("arg2") = 3, Arg("arg3") = true);
|
264
266
|
|
265
267
|
ASSERT_EXCEPTION_CHECK(
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
Object(CLASS_OF(ex.value()))
|
271
|
-
)
|
272
|
-
);
|
268
|
+
Exception,
|
269
|
+
m.module_eval("o = Object.new; o.extend(self); o.foo()"),
|
270
|
+
ASSERT_EQUAL(Object(rb_eArgError), Object(CLASS_OF(ex.value())))
|
271
|
+
);
|
273
272
|
|
274
273
|
ASSERT_EXCEPTION_CHECK(
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
274
|
+
Exception,
|
275
|
+
m.module_eval("o = Object.new; o.extend(self); o.foo()"),
|
276
|
+
ASSERT_EQUAL("Missing argument. Name: arg1. Index: 0.", ex.what())
|
277
|
+
);
|
278
|
+
|
279
|
+
ASSERT_EXCEPTION_CHECK(
|
280
|
+
Exception,
|
281
|
+
m.module_eval("o = Object.new; o.extend(self); o.foo(3, 4, false, 17)"),
|
282
|
+
ASSERT_EQUAL(Object(rb_eArgError), Object(CLASS_OF(ex.value())))
|
283
|
+
);
|
284
|
+
|
285
|
+
ASSERT_EXCEPTION_CHECK(
|
286
|
+
Exception,
|
287
|
+
m.module_eval("o = Object.new; o.extend(self); o.foo(3, 4, false, 17)"),
|
288
|
+
ASSERT_EQUAL("wrong number of arguments (given 4, expected 3)", ex.what())
|
289
|
+
);
|
282
290
|
}
|
283
291
|
|
284
292
|
namespace {
|
@@ -457,7 +465,9 @@ TESTCASE(define_method_works_with_pointers)
|
|
457
465
|
Module m(anonymous_module());
|
458
466
|
m.define_module_function("bar", &with_pointers);
|
459
467
|
|
460
|
-
|
468
|
+
int anInt = 3;
|
469
|
+
Buffer<int> buffer(&anInt, 1);
|
470
|
+
m.call("bar", std::move(buffer), "testing");
|
461
471
|
|
462
472
|
ASSERT_EQUAL(3, with_pointers_x);
|
463
473
|
ASSERT_EQUAL("testing", with_pointers_str);
|
@@ -492,8 +502,12 @@ TESTCASE(pointers)
|
|
492
502
|
define_global_function("with_pointers", &withPointers);
|
493
503
|
|
494
504
|
Module m = define_module("TestingModule");
|
505
|
+
std::string code = R"(int_buffer = Rice::Buffer≺int≻.new(32)
|
506
|
+
bool_buffer = Rice::Buffer≺bool≻.new(true)
|
507
|
+
double_buffer = Rice::Buffer≺float≻.new(33.0)
|
508
|
+
float_buffer = Rice::Buffer≺double≻.new(34.0)
|
509
|
+
with_pointers(int_buffer, bool_buffer, double_buffer, float_buffer))";
|
495
510
|
|
496
|
-
std::string code = "with_pointers(32, true, 33.0, 34.0)";
|
497
511
|
m.module_eval(code);
|
498
512
|
|
499
513
|
ASSERT_EQUAL(intValue, 32);
|
@@ -515,4 +529,51 @@ TESTCASE(references)
|
|
515
529
|
ASSERT_EQUAL(boolValue, true);
|
516
530
|
ASSERT_EQUAL(floatValue, 43.0);
|
517
531
|
ASSERT_EQUAL(doubleValue, 44.0);
|
518
|
-
}
|
532
|
+
}
|
533
|
+
|
534
|
+
TESTCASE(lvalue_function)
|
535
|
+
{
|
536
|
+
Module m(anonymous_module());
|
537
|
+
Class c = define_class<MyClass>("MyClass").
|
538
|
+
define_constructor(Constructor<MyClass>());
|
539
|
+
|
540
|
+
m.define_module_function("method_lvalue", &method_lvalue);
|
541
|
+
m.define_module_function("method_lvalue_return_void", &method_lvalue_return_void);
|
542
|
+
|
543
|
+
Object result = m.module_eval(R"(o = MyClass.new
|
544
|
+
method_lvalue_return_void(1, o)
|
545
|
+
method_lvalue(o))");
|
546
|
+
|
547
|
+
ASSERT_EQUAL(Qtrue, result.value());
|
548
|
+
}
|
549
|
+
|
550
|
+
TESTCASE(rvalue_function)
|
551
|
+
{
|
552
|
+
Module m(anonymous_module());
|
553
|
+
Class c = define_class<MyClass>("MyClass").
|
554
|
+
define_constructor(Constructor<MyClass>());
|
555
|
+
|
556
|
+
m.define_module_function("method_rvalue", &method_rvalue);
|
557
|
+
m.define_module_function("method_rvalue_return_void", &method_rvalue_return_void);
|
558
|
+
|
559
|
+
Object result = m.module_eval(R"(o = MyClass.new
|
560
|
+
method_rvalue_return_void(1, o)
|
561
|
+
method_rvalue(o))");
|
562
|
+
|
563
|
+
ASSERT_EQUAL(Qtrue, result.value());
|
564
|
+
}
|
565
|
+
|
566
|
+
namespace {
|
567
|
+
namespace Constants {
|
568
|
+
#define MY_PI 314
|
569
|
+
}
|
570
|
+
}
|
571
|
+
|
572
|
+
TESTCASE(constants)
|
573
|
+
{
|
574
|
+
Module m = anonymous_module().
|
575
|
+
define_constant("MY_PI", MY_PI);
|
576
|
+
|
577
|
+
Object result = m.module_eval(R"(MY_PI)");
|
578
|
+
ASSERT_EQUAL(314, detail::From_Ruby<int>().convert(result.value()));
|
579
|
+
}
|
@@ -2,7 +2,6 @@
|
|
2
2
|
#include "embed_ruby.hpp"
|
3
3
|
|
4
4
|
#include <rice/rice.hpp>
|
5
|
-
#include <rice/stl.hpp>
|
6
5
|
|
7
6
|
using namespace Rice;
|
8
7
|
|
@@ -13,38 +12,7 @@ SETUP(NativeRegistry)
|
|
13
12
|
embed_ruby();
|
14
13
|
}
|
15
14
|
|
16
|
-
|
15
|
+
TEARDOWN(NativeRegistry)
|
17
16
|
{
|
18
|
-
|
19
|
-
int scale = 1000;
|
20
|
-
|
21
|
-
for (int i = 0; i < std::size(classes); i++)
|
22
|
-
{
|
23
|
-
Class cls(anonymous_class());
|
24
|
-
|
25
|
-
for (int j = 0; j < scale; j++)
|
26
|
-
{
|
27
|
-
cls.define_function("int" + std::to_string(j), []() { return 1; });
|
28
|
-
cls.define_function("long" + std::to_string(j), []() { return 1L; });
|
29
|
-
cls.define_function("double" + std::to_string(j), []() { return 1.0; });
|
30
|
-
cls.define_function("float" + std::to_string(j), []() { return 1.0f; });
|
31
|
-
cls.define_function("bool" + std::to_string(j), []() { return true; });
|
32
|
-
}
|
33
|
-
|
34
|
-
classes[i] = cls;
|
35
|
-
}
|
36
|
-
|
37
|
-
for (auto& cls : classes)
|
38
|
-
{
|
39
|
-
auto obj = cls.call("new");
|
40
|
-
|
41
|
-
for (int j = 0; j < scale; j++)
|
42
|
-
{
|
43
|
-
obj.call("int" + std::to_string(j));
|
44
|
-
obj.call("long" + std::to_string(j));
|
45
|
-
obj.call("double" + std::to_string(j));
|
46
|
-
obj.call("float" + std::to_string(j));
|
47
|
-
obj.call("bool" + std::to_string(j));
|
48
|
-
}
|
49
|
-
}
|
17
|
+
rb_gc_start();
|
50
18
|
}
|