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
e3beef06
Commit
e3beef06
authored
Apr 09, 2019
by
KOBAYASHI Shuji
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract frozen checking to function
parent
ec168880
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
20 additions
and
30 deletions
+20
-30
include/mruby.h
include/mruby.h
+6
-0
mrbgems/mruby-struct/src/struct.c
mrbgems/mruby-struct/src/struct.c
+1
-4
src/array.c
src/array.c
+1
-3
src/class.c
src/class.c
+1
-6
src/error.c
src/error.c
+7
-0
src/hash.c
src/hash.c
+1
-4
src/string.c
src/string.c
+2
-10
src/variable.c
src/variable.c
+1
-3
No files found.
include/mruby.h
View file @
e3beef06
...
@@ -1143,6 +1143,7 @@ MRB_API mrb_noreturn void mrb_exc_raise(mrb_state *mrb, mrb_value exc);
...
@@ -1143,6 +1143,7 @@ MRB_API mrb_noreturn void mrb_exc_raise(mrb_state *mrb, mrb_value exc);
MRB_API
mrb_noreturn
void
mrb_raise
(
mrb_state
*
mrb
,
struct
RClass
*
c
,
const
char
*
msg
);
MRB_API
mrb_noreturn
void
mrb_raise
(
mrb_state
*
mrb
,
struct
RClass
*
c
,
const
char
*
msg
);
MRB_API
mrb_noreturn
void
mrb_raisef
(
mrb_state
*
mrb
,
struct
RClass
*
c
,
const
char
*
fmt
,
...);
MRB_API
mrb_noreturn
void
mrb_raisef
(
mrb_state
*
mrb
,
struct
RClass
*
c
,
const
char
*
fmt
,
...);
MRB_API
mrb_noreturn
void
mrb_name_error
(
mrb_state
*
mrb
,
mrb_sym
id
,
const
char
*
fmt
,
...);
MRB_API
mrb_noreturn
void
mrb_name_error
(
mrb_state
*
mrb
,
mrb_sym
id
,
const
char
*
fmt
,
...);
MRB_API
mrb_noreturn
void
mrb_frozen_error
(
mrb_state
*
mrb
,
void
*
frozen_obj
);
MRB_API
void
mrb_warn
(
mrb_state
*
mrb
,
const
char
*
fmt
,
...);
MRB_API
void
mrb_warn
(
mrb_state
*
mrb
,
const
char
*
fmt
,
...);
MRB_API
mrb_noreturn
void
mrb_bug
(
mrb_state
*
mrb
,
const
char
*
fmt
,
...);
MRB_API
mrb_noreturn
void
mrb_bug
(
mrb_state
*
mrb
,
const
char
*
fmt
,
...);
MRB_API
void
mrb_print_backtrace
(
mrb_state
*
mrb
);
MRB_API
void
mrb_print_backtrace
(
mrb_state
*
mrb
);
...
@@ -1196,6 +1197,11 @@ MRB_API mrb_value mrb_to_int(mrb_state *mrb, mrb_value val);
...
@@ -1196,6 +1197,11 @@ MRB_API mrb_value mrb_to_int(mrb_state *mrb, mrb_value val);
MRB_API
mrb_value
mrb_to_str
(
mrb_state
*
mrb
,
mrb_value
val
);
MRB_API
mrb_value
mrb_to_str
(
mrb_state
*
mrb
,
mrb_value
val
);
MRB_API
void
mrb_check_type
(
mrb_state
*
mrb
,
mrb_value
x
,
enum
mrb_vtype
t
);
MRB_API
void
mrb_check_type
(
mrb_state
*
mrb
,
mrb_value
x
,
enum
mrb_vtype
t
);
static
inline
void
mrb_check_frozen
(
mrb_state
*
mrb
,
void
*
o
)
{
if
(
MRB_FROZEN_P
((
struct
RBasic
*
)
o
))
mrb_frozen_error
(
mrb
,
o
);
}
typedef
enum
call_type
{
typedef
enum
call_type
{
CALL_PUBLIC
,
CALL_PUBLIC
,
CALL_FCALL
,
CALL_FCALL
,
...
...
mrbgems/mruby-struct/src/struct.c
View file @
e3beef06
...
@@ -87,10 +87,7 @@ mrb_struct_s_members_m(mrb_state *mrb, mrb_value klass)
...
@@ -87,10 +87,7 @@ mrb_struct_s_members_m(mrb_state *mrb, mrb_value klass)
static
void
static
void
mrb_struct_modify
(
mrb_state
*
mrb
,
mrb_value
strct
)
mrb_struct_modify
(
mrb_state
*
mrb
,
mrb_value
strct
)
{
{
if
(
MRB_FROZEN_P
(
mrb_basic_ptr
(
strct
)))
{
mrb_check_frozen
(
mrb
,
mrb_basic_ptr
(
strct
));
mrb_raise
(
mrb
,
E_FROZEN_ERROR
,
"can't modify frozen struct"
);
}
mrb_write_barrier
(
mrb
,
mrb_basic_ptr
(
strct
));
mrb_write_barrier
(
mrb
,
mrb_basic_ptr
(
strct
));
}
}
...
...
src/array.c
View file @
e3beef06
...
@@ -120,9 +120,7 @@ ary_fill_with_nil(mrb_value *ptr, mrb_int size)
...
@@ -120,9 +120,7 @@ ary_fill_with_nil(mrb_value *ptr, mrb_int size)
static
void
static
void
ary_modify_check
(
mrb_state
*
mrb
,
struct
RArray
*
a
)
ary_modify_check
(
mrb_state
*
mrb
,
struct
RArray
*
a
)
{
{
if
(
MRB_FROZEN_P
(
a
))
{
mrb_check_frozen
(
mrb
,
a
);
mrb_raise
(
mrb
,
E_FROZEN_ERROR
,
"can't modify frozen array"
);
}
}
}
static
void
static
void
...
...
src/class.c
View file @
e3beef06
...
@@ -441,12 +441,7 @@ mrb_define_method_raw(mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_method_
...
@@ -441,12 +441,7 @@ mrb_define_method_raw(mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_method_
MRB_CLASS_ORIGIN
(
c
);
MRB_CLASS_ORIGIN
(
c
);
h
=
c
->
mt
;
h
=
c
->
mt
;
if
(
MRB_FROZEN_P
(
c
))
{
mrb_check_frozen
(
mrb
,
c
);
if
(
c
->
tt
==
MRB_TT_MODULE
)
mrb_raise
(
mrb
,
E_FROZEN_ERROR
,
"can't modify frozen module"
);
else
mrb_raise
(
mrb
,
E_FROZEN_ERROR
,
"can't modify frozen class"
);
}
if
(
!
h
)
h
=
c
->
mt
=
kh_init
(
mt
,
mrb
);
if
(
!
h
)
h
=
c
->
mt
=
kh_init
(
mt
,
mrb
);
k
=
kh_put
(
mt
,
mrb
,
h
,
mid
);
k
=
kh_put
(
mt
,
mrb
,
h
,
mid
);
kh_value
(
h
,
k
)
=
m
;
kh_value
(
h
,
k
)
=
m
;
...
...
src/error.c
View file @
e3beef06
...
@@ -484,6 +484,13 @@ mrb_no_method_error(mrb_state *mrb, mrb_sym id, mrb_value args, char const* fmt,
...
@@ -484,6 +484,13 @@ mrb_no_method_error(mrb_state *mrb, mrb_sym id, mrb_value args, char const* fmt,
mrb_exc_raise
(
mrb
,
exc
);
mrb_exc_raise
(
mrb
,
exc
);
}
}
MRB_API
mrb_noreturn
void
mrb_frozen_error
(
mrb_state
*
mrb
,
void
*
frozen_obj
)
{
mrb_raisef
(
mrb
,
E_FROZEN_ERROR
,
"can't modify frozen %S"
,
mrb_obj_value
(
mrb_class
(
mrb
,
mrb_obj_value
(
frozen_obj
))));
}
void
void
mrb_init_exception
(
mrb_state
*
mrb
)
mrb_init_exception
(
mrb_state
*
mrb
)
{
{
...
...
src/hash.c
View file @
e3beef06
...
@@ -746,10 +746,7 @@ mrb_hash_set(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value val)
...
@@ -746,10 +746,7 @@ mrb_hash_set(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value val)
static
void
static
void
mrb_hash_modify
(
mrb_state
*
mrb
,
mrb_value
hash
)
mrb_hash_modify
(
mrb_state
*
mrb
,
mrb_value
hash
)
{
{
if
(
MRB_FROZEN_P
(
mrb_hash_ptr
(
hash
)))
{
mrb_check_frozen
(
mrb
,
mrb_hash_ptr
(
hash
));
mrb_raise
(
mrb
,
E_FROZEN_ERROR
,
"can't modify frozen hash"
);
}
if
(
!
RHASH_TBL
(
hash
))
{
if
(
!
RHASH_TBL
(
hash
))
{
RHASH_TBL
(
hash
)
=
ht_new
(
mrb
);
RHASH_TBL
(
hash
)
=
ht_new
(
mrb
);
}
}
...
...
src/string.c
View file @
e3beef06
...
@@ -493,20 +493,12 @@ str_index_str(mrb_state *mrb, mrb_value str, mrb_value str2, mrb_int offset)
...
@@ -493,20 +493,12 @@ str_index_str(mrb_state *mrb, mrb_value str, mrb_value str2, mrb_int offset)
return
mrb_str_index
(
mrb
,
str
,
ptr
,
len
,
offset
);
return
mrb_str_index
(
mrb
,
str
,
ptr
,
len
,
offset
);
}
}
static
void
check_frozen
(
mrb_state
*
mrb
,
struct
RString
*
s
)
{
if
(
MRB_FROZEN_P
(
s
))
{
mrb_raise
(
mrb
,
E_FROZEN_ERROR
,
"can't modify frozen string"
);
}
}
static
mrb_value
static
mrb_value
str_replace
(
mrb_state
*
mrb
,
struct
RString
*
s1
,
struct
RString
*
s2
)
str_replace
(
mrb_state
*
mrb
,
struct
RString
*
s1
,
struct
RString
*
s2
)
{
{
mrb_int
len
;
mrb_int
len
;
check_frozen
(
mrb
,
s1
);
mrb_
check_frozen
(
mrb
,
s1
);
if
(
s1
==
s2
)
return
mrb_obj_value
(
s1
);
if
(
s1
==
s2
)
return
mrb_obj_value
(
s1
);
s1
->
flags
&=
~
MRB_STR_NO_UTF
;
s1
->
flags
&=
~
MRB_STR_NO_UTF
;
s1
->
flags
|=
s2
->
flags
&
MRB_STR_NO_UTF
;
s1
->
flags
|=
s2
->
flags
&
MRB_STR_NO_UTF
;
...
@@ -646,7 +638,7 @@ mrb_locale_from_utf8(const char *utf8, int len)
...
@@ -646,7 +638,7 @@ mrb_locale_from_utf8(const char *utf8, int len)
MRB_API
void
MRB_API
void
mrb_str_modify
(
mrb_state
*
mrb
,
struct
RString
*
s
)
mrb_str_modify
(
mrb_state
*
mrb
,
struct
RString
*
s
)
{
{
check_frozen
(
mrb
,
s
);
mrb_
check_frozen
(
mrb
,
s
);
s
->
flags
&=
~
MRB_STR_NO_UTF
;
s
->
flags
&=
~
MRB_STR_NO_UTF
;
if
(
RSTR_SHARED_P
(
s
))
{
if
(
RSTR_SHARED_P
(
s
))
{
mrb_shared_string
*
shared
=
s
->
as
.
heap
.
aux
.
shared
;
mrb_shared_string
*
shared
=
s
->
as
.
heap
.
aux
.
shared
;
...
...
src/variable.c
View file @
e3beef06
...
@@ -346,9 +346,7 @@ mrb_obj_iv_set(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v)
...
@@ -346,9 +346,7 @@ mrb_obj_iv_set(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v)
{
{
iv_tbl
*
t
;
iv_tbl
*
t
;
if
(
MRB_FROZEN_P
(
obj
))
{
mrb_check_frozen
(
mrb
,
obj
);
mrb_raisef
(
mrb
,
E_FROZEN_ERROR
,
"can't modify frozen %S"
,
mrb_obj_value
(
obj
));
}
assign_class_name
(
mrb
,
obj
,
sym
,
v
);
assign_class_name
(
mrb
,
obj
,
sym
,
v
);
if
(
!
obj
->
iv
)
{
if
(
!
obj
->
iv
)
{
obj
->
iv
=
iv_new
(
mrb
);
obj
->
iv
=
iv_new
(
mrb
);
...
...
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