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
e0064aca
Commit
e0064aca
authored
May 15, 2014
by
take_cheeze
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement `LVAR` section removing option in mruby-strip.
parent
30e0dc79
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
6 deletions
+83
-6
mrbgems/mruby-bin-strip/bintest/mruby-strip.rb
mrbgems/mruby-bin-strip/bintest/mruby-strip.rb
+20
-1
mrbgems/mruby-bin-strip/mrbgem.rake
mrbgems/mruby-bin-strip/mrbgem.rake
+1
-0
mrbgems/mruby-bin-strip/tools/mruby-strip/mruby-strip.c
mrbgems/mruby-bin-strip/tools/mruby-strip/mruby-strip.c
+62
-5
No files found.
mrbgems/mruby-bin-strip/bintest/mruby-strip.rb
View file @
e0064aca
...
...
@@ -3,7 +3,7 @@ require 'tempfile'
assert
(
'no files'
)
do
o
=
`bin/mruby-strip 2>&1`
assert_equal
1
,
$?
.
exitstatus
assert_equal
"no files to strip
\n
"
,
o
assert_equal
"no files to strip
"
,
o
.
split
(
"
\n
"
)[
0
]
end
assert
(
'file not found'
)
do
...
...
@@ -52,3 +52,22 @@ assert('check debug section') do
`bin/mruby-strip
#{
with_debug
.
path
}
`
assert_equal
without_debug
.
size
,
with_debug
.
size
end
assert
(
'check lv section'
)
do
script_file
,
with_lv
,
without_lv
=
Tempfile
.
new
(
'script.rb'
),
Tempfile
.
new
(
'c1.mrb'
),
Tempfile
.
new
(
'c2.mrb'
)
script_file
.
write
<<
EOS
a, b = 0, 1
a += b
p Kernel.local_variables
EOS
script_file
.
flush
`bin/mrbc -o
#{
with_lv
.
path
}
#{
script_file
.
path
}
`
`bin/mrbc -o
#{
without_lv
.
path
}
#{
script_file
.
path
}
`
`bin/mruby-strip -l
#{
without_lv
.
path
}
`
assert_true
without_lv
.
size
<
with_lv
.
size
assert_equal
'[:a, :b]'
,
`bin/mruby -b
#{
with_lv
.
path
}
`
.
chomp
assert_equal
'[]'
,
`bin/mruby -b
#{
without_lv
.
path
}
`
.
chomp
end
mrbgems/mruby-bin-strip/mrbgem.rake
View file @
e0064aca
...
...
@@ -3,4 +3,5 @@ MRuby::Gem::Specification.new('mruby-bin-strip') do |spec|
spec
.
author
=
'mruby developers'
spec
.
summary
=
'irep dump debug section remover command'
spec
.
bins
=
%w(mruby-strip)
spec
.
add_dependency
'mruby-proc-ext'
,
:core
=>
'mruby-proc-ext'
end
mrbgems/mruby-bin-strip/tools/mruby-strip/mruby-strip.c
View file @
e0064aca
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mruby.h"
#include "mruby/irep.h"
#include "mruby/dump.h"
struct
strip_args
{
mrb_bool
lvar
;
};
static
void
print_usage
(
const
char
*
f
)
{
printf
(
"Usage: %s [options] irepfiles
\n
"
,
f
);
printf
(
"options:
\n
"
);
printf
(
" -l, --lvar remove LVAR section too.
\n
"
);
}
static
int
parse_args
(
int
argc
,
char
**
argv
,
struct
strip_args
*
args
)
{
static
const
struct
strip_args
initial_args
=
{
0
};
int
i
;
*
args
=
initial_args
;
for
(
i
=
1
;
i
<
argc
;
++
i
)
{
size_t
const
len
=
strlen
(
argv
[
i
]);
if
(
len
>=
2
&&
argv
[
i
][
0
]
==
'-'
)
{
switch
(
argv
[
i
][
1
])
{
case
'l'
:
args
->
lvar
=
TRUE
;
break
;
case
'-'
:
if
(
strncmp
((
*
argv
)
+
2
,
"lvar"
,
len
)
==
0
)
{
args
->
lvar
=
TRUE
;
break
;
}
default:
return
-
1
;
}
}
else
{
break
;
}
}
return
i
;
}
int
main
(
int
argc
,
char
**
argv
)
{
int
i
,
dump_result
;
struct
strip_args
args
;
int
args_result
,
i
,
dump_result
;
FILE
**
files
;
mrb_irep
**
ireps
;
mrb_state
*
mrb
;
if
(
argc
<=
1
)
{
fprintf
(
stderr
,
"no files to strip
\n
"
);
printf
(
"no files to strip
\n
"
);
print_usage
(
argv
[
0
]);
return
EXIT_FAILURE
;
}
args_result
=
parse_args
(
argc
,
argv
,
&
args
);
if
(
args_result
<
0
)
{
print_usage
(
argv
[
0
]);
return
EXIT_FAILURE
;
}
files
=
(
FILE
**
)
malloc
(
sizeof
(
FILE
*
)
*
argc
);
for
(
i
=
1
;
i
<
argc
;
++
i
)
{
for
(
i
=
args_result
;
i
<
argc
;
++
i
)
{
files
[
i
]
=
fopen
(
argv
[
i
],
"rb"
);
if
(
!
files
[
i
])
{
...
...
@@ -30,7 +82,7 @@ main(int argc, char **argv)
mrb
=
mrb_open
();
ireps
=
(
mrb_irep
**
)
malloc
(
sizeof
(
mrb_irep
*
)
*
argc
);
for
(
i
=
1
;
i
<
argc
;
++
i
)
{
for
(
i
=
args_result
;
i
<
argc
;
++
i
)
{
ireps
[
i
]
=
mrb_read_irep_file
(
mrb
,
files
[
i
]);
if
(
!
ireps
[
i
])
{
fprintf
(
stderr
,
"can't read irep file %s
\n
"
,
argv
[
i
]);
...
...
@@ -44,7 +96,12 @@ main(int argc, char **argv)
}
}
for
(
i
=
1
;
i
<
argc
;
++
i
)
{
for
(
i
=
args_result
;
i
<
argc
;
++
i
)
{
/* clear lv if --lvar is enabled */
if
(
args
.
lvar
)
{
mrb_irep_remove_lv
(
mrb
,
ireps
[
i
]);
}
/* debug flag must be alway false */
dump_result
=
mrb_dump_irep_binary
(
mrb
,
ireps
[
i
],
FALSE
,
files
[
i
]);
if
(
dump_result
!=
MRB_DUMP_OK
)
{
...
...
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