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
d77b2541
Commit
d77b2541
authored
Nov 25, 2016
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Nov 25, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3287 from bouk/proc-arity
Fix calling .arity on Proc with undefined `initialize`
parents
6905597f
1ec59943
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
7 deletions
+33
-7
mrbgems/mruby-proc-ext/src/proc.c
mrbgems/mruby-proc-ext/src/proc.c
+3
-0
mrbgems/mruby-proc-ext/test/proc.rb
mrbgems/mruby-proc-ext/test/proc.rb
+11
-0
src/proc.c
src/proc.c
+8
-7
test/t/proc.rb
test/t/proc.rb
+11
-0
No files found.
mrbgems/mruby-proc-ext/src/proc.c
View file @
d77b2541
...
@@ -114,6 +114,9 @@ mrb_proc_parameters(mrb_state *mrb, mrb_value self)
...
@@ -114,6 +114,9 @@ mrb_proc_parameters(mrb_state *mrb, mrb_value self)
// TODO cfunc aspec is not implemented yet
// TODO cfunc aspec is not implemented yet
return
mrb_ary_new
(
mrb
);
return
mrb_ary_new
(
mrb
);
}
}
if
(
!
irep
)
{
return
mrb_ary_new
(
mrb
);
}
if
(
!
irep
->
lv
)
{
if
(
!
irep
->
lv
)
{
return
mrb_ary_new
(
mrb
);
return
mrb_ary_new
(
mrb
);
}
}
...
...
mrbgems/mruby-proc-ext/test/proc.rb
View file @
d77b2541
...
@@ -58,6 +58,17 @@ assert('Proc#parameters') do
...
@@ -58,6 +58,17 @@ assert('Proc#parameters') do
assert_equal
([[
:req
,
:a
],
[
:req
,
:b
],
[
:opt
,
:c
],
[
:opt
,
:d
],
[
:rest
,
:e
],
[
:req
,
:f
],
[
:req
,
:g
],
[
:block
,
:h
]],
lambda
{
|
a
,
b
,
c
=
:c
,
d
=
:d
,
*
e
,
f
,
g
,
&
h
|
}.
parameters
)
assert_equal
([[
:req
,
:a
],
[
:req
,
:b
],
[
:opt
,
:c
],
[
:opt
,
:d
],
[
:rest
,
:e
],
[
:req
,
:f
],
[
:req
,
:g
],
[
:block
,
:h
]],
lambda
{
|
a
,
b
,
c
=
:c
,
d
=
:d
,
*
e
,
f
,
g
,
&
h
|
}.
parameters
)
end
end
assert
(
'Proc#parameters with uninitialized Proc'
)
do
begin
Proc
.
alias_method
(
:original_initialize
,
:initialize
)
Proc
.
remove_method
(
:initialize
)
assert_equal
[],
Proc
.
new
{
|
a
,
b
,
c
|
1
}.
parameters
ensure
Proc
.
alias_method
(
:initialize
,
:original_initialize
)
Proc
.
remove_method
(
:original_initialize
)
end
end
assert
(
'Proc#to_proc'
)
do
assert
(
'Proc#to_proc'
)
do
proc
=
Proc
.
new
{}
proc
=
Proc
.
new
{}
assert_equal
proc
,
proc
.
to_proc
assert_equal
proc
,
proc
.
to_proc
...
...
src/proc.c
View file @
d77b2541
...
@@ -188,18 +188,13 @@ mrb_proc_call_cfunc(mrb_state *mrb, struct RProc *p, mrb_value self)
...
@@ -188,18 +188,13 @@ mrb_proc_call_cfunc(mrb_state *mrb, struct RProc *p, mrb_value self)
return
(
p
->
body
.
func
)(
mrb
,
self
);
return
(
p
->
body
.
func
)(
mrb
,
self
);
}
}
mrb_code
*
mrb_proc_iseq
(
mrb_state
*
mrb
,
struct
RProc
*
p
)
{
return
p
->
body
.
irep
->
iseq
;
}
/* 15.2.17.4.2 */
/* 15.2.17.4.2 */
static
mrb_value
static
mrb_value
mrb_proc_arity
(
mrb_state
*
mrb
,
mrb_value
self
)
mrb_proc_arity
(
mrb_state
*
mrb
,
mrb_value
self
)
{
{
struct
RProc
*
p
=
mrb_proc_ptr
(
self
);
struct
RProc
*
p
=
mrb_proc_ptr
(
self
);
mrb_code
*
iseq
=
mrb_proc_iseq
(
mrb
,
p
);
struct
mrb_irep
*
irep
;
mrb_code
*
iseq
;
mrb_aspec
aspec
;
mrb_aspec
aspec
;
int
ma
,
op
,
ra
,
pa
,
arity
;
int
ma
,
op
,
ra
,
pa
,
arity
;
...
@@ -208,6 +203,12 @@ mrb_proc_arity(mrb_state *mrb, mrb_value self)
...
@@ -208,6 +203,12 @@ mrb_proc_arity(mrb_state *mrb, mrb_value self)
return
mrb_fixnum_value
(
-
1
);
return
mrb_fixnum_value
(
-
1
);
}
}
irep
=
p
->
body
.
irep
;
if
(
!
irep
)
{
return
mrb_fixnum_value
(
0
);
}
iseq
=
irep
->
iseq
;
/* arity is depend on OP_ENTER */
/* arity is depend on OP_ENTER */
if
(
GET_OPCODE
(
*
iseq
)
!=
OP_ENTER
)
{
if
(
GET_OPCODE
(
*
iseq
)
!=
OP_ENTER
)
{
return
mrb_fixnum_value
(
0
);
return
mrb_fixnum_value
(
0
);
...
...
test/t/proc.rb
View file @
d77b2541
...
@@ -46,6 +46,17 @@ assert('Proc#arity', '15.2.17.4.2') do
...
@@ -46,6 +46,17 @@ assert('Proc#arity', '15.2.17.4.2') do
assert_equal
(
-
1
,
g
)
assert_equal
(
-
1
,
g
)
end
end
assert
(
'Proc#arity with unitialized Proc'
)
do
begin
Proc
.
alias_method
(
:original_initialize
,
:initialize
)
Proc
.
remove_method
(
:initialize
)
assert_equal
0
,
Proc
.
new
{
|
a
,
b
,
c
|
1
}.
arity
ensure
Proc
.
alias_method
(
:initialize
,
:original_initialize
)
Proc
.
remove_method
(
:original_initialize
)
end
end
assert
(
'Proc#call'
,
'15.2.17.4.3'
)
do
assert
(
'Proc#call'
,
'15.2.17.4.3'
)
do
a
=
0
a
=
0
b
=
Proc
.
new
{
a
+=
1
}
b
=
Proc
.
new
{
a
+=
1
}
...
...
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