зеркало из https://github.com/github/ruby.git
Fixed marshal compatibility of Process::Status
This commit is contained in:
Родитель
b30d7fea56
Коммит
ad8e82f708
25
process.c
25
process.c
|
@ -631,6 +631,29 @@ rb_process_status_new(rb_pid_t pid, int status)
|
|||
return last_status;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
process_status_dump(VALUE status)
|
||||
{
|
||||
VALUE dump = rb_class_new_instance(0, 0, rb_cObject);
|
||||
struct rb_process_status *data = RTYPEDDATA_DATA(status);
|
||||
if (data->pid) {
|
||||
rb_ivar_set(dump, id_status, INT2NUM(data->status));
|
||||
rb_ivar_set(dump, id_pid, PIDT2NUM(data->pid));
|
||||
}
|
||||
return dump;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
process_status_load(VALUE real_obj, VALUE load_obj)
|
||||
{
|
||||
struct rb_process_status *data = rb_check_typeddata(real_obj, &rb_process_status_type);
|
||||
VALUE status = rb_attr_get(load_obj, id_status);
|
||||
VALUE pid = rb_attr_get(load_obj, id_pid);
|
||||
data->pid = NIL_P(pid) ? 0 : NUM2PIDT(pid);
|
||||
data->status = NIL_P(status) ? 0 : NUM2INT(status);
|
||||
return real_obj;
|
||||
}
|
||||
|
||||
void
|
||||
rb_last_status_set(int status, rb_pid_t pid)
|
||||
{
|
||||
|
@ -8638,6 +8661,8 @@ InitVM_process(void)
|
|||
rb_cProcessStatus = rb_define_class_under(rb_mProcess, "Status", rb_cObject);
|
||||
rb_define_alloc_func(rb_cProcessStatus, rb_process_status_allocate);
|
||||
rb_undef_method(CLASS_OF(rb_cProcessStatus), "new");
|
||||
rb_marshal_define_compat(rb_cProcessStatus, rb_cObject,
|
||||
process_status_dump, process_status_load);
|
||||
|
||||
rb_define_singleton_method(rb_cProcessStatus, "wait", rb_process_status_waitv, -1);
|
||||
|
||||
|
|
|
@ -1425,6 +1425,8 @@ class TestProcess < Test::Unit::TestCase
|
|||
assert_equal(s.to_i >> 1, s >> 1)
|
||||
assert_equal(false, s.stopped?)
|
||||
assert_equal(nil, s.stopsig)
|
||||
|
||||
assert_equal(s, Marshal.load(Marshal.dump(s)))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1442,6 +1444,8 @@ class TestProcess < Test::Unit::TestCase
|
|||
assert_equal(expected,
|
||||
[s.exited?, s.signaled?, s.stopped?, s.success?],
|
||||
"[s.exited?, s.signaled?, s.stopped?, s.success?]")
|
||||
|
||||
assert_equal(s, Marshal.load(Marshal.dump(s)))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1456,6 +1460,8 @@ class TestProcess < Test::Unit::TestCase
|
|||
"[s.exited?, s.signaled?, s.stopped?, s.success?]")
|
||||
assert_equal("#<Process::Status: pid #{ s.pid } SIGQUIT (signal #{ s.termsig })>",
|
||||
s.inspect.sub(/ \(core dumped\)(?=>\z)/, ''))
|
||||
|
||||
assert_equal(s, Marshal.load(Marshal.dump(s)))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче