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
24b02955
Commit
24b02955
authored
Jun 07, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
git push origin masterMerge branch 'suzukaze-add-string.clear2'
parents
d3fda42e
9709fe79
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
70 additions
and
6 deletions
+70
-6
bintest/mrbc.rb
bintest/mrbc.rb
+12
-0
src/parse.y
src/parse.y
+2
-5
src/string.c
src/string.c
+33
-0
tasks/mruby_build.rake
tasks/mruby_build.rake
+1
-0
test/t/string.rb
test/t/string.rb
+21
-0
tools/mrbc/mrbc.c
tools/mrbc/mrbc.c
+1
-1
No files found.
bintest/mrbc.rb
0 → 100644
View file @
24b02955
require
'tempfile'
assert
(
'Compiling multiple files without new line in last line. #2361'
)
do
a
,
b
,
out
=
Tempfile
.
new
(
'a.rb'
),
Tempfile
.
new
(
'b.rb'
),
Tempfile
.
new
(
'out.mrb'
)
a
.
write
(
'module A; end'
)
a
.
flush
b
.
write
(
'module B; end'
)
b
.
flush
result
=
`bin/mrbc -c -o
#{
out
.
path
}
#{
a
.
path
}
#{
b
.
path
}
2>&1`
assert_equal
"bin/mrbc:
#{
a
.
path
}
:Syntax OK"
,
result
.
chomp
assert_equal
0
,
$?
.
exitstatus
end
src/parse.y
View file @
24b02955
...
@@ -3389,7 +3389,7 @@ nextc(parser_state *p)
...
@@ -3389,7 +3389,7 @@ nextc(parser_state *p)
else {
else {
if (p->cxt->partial_hook(p) < 0)
if (p->cxt->partial_hook(p) < 0)
return -1;
return -1;
return
-2
;
return
'\n'
;
}
}
}
}
...
@@ -3777,7 +3777,6 @@ read_escape(parser_state *p)
...
@@ -3777,7 +3777,6 @@ read_escape(parser_state *p)
eof:
eof:
case -1:
case -1:
case -2:
yyerror(p, "Invalid escape character syntax");
yyerror(p, "Invalid escape character syntax");
return '\0';
return '\0';
...
@@ -4093,7 +4092,6 @@ parser_yylex(parser_state *p)
...
@@ -4093,7 +4092,6 @@ parser_yylex(parser_state *p)
case '#': /* it's a comment */
case '#': /* it's a comment */
skip(p, '\n');
skip(p, '\n');
/* fall through */
/* fall through */
case -2: /* end of partial script. */
case '\n':
case '\n':
maybe_heredoc:
maybe_heredoc:
heredoc_treat_nextline(p);
heredoc_treat_nextline(p);
...
@@ -4128,7 +4126,6 @@ parser_yylex(parser_state *p)
...
@@ -4128,7 +4126,6 @@ parser_yylex(parser_state *p)
goto retry;
goto retry;
}
}
case -1: /* EOF */
case -1: /* EOF */
case -2: /* end of partial script */
goto normal_newline;
goto normal_newline;
default:
default:
pushback(p, c);
pushback(p, c);
...
@@ -5450,7 +5447,7 @@ mrb_parser_set_filename(struct mrb_parser_state *p, const char *f)
...
@@ -5450,7 +5447,7 @@ mrb_parser_set_filename(struct mrb_parser_state *p, const char *f)
sym = mrb_intern_cstr(p->mrb, f);
sym = mrb_intern_cstr(p->mrb, f);
p->filename = mrb_sym2name_len(p->mrb, sym, NULL);
p->filename = mrb_sym2name_len(p->mrb, sym, NULL);
p->lineno = (p->filename_table_length > 0)?
0
: 1;
p->lineno = (p->filename_table_length > 0)?
-1
: 1;
for (i = 0; i < p->filename_table_length; ++i) {
for (i = 0; i < p->filename_table_length; ++i) {
if (p->filename_table[i] == sym) {
if (p->filename_table[i] == sym) {
...
...
src/string.c
View file @
24b02955
...
@@ -2523,6 +2523,38 @@ mrb_str_bytes(mrb_state *mrb, mrb_value str)
...
@@ -2523,6 +2523,38 @@ mrb_str_bytes(mrb_state *mrb, mrb_value str)
return
a
;
return
a
;
}
}
static
inline
void
str_discard
(
mrb_state
*
mrb
,
mrb_value
str
)
{
struct
RString
*
s
=
mrb_str_ptr
(
str
);
if
(
!
STR_SHARED_P
(
s
)
&&
!
STR_EMBED_P
(
s
)
&&
((
s
->
flags
&
MRB_STR_NOFREE
)
==
0
))
{
mrb_free
(
mrb
,
s
->
as
.
heap
.
ptr
);
RSTRING
(
str
)
->
as
.
heap
.
ptr
=
0
;
RSTRING
(
str
)
->
as
.
heap
.
len
=
0
;
}
}
/*
* call-seq:
* string.clear -> string
*
* Makes string empty.
*
* a = "abcde"
* a.clear #=> ""
*/
static
mrb_value
mrb_str_clear
(
mrb_state
*
mrb
,
mrb_value
str
)
{
struct
RString
*
s
=
mrb_str_ptr
(
str
);
str_discard
(
mrb
,
str
);
STR_SET_EMBED_FLAG
(
s
);
STR_SET_EMBED_LEN
(
s
,
0
);
RSTRING_PTR
(
str
)[
0
]
=
'\0'
;
return
str
;
}
/* ---------------------------*/
/* ---------------------------*/
void
void
mrb_init_string
(
mrb_state
*
mrb
)
mrb_init_string
(
mrb_state
*
mrb
)
...
@@ -2574,4 +2606,5 @@ mrb_init_string(mrb_state *mrb)
...
@@ -2574,4 +2606,5 @@ mrb_init_string(mrb_state *mrb)
mrb_define_method
(
mrb
,
s
,
"upcase!"
,
mrb_str_upcase_bang
,
MRB_ARGS_REQ
(
1
));
/* 15.2.10.5.43 */
mrb_define_method
(
mrb
,
s
,
"upcase!"
,
mrb_str_upcase_bang
,
MRB_ARGS_REQ
(
1
));
/* 15.2.10.5.43 */
mrb_define_method
(
mrb
,
s
,
"inspect"
,
mrb_str_inspect
,
MRB_ARGS_NONE
());
/* 15.2.10.5.46(x) */
mrb_define_method
(
mrb
,
s
,
"inspect"
,
mrb_str_inspect
,
MRB_ARGS_NONE
());
/* 15.2.10.5.46(x) */
mrb_define_method
(
mrb
,
s
,
"bytes"
,
mrb_str_bytes
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
s
,
"bytes"
,
mrb_str_bytes
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
s
,
"clear"
,
mrb_str_clear
,
MRB_ARGS_NONE
());
}
}
tasks/mruby_build.rake
View file @
24b02955
...
@@ -209,6 +209,7 @@ module MRuby
...
@@ -209,6 +209,7 @@ module MRuby
def
run_bintest
def
run_bintest
targets
=
@gems
.
select
{
|
v
|
File
.
directory?
"
#{
v
.
dir
}
/bintest"
}.
map
{
|
v
|
filename
v
.
dir
}
targets
=
@gems
.
select
{
|
v
|
File
.
directory?
"
#{
v
.
dir
}
/bintest"
}.
map
{
|
v
|
filename
v
.
dir
}
targets
<<
filename
(
"."
)
if
File
.
directory?
"./bintest"
sh
"ruby test/bintest.rb
#{
targets
.
join
' '
}
"
sh
"ruby test/bintest.rb
#{
targets
.
join
' '
}
"
end
end
...
...
test/t/string.rb
View file @
24b02955
...
@@ -515,3 +515,24 @@ assert('String#each_byte') do
...
@@ -515,3 +515,24 @@ assert('String#each_byte') do
assert_equal
bytes1
,
bytes2
assert_equal
bytes1
,
bytes2
end
end
assert
(
'String#clear'
)
do
# embed string
s
=
"foo"
assert_equal
(
""
,
s
.
clear
)
assert_equal
(
""
,
s
)
# not embed string and not shared string
s
=
"foo"
*
100
a
=
s
assert_equal
(
""
,
s
.
clear
)
assert_equal
(
""
,
s
)
assert_equal
(
""
,
a
)
# shared string
s
=
"foo"
*
100
a
=
s
[
10
,
90
]
# create shared string
assert_equal
(
""
,
s
.
clear
)
# clear
assert_equal
(
""
,
s
)
# s is cleared
assert_not_equal
(
""
,
a
)
# a should not be affected
end
tools/mrbc/mrbc.c
View file @
24b02955
...
@@ -270,7 +270,7 @@ main(int argc, char **argv)
...
@@ -270,7 +270,7 @@ main(int argc, char **argv)
fprintf
(
stderr
,
"%s: no program file given
\n
"
,
args
.
prog
);
fprintf
(
stderr
,
"%s: no program file given
\n
"
,
args
.
prog
);
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
}
}
if
(
args
.
outfile
==
NULL
)
{
if
(
args
.
outfile
==
NULL
&&
!
args
.
check_syntax
)
{
if
(
n
+
1
==
argc
)
{
if
(
n
+
1
==
argc
)
{
args
.
outfile
=
get_outfilename
(
mrb
,
argv
[
n
],
args
.
initname
?
C_EXT
:
RITEBIN_EXT
);
args
.
outfile
=
get_outfilename
(
mrb
,
argv
[
n
],
args
.
initname
?
C_EXT
:
RITEBIN_EXT
);
}
}
...
...
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