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
272fe3d8
Commit
272fe3d8
authored
Mar 20, 2014
by
take_cheeze
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use FiberError in fiber exception raise
parent
07d81a11
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
14 deletions
+21
-14
include/mruby.h
include/mruby.h
+1
-0
mrbgems/mruby-fiber/src/fiber.c
mrbgems/mruby-fiber/src/fiber.c
+12
-10
mrbgems/mruby-fiber/test/fiber.rb
mrbgems/mruby-fiber/test/fiber.rb
+8
-4
No files found.
include/mruby.h
View file @
272fe3d8
...
...
@@ -389,6 +389,7 @@ mrb_bool mrb_obj_is_instance_of(mrb_state *mrb, mrb_value obj, struct RClass* c)
/* fiber functions (you need to link mruby-fiber mrbgem to use) */
mrb_value
mrb_fiber_yield
(
mrb_state
*
mrb
,
int
argc
,
mrb_value
*
argv
);
#define E_FIBER_ERROR (mrb_class_get(mrb, "FiberError"))
/* memory pool implementation */
typedef
struct
mrb_pool
mrb_pool
;
...
...
mrbgems/mruby-fiber/src/fiber.c
View file @
272fe3d8
...
...
@@ -36,7 +36,7 @@
*
* 1
* 2
* resuming dead fiber (
Runtime
Error)
* resuming dead fiber (
Fiber
Error)
*
* The <code>Fiber#resume</code> method accepts an arbitrary number of
* parameters, if it is the first call to <code>resume</code> then they
...
...
@@ -57,7 +57,7 @@
*
* 12
* 14
* resuming dead fiber (
Runtime
Error)
* resuming dead fiber (
Fiber
Error)
*
*/
static
mrb_value
...
...
@@ -73,11 +73,11 @@ fiber_init(mrb_state *mrb, mrb_value self)
mrb_get_args
(
mrb
,
"&"
,
&
blk
);
if
(
mrb_nil_p
(
blk
))
{
mrb_raise
(
mrb
,
E_
ARGUMENT
_ERROR
,
"tried to create Fiber object without a block"
);
mrb_raise
(
mrb
,
E_
FIBER
_ERROR
,
"tried to create Fiber object without a block"
);
}
p
=
mrb_proc_ptr
(
blk
);
if
(
MRB_PROC_CFUNC_P
(
p
))
{
mrb_raise
(
mrb
,
E_
ARGUMENT
_ERROR
,
"tried to create Fiber from C defined method"
);
mrb_raise
(
mrb
,
E_
FIBER
_ERROR
,
"tried to create Fiber from C defined method"
);
}
f
->
cxt
=
(
struct
mrb_context
*
)
mrb_malloc
(
mrb
,
sizeof
(
struct
mrb_context
));
...
...
@@ -120,7 +120,7 @@ fiber_check(mrb_state *mrb, mrb_value fib)
mrb_assert
(
f
->
tt
==
MRB_TT_FIBER
);
if
(
!
f
->
cxt
)
{
mrb_raise
(
mrb
,
E_
ARGUMENT
_ERROR
,
"uninitialized Fiber"
);
mrb_raise
(
mrb
,
E_
FIBER
_ERROR
,
"uninitialized Fiber"
);
}
return
f
->
cxt
;
}
...
...
@@ -161,14 +161,14 @@ fiber_resume(mrb_state *mrb, mrb_value self)
for
(
ci
=
c
->
ci
;
ci
>=
c
->
cibase
;
ci
--
)
{
if
(
ci
->
acc
<
0
)
{
mrb_raise
(
mrb
,
E_
ARGUMENT
_ERROR
,
"can't cross C function boundary"
);
mrb_raise
(
mrb
,
E_
FIBER
_ERROR
,
"can't cross C function boundary"
);
}
}
if
(
c
->
status
==
MRB_FIBER_RUNNING
||
c
->
status
==
MRB_FIBER_RESUMING
)
{
mrb_raise
(
mrb
,
E_
RUNTIME
_ERROR
,
"double resume"
);
mrb_raise
(
mrb
,
E_
FIBER
_ERROR
,
"double resume"
);
}
if
(
c
->
status
==
MRB_FIBER_TERMINATED
)
{
mrb_raise
(
mrb
,
E_
RUNTIME
_ERROR
,
"resuming dead fiber"
);
mrb_raise
(
mrb
,
E_
FIBER
_ERROR
,
"resuming dead fiber"
);
}
mrb_get_args
(
mrb
,
"*"
,
&
a
,
&
len
);
mrb
->
c
->
status
=
MRB_FIBER_RESUMING
;
...
...
@@ -235,11 +235,11 @@ mrb_fiber_yield(mrb_state *mrb, int len, mrb_value *a)
for
(
ci
=
c
->
ci
;
ci
>=
c
->
cibase
;
ci
--
)
{
if
(
ci
->
acc
<
0
)
{
mrb_raise
(
mrb
,
E_
ARGUMENT
_ERROR
,
"can't cross C function boundary"
);
mrb_raise
(
mrb
,
E_
FIBER
_ERROR
,
"can't cross C function boundary"
);
}
}
if
(
!
c
->
prev
)
{
mrb_raise
(
mrb
,
E_
ARGUMENT
_ERROR
,
"can't yield from root fiber"
);
mrb_raise
(
mrb
,
E_
FIBER
_ERROR
,
"can't yield from root fiber"
);
}
c
->
prev
->
status
=
MRB_FIBER_RUNNING
;
...
...
@@ -305,6 +305,8 @@ mrb_mruby_fiber_gem_init(mrb_state* mrb)
mrb_define_class_method
(
mrb
,
c
,
"yield"
,
fiber_yield
,
MRB_ARGS_ANY
());
mrb_define_class_method
(
mrb
,
c
,
"current"
,
fiber_current
,
MRB_ARGS_NONE
());
mrb_define_class
(
mrb
,
"FiberError"
,
mrb
->
eStandardError_class
);
}
void
...
...
mrbgems/mruby-fiber/test/fiber.rb
View file @
272fe3d8
...
...
@@ -35,6 +35,10 @@ assert('Fiber.yield') {
f
.
resume
(
3
)
}
assert
(
'FiberError'
)
do
assert_equal
StandardError
,
FiberError
.
superclass
end
assert
(
'Fiber iteration'
)
{
f1
=
Fiber
.
new
{
[
1
,
2
,
3
].
each
{
|
x
|
Fiber
.
yield
(
x
)}
...
...
@@ -80,7 +84,7 @@ assert('Double resume of Fiber') do
f1
=
Fiber
.
new
{}
f2
=
Fiber
.
new
{
f1
.
resume
assert_raise
(
Runtime
Error
)
{
f2
.
resume
}
assert_raise
(
Fiber
Error
)
{
f2
.
resume
}
Fiber
.
yield
0
}
assert_equal
0
,
f2
.
resume
...
...
@@ -91,7 +95,7 @@ end
assert
(
'Recursive resume of Fiber'
)
do
f1
,
f2
=
nil
,
nil
f1
=
Fiber
.
new
{
assert_raise
(
Runtime
Error
)
{
f2
.
resume
}
}
f1
=
Fiber
.
new
{
assert_raise
(
Fiber
Error
)
{
f2
.
resume
}
}
f2
=
Fiber
.
new
{
f1
.
resume
Fiber
.
yield
0
...
...
@@ -108,9 +112,9 @@ end
assert
(
'Root fiber resume'
)
do
root
=
Fiber
.
current
assert_raise
(
Runtime
Error
)
{
root
.
resume
}
assert_raise
(
Fiber
Error
)
{
root
.
resume
}
f
=
Fiber
.
new
{
assert_raise
(
Runtime
Error
)
{
root
.
resume
}
assert_raise
(
Fiber
Error
)
{
root
.
resume
}
}
f
.
resume
assert_false
f
.
alive?
...
...
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