ruby-lzws 1.1.0 → 1.1.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: '08551ca534634f131621d9bea42ec6d06bf7b1be6f3f7f3cb33bd11f9744ec1a'
4
- data.tar.gz: db0b8c35c381df919bb9b21b9064abd4d88bdc28a82cdead9365f97c4e698b96
3
+ metadata.gz: c705cd3581e745a96ee58e79c8b9b9ca69a55294d499db00ed5a073be0efa42b
4
+ data.tar.gz: 4925c44f35575a3be67419285b0ca911e6f10e74d52c63c42f9277a249de9a01
5
5
  SHA512:
6
- metadata.gz: 0063ee032bf5b6cac9d7e16e696e235c18acec9a6ae48a66c5516906ca290b1c30fb6a0867d371b7b2404706a7523130e00e3b7bb17c1484017a0862a0c7c03f
7
- data.tar.gz: eb1905eb2a128c716ffec1693b5be4ce94fb52894ea60adcb446ae03cc3263d8b51b62092e7e164085e875dac752a328b110c68bfdcfc631356d294ec3c50bd6
6
+ metadata.gz: f879b4d19f3de43d0304a6e70ce86c262b4d0085e2f3f7d101308a80785ccd808d1240372a85f8f49929526566682824f28c61b90bb0b9a1649e75c6726dabae
7
+ data.tar.gz: f2bbb94977b0eecb1e00a3bf655b4dcf08d428b256bebebcb95b37e9da7bf135a9958e7f38f6a0fe2ce5abdfb9bf413e0a3864e1ade7885102726a1541c884ed
data/README.md CHANGED
@@ -1,13 +1,14 @@
1
1
  # Ruby bindings for lzws library
2
2
 
3
- [![Travis build status](https://travis-ci.org/andrew-aladev/ruby-lzws.svg?branch=master)](https://travis-ci.org/andrew-aladev/ruby-lzws)
4
- [![AppVeyor build 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)
3
+ | Travis | AppVeyor | Cirrus | Circle |
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) |
5
6
 
6
7
  See [lzws library](https://github.com/andrew-aladev/lzws).
7
8
 
8
9
  ## Installation
9
10
 
10
- Please install lzws library first.
11
+ Please install lzws library first, use latest 1.3.0+ version.
11
12
 
12
13
  ```sh
13
14
  gem install ruby-lzws
@@ -81,7 +82,7 @@ Values: 0, 2 - infinity, default value: 0.
81
82
  :max_code_bit_length
82
83
  ```
83
84
 
84
- Values: 9 - 16, default value: 16.
85
+ Values: `LZWS::Option::LOWEST_MAX_CODE_BIT_LENGTH` - `LZWS::Option::BIGGEST_MAX_CODE_BIT_LENGTH`, default value: `LZWS::Option::BIGGEST_MAX_CODE_BIT_LENGTH`.
85
86
 
86
87
  ```
87
88
  :block_mode
@@ -332,6 +333,12 @@ See [`IO`](https://ruby-doc.org/core-2.6.1/IO.html) docs.
332
333
 
333
334
  Typical helpers, see [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.6.1/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
334
335
 
336
+ ## CI
337
+
338
+ Travis and Appveyor CI uses [scripts/ci_test.sh](scripts/ci_test.sh) directly.
339
+ Cirrus and Circle CI uses prebuilt [scripts/test-images](scripts/test-images).
340
+ Cirrus CI uses amd64 image, Circle CI - i686.
341
+
335
342
  ## License
336
343
 
337
344
  MIT license, see LICENSE and AUTHORS.
data/ext/extconf.rb CHANGED
@@ -3,51 +3,57 @@
3
3
 
4
4
  require "mkmf"
5
5
 
6
- def require_header(name)
6
+ def require_header(name, types = [])
7
7
  abort "Can't find #{name} header" unless find_header name
8
+
9
+ types.each do |type|
10
+ abort "Can't find #{type} type in #{name} header" unless find_type type, nil, name
11
+ end
8
12
  end
9
13
 
10
14
  require_header "lzws/buffer.h"
15
+ require_header "lzws/common.h", %w[lzws_result_t]
11
16
  require_header "lzws/compressor/common.h"
12
17
  require_header "lzws/compressor/main.h"
13
- require_header "lzws/compressor/state.h"
18
+ require_header "lzws/compressor/state.h", %w[lzws_compressor_state_t]
14
19
  require_header "lzws/decompressor/common.h"
15
20
  require_header "lzws/decompressor/main.h"
16
- require_header "lzws/decompressor/state.h"
21
+ require_header "lzws/decompressor/state.h", %w[lzws_decompressor_state_t]
17
22
  require_header "lzws/file.h"
18
23
 
19
24
  def require_library(name, functions)
20
25
  functions.each do |function|
21
- abort "Can't find #{name} library and #{function} function" unless find_library name, function
26
+ abort "Can't find #{function} function in #{name} library" unless find_library name, function
22
27
  end
23
28
  end
24
29
 
25
- functions = %w[
26
- lzws_create_source_buffer_for_compressor
27
- lzws_create_destination_buffer_for_compressor
28
- lzws_create_source_buffer_for_decompressor
29
- lzws_create_destination_buffer_for_decompressor
30
+ require_library(
31
+ "lzws",
32
+ %w[
33
+ lzws_create_source_buffer_for_compressor
34
+ lzws_create_destination_buffer_for_compressor
35
+ lzws_create_source_buffer_for_decompressor
36
+ lzws_create_destination_buffer_for_decompressor
30
37
 
31
- lzws_compressor_get_initial_state
32
- lzws_compressor_free_state
33
- lzws_compress
34
- lzws_compressor_finish
38
+ lzws_compressor_get_initial_state
39
+ lzws_compressor_free_state
40
+ lzws_compress
41
+ lzws_compressor_finish
35
42
 
36
- lzws_decompressor_get_initial_state
37
- lzws_decompressor_free_state
38
- lzws_decompress
39
-
40
- lzws_compress_file
41
- lzws_decompress_file
42
- ]
43
- .freeze
43
+ lzws_decompressor_get_initial_state
44
+ lzws_decompressor_free_state
45
+ lzws_decompress
44
46
 
45
- require_library "lzws", functions
47
+ lzws_compress_file
48
+ lzws_decompress_file
49
+ ]
50
+ )
46
51
 
47
52
  extension_name = "lzws_ext".freeze
48
53
  dir_config extension_name
49
54
 
50
- sources = %w[
55
+ # rubocop:disable Style/GlobalVars
56
+ $srcs = %w[
51
57
  stream/compressor
52
58
  stream/decompressor
53
59
  buffer
@@ -57,13 +63,9 @@ sources = %w[
57
63
  option
58
64
  string
59
65
  ]
66
+ .map { |name| "src/#{extension_name}/#{name}.c" }
60
67
  .freeze
61
68
 
62
- # rubocop:disable Style/GlobalVars
63
- $srcs = sources
64
- .map { |name| "src/#{extension_name}/#{name}.c" }
65
- .freeze
66
-
67
69
  $CFLAGS << " -Wno-declaration-after-statement"
68
70
  $VPATH << "$(srcdir)/#{extension_name}:$(srcdir)/#{extension_name}/stream"
69
71
  # rubocop:enable Style/GlobalVars
@@ -7,12 +7,24 @@
7
7
 
8
8
  #include "ruby.h"
9
9
 
10
+ VALUE lzws_ext_create_string_buffer(VALUE length)
11
+ {
12
+ return rb_str_new(NULL, NUM2SIZET(length));
13
+ }
14
+
15
+ VALUE lzws_ext_resize_string_buffer(VALUE args)
16
+ {
17
+ VALUE buffer = rb_ary_entry(args, 0);
18
+ VALUE length = rb_ary_entry(args, 1);
19
+ return rb_str_resize(buffer, NUM2SIZET(length));
20
+ }
21
+
10
22
  void lzws_ext_buffer_exports(VALUE root_module)
11
23
  {
12
- VALUE option = rb_define_module_under(root_module, "Buffer");
24
+ VALUE module = rb_define_module_under(root_module, "Buffer");
13
25
 
14
- rb_define_const(option, "DEFAULT_SOURCE_BUFFER_LENGTH_FOR_COMPRESSOR", UINT2NUM(LZWS_DEFAULT_SOURCE_BUFFER_LENGTH_FOR_COMPRESSOR));
15
- rb_define_const(option, "DEFAULT_DESTINATION_BUFFER_LENGTH_FOR_COMPRESSOR", UINT2NUM(LZWS_DEFAULT_DESTINATION_BUFFER_LENGTH_FOR_COMPRESSOR));
16
- rb_define_const(option, "DEFAULT_SOURCE_BUFFER_LENGTH_FOR_DECOMPRESSOR", UINT2NUM(LZWS_DEFAULT_SOURCE_BUFFER_LENGTH_FOR_DECOMPRESSOR));
17
- rb_define_const(option, "DEFAULT_DESTINATION_BUFFER_LENGTH_FOR_DECOMPRESSOR", UINT2NUM(LZWS_DEFAULT_DESTINATION_BUFFER_LENGTH_FOR_DECOMPRESSOR));
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));
18
30
  }
@@ -6,6 +6,18 @@
6
6
 
7
7
  #include "ruby.h"
8
8
 
9
+ VALUE lzws_ext_create_string_buffer(VALUE length);
10
+
11
+ #define LZWS_EXT_CREATE_STRING_BUFFER(buffer, length, exception) \
12
+ VALUE buffer = rb_protect(lzws_ext_create_string_buffer, SIZET2NUM(length), &exception);
13
+
14
+ VALUE lzws_ext_resize_string_buffer(VALUE args);
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);
20
+
9
21
  void lzws_ext_buffer_exports(VALUE root_module);
10
22
 
11
23
  #endif // LZWS_EXT_BUFFER_H
data/ext/lzws_ext/error.c CHANGED
@@ -13,9 +13,9 @@ static inline NORETURN(void raise(const char* name, const char* description))
13
13
  rb_raise(error, "%s", description);
14
14
  }
15
15
 
16
- void lzws_ext_raise_error(lzws_ext_result_t result)
16
+ void lzws_ext_raise_error(lzws_ext_result_t ext_result)
17
17
  {
18
- switch (result) {
18
+ switch (ext_result) {
19
19
  case LZWS_EXT_ERROR_ALLOCATE_FAILED:
20
20
  raise("AllocateError", "allocate error");
21
21
  case LZWS_EXT_ERROR_VALIDATE_FAILED:
data/ext/lzws_ext/error.h CHANGED
@@ -25,6 +25,6 @@ enum {
25
25
  LZWS_EXT_ERROR_UNEXPECTED
26
26
  };
27
27
 
28
- NORETURN(void lzws_ext_raise_error(lzws_ext_result_t result));
28
+ NORETURN(void lzws_ext_raise_error(lzws_ext_result_t ext_result));
29
29
 
30
30
  #endif // LZWS_EXT_ERROR_H
data/ext/lzws_ext/io.c CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
  #include "ruby/io.h"
5
5
 
6
+ #include <lzws/common.h>
6
7
  #include <lzws/file.h>
7
8
 
8
9
  #include "lzws_ext/common.h"
@@ -63,8 +64,7 @@ VALUE lzws_ext_compress_io(VALUE LZWS_EXT_UNUSED(self), VALUE source, VALUE dest
63
64
  without_magic_header, max_code_bit_length, block_mode, msb, unaligned_bit_groups, quiet);
64
65
 
65
66
  if (result != 0) {
66
- lzws_ext_result_t ext_result = get_file_error(result);
67
- lzws_ext_raise_error(ext_result);
67
+ lzws_ext_raise_error(get_file_error(result));
68
68
  }
69
69
 
70
70
  // Ruby itself won't flush stdio file before closing fd, flush is required.
@@ -88,8 +88,7 @@ VALUE lzws_ext_decompress_io(VALUE LZWS_EXT_UNUSED(self), VALUE source, VALUE de
88
88
  without_magic_header, msb, unaligned_bit_groups, quiet);
89
89
 
90
90
  if (result != 0) {
91
- lzws_ext_result_t ext_result = get_file_error(result);
92
- lzws_ext_raise_error(ext_result);
91
+ lzws_ext_raise_error(get_file_error(result));
93
92
  }
94
93
 
95
94
  // Ruby itself won't flush stdio file before closing fd, flush is required.
@@ -4,6 +4,7 @@
4
4
  #include "lzws_ext/option.h"
5
5
 
6
6
  #include <stdbool.h>
7
+ #include <stdlib.h>
7
8
 
8
9
  #include "lzws_ext/error.h"
9
10
  #include "ruby.h"
@@ -25,7 +26,7 @@ bool lzws_ext_get_bool_option_value(VALUE options, const char* name)
25
26
  return raw_type == T_TRUE;
26
27
  }
27
28
 
28
- unsigned long lzws_ext_get_fixnum_option_value(VALUE options, const char* name)
29
+ unsigned int lzws_ext_get_uint_option_value(VALUE options, const char* name)
29
30
  {
30
31
  VALUE raw_value = get_raw_option_value(options, name);
31
32
 
@@ -33,3 +34,12 @@ unsigned long lzws_ext_get_fixnum_option_value(VALUE options, const char* name)
33
34
 
34
35
  return NUM2UINT(raw_value);
35
36
  }
37
+
38
+ size_t lzws_ext_get_size_option_value(VALUE options, const char* name)
39
+ {
40
+ VALUE raw_value = get_raw_option_value(options, name);
41
+
42
+ Check_Type(raw_value, T_FIXNUM);
43
+
44
+ return NUM2SIZET(raw_value);
45
+ }
@@ -5,24 +5,29 @@
5
5
  #define LZWS_EXT_OPTIONS_H
6
6
 
7
7
  #include <stdbool.h>
8
+ #include <stdlib.h>
8
9
 
9
10
  #include "ruby.h"
10
11
 
11
- bool lzws_ext_get_bool_option_value(VALUE options, const char* name);
12
- unsigned long lzws_ext_get_fixnum_option_value(VALUE options, const char* name);
12
+ bool lzws_ext_get_bool_option_value(VALUE options, const char* name);
13
+ unsigned int lzws_ext_get_uint_option_value(VALUE options, const char* name);
14
+ size_t lzws_ext_get_size_option_value(VALUE options, const char* name);
13
15
 
14
16
  #define LZWS_EXT_GET_BOOL_OPTION(options, name) \
15
17
  bool name = lzws_ext_get_bool_option_value(options, #name);
16
18
 
17
- #define LZWS_EXT_GET_FIXNUM_OPTION(options, type, name) \
18
- type name = lzws_ext_get_fixnum_option_value(options, #name);
19
+ #define LZWS_EXT_GET_UINT_OPTION(options, type, name) \
20
+ type name = lzws_ext_get_uint_option_value(options, #name);
19
21
 
20
- #define LZWS_EXT_GET_COMPRESSOR_OPTIONS(options) \
21
- LZWS_EXT_GET_BOOL_OPTION(options, without_magic_header); \
22
- LZWS_EXT_GET_FIXNUM_OPTION(options, uint_fast8_t, max_code_bit_length); \
23
- LZWS_EXT_GET_BOOL_OPTION(options, block_mode); \
24
- LZWS_EXT_GET_BOOL_OPTION(options, msb); \
25
- LZWS_EXT_GET_BOOL_OPTION(options, unaligned_bit_groups); \
22
+ #define LZWS_EXT_GET_SIZE_OPTION(options, name) \
23
+ size_t name = lzws_ext_get_size_option_value(options, #name);
24
+
25
+ #define LZWS_EXT_GET_COMPRESSOR_OPTIONS(options) \
26
+ LZWS_EXT_GET_BOOL_OPTION(options, without_magic_header); \
27
+ LZWS_EXT_GET_UINT_OPTION(options, uint_fast8_t, max_code_bit_length); \
28
+ LZWS_EXT_GET_BOOL_OPTION(options, block_mode); \
29
+ LZWS_EXT_GET_BOOL_OPTION(options, msb); \
30
+ LZWS_EXT_GET_BOOL_OPTION(options, unaligned_bit_groups); \
26
31
  LZWS_EXT_GET_BOOL_OPTION(options, quiet);
27
32
 
28
33
  #define LZWS_EXT_GET_DECOMPRESSOR_OPTIONS(options) \
@@ -32,6 +37,6 @@ unsigned long lzws_ext_get_fixnum_option_value(VALUE options, const char* name);
32
37
  LZWS_EXT_GET_BOOL_OPTION(options, quiet);
33
38
 
34
39
  #define LZWS_EXT_GET_BUFFER_LENGTH_OPTION(options, name) \
35
- LZWS_EXT_GET_FIXNUM_OPTION(options, size_t, name);
40
+ LZWS_EXT_GET_SIZE_OPTION(options, name);
36
41
 
37
42
  #endif // LZWS_EXT_OPTIONS_H
@@ -4,6 +4,7 @@
4
4
  #include "lzws_ext/stream/compressor.h"
5
5
 
6
6
  #include <lzws/buffer.h>
7
+ #include <lzws/common.h>
7
8
  #include <lzws/compressor/common.h>
8
9
  #include <lzws/compressor/main.h>
9
10
  #include <lzws/compressor/state.h>
@@ -119,7 +120,7 @@ VALUE lzws_ext_compress(VALUE self, VALUE source_value)
119
120
  lzws_ext_raise_error(LZWS_EXT_ERROR_UNEXPECTED);
120
121
  }
121
122
 
122
- VALUE bytes_written = UINT2NUM(source_length - remaining_source_length);
123
+ VALUE bytes_written = SIZET2NUM(source_length - remaining_source_length);
123
124
  VALUE needs_more_destination = result == LZWS_COMPRESSOR_NEEDS_MORE_DESTINATION ? Qtrue : Qfalse;
124
125
 
125
126
  return rb_ary_new_from_args(2, bytes_written, needs_more_destination);
@@ -192,9 +193,10 @@ VALUE lzws_ext_compressor_close(VALUE self)
192
193
 
193
194
  void lzws_ext_compressor_exports(VALUE root_module)
194
195
  {
195
- VALUE stream = rb_define_module_under(root_module, "Stream");
196
+ VALUE module = rb_define_module_under(root_module, "Stream");
197
+
198
+ VALUE compressor = rb_define_class_under(module, "NativeCompressor", rb_cObject);
196
199
 
197
- VALUE compressor = rb_define_class_under(stream, "NativeCompressor", rb_cObject);
198
200
  rb_define_alloc_func(compressor, lzws_ext_allocate_compressor);
199
201
  rb_define_method(compressor, "initialize", lzws_ext_initialize_compressor, 1);
200
202
  rb_define_method(compressor, "write", lzws_ext_compress, 1);
@@ -4,6 +4,7 @@
4
4
  #include "lzws_ext/stream/decompressor.h"
5
5
 
6
6
  #include <lzws/buffer.h>
7
+ #include <lzws/common.h>
7
8
  #include <lzws/decompressor/common.h>
8
9
  #include <lzws/decompressor/main.h>
9
10
  #include <lzws/decompressor/state.h>
@@ -125,7 +126,7 @@ VALUE lzws_ext_decompress(VALUE self, VALUE source_value)
125
126
  }
126
127
  }
127
128
 
128
- VALUE bytes_read = UINT2NUM(source_length - remaining_source_length);
129
+ VALUE bytes_read = SIZET2NUM(source_length - remaining_source_length);
129
130
  VALUE needs_more_destination = result == LZWS_DECOMPRESSOR_NEEDS_MORE_DESTINATION ? Qtrue : Qfalse;
130
131
 
131
132
  return rb_ary_new_from_args(2, bytes_read, needs_more_destination);
@@ -178,9 +179,10 @@ VALUE lzws_ext_decompressor_close(VALUE self)
178
179
 
179
180
  void lzws_ext_decompressor_exports(VALUE root_module)
180
181
  {
181
- VALUE stream = rb_define_module_under(root_module, "Stream");
182
+ VALUE module = rb_define_module_under(root_module, "Stream");
183
+
184
+ VALUE decompressor = rb_define_class_under(module, "NativeDecompressor", rb_cObject);
182
185
 
183
- VALUE decompressor = rb_define_class_under(stream, "NativeDecompressor", rb_cObject);
184
186
  rb_define_alloc_func(decompressor, lzws_ext_allocate_decompressor);
185
187
  rb_define_method(decompressor, "initialize", lzws_ext_initialize_decompressor, 1);
186
188
  rb_define_method(decompressor, "read", lzws_ext_decompress, 1);
@@ -4,6 +4,7 @@
4
4
  #include "lzws_ext/string.h"
5
5
 
6
6
  #include <lzws/buffer.h>
7
+ #include <lzws/common.h>
7
8
  #include <lzws/compressor/common.h>
8
9
  #include <lzws/compressor/main.h>
9
10
  #include <lzws/compressor/state.h>
@@ -13,6 +14,7 @@
13
14
  #include <stdint.h>
14
15
  #include <stdlib.h>
15
16
 
17
+ #include "lzws_ext/buffer.h"
16
18
  #include "lzws_ext/error.h"
17
19
  #include "lzws_ext/macro.h"
18
20
  #include "lzws_ext/option.h"
@@ -20,26 +22,6 @@
20
22
 
21
23
  // -- buffer --
22
24
 
23
- static inline VALUE create_buffer(VALUE length)
24
- {
25
- return rb_str_new(NULL, NUM2UINT(length));
26
- }
27
-
28
- #define CREATE_BUFFER(buffer, length, exception) \
29
- VALUE buffer = rb_protect(create_buffer, UINT2NUM(length), &exception);
30
-
31
- static inline VALUE resize_buffer(VALUE args)
32
- {
33
- VALUE buffer = rb_ary_entry(args, 0);
34
- VALUE length = rb_ary_entry(args, 1);
35
- return rb_str_resize(buffer, NUM2UINT(length));
36
- }
37
-
38
- #define RESIZE_BUFFER(buffer, length, exception) \
39
- VALUE resize_buffer_args = rb_ary_new_from_args(2, buffer, UINT2NUM(length)); \
40
- buffer = rb_protect(resize_buffer, resize_buffer_args, &exception); \
41
- RB_GC_GUARD(resize_buffer_args);
42
-
43
25
  static inline lzws_ext_result_t increase_destination_buffer(
44
26
  VALUE destination_value, size_t destination_length,
45
27
  size_t* remaining_destination_buffer_length_ptr, size_t destination_buffer_length)
@@ -51,7 +33,7 @@ static inline lzws_ext_result_t increase_destination_buffer(
51
33
 
52
34
  int exception;
53
35
 
54
- RESIZE_BUFFER(destination_value, destination_length + destination_buffer_length, exception);
36
+ LZWS_EXT_RESIZE_STRING_BUFFER(destination_value, destination_length + destination_buffer_length, exception);
55
37
  if (exception != 0) {
56
38
  return LZWS_EXT_ERROR_ALLOCATE_FAILED;
57
39
  }
@@ -63,13 +45,11 @@ static inline lzws_ext_result_t increase_destination_buffer(
63
45
 
64
46
  // -- utils --
65
47
 
66
- #define GET_SOURCE_DATA(source_value) \
67
- Check_Type(source_value, T_STRING); \
68
- \
69
- const char* source = RSTRING_PTR(source_value); \
70
- size_t source_length = RSTRING_LEN(source_value); \
71
- uint8_t* remaining_source = (uint8_t*)source; \
72
- size_t remaining_source_length = source_length;
48
+ #define GET_SOURCE_DATA(source_value) \
49
+ Check_Type(source_value, T_STRING); \
50
+ \
51
+ const char* source = RSTRING_PTR(source_value); \
52
+ size_t source_length = RSTRING_LEN(source_value);
73
53
 
74
54
  // -- compress --
75
55
 
@@ -105,12 +85,15 @@ static inline lzws_ext_result_t increase_destination_buffer(
105
85
 
106
86
  static inline lzws_ext_result_t compress(
107
87
  lzws_compressor_state_t* state_ptr,
108
- uint8_t* remaining_source, size_t remaining_source_length,
88
+ const char* source, size_t source_length,
109
89
  VALUE destination_value, size_t destination_buffer_length)
110
90
  {
111
91
  lzws_result_t result;
112
92
  lzws_ext_result_t ext_result;
113
93
 
94
+ uint8_t* remaining_source = (uint8_t*)source;
95
+ size_t remaining_source_length = source_length;
96
+
114
97
  size_t destination_length = 0;
115
98
  size_t remaining_destination_buffer_length = destination_buffer_length;
116
99
 
@@ -119,7 +102,7 @@ static inline lzws_ext_result_t compress(
119
102
 
120
103
  int exception;
121
104
 
122
- RESIZE_BUFFER(destination_value, destination_length, exception);
105
+ LZWS_EXT_RESIZE_STRING_BUFFER(destination_value, destination_length, exception);
123
106
  if (exception != 0) {
124
107
  return LZWS_EXT_ERROR_ALLOCATE_FAILED;
125
108
  }
@@ -157,7 +140,7 @@ VALUE lzws_ext_compress_string(VALUE LZWS_EXT_UNUSED(self), VALUE source_value,
157
140
 
158
141
  int exception;
159
142
 
160
- CREATE_BUFFER(destination_value, destination_buffer_length, exception);
143
+ LZWS_EXT_CREATE_STRING_BUFFER(destination_value, destination_buffer_length, exception);
161
144
  if (exception != 0) {
162
145
  lzws_compressor_free_state(state_ptr);
163
146
  lzws_ext_raise_error(LZWS_EXT_ERROR_ALLOCATE_FAILED);
@@ -165,7 +148,7 @@ VALUE lzws_ext_compress_string(VALUE LZWS_EXT_UNUSED(self), VALUE source_value,
165
148
 
166
149
  lzws_ext_result_t ext_result = compress(
167
150
  state_ptr,
168
- remaining_source, remaining_source_length,
151
+ source, source_length,
169
152
  destination_value, destination_buffer_length);
170
153
 
171
154
  lzws_compressor_free_state(state_ptr);
@@ -181,12 +164,15 @@ VALUE lzws_ext_compress_string(VALUE LZWS_EXT_UNUSED(self), VALUE source_value,
181
164
 
182
165
  static inline lzws_ext_result_t decompress(
183
166
  lzws_decompressor_state_t* state_ptr,
184
- uint8_t* remaining_source, size_t remaining_source_length,
167
+ const char* source, size_t source_length,
185
168
  VALUE destination_value, size_t destination_buffer_length)
186
169
  {
187
170
  lzws_result_t result;
188
171
  lzws_ext_result_t ext_result;
189
172
 
173
+ uint8_t* remaining_source = (uint8_t*)source;
174
+ size_t remaining_source_length = source_length;
175
+
190
176
  size_t destination_length = 0;
191
177
  size_t remaining_destination_buffer_length = destination_buffer_length;
192
178
 
@@ -232,7 +218,7 @@ static inline lzws_ext_result_t decompress(
232
218
 
233
219
  int exception;
234
220
 
235
- RESIZE_BUFFER(destination_value, destination_length, exception);
221
+ LZWS_EXT_RESIZE_STRING_BUFFER(destination_value, destination_length, exception);
236
222
  if (exception != 0) {
237
223
  return LZWS_EXT_ERROR_ALLOCATE_FAILED;
238
224
  }
@@ -268,7 +254,7 @@ VALUE lzws_ext_decompress_string(VALUE LZWS_EXT_UNUSED(self), VALUE source_value
268
254
 
269
255
  int exception;
270
256
 
271
- CREATE_BUFFER(destination_value, destination_buffer_length, exception);
257
+ LZWS_EXT_CREATE_STRING_BUFFER(destination_value, destination_buffer_length, exception);
272
258
  if (exception != 0) {
273
259
  lzws_decompressor_free_state(state_ptr);
274
260
  lzws_ext_raise_error(LZWS_EXT_ERROR_ALLOCATE_FAILED);
@@ -276,7 +262,7 @@ VALUE lzws_ext_decompress_string(VALUE LZWS_EXT_UNUSED(self), VALUE source_value
276
262
 
277
263
  lzws_ext_result_t ext_result = decompress(
278
264
  state_ptr,
279
- remaining_source, remaining_source_length,
265
+ source, source_length,
280
266
  destination_value, destination_buffer_length);
281
267
 
282
268
  lzws_decompressor_free_state(state_ptr);
data/lib/lzws/option.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # Ruby bindings for lzws library.
2
2
  # Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
+ require "lzws_ext"
5
+
4
6
  require_relative "error"
5
7
  require_relative "validation"
6
8
 
@@ -38,8 +40,7 @@ module LZWS
38
40
  Validation.validate_positive_integer max_code_bit_length
39
41
 
40
42
  raise ValidateError, "invalid max code bit length" if
41
- max_code_bit_length < LOWEST_MAX_CODE_BIT_LENGTH ||
42
- max_code_bit_length > BIGGEST_MAX_CODE_BIT_LENGTH
43
+ max_code_bit_length < LOWEST_MAX_CODE_BIT_LENGTH || max_code_bit_length > BIGGEST_MAX_CODE_BIT_LENGTH
43
44
 
44
45
  Validation.validate_bool options[:without_magic_header]
45
46
  Validation.validate_bool options[:block_mode]
data/lib/lzws/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
4
  module LZWS
5
- VERSION = "1.1.0".freeze
5
+ VERSION = "1.1.1".freeze
6
6
  end
data/lib/lzws.rb CHANGED
@@ -5,3 +5,4 @@ require_relative "lzws/stream/reader"
5
5
  require_relative "lzws/stream/writer"
6
6
  require_relative "lzws/file"
7
7
  require_relative "lzws/string"
8
+ require_relative "lzws/version"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-lzws
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Aladjev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-12 00:00:00.000000000 Z
11
+ date: 2019-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitar
@@ -16,28 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.8'
19
+ version: '0.9'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.8'
26
+ version: '0.9'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '5.11'
33
+ version: '5.12'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '5.11'
40
+ version: '5.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ocg
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.1'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake-compiler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -58,42 +72,42 @@ dependencies:
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '0.74'
75
+ version: '0.75'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '0.74'
82
+ version: '0.75'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rubocop-performance
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '1.4'
89
+ version: '1.5'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '1.4'
96
+ version: '1.5'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rubocop-rails
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '2.2'
103
+ version: '2.3'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: '2.2'
110
+ version: '2.3'
97
111
  description:
98
112
  email: aladjev.andrew@gmail.com
99
113
  executables: []