extpp 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +1 -1
  4. data/Rakefile +1 -28
  5. data/doc/text/news.md +43 -0
  6. data/include/ruby/cast.hpp +4 -4
  7. data/include/ruby/class.hpp +190 -13
  8. data/{ext/extpp → include/ruby}/function.hpp +20 -7
  9. data/include/ruby/object.hpp +44 -5
  10. data/include/ruby/protect.hpp +12 -5
  11. data/lib/extpp/compiler.rb +17 -10
  12. data/lib/extpp/setup.rb +0 -0
  13. data/lib/extpp/version.rb +1 -1
  14. data/lib/extpp.rb +0 -12
  15. data/sample/hello/Rakefile +6 -1
  16. metadata +7 -74
  17. data/ext/extpp/class.cpp +0 -277
  18. data/ext/extpp/extconf.rb +0 -110
  19. data/ext/extpp/function.cpp +0 -28
  20. data/ext/extpp/object.cpp +0 -48
  21. data/ext/extpp/protect.cpp +0 -12
  22. data/lib/extpp/platform.rb +0 -14
  23. data/test/fixtures/cast/Makefile +0 -269
  24. data/test/fixtures/cast/cast.cpp +0 -39
  25. data/test/fixtures/cast/cast.o +0 -0
  26. data/test/fixtures/cast/cast.so +0 -0
  27. data/test/fixtures/cast/extconf.rb +0 -4
  28. data/test/fixtures/cast/mkmf.log +0 -140
  29. data/test/fixtures/class/Makefile +0 -269
  30. data/test/fixtures/class/class.cpp +0 -46
  31. data/test/fixtures/class/class.o +0 -0
  32. data/test/fixtures/class/class.so +0 -0
  33. data/test/fixtures/class/extconf.rb +0 -4
  34. data/test/fixtures/class/mkmf.log +0 -140
  35. data/test/fixtures/object/Makefile +0 -269
  36. data/test/fixtures/object/extconf.rb +0 -4
  37. data/test/fixtures/object/mkmf.log +0 -140
  38. data/test/fixtures/object/object.cpp +0 -102
  39. data/test/fixtures/object/object.o +0 -0
  40. data/test/fixtures/object/object.so +0 -0
  41. data/test/fixtures/protect/Makefile +0 -269
  42. data/test/fixtures/protect/extconf.rb +0 -4
  43. data/test/fixtures/protect/mkmf.log +0 -140
  44. data/test/fixtures/protect/protect.cpp +0 -70
  45. data/test/fixtures/protect/protect.o +0 -0
  46. data/test/fixtures/protect/protect.so +0 -0
  47. data/test/helper.rb +0 -9
  48. data/test/run-test.rb +0 -23
  49. data/test/test-cast.rb +0 -46
  50. data/test/test-class.rb +0 -47
  51. data/test/test-object.rb +0 -68
  52. data/test/test-protect.rb +0 -54
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: extpp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-25 00:00:00.000000000 Z
11
+ date: 2021-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,63 +58,27 @@ description: |-
58
58
  email:
59
59
  - kou@clear-code.com
60
60
  executables: []
61
- extensions:
62
- - ext/extpp/extconf.rb
61
+ extensions: []
63
62
  extra_rdoc_files: []
64
63
  files:
65
64
  - LICENSE.txt
66
65
  - README.md
67
66
  - Rakefile
68
67
  - doc/text/news.md
69
- - ext/extpp/class.cpp
70
- - ext/extpp/extconf.rb
71
- - ext/extpp/function.cpp
72
- - ext/extpp/function.hpp
73
- - ext/extpp/object.cpp
74
- - ext/extpp/protect.cpp
75
68
  - include/ruby.hpp
76
69
  - include/ruby/cast.hpp
77
70
  - include/ruby/class.hpp
71
+ - include/ruby/function.hpp
78
72
  - include/ruby/object.hpp
79
73
  - include/ruby/protect.hpp
80
74
  - include/ruby/type.hpp
81
75
  - lib/extpp.rb
82
76
  - lib/extpp/compiler.rb
83
- - lib/extpp/platform.rb
77
+ - lib/extpp/setup.rb
84
78
  - lib/extpp/version.rb
85
79
  - sample/hello/Rakefile
86
80
  - sample/hello/extconf.rb
87
81
  - sample/hello/hello.cpp
88
- - test/fixtures/cast/Makefile
89
- - test/fixtures/cast/cast.cpp
90
- - test/fixtures/cast/cast.o
91
- - test/fixtures/cast/cast.so
92
- - test/fixtures/cast/extconf.rb
93
- - test/fixtures/cast/mkmf.log
94
- - test/fixtures/class/Makefile
95
- - test/fixtures/class/class.cpp
96
- - test/fixtures/class/class.o
97
- - test/fixtures/class/class.so
98
- - test/fixtures/class/extconf.rb
99
- - test/fixtures/class/mkmf.log
100
- - test/fixtures/object/Makefile
101
- - test/fixtures/object/extconf.rb
102
- - test/fixtures/object/mkmf.log
103
- - test/fixtures/object/object.cpp
104
- - test/fixtures/object/object.o
105
- - test/fixtures/object/object.so
106
- - test/fixtures/protect/Makefile
107
- - test/fixtures/protect/extconf.rb
108
- - test/fixtures/protect/mkmf.log
109
- - test/fixtures/protect/protect.cpp
110
- - test/fixtures/protect/protect.o
111
- - test/fixtures/protect/protect.so
112
- - test/helper.rb
113
- - test/run-test.rb
114
- - test/test-cast.rb
115
- - test/test-class.rb
116
- - test/test-object.rb
117
- - test/test-protect.rb
118
82
  homepage: https://github.com/red-data-tools/extpp
119
83
  licenses:
120
84
  - BSD-2-Clause
@@ -134,39 +98,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
98
  - !ruby/object:Gem::Version
135
99
  version: '0'
136
100
  requirements: []
137
- rubyforge_project:
138
- rubygems_version: 2.7.6
101
+ rubygems_version: 3.3.0.dev
139
102
  signing_key:
140
103
  specification_version: 4
141
104
  summary: Ext++ is a Ruby extension that provides C++ API for writing Ruby extension.
142
- test_files:
143
- - test/test-object.rb
144
- - test/test-protect.rb
145
- - test/test-class.rb
146
- - test/fixtures/class/class.so
147
- - test/fixtures/class/mkmf.log
148
- - test/fixtures/class/class.cpp
149
- - test/fixtures/class/class.o
150
- - test/fixtures/class/Makefile
151
- - test/fixtures/class/extconf.rb
152
- - test/fixtures/protect/mkmf.log
153
- - test/fixtures/protect/protect.so
154
- - test/fixtures/protect/protect.cpp
155
- - test/fixtures/protect/Makefile
156
- - test/fixtures/protect/protect.o
157
- - test/fixtures/protect/extconf.rb
158
- - test/fixtures/cast/mkmf.log
159
- - test/fixtures/cast/cast.cpp
160
- - test/fixtures/cast/cast.so
161
- - test/fixtures/cast/Makefile
162
- - test/fixtures/cast/cast.o
163
- - test/fixtures/cast/extconf.rb
164
- - test/fixtures/object/mkmf.log
165
- - test/fixtures/object/object.so
166
- - test/fixtures/object/Makefile
167
- - test/fixtures/object/object.cpp
168
- - test/fixtures/object/object.o
169
- - test/fixtures/object/extconf.rb
170
- - test/helper.rb
171
- - test/run-test.rb
172
- - test/test-cast.rb
105
+ test_files: []
data/ext/extpp/class.cpp DELETED
@@ -1,277 +0,0 @@
1
- #include "function.hpp"
2
-
3
- #include <string>
4
- #include <unordered_map>
5
- #include <vector>
6
-
7
- namespace rb {
8
- using MethodTable = std::unordered_map<ID, Function *>;
9
-
10
- struct MethodDefinition {
11
- MethodDefinition(std::string name_, Function *function_) :
12
- name(name_),
13
- function(function_) {
14
- }
15
-
16
- std::string name;
17
- Function *function;
18
- };
19
- using MethodDefinitions = std::vector<MethodDefinition>;
20
- }
21
-
22
- namespace {
23
- VALUE MethodTable = Qnil;
24
-
25
- void free_method_table(void *data) {
26
- auto method_table = static_cast<rb::MethodTable *>(data);
27
- delete method_table;
28
- }
29
-
30
- const rb_data_type_t MethodTableType = {
31
- "MethodTable",
32
- {nullptr, free_method_table, nullptr,},
33
- nullptr,
34
- nullptr,
35
- RUBY_TYPED_FREE_IMMEDIATELY,
36
- };
37
-
38
- rb::MethodTable *method_table_from_ruby(VALUE rb_method_table) {
39
- rb::MethodTable *method_table;
40
- TypedData_Get_Struct(rb_method_table,
41
- rb::MethodTable,
42
- &MethodTableType,
43
- method_table);
44
- return method_table;
45
- }
46
-
47
- VALUE method_table_to_ruby(rb::MethodTable *method_table) {
48
- if (NIL_P(MethodTable)) {
49
- MethodTable = rb_define_class("MethodTable", rb_cData);
50
- }
51
- return TypedData_Wrap_Struct(MethodTable, &MethodTableType, method_table);
52
- }
53
-
54
- VALUE MethodDefinitions = Qnil;
55
-
56
- void free_method_definitions(void *data) {
57
- auto method_definitions = static_cast<rb::MethodDefinitions *>(data);
58
- delete method_definitions;
59
- }
60
-
61
- const rb_data_type_t MethodDefinitionsType = {
62
- "MethodDefinitions",
63
- {nullptr, free_method_definitions, nullptr,},
64
- nullptr,
65
- nullptr,
66
- RUBY_TYPED_FREE_IMMEDIATELY,
67
- };
68
-
69
- rb::MethodDefinitions *method_definitions_from_ruby(VALUE rb_definitions) {
70
- rb::MethodDefinitions *definitions;
71
- TypedData_Get_Struct(rb_definitions,
72
- rb::MethodDefinitions,
73
- &MethodDefinitionsType,
74
- definitions);
75
- return definitions;
76
- }
77
-
78
- VALUE method_definitions_to_ruby(rb::MethodDefinitions *definitions) {
79
- if (NIL_P(MethodDefinitions)) {
80
- MethodDefinitions = rb_define_class("MethodDefinitions", rb_cData);
81
- }
82
- return TypedData_Wrap_Struct(MethodDefinitions,
83
- &MethodDefinitionsType,
84
- definitions);
85
- }
86
-
87
- VALUE call_func(int argc, VALUE *argv, VALUE self) {
88
- auto rb_method_table =
89
- rb_ivar_get(rb_obj_class(self), rb_intern("__method_table__"));
90
- auto method_table = method_table_from_ruby(rb_method_table);
91
- auto method_name_symbol = rb_funcall(self, rb_intern("__method__"), 0);
92
- auto function = (*method_table)[rb_sym2id(method_name_symbol)];
93
- return function->call(self, argc, argv);
94
- }
95
-
96
- bool flush_method_definitions(VALUE klass) {
97
- ID id_method_definitions = rb_intern("__method_definitions__");
98
- auto rb_definitions = rb_ivar_get(klass, id_method_definitions);
99
- if (NIL_P(rb_definitions)) {
100
- return false;
101
- }
102
-
103
- auto definitions = method_definitions_from_ruby(rb_definitions);
104
- auto rb_method_table = rb_ivar_get(klass, rb_intern("__method_table__"));
105
- auto method_table = method_table_from_ruby(rb_method_table);
106
- for (const auto &definition : *definitions) {
107
- ID name_id = rb_intern(definition.name.c_str());
108
- (*method_table)[name_id] = definition.function;
109
- rb_define_method(klass,
110
- definition.name.c_str(),
111
- reinterpret_cast<rb::RawMethod>(call_func),
112
- -1);
113
- }
114
- rb_ivar_set(klass, id_method_definitions, Qnil);
115
- return true;
116
- }
117
-
118
- VALUE method_missing(int argc, VALUE *argv, VALUE self) {
119
- auto klass = rb_obj_class(self);
120
-
121
- if (flush_method_definitions(klass)) {
122
- auto rb_method_table = rb_ivar_get(klass, rb_intern("__method_table__"));
123
- auto method_table = method_table_from_ruby(rb_method_table);
124
-
125
- VALUE rb_name_symbol;
126
- VALUE rb_args;
127
- rb_scan_args(argc, argv, "1*", &rb_name_symbol, &rb_args);
128
- auto function = (*method_table)[rb_sym2id(rb_name_symbol)];
129
- if (function) {
130
- return function->call(self,
131
- static_cast<int>(RARRAY_LEN(rb_args)),
132
- RARRAY_PTR(rb_args));
133
- }
134
- }
135
-
136
- return rb_call_super(argc, argv);
137
- }
138
-
139
- VALUE respond_to_missing_p(VALUE self,
140
- VALUE rb_name_symbol,
141
- VALUE rb_include_private) {
142
- auto klass = rb_obj_class(self);
143
-
144
- if (flush_method_definitions(klass)) {
145
- auto rb_method_table = rb_ivar_get(klass, rb_intern("__method_table__"));
146
- auto method_table = method_table_from_ruby(rb_method_table);
147
-
148
- auto function = (*method_table)[rb_sym2id(rb_name_symbol)];
149
- if (function) {
150
- return Qtrue;
151
- }
152
- }
153
-
154
- VALUE rb_args[] = {rb_name_symbol, rb_include_private};
155
- return rb_call_super(2, rb_args);
156
- }
157
- }
158
-
159
- namespace rb {
160
- class Class::ClassImpl {
161
- public:
162
- ClassImpl(VALUE klass) :
163
- class_(klass),
164
- method_table_(new MethodTable()),
165
- lazy_define_method_(false),
166
- method_definitions_(nullptr) {
167
- rb_iv_set(class_, "__method_table__", method_table_to_ruby(method_table_));
168
- rb_iv_set(class_, "__method_definitions__", Qnil);
169
- }
170
-
171
- void enable_lazy_define_method() {
172
- if (lazy_define_method_) {
173
- return;
174
- }
175
-
176
- lazy_define_method_ = true;
177
- method_definitions_ = new MethodDefinitions();
178
- rb_iv_set(class_, "__method_definitions__",
179
- method_definitions_to_ruby(method_definitions_));
180
- rb_define_method(class_,
181
- "method_missing",
182
- reinterpret_cast<RawMethod>(method_missing),
183
- -1);
184
- rb_define_method(class_,
185
- "respond_to_missing?",
186
- reinterpret_cast<RawMethod>(respond_to_missing_p),
187
- -1);
188
- }
189
-
190
- void define_method(const char *name, VALUE (*body)(VALUE self)) {
191
- rb_define_method(class_,
192
- name,
193
- reinterpret_cast<RawMethod>(body),
194
- 0);
195
- }
196
-
197
- void define_method(const char *name,
198
- VALUE (*body)(int argc, VALUE *argv, VALUE self)) {
199
- rb_define_method(class_,
200
- name,
201
- reinterpret_cast<RawMethod>(body),
202
- -1);
203
- }
204
-
205
- void define_method(const char *name, Function *function) {
206
- if (lazy_define_method_) {
207
- method_definitions_->emplace_back(name, function);
208
- } else {
209
- ID name_id = rb_intern(name);
210
- (*method_table_)[name_id] = function;
211
- rb_define_method(class_,
212
- name,
213
- reinterpret_cast<RawMethod>(call_func),
214
- -1);
215
- }
216
- }
217
-
218
- private:
219
- VALUE class_;
220
- MethodTable *method_table_;
221
- bool lazy_define_method_;
222
- MethodDefinitions *method_definitions_;
223
- };
224
-
225
- Class::Class(const char *name) :
226
- Object(RTEST(rb_funcall(rb_cObject,
227
- rb_intern("const_defined?"),
228
- 1,
229
- rb_str_new_static(name, strlen(name)))) ?
230
- rb_funcall(rb_cObject,
231
- rb_intern("const_get"),
232
- 1,
233
- rb_str_new_static(name, strlen(name))) :
234
- rb_define_class(name, rb_cObject)),
235
- impl_(new ClassImpl(this->to_ruby())) {
236
- }
237
-
238
- Class::Class(const char *name, VALUE parent) :
239
- Object(rb_define_class(name, parent)),
240
- impl_(new ClassImpl(this->to_ruby())) {
241
- }
242
-
243
- Class::Class(VALUE klass) :
244
- Object(klass),
245
- impl_(new ClassImpl(this->to_ruby())) {
246
- }
247
-
248
- Class::~Class() {
249
- delete impl_;
250
- }
251
-
252
- Class &Class::define_method(const char *name,
253
- MethodWithoutArguments body) {
254
- auto function = new FunctionWithoutArgument(body);
255
- impl_->define_method(name, function);
256
- return (Class &)*this;
257
- }
258
-
259
- Class &Class::define_method(const char *name,
260
- MethodWithArguments body) {
261
- auto function = new FunctionWithArguments(body);
262
- impl_->define_method(name, function);
263
- return (Class &)*this;
264
- }
265
-
266
- Class &Class::define_method(const char *name,
267
- MethodWithArgumentsCompatible body) {
268
- auto function = new FunctionWithArgumentsCompatible(body);
269
- impl_->define_method(name, function);
270
- return (Class &)*this;
271
- }
272
-
273
- Class &Class::enable_lazy_define_method() {
274
- impl_->enable_lazy_define_method();
275
- return (Class &)*this;
276
- }
277
- }
data/ext/extpp/extconf.rb DELETED
@@ -1,110 +0,0 @@
1
- require_relative "../../lib/extpp/compiler"
2
- require_relative "../../lib/extpp/platform"
3
-
4
- cxxflags = RbConfig.expand("$(CXXFLAGS)")
5
- compiler = ExtPP::Compiler.new(cxxflags)
6
- compiler.check
7
- cxxflags = compiler.cxx_flags
8
-
9
- sources = Dir.chdir(__dir__) do
10
- Dir.glob("*.cpp").collect do |cpp_source|
11
- File.join(__dir__, cpp_source)
12
- end
13
- end
14
- objects = sources.collect do |source|
15
- source.gsub(/\.cpp\z/, ".o")
16
- end
17
-
18
- def collect_headers(dir)
19
- Dir.chdir(dir) do
20
- Dir.glob("**/*.hpp").collect do |header|
21
- File.join(dir, header)
22
- end
23
- end
24
- end
25
-
26
- include_dir = File.expand_path(File.join(__dir__, "..", "..", "include"))
27
- public_headers = collect_headers(include_dir)
28
- private_headers = collect_headers(__dir__)
29
- headers = public_headers + private_headers
30
-
31
- platform = ExtPP::Platform.new
32
- case RUBY_PLATFORM
33
- when /darwin/
34
- ldsharedxx = RbConfig::CONFIG["LDSHAREDXX"]
35
- ldsharedxx = ldsharedxx.gsub(/ (?:-dynamic|-bundle)/, "") + " -shared"
36
- ldsharedxx += " -install_name #{Dir.pwd.quote}/$(LIBRARY)"
37
- else
38
- ldsharedxx = RbConfig::CONFIG["LDSHAREDXX"]
39
- end
40
-
41
- librubyarg_shared = RbConfig::CONFIG["LIBRUBYARG_SHARED"]
42
- if compiler.gcc? and !librubyarg_shared.include?("-L")
43
- librubyarg_shared += " -L$(libdir)"
44
- end
45
-
46
- File.open("Makefile", "w") do |makefile|
47
- makefile.puts(<<-MAKEFILE)
48
- LIBRARY = libruby-extpp.#{platform.dynamic_library_extension}
49
-
50
- SOURCES = #{sources.collect(&:quote).join(" ")}
51
- OBJECTS = #{objects.collect(&:quote).join(" ")}
52
- HEADERS = #{headers.collect(&:quote).join(" ")}
53
-
54
- INCLUDE_DIR = #{include_dir.quote}
55
-
56
- CXX = #{RbConfig::CONFIG["CXX"].quote}
57
-
58
- RUBY = #{RbConfig.ruby.quote}
59
- RUBY_HEADER_DIR = #{RbConfig::CONFIG["rubyhdrdir"].quote}
60
- RUBY_ARCH_HEADER_DIR = #{RbConfig::CONFIG["rubyarchhdrdir"].quote}
61
-
62
- libdir = #{RbConfig::CONFIG["libdir"].quote}
63
- sitearchdir = #{RbConfig::CONFIG["sitearchdir"].quote}
64
- sitelibdir = #{RbConfig::CONFIG["sitelibdir"].quote}
65
-
66
- LIBRUBYARG_SHARED = #{librubyarg_shared}
67
- ARCH_FLAG = #{RbConfig::CONFIG["ARCH_FLAG"]}
68
- LDFLAGS = #{RbConfig::CONFIG["LDFLAGS"]}
69
- DLDFLAGS = #{RbConfig::CONFIG["DLDFLAGS"]}
70
- EXTDLDFLAGS = #{RbConfig::CONFIG["EXTDLDFLAGS"]}
71
- LDSHAREDXX = #{ldsharedxx}
72
- CCDLFLAGS = #{RbConfig::CONFIG["CCDLFLAGS"]}
73
-
74
- INCLUDEFLAGS = \
75
- -I$(INCLUDE_DIR) \
76
- -I$(RUBY_HEADER_DIR) \
77
- -I$(RUBY_ARCH_HEADER_DIR)
78
- CPPFLAGS = #{RbConfig::CONFIG["CPPFLAGS"]}
79
- CXXFLAGS = $(CCDLFLAGS) #{cxxflags}
80
-
81
- all: $(LIBRARY)
82
-
83
- clean:
84
- rm -rf $(OBJECTS) $(LIBRARY)
85
-
86
- dist-clean:
87
- $(MAKE) clean
88
- rm -rf Makefile
89
-
90
- install: install-so
91
-
92
- install-so: $(LIBRARY)
93
- "$(RUBY)" -run -e install -- $(LIBRARY) $(sitearchdir)
94
-
95
- $(LIBRARY): $(OBJECTS) Makefile
96
- $(LDSHAREDXX) \\
97
- -o $@ \\
98
- $(OBJECTS) \\
99
- $(LDFLAGS) \\
100
- $(DLDFLAGS) \\
101
- $(EXTDLDFLAGS) \\
102
- $(ARCH_FLAG) \\
103
- $(LIBRUBYARG_SHARED)
104
-
105
- .cpp.o:
106
- $(CXX) $(INCLUDEFLAGS) $(CPPFLAGS) $(CXXFLAGS) -o $@ -c $<
107
-
108
- $(OBJECTS): $(HEADERS)
109
- MAKEFILE
110
- end
@@ -1,28 +0,0 @@
1
- #include "function.hpp"
2
-
3
- namespace rb {
4
- FunctionWithoutArgument::FunctionWithoutArgument(const MethodWithoutArguments &function) :
5
- function_(function) {
6
- }
7
-
8
- VALUE FunctionWithoutArgument::call(VALUE self, int argc, VALUE *argv) {
9
- return function_(self);
10
- };
11
-
12
-
13
- FunctionWithArguments::FunctionWithArguments(const MethodWithArguments &function) :
14
- function_(function) {
15
- }
16
-
17
- VALUE FunctionWithArguments::call(VALUE self, int argc, VALUE *argv) {
18
- return function_(self, argc, argv);
19
- };
20
-
21
- FunctionWithArgumentsCompatible::FunctionWithArgumentsCompatible(const MethodWithArgumentsCompatible &function) :
22
- function_(function) {
23
- }
24
-
25
- VALUE FunctionWithArgumentsCompatible::call(VALUE self, int argc, VALUE *argv) {
26
- return function_(argc, argv, self);
27
- };
28
- }
data/ext/extpp/object.cpp DELETED
@@ -1,48 +0,0 @@
1
- #include <ruby/object.hpp>
2
-
3
- namespace {
4
- VALUE call_block(RB_BLOCK_CALL_FUNC_ARGLIST(rb_data, rb_block)) {
5
- auto block = reinterpret_cast<rb::MethodWithoutArguments>(rb_block);
6
- return block(rb_data);
7
- }
8
- }
9
-
10
- namespace rb {
11
- Object Object::send(ID name_id) {
12
- VALUE rb_result = rb_funcall(rb_object_, name_id, 0);
13
- return Object(rb_result);
14
- }
15
-
16
- Object Object::send(ID name_id,
17
- std::initializer_list<VALUE> args) {
18
- auto n = args.size();
19
- VALUE rb_args[n];
20
- int i = 0;
21
- for (auto arg : args) {
22
- rb_args[i++] = arg;
23
- }
24
- VALUE rb_result = rb_funcallv(rb_object_,
25
- name_id,
26
- static_cast<int>(n),
27
- rb_args);
28
- return Object(rb_result);
29
- }
30
-
31
- Object Object::send(ID name_id,
32
- std::initializer_list<VALUE> args,
33
- MethodWithoutArguments block) {
34
- auto n = args.size();
35
- VALUE rb_args[n];
36
- int i = 0;
37
- for (auto arg : args) {
38
- rb_args[i++] = arg;
39
- }
40
- VALUE rb_result = rb_block_call(rb_object_,
41
- name_id,
42
- static_cast<int>(n),
43
- rb_args,
44
- reinterpret_cast<RawMethod>(call_block),
45
- reinterpret_cast<VALUE>(block));
46
- return Object(rb_result);
47
- }
48
- }
@@ -1,12 +0,0 @@
1
- #include <ruby/protect.hpp>
2
-
3
- namespace rb {
4
- VALUE protect(RawCallback callback, VALUE callback_data) {
5
- int state = 0;
6
- auto result = rb_protect(callback, callback_data, &state);
7
- if (state != 0) {
8
- throw State(state);
9
- }
10
- return result;
11
- }
12
- }
@@ -1,14 +0,0 @@
1
- module ExtPP
2
- class Platform
3
- def dynamic_library_extension
4
- case RUBY_PLATFORM
5
- when /windows/, /mingw/
6
- "dll"
7
- when /darwin/
8
- "dylib"
9
- else
10
- RbConfig::CONFIG["DLEXT"]
11
- end
12
- end
13
- end
14
- end