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
6a96bc46
Commit
6a96bc46
authored
Jun 05, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
git push origin masterMerge branch 'take-cheeze-atexit'
parents
cbbed402
a763d114
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
15 deletions
+34
-15
include/mruby.h
include/mruby.h
+7
-0
src/init.c
src/init.c
+0
-8
src/state.c
src/state.c
+21
-2
tasks/mrbgems.rake
tasks/mrbgems.rake
+6
-5
No files found.
include/mruby.h
View file @
6a96bc46
...
...
@@ -102,6 +102,8 @@ enum gc_state {
struct
mrb_jmpbuf
;
typedef
void
(
*
mrb_atexit_func
)(
struct
mrb_state
*
);
typedef
struct
mrb_state
{
struct
mrb_jmpbuf
*
jmp
;
...
...
@@ -170,6 +172,9 @@ typedef struct mrb_state {
struct
RObject
*
nomem_err
;
/* pre-allocated NoMemoryError */
void
*
ud
;
/* auxiliary data */
mrb_atexit_func
*
atexit_stack
;
mrb_int
atexit_stack_len
;
}
mrb_state
;
#if __STDC_VERSION__ >= 201112L
...
...
@@ -414,6 +419,8 @@ void* mrb_pool_realloc(struct mrb_pool*, void*, size_t oldlen, size_t newlen);
mrb_bool
mrb_pool_can_realloc
(
struct
mrb_pool
*
,
void
*
,
size_t
);
void
*
mrb_alloca
(
mrb_state
*
mrb
,
size_t
);
void
mrb_atexit
(
mrb_state
*
mrb
,
mrb_atexit_func
func
);
#ifdef MRB_DEBUG
#include <assert.h>
#define mrb_assert(p) assert(p)
...
...
src/init.c
View file @
6a96bc46
...
...
@@ -54,11 +54,3 @@ 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
}
src/state.c
View file @
6a96bc46
...
...
@@ -14,7 +14,6 @@
void
mrb_init_heap
(
mrb_state
*
);
void
mrb_init_core
(
mrb_state
*
);
void
mrb_final_core
(
mrb_state
*
);
static
mrb_value
inspect_main
(
mrb_state
*
mrb
,
mrb_value
mod
)
...
...
@@ -40,6 +39,7 @@ mrb_open_allocf(mrb_allocf f, void *ud)
mrb
->
ud
=
ud
;
mrb
->
allocf
=
f
;
mrb
->
current_white_part
=
MRB_GC_WHITE_A
;
mrb
->
atexit_stack_len
=
0
;
#ifndef MRB_GC_FIXED_ARENA
mrb
->
arena
=
(
struct
RBasic
**
)
mrb_malloc
(
mrb
,
sizeof
(
struct
RBasic
*
)
*
MRB_GC_ARENA_SIZE
);
...
...
@@ -221,7 +221,11 @@ mrb_free_context(mrb_state *mrb, struct mrb_context *c)
void
mrb_close
(
mrb_state
*
mrb
)
{
mrb_final_core
(
mrb
);
mrb_int
i
;
for
(
i
=
mrb
->
atexit_stack_len
;
i
>
0
;
--
i
)
{
mrb
->
atexit_stack
[
i
-
1
](
mrb
);
}
/* free */
mrb_gc_free_gv
(
mrb
);
...
...
@@ -258,3 +262,18 @@ mrb_top_self(mrb_state *mrb)
}
return
mrb_obj_value
(
mrb
->
top_self
);
}
void
mrb_atexit
(
mrb_state
*
mrb
,
mrb_atexit_func
f
)
{
size_t
stack_size
;
stack_size
=
sizeof
(
mrb_atexit_func
)
*
(
mrb
->
atexit_stack_len
+
1
);
if
(
mrb
->
atexit_stack_len
==
0
)
{
mrb
->
atexit_stack
=
(
mrb_atexit_func
*
)
mrb_malloc
(
mrb
,
stack_size
);
}
else
{
mrb
->
atexit_stack
=
(
mrb_atexit_func
*
)
mrb_realloc
(
mrb
,
mrb
->
atexit_stack
,
stack_size
);
}
mrb
->
atexit_stack
[
mrb
->
atexit_stack_len
++
]
=
f
;
}
tasks/mrbgems.rake
View file @
6a96bc46
...
...
@@ -26,14 +26,15 @@ MRuby.each_target do
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[
static
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[}]
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[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[mrb_atexit(mrb, mrb_final_mrbgems);]
f
.
puts
%Q[}]
end
end
...
...
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