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
bd72dba8
Unverified
Commit
bd72dba8
authored
Feb 06, 2017
by
ksss
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Kernel#local_variables: Make result array unique
parent
f2b18a60
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
9 deletions
+9
-9
src/kernel.c
src/kernel.c
+6
-5
test/t/kernel.rb
test/t/kernel.rb
+3
-4
No files found.
src/kernel.c
View file @
bd72dba8
...
...
@@ -6,6 +6,7 @@
#include <mruby.h>
#include <mruby/array.h>
#include <mruby/hash.h>
#include <mruby/class.h>
#include <mruby/proc.h>
#include <mruby/string.h>
...
...
@@ -1106,8 +1107,8 @@ mrb_obj_ceqq(mrb_state *mrb, mrb_value self)
static
mrb_value
mrb_local_variables
(
mrb_state
*
mrb
,
mrb_value
self
)
{
mrb_value
ret
;
struct
RProc
*
proc
;
mrb_value
vars
;
struct
mrb_irep
*
irep
;
size_t
i
;
...
...
@@ -1121,10 +1122,10 @@ mrb_local_variables(mrb_state *mrb, mrb_value self)
if
(
!
irep
->
lv
)
{
return
mrb_ary_new
(
mrb
);
}
ret
=
mrb_ary_new_capa
(
mrb
,
irep
->
nlocals
-
1
);
vars
=
mrb_hash_new
(
mrb
);
for
(
i
=
0
;
i
+
1
<
irep
->
nlocals
;
++
i
)
{
if
(
irep
->
lv
[
i
].
name
)
{
mrb_
ary_push
(
mrb
,
ret
,
mrb_symbol_value
(
irep
->
lv
[
i
].
name
));
mrb_
hash_set
(
mrb
,
vars
,
mrb_symbol_value
(
irep
->
lv
[
i
].
name
),
mrb_true_value
(
));
}
}
if
(
proc
->
env
)
{
...
...
@@ -1137,7 +1138,7 @@ mrb_local_variables(mrb_state *mrb, mrb_value self)
if
(
irep
->
lv
)
{
for
(
i
=
0
;
i
+
1
<
irep
->
nlocals
;
++
i
)
{
if
(
irep
->
lv
[
i
].
name
)
{
mrb_
ary_push
(
mrb
,
ret
,
mrb_symbol_value
(
irep
->
lv
[
i
].
name
));
mrb_
hash_set
(
mrb
,
vars
,
mrb_symbol_value
(
irep
->
lv
[
i
].
name
),
mrb_true_value
(
));
}
}
}
...
...
@@ -1146,7 +1147,7 @@ mrb_local_variables(mrb_state *mrb, mrb_value self)
}
}
return
ret
;
return
mrb_hash_keys
(
mrb
,
vars
)
;
}
void
...
...
test/t/kernel.rb
View file @
bd72dba8
...
...
@@ -549,11 +549,10 @@ assert('Kernel.local_variables', '15.3.1.2.7') do
vars
=
Kernel
.
local_variables
.
sort
assert_equal
[
:a
,
:b
,
:vars
],
vars
Proc
.
new
{
assert_equal
[
:a
,
:b
,
:c
,
:vars
],
Proc
.
new
{
|
a
,
b
|
c
=
2
vars
=
Kernel
.
local_variables
.
sort
assert_equal
[
:a
,
:b
,
:c
,
:vars
],
vars
}.
call
Kernel
.
local_variables
.
sort
}.
call
(
-
1
,
-
2
)
end
assert
(
'Kernel#!='
)
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