polyphony 0.92 → 0.93

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: 73f54eb3c5d34b89d6f24b7e66ba330e6d5345fb94a59f5f6c29efa9d6f6c695
4
- data.tar.gz: 03ceb137c92d641d90daea57fc40eeababc86996c0f50df5e4c5246b79e134fc
3
+ metadata.gz: bb7ee7e43bec0bfffbcff8c78cdcdcc7d93f4283014bd9caebfcd94c3da6b96f
4
+ data.tar.gz: add731011308495bc5ec0f4f5bc1f7152cfaa1dddd0f53f8027b4a64ea0ba08f
5
5
  SHA512:
6
- metadata.gz: cd04383a8ec148ac7c8d79d9d2ba3cd3d53c4eeb459a0bf91d8aa6b5e97523a7a414dac8ca79d81f0182f6be3db741f7eac0d6eb4f9f405f568fea61c0b5ce5e
7
- data.tar.gz: bd4fe45c1bc1a014f0c395580f2975e7273f621f43979fa6a59cefd64388ce371631846b29e30589928071532ddebfa5e0c4cbbb9c2fb57bd384648b092d1621
6
+ metadata.gz: 108f69257c57caab18780bad60dbd6bed240dd8a45e05e54e54cbb4b90d31382c10c8f25d3c8bb92f8753e134054782eb4b9d47e79ec79da8938ac4c3d14f4a6
7
+ data.tar.gz: be78ce7748655d18014074fbb95bedecccab8af94b53e7a2db797cdb503a4f67c25a81b9e9b9154d6e1187efbc3c5fd1b4454e604ad068d51a0c3f411ee7c8ea
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.93 2022-04-05
2
+
3
+ - Add support for IO::Buffer in Ruby 3.1 (#80)
4
+
1
5
  ## 0.92 2022-04-04
2
6
 
3
7
  - Fix plice on non-Linux OS
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- polyphony (0.92)
4
+ polyphony (0.93)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ task :recompile => [:clean, :compile]
12
12
  task :default => [:compile, :test]
13
13
 
14
14
  task :test do
15
- exec 'ruby test/run.rb'
15
+ exec 'ruby test/run.rb --verbose'
16
16
  end
17
17
 
18
18
  task :stress_test do
@@ -4,6 +4,9 @@
4
4
  #include "ruby/io.h"
5
5
  #include "polyphony.h"
6
6
  #include "backend_common.h"
7
+ #ifdef HAVE_RUBY_IO_BUFFER_H
8
+ #include "ruby/io/buffer.h"
9
+ #endif
7
10
 
8
11
  inline void backend_base_initialize(struct Backend_base *base) {
9
12
  runqueue_initialize(&base->runqueue);
@@ -476,11 +479,24 @@ int backend_getaddrinfo(VALUE host, VALUE port, struct sockaddr **ai_addr) {
476
479
  return addrinfo_result->ai_addrlen;
477
480
  }
478
481
 
479
- struct io_buffer get_io_buffer(VALUE in) {
482
+ struct io_buffer get_io_buffer(VALUE in, int rw) {
480
483
  if (FIXNUM_P(in)) {
481
484
  struct raw_buffer *raw = FIX2PTR(in);
482
485
  return (struct io_buffer){ raw->ptr, raw->len, 1 };
483
486
  }
487
+
488
+ #ifdef HAVE_RUBY_IO_BUFFER_H
489
+ if (rb_obj_is_kind_of(in, rb_cIOBuffer) == Qtrue) {
490
+ void *ptr;
491
+ size_t len;
492
+ if (rw)
493
+ rb_io_buffer_get_bytes_for_reading(in, (const void **)&ptr, &len);
494
+ else
495
+ rb_io_buffer_get_bytes_for_writing(in, &ptr, &len);
496
+ return (struct io_buffer){ ptr, len, 1 };
497
+ }
498
+ #endif
499
+
484
500
  return (struct io_buffer){ (unsigned char *)RSTRING_PTR(in), RSTRING_LEN(in), 0 };
485
501
  }
486
502
 
@@ -71,7 +71,7 @@ struct io_buffer {
71
71
  #define FIX2PTR(v) ((void *)(FIX2LONG(v)))
72
72
  #define PTR2FIX(p) LONG2FIX((long)p)
73
73
 
74
- struct io_buffer get_io_buffer(VALUE in);
74
+ struct io_buffer get_io_buffer(VALUE in, int rw);
75
75
  VALUE coerce_io_string_or_buffer(VALUE buf);
76
76
 
77
77
  #ifdef POLYPHONY_USE_PIDFD_OPEN
@@ -363,7 +363,7 @@ VALUE Backend_read(VALUE self, VALUE io, VALUE str, VALUE length, VALUE to_eof,
363
363
  Backend_t *backend;
364
364
  int fd;
365
365
  rb_io_t *fptr;
366
- struct io_buffer buffer = get_io_buffer(str);
366
+ struct io_buffer buffer = get_io_buffer(str, 0);
367
367
  long buf_pos = FIX2INT(pos);
368
368
  int shrinkable_string = 0;
369
369
  int expandable_buffer = 0;
@@ -552,7 +552,7 @@ VALUE Backend_write(VALUE self, VALUE io, VALUE str) {
552
552
  int fd;
553
553
  rb_io_t *fptr;
554
554
 
555
- struct io_buffer buffer = get_io_buffer(str);
555
+ struct io_buffer buffer = get_io_buffer(str, 1);
556
556
  long left = buffer.len;
557
557
 
558
558
  GetBackend(self, backend);
@@ -668,7 +668,7 @@ VALUE Backend_recv(VALUE self, VALUE io, VALUE str, VALUE length, VALUE pos) {
668
668
  Backend_t *backend;
669
669
  int fd;
670
670
  rb_io_t *fptr;
671
- struct io_buffer buffer = get_io_buffer(str);
671
+ struct io_buffer buffer = get_io_buffer(str, 0);
672
672
  long buf_pos = FIX2INT(pos);
673
673
  int shrinkable_string = 0;
674
674
  int expandable_buffer = 0;
@@ -836,7 +836,7 @@ VALUE Backend_send(VALUE self, VALUE io, VALUE str, VALUE flags) {
836
836
  int fd;
837
837
  rb_io_t *fptr;
838
838
 
839
- struct io_buffer buffer = get_io_buffer(str);
839
+ struct io_buffer buffer = get_io_buffer(str, 1);
840
840
  long left = buffer.len;
841
841
  int flags_int = FIX2INT(flags);
842
842
 
@@ -1075,7 +1075,7 @@ VALUE double_splice_cleanup(struct double_splice_ctx *ctx) {
1075
1075
  }
1076
1076
 
1077
1077
  VALUE Backend_double_splice(VALUE self, VALUE src, VALUE dest) {
1078
- struct double_splice_ctx ctx = { NULL, src, dest, 0, 0 };
1078
+ struct double_splice_ctx ctx = { NULL, src, dest, {0, 0} };
1079
1079
  GetBackend(self, ctx.backend);
1080
1080
  if (pipe(ctx.pipefd) == -1) rb_syserr_fail(errno, strerror(errno));
1081
1081
 
@@ -290,7 +290,7 @@ VALUE Backend_read(VALUE self, VALUE io, VALUE str, VALUE length, VALUE to_eof,
290
290
  int fd;
291
291
  rb_io_t *fptr;
292
292
 
293
- struct io_buffer buffer = get_io_buffer(str);
293
+ struct io_buffer buffer = get_io_buffer(str, 0);
294
294
  long buf_pos = FIX2INT(pos);
295
295
  int shrinkable_string = 0;
296
296
  int expandable_buffer = 0;
@@ -486,7 +486,7 @@ VALUE Backend_write(VALUE self, VALUE io, VALUE str) {
486
486
  rb_io_t *fptr;
487
487
  VALUE switchpoint_result = Qnil;
488
488
 
489
- struct io_buffer buffer = get_io_buffer(str);
489
+ struct io_buffer buffer = get_io_buffer(str, 1);
490
490
  long left = buffer.len;
491
491
 
492
492
  GetBackend(self, backend);
@@ -761,7 +761,7 @@ VALUE Backend_send(VALUE self, VALUE io, VALUE str, VALUE flags) {
761
761
  rb_io_t *fptr;
762
762
  VALUE switchpoint_result = Qnil;
763
763
 
764
- struct io_buffer buffer = get_io_buffer(str);
764
+ struct io_buffer buffer = get_io_buffer(str, 1);
765
765
  long left = buffer.len;
766
766
  int flags_int = FIX2INT(flags);
767
767
 
@@ -61,6 +61,8 @@ else
61
61
  $defs << '-DEV_USE_PORT' if have_type('port_event_t', 'port.h')
62
62
  $defs << '-DHAVE_SYS_RESOURCE_H' if have_header('sys/resource.h')
63
63
 
64
+ $defs << "-DEV_STANDALONE" # prevent libev from assuming "config.h" exists
65
+
64
66
  $CFLAGS << " -Wno-comment"
65
67
  $CFLAGS << " -Wno-unused-result"
66
68
  $CFLAGS << " -Wno-dangling-else"
@@ -75,4 +77,6 @@ if RUBY_VERSION >= '3.1'
75
77
  have_func('rb_fiber_transfer', 'ruby.h')
76
78
  end
77
79
 
80
+ have_header('ruby/io/buffer.h')
81
+
78
82
  create_makefile 'polyphony_ext'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polyphony
4
- VERSION = '0.92'
4
+ VERSION = '0.93'
5
5
  end
data/test/test_backend.rb CHANGED
@@ -404,6 +404,23 @@ class BackendTest < MiniTest::Test
404
404
  sleep 0.01
405
405
  assert_equal 2, counter
406
406
  end
407
+
408
+ def test_read_write_with_io_buffer
409
+ skip "Works only on Ruby >= 3.1" if RUBY_VERSION < '3.1'
410
+
411
+ msg = 'Hello world'
412
+ i, o = IO.pipe
413
+ read_buffer = IO::Buffer.new(64)
414
+ f = spin { @backend.read(i, read_buffer, 64, true, 0) }
415
+ write_buffer = IO::Buffer.new(msg.bytesize)
416
+ write_buffer.set_string(msg, 0)
417
+ @backend.write(o, write_buffer)
418
+ o.close
419
+ return_value = f.await
420
+
421
+ assert_equal msg.bytesize, return_value
422
+ assert_equal msg, read_buffer.get_string(0, msg.bytesize)
423
+ end
407
424
  end
408
425
 
409
426
  class BackendChainTest < MiniTest::Test
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polyphony
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.92'
4
+ version: '0.93'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-04 00:00:00.000000000 Z
11
+ date: 2022-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -136,7 +136,7 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: 1.1.4
139
- description:
139
+ description:
140
140
  email: sharon@noteflakes.com
141
141
  executables: []
142
142
  extensions:
@@ -645,7 +645,7 @@ metadata:
645
645
  documentation_uri: https://digital-fabric.github.io/polyphony/
646
646
  homepage_uri: https://digital-fabric.github.io/polyphony/
647
647
  changelog_uri: https://github.com/digital-fabric/polyphony/blob/master/CHANGELOG.md
648
- post_install_message:
648
+ post_install_message:
649
649
  rdoc_options:
650
650
  - "--title"
651
651
  - polyphony
@@ -664,8 +664,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
664
664
  - !ruby/object:Gem::Version
665
665
  version: '0'
666
666
  requirements: []
667
- rubygems_version: 3.1.6
668
- signing_key:
667
+ rubygems_version: 3.3.3
668
+ signing_key:
669
669
  specification_version: 4
670
670
  summary: Fine grained concurrency for Ruby
671
671
  test_files: []