rucy 0.1.6 → 0.1.7
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 +7 -0
- data/.doc/ext/rucy/class.cpp +48 -56
- data/.doc/ext/rucy/exception.cpp +1 -1
- data/.doc/ext/rucy/function.cpp +14 -2
- data/.doc/ext/rucy/struct.cpp +2 -20
- data/.doc/ext/rucy/tester.cpp +7 -19
- data/.doc/ext/rucy/value.cpp +23 -1
- data/{README → README.md} +0 -0
- data/Rakefile +7 -5
- data/VERSION +1 -1
- data/bin/rucy2rdoc +8 -5
- data/ext/rucy/class.cpp +78 -87
- data/ext/rucy/class.h +12 -6
- data/ext/rucy/exception.cpp +17 -17
- data/ext/rucy/extconf.rb +11 -52
- data/ext/rucy/function.cpp +25 -12
- data/ext/rucy/struct.cpp +8 -26
- data/ext/rucy/tester.cpp +11 -24
- data/ext/rucy/value.cpp +32 -9
- data/include/rucy/class.h +5 -3
- data/include/rucy/exception.h +17 -71
- data/include/rucy/extension.h.erb +489 -0
- data/include/rucy/function.h.erb +20 -34
- data/include/rucy/module.h.erb +20 -14
- data/include/rucy/ruby.h +23 -0
- data/include/rucy/rucy.h +7 -66
- data/include/rucy/symbol.h +11 -11
- data/include/rucy/value.h.erb +98 -176
- data/include/rucy.h +9 -1
- data/lib/rucy/module.rb +11 -7
- data/rucy.gemspec +3 -4
- data/src/class.cpp +34 -6
- data/src/exception.cpp +69 -54
- data/src/extension.cpp +59 -0
- data/src/function.cpp.erb +17 -25
- data/src/module.cpp.erb +25 -16
- data/src/rucy.cpp +15 -25
- data/src/symbol.cpp +18 -17
- data/src/value.cpp.erb +374 -175
- data/task/doc.rake +5 -0
- data/test/helper.rb +6 -2
- data/test/test_class.rb +27 -20
- data/test/test_function.rb +6 -0
- data/test/test_value.rb +4 -0
- metadata +29 -39
- data/.gitignore +0 -22
- data/ChangeLog +0 -13
- data/include/rucy/defs.h.erb +0 -76
- data/include/rucy/extension.h +0 -206
data/task/doc.rake
CHANGED
data/test/helper.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
%w[../xot .]
|
5
|
+
.map {|s| File.expand_path "../../#{s}/lib", __FILE__}
|
6
|
+
.each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
6
7
|
|
7
8
|
require 'test/unit'
|
9
|
+
require 'xot/test'
|
8
10
|
require 'rucy'
|
9
11
|
require 'rucy/tester'
|
12
|
+
|
13
|
+
include Xot::Test
|
data/test/test_class.rb
CHANGED
@@ -45,6 +45,12 @@ class TestClass < Test::Unit::TestCase
|
|
45
45
|
Sub.new_raw *args
|
46
46
|
end
|
47
47
|
|
48
|
+
def last_log (pattern = nil)
|
49
|
+
logs = Rucy::Tester.all_logs
|
50
|
+
logs.select! {|o| o =~ pattern} if pattern
|
51
|
+
logs.last
|
52
|
+
end
|
53
|
+
|
48
54
|
def test_is_kind_of_base ()
|
49
55
|
assert_kind_of Base, base
|
50
56
|
assert_kind_of Base, base_raw
|
@@ -58,13 +64,13 @@ class TestClass < Test::Unit::TestCase
|
|
58
64
|
assert_kind_of Sub, temp
|
59
65
|
assert_kind_of Temp, temp
|
60
66
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
67
|
+
assert_not base .kind_of?(Sub)
|
68
|
+
assert_not base_raw .kind_of?(Sub)
|
69
|
+
assert_not base .kind_of?(Temp)
|
70
|
+
assert_not base_raw .kind_of?(Temp)
|
65
71
|
|
66
|
-
|
67
|
-
|
72
|
+
assert_not sub .kind_of?(Temp)
|
73
|
+
assert_not sub_raw.kind_of?(Temp)
|
68
74
|
end
|
69
75
|
|
70
76
|
def test_name ()
|
@@ -128,34 +134,35 @@ class TestClass < Test::Unit::TestCase
|
|
128
134
|
end
|
129
135
|
|
130
136
|
def test_gc ()
|
131
|
-
def
|
137
|
+
def simple_objs (name, n = 10) ([nil] * n).map {SimpleObj.new name} end
|
138
|
+
def gc (n = 10) n.times {GC.start}; print '' end
|
132
139
|
rt = Rucy::Tester
|
133
140
|
|
134
141
|
gc
|
135
142
|
rt.clear_logs
|
136
143
|
|
137
|
-
|
138
|
-
assert_equal '
|
144
|
+
objs = simple_objs 1
|
145
|
+
assert_equal 'SimpleObj(1)', last_log(/1/)
|
139
146
|
gc
|
140
|
-
assert_equal '
|
141
|
-
|
147
|
+
assert_equal 'SimpleObj(1)', last_log(/1/)
|
148
|
+
objs = nil
|
142
149
|
gc
|
143
|
-
assert_equal '~
|
150
|
+
assert_equal '~SimpleObj(1)', last_log(/1/)
|
144
151
|
|
145
152
|
gc
|
146
153
|
rt.clear_logs
|
147
154
|
|
148
|
-
|
149
|
-
assert_equal '
|
150
|
-
|
155
|
+
objs = simple_objs 2
|
156
|
+
assert_equal 'SimpleObj(2)', last_log(/2/)
|
157
|
+
SimpleObj.set_refs objs
|
151
158
|
gc
|
152
|
-
assert_equal '
|
153
|
-
|
159
|
+
assert_equal 'SimpleObj(2)', last_log(/2/)
|
160
|
+
objs = nil
|
154
161
|
gc
|
155
|
-
assert_equal '
|
156
|
-
|
162
|
+
assert_equal 'SimpleObj(2)', last_log(/2/)
|
163
|
+
SimpleObj.clear_refs
|
157
164
|
gc
|
158
|
-
assert_equal '~
|
165
|
+
assert_equal '~SimpleObj(2)', last_log(/2/)
|
159
166
|
end
|
160
167
|
|
161
168
|
end# TestClass
|
data/test/test_function.rb
CHANGED
@@ -28,4 +28,10 @@ class TestFunction < Test::Unit::TestCase
|
|
28
28
|
assert_kind_of String, return_string
|
29
29
|
end
|
30
30
|
|
31
|
+
def test_check_arg_count ()
|
32
|
+
assert_equal :ok, arg_count_must_1(:arg1)
|
33
|
+
assert_raise(ArgumentError) {arg_count_must_1}
|
34
|
+
assert_raises(ArgumentError) {arg_count_must_1 :arg1, :arg2}
|
35
|
+
end
|
36
|
+
|
31
37
|
end# TestFunction
|
data/test/test_value.rb
CHANGED
@@ -13,6 +13,10 @@ class TestFunction < Test::Unit::TestCase
|
|
13
13
|
assert_equal false, false_to_value
|
14
14
|
assert_equal nil, null_to_value
|
15
15
|
assert_equal nil, nil_value
|
16
|
+
assert_equal [1], array_value(1)
|
17
|
+
assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], array_value(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
|
18
|
+
assert_raise(ArgumentError) {array_value}
|
19
|
+
assert_raise(ArgumentError) {array_value 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
|
16
20
|
end
|
17
21
|
|
18
22
|
end# TestFunction
|
metadata
CHANGED
@@ -1,62 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rucy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.7
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- snori
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-08-07 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: xot
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: gemcutter
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
description: This library helps you to develop Ruby Extension by C++.
|
@@ -66,17 +59,14 @@ executables:
|
|
66
59
|
extensions:
|
67
60
|
- Rakefile
|
68
61
|
extra_rdoc_files:
|
69
|
-
-
|
70
|
-
- .doc/ext/rucy/
|
71
|
-
- .doc/ext/rucy/
|
72
|
-
- .doc/ext/rucy/
|
73
|
-
- .doc/ext/rucy/
|
74
|
-
- .doc/ext/rucy/
|
75
|
-
- .doc/ext/rucy/value.cpp
|
62
|
+
- ".doc/ext/rucy/class.cpp"
|
63
|
+
- ".doc/ext/rucy/exception.cpp"
|
64
|
+
- ".doc/ext/rucy/function.cpp"
|
65
|
+
- ".doc/ext/rucy/struct.cpp"
|
66
|
+
- ".doc/ext/rucy/tester.cpp"
|
67
|
+
- ".doc/ext/rucy/value.cpp"
|
76
68
|
files:
|
77
|
-
- .
|
78
|
-
- ChangeLog
|
79
|
-
- README
|
69
|
+
- README.md
|
80
70
|
- Rakefile
|
81
71
|
- VERSION
|
82
72
|
- bin/rucy2rdoc
|
@@ -91,11 +81,11 @@ files:
|
|
91
81
|
- ext/rucy/value.cpp
|
92
82
|
- include/rucy.h
|
93
83
|
- include/rucy/class.h
|
94
|
-
- include/rucy/defs.h.erb
|
95
84
|
- include/rucy/exception.h
|
96
|
-
- include/rucy/extension.h
|
85
|
+
- include/rucy/extension.h.erb
|
97
86
|
- include/rucy/function.h.erb
|
98
87
|
- include/rucy/module.h.erb
|
88
|
+
- include/rucy/ruby.h
|
99
89
|
- include/rucy/rucy.h
|
100
90
|
- include/rucy/symbol.h
|
101
91
|
- include/rucy/value.h.erb
|
@@ -104,6 +94,7 @@ files:
|
|
104
94
|
- rucy.gemspec
|
105
95
|
- src/class.cpp
|
106
96
|
- src/exception.cpp
|
97
|
+
- src/extension.cpp
|
107
98
|
- src/function.cpp.erb
|
108
99
|
- src/module.cpp.erb
|
109
100
|
- src/rucy.cpp
|
@@ -116,35 +107,34 @@ files:
|
|
116
107
|
- test/test_function.rb
|
117
108
|
- test/test_struct.rb
|
118
109
|
- test/test_value.rb
|
119
|
-
- .doc/ext/rucy/class.cpp
|
120
|
-
- .doc/ext/rucy/exception.cpp
|
121
|
-
- .doc/ext/rucy/function.cpp
|
122
|
-
- .doc/ext/rucy/struct.cpp
|
123
|
-
- .doc/ext/rucy/tester.cpp
|
124
|
-
- .doc/ext/rucy/value.cpp
|
110
|
+
- ".doc/ext/rucy/class.cpp"
|
111
|
+
- ".doc/ext/rucy/exception.cpp"
|
112
|
+
- ".doc/ext/rucy/function.cpp"
|
113
|
+
- ".doc/ext/rucy/struct.cpp"
|
114
|
+
- ".doc/ext/rucy/tester.cpp"
|
115
|
+
- ".doc/ext/rucy/value.cpp"
|
125
116
|
homepage: http://github.com/xord/rucy/wiki
|
126
117
|
licenses: []
|
118
|
+
metadata: {}
|
127
119
|
post_install_message:
|
128
120
|
rdoc_options: []
|
129
121
|
require_paths:
|
130
122
|
- lib
|
131
123
|
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
-
none: false
|
133
124
|
requirements:
|
134
|
-
- -
|
125
|
+
- - ">="
|
135
126
|
- !ruby/object:Gem::Version
|
136
127
|
version: 1.9.0
|
137
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
-
none: false
|
139
129
|
requirements:
|
140
|
-
- -
|
130
|
+
- - ">="
|
141
131
|
- !ruby/object:Gem::Version
|
142
132
|
version: '0'
|
143
133
|
requirements: []
|
144
134
|
rubyforge_project:
|
145
|
-
rubygems_version:
|
135
|
+
rubygems_version: 2.0.3
|
146
136
|
signing_key:
|
147
|
-
specification_version:
|
137
|
+
specification_version: 4
|
148
138
|
summary: A Ruby C++ Extension Helper Library.
|
149
139
|
test_files:
|
150
140
|
- test/helper.rb
|
data/.gitignore
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
*.o
|
2
|
-
*.so
|
3
|
-
*.bundle
|
4
|
-
*.dll.a
|
5
|
-
*.gem
|
6
|
-
*.log
|
7
|
-
*.rdoc.cpp
|
8
|
-
*~
|
9
|
-
lib/*.a
|
10
|
-
.doc
|
11
|
-
.yardoc
|
12
|
-
.DS_Store
|
13
|
-
Makefile
|
14
|
-
depend.mf
|
15
|
-
|
16
|
-
include/rucy/defs.h
|
17
|
-
include/rucy/function.h
|
18
|
-
include/rucy/module.h
|
19
|
-
include/rucy/value.h
|
20
|
-
src/function.cpp
|
21
|
-
src/module.cpp
|
22
|
-
src/value.cpp
|
data/ChangeLog
DELETED
data/include/rucy/defs.h.erb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
// -*- c++ -*-
|
2
|
-
#pragma once
|
3
|
-
#ifndef __RUCY_DEFS_H__
|
4
|
-
#define __RUCY_DEFS_H__
|
5
|
-
|
6
|
-
|
7
|
-
#include <ruby.h>
|
8
|
-
#include <xot/string.h>
|
9
|
-
|
10
|
-
|
11
|
-
namespace Rucy
|
12
|
-
{
|
13
|
-
|
14
|
-
|
15
|
-
using Xot::String;
|
16
|
-
|
17
|
-
|
18
|
-
class Value;
|
19
|
-
|
20
|
-
|
21
|
-
typedef VALUE (*RubyFunctionN) (int argc, const Value* argv, Value self);
|
22
|
-
% NTIMES.each do |n|
|
23
|
-
typedef VALUE (*RubyFunction<%= n %>) (Value self<%= params(n) {|i| ", Value v#{i}"} %>);
|
24
|
-
% end
|
25
|
-
|
26
|
-
|
27
|
-
}// Rucy
|
28
|
-
|
29
|
-
|
30
|
-
#define RUBY_DEF_ALLOC(name, klass) \
|
31
|
-
VALUE name (Value klass) \
|
32
|
-
{ \
|
33
|
-
RUBY_TRY
|
34
|
-
#define RUBY_DEFN(name) \
|
35
|
-
VALUE name (int argc, const Value* argv, Value self) \
|
36
|
-
{ \
|
37
|
-
RUBY_TRY
|
38
|
-
% NTIMES.each do |n|
|
39
|
-
#define RUBY_DEF<%= n %>(name<%= params(n) {|i| ", v#{i}"} %>) \
|
40
|
-
VALUE name (Value self<%= params(n) {|i| ", Value v#{i}"} %>) \
|
41
|
-
{ \
|
42
|
-
RUBY_TRY
|
43
|
-
% end
|
44
|
-
|
45
|
-
#define RUBY_END \
|
46
|
-
RUBY_CATCH \
|
47
|
-
return Qnil; \
|
48
|
-
}
|
49
|
-
|
50
|
-
#ifdef RUCY_USE_DEF
|
51
|
-
#define DEFN RUBY_DEFN
|
52
|
-
% NTIMES.each do |n|
|
53
|
-
#define DEF<%= n %> RUBY_DEF<%= n %>
|
54
|
-
% end
|
55
|
-
#define END RUBY_END
|
56
|
-
#endif
|
57
|
-
|
58
|
-
|
59
|
-
#define RUCY_CHECK_OBJ(obj, type, klass) \
|
60
|
-
do \
|
61
|
-
{ \
|
62
|
-
type* p = Rucy::get_type_ptr<type>(obj, klass); \
|
63
|
-
if (!p) Rucy::invalid_object_error(); \
|
64
|
-
} \
|
65
|
-
while(0)
|
66
|
-
|
67
|
-
#define RUCY_CHECK_OBJECT(obj, type, klass) \
|
68
|
-
do \
|
69
|
-
{ \
|
70
|
-
type* p = Rucy::get_type_ptr<type>(obj, klass); \
|
71
|
-
if (!p || !*p) Rucy::invalid_object_error(); \
|
72
|
-
} \
|
73
|
-
while(0)
|
74
|
-
|
75
|
-
|
76
|
-
#endif//EOH
|
data/include/rucy/extension.h
DELETED
@@ -1,206 +0,0 @@
|
|
1
|
-
// -*- c++ -*-
|
2
|
-
#pragma once
|
3
|
-
#ifndef __RUCY_EXTENSION_H__
|
4
|
-
#define __RUCY_EXTENSION_H__
|
5
|
-
|
6
|
-
|
7
|
-
#include <boost/dynamic_bitset.hpp>
|
8
|
-
#include <xot/ref.h>
|
9
|
-
#include <rucy/module.h>
|
10
|
-
|
11
|
-
|
12
|
-
namespace Rucy
|
13
|
-
{
|
14
|
-
|
15
|
-
|
16
|
-
template <typename T>
|
17
|
-
class ClassWrapper : public T
|
18
|
-
{
|
19
|
-
|
20
|
-
typedef ClassWrapper This;
|
21
|
-
|
22
|
-
public:
|
23
|
-
|
24
|
-
typedef T Super;
|
25
|
-
|
26
|
-
GlobalValue value;
|
27
|
-
|
28
|
-
ClassWrapper ()
|
29
|
-
: value(Qnil, true)
|
30
|
-
{
|
31
|
-
}
|
32
|
-
|
33
|
-
virtual void retain ()
|
34
|
-
{
|
35
|
-
value.gc(false);
|
36
|
-
Super::retain();
|
37
|
-
}
|
38
|
-
|
39
|
-
virtual void release ()
|
40
|
-
{
|
41
|
-
Super::release();
|
42
|
-
value.gc(true);
|
43
|
-
}
|
44
|
-
|
45
|
-
virtual void clear_override_flags ()
|
46
|
-
{
|
47
|
-
override_flags.reset();
|
48
|
-
}
|
49
|
-
|
50
|
-
virtual bool is_overridden (const Value& klass, const Symbol& name, uint id) const
|
51
|
-
{
|
52
|
-
if (id <= OVERRIDE_ID_UNKNOWN)
|
53
|
-
return false;
|
54
|
-
|
55
|
-
bool checked = false, overridden = false;
|
56
|
-
get_override_flag(&checked, &overridden, id);
|
57
|
-
if (checked) return overridden;
|
58
|
-
|
59
|
-
overridden = check_overridden(klass, name);
|
60
|
-
if (!const_cast<This*>(this)->set_override_flag(id, true, overridden))
|
61
|
-
return false;
|
62
|
-
|
63
|
-
return overridden;
|
64
|
-
}
|
65
|
-
|
66
|
-
protected:
|
67
|
-
|
68
|
-
enum
|
69
|
-
{
|
70
|
-
|
71
|
-
OVERRIDE_ID_UNKNOWN = 0,
|
72
|
-
|
73
|
-
OVERRIDE_ID_LAST,
|
74
|
-
|
75
|
-
OVERRIDE_ID_MAX = 256
|
76
|
-
|
77
|
-
};
|
78
|
-
|
79
|
-
private:
|
80
|
-
|
81
|
-
boost::dynamic_bitset<> override_flags;
|
82
|
-
|
83
|
-
bool check_overridden (const Value& klass, const Symbol& name) const
|
84
|
-
{
|
85
|
-
SYM(method);
|
86
|
-
SYM(owner);
|
87
|
-
return this->value.call(method, name.value()).call(owner) != klass;
|
88
|
-
}
|
89
|
-
|
90
|
-
void get_override_flag (bool* checked, bool* overridden, uint id) const
|
91
|
-
{
|
92
|
-
assert(checked || overridden);
|
93
|
-
|
94
|
-
int checked_pos = id2index(id);
|
95
|
-
int overridden_pos = checked_pos + 1;
|
96
|
-
bool valid = 0 <= checked_pos && overridden_pos < (int) override_flags.size();
|
97
|
-
if (checked) *checked = valid ? override_flags[checked_pos] : false;
|
98
|
-
if (overridden) *overridden = valid ? override_flags[overridden_pos] : false;
|
99
|
-
}
|
100
|
-
|
101
|
-
bool set_override_flag (uint id, bool checked, bool overridden)
|
102
|
-
{
|
103
|
-
assert(id < OVERRIDE_ID_MAX);
|
104
|
-
|
105
|
-
int checked_pos = id2index(id);
|
106
|
-
if (checked_pos < 0) return true;
|
107
|
-
|
108
|
-
int overridden_pos = checked_pos + 1;
|
109
|
-
if (overridden_pos >= (int) override_flags.size())
|
110
|
-
override_flags.resize(overridden_pos + 1);
|
111
|
-
|
112
|
-
override_flags[checked_pos] = checked;
|
113
|
-
override_flags[overridden_pos] = overridden;
|
114
|
-
return true;
|
115
|
-
}
|
116
|
-
|
117
|
-
int id2index (uint id) const
|
118
|
-
{
|
119
|
-
return (id - 1) * 2;
|
120
|
-
}
|
121
|
-
|
122
|
-
};// ClassWrapper
|
123
|
-
|
124
|
-
|
125
|
-
template <typename T> inline void release_wrapper (void* p)
|
126
|
-
{
|
127
|
-
if (p) ((T*) p)->Xot::template RefCountable<>::release();
|
128
|
-
}
|
129
|
-
|
130
|
-
template <typename T> inline Value new_wrapper (
|
131
|
-
Value klass, T* ptr,
|
132
|
-
RUBY_DATA_FUNC mark = NULL,
|
133
|
-
RUBY_DATA_FUNC free = release_wrapper<T>)
|
134
|
-
{
|
135
|
-
if (ptr) ptr->Xot::template RefCountable<>::retain();
|
136
|
-
return new_type(klass, ptr, mark, free);
|
137
|
-
}
|
138
|
-
|
139
|
-
template <typename T> inline Value new_wrapper (
|
140
|
-
Value klass,
|
141
|
-
RUBY_DATA_FUNC mark = NULL,
|
142
|
-
RUBY_DATA_FUNC free = release_wrapper<T>)
|
143
|
-
{
|
144
|
-
return new_wrapper(klass, new T, mark, free);
|
145
|
-
}
|
146
|
-
|
147
|
-
|
148
|
-
}// Rucy
|
149
|
-
|
150
|
-
|
151
|
-
#define RUCY_WRAPPER_VALUE_FROM(wrapped_class, ruby_class) \
|
152
|
-
namespace Rucy \
|
153
|
-
{ \
|
154
|
-
inline Value \
|
155
|
-
value (wrapped_class* obj, Value klass = ruby_class) \
|
156
|
-
{ \
|
157
|
-
if (!obj) return Qnil; \
|
158
|
-
ClassWrapper<wrapped_class>* p = dynamic_cast<ClassWrapper<wrapped_class>*>(obj); \
|
159
|
-
if (!p) return new_ref(klass, obj); \
|
160
|
-
if (p->value.is_nil()) p->value = new_wrapper(klass, obj); \
|
161
|
-
return p->value; \
|
162
|
-
} \
|
163
|
-
}
|
164
|
-
|
165
|
-
#define RUCY_WRAPPER_VALUE_TO(wrapped_class, ruby_class) \
|
166
|
-
namespace Rucy \
|
167
|
-
{ \
|
168
|
-
template <> inline wrapped_class* \
|
169
|
-
value_to<wrapped_class*> (Value value, bool convert) \
|
170
|
-
{ \
|
171
|
-
return get_type_ptr<wrapped_class>(value, ruby_class); \
|
172
|
-
} \
|
173
|
-
}
|
174
|
-
|
175
|
-
#define RUCY_WRAPPER_VALUE_FROM_TO(wrapped_class, ruby_class) \
|
176
|
-
RUCY_WRAPPER_VALUE_FROM(wrapped_class, ruby_class) \
|
177
|
-
RUCY_WRAPPER_VALUE_TO(wrapped_class, ruby_class)
|
178
|
-
|
179
|
-
|
180
|
-
#define RUCY_WRAPPER_CALL(wrapper_class, obj, fun) \
|
181
|
-
(dynamic_cast<wrapper_class*>(obj) \
|
182
|
-
? reinterpret_cast<wrapper_class*>(obj)->Super::fun \
|
183
|
-
: (obj)->fun)
|
184
|
-
|
185
|
-
|
186
|
-
#define RUCY_OVERRIDE_ID_START(name) enum { OID_##name = Super::OVERRIDE_ID_LAST,
|
187
|
-
#define RUCY_OVERRIDE_ID(name) OID_##name,
|
188
|
-
#define RUCY_OVERRIDE_ID_LAST OVERRIDE_ID_LAST };
|
189
|
-
|
190
|
-
|
191
|
-
#define RUCY_IS_OVERRIDDEN(name, ruby_class) \
|
192
|
-
this->is_overridden(ruby_class, name, OID_##name)
|
193
|
-
|
194
|
-
#define RUCY_OVERRIDABLE_METHOD(name, ruby_class, suffix) \
|
195
|
-
SYM(name); \
|
196
|
-
return this->value.call(name) suffix ;
|
197
|
-
|
198
|
-
#define RUCY_OVERRIDABLE_METHOD_FAST(name, ruby_class, suffix) \
|
199
|
-
SYM(name); \
|
200
|
-
if (RUCY_IS_OVERRIDDEN(name, ruby_class)) \
|
201
|
-
return this->value.call(name) suffix ; \
|
202
|
-
else \
|
203
|
-
return this->Super::name();
|
204
|
-
|
205
|
-
|
206
|
-
#endif//EOH
|