nio4r 2.6.1 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ab6233e95080b12f5cee36509a9b3b0c5981ecfaf1071f8940b95a8a3a92c7f
4
- data.tar.gz: 064a65f0305f469c60211413435f0f8d7549cd28c2e5b5cbff8053c133c269df
3
+ metadata.gz: ae8b5e59a799c0161b454b1e4dcd97becc5bdb0b835ec6becf2a3a4488b648b5
4
+ data.tar.gz: e5b186044e74c4ad7c3b9846d6244dd21938b831eb415eccb63a781a4ee5dc9e
5
5
  SHA512:
6
- metadata.gz: 3d5a0bddabfecd71020737c060083bb4f2582eb9dd6eca234589181b3e2d3825e02374560389a7012dd9ea1ea0cfe1b4ea627990860f7d9671f9dff8d377e44c
7
- data.tar.gz: c608bedc5fb5b4f4478ad771b3e6120b8061235a0e607a2c69dacbd818b69a9512052e04395688417067c680662674b11c9f6cd84d74b7b9167ab4358dd31305
6
+ metadata.gz: c22f5d7466ede134956ab01ea87c4554ce38a950019519f0a7c4a9f16cbe81c5a338de488d885761bd49393cfd72bf20a857204db13b051d6f59f8e5bc52bc1d
7
+ data.tar.gz: 27152f810d81a2f94b7428a3662e991441adb4756e24cb09753addd8d00b1a3a6ea80a2e89580eac76ab5d3328fa368cb43147ccaa9432d70e74a771ce22c863
data/Gemfile CHANGED
@@ -7,6 +7,7 @@ gemspec
7
7
  gem "jruby-openssl" if defined? JRUBY_VERSION
8
8
 
9
9
  group :maintenance, optional: true do
10
+ gem "bake"
10
11
  gem "bake-gem"
11
12
  # gem "bake-modernize"
12
13
  end
data/changes.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## 2.6.2
2
+
3
+ * Convert NIO objects to TypedData API.
4
+
5
+ ## 2.6.1
6
+
7
+ * Don't update `io` which is subsequently stored. Retain the original.
8
+
9
+ ## 2.6.0
10
+
11
+ * Fix conversion loses int precision.
12
+ * Avoid direct access to IO internals.
13
+ * Resolve issue loading both nio and nio4r gems.
14
+
1
15
  ## 2.5.9 (2023-04-02)
2
16
 
3
17
  https://github.com/socketry/nio4r/compare/v2.5.8..v2.5.9
@@ -8,8 +8,8 @@ static VALUE cNIO_ByteBuffer_MarkUnsetError = Qnil;
8
8
 
9
9
  /* Allocator/deallocator */
10
10
  static VALUE NIO_ByteBuffer_allocate(VALUE klass);
11
- static void NIO_ByteBuffer_gc_mark(struct NIO_ByteBuffer *byteBuffer);
12
- static void NIO_ByteBuffer_free(struct NIO_ByteBuffer *byteBuffer);
11
+ static void NIO_ByteBuffer_free(void *data);
12
+ static size_t NIO_ByteBuffer_memsize(const void *data);
13
13
 
14
14
  /* Methods */
15
15
  static VALUE NIO_ByteBuffer_initialize(VALUE self, VALUE capacity);
@@ -92,28 +92,46 @@ void Init_NIO_ByteBuffer()
92
92
  rb_define_method(cNIO_ByteBuffer, "inspect", NIO_ByteBuffer_inspect, 0);
93
93
  }
94
94
 
95
+ static const rb_data_type_t NIO_ByteBuffer_type = {
96
+ "NIO::ByteBuffer",
97
+ {
98
+ NULL, // Nothing to mark
99
+ NIO_ByteBuffer_free,
100
+ NIO_ByteBuffer_memsize,
101
+ },
102
+ 0,
103
+ 0,
104
+ RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
105
+ };
106
+
95
107
  static VALUE NIO_ByteBuffer_allocate(VALUE klass)
96
108
  {
97
109
  struct NIO_ByteBuffer *bytebuffer = (struct NIO_ByteBuffer *)xmalloc(sizeof(struct NIO_ByteBuffer));
98
110
  bytebuffer->buffer = NULL;
99
- return Data_Wrap_Struct(klass, NIO_ByteBuffer_gc_mark, NIO_ByteBuffer_free, bytebuffer);
111
+ return TypedData_Wrap_Struct(klass, &NIO_ByteBuffer_type, bytebuffer);
100
112
  }
101
113
 
102
- static void NIO_ByteBuffer_gc_mark(struct NIO_ByteBuffer *buffer)
114
+ static void NIO_ByteBuffer_free(void *data)
103
115
  {
116
+ struct NIO_ByteBuffer *buffer = (struct NIO_ByteBuffer *)data;
117
+ if (buffer->buffer)
118
+ xfree(buffer->buffer);
119
+ xfree(buffer);
104
120
  }
105
121
 
106
- static void NIO_ByteBuffer_free(struct NIO_ByteBuffer *buffer)
122
+ static size_t NIO_ByteBuffer_memsize(const void *data)
107
123
  {
124
+ const struct NIO_ByteBuffer *buffer = (const struct NIO_ByteBuffer *)data;
125
+ size_t memsize = sizeof(struct NIO_ByteBuffer);
108
126
  if (buffer->buffer)
109
- xfree(buffer->buffer);
110
- xfree(buffer);
127
+ memsize += buffer->capacity;
128
+ return memsize;
111
129
  }
112
130
 
113
131
  static VALUE NIO_ByteBuffer_initialize(VALUE self, VALUE capacity)
114
132
  {
115
133
  struct NIO_ByteBuffer *buffer;
116
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
134
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
117
135
 
118
136
  buffer->capacity = NUM2INT(capacity);
119
137
  buffer->buffer = xmalloc(buffer->capacity);
@@ -126,7 +144,7 @@ static VALUE NIO_ByteBuffer_initialize(VALUE self, VALUE capacity)
126
144
  static VALUE NIO_ByteBuffer_clear(VALUE self)
127
145
  {
128
146
  struct NIO_ByteBuffer *buffer;
129
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
147
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
130
148
 
131
149
  memset(buffer->buffer, 0, buffer->capacity);
132
150
 
@@ -140,7 +158,7 @@ static VALUE NIO_ByteBuffer_clear(VALUE self)
140
158
  static VALUE NIO_ByteBuffer_get_position(VALUE self)
141
159
  {
142
160
  struct NIO_ByteBuffer *buffer;
143
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
161
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
144
162
 
145
163
  return INT2NUM(buffer->position);
146
164
  }
@@ -149,7 +167,7 @@ static VALUE NIO_ByteBuffer_set_position(VALUE self, VALUE new_position)
149
167
  {
150
168
  int pos;
151
169
  struct NIO_ByteBuffer *buffer;
152
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
170
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
153
171
 
154
172
  pos = NUM2INT(new_position);
155
173
 
@@ -173,7 +191,7 @@ static VALUE NIO_ByteBuffer_set_position(VALUE self, VALUE new_position)
173
191
  static VALUE NIO_ByteBuffer_get_limit(VALUE self)
174
192
  {
175
193
  struct NIO_ByteBuffer *buffer;
176
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
194
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
177
195
 
178
196
  return INT2NUM(buffer->limit);
179
197
  }
@@ -182,7 +200,7 @@ static VALUE NIO_ByteBuffer_set_limit(VALUE self, VALUE new_limit)
182
200
  {
183
201
  int lim;
184
202
  struct NIO_ByteBuffer *buffer;
185
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
203
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
186
204
 
187
205
  lim = NUM2INT(new_limit);
188
206
 
@@ -210,7 +228,7 @@ static VALUE NIO_ByteBuffer_set_limit(VALUE self, VALUE new_limit)
210
228
  static VALUE NIO_ByteBuffer_capacity(VALUE self)
211
229
  {
212
230
  struct NIO_ByteBuffer *buffer;
213
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
231
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
214
232
 
215
233
  return INT2NUM(buffer->capacity);
216
234
  }
@@ -218,7 +236,7 @@ static VALUE NIO_ByteBuffer_capacity(VALUE self)
218
236
  static VALUE NIO_ByteBuffer_remaining(VALUE self)
219
237
  {
220
238
  struct NIO_ByteBuffer *buffer;
221
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
239
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
222
240
 
223
241
  return INT2NUM(buffer->limit - buffer->position);
224
242
  }
@@ -226,7 +244,7 @@ static VALUE NIO_ByteBuffer_remaining(VALUE self)
226
244
  static VALUE NIO_ByteBuffer_full(VALUE self)
227
245
  {
228
246
  struct NIO_ByteBuffer *buffer;
229
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
247
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
230
248
 
231
249
  return buffer->position == buffer->limit ? Qtrue : Qfalse;
232
250
  }
@@ -236,7 +254,7 @@ static VALUE NIO_ByteBuffer_get(int argc, VALUE *argv, VALUE self)
236
254
  int len;
237
255
  VALUE length, result;
238
256
  struct NIO_ByteBuffer *buffer;
239
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
257
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
240
258
 
241
259
  rb_scan_args(argc, argv, "01", &length);
242
260
 
@@ -264,7 +282,7 @@ static VALUE NIO_ByteBuffer_fetch(VALUE self, VALUE index)
264
282
  {
265
283
  int i;
266
284
  struct NIO_ByteBuffer *buffer;
267
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
285
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
268
286
 
269
287
  i = NUM2INT(index);
270
288
 
@@ -283,7 +301,7 @@ static VALUE NIO_ByteBuffer_put(VALUE self, VALUE string)
283
301
  {
284
302
  long length;
285
303
  struct NIO_ByteBuffer *buffer;
286
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
304
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
287
305
 
288
306
  StringValue(string);
289
307
  length = RSTRING_LEN(string);
@@ -303,7 +321,7 @@ static VALUE NIO_ByteBuffer_read_from(VALUE self, VALUE io)
303
321
  struct NIO_ByteBuffer *buffer;
304
322
  ssize_t nbytes, bytes_read;
305
323
 
306
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
324
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
307
325
 
308
326
  io = rb_convert_type(io, T_FILE, "IO", "to_io");
309
327
  io_set_nonblock(io);
@@ -333,7 +351,7 @@ static VALUE NIO_ByteBuffer_write_to(VALUE self, VALUE io)
333
351
  struct NIO_ByteBuffer *buffer;
334
352
  ssize_t nbytes, bytes_written;
335
353
 
336
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
354
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
337
355
  io = rb_convert_type(io, T_FILE, "IO", "to_io");
338
356
  io_set_nonblock(io);
339
357
 
@@ -360,7 +378,7 @@ static VALUE NIO_ByteBuffer_write_to(VALUE self, VALUE io)
360
378
  static VALUE NIO_ByteBuffer_flip(VALUE self)
361
379
  {
362
380
  struct NIO_ByteBuffer *buffer;
363
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
381
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
364
382
 
365
383
  buffer->limit = buffer->position;
366
384
  buffer->position = 0;
@@ -372,7 +390,7 @@ static VALUE NIO_ByteBuffer_flip(VALUE self)
372
390
  static VALUE NIO_ByteBuffer_rewind(VALUE self)
373
391
  {
374
392
  struct NIO_ByteBuffer *buffer;
375
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
393
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
376
394
 
377
395
  buffer->position = 0;
378
396
  buffer->mark = MARK_UNSET;
@@ -383,7 +401,7 @@ static VALUE NIO_ByteBuffer_rewind(VALUE self)
383
401
  static VALUE NIO_ByteBuffer_mark(VALUE self)
384
402
  {
385
403
  struct NIO_ByteBuffer *buffer;
386
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
404
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
387
405
 
388
406
  buffer->mark = buffer->position;
389
407
  return self;
@@ -392,7 +410,7 @@ static VALUE NIO_ByteBuffer_mark(VALUE self)
392
410
  static VALUE NIO_ByteBuffer_reset(VALUE self)
393
411
  {
394
412
  struct NIO_ByteBuffer *buffer;
395
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
413
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
396
414
 
397
415
  if (buffer->mark < 0) {
398
416
  rb_raise(cNIO_ByteBuffer_MarkUnsetError, "mark has not been set");
@@ -406,7 +424,7 @@ static VALUE NIO_ByteBuffer_reset(VALUE self)
406
424
  static VALUE NIO_ByteBuffer_compact(VALUE self)
407
425
  {
408
426
  struct NIO_ByteBuffer *buffer;
409
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
427
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
410
428
 
411
429
  memmove(buffer->buffer, buffer->buffer + buffer->position, buffer->limit - buffer->position);
412
430
  buffer->position = buffer->limit - buffer->position;
@@ -419,7 +437,7 @@ static VALUE NIO_ByteBuffer_each(VALUE self)
419
437
  {
420
438
  int i;
421
439
  struct NIO_ByteBuffer *buffer;
422
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
440
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
423
441
 
424
442
  if (rb_block_given_p()) {
425
443
  for (i = 0; i < buffer->limit; i++) {
@@ -435,7 +453,7 @@ static VALUE NIO_ByteBuffer_each(VALUE self)
435
453
  static VALUE NIO_ByteBuffer_inspect(VALUE self)
436
454
  {
437
455
  struct NIO_ByteBuffer *buffer;
438
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
456
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
439
457
 
440
458
  return rb_sprintf(
441
459
  "#<%s:%p @position=%d @limit=%d @capacity=%d>",
data/ext/nio4r/monitor.c CHANGED
@@ -11,8 +11,8 @@ static VALUE cNIO_Monitor = Qnil;
11
11
 
12
12
  /* Allocator/deallocator */
13
13
  static VALUE NIO_Monitor_allocate(VALUE klass);
14
- static void NIO_Monitor_mark(struct NIO_Monitor *monitor);
15
- static void NIO_Monitor_free(struct NIO_Monitor *monitor);
14
+ static void NIO_Monitor_mark(void *data);
15
+ static size_t NIO_Monitor_memsize(const void *data);
16
16
 
17
17
  /* Methods */
18
18
  static VALUE NIO_Monitor_initialize(VALUE self, VALUE selector, VALUE io, VALUE interests);
@@ -70,22 +70,36 @@ void Init_NIO_Monitor()
70
70
  rb_define_method(cNIO_Monitor, "writeable?", NIO_Monitor_is_writable, 0);
71
71
  }
72
72
 
73
+ static const rb_data_type_t NIO_Monitor_type = {
74
+ "NIO::Monitor",
75
+ {
76
+ NIO_Monitor_mark,
77
+ RUBY_TYPED_DEFAULT_FREE,
78
+ NIO_Monitor_memsize,
79
+ },
80
+ 0,
81
+ 0,
82
+ RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
83
+ };
84
+
73
85
  static VALUE NIO_Monitor_allocate(VALUE klass)
74
86
  {
75
87
  struct NIO_Monitor *monitor = (struct NIO_Monitor *)xmalloc(sizeof(struct NIO_Monitor));
76
88
  assert(monitor);
77
89
  *monitor = (struct NIO_Monitor){.self = Qnil};
78
- return Data_Wrap_Struct(klass, NIO_Monitor_mark, NIO_Monitor_free, monitor);
90
+ return TypedData_Wrap_Struct(klass, &NIO_Monitor_type, monitor);
79
91
  }
80
92
 
81
- static void NIO_Monitor_mark(struct NIO_Monitor *monitor)
93
+ static void NIO_Monitor_mark(void *data)
82
94
  {
95
+ struct NIO_Monitor *monitor = (struct NIO_Monitor *)data;
83
96
  rb_gc_mark(monitor->self);
84
97
  }
85
98
 
86
- static void NIO_Monitor_free(struct NIO_Monitor *monitor)
99
+ static size_t NIO_Monitor_memsize(const void *data)
87
100
  {
88
- xfree(monitor);
101
+ const struct NIO_Monitor *monitor = (const struct NIO_Monitor *)data;
102
+ return sizeof(*monitor);
89
103
  }
90
104
 
91
105
  static VALUE NIO_Monitor_initialize(VALUE self, VALUE io, VALUE interests, VALUE selector_obj)
@@ -96,7 +110,7 @@ static VALUE NIO_Monitor_initialize(VALUE self, VALUE io, VALUE interests, VALUE
96
110
 
97
111
  interests_id = SYM2ID(interests);
98
112
 
99
- Data_Get_Struct(self, struct NIO_Monitor, monitor);
113
+ TypedData_Get_Struct(self, struct NIO_Monitor, &NIO_Monitor_type, monitor);
100
114
 
101
115
  if (interests_id == rb_intern("r")) {
102
116
  monitor->interests = EV_READ;
@@ -115,9 +129,9 @@ static VALUE NIO_Monitor_initialize(VALUE self, VALUE io, VALUE interests, VALUE
115
129
  rb_ivar_set(self, rb_intern("interests"), interests);
116
130
  rb_ivar_set(self, rb_intern("selector"), selector_obj);
117
131
 
118
- Data_Get_Struct(selector_obj, struct NIO_Selector, selector);
132
+ selector = NIO_Selector_unwrap(selector_obj);
119
133
 
120
- monitor->self = self;
134
+ RB_OBJ_WRITE(self, &monitor->self, self);
121
135
  monitor->ev_io.data = (void *)monitor;
122
136
 
123
137
  /* We can safely hang onto this as we also hang onto a reference to the
@@ -135,7 +149,7 @@ static VALUE NIO_Monitor_close(int argc, VALUE *argv, VALUE self)
135
149
  {
136
150
  VALUE deregister, selector;
137
151
  struct NIO_Monitor *monitor;
138
- Data_Get_Struct(self, struct NIO_Monitor, monitor);
152
+ TypedData_Get_Struct(self, struct NIO_Monitor, &NIO_Monitor_type, monitor);
139
153
 
140
154
  rb_scan_args(argc, argv, "01", &deregister);
141
155
  selector = rb_ivar_get(self, rb_intern("selector"));
@@ -161,7 +175,7 @@ static VALUE NIO_Monitor_close(int argc, VALUE *argv, VALUE self)
161
175
  static VALUE NIO_Monitor_is_closed(VALUE self)
162
176
  {
163
177
  struct NIO_Monitor *monitor;
164
- Data_Get_Struct(self, struct NIO_Monitor, monitor);
178
+ TypedData_Get_Struct(self, struct NIO_Monitor, &NIO_Monitor_type, monitor);
165
179
 
166
180
  return monitor->selector == 0 ? Qtrue : Qfalse;
167
181
  }
@@ -190,7 +204,7 @@ static VALUE NIO_Monitor_set_interests(VALUE self, VALUE interests)
190
204
  static VALUE NIO_Monitor_add_interest(VALUE self, VALUE interest)
191
205
  {
192
206
  struct NIO_Monitor *monitor;
193
- Data_Get_Struct(self, struct NIO_Monitor, monitor);
207
+ TypedData_Get_Struct(self, struct NIO_Monitor, &NIO_Monitor_type, monitor);
194
208
 
195
209
  interest = monitor->interests | NIO_Monitor_symbol2interest(interest);
196
210
  NIO_Monitor_update_interests(self, (int)interest);
@@ -201,7 +215,7 @@ static VALUE NIO_Monitor_add_interest(VALUE self, VALUE interest)
201
215
  static VALUE NIO_Monitor_remove_interest(VALUE self, VALUE interest)
202
216
  {
203
217
  struct NIO_Monitor *monitor;
204
- Data_Get_Struct(self, struct NIO_Monitor, monitor);
218
+ TypedData_Get_Struct(self, struct NIO_Monitor, &NIO_Monitor_type, monitor);
205
219
 
206
220
  interest = monitor->interests & ~NIO_Monitor_symbol2interest(interest);
207
221
  NIO_Monitor_update_interests(self, (int)interest);
@@ -227,7 +241,7 @@ static VALUE NIO_Monitor_set_value(VALUE self, VALUE obj)
227
241
  static VALUE NIO_Monitor_readiness(VALUE self)
228
242
  {
229
243
  struct NIO_Monitor *monitor;
230
- Data_Get_Struct(self, struct NIO_Monitor, monitor);
244
+ TypedData_Get_Struct(self, struct NIO_Monitor, &NIO_Monitor_type, monitor);
231
245
 
232
246
  if ((monitor->revents & (EV_READ | EV_WRITE)) == (EV_READ | EV_WRITE)) {
233
247
  return ID2SYM(rb_intern("rw"));
@@ -243,7 +257,7 @@ static VALUE NIO_Monitor_readiness(VALUE self)
243
257
  static VALUE NIO_Monitor_is_readable(VALUE self)
244
258
  {
245
259
  struct NIO_Monitor *monitor;
246
- Data_Get_Struct(self, struct NIO_Monitor, monitor);
260
+ TypedData_Get_Struct(self, struct NIO_Monitor, &NIO_Monitor_type, monitor);
247
261
 
248
262
  if (monitor->revents & EV_READ) {
249
263
  return Qtrue;
@@ -255,7 +269,7 @@ static VALUE NIO_Monitor_is_readable(VALUE self)
255
269
  static VALUE NIO_Monitor_is_writable(VALUE self)
256
270
  {
257
271
  struct NIO_Monitor *monitor;
258
- Data_Get_Struct(self, struct NIO_Monitor, monitor);
272
+ TypedData_Get_Struct(self, struct NIO_Monitor, &NIO_Monitor_type, monitor);
259
273
 
260
274
  if (monitor->revents & EV_WRITE) {
261
275
  return Qtrue;
@@ -286,7 +300,7 @@ static void NIO_Monitor_update_interests(VALUE self, int interests)
286
300
  {
287
301
  ID interests_id;
288
302
  struct NIO_Monitor *monitor;
289
- Data_Get_Struct(self, struct NIO_Monitor, monitor);
303
+ TypedData_Get_Struct(self, struct NIO_Monitor, &NIO_Monitor_type, monitor);
290
304
 
291
305
  if (NIO_Monitor_is_closed(self) == Qtrue) {
292
306
  rb_raise(rb_eEOFError, "monitor is closed");
data/ext/nio4r/nio4r.h CHANGED
@@ -40,6 +40,8 @@ struct NIO_ByteBuffer {
40
40
  int position, limit, capacity, mark;
41
41
  };
42
42
 
43
+ struct NIO_Selector *NIO_Selector_unwrap(VALUE selector);
44
+
43
45
  /* Thunk between libev callbacks in NIO::Monitors and NIO::Selectors */
44
46
  void NIO_Selector_monitor_callback(struct ev_loop *ev_loop, struct ev_io *io, int revents);
45
47
 
data/ext/nio4r/selector.c CHANGED
@@ -23,9 +23,10 @@ static VALUE cNIO_Selector = Qnil;
23
23
 
24
24
  /* Allocator/deallocator */
25
25
  static VALUE NIO_Selector_allocate(VALUE klass);
26
- static void NIO_Selector_mark(struct NIO_Selector *loop);
26
+ static void NIO_Selector_mark(void *data);
27
27
  static void NIO_Selector_shutdown(struct NIO_Selector *selector);
28
- static void NIO_Selector_free(struct NIO_Selector *loop);
28
+ static void NIO_Selector_free(void *data);
29
+ static size_t NIO_Selector_memsize(const void *data);
29
30
 
30
31
  /* Class methods */
31
32
  static VALUE NIO_Selector_supported_backends(VALUE klass);
@@ -83,6 +84,18 @@ void Init_NIO_Selector(void)
83
84
  cNIO_Monitor = rb_define_class_under(mNIO, "Monitor", rb_cObject);
84
85
  }
85
86
 
87
+ static const rb_data_type_t NIO_Selector_type = {
88
+ "NIO::Selector",
89
+ {
90
+ NIO_Selector_mark,
91
+ NIO_Selector_free,
92
+ NIO_Selector_memsize,
93
+ },
94
+ 0,
95
+ 0,
96
+ RUBY_TYPED_WB_PROTECTED // Don't free immediately because of shutdown
97
+ };
98
+
86
99
  /* Create the libev event loop and incoming event buffer */
87
100
  static VALUE NIO_Selector_allocate(VALUE klass)
88
101
  {
@@ -104,8 +117,7 @@ static VALUE NIO_Selector_allocate(VALUE klass)
104
117
  rb_sys_fail("fcntl");
105
118
  }
106
119
 
107
- selector = (struct NIO_Selector *)xmalloc(sizeof(struct NIO_Selector));
108
-
120
+ VALUE obj = TypedData_Make_Struct(klass, struct NIO_Selector, &NIO_Selector_type, selector);
109
121
  /* Defer initializing the loop to #initialize */
110
122
  selector->ev_loop = 0;
111
123
 
@@ -118,14 +130,21 @@ static VALUE NIO_Selector_allocate(VALUE klass)
118
130
  selector->wakeup.data = (void *)selector;
119
131
 
120
132
  selector->closed = selector->selecting = selector->wakeup_fired = selector->ready_count = 0;
121
- selector->ready_array = Qnil;
133
+ RB_OBJ_WRITE(obj, &selector->ready_array, Qnil);
134
+ return obj;
135
+ }
122
136
 
123
- return Data_Wrap_Struct(klass, NIO_Selector_mark, NIO_Selector_free, selector);
137
+ struct NIO_Selector *NIO_Selector_unwrap(VALUE self)
138
+ {
139
+ struct NIO_Selector *selector;
140
+ TypedData_Get_Struct(self, struct NIO_Selector, &NIO_Selector_type, selector);
141
+ return selector;
124
142
  }
125
143
 
126
144
  /* NIO selectors store all Ruby objects in instance variables so mark is a stub */
127
- static void NIO_Selector_mark(struct NIO_Selector *selector)
145
+ static void NIO_Selector_mark(void *data)
128
146
  {
147
+ struct NIO_Selector *selector = (struct NIO_Selector *)data;
129
148
  if (selector->ready_array != Qnil) {
130
149
  rb_gc_mark(selector->ready_array);
131
150
  }
@@ -151,12 +170,18 @@ static void NIO_Selector_shutdown(struct NIO_Selector *selector)
151
170
  }
152
171
 
153
172
  /* Ruby finalizer for selector objects */
154
- static void NIO_Selector_free(struct NIO_Selector *selector)
173
+ static void NIO_Selector_free(void *data)
155
174
  {
175
+ struct NIO_Selector *selector = (struct NIO_Selector *)data;
156
176
  NIO_Selector_shutdown(selector);
157
177
  xfree(selector);
158
178
  }
159
179
 
180
+ static size_t NIO_Selector_memsize(const void *data)
181
+ {
182
+ return sizeof(struct NIO_Selector);
183
+ }
184
+
160
185
  /* Return an array of symbols for supported backends */
161
186
  static VALUE NIO_Selector_supported_backends(VALUE klass)
162
187
  {
@@ -205,7 +230,7 @@ static VALUE NIO_Selector_initialize(int argc, VALUE *argv, VALUE self)
205
230
  struct NIO_Selector *selector;
206
231
  unsigned int flags = 0;
207
232
 
208
- Data_Get_Struct(self, struct NIO_Selector, selector);
233
+ TypedData_Get_Struct(self, struct NIO_Selector, &NIO_Selector_type, selector);
209
234
 
210
235
  rb_scan_args(argc, argv, "01", &backend);
211
236
 
@@ -259,7 +284,7 @@ static VALUE NIO_Selector_backend(VALUE self)
259
284
  {
260
285
  struct NIO_Selector *selector;
261
286
 
262
- Data_Get_Struct(self, struct NIO_Selector, selector);
287
+ TypedData_Get_Struct(self, struct NIO_Selector, &NIO_Selector_type, selector);
263
288
  if (selector->closed) {
264
289
  rb_raise(rb_eIOError, "selector is closed");
265
290
  }
@@ -337,7 +362,7 @@ static VALUE NIO_Selector_register_synchronized(VALUE _args)
337
362
  io = args[1];
338
363
  interests = args[2];
339
364
 
340
- Data_Get_Struct(self, struct NIO_Selector, selector);
365
+ TypedData_Get_Struct(self, struct NIO_Selector, &NIO_Selector_type, selector);
341
366
  if (selector->closed) {
342
367
  rb_raise(rb_eIOError, "selector is closed");
343
368
  }
@@ -418,14 +443,14 @@ static VALUE NIO_Selector_select_synchronized(VALUE _args)
418
443
 
419
444
  VALUE *args = (VALUE *)_args;
420
445
 
421
- Data_Get_Struct(args[0], struct NIO_Selector, selector);
446
+ TypedData_Get_Struct(args[0], struct NIO_Selector, &NIO_Selector_type, selector);
422
447
 
423
448
  if (selector->closed) {
424
449
  rb_raise(rb_eIOError, "selector is closed");
425
450
  }
426
451
 
427
452
  if (!rb_block_given_p()) {
428
- selector->ready_array = rb_ary_new();
453
+ RB_OBJ_WRITE(args[0], &selector->ready_array, rb_ary_new());
429
454
  }
430
455
 
431
456
  ready = NIO_Selector_run(selector, args[1]);
@@ -433,7 +458,7 @@ static VALUE NIO_Selector_select_synchronized(VALUE _args)
433
458
  /* Timeout */
434
459
  if (ready < 0) {
435
460
  if (!rb_block_given_p()) {
436
- selector->ready_array = Qnil;
461
+ RB_OBJ_WRITE(args[0], &selector->ready_array, Qnil);
437
462
  }
438
463
 
439
464
  return Qnil;
@@ -443,7 +468,7 @@ static VALUE NIO_Selector_select_synchronized(VALUE _args)
443
468
  return INT2NUM(ready);
444
469
  } else {
445
470
  ready_array = selector->ready_array;
446
- selector->ready_array = Qnil;
471
+ RB_OBJ_WRITE(args[0], &selector->ready_array, Qnil);
447
472
  return ready_array;
448
473
  }
449
474
  }
@@ -490,7 +515,7 @@ static int NIO_Selector_run(struct NIO_Selector *selector, VALUE timeout)
490
515
  static VALUE NIO_Selector_wakeup(VALUE self)
491
516
  {
492
517
  struct NIO_Selector *selector;
493
- Data_Get_Struct(self, struct NIO_Selector, selector);
518
+ TypedData_Get_Struct(self, struct NIO_Selector, &NIO_Selector_type, selector);
494
519
 
495
520
  if (selector->closed) {
496
521
  rb_raise(rb_eIOError, "selector is closed");
@@ -512,7 +537,7 @@ static VALUE NIO_Selector_close_synchronized(VALUE self)
512
537
  {
513
538
  struct NIO_Selector *selector;
514
539
 
515
- Data_Get_Struct(self, struct NIO_Selector, selector);
540
+ TypedData_Get_Struct(self, struct NIO_Selector, &NIO_Selector_type, selector);
516
541
 
517
542
  NIO_Selector_shutdown(selector);
518
543
 
@@ -529,7 +554,7 @@ static VALUE NIO_Selector_closed_synchronized(VALUE self)
529
554
  {
530
555
  struct NIO_Selector *selector;
531
556
 
532
- Data_Get_Struct(self, struct NIO_Selector, selector);
557
+ TypedData_Get_Struct(self, struct NIO_Selector, &NIO_Selector_type, selector);
533
558
 
534
559
  return selector->closed ? Qtrue : Qfalse;
535
560
  }
data/lib/nio/version.rb CHANGED
@@ -6,5 +6,5 @@
6
6
  # Copyright, 2023, by Tsimnuj Hawj.
7
7
 
8
8
  module NIO
9
- VERSION = "2.6.1"
9
+ VERSION = "2.7.0"
10
10
  end
data/license.md CHANGED
@@ -69,7 +69,8 @@ SOFTWARE.
69
69
 
70
70
  ## libev
71
71
 
72
- Released under the BSD license. See [ext/libev/LICENSE] for details.
72
+ Released under the BSD-2-Clause OR GPL-2.0-or-later license.
73
+ See [ext/libev/LICENSE] for details.
73
74
 
74
75
  Copyright, 2007-2019, by Marc Alexander Lehmann.
75
76
 
data/nio4r.gemspec CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
6
6
  spec.authors = ["Tony Arcieri"]
7
7
  spec.email = ["bascule@gmail.com"]
8
8
  spec.homepage = "https://github.com/socketry/nio4r"
9
- spec.license = "MIT"
9
+ spec.license = "MIT AND (BSD-2-Clause OR GPL-2.0-or-later)"
10
10
  spec.summary = "New IO for Ruby"
11
11
  spec.description = <<-DESCRIPTION.strip.gsub(/\s+/, " ")
12
12
  Cross-platform asynchronous I/O primitives for scalable network clients
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.metadata = {
24
24
  "bug_tracker_uri" => "https://github.com/socketry/nio4r/issues",
25
- "changelog_uri" => "https://github.com/socketry/nio4r/blob/master/CHANGES.md",
25
+ "changelog_uri" => "https://github.com/socketry/nio4r/blob/main/changes.md",
26
26
  "documentation_uri" => "https://www.rubydoc.info/gems/nio4r/#{spec.version}",
27
27
  "source_code_uri" => "https://github.com/socketry/nio4r/tree/v#{spec.version}",
28
28
  "wiki_uri" => "https://github.com/socketry/nio4r/wiki",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nio4r
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.1
4
+ version: 2.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Arcieri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-21 00:00:00.000000000 Z
11
+ date: 2023-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,10 +108,10 @@ files:
108
108
  - spec/support/selectable_examples.rb
109
109
  homepage: https://github.com/socketry/nio4r
110
110
  licenses:
111
- - MIT
111
+ - MIT AND (BSD-2-Clause OR GPL-2.0-or-later)
112
112
  metadata:
113
113
  bug_tracker_uri: https://github.com/socketry/nio4r/issues
114
- changelog_uri: https://github.com/socketry/nio4r/blob/master/CHANGES.md
114
+ changelog_uri: https://github.com/socketry/nio4r/blob/main/changes.md
115
115
  documentation_uri: https://www.rubydoc.info/gems/nio4r/2.6.1
116
116
  source_code_uri: https://github.com/socketry/nio4r/tree/v2.6.1
117
117
  wiki_uri: https://github.com/socketry/nio4r/wiki
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  - !ruby/object:Gem::Version
132
132
  version: '0'
133
133
  requirements: []
134
- rubygems_version: 3.4.10
134
+ rubygems_version: 3.4.22
135
135
  signing_key:
136
136
  specification_version: 4
137
137
  summary: New IO for Ruby