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
@@ -0,0 +1,147 @@
|
|
1
|
+
#include "unittest.hpp"
|
2
|
+
#include "embed_ruby.hpp"
|
3
|
+
|
4
|
+
#include <rice/rice.hpp>
|
5
|
+
#include <rice/stl.hpp>
|
6
|
+
|
7
|
+
using namespace Rice;
|
8
|
+
|
9
|
+
TESTSUITE(TypeInfo);
|
10
|
+
|
11
|
+
SETUP(TypeInfo)
|
12
|
+
{
|
13
|
+
embed_ruby();
|
14
|
+
}
|
15
|
+
|
16
|
+
TEARDOWN(TypeInfo)
|
17
|
+
{
|
18
|
+
rb_gc_start();
|
19
|
+
}
|
20
|
+
|
21
|
+
namespace
|
22
|
+
{
|
23
|
+
const std::type_info& typeInfo(int value)
|
24
|
+
{
|
25
|
+
return typeid(value);
|
26
|
+
}
|
27
|
+
|
28
|
+
const std::string typeInfoName(const std::type_info& value)
|
29
|
+
{
|
30
|
+
return value.name();
|
31
|
+
}
|
32
|
+
|
33
|
+
const std::type_index typeIndex(const std::type_info& value)
|
34
|
+
{
|
35
|
+
return std::type_index(value);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
TESTCASE(TypeInfoName)
|
40
|
+
{
|
41
|
+
Module m = define_module("TestingModule");
|
42
|
+
m.define_module_function("get_type_info", typeInfo);
|
43
|
+
|
44
|
+
std::string code = R"(int = 5
|
45
|
+
type_info = get_type_info(5)
|
46
|
+
type_info.name)";
|
47
|
+
|
48
|
+
#ifdef _MSC_VER
|
49
|
+
const char* expected = "int";
|
50
|
+
#else
|
51
|
+
const char* expected = "i";
|
52
|
+
#endif
|
53
|
+
|
54
|
+
String result = m.module_eval(code);
|
55
|
+
ASSERT_EQUAL(expected, result.c_str());
|
56
|
+
}
|
57
|
+
|
58
|
+
TESTCASE(TypeInfoHash)
|
59
|
+
{
|
60
|
+
Module m = define_module("TestingModule");
|
61
|
+
m.define_module_function("get_type_info", typeInfo);
|
62
|
+
|
63
|
+
std::string code = R"(int = 5
|
64
|
+
type_info = get_type_info(5)
|
65
|
+
type_info.hash)";
|
66
|
+
|
67
|
+
Object result = m.module_eval(code);
|
68
|
+
size_t hash = detail::From_Ruby<size_t>().convert(result);
|
69
|
+
ASSERT((hash > 0));
|
70
|
+
}
|
71
|
+
|
72
|
+
TESTCASE(TypeInfoParameter)
|
73
|
+
{
|
74
|
+
Module m = define_module("TestingModule");
|
75
|
+
m.define_module_function("get_type_info", typeInfo).
|
76
|
+
define_module_function("get_type_info_name", typeInfoName);
|
77
|
+
|
78
|
+
std::string code = R"(int = 5
|
79
|
+
type_info = get_type_info(5)
|
80
|
+
get_type_info_name(type_info))";
|
81
|
+
|
82
|
+
#ifdef _MSC_VER
|
83
|
+
const char* expected = "int";
|
84
|
+
#else
|
85
|
+
const char* expected = "i";
|
86
|
+
#endif
|
87
|
+
|
88
|
+
String result = m.module_eval(code);
|
89
|
+
ASSERT_EQUAL(expected, result.c_str());
|
90
|
+
}
|
91
|
+
|
92
|
+
TESTCASE(TypeIndexCreate)
|
93
|
+
{
|
94
|
+
Module m = define_module("TestingModule");
|
95
|
+
m.define_module_function("get_type_info", typeInfo).
|
96
|
+
define_module_function("get_type_index", typeIndex);
|
97
|
+
|
98
|
+
std::string code = R"(int = 5
|
99
|
+
type_info = get_type_info(5)
|
100
|
+
Std::TypeIndex.new(type_info))";
|
101
|
+
|
102
|
+
#ifdef _MSC_VER
|
103
|
+
const char* expected = "int";
|
104
|
+
#else
|
105
|
+
const char* expected = "i";
|
106
|
+
#endif
|
107
|
+
|
108
|
+
Data_Object<std::type_index> result = m.module_eval(code);
|
109
|
+
ASSERT_EQUAL(expected, result->name());
|
110
|
+
}
|
111
|
+
|
112
|
+
TESTCASE(TypeIndexName)
|
113
|
+
{
|
114
|
+
Module m = define_module("TestingModule");
|
115
|
+
m.define_module_function("get_type_info", typeInfo).
|
116
|
+
define_module_function("get_type_index", typeIndex);
|
117
|
+
|
118
|
+
std::string code = R"(int = 5
|
119
|
+
type_info = get_type_info(5)
|
120
|
+
type_index = get_type_index(type_info)
|
121
|
+
type_index.name)";
|
122
|
+
|
123
|
+
#ifdef _MSC_VER
|
124
|
+
const char* expected = "int";
|
125
|
+
#else
|
126
|
+
const char* expected = "i";
|
127
|
+
#endif
|
128
|
+
|
129
|
+
String result = m.module_eval(code);
|
130
|
+
ASSERT_EQUAL(expected, result.str());
|
131
|
+
}
|
132
|
+
|
133
|
+
TESTCASE(TypeIndexHash)
|
134
|
+
{
|
135
|
+
Module m = define_module("TestingModule");
|
136
|
+
m.define_module_function("get_type_info", typeInfo).
|
137
|
+
define_module_function("get_type_index", typeIndex);
|
138
|
+
|
139
|
+
std::string code = R"(int = 5
|
140
|
+
type_info = get_type_info(5)
|
141
|
+
type_index = get_type_index(type_info)
|
142
|
+
type_index.hash)";
|
143
|
+
|
144
|
+
Object result = m.module_eval(code);
|
145
|
+
size_t hash = detail::From_Ruby<size_t>().convert(result);
|
146
|
+
ASSERT((hash > 0));
|
147
|
+
}
|
@@ -0,0 +1,202 @@
|
|
1
|
+
#include "unittest.hpp"
|
2
|
+
#include "embed_ruby.hpp"
|
3
|
+
#include <rice/rice.hpp>
|
4
|
+
#include <rice/stl.hpp>
|
5
|
+
|
6
|
+
#include <memory>
|
7
|
+
|
8
|
+
using namespace Rice;
|
9
|
+
|
10
|
+
TESTSUITE(UniquePtr);
|
11
|
+
|
12
|
+
namespace
|
13
|
+
{
|
14
|
+
class MyClass
|
15
|
+
{
|
16
|
+
public:
|
17
|
+
static inline int32_t constructorCalls = 0;
|
18
|
+
static inline int32_t copyConstructorCalls = 0;
|
19
|
+
static inline int32_t moveConstructorCalls = 0;
|
20
|
+
static inline int32_t destructorCalls = 0;
|
21
|
+
|
22
|
+
static void reset()
|
23
|
+
{
|
24
|
+
constructorCalls = 0;
|
25
|
+
copyConstructorCalls = 0;
|
26
|
+
moveConstructorCalls = 0;
|
27
|
+
destructorCalls = 0;
|
28
|
+
}
|
29
|
+
|
30
|
+
public:
|
31
|
+
int flag = 0;
|
32
|
+
|
33
|
+
public:
|
34
|
+
MyClass()
|
35
|
+
{
|
36
|
+
constructorCalls++;
|
37
|
+
}
|
38
|
+
|
39
|
+
~MyClass()
|
40
|
+
{
|
41
|
+
destructorCalls++;
|
42
|
+
}
|
43
|
+
|
44
|
+
MyClass(const MyClass& other): flag(other.flag)
|
45
|
+
{
|
46
|
+
copyConstructorCalls++;
|
47
|
+
}
|
48
|
+
|
49
|
+
MyClass(MyClass&& other) : flag(other.flag)
|
50
|
+
{
|
51
|
+
moveConstructorCalls++;
|
52
|
+
}
|
53
|
+
|
54
|
+
void setFlag(int value)
|
55
|
+
{
|
56
|
+
this->flag = value;
|
57
|
+
}
|
58
|
+
};
|
59
|
+
|
60
|
+
class Factory
|
61
|
+
{
|
62
|
+
public:
|
63
|
+
std::unique_ptr<MyClass> transfer()
|
64
|
+
{
|
65
|
+
return std::make_unique<MyClass>();
|
66
|
+
}
|
67
|
+
};
|
68
|
+
|
69
|
+
class Sink
|
70
|
+
{
|
71
|
+
public:
|
72
|
+
int takeOwnership(std::unique_ptr<MyClass> ptr)
|
73
|
+
{
|
74
|
+
return ptr->flag;
|
75
|
+
}
|
76
|
+
|
77
|
+
int updatePointer(std::unique_ptr<MyClass>& ptr, MyClass* myClass)
|
78
|
+
{
|
79
|
+
ptr.reset(myClass);
|
80
|
+
return ptr->flag;
|
81
|
+
}
|
82
|
+
};
|
83
|
+
|
84
|
+
int extractFlagUniquePtrRef(std::unique_ptr<MyClass>& myClass)
|
85
|
+
{
|
86
|
+
return myClass->flag;
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
SETUP(UniquePtr)
|
91
|
+
{
|
92
|
+
embed_ruby();
|
93
|
+
|
94
|
+
#if RUBY_API_VERSION_MAJOR == 3 && RUBY_API_VERSION_MINOR >= 2
|
95
|
+
rb_eval_string("GC.stress = true");
|
96
|
+
#endif
|
97
|
+
|
98
|
+
define_class<MyClass>("MyClass").
|
99
|
+
define_constructor(Constructor<MyClass>()).
|
100
|
+
define_method("set_flag", &MyClass::setFlag);
|
101
|
+
|
102
|
+
define_class<Factory>("Factory").
|
103
|
+
define_constructor(Constructor<Factory>()).
|
104
|
+
define_method("transfer", &Factory::transfer);
|
105
|
+
|
106
|
+
define_class<Sink>("Sink").
|
107
|
+
define_constructor(Constructor<Sink>()).
|
108
|
+
define_method("take_ownership", &Sink::takeOwnership).
|
109
|
+
define_method("update_pointer", &Sink::updatePointer,
|
110
|
+
Arg("ptr"), Arg("myClass").takeOwnership());
|
111
|
+
|
112
|
+
define_global_function("extract_flag_unique_ptr_ref", &extractFlagUniquePtrRef);
|
113
|
+
}
|
114
|
+
|
115
|
+
TEARDOWN(UniquePtr)
|
116
|
+
{
|
117
|
+
rb_gc_start();
|
118
|
+
#if RUBY_API_VERSION_MAJOR == 3 && RUBY_API_VERSION_MINOR >= 2
|
119
|
+
rb_eval_string("GC.stress = false");
|
120
|
+
#endif
|
121
|
+
}
|
122
|
+
|
123
|
+
TESTCASE(takeOwnership)
|
124
|
+
{
|
125
|
+
MyClass::reset();
|
126
|
+
|
127
|
+
Module m = define_module("TestingModule");
|
128
|
+
|
129
|
+
std::string code = R"(factory = Factory.new
|
130
|
+
10.times do |i|
|
131
|
+
my_class = factory.transfer
|
132
|
+
my_class.set_flag(i)
|
133
|
+
my_class = nil
|
134
|
+
end)";
|
135
|
+
|
136
|
+
m.module_eval(code);
|
137
|
+
rb_gc_start();
|
138
|
+
|
139
|
+
ASSERT_EQUAL(10, MyClass::constructorCalls);
|
140
|
+
ASSERT_EQUAL(0, MyClass::copyConstructorCalls);
|
141
|
+
ASSERT_EQUAL(0, MyClass::moveConstructorCalls);
|
142
|
+
ASSERT_EQUAL(10, MyClass::destructorCalls);
|
143
|
+
}
|
144
|
+
|
145
|
+
TESTCASE(RefParameter)
|
146
|
+
{
|
147
|
+
MyClass::reset();
|
148
|
+
|
149
|
+
Module m = define_module("TestingModule");
|
150
|
+
|
151
|
+
std::string code = R"(factory = Factory.new
|
152
|
+
my_class = factory.transfer
|
153
|
+
my_class.set_flag(7)
|
154
|
+
extract_flag_unique_ptr_ref(my_class))";
|
155
|
+
|
156
|
+
Object result = m.module_eval(code);
|
157
|
+
ASSERT_EQUAL(7, detail::From_Ruby<int>().convert(result));
|
158
|
+
}
|
159
|
+
|
160
|
+
TESTCASE(RoundTrip)
|
161
|
+
{
|
162
|
+
MyClass::reset();
|
163
|
+
|
164
|
+
Module m = define_module("TestingModule");
|
165
|
+
|
166
|
+
// Create ruby objects that point to the same instance of MyClass
|
167
|
+
std::string code = R"(factory = Factory.new
|
168
|
+
my_class = factory.transfer
|
169
|
+
my_class.set_flag(5)
|
170
|
+
|
171
|
+
sink = Sink.new
|
172
|
+
sink.take_ownership(my_class))";
|
173
|
+
|
174
|
+
Object result = m.instance_eval(code);
|
175
|
+
ASSERT_EQUAL(5, detail::From_Ruby<int>().convert(result.value()));
|
176
|
+
|
177
|
+
ASSERT_EQUAL(1, MyClass::constructorCalls);
|
178
|
+
ASSERT_EQUAL(0, MyClass::copyConstructorCalls);
|
179
|
+
ASSERT_EQUAL(0, MyClass::moveConstructorCalls);
|
180
|
+
ASSERT_EQUAL(1, MyClass::destructorCalls);
|
181
|
+
}
|
182
|
+
|
183
|
+
TESTCASE(Update)
|
184
|
+
{
|
185
|
+
MyClass::reset();
|
186
|
+
|
187
|
+
Module m = define_module("TestingModule");
|
188
|
+
|
189
|
+
// Create ruby objects that point to the same instance of MyClass
|
190
|
+
std::string code = R"(factory = Factory.new
|
191
|
+
my_class1 = factory.transfer
|
192
|
+
my_class1.set_flag(5)
|
193
|
+
|
194
|
+
my_class2 = MyClass.new
|
195
|
+
my_class2.set_flag(11)
|
196
|
+
|
197
|
+
sink = Sink.new
|
198
|
+
sink.update_pointer(my_class1, my_class2))";
|
199
|
+
|
200
|
+
Object result = m.instance_eval(code);
|
201
|
+
ASSERT_EQUAL(11, detail::From_Ruby<long>().convert(result.value()));
|
202
|
+
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#include <complex>
|
1
|
+
#include <complex>
|
2
2
|
#include <memory>
|
3
3
|
|
4
4
|
#include "unittest.hpp"
|
@@ -15,6 +15,11 @@ SETUP(UnorderedMap)
|
|
15
15
|
embed_ruby();
|
16
16
|
}
|
17
17
|
|
18
|
+
TEARDOWN(UnorderedMap)
|
19
|
+
{
|
20
|
+
rb_gc_start();
|
21
|
+
}
|
22
|
+
|
18
23
|
namespace
|
19
24
|
{
|
20
25
|
|
@@ -42,9 +47,9 @@ TESTCASE(StringUnorderedMap)
|
|
42
47
|
{
|
43
48
|
Module m = define_module("Testing");
|
44
49
|
|
45
|
-
Class c = define_unordered_map<std::
|
50
|
+
Class c = define_unordered_map<std::string, std::string>("StringUnorderedMap");
|
46
51
|
|
47
|
-
Object unordered_map = m.module_eval("$unordered_map = StringUnorderedMap.new");
|
52
|
+
Object unordered_map = m.module_eval("$unordered_map = Std::StringUnorderedMap.new");
|
48
53
|
Object result = unordered_map.call("size");
|
49
54
|
ASSERT_EQUAL(0, detail::From_Ruby<int32_t>().convert(result));
|
50
55
|
|
@@ -61,8 +66,8 @@ TESTCASE(WrongType)
|
|
61
66
|
{
|
62
67
|
Module m = define_module("Testing");
|
63
68
|
|
64
|
-
Class c = define_unordered_map<std::
|
65
|
-
Object unordered_map = m.module_eval("$unordered_map = StringUnorderedMap.new");
|
69
|
+
Class c = define_unordered_map<std::string, std::string>("StringUnorderedMap");
|
70
|
+
Object unordered_map = m.module_eval("$unordered_map = Std::StringUnorderedMap.new");
|
66
71
|
|
67
72
|
ASSERT_EXCEPTION_CHECK(
|
68
73
|
Exception,
|
@@ -79,7 +84,7 @@ TESTCASE(Empty)
|
|
79
84
|
{
|
80
85
|
Module m = define_module("Testing");
|
81
86
|
|
82
|
-
Class c = define_unordered_map<std::
|
87
|
+
Class c = define_unordered_map<std::string, std::int32_t>("IntUnorderedMap");
|
83
88
|
Data_Object<std::unordered_map<std::string, std::int32_t>> unordered_map = c.call("new");
|
84
89
|
|
85
90
|
Object result = unordered_map.call("size");
|
@@ -93,7 +98,7 @@ TESTCASE(Include)
|
|
93
98
|
{
|
94
99
|
Module m = define_module("Testing");
|
95
100
|
|
96
|
-
Class c = define_unordered_map<std::
|
101
|
+
Class c = define_unordered_map<std::string, std::int32_t>("IntUnorderedMap");
|
97
102
|
Data_Object<std::unordered_map<std::string, std::int32_t>> unordered_map = c.call("new");
|
98
103
|
unordered_map.call("[]=", "one", 1);
|
99
104
|
unordered_map.call("[]=", "two", 2);
|
@@ -112,7 +117,7 @@ TESTCASE(Value)
|
|
112
117
|
{
|
113
118
|
Module m = define_module("Testing");
|
114
119
|
|
115
|
-
Class c = define_unordered_map<std::
|
120
|
+
Class c = define_unordered_map<std::string, std::int32_t>("IntUnorderedMap");
|
116
121
|
Data_Object<std::unordered_map<std::string, std::int32_t>> unordered_map = c.call("new");
|
117
122
|
unordered_map.call("[]=", "one", 1);
|
118
123
|
unordered_map.call("[]=", "two", 2);
|
@@ -128,7 +133,7 @@ TESTCASE(ToString)
|
|
128
133
|
{
|
129
134
|
Module m = define_module("Testing");
|
130
135
|
|
131
|
-
Class c = define_unordered_map<std::
|
136
|
+
Class c = define_unordered_map<std::string, std::int32_t>("IntUnorderedMap");
|
132
137
|
Data_Object<std::unordered_map<std::string, std::int32_t>> unordered_map = c.call("new");
|
133
138
|
unordered_map.call("[]=", "one", 1);
|
134
139
|
unordered_map.call("[]=", "two", 2);
|
@@ -146,7 +151,7 @@ TESTCASE(Update)
|
|
146
151
|
{
|
147
152
|
Module m = define_module("Testing");
|
148
153
|
|
149
|
-
Class c = define_unordered_map<std::
|
154
|
+
Class c = define_unordered_map<std::string, std::string>("StringUnorderedMap");
|
150
155
|
Data_Object<std::unordered_map<std::string, std::string>> unordered_map = c.call("new");
|
151
156
|
unordered_map.call("[]=", "one", "original 1");
|
152
157
|
unordered_map.call("[]=", "two", "original 2");
|
@@ -168,7 +173,7 @@ TESTCASE(Modify)
|
|
168
173
|
{
|
169
174
|
Module m = define_module("Testing");
|
170
175
|
|
171
|
-
Class c = define_unordered_map<std::
|
176
|
+
Class c = define_unordered_map<std::string, int64_t>("Int64UnorderedMap");
|
172
177
|
Data_Object<std::unordered_map<std::string, std::int64_t>> unordered_map = c.call("new");
|
173
178
|
|
174
179
|
Object result = unordered_map.call("[]=", "one", 3232323232);
|
@@ -187,7 +192,7 @@ TESTCASE(KeysAndValues)
|
|
187
192
|
{
|
188
193
|
Module m = define_module("Testing");
|
189
194
|
|
190
|
-
Class c = define_unordered_map<std::
|
195
|
+
Class c = define_unordered_map<std::string, int32_t>("Int32UnorderedMap");
|
191
196
|
Data_Object<std::unordered_map<std::string, std::int32_t>> unordered_map = c.call("new");
|
192
197
|
|
193
198
|
unordered_map.call("[]=", "one", 1);
|
@@ -215,7 +220,7 @@ TESTCASE(Copy)
|
|
215
220
|
{
|
216
221
|
Module m = define_module("Testing");
|
217
222
|
|
218
|
-
Class c = define_unordered_map<std::
|
223
|
+
Class c = define_unordered_map<std::string, double>("DoubleUnorderedMap");
|
219
224
|
Object object = c.call("new");
|
220
225
|
|
221
226
|
object.call("[]=", "one", 11.1);
|
@@ -236,9 +241,9 @@ TESTCASE(Copy)
|
|
236
241
|
TESTCASE(Iterate)
|
237
242
|
{
|
238
243
|
Module m = define_module("Testing");
|
239
|
-
Class c = define_unordered_map<std::
|
244
|
+
Class c = define_unordered_map<std::string, int>("IntUnorderedMap");
|
240
245
|
|
241
|
-
std::string code = R"(unordered_map = IntUnorderedMap.new
|
246
|
+
std::string code = R"(unordered_map = Std::IntUnorderedMap.new
|
242
247
|
unordered_map["five"] = 5
|
243
248
|
unordered_map["six"] = 6
|
244
249
|
unordered_map["seven"] = 7
|
@@ -260,9 +265,9 @@ TESTCASE(Iterate)
|
|
260
265
|
TESTCASE(ToEnum)
|
261
266
|
{
|
262
267
|
Module m = define_module("Testing");
|
263
|
-
Class c = define_unordered_map<std::
|
268
|
+
Class c = define_unordered_map<std::string, int>("IntUnorderedMap");
|
264
269
|
|
265
|
-
std::string code = R"(unordered_map = IntUnorderedMap.new
|
270
|
+
std::string code = R"(unordered_map = Std::IntUnorderedMap.new
|
266
271
|
unordered_map["five"] = 5
|
267
272
|
unordered_map["six"] = 6
|
268
273
|
unordered_map["seven"] = 7
|
@@ -285,9 +290,9 @@ TESTCASE(ToEnum)
|
|
285
290
|
TESTCASE(ToEnumSize)
|
286
291
|
{
|
287
292
|
Module m = define_module("TestingModule");
|
288
|
-
Class c = define_unordered_map<std::
|
293
|
+
Class c = define_unordered_map<std::string, int>("IntUnorderedMap");
|
289
294
|
|
290
|
-
std::string code = R"(map = IntUnorderedMap.new
|
295
|
+
std::string code = R"(map = Std::IntUnorderedMap.new
|
291
296
|
map["five"] = 5
|
292
297
|
map["six"] = 6
|
293
298
|
map["seven"] = 7
|
@@ -322,7 +327,7 @@ TESTCASE(NotComparable)
|
|
322
327
|
define_class<NotComparable>("NotComparable").
|
323
328
|
define_constructor(Constructor<NotComparable, uint32_t>());
|
324
329
|
|
325
|
-
Class c = define_unordered_map<std::
|
330
|
+
Class c = define_unordered_map<std::string, NotComparable>("NotComparableUnorderedMap");
|
326
331
|
|
327
332
|
Data_Object<std::unordered_map<std::string, NotComparable>> unordered_map = c.call("new");
|
328
333
|
unordered_map.call("[]=", "one", NotComparable(1));
|
@@ -341,7 +346,7 @@ TESTCASE(NotPrintable)
|
|
341
346
|
define_class<NotComparable>("NotComparable").
|
342
347
|
define_constructor(Constructor<NotComparable, uint32_t>());
|
343
348
|
|
344
|
-
Class c = define_unordered_map<std::
|
349
|
+
Class c = define_unordered_map<std::string, NotComparable>("NotComparableUnorderedMap");
|
345
350
|
|
346
351
|
Data_Object<std::unordered_map<std::string, NotComparable>> unordered_map = c.call("new");
|
347
352
|
unordered_map.call("[]=", "one", NotComparable(1));
|
@@ -382,7 +387,7 @@ TESTCASE(Comparable)
|
|
382
387
|
define_class<Comparable>("IsComparable").
|
383
388
|
define_constructor(Constructor<Comparable, uint32_t>());
|
384
389
|
|
385
|
-
Class c = define_unordered_map<std::
|
390
|
+
Class c = define_unordered_map<std::string, Comparable>("ComparableUnorderedMap");
|
386
391
|
|
387
392
|
Data_Object<std::unordered_map<std::string, Comparable>> unordered_map = c.call("new");
|
388
393
|
|
@@ -399,7 +404,7 @@ TESTCASE(Printable)
|
|
399
404
|
define_class<Comparable>("IsComparable").
|
400
405
|
define_constructor(Constructor<Comparable, uint32_t>());
|
401
406
|
|
402
|
-
Class c = define_unordered_map<std::
|
407
|
+
Class c = define_unordered_map<std::string, Comparable>("ComparableUnorderedMap");
|
403
408
|
|
404
409
|
Data_Object<std::unordered_map<std::string, Comparable>> unordered_map = c.call("new");
|
405
410
|
unordered_map.call("[]=", "one", Comparable(1));
|
@@ -438,7 +443,7 @@ TESTCASE(AutoRegisterReturn)
|
|
438
443
|
|
439
444
|
Module m = define_module("Testing");
|
440
445
|
Object unordered_map = m.module_eval("return_complex_unordered_map");
|
441
|
-
ASSERT_EQUAL("
|
446
|
+
ASSERT_EQUAL("Std::UnorderedMap≺string‚ complex≺double≻≻",
|
442
447
|
unordered_map.class_name().str());
|
443
448
|
|
444
449
|
std::string code = R"(unordered_map = return_complex_unordered_map
|
@@ -449,14 +454,8 @@ TESTCASE(AutoRegisterReturn)
|
|
449
454
|
ASSERT_EQUAL(Qtrue, result.value());
|
450
455
|
|
451
456
|
// Now register the unordered_map again
|
452
|
-
define_unordered_map<std::
|
453
|
-
code = R"(unordered_map = ComplexUnorderedMap.new)";
|
454
|
-
result = m.module_eval(code);
|
455
|
-
ASSERT(result.is_instance_of(unordered_map.class_of()));
|
456
|
-
|
457
|
-
// And again in the module
|
458
|
-
define_unordered_map_under<std::unordered_map<std::string, std::complex<double>>>(m, "ComplexUnorderedMap2");
|
459
|
-
code = R"(unordered_map = Testing::ComplexUnorderedMap2.new)";
|
457
|
+
define_unordered_map<std::string, std::complex<double>>("ComplexUnorderedMap");
|
458
|
+
code = R"(unordered_map = Std::ComplexUnorderedMap.new)";
|
460
459
|
result = m.module_eval(code);
|
461
460
|
ASSERT(result.is_instance_of(unordered_map.class_of()));
|
462
461
|
}
|
@@ -465,16 +464,16 @@ TESTCASE(AutoRegisterParameter)
|
|
465
464
|
{
|
466
465
|
define_global_function("pass_complex_unordered_map", &passComplexUnorderedMap);
|
467
466
|
|
468
|
-
std::string code = R"(unordered_map =
|
469
|
-
|
470
|
-
|
471
|
-
|
467
|
+
std::string code = R"(unordered_map = Std::UnorderedMap≺string‚ complex≺double≻≻.new
|
468
|
+
unordered_map["four"] = Complex(4.0, 4.0)
|
469
|
+
unordered_map["five"] = Complex(5.0, 5.0)
|
470
|
+
pass_complex_unordered_map(unordered_map))";
|
472
471
|
|
473
472
|
Module m = define_module("Testing");
|
474
473
|
Object unordered_map = m.module_eval(code);
|
475
474
|
|
476
475
|
Object result = unordered_map.call("size");
|
477
|
-
ASSERT_EQUAL("
|
476
|
+
ASSERT_EQUAL("Std::UnorderedMap≺string‚ complex≺double≻≻",
|
478
477
|
unordered_map.class_name().str());
|
479
478
|
ASSERT_EQUAL(2, detail::From_Ruby<int32_t>().convert(result));
|
480
479
|
|
@@ -493,7 +492,7 @@ namespace
|
|
493
492
|
|
494
493
|
TESTCASE(DefaultValue)
|
495
494
|
{
|
496
|
-
define_unordered_map<std::
|
495
|
+
define_unordered_map<std::string, std::string>("StringUnorderedMap");
|
497
496
|
define_global_function("default_unordered_map", &defaultUnorderedMap, Arg("strings") = std::unordered_map<std::string, std::string>{ {"one", "value 1"}, {"two", "value 2"}, {"three", "value 3"} });
|
498
497
|
|
499
498
|
Module m = define_module("Testing");
|
@@ -653,6 +652,12 @@ TESTCASE(HashToUnorderedMapWrongTypes)
|
|
653
652
|
"two" => 79.0,
|
654
653
|
"three" => 1000.0}))";
|
655
654
|
|
655
|
+
ASSERT_EXCEPTION_CHECK(
|
656
|
+
Exception,
|
657
|
+
m.module_eval(code),
|
658
|
+
ASSERT_EQUAL(rb_eTypeError, ex.class_of())
|
659
|
+
);
|
660
|
+
|
656
661
|
ASSERT_EXCEPTION_CHECK(
|
657
662
|
Exception,
|
658
663
|
m.module_eval(code),
|