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
c27e4519
Unverified
Commit
c27e4519
authored
Sep 10, 2020
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Sep 10, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4933 from dearblue/variables
Fix take over file scope variables with `mruby` and `mirb` command
parents
c345fe43
9840e535
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
69 additions
and
4 deletions
+69
-4
include/mruby/compile.h
include/mruby/compile.h
+1
-0
lib/mruby/gem.rb
lib/mruby/gem.rb
+5
-0
mrbgems/mruby-bin-mirb/bintest/mirb.rb
mrbgems/mruby-bin-mirb/bintest/mirb.rb
+17
-0
mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
+9
-4
mrbgems/mruby-bin-mruby/bintest/mruby.rb
mrbgems/mruby-bin-mruby/bintest/mruby.rb
+21
-0
mrbgems/mruby-bin-mruby/tools/mruby/mruby.c
mrbgems/mruby-bin-mruby/tools/mruby/mruby.c
+6
-0
mrbgems/mruby-compiler/core/parse.y
mrbgems/mruby-compiler/core/parse.y
+10
-0
No files found.
include/mruby/compile.h
View file @
c27e4519
...
...
@@ -42,6 +42,7 @@ MRB_API mrbc_context* mrbc_context_new(mrb_state *mrb);
MRB_API
void
mrbc_context_free
(
mrb_state
*
mrb
,
mrbc_context
*
cxt
);
MRB_API
const
char
*
mrbc_filename
(
mrb_state
*
mrb
,
mrbc_context
*
c
,
const
char
*
s
);
MRB_API
void
mrbc_partial_hook
(
mrb_state
*
mrb
,
mrbc_context
*
c
,
int
(
*
partial_hook
)(
struct
mrb_parser_state
*
),
void
*
data
);
MRB_API
void
mrbc_cleanup_local_variables
(
mrb_state
*
mrb
,
mrbc_context
*
c
);
/* AST node structure */
typedef
struct
mrb_ast_node
{
...
...
lib/mruby/gem.rb
View file @
c27e4519
...
...
@@ -180,6 +180,7 @@ module MRuby
f
.
puts
%Q[]
f
.
puts
%Q[void GENERATED_TMP_mrb_
#{
funcname
}
_gem_init(mrb_state *mrb) {]
f
.
puts
%Q[ int ai = mrb_gc_arena_save(mrb);]
f
.
puts
%Q[ struct REnv *e;]
unless
rbfiles
.
empty?
f
.
puts
%Q[ mrb_
#{
funcname
}
_gem_init(mrb);]
if
objs
!=
[
objfile
(
"
#{
build_dir
}
/gem_init"
)]
unless
rbfiles
.
empty?
f
.
puts
%Q[ mrb_load_irep(mrb, gem_mrblib_irep_
#{
funcname
}
);]
...
...
@@ -188,6 +189,9 @@ module MRuby
f
.
puts
%Q[ mrb_close(mrb);]
f
.
puts
%Q[ exit(EXIT_FAILURE);]
f
.
puts
%Q[ }]
f
.
puts
%Q[ e = mrb->c->cibase->env;]
f
.
puts
%Q[ mrb->c->cibase->env = NULL;]
f
.
puts
%Q[ mrb_env_unshare(mrb, e);]
end
f
.
puts
%Q[ mrb_gc_arena_restore(mrb, ai);]
f
.
puts
%Q[}]
...
...
@@ -214,6 +218,7 @@ module MRuby
f
.
puts
%Q[#include <stdlib.h>]
unless
rbfiles
.
empty?
f
.
puts
%Q[#include <mruby.h>]
f
.
puts
%Q[#include <mruby/irep.h>]
unless
rbfiles
.
empty?
f
.
puts
%Q[#include <mruby/proc.h>]
unless
rbfiles
.
empty?
end
def
print_gem_test_header
(
f
)
...
...
mrbgems/mruby-bin-mirb/bintest/mirb.rb
View file @
c27e4519
...
...
@@ -32,3 +32,20 @@ EOS
o
,
_
=
Open3
.
capture2
(
"bin/mirb -r
#{
lib
.
path
}
"
,
:stdin_data
=>
"Hoge.new.hoge
\n
"
)
assert_true
o
.
include?
(
'=> :hoge'
)
end
assert
(
'top level local variables are in file scope'
)
do
lib
=
Tempfile
.
new
(
'lib.rb'
)
lib
.
write
<<-
TESTLIB
a = 1
A = -> { a }
TESTLIB
lib
.
flush
o
,
_
=
Open3
.
capture2
(
"bin/mirb -r
#{
lib
.
path
}
"
,
:stdin_data
=>
<<-
TESTCODE
)
a
a = 5
A.call
TESTCODE
assert_kind_of
Integer
,
o
=~
/\bundefined method 'a' \(NoMethodError\).*=> 5\b.*=> 1\b/m
end
mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
View file @
c27e4519
...
...
@@ -495,12 +495,9 @@ main(int argc, char **argv)
cxt
=
mrbc_context_new
(
mrb
);
#ifndef DISABLE_MIRB_UNDERSCORE
decl_lv_underscore
(
mrb
,
cxt
);
#endif
/* Load libraries */
for
(
i
=
0
;
i
<
args
.
libc
;
i
++
)
{
struct
REnv
*
e
;
FILE
*
lfp
=
fopen
(
args
.
libv
[
i
],
"r"
);
if
(
lfp
==
NULL
)
{
printf
(
"Cannot open library file. (%s)
\n
"
,
args
.
libv
[
i
]);
...
...
@@ -509,8 +506,16 @@ main(int argc, char **argv)
}
mrb_load_file_cxt
(
mrb
,
lfp
,
cxt
);
fclose
(
lfp
);
e
=
mrb
->
c
->
cibase
->
env
;
mrb
->
c
->
cibase
->
env
=
NULL
;
mrb_env_unshare
(
mrb
,
e
);
mrbc_cleanup_local_variables
(
mrb
,
cxt
);
}
#ifndef DISABLE_MIRB_UNDERSCORE
decl_lv_underscore
(
mrb
,
cxt
);
#endif
cxt
->
capture_errors
=
TRUE
;
cxt
->
lineno
=
1
;
mrbc_filename
(
mrb
,
cxt
,
"(mirb)"
);
...
...
mrbgems/mruby-bin-mruby/bintest/mruby.rb
View file @
c27e4519
...
...
@@ -162,3 +162,24 @@ assert('codegen error') do
code
=
"def f(
#{
(
1
..
100
).
map
{
|
n
|
"a
#{
n
}
"
}
* "
,
"}); end"
assert_mruby
(
""
,
/\Acodegen error:.*\n\z/
,
false
,
[
"-e"
,
code
])
end
assert
(
'top level local variables are in file scope'
)
do
arb
,
amrb
=
Tempfile
.
new
(
'a.rb'
),
Tempfile
.
new
(
'a.mrb'
)
brb
,
bmrb
=
Tempfile
.
new
(
'b.rb'
),
Tempfile
.
new
(
'b.mrb'
)
crb
,
cmrb
=
Tempfile
.
new
(
'c.rb'
),
Tempfile
.
new
(
'c.mrb'
)
drb
,
dmrb
=
Tempfile
.
new
(
'd.rb'
),
Tempfile
.
new
(
'd.mrb'
)
File
.
write
arb
.
path
,
'a = 1'
system
"
#{
cmd
(
'mrbc'
)
}
-g -o
#{
amrb
.
path
}
#{
arb
.
path
}
"
File
.
write
brb
.
path
,
'p a'
system
"
#{
cmd
(
'mrbc'
)
}
-g -o
#{
bmrb
.
path
}
#{
brb
.
path
}
"
assert_mruby
(
""
,
/:1: undefined method 'a' \(NoMethodError\)\n\z/
,
false
,
[
"-r"
,
arb
.
path
,
brb
.
path
])
assert_mruby
(
""
,
/:1: undefined method 'a' \(NoMethodError\)\n\z/
,
false
,
[
"-b"
,
"-r"
,
amrb
.
path
,
bmrb
.
path
])
File
.
write
crb
.
path
,
'a, b, c = 1, 2, 3; A = -> { b = -2; [a, b, c] }'
system
"
#{
cmd
(
'mrbc'
)
}
-g -o
#{
cmrb
.
path
}
#{
crb
.
path
}
"
File
.
write
drb
.
path
,
'a, b = 5, 6; p A.call; p a, b'
system
"
#{
cmd
(
'mrbc'
)
}
-g -o
#{
dmrb
.
path
}
#{
drb
.
path
}
"
assert_mruby
(
"[1, -2, 3]
\n
5
\n
6
\n
"
,
""
,
true
,
[
"-r"
,
crb
.
path
,
drb
.
path
])
assert_mruby
(
"[1, -2, 3]
\n
5
\n
6
\n
"
,
""
,
true
,
[
"-b"
,
"-r"
,
cmrb
.
path
,
dmrb
.
path
])
end
mrbgems/mruby-bin-mruby/tools/mruby/mruby.c
View file @
c27e4519
...
...
@@ -10,6 +10,7 @@
#include <mruby/compile.h>
#include <mruby/dump.h>
#include <mruby/variable.h>
#include <mruby/proc.h>
struct
_args
{
FILE
*
rfp
;
...
...
@@ -307,6 +308,7 @@ main(int argc, char **argv)
/* Load libraries */
for
(
i
=
0
;
i
<
args
.
libc
;
i
++
)
{
struct
REnv
*
e
;
FILE
*
lfp
=
fopen
(
args
.
libv
[
i
],
args
.
mrbfile
?
"rb"
:
"r"
);
if
(
lfp
==
NULL
)
{
fprintf
(
stderr
,
"%s: Cannot open library file: %s
\n
"
,
*
argv
,
args
.
libv
[
i
]);
...
...
@@ -321,6 +323,10 @@ main(int argc, char **argv)
v
=
mrb_load_file_cxt
(
mrb
,
lfp
,
c
);
}
fclose
(
lfp
);
e
=
mrb
->
c
->
cibase
->
env
;
mrb
->
c
->
cibase
->
env
=
NULL
;
mrb_env_unshare
(
mrb
,
e
);
mrbc_cleanup_local_variables
(
mrb
,
c
);
}
/* Load program */
...
...
mrbgems/mruby-compiler/core/parse.y
View file @
c27e4519
...
...
@@ -6376,6 +6376,16 @@ mrbc_partial_hook(mrb_state *mrb, mrbc_context *c, int (*func)(struct mrb_parser
c->partial_data = data;
}
MRB_API void
mrbc_cleanup_local_variables(mrb_state *mrb, mrbc_context *c)
{
if (c->syms) {
mrb_free(mrb, c->syms);
c->syms = NULL;
c->slen = 0;
}
}
MRB_API void
mrb_parser_set_filename(struct mrb_parser_state *p, const char *f)
{
...
...
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