rice 4.3.3 → 4.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +63 -26
- data/README.md +7 -2
- data/Rakefile +7 -1
- data/include/rice/rice.hpp +7291 -4430
- data/include/rice/stl.hpp +769 -222
- data/lib/mkmf-rice.rb +37 -95
- data/rice/Address_Registration_Guard.hpp +72 -3
- data/rice/Arg.hpp +19 -5
- data/rice/Arg.ipp +24 -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 +74 -3
- data/rice/Data_Object.ipp +324 -32
- data/rice/Data_Type.hpp +215 -3
- data/rice/Data_Type.ipp +125 -64
- data/rice/Director.hpp +0 -2
- data/rice/Enum.hpp +4 -6
- data/rice/Enum.ipp +101 -57
- data/rice/Exception.hpp +62 -2
- data/rice/Exception.ipp +7 -12
- data/rice/JumpException.hpp +44 -0
- data/rice/JumpException.ipp +48 -0
- data/rice/MemoryView.hpp +11 -0
- data/rice/MemoryView.ipp +43 -0
- data/rice/Return.hpp +6 -26
- data/rice/Return.ipp +10 -16
- 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 +15 -5
- data/rice/detail/MethodInfo.ipp +78 -6
- data/rice/detail/Native.hpp +32 -0
- data/rice/detail/Native.ipp +129 -0
- data/rice/detail/NativeAttributeGet.hpp +51 -0
- data/rice/detail/NativeAttributeGet.ipp +51 -0
- data/rice/detail/NativeAttributeSet.hpp +43 -0
- data/rice/detail/NativeAttributeSet.ipp +82 -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 +20 -21
- data/rice/detail/NativeFunction.ipp +199 -64
- data/rice/detail/NativeIterator.hpp +8 -11
- data/rice/detail/NativeIterator.ipp +27 -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 +19 -0
- data/rice/detail/RubyType.ipp +187 -0
- data/rice/detail/TupleIterator.hpp +14 -0
- data/rice/detail/Type.hpp +5 -6
- data/rice/detail/Type.ipp +150 -33
- data/rice/detail/TypeRegistry.hpp +15 -7
- data/rice/detail/TypeRegistry.ipp +105 -12
- data/rice/detail/Wrapper.hpp +6 -5
- data/rice/detail/Wrapper.ipp +45 -23
- data/rice/detail/cpp_protect.hpp +5 -6
- data/rice/detail/default_allocation_func.ipp +0 -2
- data/rice/detail/from_ruby.hpp +37 -3
- data/rice/detail/from_ruby.ipp +911 -454
- data/rice/detail/ruby.hpp +18 -0
- data/rice/detail/to_ruby.hpp +41 -3
- data/rice/detail/to_ruby.ipp +437 -113
- data/rice/global_function.hpp +0 -4
- data/rice/global_function.ipp +1 -2
- data/rice/rice.hpp +105 -22
- data/rice/ruby_mark.hpp +4 -3
- data/rice/stl.hpp +4 -0
- data/test/embed_ruby.cpp +4 -1
- data/test/extconf.rb +2 -0
- data/test/ruby/test_multiple_extensions_same_class.rb +14 -14
- data/test/test_Address_Registration_Guard.cpp +5 -0
- data/test/test_Array.cpp +12 -1
- data/test/test_Attribute.cpp +103 -21
- data/test/test_Builtin_Object.cpp +5 -0
- data/test/test_Callback.cpp +231 -0
- data/test/test_Class.cpp +5 -31
- data/test/test_Constructor.cpp +69 -6
- data/test/test_Data_Object.cpp +9 -4
- data/test/test_Data_Type.cpp +428 -64
- data/test/test_Director.cpp +10 -5
- data/test/test_Enum.cpp +152 -40
- data/test/test_Exception.cpp +235 -0
- data/test/test_File.cpp +70 -0
- data/test/test_From_Ruby.cpp +542 -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 +5 -0
- data/test/test_JumpException.cpp +22 -0
- data/test/test_Keep_Alive.cpp +6 -1
- data/test/test_Keep_Alive_No_Wrapper.cpp +5 -0
- data/test/test_Memory_Management.cpp +5 -0
- data/test/test_Module.cpp +118 -64
- data/test/test_Native_Registry.cpp +2 -33
- data/test/test_Object.cpp +5 -0
- data/test/test_Overloads.cpp +631 -0
- data/test/test_Ownership.cpp +67 -4
- data/test/test_Proc.cpp +45 -0
- data/test/test_Self.cpp +5 -0
- data/test/test_Stl_Exception.cpp +109 -0
- data/test/test_Stl_Map.cpp +22 -8
- data/test/test_Stl_Optional.cpp +5 -0
- data/test/test_Stl_Pair.cpp +7 -2
- data/test/test_Stl_Reference_Wrapper.cpp +5 -0
- data/test/test_Stl_SmartPointer.cpp +210 -5
- data/test/test_Stl_String.cpp +5 -0
- data/test/test_Stl_String_View.cpp +5 -0
- data/test/test_Stl_Type.cpp +147 -0
- data/test/test_Stl_Unordered_Map.cpp +18 -7
- data/test/test_Stl_Variant.cpp +5 -0
- data/test/test_Stl_Vector.cpp +130 -8
- 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 +152 -0
- data/test/test_Tracking.cpp +1 -0
- data/test/test_Type.cpp +100 -0
- data/test/test_global_functions.cpp +53 -6
- data/test/unittest.cpp +8 -0
- metadata +37 -20
- 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/Identifier.hpp +0 -50
- data/rice/Identifier.ipp +0 -29
- 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_To_From_Ruby.cpp +0 -399
@@ -1,74 +1,49 @@
|
|
1
1
|
|
2
|
-
// Ruby 2.7 now includes a similarly named macro that uses templates to
|
3
|
-
// pick the right overload for the underlying function. That doesn't work
|
4
|
-
// for our cases because we are using this method dynamically and get a
|
5
|
-
// compilation error otherwise. This removes the macro and lets us fall
|
6
|
-
// back to the C-API underneath again.
|
7
|
-
#undef rb_define_method_id
|
8
|
-
|
9
|
-
#include "RubyFunction.hpp"
|
10
|
-
|
11
2
|
namespace Rice::detail
|
12
3
|
{
|
13
|
-
inline void NativeRegistry::add(VALUE klass, ID
|
4
|
+
inline void NativeRegistry::add(VALUE klass, ID methodId, std::unique_ptr<Native>& native)
|
14
5
|
{
|
15
6
|
if (rb_type(klass) == T_ICLASS)
|
16
7
|
{
|
17
8
|
klass = detail::protect(rb_class_of, klass);
|
18
9
|
}
|
19
10
|
|
20
|
-
|
21
|
-
|
22
|
-
{
|
23
|
-
const auto [k, d] = it->second;
|
11
|
+
// Create the key
|
12
|
+
std::pair<VALUE, ID> key = std::make_pair(klass, methodId);
|
24
13
|
|
25
|
-
|
26
|
-
|
27
|
-
std::get<1>(it->second) = callable;
|
28
|
-
return;
|
29
|
-
}
|
30
|
-
}
|
14
|
+
// Lookup items for method
|
15
|
+
std::vector<std::unique_ptr<Native>>& natives = this->natives_[key];
|
31
16
|
|
32
|
-
|
17
|
+
natives.push_back(std::move(native));
|
33
18
|
}
|
34
19
|
|
35
|
-
|
36
|
-
inline Return_T NativeRegistry::lookup()
|
20
|
+
inline void NativeRegistry::reset(VALUE klass)
|
37
21
|
{
|
38
|
-
|
39
|
-
VALUE klass;
|
40
|
-
if (!rb_frame_method_id_and_class(&method_id, &klass))
|
22
|
+
for (auto iter = this->natives_.begin(); iter != this->natives_.end();)
|
41
23
|
{
|
42
|
-
|
24
|
+
// Iter points to a std::pair<std::pair<VALUE, ID>, std::vector<NativeRegistryItem>
|
25
|
+
if (iter->first.first == klass)
|
26
|
+
{
|
27
|
+
iter = this->natives_.erase(iter);
|
28
|
+
}
|
29
|
+
else
|
30
|
+
{
|
31
|
+
++iter;
|
32
|
+
}
|
43
33
|
}
|
44
|
-
|
45
|
-
return this->lookup<Return_T>(klass, method_id);
|
46
34
|
}
|
47
|
-
|
48
|
-
|
49
|
-
inline Return_T NativeRegistry::lookup(VALUE klass, ID method_id)
|
35
|
+
|
36
|
+
inline const std::vector<std::unique_ptr<Native>>& NativeRegistry::lookup(VALUE klass, ID methodId)
|
50
37
|
{
|
51
38
|
if (rb_type(klass) == T_ICLASS)
|
52
39
|
{
|
53
40
|
klass = detail::protect(rb_class_of, klass);
|
54
41
|
}
|
55
42
|
|
56
|
-
|
57
|
-
|
58
|
-
{
|
59
|
-
const auto [k, d] = it->second;
|
60
|
-
|
61
|
-
if (k == klass)
|
62
|
-
{
|
63
|
-
auto* ptr = std::any_cast<Return_T>(&d);
|
64
|
-
if (!ptr)
|
65
|
-
{
|
66
|
-
rb_raise(rb_eRuntimeError, "Unexpected return type for %s#%s", rb_class2name(klass), rb_id2name(method_id));
|
67
|
-
}
|
68
|
-
return *ptr;
|
69
|
-
}
|
70
|
-
}
|
43
|
+
// Create the key
|
44
|
+
std::pair<VALUE, ID> key = std::make_pair(klass, methodId);
|
71
45
|
|
72
|
-
|
46
|
+
// Lookup items for method
|
47
|
+
return this->natives_[key];
|
73
48
|
}
|
74
49
|
}
|
@@ -0,0 +1,85 @@
|
|
1
|
+
namespace Rice::detail
|
2
|
+
{
|
3
|
+
// Note Return_T(Arg_Ts...) is intentional versus Return_T(*)(Arg_Ts...). That is
|
4
|
+
// because the Type machinery strips all pointers/references/const/val etc to avoid
|
5
|
+
// having an explosion of Type definitions
|
6
|
+
template<typename Return_T, typename ...Arg_Ts>
|
7
|
+
struct Type<Return_T(Arg_Ts...)>
|
8
|
+
{
|
9
|
+
static bool verify()
|
10
|
+
{
|
11
|
+
return true;
|
12
|
+
}
|
13
|
+
};
|
14
|
+
|
15
|
+
// Wraps a C++ function as a Ruby proc
|
16
|
+
template<typename Return_T, typename ...Arg_Ts>
|
17
|
+
class To_Ruby<Return_T(*)(Arg_Ts...)>
|
18
|
+
{
|
19
|
+
public:
|
20
|
+
using Proc_T = Return_T(*)(Arg_Ts...);
|
21
|
+
|
22
|
+
VALUE convert(Proc_T proc)
|
23
|
+
{
|
24
|
+
using NativeFunction_T = NativeFunction<void, Proc_T, false>;
|
25
|
+
auto native = new NativeFunction_T(proc);
|
26
|
+
VALUE result = rb_proc_new(NativeFunction_T::procEntry, (VALUE)native);
|
27
|
+
|
28
|
+
// Tie the lifetime of the NativeCallback C++ instance to the lifetime of the Ruby proc object
|
29
|
+
VALUE finalizer = rb_proc_new(NativeFunction_T::finalizerCallback, (VALUE)native);
|
30
|
+
rb_define_finalizer(result, finalizer);
|
31
|
+
|
32
|
+
return result;
|
33
|
+
}
|
34
|
+
};
|
35
|
+
|
36
|
+
// Makes a Ruby proc callable as C callback
|
37
|
+
template<typename Return_T, typename ...Arg_Ts>
|
38
|
+
class From_Ruby<Return_T(*)(Arg_Ts...)>
|
39
|
+
{
|
40
|
+
public:
|
41
|
+
using Callback_T = Return_T(*)(Arg_Ts...);
|
42
|
+
|
43
|
+
From_Ruby() = default;
|
44
|
+
|
45
|
+
explicit From_Ruby(Arg* arg) : arg_(arg)
|
46
|
+
{
|
47
|
+
}
|
48
|
+
|
49
|
+
Convertible is_convertible(VALUE value)
|
50
|
+
{
|
51
|
+
if (protect(rb_obj_is_proc, value) == Qtrue || protect(rb_proc_lambda_p, value))
|
52
|
+
{
|
53
|
+
return Convertible::Exact;
|
54
|
+
}
|
55
|
+
else
|
56
|
+
{
|
57
|
+
return Convertible::None;
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
#ifdef HAVE_LIBFFI
|
62
|
+
Callback_T convert(VALUE value)
|
63
|
+
{
|
64
|
+
using NativeCallback_T = NativeCallbackFFI<Return_T(*)(Arg_Ts...)>;
|
65
|
+
NativeCallback_T* nativeCallback = new NativeCallback_T(value);
|
66
|
+
|
67
|
+
// Tie the lifetime of the NativeCallback C++ instance to the lifetime of the Ruby proc object
|
68
|
+
VALUE finalizer = rb_proc_new(NativeCallback_T::finalizerCallback, (VALUE)nativeCallback);
|
69
|
+
rb_define_finalizer(value, finalizer);
|
70
|
+
|
71
|
+
return nativeCallback->callback();
|
72
|
+
}
|
73
|
+
#else
|
74
|
+
Callback_T convert(VALUE value)
|
75
|
+
{
|
76
|
+
using NativeCallback_T = NativeCallbackSimple<Return_T(*)(Arg_Ts...)>;
|
77
|
+
NativeCallback_T::proc = value;
|
78
|
+
return &NativeCallback_T::callback;
|
79
|
+
}
|
80
|
+
#endif
|
81
|
+
|
82
|
+
private:
|
83
|
+
Arg* arg_ = nullptr;
|
84
|
+
};
|
85
|
+
}
|
data/rice/detail/Registries.hpp
CHANGED
@@ -1,11 +1,6 @@
|
|
1
1
|
#ifndef Rice__Registries__hpp_
|
2
2
|
#define Rice__Registries__hpp_
|
3
3
|
|
4
|
-
#include "HandlerRegistry.hpp"
|
5
|
-
#include "InstanceRegistry.hpp"
|
6
|
-
#include "NativeRegistry.hpp"
|
7
|
-
#include "TypeRegistry.hpp"
|
8
|
-
|
9
4
|
namespace Rice::detail
|
10
5
|
{
|
11
6
|
class Registries
|
@@ -21,6 +16,4 @@ namespace Rice::detail
|
|
21
16
|
};
|
22
17
|
}
|
23
18
|
|
24
|
-
#include "Registries.ipp"
|
25
|
-
|
26
19
|
#endif // Rice__Registries__hpp_
|
data/rice/detail/Registries.ipp
CHANGED
@@ -2,22 +2,4 @@ namespace Rice::detail
|
|
2
2
|
{
|
3
3
|
//Initialize static variables here.
|
4
4
|
inline Registries Registries::instance;
|
5
|
-
|
6
|
-
// TODO - Big hack here but this code is dependent on internals
|
7
|
-
template<typename T>
|
8
|
-
bool Type<T>::verify()
|
9
|
-
{
|
10
|
-
// Use intrinsic_type so that we don't have to define specializations
|
11
|
-
// for pointers, references, const, etc.
|
12
|
-
using Intrinsic_T = intrinsic_type<T>;
|
13
|
-
|
14
|
-
if constexpr (std::is_fundamental_v<Intrinsic_T>)
|
15
|
-
{
|
16
|
-
return true;
|
17
|
-
}
|
18
|
-
else
|
19
|
-
{
|
20
|
-
return Registries::instance.types.verifyDefined<Intrinsic_T>();
|
21
|
-
}
|
22
|
-
}
|
23
5
|
}
|
@@ -1,8 +1,6 @@
|
|
1
1
|
#ifndef Rice__detail__ruby_function__hpp_
|
2
2
|
#define Rice__detail__ruby_function__hpp_
|
3
3
|
|
4
|
-
#include "ruby.hpp"
|
5
|
-
|
6
4
|
namespace Rice::detail
|
7
5
|
{
|
8
6
|
/* This is functor class that wraps calls to a Ruby C API method. It is needed because
|
@@ -29,6 +27,5 @@ namespace Rice::detail
|
|
29
27
|
template<typename Function_T, typename ...Arg_Ts>
|
30
28
|
auto protect(Function_T func, Arg_Ts...args);
|
31
29
|
}
|
32
|
-
#include "RubyFunction.ipp"
|
33
30
|
|
34
31
|
#endif // Rice__detail__ruby_function__hpp_
|
@@ -1,5 +1,3 @@
|
|
1
|
-
#include "Jump_Tag.hpp"
|
2
|
-
#include "../Exception_defn.hpp"
|
3
1
|
|
4
2
|
#include <any>
|
5
3
|
|
@@ -14,9 +12,6 @@ namespace Rice::detail
|
|
14
12
|
template<typename Function_T, typename...Arg_Ts>
|
15
13
|
inline typename RubyFunction<Function_T, Arg_Ts...>::Return_T RubyFunction<Function_T, Arg_Ts...>::operator()()
|
16
14
|
{
|
17
|
-
const int TAG_RAISE = 0x6; // From Ruby header files
|
18
|
-
int state = 0;
|
19
|
-
|
20
15
|
// Setup a thread local variable to capture the result of the Ruby function call.
|
21
16
|
// We use thread_local because the lambda has to be captureless so it can
|
22
17
|
// be converted to a function pointer callable by C.
|
@@ -45,10 +40,11 @@ namespace Rice::detail
|
|
45
40
|
};
|
46
41
|
|
47
42
|
// Now call rb_protect which will invoke the callback lambda above
|
43
|
+
int state = (int)JumpException::RUBY_TAG_NONE;
|
48
44
|
rb_protect(callback, (VALUE)this, &state);
|
49
45
|
|
50
46
|
// Did anything go wrong?
|
51
|
-
if (state ==
|
47
|
+
if (state == JumpException::RUBY_TAG_NONE)
|
52
48
|
{
|
53
49
|
if constexpr (!std::is_same_v<Return_T, void>)
|
54
50
|
{
|
@@ -58,14 +54,14 @@ namespace Rice::detail
|
|
58
54
|
else
|
59
55
|
{
|
60
56
|
VALUE err = rb_errinfo();
|
61
|
-
if (state ==
|
57
|
+
if (state == JumpException::RUBY_TAG_RAISE && RB_TEST(err))
|
62
58
|
{
|
63
59
|
rb_set_errinfo(Qnil);
|
64
60
|
throw Rice::Exception(err);
|
65
61
|
}
|
66
62
|
else
|
67
63
|
{
|
68
|
-
throw
|
64
|
+
throw Rice::JumpException((Rice::JumpException::ruby_tag_type)state);
|
69
65
|
}
|
70
66
|
}
|
71
67
|
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#ifndef Rice__detail__ruby__type__hpp_
|
2
|
+
#define Rice__detail__ruby__type__hpp_
|
3
|
+
|
4
|
+
#include <set>
|
5
|
+
|
6
|
+
namespace Rice::detail
|
7
|
+
{
|
8
|
+
template <typename T>
|
9
|
+
class RubyType
|
10
|
+
{
|
11
|
+
public:
|
12
|
+
static std::set<ruby_value_type> types();
|
13
|
+
static std::set<ruby_value_type> convertibleFrom();
|
14
|
+
static T(*converter)(VALUE);
|
15
|
+
static std::string packTemplate;
|
16
|
+
};
|
17
|
+
}
|
18
|
+
|
19
|
+
#endif // Rice__detail__ruby__type__hpp_
|
@@ -0,0 +1,187 @@
|
|
1
|
+
namespace Rice::detail
|
2
|
+
{
|
3
|
+
template<>
|
4
|
+
class RubyType<bool>
|
5
|
+
{
|
6
|
+
public:
|
7
|
+
using FromRuby_T = bool(*)(VALUE);
|
8
|
+
|
9
|
+
static inline FromRuby_T fromRuby = RB_TEST;
|
10
|
+
static inline std::set<ruby_value_type> Exact = { RUBY_T_TRUE, RUBY_T_FALSE };
|
11
|
+
static inline std::set<ruby_value_type> Castable = { RUBY_T_NIL };
|
12
|
+
static inline std::set<ruby_value_type> Narrowable = { };
|
13
|
+
static inline std::string packTemplate = "not supported";
|
14
|
+
};
|
15
|
+
|
16
|
+
template<>
|
17
|
+
class RubyType<char>
|
18
|
+
{
|
19
|
+
public:
|
20
|
+
using FromRuby_T = char(*)(VALUE);
|
21
|
+
|
22
|
+
static inline FromRuby_T fromRuby = rb_num2char_inline;
|
23
|
+
static inline std::set<ruby_value_type> Exact = { };
|
24
|
+
static inline std::set<ruby_value_type> Castable = { RUBY_T_STRING };
|
25
|
+
static inline std::set<ruby_value_type> Narrowable = { RUBY_T_FIXNUM };
|
26
|
+
static inline std::string packTemplate = CHAR_MIN < 0 ? "c*" : "C*";
|
27
|
+
};
|
28
|
+
|
29
|
+
template<>
|
30
|
+
class RubyType<signed char>
|
31
|
+
{
|
32
|
+
public:
|
33
|
+
// Hack - need to later typecast
|
34
|
+
using FromRuby_T = char(*)(VALUE);
|
35
|
+
|
36
|
+
static inline FromRuby_T fromRuby = rb_num2char_inline;
|
37
|
+
static inline std::set<ruby_value_type> Exact = { };
|
38
|
+
static inline std::set<ruby_value_type> Castable = { RUBY_T_STRING };
|
39
|
+
static inline std::set<ruby_value_type> Narrowable = { RUBY_T_FIXNUM };
|
40
|
+
static inline std::string packTemplate = "c*";
|
41
|
+
};
|
42
|
+
|
43
|
+
template<>
|
44
|
+
class RubyType<unsigned char>
|
45
|
+
{
|
46
|
+
public:
|
47
|
+
// Hack - need to later typecast, although char's in ruby are unsigned
|
48
|
+
using FromRuby_T = char(*)(VALUE);
|
49
|
+
|
50
|
+
static inline FromRuby_T fromRuby = rb_num2char_inline;
|
51
|
+
static inline std::set<ruby_value_type> Exact = { };
|
52
|
+
static inline std::set<ruby_value_type> Castable = { RUBY_T_STRING };
|
53
|
+
static inline std::set<ruby_value_type> Narrowable = { RUBY_T_FIXNUM };
|
54
|
+
static inline std::string packTemplate = "C*";
|
55
|
+
};
|
56
|
+
|
57
|
+
template<>
|
58
|
+
class RubyType<short>
|
59
|
+
{
|
60
|
+
public:
|
61
|
+
using FromRuby_T = short(*)(VALUE);
|
62
|
+
|
63
|
+
static inline FromRuby_T fromRuby = rb_num2short_inline;
|
64
|
+
static inline std::set<ruby_value_type> Exact = { };
|
65
|
+
static inline std::set<ruby_value_type> Castable = { };
|
66
|
+
static inline std::set<ruby_value_type> Narrowable = { RUBY_T_FIXNUM };
|
67
|
+
static inline std::string packTemplate = "s*";
|
68
|
+
};
|
69
|
+
|
70
|
+
template<>
|
71
|
+
class RubyType<unsigned short>
|
72
|
+
{
|
73
|
+
public:
|
74
|
+
using FromRuby_T = unsigned short(*)(VALUE);
|
75
|
+
|
76
|
+
static inline FromRuby_T fromRuby = rb_num2ushort;
|
77
|
+
static inline std::set<ruby_value_type> Exact = { };
|
78
|
+
static inline std::set<ruby_value_type> Castable = { };
|
79
|
+
static inline std::set<ruby_value_type> Narrowable = { RUBY_T_FIXNUM };
|
80
|
+
static inline std::string packTemplate = "S*";
|
81
|
+
};
|
82
|
+
|
83
|
+
template<>
|
84
|
+
class RubyType<int>
|
85
|
+
{
|
86
|
+
public:
|
87
|
+
using FromRuby_T = int(*)(VALUE);
|
88
|
+
|
89
|
+
static inline FromRuby_T fromRuby = rb_num2int_inline;
|
90
|
+
static inline std::set<ruby_value_type> Exact = { RUBY_T_FIXNUM };
|
91
|
+
static inline std::set<ruby_value_type> Castable = { };
|
92
|
+
static inline std::set<ruby_value_type> Narrowable = { };
|
93
|
+
static inline std::string packTemplate = "i*";
|
94
|
+
};
|
95
|
+
|
96
|
+
template<>
|
97
|
+
class RubyType<unsigned int>
|
98
|
+
{
|
99
|
+
public:
|
100
|
+
using FromRuby_T = unsigned int(*)(VALUE);
|
101
|
+
|
102
|
+
static inline FromRuby_T fromRuby = RB_NUM2UINT;
|
103
|
+
static inline std::set<ruby_value_type> Exact = { RUBY_T_FIXNUM };
|
104
|
+
static inline std::set<ruby_value_type> Castable = { };
|
105
|
+
static inline std::set<ruby_value_type> Narrowable = { };
|
106
|
+
static inline std::string packTemplate = "I*";
|
107
|
+
};
|
108
|
+
|
109
|
+
template<>
|
110
|
+
class RubyType<long>
|
111
|
+
{
|
112
|
+
public:
|
113
|
+
using FromRuby_T = long(*)(VALUE);
|
114
|
+
|
115
|
+
static inline FromRuby_T fromRuby = rb_num2long_inline;
|
116
|
+
static inline std::set<ruby_value_type> Exact = { RUBY_T_FIXNUM };
|
117
|
+
static inline std::set<ruby_value_type> Castable = { };
|
118
|
+
static inline std::set<ruby_value_type> Narrowable = { };
|
119
|
+
static inline std::string packTemplate = "l_*";
|
120
|
+
};
|
121
|
+
|
122
|
+
template<>
|
123
|
+
class RubyType<unsigned long>
|
124
|
+
{
|
125
|
+
public:
|
126
|
+
using FromRuby_T = unsigned long(*)(VALUE);
|
127
|
+
|
128
|
+
static inline FromRuby_T fromRuby = rb_num2ulong_inline;
|
129
|
+
static inline std::set<ruby_value_type> Exact = { RUBY_T_FIXNUM };
|
130
|
+
static inline std::set<ruby_value_type> Castable = { };
|
131
|
+
static inline std::set<ruby_value_type> Narrowable = { };
|
132
|
+
static inline std::string packTemplate = "L_*";
|
133
|
+
};
|
134
|
+
|
135
|
+
template<>
|
136
|
+
class RubyType<long long>
|
137
|
+
{
|
138
|
+
public:
|
139
|
+
using FromRuby_T = long long(*)(VALUE);
|
140
|
+
|
141
|
+
static inline FromRuby_T fromRuby = rb_num2ll_inline;
|
142
|
+
static inline std::set<ruby_value_type> Exact = { RUBY_T_FIXNUM, RUBY_T_BIGNUM };
|
143
|
+
static inline std::set<ruby_value_type> Castable = { };
|
144
|
+
static inline std::set<ruby_value_type> Narrowable = { };
|
145
|
+
static inline std::string packTemplate = "q_*";
|
146
|
+
};
|
147
|
+
|
148
|
+
template<>
|
149
|
+
class RubyType<unsigned long long>
|
150
|
+
{
|
151
|
+
public:
|
152
|
+
using FromRuby_T = unsigned long long(*)(VALUE);
|
153
|
+
|
154
|
+
static inline FromRuby_T fromRuby = RB_NUM2ULL;
|
155
|
+
static inline std::set<ruby_value_type> Exact = { RUBY_T_FIXNUM, RUBY_T_BIGNUM };
|
156
|
+
static inline std::set<ruby_value_type> Castable = { };
|
157
|
+
static inline std::set<ruby_value_type> Narrowable = { };
|
158
|
+
static inline std::string packTemplate = "Q_*";
|
159
|
+
};
|
160
|
+
|
161
|
+
|
162
|
+
template<>
|
163
|
+
class RubyType<float>
|
164
|
+
{
|
165
|
+
public:
|
166
|
+
using FromRuby_T = double(*)(VALUE);
|
167
|
+
|
168
|
+
static inline FromRuby_T fromRuby = rb_num2dbl;
|
169
|
+
static inline std::set<ruby_value_type> Exact = { };
|
170
|
+
static inline std::set<ruby_value_type> Castable = { RUBY_T_FIXNUM };
|
171
|
+
static inline std::set<ruby_value_type> Narrowable = { RUBY_T_FLOAT };
|
172
|
+
static inline std::string packTemplate = "f*";
|
173
|
+
};
|
174
|
+
|
175
|
+
template<>
|
176
|
+
class RubyType<double>
|
177
|
+
{
|
178
|
+
public:
|
179
|
+
using FromRuby_T = double(*)(VALUE);
|
180
|
+
|
181
|
+
static inline FromRuby_T fromRuby = rb_num2dbl;
|
182
|
+
static inline std::set<ruby_value_type> Exact = { RUBY_T_FLOAT };
|
183
|
+
static inline std::set<ruby_value_type> Castable = { RUBY_T_FIXNUM, RUBY_T_BIGNUM };
|
184
|
+
static inline std::set<ruby_value_type> Narrowable = { };
|
185
|
+
static inline std::string packTemplate = "d*";
|
186
|
+
};
|
187
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#ifndef Rice__stl__tuple_iterator__hpp_
|
2
|
+
#define Rice__stl__tuple_iterator__hpp_
|
3
|
+
|
4
|
+
// See https://www.cppstories.com/2022/tuple-iteration-apply/
|
5
|
+
template <typename Tuple_T, typename Function_T>
|
6
|
+
void for_each_tuple(Tuple_T&& tuple, Function_T&& callable)
|
7
|
+
{
|
8
|
+
std::apply([&callable](auto&& ...args)
|
9
|
+
{
|
10
|
+
(callable(std::forward<decltype(args)>(args)), ...);
|
11
|
+
}, std::forward<Tuple_T>(tuple));
|
12
|
+
}
|
13
|
+
|
14
|
+
#endif // Rice__stl__tuple_iterator__hpp_
|
data/rice/detail/Type.hpp
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
#ifndef Rice__Type__hpp_
|
2
2
|
#define Rice__Type__hpp_
|
3
3
|
|
4
|
-
#include <
|
5
|
-
#include <typeinfo>
|
6
|
-
#include "../traits/rice_traits.hpp"
|
4
|
+
#include <regex>
|
7
5
|
|
8
6
|
namespace Rice::detail
|
9
7
|
{
|
@@ -15,7 +13,10 @@ namespace Rice::detail
|
|
15
13
|
|
16
14
|
// Return the name of a type
|
17
15
|
std::string typeName(const std::type_info& typeInfo);
|
18
|
-
std::string
|
16
|
+
std::string typeName(const std::type_index& typeIndex);
|
17
|
+
std::string makeClassName(const std::string& typeInfoName);
|
18
|
+
std::string findGroup(std::string& string, size_t start = 0);
|
19
|
+
void replaceAll(std::string& string, std::regex regex, std::string replacement);
|
19
20
|
|
20
21
|
template<typename T>
|
21
22
|
void verifyType();
|
@@ -24,6 +25,4 @@ namespace Rice::detail
|
|
24
25
|
void verifyTypes();
|
25
26
|
}
|
26
27
|
|
27
|
-
#include "Type.ipp"
|
28
|
-
|
29
28
|
#endif // Rice__Type__hpp_
|