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
@@ -1,38 +0,0 @@
|
|
1
|
-
#ifndef Rice__detail__from_ruby_defn__hpp_
|
2
|
-
#define Rice__detail__from_ruby_defn__hpp_
|
3
|
-
|
4
|
-
#include <type_traits>
|
5
|
-
|
6
|
-
#include "ruby.hpp"
|
7
|
-
|
8
|
-
namespace Rice::detail
|
9
|
-
{
|
10
|
-
//! Convert a Ruby object to C++.
|
11
|
-
/*! If the Ruby object can be converted to an immediate value, returns a
|
12
|
-
* copy of the Ruby object. If the Ruby object is holding a C++
|
13
|
-
* object and the type specified is a pointer to that type, returns a
|
14
|
-
* pointer to that object.
|
15
|
-
*
|
16
|
-
* Conversions from ruby to a pointer type are automatically generated
|
17
|
-
* when a type is bound using Data_Type. If no conversion exists an
|
18
|
-
* exception is thrown.
|
19
|
-
*
|
20
|
-
* \param T the C++ type to which to convert.
|
21
|
-
* \param x the Ruby object to convert.
|
22
|
-
* \return a C++ representation of the Ruby object.
|
23
|
-
*
|
24
|
-
* Example:
|
25
|
-
* \code
|
26
|
-
* Object x = INT2NUM(42);
|
27
|
-
* std::cout << From_Ruby<int>::convert(x);
|
28
|
-
*
|
29
|
-
* Data_Object<Foo> foo(new Foo);
|
30
|
-
* std::cout << *From_Ruby<Foo *>(foo) << std::endl;
|
31
|
-
* \endcode
|
32
|
-
*/
|
33
|
-
|
34
|
-
template <typename T>
|
35
|
-
class From_Ruby;
|
36
|
-
}
|
37
|
-
|
38
|
-
#endif // Rice__detail__From_Ruby2_defn__hpp_
|
@@ -1,48 +0,0 @@
|
|
1
|
-
#ifndef Rice__detail__to_ruby_defn__hpp_
|
2
|
-
#define Rice__detail__to_ruby_defn__hpp_
|
3
|
-
|
4
|
-
#include "../traits/rice_traits.hpp"
|
5
|
-
|
6
|
-
namespace Rice
|
7
|
-
{
|
8
|
-
namespace detail
|
9
|
-
{
|
10
|
-
//! Convert a C++ object to Ruby.
|
11
|
-
/*! If x is a pointer, wraps the pointee as a Ruby object. If x is an
|
12
|
-
* Object, returns x.
|
13
|
-
*
|
14
|
-
* If no conversion exists a compile-time error is generated.
|
15
|
-
*
|
16
|
-
* \param x the object to convert.
|
17
|
-
* \return a Ruby representation of the C++ object.
|
18
|
-
*
|
19
|
-
* Example:
|
20
|
-
* \code
|
21
|
-
* rb_p(to_ruby(42));
|
22
|
-
*
|
23
|
-
* Foo * p_foo = new Foo();
|
24
|
-
* rb_p(to_ruby(p_foo));
|
25
|
-
* \endcode
|
26
|
-
*/
|
27
|
-
template <typename T>
|
28
|
-
class To_Ruby;
|
29
|
-
|
30
|
-
// Helper template function that let's users avoid having to specify the template type - its deduced
|
31
|
-
template <typename T>
|
32
|
-
VALUE to_ruby(T&& x)
|
33
|
-
{
|
34
|
-
using Unqualified_T = remove_cv_recursive_t<T>;
|
35
|
-
return To_Ruby<Unqualified_T>().convert(std::forward<T>(x));
|
36
|
-
}
|
37
|
-
|
38
|
-
// Helper template function that let's users avoid having to specify the template type - its deduced
|
39
|
-
template <typename T>
|
40
|
-
VALUE to_ruby(T* x)
|
41
|
-
{
|
42
|
-
using Unqualified_T = remove_cv_recursive_t<T>;
|
43
|
-
return To_Ruby<Unqualified_T*>().convert(x);
|
44
|
-
}
|
45
|
-
} // detail
|
46
|
-
} // Rice
|
47
|
-
|
48
|
-
#endif // Rice__detail__to_ruby_defn__hpp_
|
data/test/test_Jump_Tag.cpp
DELETED
@@ -1,283 +0,0 @@
|
|
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(SmartPointer);
|
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
|
-
std::shared_ptr<MyClass> share()
|
69
|
-
{
|
70
|
-
if (!instance_)
|
71
|
-
{
|
72
|
-
instance_ = std::make_shared<MyClass>();
|
73
|
-
}
|
74
|
-
return instance_;
|
75
|
-
}
|
76
|
-
|
77
|
-
std::shared_ptr<MyClass>& share_ref()
|
78
|
-
{
|
79
|
-
if (!instance_)
|
80
|
-
{
|
81
|
-
instance_ = std::make_shared<MyClass>();
|
82
|
-
}
|
83
|
-
return instance_;
|
84
|
-
}
|
85
|
-
|
86
|
-
public:
|
87
|
-
static inline std::shared_ptr<MyClass> instance_;
|
88
|
-
};
|
89
|
-
|
90
|
-
int extractFlagUniquePtrRef(std::unique_ptr<MyClass>& myClass)
|
91
|
-
{
|
92
|
-
return myClass->flag;
|
93
|
-
}
|
94
|
-
|
95
|
-
int extractFlagSharedPtr(std::shared_ptr<MyClass> myClass)
|
96
|
-
{
|
97
|
-
return myClass->flag;
|
98
|
-
}
|
99
|
-
|
100
|
-
int extractFlagSharedPtrRef(std::shared_ptr<MyClass>& myClass)
|
101
|
-
{
|
102
|
-
return myClass->flag;
|
103
|
-
}
|
104
|
-
}
|
105
|
-
|
106
|
-
SETUP(SmartPointer)
|
107
|
-
{
|
108
|
-
embed_ruby();
|
109
|
-
|
110
|
-
define_class<MyClass>("MyClass").
|
111
|
-
define_method("set_flag", &MyClass::setFlag);
|
112
|
-
|
113
|
-
define_class<Factory>("Factory").
|
114
|
-
define_constructor(Constructor<Factory>()).
|
115
|
-
define_method("transfer", &Factory::transfer).
|
116
|
-
define_method("share", &Factory::share).
|
117
|
-
define_method("share_ref", &Factory::share_ref);
|
118
|
-
|
119
|
-
define_global_function("extract_flag_unique_ptr_ref", &extractFlagUniquePtrRef);
|
120
|
-
define_global_function("extract_flag_shared_ptr", &extractFlagSharedPtr);
|
121
|
-
define_global_function("extract_flag_shared_ptr_ref", &extractFlagSharedPtrRef);
|
122
|
-
|
123
|
-
define_global_function("extract_flag_shared_ptr_with_default", &extractFlagSharedPtr,
|
124
|
-
Arg("myClass") = std::make_shared<MyClass>());
|
125
|
-
define_global_function("extract_flag_shared_ptr_ref_with_default", &extractFlagSharedPtrRef,
|
126
|
-
Arg("myClass") = std::make_shared<MyClass>());
|
127
|
-
}
|
128
|
-
|
129
|
-
TESTCASE(TransferOwnership)
|
130
|
-
{
|
131
|
-
MyClass::reset();
|
132
|
-
|
133
|
-
Module m = define_module("TestingModule");
|
134
|
-
|
135
|
-
std::string code = R"(factory = Factory.new
|
136
|
-
10.times do |i|
|
137
|
-
my_class = factory.transfer
|
138
|
-
my_class.set_flag(i)
|
139
|
-
my_class = nil
|
140
|
-
end)";
|
141
|
-
|
142
|
-
m.module_eval(code);
|
143
|
-
rb_gc_start();
|
144
|
-
|
145
|
-
ASSERT_EQUAL(10, MyClass::constructorCalls);
|
146
|
-
ASSERT_EQUAL(0, MyClass::copyConstructorCalls);
|
147
|
-
ASSERT_EQUAL(0, MyClass::moveConstructorCalls);
|
148
|
-
ASSERT_EQUAL(10, MyClass::destructorCalls);
|
149
|
-
ASSERT(!Factory::instance_);
|
150
|
-
}
|
151
|
-
|
152
|
-
TESTCASE(ShareOwnership)
|
153
|
-
{
|
154
|
-
MyClass::reset();
|
155
|
-
|
156
|
-
Module m = define_module("TestingModule");
|
157
|
-
|
158
|
-
// Create ruby objects that point to the same instance of MyClass
|
159
|
-
std::string code = R"(factory = Factory.new
|
160
|
-
10.times do |i|
|
161
|
-
my_class = factory.share
|
162
|
-
my_class.set_flag(i)
|
163
|
-
end)";
|
164
|
-
|
165
|
-
|
166
|
-
ASSERT_EQUAL(0, Factory::instance_.use_count());
|
167
|
-
m.module_eval(code);
|
168
|
-
|
169
|
-
ASSERT_EQUAL(11, Factory::instance_.use_count());
|
170
|
-
rb_gc_start();
|
171
|
-
ASSERT_EQUAL(1, Factory::instance_.use_count());
|
172
|
-
|
173
|
-
ASSERT_EQUAL(1, MyClass::constructorCalls);
|
174
|
-
ASSERT_EQUAL(0, MyClass::copyConstructorCalls);
|
175
|
-
ASSERT_EQUAL(0, MyClass::moveConstructorCalls);
|
176
|
-
ASSERT_EQUAL(0, MyClass::destructorCalls);
|
177
|
-
ASSERT_EQUAL(9, Factory::instance_->flag);
|
178
|
-
}
|
179
|
-
|
180
|
-
|
181
|
-
TESTCASE(ShareOwnership2)
|
182
|
-
{
|
183
|
-
MyClass::reset();
|
184
|
-
|
185
|
-
Module m = define_module("TestingModule");
|
186
|
-
|
187
|
-
// Create ruby objects that point to the same instance of MyClass
|
188
|
-
std::string code = R"(factory = Factory.new
|
189
|
-
10.times do |i|
|
190
|
-
my_class = factory.share
|
191
|
-
my_class.set_flag(i)
|
192
|
-
end)";
|
193
|
-
|
194
|
-
Factory factory;
|
195
|
-
std::shared_ptr<MyClass> myClass = factory.share();
|
196
|
-
ASSERT_EQUAL(2, Factory::instance_.use_count());
|
197
|
-
|
198
|
-
// Call some ruby code
|
199
|
-
Data_Object<Factory> wrapper(factory);
|
200
|
-
ASSERT_EQUAL(2, Factory::instance_.use_count());
|
201
|
-
wrapper.instance_eval("self.share_ref.set_flag(1)");
|
202
|
-
|
203
|
-
ASSERT_EQUAL(3, Factory::instance_.use_count());
|
204
|
-
rb_gc_start();
|
205
|
-
ASSERT_EQUAL(2, Factory::instance_.use_count());
|
206
|
-
}
|
207
|
-
|
208
|
-
TESTCASE(UniquePtrRefParameter)
|
209
|
-
{
|
210
|
-
MyClass::reset();
|
211
|
-
|
212
|
-
Module m = define_module("TestingModule");
|
213
|
-
|
214
|
-
std::string code = R"(factory = Factory.new
|
215
|
-
my_class = factory.transfer
|
216
|
-
my_class.set_flag(7)
|
217
|
-
extract_flag_unique_ptr_ref(my_class))";
|
218
|
-
|
219
|
-
Object result = m.module_eval(code);
|
220
|
-
ASSERT_EQUAL(7, detail::From_Ruby<int>().convert(result));
|
221
|
-
}
|
222
|
-
|
223
|
-
TESTCASE(SharedPtrParameter)
|
224
|
-
{
|
225
|
-
MyClass::reset();
|
226
|
-
|
227
|
-
Module m = define_module("TestingModule");
|
228
|
-
|
229
|
-
std::string code = R"(factory = Factory.new
|
230
|
-
my_class = factory.share
|
231
|
-
my_class.set_flag(8)
|
232
|
-
extract_flag_shared_ptr(my_class))";
|
233
|
-
|
234
|
-
Object result = m.module_eval(code);
|
235
|
-
ASSERT_EQUAL(8, detail::From_Ruby<int>().convert(result));
|
236
|
-
}
|
237
|
-
|
238
|
-
TESTCASE(SharedPtrRefParameter)
|
239
|
-
{
|
240
|
-
MyClass::reset();
|
241
|
-
|
242
|
-
Module m = define_module("TestingModule");
|
243
|
-
|
244
|
-
std::string code = R"(factory = Factory.new
|
245
|
-
my_class = factory.share
|
246
|
-
my_class.set_flag(9)
|
247
|
-
extract_flag_shared_ptr_ref(my_class))";
|
248
|
-
|
249
|
-
Object result = m.module_eval(code);
|
250
|
-
ASSERT_EQUAL(9, detail::From_Ruby<int>().convert(result));
|
251
|
-
}
|
252
|
-
|
253
|
-
TESTCASE(SharedPtrDefaultParameter)
|
254
|
-
{
|
255
|
-
MyClass::reset();
|
256
|
-
|
257
|
-
Module m = define_module("TestingModule");
|
258
|
-
|
259
|
-
std::string code = R"(factory = Factory.new
|
260
|
-
my_class = factory.share
|
261
|
-
my_class.set_flag(7)
|
262
|
-
extract_flag_shared_ptr_with_default())";
|
263
|
-
|
264
|
-
Object result = m.module_eval(code);
|
265
|
-
// The default value kicks in and ignores any previous pointer
|
266
|
-
ASSERT_EQUAL(0, detail::From_Ruby<int>().convert(result));
|
267
|
-
}
|
268
|
-
|
269
|
-
TESTCASE(SharedPtrRefDefaultParameter)
|
270
|
-
{
|
271
|
-
MyClass::reset();
|
272
|
-
|
273
|
-
Module m = define_module("TestingModule");
|
274
|
-
|
275
|
-
std::string code = R"(factory = Factory.new
|
276
|
-
my_class = factory.share
|
277
|
-
my_class.set_flag(7)
|
278
|
-
extract_flag_shared_ptr_ref_with_default())";
|
279
|
-
|
280
|
-
Object result = m.module_eval(code);
|
281
|
-
// The default value kicks in and ignores any previous pointer
|
282
|
-
ASSERT_EQUAL(0, detail::From_Ruby<int>().convert(result));
|
283
|
-
}
|