rucy 0.3.7 → 0.3.8
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/.doc/ext/rucy/value.cpp +30 -0
- data/ChangeLog.md +7 -0
- data/VERSION +1 -1
- data/ext/rucy/value.cpp +34 -0
- data/include/rucy/exception.h +7 -3
- data/include/rucy/extension.h.erb +8 -0
- data/rucy.gemspec +1 -1
- data/src/exception.cpp +13 -6
- data/src/value.cpp.erb +33 -4
- data/test/test_value.rb +30 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afca4aa57caaccf5b8d75e2c2909ed31b380c03826ae3e38b5cf48398d068d96
|
4
|
+
data.tar.gz: e08567506ca4e42719de7e59521842b4602bfa7e1d47423f8e9a90efb0e89d8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3454ac8b968bb97b206ad3e71c1f31bddc17b46a303dcfe157be12077040edc072154ce83e515856b7afb575a2eec70c0324ccc7426393f2f94c82ef86a92dd9
|
7
|
+
data.tar.gz: c0c7eb8522874793fde72c2e339494f910cf99f8c041f57772ebf47e95fa448ad2835e30d25ab482c4e6ba899acfc256c03a253c5721a41af02505709d526cdb
|
data/.doc/ext/rucy/value.cpp
CHANGED
@@ -4,6 +4,30 @@
|
|
4
4
|
using namespace Rucy;
|
5
5
|
|
6
6
|
|
7
|
+
static
|
8
|
+
VALUE value_to_char(VALUE self, VALUE num)
|
9
|
+
{
|
10
|
+
return value(to<char>(num));
|
11
|
+
}
|
12
|
+
|
13
|
+
static
|
14
|
+
VALUE value_to_uchar(VALUE self, VALUE num)
|
15
|
+
{
|
16
|
+
return value(to<unsigned char>(num));
|
17
|
+
}
|
18
|
+
|
19
|
+
static
|
20
|
+
VALUE value_to_short(VALUE self, VALUE num)
|
21
|
+
{
|
22
|
+
return value(to<short>(num));
|
23
|
+
}
|
24
|
+
|
25
|
+
static
|
26
|
+
VALUE value_to_ushort(VALUE self, VALUE num)
|
27
|
+
{
|
28
|
+
return value(to<unsigned short>(num));
|
29
|
+
}
|
30
|
+
|
7
31
|
static
|
8
32
|
VALUE true_to_value(VALUE self)
|
9
33
|
{
|
@@ -56,9 +80,15 @@ Init_value ()
|
|
56
80
|
Module mRucy = rb_define_module("Rucy");
|
57
81
|
Module mTester = rb_define_module_under(mRucy, "Tester");
|
58
82
|
|
83
|
+
rb_define_method(mTester, "value_to_char", RUBY_METHOD_FUNC(value_to_char), 1);
|
84
|
+
rb_define_method(mTester, "value_to_uchar", RUBY_METHOD_FUNC(value_to_uchar), 1);
|
85
|
+
rb_define_method(mTester, "value_to_short", RUBY_METHOD_FUNC(value_to_short), 1);
|
86
|
+
rb_define_method(mTester, "value_to_ushort", RUBY_METHOD_FUNC(value_to_ushort), 1);
|
87
|
+
|
59
88
|
rb_define_method(mTester, "true_to_value", RUBY_METHOD_FUNC(true_to_value), -1);
|
60
89
|
rb_define_method(mTester, "false_to_value", RUBY_METHOD_FUNC(false_to_value), -1);
|
61
90
|
rb_define_method(mTester, "null_to_value", RUBY_METHOD_FUNC(NULL_to_value), -1);
|
91
|
+
|
62
92
|
rb_define_method(mTester, "nil_value", RUBY_METHOD_FUNC(nil_value), -1);
|
63
93
|
rb_define_method(mTester, "array_value", RUBY_METHOD_FUNC(array_value), -1);
|
64
94
|
}
|
data/ChangeLog.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
# rucy ChangeLog
|
2
2
|
|
3
3
|
|
4
|
+
## [v0.3.8] - 2025-05-22
|
5
|
+
|
6
|
+
- Catch std::out_of_range and std::range_error, then throw Ruby's IndexError and RangeError
|
7
|
+
- Rucy::value_to<>() checks the value range when converting a ruby value to char or short
|
8
|
+
- Add Rucy::range_error()
|
9
|
+
|
10
|
+
|
4
11
|
## [v0.3.7] - 2025-05-11
|
5
12
|
|
6
13
|
- Fixed complex overloading of array(Value,Value) and array(iterator,iterator) functions
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.8
|
data/ext/rucy/value.cpp
CHANGED
@@ -4,6 +4,34 @@
|
|
4
4
|
using namespace Rucy;
|
5
5
|
|
6
6
|
|
7
|
+
static
|
8
|
+
RUCY_DEF1(value_to_char, num)
|
9
|
+
{
|
10
|
+
return value(to<char>(num));
|
11
|
+
}
|
12
|
+
RUCY_END
|
13
|
+
|
14
|
+
static
|
15
|
+
RUCY_DEF1(value_to_uchar, num)
|
16
|
+
{
|
17
|
+
return value(to<unsigned char>(num));
|
18
|
+
}
|
19
|
+
RUCY_END
|
20
|
+
|
21
|
+
static
|
22
|
+
RUCY_DEF1(value_to_short, num)
|
23
|
+
{
|
24
|
+
return value(to<short>(num));
|
25
|
+
}
|
26
|
+
RUCY_END
|
27
|
+
|
28
|
+
static
|
29
|
+
RUCY_DEF1(value_to_ushort, num)
|
30
|
+
{
|
31
|
+
return value(to<unsigned short>(num));
|
32
|
+
}
|
33
|
+
RUCY_END
|
34
|
+
|
7
35
|
static
|
8
36
|
RUCY_DEFN(true_to_value)
|
9
37
|
{
|
@@ -61,9 +89,15 @@ Init_value ()
|
|
61
89
|
Module mRucy = define_module("Rucy");
|
62
90
|
Module mTester = mRucy.define_module("Tester");
|
63
91
|
|
92
|
+
mTester.define_method("value_to_char", value_to_char);
|
93
|
+
mTester.define_method("value_to_uchar", value_to_uchar);
|
94
|
+
mTester.define_method("value_to_short", value_to_short);
|
95
|
+
mTester.define_method("value_to_ushort", value_to_ushort);
|
96
|
+
|
64
97
|
mTester.define_method("true_to_value", true_to_value);
|
65
98
|
mTester.define_method("false_to_value", false_to_value);
|
66
99
|
mTester.define_method("null_to_value", NULL_to_value);
|
100
|
+
|
67
101
|
mTester.define_method("nil_value", nil_value);
|
68
102
|
mTester.define_method("array_value", array_value);
|
69
103
|
}
|
data/include/rucy/exception.h
CHANGED
@@ -74,15 +74,19 @@ namespace Rucy
|
|
74
74
|
int n6 = -1, int n7 = -1, int n8 = -1, int n9 = -1, int n10 = -1);
|
75
75
|
|
76
76
|
[[noreturn]]
|
77
|
-
void
|
77
|
+
void index_error (
|
78
78
|
const char* file, int line, const char* format = NULL, ...);
|
79
79
|
|
80
80
|
[[noreturn]]
|
81
|
-
void
|
81
|
+
void range_error (
|
82
82
|
const char* file, int line, const char* format = NULL, ...);
|
83
83
|
|
84
84
|
[[noreturn]]
|
85
|
-
void
|
85
|
+
void invalid_state_error (
|
86
|
+
const char* file, int line, const char* format = NULL, ...);
|
87
|
+
|
88
|
+
[[noreturn]]
|
89
|
+
void invalid_object_error (
|
86
90
|
const char* file, int line, const char* format = NULL, ...);
|
87
91
|
|
88
92
|
[[noreturn]]
|
@@ -222,6 +222,14 @@
|
|
222
222
|
{ \
|
223
223
|
RUCY_GOTO_RAISE(rb_exc_new2(rb_eArgError, e.what())); \
|
224
224
|
} \
|
225
|
+
catch (const std::out_of_range& e) \
|
226
|
+
{ \
|
227
|
+
RUCY_GOTO_RAISE(rb_exc_new2(rb_eIndexError, e.what())); \
|
228
|
+
} \
|
229
|
+
catch (const std::range_error& e) \
|
230
|
+
{ \
|
231
|
+
RUCY_GOTO_RAISE(rb_exc_new2(rb_eRangeError, e.what())); \
|
232
|
+
} \
|
225
233
|
catch (const std::exception& e) \
|
226
234
|
{ \
|
227
235
|
Xot::String text = e.what(), type = typeid(e).name(); \
|
data/rucy.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.platform = Gem::Platform::RUBY
|
26
26
|
s.required_ruby_version = '>= 3.0.0'
|
27
27
|
|
28
|
-
s.add_dependency 'xot', '~> 0.3.
|
28
|
+
s.add_dependency 'xot', '~> 0.3.8', '>= 0.3.8'
|
29
29
|
|
30
30
|
s.files = `git ls-files`.split $/
|
31
31
|
s.executables = s.files.grep(%r{^bin/}) {|f| File.basename f}
|
data/src/exception.cpp
CHANGED
@@ -102,24 +102,31 @@ namespace Rucy
|
|
102
102
|
}
|
103
103
|
|
104
104
|
void
|
105
|
-
|
105
|
+
index_error (const char* file, int line, const char* format, ...)
|
106
106
|
{
|
107
107
|
XOT_STRINGF(format, s);
|
108
|
-
raise(
|
108
|
+
raise(rb_eIndexError, Xot::error_text(file, line, s));
|
109
109
|
}
|
110
110
|
|
111
111
|
void
|
112
|
-
|
112
|
+
range_error (const char* file, int line, const char* format, ...)
|
113
113
|
{
|
114
114
|
XOT_STRINGF(format, s);
|
115
|
-
raise(
|
115
|
+
raise(rb_eRangeError, Xot::error_text(file, line, s));
|
116
116
|
}
|
117
117
|
|
118
118
|
void
|
119
|
-
|
119
|
+
invalid_state_error (const char* file, int line, const char* format, ...)
|
120
120
|
{
|
121
121
|
XOT_STRINGF(format, s);
|
122
|
-
raise(
|
122
|
+
raise(invalid_state_error_class(), Xot::error_text(file, line, s));
|
123
|
+
}
|
124
|
+
|
125
|
+
void
|
126
|
+
invalid_object_error (const char* file, int line, const char* format, ...)
|
127
|
+
{
|
128
|
+
XOT_STRINGF(format, s);
|
129
|
+
raise(invalid_object_error_class(), Xot::error_text(file, line, s));
|
123
130
|
}
|
124
131
|
|
125
132
|
void
|
data/src/value.cpp.erb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
#include "rucy/value.h"
|
3
3
|
|
4
4
|
|
5
|
+
#include <limits>
|
5
6
|
#include "rucy/function.h"
|
6
7
|
#include "rucy/exception.h"
|
7
8
|
#include "rucy/debug.h"
|
@@ -662,25 +663,53 @@ namespace Rucy
|
|
662
663
|
template <> char
|
663
664
|
value_to<char> (Value obj, bool convert)
|
664
665
|
{
|
665
|
-
|
666
|
+
int n = value_to<int>(obj, convert);
|
667
|
+
if (
|
668
|
+
n < std::numeric_limits<char>::min() ||
|
669
|
+
n > std::numeric_limits<char>::max())
|
670
|
+
{
|
671
|
+
range_error(__FILE__, __LINE__, "cannot cast '%d' to char");
|
672
|
+
}
|
673
|
+
return (char) n;
|
666
674
|
}
|
667
675
|
|
668
676
|
template <> unsigned char
|
669
677
|
value_to<unsigned char> (Value obj, bool convert)
|
670
678
|
{
|
671
|
-
|
679
|
+
int n = value_to<int>(obj, convert);
|
680
|
+
if (
|
681
|
+
n < std::numeric_limits<unsigned char>::min() ||
|
682
|
+
n > std::numeric_limits<unsigned char>::max())
|
683
|
+
{
|
684
|
+
range_error(__FILE__, __LINE__, "cannot cast '%d' to unsigned char");
|
685
|
+
}
|
686
|
+
return (unsigned char) n;
|
672
687
|
}
|
673
688
|
|
674
689
|
template <> short
|
675
690
|
value_to<short> (Value obj, bool convert)
|
676
691
|
{
|
677
|
-
|
692
|
+
int n = value_to<int>(obj, convert);
|
693
|
+
if (
|
694
|
+
n < std::numeric_limits<short>::min() ||
|
695
|
+
n > std::numeric_limits<short>::max())
|
696
|
+
{
|
697
|
+
range_error(__FILE__, __LINE__, "cannot cast '%d' to short");
|
698
|
+
}
|
699
|
+
return (short) n;
|
678
700
|
}
|
679
701
|
|
680
702
|
template <> unsigned short
|
681
703
|
value_to<unsigned short> (Value obj, bool convert)
|
682
704
|
{
|
683
|
-
|
705
|
+
int n = value_to<int>(obj, convert);
|
706
|
+
if (
|
707
|
+
n < std::numeric_limits<unsigned short>::min() ||
|
708
|
+
n > std::numeric_limits<unsigned short>::max())
|
709
|
+
{
|
710
|
+
range_error(__FILE__, __LINE__, "cannot cast '%d' to unsigned short");
|
711
|
+
}
|
712
|
+
return (unsigned short) n;
|
684
713
|
}
|
685
714
|
|
686
715
|
template <> long
|
data/test/test_value.rb
CHANGED
@@ -5,6 +5,36 @@ class TestFunction < Test::Unit::TestCase
|
|
5
5
|
|
6
6
|
include Rucy::Tester
|
7
7
|
|
8
|
+
def test_value_to_char()
|
9
|
+
assert_equal 0, value_to_char( 0)
|
10
|
+
assert_equal 127, value_to_char( 127)
|
11
|
+
assert_equal -128, value_to_char(-128)
|
12
|
+
assert_raise(RangeError) {value_to_char 128}
|
13
|
+
assert_raise(RangeError) {value_to_char -129}
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_value_to_uchar()
|
17
|
+
assert_equal 0, value_to_uchar( 0)
|
18
|
+
assert_equal 255, value_to_uchar(255)
|
19
|
+
assert_raise(RangeError) {value_to_uchar 256}
|
20
|
+
assert_raise(RangeError) {value_to_uchar -1}
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_value_to_short()
|
24
|
+
assert_equal 0, value_to_short( 0)
|
25
|
+
assert_equal 32767, value_to_short( 32767)
|
26
|
+
assert_equal -32768, value_to_short(-32768)
|
27
|
+
assert_raise(RangeError) {value_to_short 32768}
|
28
|
+
assert_raise(RangeError) {value_to_short -32769}
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_value_to_ushort()
|
32
|
+
assert_equal 0, value_to_ushort( 0)
|
33
|
+
assert_equal 65535, value_to_ushort(65535)
|
34
|
+
assert_raise(RangeError) {value_to_ushort 65536}
|
35
|
+
assert_raise(RangeError) {value_to_ushort -1}
|
36
|
+
end
|
37
|
+
|
8
38
|
def test_to_value()
|
9
39
|
assert_equal true, true_to_value
|
10
40
|
assert_equal false, false_to_value
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rucy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xordog
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-05-
|
11
|
+
date: 2025-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: xot
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.3.
|
19
|
+
version: 0.3.8
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.3.
|
22
|
+
version: 0.3.8
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.3.
|
29
|
+
version: 0.3.8
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.3.
|
32
|
+
version: 0.3.8
|
33
33
|
description: This library helps you to develop Ruby Extension by C++.
|
34
34
|
email: xordog@gmail.com
|
35
35
|
executables:
|