ruby-lzws 1.1.5 → 1.3.1

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: a57fe20aab5886c14c0891ae6d61992532bb93a39a3ac3bac615d274666b9cee
4
- data.tar.gz: '09fe72cfbf5aa061849efcbb3b73148dcb4481ccf9284544cbb74c2ee20de88d'
3
+ metadata.gz: 72fd9e1b55088bd5ba7a6d57edc857322ede1d9764b6b2eb3aeafe85193605ad
4
+ data.tar.gz: 2f08eb4371bef83f138233ab62a5a54b5fa01f5a2904d6d1f64ee00fb9aebd1c
5
5
  SHA512:
6
- metadata.gz: 0c54fcae56fd3316e5a5ef3a84d381bc9a0c878c4f37a3b012a01cda98de8a8580809cfe03b81614260ba2518833aa691db6180a49862d0f41954f391ca8b1f2
7
- data.tar.gz: 640e27b7c541376b0c816158749dda2b7f40926c0b773d48255135be98261f3110ed75711b7ee648d1ea1f316aaf4a951068d89eebc672b45e75013f993d4320
6
+ metadata.gz: beff1dd2f2016bb9660f26bd62f3eaf1fdab8af9e70c24a65bfda4090190c4c02ef66ff943346b9483f5b588ceff6b5964f33d32dfc15e017b3e7964877ce7f9
7
+ data.tar.gz: a5c0074902b21193725bb0f215cef8ebaad55b3a029e20d0d0b54c0382e527a86c3460feca7a36ed7754b96254497eacb4a08900a425c7bfda70fa44153e60b6
data/README.md CHANGED
@@ -1,14 +1,14 @@
1
1
  # Ruby bindings for lzws library
2
2
 
3
- | Travis | AppVeyor | Cirrus | Circle | Codecov |
4
- | :---: | :---: | :---: | :---: | :---: |
5
- | [![Travis test status](https://travis-ci.com/andrew-aladev/ruby-lzws.svg?branch=master)](https://travis-ci.com/andrew-aladev/ruby-lzws) | [![AppVeyor test status](https://ci.appveyor.com/api/projects/status/github/andrew-aladev/ruby-lzws?branch=master&svg=true)](https://ci.appveyor.com/project/andrew-aladev/ruby-lzws/branch/master) | [![Cirrus test status](https://api.cirrus-ci.com/github/andrew-aladev/ruby-lzws.svg?branch=master)](https://cirrus-ci.com/github/andrew-aladev/ruby-lzws) | [![Circle test status](https://circleci.com/gh/andrew-aladev/ruby-lzws/tree/master.svg?style=shield)](https://circleci.com/gh/andrew-aladev/ruby-lzws/tree/master) | [![Codecov](https://codecov.io/gh/andrew-aladev/ruby-lzws/branch/master/graph/badge.svg)](https://codecov.io/gh/andrew-aladev/ruby-lzws) |
3
+ | AppVeyor | Circle | Github actions | Codecov | Gem |
4
+ | :------: | :----: | :------------: | :-----: | :--: |
5
+ | [![AppVeyor test status](https://ci.appveyor.com/api/projects/status/github/andrew-aladev/ruby-lzws?branch=master&svg=true)](https://ci.appveyor.com/project/andrew-aladev/ruby-lzws/branch/master) | [![Circle test status](https://circleci.com/gh/andrew-aladev/ruby-lzws/tree/master.svg?style=shield)](https://circleci.com/gh/andrew-aladev/ruby-lzws/tree/master) | [![Github Actions test status](https://github.com/andrew-aladev/ruby-lzws/workflows/test/badge.svg?branch=master)](https://github.com/andrew-aladev/ruby-lzws/actions) | [![Codecov](https://codecov.io/gh/andrew-aladev/ruby-lzws/branch/master/graph/badge.svg)](https://codecov.io/gh/andrew-aladev/ruby-lzws) | [![Gem](https://img.shields.io/gem/v/ruby-lzws.svg)](https://rubygems.org/gems/ruby-lzws) |
6
6
 
7
7
  See [lzws library](https://github.com/andrew-aladev/lzws).
8
8
 
9
9
  ## Installation
10
10
 
11
- Please install lzws library first, use latest 1.3.0+ version.
11
+ Please install lzws library first, use latest 1.4.0+ version.
12
12
 
13
13
  ```sh
14
14
  gem install ruby-lzws
@@ -21,6 +21,8 @@ rake gem
21
21
  gem install pkg/ruby-lzws-*.gem
22
22
  ```
23
23
 
24
+ You can also use [overlay](https://github.com/andrew-aladev/overlay) for gentoo.
25
+
24
26
  ## Usage
25
27
 
26
28
  There are simple APIs: `String` and `File`. Also you can use generic streaming API: `Stream::Writer` and `Stream::Reader`.
@@ -59,8 +61,8 @@ ensure
59
61
  end
60
62
  ```
61
63
 
62
- You can create and read `tar.Z` archives with `minitar` for example.
63
- LZWS is compatible with UNIX compress (with default options).
64
+ You can create and read `tar.Z` archives with [minitar](https://github.com/halostatue/minitar).
65
+ LZWS is compatible with [UNIX compress](https://en.wikipedia.org/wiki/Compress) (with default options).
64
66
 
65
67
  ```ruby
66
68
  require "lzws"
@@ -82,66 +84,63 @@ LZWS::Stream::Reader.open "file.tar.Z" do |reader|
82
84
  end
83
85
  ```
84
86
 
85
- ## Options
86
-
87
- Each API supports several options:
88
-
89
- ```
90
- :source_buffer_length
91
- :destination_buffer_length
92
- ```
93
-
94
- There are internal buffers for compressed and decompressed data.
95
- For example you want to use 1 KB as source buffer length for compressor - please use 256 B as destination buffer length.
96
- You want to use 256 B as source buffer length for decompressor - please use 1 KB as destination buffer length.
97
-
98
- Values: 0, 2 - infinity, default value: 0.
99
- 0 means automatic buffer length selection.
100
- 1 byte is not enough, 2 bytes is minimal buffer length.
101
-
102
- ```
103
- :max_code_bit_length
104
- ```
87
+ You can also use `Content-Encoding: compress` with [sinatra](http://sinatrarb.com):
105
88
 
106
- Values: `LZWS::Option::LOWEST_MAX_CODE_BIT_LENGTH` - `LZWS::Option::BIGGEST_MAX_CODE_BIT_LENGTH`, default value: `LZWS::Option::BIGGEST_MAX_CODE_BIT_LENGTH`.
89
+ ```ruby
90
+ require "lzws"
91
+ require "sinatra"
107
92
 
108
- ```
109
- :block_mode
93
+ get "/" do
94
+ headers["Content-Encoding"] = "compress"
95
+ LZWS::String.compress "TOBEORNOTTOBEORTOBEORNOT"
96
+ end
110
97
  ```
111
98
 
112
- Values: true/false, default value: true.
99
+ All functionality (including streaming) can be used inside multiple threads with [parallel](https://github.com/grosser/parallel).
100
+ This code will provide heavy load for your CPU.
113
101
 
114
- ```
115
- :without_magic_header
116
- ```
117
-
118
- Values: true/false, default value: false.
102
+ ```ruby
103
+ require "lzws"
104
+ require "parallel"
119
105
 
120
- ```
121
- :msb
106
+ Parallel.each large_datas do |large_data|
107
+ LZWS::String.compress large_data
108
+ end
122
109
  ```
123
110
 
124
- Values: true/false, default value: false.
111
+ ## Options
125
112
 
126
- ```
127
- :unaligned_bit_groups
128
- ```
113
+ | Option | Values | Default | Description |
114
+ |-----------------------------|------------|----------|-------------|
115
+ | `source_buffer_length` | 0, 2 - inf | 0 (auto) | internal buffer length for source data |
116
+ | `destination_buffer_length` | 0, 2 - inf | 0 (auto) | internal buffer length for description data |
117
+ | `gvl` | true/false | false | enables global VM lock where possible |
118
+ | `max_code_bit_length` | 9 - 16 | 16 | max code bit length |
119
+ | `block_mode` | true/false | true | enables block mode |
120
+ | `without_magic_header` | true/false | false | disables magic header |
121
+ | `msb` | true/false | false | enables most significant bit mode |
122
+ | `unaligned_bit_groups` | true/false | false | enables unaligned bit groups |
123
+ | `quiet` | true/false | false | disables lzws library logging |
129
124
 
130
- Values: true/false, default value: false.
125
+ There are internal buffers for compressed and decompressed data.
126
+ For example you want to use 1 KB as `source_buffer_length` for compressor - please use 256 B as `destination_buffer_length`.
127
+ You want to use 256 B as `source_buffer_length` for decompressor - please use 1 KB as `destination_buffer_length`.
131
128
 
132
- ```
133
- :quiet
134
- ```
129
+ `gvl` is disabled by default, this mode allows running multiple compressors/decompressors in different threads simultaneously.
130
+ Please consider enabling `gvl` if you don't want to launch processors in separate threads.
131
+ If `gvl` is enabled ruby won't waste time on acquiring/releasing VM lock.
135
132
 
136
- Values: true/false, default value: false.
137
- Disables lzws library logging.
133
+ You can also read lzws docs for more info about options.
138
134
 
139
- Please read lzws docs for more info about options.
135
+ | Option | Related constants |
136
+ |-----------------------|-------------------|
137
+ | `max_code_bit_length` | `LZWS::Option::LOWEST_MAX_CODE_BIT_LENGTH` = 9, `LZWS::Option::BIGGEST_MAX_CODE_BIT_LENGTH` = 16 |
140
138
 
141
139
  Possible compressor options:
142
140
  ```
143
141
  :source_buffer_length
144
142
  :destination_buffer_length
143
+ :gvl
145
144
  :max_code_bit_length
146
145
  :block_mode
147
146
  :without_magic_header
@@ -154,6 +153,7 @@ Possible decompressor options:
154
153
  ```
155
154
  :source_buffer_length
156
155
  :destination_buffer_length
156
+ :gvl
157
157
  :without_magic_header
158
158
  :msb
159
159
  :unaligned_bit_groups
@@ -169,18 +169,6 @@ data = LZWS::String.compress "TOBEORNOTTOBEORTOBEORNOT", :msb => true
169
169
  puts LZWS::String.decompress(data, :msb => true)
170
170
  ```
171
171
 
172
- Default options are compatible with UNIX compress (`Content-Encoding: compress`):
173
-
174
- ```ruby
175
- require "lzws"
176
- require "sinatra"
177
-
178
- get "/" do
179
- headers["Content-Encoding"] = "compress"
180
- LZWS::String.compress "TOBEORNOTTOBEORTOBEORNOT"
181
- end
182
- ```
183
-
184
172
  Please read more about compatibility in lzws docs.
185
173
 
186
174
  ## String
@@ -207,7 +195,7 @@ File maintains both source and destination buffers, it accepts both `source_buff
207
195
 
208
196
  ## Stream::Writer
209
197
 
210
- Its behaviour is similar to builtin [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipWriter.html).
198
+ Its behaviour is similar to builtin [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib/libdoc/zlib/rdoc/Zlib/GzipWriter.html).
211
199
 
212
200
  Writer maintains destination buffer only, so it accepts `destination_buffer_length` option only.
213
201
 
@@ -241,7 +229,7 @@ Set another encodings, `nil` is just for compatibility with `IO`.
241
229
  #tell
242
230
  ```
243
231
 
244
- See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
232
+ See [`IO`](https://ruby-doc.org/core/IO.html) docs.
245
233
 
246
234
  ```
247
235
  #write(*objects)
@@ -251,7 +239,7 @@ See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
251
239
  #closed?
252
240
  ```
253
241
 
254
- See [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
242
+ See [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
255
243
 
256
244
  ```
257
245
  #write_nonblock(object, *options)
@@ -265,6 +253,9 @@ Special asynchronous methods missing in `Zlib::GzipWriter`.
265
253
  So it is possible to have asynchronous variants for these synchronous methods.
266
254
  Behaviour is the same as `IO#write_nonblock` method.
267
255
 
256
+ All nonblock operations for file will raise `EBADF` error on Windows.
257
+ Setting file into nonblocking mode is [not available on Windows](https://github.com/ruby/ruby/blob/master/win32/win32.c#L4388).
258
+
268
259
  ```
269
260
  #<<(object)
270
261
  #print(*objects)
@@ -273,11 +264,11 @@ Behaviour is the same as `IO#write_nonblock` method.
273
264
  #puts(*objects)
274
265
  ```
275
266
 
276
- Typical helpers, see [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
267
+ Typical helpers, see [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
277
268
 
278
269
  ## Stream::Reader
279
270
 
280
- Its behaviour is similar to builtin [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipReader.html).
271
+ Its behaviour is similar to builtin [`Zlib::GzipReader`](https://ruby-doc.org/stdlib/libdoc/zlib/rdoc/Zlib/GzipReader.html).
281
272
 
282
273
  Reader maintains both source and destination buffers, it accepts both `source_buffer_length` and `destination_buffer_length` options.
283
274
 
@@ -312,7 +303,7 @@ Set another encodings.
312
303
  #tell
313
304
  ```
314
305
 
315
- See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
306
+ See [`IO`](https://ruby-doc.org/core/IO.html) docs.
316
307
 
317
308
  ```
318
309
  #read(bytes_to_read = nil, out_buffer = nil)
@@ -322,14 +313,14 @@ See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
322
313
  #closed?
323
314
  ```
324
315
 
325
- See [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
316
+ See [`Zlib::GzipReader`](https://ruby-doc.org/stdlib/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
326
317
 
327
318
  ```
328
319
  #readpartial(bytes_to_read = nil, out_buffer = nil)
329
320
  #read_nonblock(bytes_to_read, out_buffer = nil, *options)
330
321
  ```
331
322
 
332
- See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
323
+ See [`IO`](https://ruby-doc.org/core/IO.html) docs.
333
324
 
334
325
  ```
335
326
  #getbyte
@@ -352,16 +343,26 @@ See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
352
343
  #ungetline(line)
353
344
  ```
354
345
 
355
- Typical helpers, see [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
346
+ Typical helpers, see [`Zlib::GzipReader`](https://ruby-doc.org/stdlib/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
347
+
348
+ ## Thread safety
349
+
350
+ `:gvl` option is disabled by default, you can use bindings effectively in multiple threads.
351
+ Please be careful: bindings are not thread safe.
352
+ You should lock all shared data between threads.
353
+
354
+ For example: you should not use same compressor/decompressor inside multiple threads.
355
+ Please verify that you are using each processor inside single thread at the same time.
356
+
357
+ ## Operating systems
358
+
359
+ GNU/Linux, FreeBSD, OSX, Windows (MinGW).
356
360
 
357
361
  ## CI
358
362
 
359
- See universal test script [scripts/ci_test.sh](scripts/ci_test.sh) for CI.
360
363
  Please visit [scripts/test-images](scripts/test-images).
361
- You can run this test script using many native and cross images.
362
-
363
- Cirrus CI uses `x86_64-pc-linux-gnu` image, Circle CI - `x86_64-gentoo-linux-musl` image.
364
+ See universal test script [scripts/ci_test.sh](scripts/ci_test.sh) for CI.
364
365
 
365
366
  ## License
366
367
 
367
- MIT license, see LICENSE and AUTHORS.
368
+ MIT license, see [LICENSE](LICENSE) and [AUTHORS](AUTHORS).
data/ext/extconf.rb CHANGED
@@ -3,6 +3,8 @@
3
3
 
4
4
  require "mkmf"
5
5
 
6
+ have_func "rb_thread_call_without_gvl", "ruby/thread.h"
7
+
6
8
  def require_header(name, types = [])
7
9
  abort "Can't find #{name} header" unless find_header name
8
10
 
@@ -13,10 +15,10 @@ end
13
15
 
14
16
  require_header "lzws/buffer.h"
15
17
  require_header "lzws/common.h", %w[lzws_result_t]
16
- require_header "lzws/compressor/common.h"
18
+ require_header "lzws/compressor/common.h", %w[lzws_compressor_options_t]
17
19
  require_header "lzws/compressor/main.h"
18
20
  require_header "lzws/compressor/state.h", %w[lzws_compressor_state_t]
19
- require_header "lzws/decompressor/common.h"
21
+ require_header "lzws/decompressor/common.h", %w[lzws_decompressor_options_t]
20
22
  require_header "lzws/decompressor/main.h"
21
23
  require_header "lzws/decompressor/state.h", %w[lzws_decompressor_state_t]
22
24
  require_header "lzws/file.h"
@@ -66,7 +68,14 @@ $srcs = %w[
66
68
  .map { |name| "src/#{extension_name}/#{name}.c" }
67
69
  .freeze
68
70
 
69
- if ENV["CI"] || ENV["COVERAGE"]
71
+ # Removing library duplicates.
72
+ $libs = $libs.split(%r{\s})
73
+ .reject(&:empty?)
74
+ .sort
75
+ .uniq
76
+ .join " "
77
+
78
+ if ENV["CI"]
70
79
  $CFLAGS << " --coverage"
71
80
  $LDFLAGS << " --coverage"
72
81
  end
@@ -12,10 +12,11 @@ VALUE lzws_ext_create_string_buffer(VALUE length)
12
12
  return rb_str_new(NULL, NUM2SIZET(length));
13
13
  }
14
14
 
15
- VALUE lzws_ext_resize_string_buffer(VALUE args)
15
+ VALUE lzws_ext_resize_string_buffer(VALUE buffer_args)
16
16
  {
17
- VALUE buffer = rb_ary_entry(args, 0);
18
- VALUE length = rb_ary_entry(args, 1);
17
+ VALUE buffer = rb_ary_entry(buffer_args, 0);
18
+ VALUE length = rb_ary_entry(buffer_args, 1);
19
+
19
20
  return rb_str_resize(buffer, NUM2SIZET(length));
20
21
  }
21
22
 
@@ -23,8 +24,21 @@ void lzws_ext_buffer_exports(VALUE root_module)
23
24
  {
24
25
  VALUE module = rb_define_module_under(root_module, "Buffer");
25
26
 
26
- rb_define_const(module, "DEFAULT_SOURCE_BUFFER_LENGTH_FOR_COMPRESSOR", SIZET2NUM(LZWS_DEFAULT_SOURCE_BUFFER_LENGTH_FOR_COMPRESSOR));
27
- rb_define_const(module, "DEFAULT_DESTINATION_BUFFER_LENGTH_FOR_COMPRESSOR", SIZET2NUM(LZWS_DEFAULT_DESTINATION_BUFFER_LENGTH_FOR_COMPRESSOR));
28
- rb_define_const(module, "DEFAULT_SOURCE_BUFFER_LENGTH_FOR_DECOMPRESSOR", SIZET2NUM(LZWS_DEFAULT_SOURCE_BUFFER_LENGTH_FOR_DECOMPRESSOR));
29
- rb_define_const(module, "DEFAULT_DESTINATION_BUFFER_LENGTH_FOR_DECOMPRESSOR", SIZET2NUM(LZWS_DEFAULT_DESTINATION_BUFFER_LENGTH_FOR_DECOMPRESSOR));
27
+ rb_define_const(
28
+ module, "DEFAULT_SOURCE_BUFFER_LENGTH_FOR_COMPRESSOR", SIZET2NUM(LZWS_DEFAULT_SOURCE_BUFFER_LENGTH_FOR_COMPRESSOR));
29
+
30
+ rb_define_const(
31
+ module,
32
+ "DEFAULT_DESTINATION_BUFFER_LENGTH_FOR_COMPRESSOR",
33
+ SIZET2NUM(LZWS_DEFAULT_DESTINATION_BUFFER_LENGTH_FOR_COMPRESSOR));
34
+
35
+ rb_define_const(
36
+ module,
37
+ "DEFAULT_SOURCE_BUFFER_LENGTH_FOR_DECOMPRESSOR",
38
+ SIZET2NUM(LZWS_DEFAULT_SOURCE_BUFFER_LENGTH_FOR_DECOMPRESSOR));
39
+
40
+ rb_define_const(
41
+ module,
42
+ "DEFAULT_DESTINATION_BUFFER_LENGTH_FOR_DECOMPRESSOR",
43
+ SIZET2NUM(LZWS_DEFAULT_DESTINATION_BUFFER_LENGTH_FOR_DECOMPRESSOR));
30
44
  }
@@ -11,12 +11,12 @@ VALUE lzws_ext_create_string_buffer(VALUE length);
11
11
  #define LZWS_EXT_CREATE_STRING_BUFFER(buffer, length, exception) \
12
12
  VALUE buffer = rb_protect(lzws_ext_create_string_buffer, SIZET2NUM(length), &exception);
13
13
 
14
- VALUE lzws_ext_resize_string_buffer(VALUE args);
14
+ VALUE lzws_ext_resize_string_buffer(VALUE buffer_args);
15
15
 
16
- #define LZWS_EXT_RESIZE_STRING_BUFFER(buffer, length, exception) \
17
- VALUE args = rb_ary_new_from_args(2, buffer, SIZET2NUM(length)); \
18
- buffer = rb_protect(lzws_ext_resize_string_buffer, args, &exception); \
19
- RB_GC_GUARD(args);
16
+ #define LZWS_EXT_RESIZE_STRING_BUFFER(buffer, length, exception) \
17
+ VALUE buffer_args = rb_ary_new_from_args(2, buffer, SIZET2NUM(length)); \
18
+ buffer = rb_protect(lzws_ext_resize_string_buffer, buffer_args, &exception); \
19
+ RB_GC_GUARD(buffer_args);
20
20
 
21
21
  void lzws_ext_buffer_exports(VALUE root_module);
22
22
 
data/ext/lzws_ext/error.c CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  #include "ruby.h"
7
7
 
8
- static inline NORETURN(void raise(const char* name, const char* description))
8
+ static inline NORETURN(void raise_error(const char* name, const char* description))
9
9
  {
10
10
  VALUE module = rb_define_module(LZWS_EXT_MODULE_NAME);
11
11
  VALUE error = rb_const_get(module, rb_intern(name));
@@ -16,28 +16,28 @@ void lzws_ext_raise_error(lzws_ext_result_t ext_result)
16
16
  {
17
17
  switch (ext_result) {
18
18
  case LZWS_EXT_ERROR_ALLOCATE_FAILED:
19
- raise("AllocateError", "allocate error");
19
+ raise_error("AllocateError", "allocate error");
20
20
  case LZWS_EXT_ERROR_VALIDATE_FAILED:
21
- raise("ValidateError", "validate error");
21
+ raise_error("ValidateError", "validate error");
22
22
 
23
23
  case LZWS_EXT_ERROR_USED_AFTER_CLOSE:
24
- raise("UsedAfterCloseError", "used after closed");
24
+ raise_error("UsedAfterCloseError", "used after closed");
25
25
  case LZWS_EXT_ERROR_NOT_ENOUGH_SOURCE_BUFFER:
26
- raise("NotEnoughSourceBufferError", "not enough source buffer");
26
+ raise_error("NotEnoughSourceBufferError", "not enough source buffer");
27
27
  case LZWS_EXT_ERROR_NOT_ENOUGH_DESTINATION_BUFFER:
28
- raise("NotEnoughDestinationBufferError", "not enough destination buffer");
28
+ raise_error("NotEnoughDestinationBufferError", "not enough destination buffer");
29
29
  case LZWS_EXT_ERROR_DECOMPRESSOR_CORRUPTED_SOURCE:
30
- raise("DecompressorCorruptedSourceError", "decompressor received corrupted source");
30
+ raise_error("DecompressorCorruptedSourceError", "decompressor received corrupted source");
31
31
 
32
32
  case LZWS_EXT_ERROR_ACCESS_IO:
33
- raise("AccessIOError", "failed to access IO");
33
+ raise_error("AccessIOError", "failed to access IO");
34
34
  case LZWS_EXT_ERROR_READ_IO:
35
- raise("ReadIOError", "failed to read IO");
35
+ raise_error("ReadIOError", "failed to read IO");
36
36
  case LZWS_EXT_ERROR_WRITE_IO:
37
- raise("WriteIOError", "failed to write IO");
37
+ raise_error("WriteIOError", "failed to write IO");
38
38
 
39
39
  default:
40
40
  // LZWS_EXT_ERROR_UNEXPECTED
41
- raise("UnexpectedError", "unexpected error");
41
+ raise_error("UnexpectedError", "unexpected error");
42
42
  }
43
43
  }
data/ext/lzws_ext/error.h CHANGED
@@ -9,7 +9,8 @@
9
9
 
10
10
  // Results for errors listed in "lib/lzws/error" used in c extension.
11
11
 
12
- enum {
12
+ enum
13
+ {
13
14
  LZWS_EXT_ERROR_ALLOCATE_FAILED = 1,
14
15
  LZWS_EXT_ERROR_VALIDATE_FAILED,
15
16
 
@@ -0,0 +1,24 @@
1
+ // Ruby bindings for lzws library.
2
+ // Copyright (c) 2019 AUTHORS, MIT License.
3
+
4
+ #if !defined(LZWS_EXT_GVL_H)
5
+ #define LZWS_EXT_GVL_H
6
+
7
+ #ifdef HAVE_RB_THREAD_CALL_WITHOUT_GVL
8
+
9
+ #include "ruby/thread.h"
10
+
11
+ #define LZWS_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 LZWS_EXT_GVL_WRAP(_gvl, function, data) function((void*) data);
21
+
22
+ #endif
23
+
24
+ #endif // LZWS_EXT_GVL_H