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
e926b532
Commit
e926b532
authored
Jul 22, 2014
by
take_cheeze
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Store exception message to `mesg` field of `struct RException`.
parent
23b6e22c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
6 deletions
+34
-6
include/mruby/error.h
include/mruby/error.h
+2
-0
src/error.c
src/error.c
+18
-4
src/gc.c
src/gc.c
+14
-2
No files found.
include/mruby/error.h
View file @
e926b532
...
...
@@ -14,9 +14,11 @@ extern "C" {
struct
RException
{
MRB_OBJECT_HEADER
;
struct
iv_tbl
*
iv
;
mrb_value
mesg
;
};
#define mrb_exc_ptr(v) ((struct RException*)mrb_ptr(v))
#define MRB_EXC_MESG_INIT_FLAG 0x100
void
mrb_sys_fail
(
mrb_state
*
mrb
,
const
char
*
mesg
);
mrb_value
mrb_exc_new_str
(
mrb_state
*
mrb
,
struct
RClass
*
c
,
mrb_value
str
);
...
...
src/error.c
View file @
e926b532
...
...
@@ -18,6 +18,20 @@
#include "mruby/class.h"
#include "mrb_throw.h"
static
void
exc_mesg_set
(
mrb_state
*
mrb
,
struct
RException
*
exc
,
mrb_value
mesg
)
{
exc
->
flags
|=
MRB_EXC_MESG_INIT_FLAG
;
exc
->
mesg
=
mesg
;
mrb_field_write_barrier_value
(
mrb
,
(
struct
RBasic
*
)
exc
,
mesg
);
}
static
mrb_value
exc_mesg_get
(
mrb_state
*
mrb
,
struct
RException
*
exc
)
{
return
(
exc
->
flags
&
MRB_EXC_MESG_INIT_FLAG
)
!=
0
?
exc
->
mesg
:
mrb_nil_value
();
}
mrb_value
mrb_exc_new
(
mrb_state
*
mrb
,
struct
RClass
*
c
,
const
char
*
ptr
,
long
len
)
{
...
...
@@ -46,7 +60,7 @@ exc_initialize(mrb_state *mrb, mrb_value exc)
mrb_value
mesg
;
if
(
mrb_get_args
(
mrb
,
"|o"
,
&
mesg
)
==
1
)
{
mrb_iv_set
(
mrb
,
exc
,
mrb_intern_lit
(
mrb
,
"mesg"
),
mesg
);
exc_mesg_set
(
mrb
,
mrb_exc_ptr
(
exc
),
mesg
);
}
return
exc
;
}
...
...
@@ -75,7 +89,7 @@ exc_exception(mrb_state *mrb, mrb_value self)
if
(
argc
==
0
)
return
self
;
if
(
mrb_obj_equal
(
mrb
,
self
,
a
))
return
self
;
exc
=
mrb_obj_clone
(
mrb
,
self
);
mrb_iv_set
(
mrb
,
exc
,
mrb_intern_lit
(
mrb
,
"mesg"
),
a
);
exc_mesg_set
(
mrb
,
mrb_exc_ptr
(
exc
),
a
);
return
exc
;
}
...
...
@@ -91,7 +105,7 @@ exc_exception(mrb_state *mrb, mrb_value self)
static
mrb_value
exc_to_s
(
mrb_state
*
mrb
,
mrb_value
exc
)
{
mrb_value
mesg
=
mrb_attr_get
(
mrb
,
exc
,
mrb_intern_lit
(
mrb
,
"mesg"
));
mrb_value
mesg
=
exc_mesg_get
(
mrb
,
mrb_exc_ptr
(
exc
));
struct
RObject
*
p
;
if
(
!
mrb_string_p
(
mesg
))
{
...
...
@@ -136,7 +150,7 @@ exc_inspect(mrb_state *mrb, mrb_value exc)
mrb_value
str
,
mesg
,
file
,
line
;
mrb_bool
append_mesg
;
mesg
=
mrb_attr_get
(
mrb
,
exc
,
mrb_intern_lit
(
mrb
,
"mesg"
));
mesg
=
exc_mesg_get
(
mrb
,
mrb_exc_ptr
(
exc
));
file
=
mrb_attr_get
(
mrb
,
exc
,
mrb_intern_lit
(
mrb
,
"file"
));
line
=
mrb_attr_get
(
mrb
,
exc
,
mrb_intern_lit
(
mrb
,
"line"
));
...
...
src/gc.c
View file @
e926b532
...
...
@@ -515,7 +515,6 @@ gc_mark_children(mrb_state *mrb, struct RBasic *obj)
case
MRB_TT_OBJECT
:
case
MRB_TT_DATA
:
case
MRB_TT_EXCEPTION
:
mrb_gc_mark_iv
(
mrb
,
(
struct
RObject
*
)
obj
);
break
;
...
...
@@ -581,6 +580,13 @@ gc_mark_children(mrb_state *mrb, struct RBasic *obj)
}
break
;
case
MRB_TT_EXCEPTION
:
mrb_gc_mark_iv
(
mrb
,
(
struct
RObject
*
)
obj
);
if
((
obj
->
flags
&
MRB_EXC_MESG_INIT_FLAG
)
!=
0
)
{
mrb_gc_mark_value
(
mrb
,
((
struct
RException
*
)
obj
)
->
mesg
);
}
break
;
default:
break
;
}
...
...
@@ -751,7 +757,6 @@ gc_gray_mark(mrb_state *mrb, struct RBasic *obj)
case
MRB_TT_OBJECT
:
case
MRB_TT_DATA
:
case
MRB_TT_EXCEPTION
:
children
+=
mrb_gc_mark_iv_size
(
mrb
,
(
struct
RObject
*
)
obj
);
break
;
...
...
@@ -801,6 +806,13 @@ gc_gray_mark(mrb_state *mrb, struct RBasic *obj)
children
+=
2
;
break
;
case
MRB_TT_EXCEPTION
:
children
+=
mrb_gc_mark_iv_size
(
mrb
,
(
struct
RObject
*
)
obj
);
if
((
obj
->
flags
&
MRB_EXC_MESG_INIT_FLAG
)
!=
0
)
{
children
++
;
}
break
;
default:
break
;
}
...
...
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