Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
8961a788
Commit
8961a788
authored
Jan 23, 2013
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #770 from masuidrive/mrbgem_finalizer
Added finalizer of mrbgems
parents
b79e1ecb
310b0dce
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
56 additions
and
0 deletions
+56
-0
doc/mrbgems/README.md
doc/mrbgems/README.md
+15
-0
doc/mrbgems/c_and_ruby_extension_example/src/example.c
doc/mrbgems/c_and_ruby_extension_example/src/example.c
+5
-0
doc/mrbgems/c_extension_example/src/example.c
doc/mrbgems/c_extension_example/src/example.c
+5
-0
src/init.c
src/init.c
+9
-0
src/state.c
src/state.c
+3
-0
tasks/mrbgem_spec.rake
tasks/mrbgem_spec.rake
+6
-0
tasks/mrbgems.rake
tasks/mrbgems.rake
+8
-0
tools/mrbc/mrbc.c
tools/mrbc/mrbc.c
+5
-0
No files found.
doc/mrbgems/README.md
View file @
8961a788
...
...
@@ -106,6 +106,21 @@ mrb_c_extension_example_gem_init(mrb_state* mrb) {
}
```
### Finalize
mrbgems expects that you have implemented a C method called
```
mrb_YOURGEMNAME_gem_final(mrb_state)
```. ```
YOURGEMNAME
``` will be replaced
by the name of your GEM. If you call your GEM *c_extension_example*, your
finalizer method could look like this:
```
void
mrb_c_extension_example_gem_final(mrb_state
*
mrb) {
free(someone);
}
```
### Example
```
...
...
doc/mrbgems/c_and_ruby_extension_example/src/example.c
View file @
8961a788
...
...
@@ -13,3 +13,8 @@ mrb_c_and_ruby_extension_example_gem_init(mrb_state* mrb) {
struct
RClass
*
class_cextension
=
mrb_define_module
(
mrb
,
"CRubyExtension"
);
mrb_define_class_method
(
mrb
,
class_cextension
,
"c_method"
,
mrb_c_method
,
ARGS_NONE
());
}
void
mrb_c_and_ruby_extension_example_gem_final
(
mrb_state
*
mrb
)
{
// finalizer
}
doc/mrbgems/c_extension_example/src/example.c
View file @
8961a788
...
...
@@ -13,3 +13,8 @@ mrb_c_extension_example_gem_init(mrb_state* mrb) {
struct
RClass
*
class_cextension
=
mrb_define_module
(
mrb
,
"CExtension"
);
mrb_define_class_method
(
mrb
,
class_cextension
,
"c_method"
,
mrb_c_method
,
ARGS_NONE
());
}
void
mrb_c_extension_example_gem_final
(
mrb_state
*
mrb
)
{
// finalizer
}
src/init.c
View file @
8961a788
...
...
@@ -28,6 +28,7 @@ void mrb_init_time(mrb_state*);
void
mrb_init_math
(
mrb_state
*
);
void
mrb_init_mrblib
(
mrb_state
*
);
void
mrb_init_mrbgems
(
mrb_state
*
);
void
mrb_final_mrbgems
(
mrb_state
*
);
#define DONE mrb_gc_arena_restore(mrb, 0);
void
...
...
@@ -70,3 +71,11 @@ mrb_init_core(mrb_state *mrb)
mrb_init_mrbgems
(
mrb
);
DONE
;
#endif
}
void
mrb_final_core
(
mrb_state
*
mrb
)
{
#ifndef DISABLE_GEMS
mrb_final_mrbgems
(
mrb
);
DONE
;
#endif
}
\ No newline at end of file
src/state.c
View file @
8961a788
...
...
@@ -12,6 +12,7 @@
void
mrb_init_heap
(
mrb_state
*
);
void
mrb_init_core
(
mrb_state
*
);
void
mrb_init_ext
(
mrb_state
*
);
void
mrb_final_core
(
mrb_state
*
);
mrb_state
*
mrb_open_allocf
(
mrb_allocf
f
,
void
*
ud
)
...
...
@@ -88,6 +89,8 @@ mrb_close(mrb_state *mrb)
{
int
i
;
mrb_final_core
(
mrb
);
/* free */
mrb_gc_free_gv
(
mrb
);
mrb_free
(
mrb
,
mrb
->
stbase
);
...
...
tasks/mrbgem_spec.rake
View file @
8961a788
...
...
@@ -105,6 +105,8 @@ module MRuby
print_gem_init_header
f
build
.
mrbc
.
run
f
,
rbfiles
,
"gem_mrblib_irep_
#{
funcname
}
"
unless
rbfiles
.
empty?
f
.
puts
%Q[void mrb_
#{
funcname
}
_gem_init(mrb_state *mrb);]
f
.
puts
%Q[void mrb_
#{
funcname
}
_gem_final(mrb_state *mrb);]
f
.
puts
%Q[]
f
.
puts
%Q[void GENERATED_TMP_mrb_
#{
funcname
}
_gem_init(mrb_state *mrb) {]
f
.
puts
%Q[ int ai = mrb_gc_arena_save(mrb);]
f
.
puts
%Q[ mrb_
#{
funcname
}
_gem_init(mrb);]
if
objs
!=
[
objfile
(
"
#{
build_dir
}
/gem_init"
)]
...
...
@@ -117,6 +119,10 @@ module MRuby
end
f
.
puts
%Q[ mrb_gc_arena_restore(mrb, ai);]
f
.
puts
%Q[}]
f
.
puts
%Q[]
f
.
puts
%Q[void GENERATED_TMP_mrb_
#{
funcname
}
_gem_final(mrb_state *mrb) {]
f
.
puts
%Q[ mrb_
#{
funcname
}
_gem_final(mrb);]
if
objs
!=
[
objfile
(
"
#{
build_dir
}
/gem_init"
)]
f
.
puts
%Q[}]
end
end
# generate_gem_init
...
...
tasks/mrbgems.rake
View file @
8961a788
...
...
@@ -24,10 +24,18 @@ MRuby.each_target do
f
.
puts
%Q[#include "mruby.h"]
f
.
puts
%Q[]
f
.
puts
%Q[
#{
gems
.
map
{
|
g
|
"void GENERATED_TMP_mrb_%s_gem_init(mrb_state* mrb);"
%
g
.
funcname
}
.join("
\n
")}]
f
.
puts
%Q[]
f
.
puts
%Q[
#{
gems
.
map
{
|
g
|
"void GENERATED_TMP_mrb_%s_gem_final(mrb_state* mrb);"
%
g
.
funcname
}
.join("
\n
")}]
f
.
puts
%Q[]
f
.
puts
%Q[void]
f
.
puts
%Q[mrb_init_mrbgems(mrb_state *mrb) {]
f
.
puts
%Q[
#{
gems
.
map
{
|
g
|
"GENERATED_TMP_mrb_%s_gem_init(mrb);"
%
g
.
funcname
}
.join("
\n
")}]
f
.
puts
%Q[}]
f
.
puts
%Q[]
f
.
puts
%Q[void]
f
.
puts
%Q[mrb_final_mrbgems(mrb_state *mrb) {]
f
.
puts
%Q[
#{
gems
.
map
{
|
g
|
"GENERATED_TMP_mrb_%s_gem_final(mrb);"
%
g
.
funcname
}
.join("
\n
")}]
f
.
puts
%Q[}]
end
end
end
...
...
tools/mrbc/mrbc.c
View file @
8961a788
...
...
@@ -231,4 +231,9 @@ void
mrb_init_mrbgems
(
mrb_state
*
mrb
)
{
}
void
mrb_final_mrbgems
(
mrb_state
*
mrb
)
{
}
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment