Skip to content

Commit 7d5ccca

Browse files
Robert Marshallstanhu
Robert Marshall
andcommitted
Merge branch 'sh-upgrade-ruby' into 'master'
Upgrade to Ruby 3.1.5 and add support for Ruby 3.2.5 See merge request https://gitlab.com/gitlab-org/omnibus-gitlab/-/merge_requests/7591 Merged-by: Robert Marshall <[email protected]> Approved-by: Robert Marshall <[email protected]> Co-authored-by: Stan Hu <[email protected]>
2 parents 31c099f + ab12454 commit 7d5ccca

File tree

2 files changed

+156
-4
lines changed

2 files changed

+156
-4
lines changed
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
From 17aa5c633d13f3ef6dcbec7f08a01b20ed4fbc12 Mon Sep 17 00:00:00 2001
2+
From: Sutou Kouhei <[email protected]>
3+
Date: Thu, 15 Sep 2022 07:08:20 +0900
4+
Subject: [PATCH] merge revision(s) a4ad6bd9aac564e93219284c912b26a72f9e82fc:
5+
6+
[ruby/fiddle] closure: free resources when an exception is raised in
7+
Closure.new
8+
9+
GitHub: GH-102
10+
11+
https://github.com/ruby/fiddle/commit/81a8a56239
12+
---
13+
ext/fiddle/closure.c | 56 ++++++++++++++++++++++++++++++++++++++++------------
14+
1 file changed, 43 insertions(+), 13 deletions(-)
15+
---
16+
ext/fiddle/closure.c | 56 ++++++++++++++++++++++++++++++++++----------
17+
version.h | 6 ++---
18+
2 files changed, 46 insertions(+), 16 deletions(-)
19+
20+
diff --git a/ext/fiddle/closure.c b/ext/fiddle/closure.c
21+
index 27f448a24f0108..c08ec5940da84c 100644
22+
--- a/ext/fiddle/closure.c
23+
+++ b/ext/fiddle/closure.c
24+
@@ -224,9 +224,16 @@ allocate(VALUE klass)
25+
return i;
26+
}
27+
28+
+typedef struct {
29+
+ VALUE self;
30+
+ int argc;
31+
+ VALUE *argv;
32+
+} initialize_data;
33+
+
34+
static VALUE
35+
-initialize(int rbargc, VALUE argv[], VALUE self)
36+
+initialize_body(VALUE user_data)
37+
{
38+
+ initialize_data *data = (initialize_data *)user_data;
39+
VALUE ret;
40+
VALUE args;
41+
VALUE normalized_args;
42+
@@ -237,14 +244,14 @@ initialize(int rbargc, VALUE argv[], VALUE self)
43+
ffi_status result;
44+
int i, argc;
45+
46+
- if (2 == rb_scan_args(rbargc, argv, "21", &ret, &args, &abi))
47+
- abi = INT2NUM(FFI_DEFAULT_ABI);
48+
+ if (2 == rb_scan_args(data->argc, data->argv, "21", &ret, &args, &abi))
49+
+ abi = INT2NUM(FFI_DEFAULT_ABI);
50+
51+
Check_Type(args, T_ARRAY);
52+
53+
argc = RARRAY_LENINT(args);
54+
55+
- TypedData_Get_Struct(self, fiddle_closure, &closure_data_type, cl);
56+
+ TypedData_Get_Struct(data->self, fiddle_closure, &closure_data_type, cl);
57+
58+
cl->argv = (ffi_type **)xcalloc(argc + 1, sizeof(ffi_type *));
59+
60+
@@ -257,8 +264,8 @@ initialize(int rbargc, VALUE argv[], VALUE self)
61+
cl->argv[argc] = NULL;
62+
63+
ret = rb_fiddle_type_ensure(ret);
64+
- rb_iv_set(self, "@ctype", ret);
65+
- rb_iv_set(self, "@args", normalized_args);
66+
+ rb_iv_set(data->self, "@ctype", ret);
67+
+ rb_iv_set(data->self, "@args", normalized_args);
68+
69+
cif = &cl->cif;
70+
pcl = cl->pcl;
71+
@@ -269,25 +276,48 @@ initialize(int rbargc, VALUE argv[], VALUE self)
72+
rb_fiddle_int_to_ffi_type(NUM2INT(ret)),
73+
cl->argv);
74+
75+
- if (FFI_OK != result)
76+
- rb_raise(rb_eRuntimeError, "error prepping CIF %d", result);
77+
+ if (FFI_OK != result) {
78+
+ rb_raise(rb_eRuntimeError, "error prepping CIF %d", result);
79+
+ }
80+
81+
#if USE_FFI_CLOSURE_ALLOC
82+
result = ffi_prep_closure_loc(pcl, cif, callback,
83+
- (void *)self, cl->code);
84+
+ (void *)(data->self), cl->code);
85+
#else
86+
result = ffi_prep_closure(pcl, cif, callback, (void *)(data->self));
87+
cl->code = (void *)pcl;
88+
i = mprotect(pcl, sizeof(*pcl), PROT_READ | PROT_EXEC);
89+
if (i) {
90+
- rb_sys_fail("mprotect");
91+
+ rb_sys_fail("mprotect");
92+
}
93+
#endif
94+
95+
- if (FFI_OK != result)
96+
- rb_raise(rb_eRuntimeError, "error prepping closure %d", result);
97+
+ if (FFI_OK != result) {
98+
+ rb_raise(rb_eRuntimeError, "error prepping closure %d", result);
99+
+ }
100+
+
101+
+ return data->self;
102+
+}
103+
104+
- return self;
105+
+static VALUE
106+
+initialize_rescue(VALUE user_data, VALUE exception)
107+
+{
108+
+ initialize_data *data = (initialize_data *)user_data;
109+
+ dealloc(RTYPEDDATA_DATA(data->self));
110+
+ RTYPEDDATA_DATA(data->self) = NULL;
111+
+ rb_exc_raise(exception);
112+
+ return data->self;
113+
+}
114+
+
115+
+static VALUE
116+
+initialize(int argc, VALUE *argv, VALUE self)
117+
+{
118+
+ initialize_data data;
119+
+ data.self = self;
120+
+ data.argc = argc;
121+
+ data.argv = argv;
122+
+ return rb_rescue(initialize_body, (VALUE)&data,
123+
+ initialize_rescue, (VALUE)&data);
124+
}
125+
126+
static VALUE
127+
diff --git a/version.h b/version.h
128+
index 7c8bc046b33c54..99b715563a17ba 100644
129+
--- a/version.h
130+
+++ b/version.h
131+
@@ -11,11 +11,11 @@
132+
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
133+
#define RUBY_VERSION_TEENY 5
134+
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
135+
-#define RUBY_PATCHLEVEL 252
136+
+#define RUBY_PATCHLEVEL 253
137+
138+
#define RUBY_RELEASE_YEAR 2024
139+
-#define RUBY_RELEASE_MONTH 4
140+
-#define RUBY_RELEASE_DAY 23
141+
+#define RUBY_RELEASE_MONTH 5
142+
+#define RUBY_RELEASE_DAY 2
143+
144+
#include "ruby/version.h"
145+

config/software/ruby.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424

2525
# Follow the Ruby upgrade guide when changing the ruby version
2626
# link: https://docs.gitlab.com/ee/development/ruby_upgrade.html
27-
current_ruby_version = Gitlab::Util.get_env('RUBY_VERSION') || '3.1.4'
27+
current_ruby_version = Gitlab::Util.get_env('RUBY_VERSION') || '3.1.5'
2828

2929
# NOTE: When this value is updated, flip `USE_NEXT_RUBY_VERSION_IN_*` variable
3030
# to false to avoid surprises.
31-
next_ruby_version = Gitlab::Util.get_env('NEXT_RUBY_VERSION') || '3.1.4'
31+
next_ruby_version = Gitlab::Util.get_env('NEXT_RUBY_VERSION') || '3.1.5'
3232

3333
# MRs targeting stable branches should use current Ruby version and ignore next
3434
# Ruby version. Also, we provide `USE_SPECIFIED_RUBY_VERSION` variable to force
@@ -68,7 +68,9 @@
6868

6969
version('3.0.6') { source sha256: '6e6cbd490030d7910c0ff20edefab4294dfcd1046f0f8f47f78b597987ac683e' }
7070
version('3.1.4') { source sha256: 'a3d55879a0dfab1d7141fdf10d22a07dbf8e5cdc4415da1bde06127d5cc3c7b6' }
71+
version('3.1.5') { source sha256: '3685c51eeee1352c31ea039706d71976f53d00ab6d77312de6aa1abaf5cda2c5' }
7172
version('3.2.3') { source sha256: 'af7f1757d9ddb630345988139211f1fd570ff5ba830def1cc7c468ae9b65c9ba' }
73+
version('3.2.4') { source sha256: 'c72b3c5c30482dca18b0f868c9075f3f47d8168eaf626d4e682ce5b59c858692' }
7274

7375
source url: "https://cache.ruby-lang.org/pub/ruby/#{version.match(/^(\d+\.\d+)/)[0]}/ruby-#{version}.tar.gz"
7476

@@ -109,13 +111,18 @@
109111
# 1. Enable custom patch created by ayufan that allows to count memory allocations
110112
# per-thread. This is asked to be upstreamed as part of https://github.com/ruby/ruby/pull/3978
111113
# 2. Backport Ruby upstream patch to fix seg faults in libxml2/Nokogiri: https://bugs.ruby-lang.org/issues/19580
112-
# This has been merged for Ruby 3.2.3 but not yet backported: https://github.com/ruby/ruby/pull/7663
113-
patches = if version.satisfies?('>= 3.2.3')
114+
# This has been merged for Ruby 3.2.3 and backported to 3.1.5.
115+
patches = if version.satisfies?('>= 3.2.3') || version.satisfies?(['>= 3.1.5', '< 3.2.0'])
114116
%w[thread-memory-allocations]
115117
else
116118
%w[thread-memory-allocations fix-ruby-xfree-for-libxml2]
117119
end
118120

121+
# Due to https://bugs.ruby-lang.org/issues/20451, this patch is needed
122+
# to compile Ruby 3.1.5 on platforms with libffi < 3.2. This patch pulls in
123+
# https://github.com/ruby/ruby/pull/10696.
124+
patches += %w[fiddle-closure] if version.satisfies?('= 3.1.5')
125+
119126
ruby_version = Gem::Version.new(version).canonical_segments[0..1].join('.')
120127

121128
patches.each do |patch_name|

0 commit comments

Comments
 (0)