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
93d481d4
Commit
93d481d4
authored
Jun 22, 2016
by
Tomoyuki Sahara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update $? when IO object is closed. closes #58.
parent
e90ecff6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
5 deletions
+39
-5
src/io.c
src/io.c
+32
-5
test/io.rb
test/io.rb
+7
-0
No files found.
src/io.c
View file @
93d481d4
...
...
@@ -47,7 +47,7 @@ struct mrb_data_type mrb_io_type = { "IO", mrb_io_free };
static
struct
mrb_io
*
io_get_open_fptr
(
mrb_state
*
mrb
,
mrb_value
self
);
static
int
mrb_io_modestr_to_flags
(
mrb_state
*
mrb
,
const
char
*
modestr
);
static
int
mrb_io_flags_to_modenum
(
mrb_state
*
mrb
,
int
flags
);
static
void
fptr_finalize
(
mrb_state
*
mrb
,
struct
mrb_io
*
fptr
,
int
noraise
);
static
void
fptr_finalize
(
mrb_state
*
mrb
,
struct
mrb_io
*
fptr
,
int
quiet
);
#if MRUBY_RELEASE_NO < 10000
static
struct
RClass
*
...
...
@@ -69,6 +69,29 @@ io_get_open_fptr(mrb_state *mrb, mrb_value self)
return
fptr
;
}
#if !defined(_WIN32) && !defined(_WIN64)
static
void
io_set_process_status
(
mrb_state
*
mrb
,
pid_t
pid
,
int
status
)
{
struct
RClass
*
c_process
,
*
c_status
;
mrb_value
v
;
c_status
=
NULL
;
if
(
mrb_class_defined
(
mrb
,
"Process"
))
{
c_process
=
mrb_class_get
(
mrb
,
"Process"
);
if
(
mrb_const_defined
(
mrb
,
mrb_obj_value
(
c_process
),
mrb_intern_cstr
(
mrb
,
"Status"
)))
{
c_status
=
mrb_class_get_under
(
mrb
,
c_process
,
"Status"
);
}
}
if
(
c_status
!=
NULL
)
{
v
=
mrb_funcall
(
mrb
,
mrb_obj_value
(
c_status
),
"new"
,
2
,
mrb_fixnum_value
(
pid
),
mrb_fixnum_value
(
status
));
}
else
{
v
=
mrb_fixnum_value
(
WEXITSTATUS
(
status
));
}
mrb_gv_set
(
mrb
,
mrb_intern_cstr
(
mrb
,
"$?"
),
v
);
}
#endif
static
int
mrb_io_modestr_to_flags
(
mrb_state
*
mrb
,
const
char
*
mode
)
{
...
...
@@ -389,7 +412,7 @@ mrb_io_initialize(mrb_state *mrb, mrb_value io)
fptr
=
DATA_PTR
(
io
);
if
(
fptr
!=
NULL
)
{
fptr_finalize
(
mrb
,
fptr
,
0
);
fptr_finalize
(
mrb
,
fptr
,
TRUE
);
mrb_free
(
mrb
,
fptr
);
}
fptr
=
mrb_io_alloc
(
mrb
);
...
...
@@ -404,7 +427,7 @@ mrb_io_initialize(mrb_state *mrb, mrb_value io)
}
static
void
fptr_finalize
(
mrb_state
*
mrb
,
struct
mrb_io
*
fptr
,
int
noraise
)
fptr_finalize
(
mrb_state
*
mrb
,
struct
mrb_io
*
fptr
,
int
quiet
)
{
int
n
=
0
;
...
...
@@ -428,13 +451,17 @@ fptr_finalize(mrb_state *mrb, struct mrb_io *fptr, int noraise)
#if !defined(_WIN32) && !defined(_WIN64)
if
(
fptr
->
pid
!=
0
)
{
pid_t
pid
;
int
status
;
do
{
pid
=
waitpid
(
fptr
->
pid
,
NULL
,
0
);
pid
=
waitpid
(
fptr
->
pid
,
&
status
,
0
);
}
while
(
pid
==
-
1
&&
errno
==
EINTR
);
if
(
!
quiet
&&
pid
==
fptr
->
pid
)
{
io_set_process_status
(
mrb
,
pid
,
status
);
}
}
#endif
if
(
!
noraise
&&
n
!=
0
)
{
if
(
!
quiet
&&
n
!=
0
)
{
mrb_sys_fail
(
mrb
,
"fptr_finalize failed."
);
}
}
...
...
test/io.rb
View file @
93d481d4
...
...
@@ -372,6 +372,7 @@ end
assert
(
'IO.popen'
)
do
begin
$?
=
nil
io
=
IO
.
popen
(
"ls"
)
assert_true
io
.
close_on_exec?
assert_equal
Fixnum
,
io
.
pid
.
class
...
...
@@ -379,7 +380,13 @@ assert('IO.popen') do
assert_equal
ls
.
class
,
String
assert_include
ls
,
'AUTHORS'
assert_include
ls
,
'mrblib'
io
.
close
if
Object
.
const_defined?
:Process
assert_true
$?
.
success?
else
assert_equal
0
,
$?
end
io
.
closed?
rescue
NotImplementedError
=>
e
skip
e
.
message
...
...
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