polyphony 0.81 → 0.83

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aef5f8ee7585e1ae6a6632099329ba35b7dc6959dba5041f4cdcbaf92caded72
4
- data.tar.gz: b168b56f080029e4167e2528e66b83186a635ea4bda8dc74882dfe70639421fc
3
+ metadata.gz: a1e0c71b9d91e674e4ce004da08cdf6535f56e48b063b63538685eb781654df6
4
+ data.tar.gz: 58bf12edd0751ecc552ee01b6eb7042585061f7800f0dfa6fdc0990b87349982
5
5
  SHA512:
6
- metadata.gz: aa7bd86706d5879c884b4f5bdc7a10556cbe28e6737ff89e5107589e1630028098dd815424ef357e51879a7e689cd5127ea30105eb1c36a174da7385b8f6f433
7
- data.tar.gz: 3c4b35eed6900d55c5295c366803b944a6e423775ca5278f4b2600a309cb547cda12a2167ae40a4ef8e0001a1b6a8b8ea936129246f24d87b0eec59c9d31a3b4
6
+ metadata.gz: c35e1c2756556db5bf11012b95c7e729d7ad43f52802c61fa5467d44a6460a2f30f840bc945347e83ed24d35e559b0ca4ac9d5657c9d0c805ffb44774765f867
7
+ data.tar.gz: 37c34a7c2cc0b3443c0f33908f40156c223eae233ca08f564a606a7bec5c8c68189b973e6fa40fd1534bb3c9f2f3985b52fcdd33c7ea9069ba21e32e7ebc1760
@@ -16,7 +16,7 @@ jobs:
16
16
  runs-on: ${{matrix.os}}
17
17
 
18
18
  env:
19
- POLYPHONY_USE_LIBEV: "1"
19
+ POLYPHONY_LIBEV: "1"
20
20
 
21
21
  steps:
22
22
  - name: Setup machine
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ## 0.83 2022-03-10
2
+
3
+ - Implement `Polyphony::Pipe` class, `Polyphony.pipe` method (#83)
4
+ - Add `IO.splice`, `IO.splice_to_eof` (#82)
5
+ - Implement compression/decompression methods (#77)
6
+
7
+ ## 0.82 2022-03-04
8
+
9
+ - Use `POLYPHONY_LIBEV` instead of `POLYPHONY_USE_LIBEV` environment variable
10
+ - Add support for working with raw buffers (#78)
11
+
12
+ ## 0.81.1 2022-03-03
13
+
14
+ - Fix `Backend_recv` regression
15
+
1
16
  ## 0.81 2022-03-03
2
17
 
3
18
  - Restore public visibility for `Polyphony::Process.kill_process`
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- polyphony (0.81)
4
+ polyphony (0.83)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/bin/test CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env bash
2
2
  set -e
3
- clear && POLYPHONY_USE_LIBEV=1 rake recompile && ruby test/run.rb
3
+ clear && POLYPHONY_LIBEV=1 rake recompile && ruby test/run.rb
4
4
  clear && rake recompile && ruby test/run.rb
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+ require 'polyphony'
5
+
6
+ puts '* pre'
7
+ Polyphony.backend_test(STDOUT, "Hello, world!\n")
8
+ puts '* post'
@@ -10,6 +10,7 @@ writer = Zlib::GzipWriter.new(w)
10
10
  writer << 'chunk'
11
11
  writer.flush
12
12
  p pos: writer.pos
13
- w.close
13
+ # w.close
14
+ writer.close
14
15
 
15
16
  p r.read
@@ -340,33 +340,38 @@ VALUE Backend_sendv(VALUE self, VALUE io, VALUE ary, VALUE flags) {
340
340
  }
341
341
  }
342
342
 
343
- inline void io_verify_blocking_mode(rb_io_t *fptr, VALUE io, VALUE blocking) {
343
+ inline void set_fd_blocking_mode(int fd, int blocking) {
344
344
  int flags;
345
345
  int is_nonblocking;
346
- VALUE blocking_mode = rb_ivar_get(io, ID_ivar_blocking_mode);
347
- if (blocking == blocking_mode) return;
348
-
349
- rb_ivar_set(io, ID_ivar_blocking_mode, blocking);
350
346
 
351
347
  #ifdef _WIN32
352
- if (blocking != Qtrue)
353
- rb_w32_set_nonblock(fptr->fd);
348
+ if (!blocking) rb_w32_set_nonblock(fd);
354
349
  #elif defined(F_GETFL)
355
- flags = fcntl(fptr->fd, F_GETFL);
350
+ flags = fcntl(fd, F_GETFL);
356
351
  if (flags == -1) return;
357
352
  is_nonblocking = flags & O_NONBLOCK;
358
353
 
359
- if (blocking == Qtrue) {
354
+ if (blocking) {
360
355
  if (!is_nonblocking) return;
361
356
  flags &= ~O_NONBLOCK;
362
357
  } else {
363
358
  if (is_nonblocking) return;
364
359
  flags |= O_NONBLOCK;
365
360
  }
366
- fcntl(fptr->fd, F_SETFL, flags);
361
+ fcntl(fd, F_SETFL, flags);
367
362
  #endif
368
363
  }
369
364
 
365
+ inline void io_verify_blocking_mode(rb_io_t *fptr, VALUE io, VALUE blocking) {
366
+ int flags;
367
+ int is_nonblocking;
368
+ VALUE blocking_mode = rb_ivar_get(io, ID_ivar_blocking_mode);
369
+ if (blocking == blocking_mode) return;
370
+
371
+ rb_ivar_set(io, ID_ivar_blocking_mode, blocking);
372
+ set_fd_blocking_mode(fptr->fd, blocking == Qtrue);
373
+ }
374
+
370
375
  inline void backend_run_idle_tasks(struct Backend_base *base) {
371
376
  double now;
372
377
 
@@ -470,3 +475,21 @@ int backend_getaddrinfo(VALUE host, VALUE port, struct sockaddr **ai_addr) {
470
475
  *ai_addr = addrinfo_result->ai_addr;
471
476
  return addrinfo_result->ai_addrlen;
472
477
  }
478
+
479
+ struct io_buffer get_io_buffer(VALUE in) {
480
+ if (FIXNUM_P(in)) {
481
+ struct raw_buffer *raw = FIX2PTR(in);
482
+ return (struct io_buffer){ raw->ptr, raw->len, 1 };
483
+ }
484
+ return (struct io_buffer){ RSTRING_PTR(in), RSTRING_LEN(in), 0 };
485
+ }
486
+
487
+ VALUE coerce_io_string_or_buffer(VALUE buf) {
488
+ switch (TYPE(buf)) {
489
+ case T_STRING:
490
+ case T_FIXNUM:
491
+ return buf;
492
+ default:
493
+ return StringValue(buf);
494
+ }
495
+ }
@@ -9,7 +9,6 @@
9
9
  #include "ruby.h"
10
10
  #include "ruby/io.h"
11
11
  #include "runqueue.h"
12
- #include "polyphony.h"
13
12
 
14
13
  struct backend_stats {
15
14
  unsigned int runqueue_size;
@@ -56,7 +55,24 @@ struct backend_stats backend_base_stats(struct Backend_base *base);
56
55
  }
57
56
  #define COND_TRACE(base, ...) if (SHOULD_TRACE(base)) { TRACE(base, __VA_ARGS__); }
58
57
 
58
+ // raw buffers
59
59
 
60
+ struct raw_buffer {
61
+ unsigned char *ptr;
62
+ int len;
63
+ };
64
+
65
+ struct io_buffer {
66
+ unsigned char *ptr;
67
+ int len;
68
+ int raw;
69
+ };
70
+
71
+ #define FIX2PTR(v) ((void *)(FIX2LONG(v)))
72
+ #define PTR2FIX(p) LONG2FIX((long)p)
73
+
74
+ struct io_buffer get_io_buffer(VALUE in);
75
+ VALUE coerce_io_string_or_buffer(VALUE buf);
60
76
 
61
77
  #ifdef POLYPHONY_USE_PIDFD_OPEN
62
78
  int pidfd_open(pid_t pid, unsigned int flags);
@@ -98,14 +114,14 @@ VALUE backend_snooze(struct Backend_base *backend);
98
114
 
99
115
  #define READ_LOOP_YIELD_STR() { \
100
116
  io_set_read_length(str, total, shrinkable); \
101
- io_enc_str(str, fptr); \
117
+ if (fptr) io_enc_str(str, fptr); \
102
118
  rb_yield(str); \
103
119
  READ_LOOP_PREPARE_STR(); \
104
120
  }
105
121
 
106
122
  #define READ_LOOP_PASS_STR_TO_RECEIVER(receiver, method_id) { \
107
123
  io_set_read_length(str, total, shrinkable); \
108
- io_enc_str(str, fptr); \
124
+ if (fptr) io_enc_str(str, fptr); \
109
125
  rb_funcall_passing_block(receiver, method_id, 1, &str); \
110
126
  READ_LOOP_PREPARE_STR(); \
111
127
  }
@@ -120,6 +136,7 @@ VALUE Backend_sendv(VALUE self, VALUE io, VALUE ary, VALUE flags);
120
136
  VALUE Backend_stats(VALUE self);
121
137
  VALUE Backend_verify_blocking_mode(VALUE self, VALUE io, VALUE blocking);
122
138
  void backend_run_idle_tasks(struct Backend_base *base);
139
+ void set_fd_blocking_mode(int fd, int blocking);
123
140
  void io_verify_blocking_mode(rb_io_t *fptr, VALUE io, VALUE blocking);
124
141
  void backend_setup_stats_symbols();
125
142
  int backend_getaddrinfo(VALUE host, VALUE port, struct sockaddr **ai_addr);