diff --git a/include/ruby/internal/intern/process.h b/include/ruby/internal/intern/process.h index cfa5e13162f52e..8b5e875c173565 100644 --- a/include/ruby/internal/intern/process.h +++ b/include/ruby/internal/intern/process.h @@ -30,6 +30,19 @@ RBIMPL_SYMBOL_EXPORT_BEGIN() /* process.c */ +/** + * Returns the Ruby value representing a waitpid(2) outcome. + * + * This is intended for Fiber Scheduler implementations of process_wait. The + * returned value should be returned from the scheduler hook. + * + * @param[in] pid The process ID returned by waitpid(2), or -1 on error. + * @param[in] status The "waitpid status", as returned by waitpid(2). This is NOT the exit status/exit code, see waitpid(2). + * @param[in] error Error code when pid is -1. + * @return The Ruby value representing this process wait result. + */ +VALUE rb_process_status_for(rb_pid_t pid, int status, int error); + /** * Wait for the specified process to terminate, reap it, and return its status. * diff --git a/process.c b/process.c index 01aea3239a3696..8bb631fe5d46c6 100644 --- a/process.c +++ b/process.c @@ -642,7 +642,7 @@ proc_s_last_status(VALUE mod) } VALUE -rb_process_status_new(rb_pid_t pid, int status, int error) +rb_process_status_for(rb_pid_t pid, int status, int error) { VALUE last_status = rb_process_status_allocate(rb_cProcessStatus); struct rb_process_status *data = RTYPEDDATA_GET_DATA(last_status); @@ -681,7 +681,7 @@ process_status_load(VALUE real_obj, VALUE load_obj) void rb_last_status_set(int status, rb_pid_t pid) { - GET_THREAD()->last_status = rb_process_status_new(pid, status, 0); + GET_THREAD()->last_status = rb_process_status_for(pid, status, 0); } static void @@ -1112,7 +1112,7 @@ rb_process_status_wait(rb_pid_t pid, int flags) if (waitpid_state.ret == 0) return Qnil; - return rb_process_status_new(waitpid_state.ret, waitpid_state.status, waitpid_state.errnum); + return rb_process_status_for(waitpid_state.ret, waitpid_state.status, waitpid_state.errnum); } /*