1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
From daeb121fb5600cc0f4fc604fbf7d742578f26483 Mon Sep 17 00:00:00 2001
From: MSP-Greg <Greg.mpls@gmail.com>
Date: Sat, 12 Jun 2021 22:37:37 -0500
Subject: [PATCH] Fixes for Process::Status changes in Ruby 3
---
ext/extconf.rb | 3 +++
ext/rubymain.cpp | 36 ++++++++++++++++++++++++++++++------
2 files changed, 33 insertions(+), 6 deletions(-)
diff --git a/ext/extconf.rb b/ext/extconf.rb
index 0fb654104..ce83c0028 100644
--- a/ext/extconf.rb
+++ b/ext/extconf.rb
@@ -138,6 +138,9 @@ def find_openssl_library
add_define "HAVE_KQUEUE" if have_header("sys/event.h") && have_header("sys/queue.h")
end
+# Add for changes to Process::Status in Ruby 3
+add_define("IS_RUBY_3_OR_LATER") if RUBY_VERSION > "3.0"
+
# Adjust number of file descriptors (FD) on Windows
if RbConfig::CONFIG["host_os"] =~ /mingw/
diff --git a/ext/rubymain.cpp b/ext/rubymain.cpp
index 5da5c8b25..36018c63d 100644
--- a/ext/rubymain.cpp
+++ b/ext/rubymain.cpp
@@ -85,7 +85,24 @@ static VALUE Intern_proxy_target_unbound;
static VALUE Intern_proxy_completed;
static VALUE Intern_connection_completed;
-static VALUE rb_cProcStatus;
+static VALUE rb_cProcessStatus;
+
+#ifdef IS_RUBY_3_OR_LATER
+struct rb_process_status {
+ rb_pid_t pid;
+ int status;
+ int error;
+};
+
+static const rb_data_type_t rb_process_status_type = {
+ .wrap_struct_name = "Process::Status",
+ .function = {
+ .dfree = RUBY_DEFAULT_FREE,
+ },
+ .data = NULL,
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY,
+};
+#endif
struct em_event {
uintptr_t signature;
@@ -553,11 +570,18 @@ static VALUE t_get_subprocess_status (VALUE self UNUSED, VALUE signature)
if (evma_get_subprocess_status (NUM2BSIG (signature), &status)) {
if (evma_get_subprocess_pid (NUM2BSIG (signature), &pid)) {
- proc_status = rb_obj_alloc(rb_cProcStatus);
+#ifdef IS_RUBY_3_OR_LATER
+ struct rb_process_status *data = NULL;
+ proc_status = TypedData_Make_Struct(rb_cProcessStatus, struct rb_process_status, &rb_process_status_type, data);
+ data->pid = pid;
+ data->status = status;
+#else
+ proc_status = rb_obj_alloc(rb_cProcessStatus);
/* MRI Ruby uses hidden instance vars */
- rb_iv_set(proc_status, "status", INT2FIX(status));
- rb_iv_set(proc_status, "pid", INT2FIX(pid));
+ rb_ivar_set(proc_status, rb_intern_const("status"), INT2FIX(status));
+ rb_ivar_set(proc_status, rb_intern_const("pid"), INT2FIX(pid));
+#endif
#ifdef RUBINIUS
/* Rubinius uses standard instance vars */
@@ -572,7 +596,7 @@ static VALUE t_get_subprocess_status (VALUE self UNUSED, VALUE signature)
#endif
}
}
-
+ rb_obj_freeze(proc_status);
return proc_status;
}
@@ -1431,7 +1455,7 @@ extern "C" void Init_rubyeventmachine()
{
// Lookup Process::Status for get_subprocess_status
VALUE rb_mProcess = rb_const_get(rb_cObject, rb_intern("Process"));
- rb_cProcStatus = rb_const_get(rb_mProcess, rb_intern("Status"));
+ rb_cProcessStatus = rb_const_get(rb_mProcess, rb_intern("Status"));
// Tuck away some symbol values so we don't have to look 'em up every time we need 'em.
Intern_at_signature = rb_intern ("@signature");
|