Skip to content

Commit 7b7b29f

Browse files
committed
ruby: Fix build failures with Ruby 3.4
Ruby 3.4 started to actually mark some deprecated functions as *deprecated* now resulting in compiler warnings (which due to -Werror we treat as errors and thus the build fails). The *new* functions were actually introduced back in Ruby 1.9.2, so have been around for quite some time. We claim support for Ruby 2.0 onwards so this is more than fine. The new API replaces the old 'mark' and 'free' parameters with a struct that allows for more fine tuning/configuration. We never made use of either of those parameters and so the only members of this struct we *need* to set is the structure wrapper name and the dsize function pointer which is passed a pointer to the underlying wrapped structure to calculate its memory usage. While this is *not* required the documentation *recommends* setting it (though it doesn't say how it's used). Ruby pytests still pass after this change... Closes: #1525 Link: <https://bugs.ruby-lang.org/issues/19998> Link: <https://docs.ruby-lang.org/en/3.4/extension_rdoc.html#label-C+struct+to+Ruby+object> Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
1 parent b4201ab commit 7b7b29f

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/ruby/nxt_ruby_stream_io.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@ static VALUE nxt_ruby_stream_io_write(VALUE obj, VALUE args);
1919
nxt_inline long nxt_ruby_stream_io_s_write(nxt_ruby_ctx_t *rctx, VALUE val);
2020
static VALUE nxt_ruby_stream_io_flush(VALUE obj);
2121
static VALUE nxt_ruby_stream_io_close(VALUE obj);
22+
nxt_inline size_t nxt_ruby_dt_dsize_rctx(const void *arg);
23+
24+
25+
static const rb_data_type_t nxt_rctx_dt = {
26+
.wrap_struct_name = "rctx",
27+
.function = {
28+
.dsize = nxt_ruby_dt_dsize_rctx,
29+
},
30+
};
31+
32+
33+
nxt_inline size_t
34+
nxt_ruby_dt_dsize_rctx(const void *arg)
35+
{
36+
const nxt_ruby_ctx_t *rctx = arg;
37+
38+
return sizeof(*rctx);
39+
}
2240

2341

2442
VALUE
@@ -73,7 +91,7 @@ nxt_ruby_stream_io_new(VALUE class, VALUE arg)
7391
{
7492
VALUE self;
7593

76-
self = Data_Wrap_Struct(class, 0, 0, (void *) (uintptr_t) arg);
94+
self = TypedData_Wrap_Struct(class, &nxt_rctx_dt, (void *)(uintptr_t)arg);
7795

7896
rb_obj_call_init(self, 0, NULL);
7997

@@ -96,7 +114,7 @@ nxt_ruby_stream_io_gets(VALUE obj)
96114
nxt_ruby_ctx_t *rctx;
97115
nxt_unit_request_info_t *req;
98116

99-
Data_Get_Struct(obj, nxt_ruby_ctx_t, rctx);
117+
TypedData_Get_Struct(obj, nxt_ruby_ctx_t, &nxt_rctx_dt, rctx);
100118
req = rctx->req;
101119

102120
if (req->content_length == 0) {
@@ -152,7 +170,7 @@ nxt_ruby_stream_io_read(VALUE obj, VALUE args)
152170
long copy_size, u_size;
153171
nxt_ruby_ctx_t *rctx;
154172

155-
Data_Get_Struct(obj, nxt_ruby_ctx_t, rctx);
173+
TypedData_Get_Struct(obj, nxt_ruby_ctx_t, &nxt_rctx_dt, rctx);
156174

157175
copy_size = rctx->req->content_length;
158176

@@ -208,7 +226,7 @@ nxt_ruby_stream_io_puts(VALUE obj, VALUE args)
208226
return Qnil;
209227
}
210228

211-
Data_Get_Struct(obj, nxt_ruby_ctx_t, rctx);
229+
TypedData_Get_Struct(obj, nxt_ruby_ctx_t, &nxt_rctx_dt, rctx);
212230

213231
nxt_ruby_stream_io_s_write(rctx, RARRAY_PTR(args)[0]);
214232

@@ -226,7 +244,7 @@ nxt_ruby_stream_io_write(VALUE obj, VALUE args)
226244
return Qnil;
227245
}
228246

229-
Data_Get_Struct(obj, nxt_ruby_ctx_t, rctx);
247+
TypedData_Get_Struct(obj, nxt_ruby_ctx_t, &nxt_rctx_dt, rctx);
230248

231249
len = nxt_ruby_stream_io_s_write(rctx, RARRAY_PTR(args)[0]);
232250

0 commit comments

Comments
 (0)