ruby-brs 1.1.4 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +86 -46
- data/ext/brs_ext/buffer.c +21 -9
- data/ext/brs_ext/buffer.h +7 -7
- data/ext/brs_ext/error.c +11 -15
- data/ext/brs_ext/error.h +2 -1
- data/ext/brs_ext/gvl.h +24 -0
- data/ext/brs_ext/io.c +240 -123
- data/ext/brs_ext/main.c +4 -1
- data/ext/brs_ext/option.c +54 -33
- data/ext/brs_ext/option.h +41 -29
- data/ext/brs_ext/stream/compressor.c +118 -54
- data/ext/brs_ext/stream/compressor.h +4 -1
- data/ext/brs_ext/stream/decompressor.c +54 -25
- data/ext/brs_ext/stream/decompressor.h +4 -1
- data/ext/brs_ext/string.c +118 -65
- data/ext/extconf.rb +90 -10
- data/lib/brs/file.rb +2 -2
- data/lib/brs/option.rb +36 -4
- data/lib/brs/stream/abstract.rb +5 -3
- data/lib/brs/stream/reader.rb +3 -2
- data/lib/brs/stream/reader_helpers.rb +1 -1
- data/lib/brs/validation.rb +3 -1
- data/lib/brs/version.rb +1 -1
- metadata +74 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 519776eef000f690d628b64310be61daf3e8cc144a103fa848586f1165e92de9
|
4
|
+
data.tar.gz: 8a0f7b24666a6291b10700a6ddf4dfd8afe90e2286750ca02531126348f0a198
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1a644ae3619da601177e0985926acffb6a43910c9686dfdb97b33f191814699f0cb6c9e38a5ecedb5f33999ac9cf129d0864bfcb2d065981faf1da61f5ef9c5
|
7
|
+
data.tar.gz: f7cf208285d14a9c2ef5b868dee4c1bf2dbe1262479cc250b6ce48d4c462007da431e8c5322097c8bf71cdef009140625ed8439d0c2a878825a4b502599a2086
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Ruby bindings for brotli library
|
2
2
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
| [![
|
3
|
+
| AppVeyor | Circle | Github actions | Codecov | Gem |
|
4
|
+
| :------: | :----: | :------------: | :-----: | :--: |
|
5
|
+
| [![AppVeyor test status](https://ci.appveyor.com/api/projects/status/github/andrew-aladev/ruby-brs?branch=master&svg=true)](https://ci.appveyor.com/project/andrew-aladev/ruby-brs/branch/master) | [![Circle test status](https://circleci.com/gh/andrew-aladev/ruby-brs/tree/master.svg?style=shield)](https://circleci.com/gh/andrew-aladev/ruby-brs/tree/master) | [![Github Actions test status](https://github.com/andrew-aladev/ruby-brs/workflows/test/badge.svg?branch=master)](https://github.com/andrew-aladev/ruby-brs/actions) | [![Codecov](https://codecov.io/gh/andrew-aladev/ruby-brs/branch/master/graph/badge.svg)](https://codecov.io/gh/andrew-aladev/ruby-brs) | [![Gem](https://img.shields.io/gem/v/ruby-brs.svg)](https://rubygems.org/gems/ruby-brs) |
|
6
6
|
|
7
7
|
See [brotli library](https://github.com/google/brotli).
|
8
8
|
|
@@ -61,7 +61,7 @@ ensure
|
|
61
61
|
end
|
62
62
|
```
|
63
63
|
|
64
|
-
You can create and read `tar.br` archives with
|
64
|
+
You can create and read `tar.br` archives with [minitar](https://github.com/halostatue/minitar).
|
65
65
|
|
66
66
|
```ruby
|
67
67
|
require "brs"
|
@@ -83,44 +83,80 @@ BRS::Stream::Reader.open "file.tar.br" do |reader|
|
|
83
83
|
end
|
84
84
|
```
|
85
85
|
|
86
|
+
You can also use `Content-Encoding: br` with [sinatra](http://sinatrarb.com):
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
require "brs"
|
90
|
+
require "sinatra"
|
91
|
+
|
92
|
+
get "/" do
|
93
|
+
headers["Content-Encoding"] = "br"
|
94
|
+
BRS::String.compress "sample string"
|
95
|
+
end
|
96
|
+
```
|
97
|
+
|
98
|
+
All functionality (including streaming) can be used inside multiple threads with [parallel](https://github.com/grosser/parallel).
|
99
|
+
This code will provide heavy load for your CPU.
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
require "brs"
|
103
|
+
require "parallel"
|
104
|
+
|
105
|
+
Parallel.each large_datas do |large_data|
|
106
|
+
BRS::String.compress large_data
|
107
|
+
end
|
108
|
+
```
|
109
|
+
|
86
110
|
## Options
|
87
111
|
|
88
|
-
| Option | Values
|
89
|
-
|
90
|
-
| `source_buffer_length` |
|
91
|
-
| `destination_buffer_length` |
|
92
|
-
| `
|
93
|
-
| `
|
94
|
-
| `
|
95
|
-
| `
|
96
|
-
| `
|
97
|
-
| `
|
98
|
-
| `
|
99
|
-
| `
|
112
|
+
| Option | Values | Default | Description |
|
113
|
+
|------------------------------------|------------|------------|-------------|
|
114
|
+
| `source_buffer_length` | 0 - inf | 0 (auto) | internal buffer length for source data |
|
115
|
+
| `destination_buffer_length` | 0 - inf | 0 (auto) | internal buffer length for description data |
|
116
|
+
| `gvl` | true/false | false | enables global VM lock where possible |
|
117
|
+
| `mode` | `MODES` | `:generic` | compressor mode |
|
118
|
+
| `quality` | 0 - 11 | 11 | compression level |
|
119
|
+
| `lgwin` | 10 - 24 | 22 | compressor window size |
|
120
|
+
| `lgblock` | 16 - 24 | nil (auto) | compressor input block size |
|
121
|
+
| `npostfix` | 0 - 3 | nil (auto) | Recommended number of postfix bits |
|
122
|
+
| `ndirect` | 0 - 120 | nil (auto) | Recommended number of direct distance codes (step 1 << npostfix, max 15 << npostfix) |
|
123
|
+
| `disable_literal_context_modeling` | true/false | false | disables literal context modeling format |
|
124
|
+
| `disable_ring_buffer_reallocation` | true/false | false | disables ring buffer reallocation |
|
125
|
+
| `size_hint` | 0 - inf | 0 (auto) | size of input (if known) |
|
126
|
+
| `large_window` | true/false | false | enables large window |
|
100
127
|
|
101
128
|
There are internal buffers for compressed and decompressed data.
|
102
129
|
For example you want to use 1 KB as `source_buffer_length` for compressor - please use 256 B as `destination_buffer_length`.
|
103
130
|
You want to use 256 B as `source_buffer_length` for decompressor - please use 1 KB as `destination_buffer_length`.
|
104
131
|
|
132
|
+
`gvl` is disabled by default, this mode allows running multiple compressors/decompressors in different threads simultaneously.
|
133
|
+
Please consider enabling `gvl` if you don't want to launch processors in separate threads.
|
134
|
+
If `gvl` is enabled ruby won't waste time on acquiring/releasing VM lock.
|
135
|
+
|
105
136
|
`String` and `File` will set `:size_hint` automaticaly.
|
106
137
|
|
107
138
|
You can also read brotli docs for more info about options.
|
108
139
|
|
109
|
-
| Option
|
110
|
-
|
111
|
-
| `mode`
|
112
|
-
| `quality`
|
113
|
-
| `lgwin`
|
114
|
-
| `lgblock`
|
140
|
+
| Option | Related constants |
|
141
|
+
|------------|-------------------|
|
142
|
+
| `mode` | `BRS::Option::MODES` = `%i[text font generic]` |
|
143
|
+
| `quality` | `BRS::Option::MIN_QUALITY` = 0, `BRS::Option::MAX_QUALITY` = 11 |
|
144
|
+
| `lgwin` | `BRS::Option::MIN_LGWIN` = 10, `BRS::Option::MAX_LGWIN` = 24 |
|
145
|
+
| `lgblock` | `BRS::Option::MIN_LGBLOCK` = 16, `BRS::Option::MAX_LGBLOCK` = 24 |
|
146
|
+
| `npostfix` | `BRS::Option::MIN_NPOSTFIX` = 0, `BRS::Option::MAX_NPOSTFIX` = 3 |
|
147
|
+
| `ndirect` | `BRS::Option::MIN_NDIRECT` = 0, `BRS::Option::MAX_NDIRECT` = 120, `BRS::Option::NDIRECT_NPOSTFIX_STEP_BASE` = 1, `BRS::Option::NDIRECT_NPOSTFIX_MAX_BASE` = 15 |
|
115
148
|
|
116
149
|
Possible compressor options:
|
117
150
|
```
|
118
151
|
:source_buffer_length
|
119
152
|
:destination_buffer_length
|
153
|
+
:gvl
|
120
154
|
:mode
|
121
155
|
:quality
|
122
156
|
:lgwin
|
123
157
|
:lgblock
|
158
|
+
:npostfix
|
159
|
+
:ndirect
|
124
160
|
:disable_literal_context_modeling
|
125
161
|
:size_hint
|
126
162
|
:large_window
|
@@ -130,6 +166,7 @@ Possible decompressor options:
|
|
130
166
|
```
|
131
167
|
:source_buffer_length
|
132
168
|
:destination_buffer_length
|
169
|
+
:gvl
|
133
170
|
:disable_ring_buffer_reallocation
|
134
171
|
:large_window
|
135
172
|
```
|
@@ -143,18 +180,6 @@ data = BRS::String.compress "sample string", :quality => 5
|
|
143
180
|
puts BRS::String.decompress(data, :disable_ring_buffer_reallocation => true)
|
144
181
|
```
|
145
182
|
|
146
|
-
HTTP encoding (`Content-Encoding: br`) using default options:
|
147
|
-
|
148
|
-
```ruby
|
149
|
-
require "brs"
|
150
|
-
require "sinatra"
|
151
|
-
|
152
|
-
get "/" do
|
153
|
-
headers["Content-Encoding"] = "br"
|
154
|
-
BRS::String.compress "sample string"
|
155
|
-
end
|
156
|
-
```
|
157
|
-
|
158
183
|
## String
|
159
184
|
|
160
185
|
String maintains destination buffer only, so it accepts `destination_buffer_length` option only.
|
@@ -179,7 +204,7 @@ File maintains both source and destination buffers, it accepts both `source_buff
|
|
179
204
|
|
180
205
|
## Stream::Writer
|
181
206
|
|
182
|
-
Its behaviour is similar to builtin [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib
|
207
|
+
Its behaviour is similar to builtin [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib/libdoc/zlib/rdoc/Zlib/GzipWriter.html).
|
183
208
|
|
184
209
|
Writer maintains destination buffer only, so it accepts `destination_buffer_length` option only.
|
185
210
|
|
@@ -217,7 +242,7 @@ Set another encodings, `nil` is just for compatibility with `IO`.
|
|
217
242
|
#tell
|
218
243
|
```
|
219
244
|
|
220
|
-
See [`IO`](https://ruby-doc.org/core
|
245
|
+
See [`IO`](https://ruby-doc.org/core/IO.html) docs.
|
221
246
|
|
222
247
|
```
|
223
248
|
#write(*objects)
|
@@ -227,7 +252,7 @@ See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
|
|
227
252
|
#closed?
|
228
253
|
```
|
229
254
|
|
230
|
-
See [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib
|
255
|
+
See [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
|
231
256
|
|
232
257
|
```
|
233
258
|
#write_nonblock(object, *options)
|
@@ -241,6 +266,9 @@ Special asynchronous methods missing in `Zlib::GzipWriter`.
|
|
241
266
|
So it is possible to have asynchronous variants for these synchronous methods.
|
242
267
|
Behaviour is the same as `IO#write_nonblock` method.
|
243
268
|
|
269
|
+
All nonblock operations for file will raise `EBADF` error on Windows.
|
270
|
+
Setting file into nonblocking mode is [not available on Windows](https://github.com/ruby/ruby/blob/master/win32/win32.c#L4388).
|
271
|
+
|
244
272
|
```
|
245
273
|
#<<(object)
|
246
274
|
#print(*objects)
|
@@ -249,11 +277,11 @@ Behaviour is the same as `IO#write_nonblock` method.
|
|
249
277
|
#puts(*objects)
|
250
278
|
```
|
251
279
|
|
252
|
-
Typical helpers, see [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib
|
280
|
+
Typical helpers, see [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
|
253
281
|
|
254
282
|
## Stream::Reader
|
255
283
|
|
256
|
-
Its behaviour is similar to builtin [`Zlib::GzipReader`](https://ruby-doc.org/stdlib
|
284
|
+
Its behaviour is similar to builtin [`Zlib::GzipReader`](https://ruby-doc.org/stdlib/libdoc/zlib/rdoc/Zlib/GzipReader.html).
|
257
285
|
|
258
286
|
Reader maintains both source and destination buffers, it accepts both `source_buffer_length` and `destination_buffer_length` options.
|
259
287
|
|
@@ -288,7 +316,7 @@ Set another encodings.
|
|
288
316
|
#tell
|
289
317
|
```
|
290
318
|
|
291
|
-
See [`IO`](https://ruby-doc.org/core
|
319
|
+
See [`IO`](https://ruby-doc.org/core/IO.html) docs.
|
292
320
|
|
293
321
|
```
|
294
322
|
#read(bytes_to_read = nil, out_buffer = nil)
|
@@ -298,14 +326,14 @@ See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
|
|
298
326
|
#closed?
|
299
327
|
```
|
300
328
|
|
301
|
-
See [`Zlib::GzipReader`](https://ruby-doc.org/stdlib
|
329
|
+
See [`Zlib::GzipReader`](https://ruby-doc.org/stdlib/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
|
302
330
|
|
303
331
|
```
|
304
332
|
#readpartial(bytes_to_read = nil, out_buffer = nil)
|
305
333
|
#read_nonblock(bytes_to_read, out_buffer = nil, *options)
|
306
334
|
```
|
307
335
|
|
308
|
-
See [`IO`](https://ruby-doc.org/core
|
336
|
+
See [`IO`](https://ruby-doc.org/core/IO.html) docs.
|
309
337
|
|
310
338
|
```
|
311
339
|
#getbyte
|
@@ -328,14 +356,26 @@ See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
|
|
328
356
|
#ungetline(line)
|
329
357
|
```
|
330
358
|
|
331
|
-
Typical helpers, see [`Zlib::GzipReader`](https://ruby-doc.org/stdlib
|
359
|
+
Typical helpers, see [`Zlib::GzipReader`](https://ruby-doc.org/stdlib/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
|
360
|
+
|
361
|
+
## Thread safety
|
362
|
+
|
363
|
+
`:gvl` option is disabled by default, you can use bindings effectively in multiple threads.
|
364
|
+
Please be careful: bindings are not thread safe.
|
365
|
+
You should lock all shared data between threads.
|
366
|
+
|
367
|
+
For example: you should not use same compressor/decompressor inside multiple threads.
|
368
|
+
Please verify that you are using each processor inside single thread at the same time.
|
369
|
+
|
370
|
+
## Operating systems
|
371
|
+
|
372
|
+
GNU/Linux, FreeBSD, OSX, Windows (MinGW).
|
332
373
|
|
333
374
|
## CI
|
334
375
|
|
335
|
-
See universal test script [scripts/ci_test.sh](scripts/ci_test.sh) for CI.
|
336
376
|
Please visit [scripts/test-images](scripts/test-images).
|
337
|
-
|
377
|
+
See universal test script [scripts/ci_test.sh](scripts/ci_test.sh) for CI.
|
338
378
|
|
339
379
|
## License
|
340
380
|
|
341
|
-
MIT license, see LICENSE and AUTHORS.
|
381
|
+
MIT license, see [LICENSE](LICENSE) and [AUTHORS](AUTHORS).
|
data/ext/brs_ext/buffer.c
CHANGED
@@ -3,17 +3,16 @@
|
|
3
3
|
|
4
4
|
#include "brs_ext/buffer.h"
|
5
5
|
|
6
|
-
#include "ruby.h"
|
7
|
-
|
8
6
|
VALUE brs_ext_create_string_buffer(VALUE length)
|
9
7
|
{
|
10
8
|
return rb_str_new(NULL, NUM2SIZET(length));
|
11
9
|
}
|
12
10
|
|
13
|
-
VALUE brs_ext_resize_string_buffer(VALUE
|
11
|
+
VALUE brs_ext_resize_string_buffer(VALUE buffer_args)
|
14
12
|
{
|
15
|
-
VALUE buffer = rb_ary_entry(
|
16
|
-
VALUE length = rb_ary_entry(
|
13
|
+
VALUE buffer = rb_ary_entry(buffer_args, 0);
|
14
|
+
VALUE length = rb_ary_entry(buffer_args, 1);
|
15
|
+
|
17
16
|
return rb_str_resize(buffer, NUM2SIZET(length));
|
18
17
|
}
|
19
18
|
|
@@ -21,8 +20,21 @@ void brs_ext_buffer_exports(VALUE root_module)
|
|
21
20
|
{
|
22
21
|
VALUE module = rb_define_module_under(root_module, "Buffer");
|
23
22
|
|
24
|
-
rb_define_const(
|
25
|
-
|
26
|
-
|
27
|
-
rb_define_const(
|
23
|
+
rb_define_const(
|
24
|
+
module, "DEFAULT_SOURCE_BUFFER_LENGTH_FOR_COMPRESSOR", SIZET2NUM(BRS_DEFAULT_SOURCE_BUFFER_LENGTH_FOR_COMPRESSOR));
|
25
|
+
|
26
|
+
rb_define_const(
|
27
|
+
module,
|
28
|
+
"DEFAULT_DESTINATION_BUFFER_LENGTH_FOR_COMPRESSOR",
|
29
|
+
SIZET2NUM(BRS_DEFAULT_DESTINATION_BUFFER_LENGTH_FOR_COMPRESSOR));
|
30
|
+
|
31
|
+
rb_define_const(
|
32
|
+
module,
|
33
|
+
"DEFAULT_SOURCE_BUFFER_LENGTH_FOR_DECOMPRESSOR",
|
34
|
+
SIZET2NUM(BRS_DEFAULT_SOURCE_BUFFER_LENGTH_FOR_DECOMPRESSOR));
|
35
|
+
|
36
|
+
rb_define_const(
|
37
|
+
module,
|
38
|
+
"DEFAULT_DESTINATION_BUFFER_LENGTH_FOR_DECOMPRESSOR",
|
39
|
+
SIZET2NUM(BRS_DEFAULT_DESTINATION_BUFFER_LENGTH_FOR_DECOMPRESSOR));
|
28
40
|
}
|
data/ext/brs_ext/buffer.h
CHANGED
@@ -6,10 +6,10 @@
|
|
6
6
|
|
7
7
|
#include "ruby.h"
|
8
8
|
|
9
|
-
#define BRS_DEFAULT_SOURCE_BUFFER_LENGTH_FOR_COMPRESSOR
|
9
|
+
#define BRS_DEFAULT_SOURCE_BUFFER_LENGTH_FOR_COMPRESSOR (1 << 18) // 256 KB
|
10
10
|
#define BRS_DEFAULT_DESTINATION_BUFFER_LENGTH_FOR_COMPRESSOR (1 << 16) // 64 KB
|
11
11
|
|
12
|
-
#define BRS_DEFAULT_SOURCE_BUFFER_LENGTH_FOR_DECOMPRESSOR
|
12
|
+
#define BRS_DEFAULT_SOURCE_BUFFER_LENGTH_FOR_DECOMPRESSOR (1 << 16) // 64 KB
|
13
13
|
#define BRS_DEFAULT_DESTINATION_BUFFER_LENGTH_FOR_DECOMPRESSOR (1 << 18) // 256 KB
|
14
14
|
|
15
15
|
VALUE brs_ext_create_string_buffer(VALUE length);
|
@@ -17,12 +17,12 @@ VALUE brs_ext_create_string_buffer(VALUE length);
|
|
17
17
|
#define BRS_EXT_CREATE_STRING_BUFFER(buffer, length, exception) \
|
18
18
|
VALUE buffer = rb_protect(brs_ext_create_string_buffer, SIZET2NUM(length), &exception);
|
19
19
|
|
20
|
-
VALUE brs_ext_resize_string_buffer(VALUE
|
20
|
+
VALUE brs_ext_resize_string_buffer(VALUE buffer_args);
|
21
21
|
|
22
|
-
#define BRS_EXT_RESIZE_STRING_BUFFER(buffer, length, exception)
|
23
|
-
VALUE
|
24
|
-
buffer
|
25
|
-
RB_GC_GUARD(
|
22
|
+
#define BRS_EXT_RESIZE_STRING_BUFFER(buffer, length, exception) \
|
23
|
+
VALUE buffer_args = rb_ary_new_from_args(2, buffer, SIZET2NUM(length)); \
|
24
|
+
buffer = rb_protect(brs_ext_resize_string_buffer, buffer_args, &exception); \
|
25
|
+
RB_GC_GUARD(buffer_args);
|
26
26
|
|
27
27
|
void brs_ext_buffer_exports(VALUE root_module);
|
28
28
|
|
data/ext/brs_ext/error.c
CHANGED
@@ -3,10 +3,6 @@
|
|
3
3
|
|
4
4
|
#include "brs_ext/error.h"
|
5
5
|
|
6
|
-
#include <brotli/decode.h>
|
7
|
-
|
8
|
-
#include "ruby.h"
|
9
|
-
|
10
6
|
brs_ext_result_t brs_ext_get_decompressor_error(BrotliDecoderErrorCode error_code)
|
11
7
|
{
|
12
8
|
switch (error_code) {
|
@@ -39,7 +35,7 @@ brs_ext_result_t brs_ext_get_decompressor_error(BrotliDecoderErrorCode error_cod
|
|
39
35
|
}
|
40
36
|
}
|
41
37
|
|
42
|
-
static inline NORETURN(void
|
38
|
+
static inline NORETURN(void raise_error(const char* name, const char* description))
|
43
39
|
{
|
44
40
|
VALUE module = rb_define_module(BRS_EXT_MODULE_NAME);
|
45
41
|
VALUE error = rb_const_get(module, rb_intern(name));
|
@@ -50,28 +46,28 @@ void brs_ext_raise_error(brs_ext_result_t ext_result)
|
|
50
46
|
{
|
51
47
|
switch (ext_result) {
|
52
48
|
case BRS_EXT_ERROR_ALLOCATE_FAILED:
|
53
|
-
|
49
|
+
raise_error("AllocateError", "allocate error");
|
54
50
|
case BRS_EXT_ERROR_VALIDATE_FAILED:
|
55
|
-
|
51
|
+
raise_error("ValidateError", "validate error");
|
56
52
|
|
57
53
|
case BRS_EXT_ERROR_USED_AFTER_CLOSE:
|
58
|
-
|
54
|
+
raise_error("UsedAfterCloseError", "used after closed");
|
59
55
|
case BRS_EXT_ERROR_NOT_ENOUGH_SOURCE_BUFFER:
|
60
|
-
|
56
|
+
raise_error("NotEnoughSourceBufferError", "not enough source buffer");
|
61
57
|
case BRS_EXT_ERROR_NOT_ENOUGH_DESTINATION_BUFFER:
|
62
|
-
|
58
|
+
raise_error("NotEnoughDestinationBufferError", "not enough destination buffer");
|
63
59
|
case BRS_EXT_ERROR_DECOMPRESSOR_CORRUPTED_SOURCE:
|
64
|
-
|
60
|
+
raise_error("DecompressorCorruptedSourceError", "decompressor received corrupted source");
|
65
61
|
|
66
62
|
case BRS_EXT_ERROR_ACCESS_IO:
|
67
|
-
|
63
|
+
raise_error("AccessIOError", "failed to access IO");
|
68
64
|
case BRS_EXT_ERROR_READ_IO:
|
69
|
-
|
65
|
+
raise_error("ReadIOError", "failed to read IO");
|
70
66
|
case BRS_EXT_ERROR_WRITE_IO:
|
71
|
-
|
67
|
+
raise_error("WriteIOError", "failed to write IO");
|
72
68
|
|
73
69
|
default:
|
74
70
|
// BRS_EXT_ERROR_UNEXPECTED
|
75
|
-
|
71
|
+
raise_error("UnexpectedError", "unexpected error");
|
76
72
|
}
|
77
73
|
}
|
data/ext/brs_ext/error.h
CHANGED
data/ext/brs_ext/gvl.h
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
// Ruby bindings for brotli library.
|
2
|
+
// Copyright (c) 2019 AUTHORS, MIT License.
|
3
|
+
|
4
|
+
#if !defined(BRS_EXT_GVL_H)
|
5
|
+
#define BRS_EXT_GVL_H
|
6
|
+
|
7
|
+
#ifdef HAVE_RB_THREAD_CALL_WITHOUT_GVL
|
8
|
+
|
9
|
+
#include "ruby/thread.h"
|
10
|
+
|
11
|
+
#define BRS_EXT_GVL_WRAP(gvl, function, data) \
|
12
|
+
if (gvl) { \
|
13
|
+
function((void*) data); \
|
14
|
+
} else { \
|
15
|
+
rb_thread_call_without_gvl(function, (void*) data, RUBY_UBF_IO, NULL); \
|
16
|
+
}
|
17
|
+
|
18
|
+
#else
|
19
|
+
|
20
|
+
#define BRS_EXT_GVL_WRAP(_gvl, function, data) function((void*) data);
|
21
|
+
|
22
|
+
#endif
|
23
|
+
|
24
|
+
#endif // BRS_EXT_GVL_H
|