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
7b0ebed0
Commit
7b0ebed0
authored
Apr 10, 2019
by
KOBAYASHI Shuji
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use `mrb_immediate_p()` in `mrb_obj_freeze()` and `mrb_obj_frozen()`
parent
d0b30f4c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
38 deletions
+25
-38
src/etc.c
src/etc.c
+2
-0
src/kernel.c
src/kernel.c
+6
-38
test/t/kernel.rb
test/t/kernel.rb
+17
-0
No files found.
src/etc.c
View file @
7b0ebed0
...
@@ -167,6 +167,7 @@ mrb_word_boxing_float_value(mrb_state *mrb, mrb_float f)
...
@@ -167,6 +167,7 @@ mrb_word_boxing_float_value(mrb_state *mrb, mrb_float f)
v
.
value
.
p
=
mrb_obj_alloc
(
mrb
,
MRB_TT_FLOAT
,
mrb
->
float_class
);
v
.
value
.
p
=
mrb_obj_alloc
(
mrb
,
MRB_TT_FLOAT
,
mrb
->
float_class
);
v
.
value
.
fp
->
f
=
f
;
v
.
value
.
fp
->
f
=
f
;
MRB_SET_FROZEN_FLAG
(
v
.
value
.
bp
);
return
v
;
return
v
;
}
}
...
@@ -177,6 +178,7 @@ mrb_word_boxing_float_pool(mrb_state *mrb, mrb_float f)
...
@@ -177,6 +178,7 @@ mrb_word_boxing_float_pool(mrb_state *mrb, mrb_float f)
nf
->
tt
=
MRB_TT_FLOAT
;
nf
->
tt
=
MRB_TT_FLOAT
;
nf
->
c
=
mrb
->
float_class
;
nf
->
c
=
mrb
->
float_class
;
nf
->
f
=
f
;
nf
->
f
=
f
;
MRB_SET_FROZEN_FLAG
(
nf
);
return
mrb_obj_value
(
nf
);
return
mrb_obj_value
(
nf
);
}
}
#endif
/* MRB_WITHOUT_FLOAT */
#endif
/* MRB_WITHOUT_FLOAT */
...
...
src/kernel.c
View file @
7b0ebed0
...
@@ -434,51 +434,19 @@ mrb_obj_extend_m(mrb_state *mrb, mrb_value self)
...
@@ -434,51 +434,19 @@ mrb_obj_extend_m(mrb_state *mrb, mrb_value self)
static
mrb_value
static
mrb_value
mrb_obj_freeze
(
mrb_state
*
mrb
,
mrb_value
self
)
mrb_obj_freeze
(
mrb_state
*
mrb
,
mrb_value
self
)
{
{
struct
RBasic
*
b
;
if
(
!
mrb_immediate_p
(
self
))
{
struct
RBasic
*
b
=
mrb_basic_ptr
(
self
);
switch
(
mrb_type
(
self
))
{
case
MRB_TT_FALSE
:
case
MRB_TT_TRUE
:
case
MRB_TT_FIXNUM
:
case
MRB_TT_SYMBOL
:
#ifndef MRB_WITHOUT_FLOAT
case
MRB_TT_FLOAT
:
#endif
return
self
;
default:
break
;
}
b
=
mrb_basic_ptr
(
self
);
if
(
!
MRB_FROZEN_P
(
b
))
{
if
(
!
MRB_FROZEN_P
(
b
))
{
MRB_SET_FROZEN_FLAG
(
b
);
MRB_SET_FROZEN_FLAG
(
b
);
}
}
}
return
self
;
return
self
;
}
}
static
mrb_value
static
mrb_value
mrb_obj_frozen
(
mrb_state
*
mrb
,
mrb_value
self
)
mrb_obj_frozen
(
mrb_state
*
mrb
,
mrb_value
self
)
{
{
struct
RBasic
*
b
;
return
mrb_bool_value
(
mrb_immediate_p
(
self
)
||
MRB_FROZEN_P
(
mrb_basic_ptr
(
self
)));
switch
(
mrb_type
(
self
))
{
case
MRB_TT_FALSE
:
case
MRB_TT_TRUE
:
case
MRB_TT_FIXNUM
:
case
MRB_TT_SYMBOL
:
#ifndef MRB_WITHOUT_FLOAT
case
MRB_TT_FLOAT
:
#endif
return
mrb_true_value
();
default:
break
;
}
b
=
mrb_basic_ptr
(
self
);
if
(
!
MRB_FROZEN_P
(
b
))
{
return
mrb_false_value
();
}
return
mrb_true_value
();
}
}
/* 15.3.1.3.15 */
/* 15.3.1.3.15 */
...
...
test/t/kernel.rb
View file @
7b0ebed0
...
@@ -247,6 +247,23 @@ assert('Kernel#freeze') do
...
@@ -247,6 +247,23 @@ assert('Kernel#freeze') do
assert_equal
obj
,
obj
.
freeze
assert_equal
obj
,
obj
.
freeze
assert_equal
0
,
0
.
freeze
assert_equal
0
,
0
.
freeze
assert_equal
:a
,
:a
.
freeze
assert_equal
:a
,
:a
.
freeze
assert_equal
true
,
true
.
freeze
assert_equal
false
,
false
.
freeze
assert_equal
nil
,
nil
.
freeze
skip
unless
Object
.
const_defined?
(
:Float
)
assert_equal
0.0
,
0.0
.
freeze
end
assert
(
'Kernel#frozen?'
)
do
assert_false
""
.
frozen?
assert_true
""
.
freeze
.
frozen?
assert_true
0
.
frozen?
assert_true
:a
.
frozen?
assert_true
true
.
frozen?
assert_true
false
.
frozen?
assert_true
nil
.
frozen?
skip
unless
Object
.
const_defined?
(
:Float
)
assert_true
0.0
.
frozen?
end
end
assert
(
'Kernel#global_variables'
,
'15.3.1.3.14'
)
do
assert
(
'Kernel#global_variables'
,
'15.3.1.3.14'
)
do
...
...
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