ruby-lzws 1.1.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,12 +4,8 @@
4
4
  #include "lzws_ext/stream/compressor.h"
5
5
 
6
6
  #include <lzws/buffer.h>
7
- #include <lzws/common.h>
8
- #include <lzws/compressor/common.h>
9
7
  #include <lzws/compressor/main.h>
10
8
  #include <lzws/compressor/state.h>
11
- #include <stdint.h>
12
- #include <stdlib.h>
13
9
 
14
10
  #include "lzws_ext/error.h"
15
11
  #include "lzws_ext/option.h"
@@ -22,7 +18,7 @@ static void free_compressor(lzws_ext_compressor_t* compressor_ptr)
22
18
  lzws_compressor_free_state(state_ptr);
23
19
  }
24
20
 
25
- uint8_t* destination_buffer = compressor_ptr->destination_buffer;
21
+ lzws_ext_byte_t* destination_buffer = compressor_ptr->destination_buffer;
26
22
  if (destination_buffer != NULL) {
27
23
  free(destination_buffer);
28
24
  }
@@ -33,8 +29,7 @@ static void free_compressor(lzws_ext_compressor_t* compressor_ptr)
33
29
  VALUE lzws_ext_allocate_compressor(VALUE klass)
34
30
  {
35
31
  lzws_ext_compressor_t* compressor_ptr;
36
-
37
- VALUE self = Data_Make_Struct(klass, lzws_ext_compressor_t, NULL, free_compressor, compressor_ptr);
32
+ VALUE self = Data_Make_Struct(klass, lzws_ext_compressor_t, NULL, free_compressor, compressor_ptr);
38
33
 
39
34
  compressor_ptr->state_ptr = NULL;
40
35
  compressor_ptr->destination_buffer = NULL;
@@ -58,10 +53,7 @@ VALUE lzws_ext_initialize_compressor(VALUE self, VALUE options)
58
53
 
59
54
  lzws_compressor_state_t* state_ptr;
60
55
 
61
- lzws_result_t result = lzws_compressor_get_initial_state(
62
- &state_ptr,
63
- without_magic_header, max_code_bit_length, block_mode, msb, unaligned_bit_groups, quiet);
64
-
56
+ lzws_result_t result = lzws_compressor_get_initial_state(&state_ptr, &compressor_options);
65
57
  if (result != 0) {
66
58
  switch (result) {
67
59
  case LZWS_COMPRESSOR_ALLOCATE_FAILED:
@@ -73,9 +65,11 @@ VALUE lzws_ext_initialize_compressor(VALUE self, VALUE options)
73
65
  }
74
66
  }
75
67
 
76
- uint8_t* destination_buffer;
68
+ lzws_ext_byte_t* destination_buffer;
69
+
70
+ result = lzws_create_destination_buffer_for_compressor(
71
+ &destination_buffer, &destination_buffer_length, compressor_options.quiet);
77
72
 
78
- result = lzws_create_destination_buffer_for_compressor(&destination_buffer, &destination_buffer_length, quiet);
79
73
  if (result != 0) {
80
74
  lzws_compressor_free_state(state_ptr);
81
75
  lzws_ext_raise_error(LZWS_EXT_ERROR_ALLOCATE_FAILED);
@@ -95,13 +89,13 @@ VALUE lzws_ext_initialize_compressor(VALUE self, VALUE options)
95
89
  lzws_ext_raise_error(LZWS_EXT_ERROR_USED_AFTER_CLOSE); \
96
90
  }
97
91
 
98
- #define GET_SOURCE_DATA(source_value) \
99
- Check_Type(source_value, T_STRING); \
100
- \
101
- const char* source = RSTRING_PTR(source_value); \
102
- size_t source_length = RSTRING_LEN(source_value); \
103
- uint8_t* remaining_source = (uint8_t*)source; \
104
- size_t remaining_source_length = source_length;
92
+ #define GET_SOURCE_DATA(source_value) \
93
+ Check_Type(source_value, T_STRING); \
94
+ \
95
+ const char* source = RSTRING_PTR(source_value); \
96
+ size_t source_length = RSTRING_LEN(source_value); \
97
+ lzws_ext_byte_t* remaining_source = (lzws_ext_byte_t*) source; \
98
+ size_t remaining_source_length = source_length;
105
99
 
106
100
  VALUE lzws_ext_compress(VALUE self, VALUE source_value)
107
101
  {
@@ -111,12 +105,12 @@ VALUE lzws_ext_compress(VALUE self, VALUE source_value)
111
105
 
112
106
  lzws_result_t result = lzws_compress(
113
107
  compressor_ptr->state_ptr,
114
- &remaining_source, &remaining_source_length,
115
- &compressor_ptr->remaining_destination_buffer, &compressor_ptr->remaining_destination_buffer_length);
108
+ &remaining_source,
109
+ &remaining_source_length,
110
+ &compressor_ptr->remaining_destination_buffer,
111
+ &compressor_ptr->remaining_destination_buffer_length);
116
112
 
117
- if (
118
- result != 0 &&
119
- result != LZWS_COMPRESSOR_NEEDS_MORE_DESTINATION) {
113
+ if (result != 0 && result != LZWS_COMPRESSOR_NEEDS_MORE_DESTINATION) {
120
114
  lzws_ext_raise_error(LZWS_EXT_ERROR_UNEXPECTED);
121
115
  }
122
116
 
@@ -133,17 +127,14 @@ VALUE lzws_ext_compressor_finish(VALUE self)
133
127
 
134
128
  lzws_result_t result = lzws_compressor_finish(
135
129
  compressor_ptr->state_ptr,
136
- &compressor_ptr->remaining_destination_buffer, &compressor_ptr->remaining_destination_buffer_length);
130
+ &compressor_ptr->remaining_destination_buffer,
131
+ &compressor_ptr->remaining_destination_buffer_length);
137
132
 
138
- if (
139
- result != 0 &&
140
- result != LZWS_COMPRESSOR_NEEDS_MORE_DESTINATION) {
133
+ if (result != 0 && result != LZWS_COMPRESSOR_NEEDS_MORE_DESTINATION) {
141
134
  lzws_ext_raise_error(LZWS_EXT_ERROR_UNEXPECTED);
142
135
  }
143
136
 
144
- VALUE needs_more_destination = result == LZWS_COMPRESSOR_NEEDS_MORE_DESTINATION ? Qtrue : Qfalse;
145
-
146
- return needs_more_destination;
137
+ return result == LZWS_COMPRESSOR_NEEDS_MORE_DESTINATION ? Qtrue : Qfalse;
147
138
  }
148
139
 
149
140
  VALUE lzws_ext_compressor_read_result(VALUE self)
@@ -151,14 +142,13 @@ VALUE lzws_ext_compressor_read_result(VALUE self)
151
142
  GET_COMPRESSOR(self);
152
143
  DO_NOT_USE_AFTER_CLOSE(compressor_ptr);
153
144
 
154
- uint8_t* destination_buffer = compressor_ptr->destination_buffer;
155
- size_t destination_buffer_length = compressor_ptr->destination_buffer_length;
156
- size_t remaining_destination_buffer_length = compressor_ptr->remaining_destination_buffer_length;
145
+ lzws_ext_byte_t* destination_buffer = compressor_ptr->destination_buffer;
146
+ size_t destination_buffer_length = compressor_ptr->destination_buffer_length;
147
+ size_t remaining_destination_buffer_length = compressor_ptr->remaining_destination_buffer_length;
157
148
 
158
- const char* result = (const char*)destination_buffer;
149
+ const char* result = (const char*) destination_buffer;
159
150
  size_t result_length = destination_buffer_length - remaining_destination_buffer_length;
160
-
161
- VALUE result_value = rb_str_new(result, result_length);
151
+ VALUE result_value = rb_str_new(result, result_length);
162
152
 
163
153
  compressor_ptr->remaining_destination_buffer = destination_buffer;
164
154
  compressor_ptr->remaining_destination_buffer_length = destination_buffer_length;
@@ -178,7 +168,7 @@ VALUE lzws_ext_compressor_close(VALUE self)
178
168
  compressor_ptr->state_ptr = NULL;
179
169
  }
180
170
 
181
- uint8_t* destination_buffer = compressor_ptr->destination_buffer;
171
+ lzws_ext_byte_t* destination_buffer = compressor_ptr->destination_buffer;
182
172
  if (destination_buffer != NULL) {
183
173
  free(destination_buffer);
184
174
 
@@ -5,16 +5,17 @@
5
5
  #define LZWS_EXT_STREAM_COMPRESSOR_H
6
6
 
7
7
  #include <lzws/compressor/state.h>
8
- #include <stdint.h>
9
8
  #include <stdlib.h>
10
9
 
10
+ #include "lzws_ext/common.h"
11
11
  #include "ruby.h"
12
12
 
13
- typedef struct {
13
+ typedef struct
14
+ {
14
15
  lzws_compressor_state_t* state_ptr;
15
- uint8_t* destination_buffer;
16
+ lzws_ext_byte_t* destination_buffer;
16
17
  size_t destination_buffer_length;
17
- uint8_t* remaining_destination_buffer;
18
+ lzws_ext_byte_t* remaining_destination_buffer;
18
19
  size_t remaining_destination_buffer_length;
19
20
  } lzws_ext_compressor_t;
20
21
 
@@ -4,12 +4,8 @@
4
4
  #include "lzws_ext/stream/decompressor.h"
5
5
 
6
6
  #include <lzws/buffer.h>
7
- #include <lzws/common.h>
8
- #include <lzws/decompressor/common.h>
9
7
  #include <lzws/decompressor/main.h>
10
8
  #include <lzws/decompressor/state.h>
11
- #include <stdint.h>
12
- #include <stdlib.h>
13
9
 
14
10
  #include "lzws_ext/error.h"
15
11
  #include "lzws_ext/option.h"
@@ -22,7 +18,7 @@ static void free_decompressor(lzws_ext_decompressor_t* decompressor_ptr)
22
18
  lzws_decompressor_free_state(state_ptr);
23
19
  }
24
20
 
25
- uint8_t* destination_buffer = decompressor_ptr->destination_buffer;
21
+ lzws_ext_byte_t* destination_buffer = decompressor_ptr->destination_buffer;
26
22
  if (destination_buffer != NULL) {
27
23
  free(destination_buffer);
28
24
  }
@@ -33,7 +29,6 @@ static void free_decompressor(lzws_ext_decompressor_t* decompressor_ptr)
33
29
  VALUE lzws_ext_allocate_decompressor(VALUE klass)
34
30
  {
35
31
  lzws_ext_decompressor_t* decompressor_ptr;
36
-
37
32
  VALUE self = Data_Make_Struct(klass, lzws_ext_decompressor_t, NULL, free_decompressor, decompressor_ptr);
38
33
 
39
34
  decompressor_ptr->state_ptr = NULL;
@@ -58,10 +53,7 @@ VALUE lzws_ext_initialize_decompressor(VALUE self, VALUE options)
58
53
 
59
54
  lzws_decompressor_state_t* state_ptr;
60
55
 
61
- lzws_result_t result = lzws_decompressor_get_initial_state(
62
- &state_ptr,
63
- without_magic_header, msb, unaligned_bit_groups, quiet);
64
-
56
+ lzws_result_t result = lzws_decompressor_get_initial_state(&state_ptr, &decompressor_options);
65
57
  if (result != 0) {
66
58
  switch (result) {
67
59
  case LZWS_DECOMPRESSOR_ALLOCATE_FAILED:
@@ -71,9 +63,11 @@ VALUE lzws_ext_initialize_decompressor(VALUE self, VALUE options)
71
63
  }
72
64
  }
73
65
 
74
- uint8_t* destination_buffer;
66
+ lzws_ext_byte_t* destination_buffer;
67
+
68
+ result = lzws_create_destination_buffer_for_decompressor(
69
+ &destination_buffer, &destination_buffer_length, decompressor_options.quiet);
75
70
 
76
- result = lzws_create_destination_buffer_for_decompressor(&destination_buffer, &destination_buffer_length, quiet);
77
71
  if (result != 0) {
78
72
  lzws_decompressor_free_state(state_ptr);
79
73
  lzws_ext_raise_error(LZWS_EXT_ERROR_ALLOCATE_FAILED);
@@ -93,13 +87,13 @@ VALUE lzws_ext_initialize_decompressor(VALUE self, VALUE options)
93
87
  lzws_ext_raise_error(LZWS_EXT_ERROR_USED_AFTER_CLOSE); \
94
88
  }
95
89
 
96
- #define GET_SOURCE_DATA(source_value) \
97
- Check_Type(source_value, T_STRING); \
98
- \
99
- const char* source = RSTRING_PTR(source_value); \
100
- size_t source_length = RSTRING_LEN(source_value); \
101
- uint8_t* remaining_source = (uint8_t*)source; \
102
- size_t remaining_source_length = source_length;
90
+ #define GET_SOURCE_DATA(source_value) \
91
+ Check_Type(source_value, T_STRING); \
92
+ \
93
+ const char* source = RSTRING_PTR(source_value); \
94
+ size_t source_length = RSTRING_LEN(source_value); \
95
+ lzws_ext_byte_t* remaining_source = (lzws_ext_byte_t*) source; \
96
+ size_t remaining_source_length = source_length;
103
97
 
104
98
  VALUE lzws_ext_decompress(VALUE self, VALUE source_value)
105
99
  {
@@ -109,12 +103,12 @@ VALUE lzws_ext_decompress(VALUE self, VALUE source_value)
109
103
 
110
104
  lzws_result_t result = lzws_decompress(
111
105
  decompressor_ptr->state_ptr,
112
- &remaining_source, &remaining_source_length,
113
- &decompressor_ptr->remaining_destination_buffer, &decompressor_ptr->remaining_destination_buffer_length);
106
+ &remaining_source,
107
+ &remaining_source_length,
108
+ &decompressor_ptr->remaining_destination_buffer,
109
+ &decompressor_ptr->remaining_destination_buffer_length);
114
110
 
115
- if (
116
- result != 0 &&
117
- result != LZWS_DECOMPRESSOR_NEEDS_MORE_DESTINATION) {
111
+ if (result != 0 && result != LZWS_DECOMPRESSOR_NEEDS_MORE_DESTINATION) {
118
112
  switch (result) {
119
113
  case LZWS_DECOMPRESSOR_INVALID_MAGIC_HEADER:
120
114
  case LZWS_DECOMPRESSOR_INVALID_MAX_CODE_BIT_LENGTH:
@@ -137,14 +131,13 @@ VALUE lzws_ext_decompressor_read_result(VALUE self)
137
131
  GET_DECOMPRESSOR(self);
138
132
  DO_NOT_USE_AFTER_CLOSE(decompressor_ptr);
139
133
 
140
- uint8_t* destination_buffer = decompressor_ptr->destination_buffer;
141
- size_t destination_buffer_length = decompressor_ptr->destination_buffer_length;
142
- size_t remaining_destination_buffer_length = decompressor_ptr->remaining_destination_buffer_length;
134
+ lzws_ext_byte_t* destination_buffer = decompressor_ptr->destination_buffer;
135
+ size_t destination_buffer_length = decompressor_ptr->destination_buffer_length;
136
+ size_t remaining_destination_buffer_length = decompressor_ptr->remaining_destination_buffer_length;
143
137
 
144
- const char* result = (const char*)destination_buffer;
138
+ const char* result = (const char*) destination_buffer;
145
139
  size_t result_length = destination_buffer_length - remaining_destination_buffer_length;
146
-
147
- VALUE result_value = rb_str_new(result, result_length);
140
+ VALUE result_value = rb_str_new(result, result_length);
148
141
 
149
142
  decompressor_ptr->remaining_destination_buffer = destination_buffer;
150
143
  decompressor_ptr->remaining_destination_buffer_length = destination_buffer_length;
@@ -164,7 +157,7 @@ VALUE lzws_ext_decompressor_close(VALUE self)
164
157
  decompressor_ptr->state_ptr = NULL;
165
158
  }
166
159
 
167
- uint8_t* destination_buffer = decompressor_ptr->destination_buffer;
160
+ lzws_ext_byte_t* destination_buffer = decompressor_ptr->destination_buffer;
168
161
  if (destination_buffer != NULL) {
169
162
  free(destination_buffer);
170
163
 
@@ -5,16 +5,17 @@
5
5
  #define LZWS_EXT_STREAM_DECOMPRESSOR_H
6
6
 
7
7
  #include <lzws/decompressor/state.h>
8
- #include <stdint.h>
9
8
  #include <stdlib.h>
10
9
 
10
+ #include "lzws_ext/common.h"
11
11
  #include "ruby.h"
12
12
 
13
- typedef struct {
13
+ typedef struct
14
+ {
14
15
  lzws_decompressor_state_t* state_ptr;
15
- uint8_t* destination_buffer;
16
+ lzws_ext_byte_t* destination_buffer;
16
17
  size_t destination_buffer_length;
17
- uint8_t* remaining_destination_buffer;
18
+ lzws_ext_byte_t* remaining_destination_buffer;
18
19
  size_t remaining_destination_buffer_length;
19
20
  } lzws_ext_decompressor_t;
20
21
 
@@ -4,14 +4,10 @@
4
4
  #include "lzws_ext/string.h"
5
5
 
6
6
  #include <lzws/buffer.h>
7
- #include <lzws/common.h>
8
- #include <lzws/compressor/common.h>
9
7
  #include <lzws/compressor/main.h>
10
8
  #include <lzws/compressor/state.h>
11
- #include <lzws/decompressor/common.h>
12
9
  #include <lzws/decompressor/main.h>
13
10
  #include <lzws/decompressor/state.h>
14
- #include <stdint.h>
15
11
  #include <stdlib.h>
16
12
 
17
13
  #include "lzws_ext/buffer.h"
@@ -23,8 +19,10 @@
23
19
  // -- buffer --
24
20
 
25
21
  static inline lzws_ext_result_t increase_destination_buffer(
26
- VALUE destination_value, size_t destination_length,
27
- size_t* remaining_destination_buffer_length_ptr, size_t destination_buffer_length)
22
+ VALUE destination_value,
23
+ size_t destination_length,
24
+ size_t* remaining_destination_buffer_length_ptr,
25
+ size_t destination_buffer_length)
28
26
  {
29
27
  if (*remaining_destination_buffer_length_ptr == destination_buffer_length) {
30
28
  // We want to write more data at once, than buffer has.
@@ -53,49 +51,46 @@ static inline lzws_ext_result_t increase_destination_buffer(
53
51
 
54
52
  // -- compress --
55
53
 
56
- #define BUFFERED_COMPRESS(function, ...) \
57
- while (true) { \
58
- uint8_t* remaining_destination_buffer = (uint8_t*)RSTRING_PTR(destination_value) + destination_length; \
59
- size_t prev_remaining_destination_buffer_length = remaining_destination_buffer_length; \
60
- \
61
- result = function(__VA_ARGS__, &remaining_destination_buffer, &remaining_destination_buffer_length); \
62
- \
63
- if ( \
64
- result != 0 && \
65
- result != LZWS_COMPRESSOR_NEEDS_MORE_DESTINATION) { \
66
- return LZWS_EXT_ERROR_UNEXPECTED; \
67
- } \
68
- \
69
- destination_length += prev_remaining_destination_buffer_length - remaining_destination_buffer_length; \
70
- \
71
- if (result == LZWS_COMPRESSOR_NEEDS_MORE_DESTINATION) { \
72
- ext_result = increase_destination_buffer( \
73
- destination_value, destination_length, \
74
- &remaining_destination_buffer_length, destination_buffer_length); \
75
- \
76
- if (ext_result != 0) { \
77
- return ext_result; \
78
- } \
79
- \
80
- continue; \
81
- } \
82
- \
83
- break; \
54
+ #define BUFFERED_COMPRESS(function, ...) \
55
+ while (true) { \
56
+ lzws_ext_byte_t* remaining_destination_buffer = \
57
+ (lzws_ext_byte_t*) RSTRING_PTR(destination_value) + destination_length; \
58
+ size_t prev_remaining_destination_buffer_length = remaining_destination_buffer_length; \
59
+ \
60
+ result = function(__VA_ARGS__, &remaining_destination_buffer, &remaining_destination_buffer_length); \
61
+ if (result != 0 && result != LZWS_COMPRESSOR_NEEDS_MORE_DESTINATION) { \
62
+ return LZWS_EXT_ERROR_UNEXPECTED; \
63
+ } \
64
+ \
65
+ destination_length += prev_remaining_destination_buffer_length - remaining_destination_buffer_length; \
66
+ \
67
+ if (result == LZWS_COMPRESSOR_NEEDS_MORE_DESTINATION) { \
68
+ ext_result = increase_destination_buffer( \
69
+ destination_value, destination_length, &remaining_destination_buffer_length, destination_buffer_length); \
70
+ \
71
+ if (ext_result != 0) { \
72
+ return ext_result; \
73
+ } \
74
+ \
75
+ continue; \
76
+ } \
77
+ \
78
+ break; \
84
79
  }
85
80
 
86
81
  static inline lzws_ext_result_t compress(
87
82
  lzws_compressor_state_t* state_ptr,
88
- const char* source, size_t source_length,
89
- VALUE destination_value, size_t destination_buffer_length)
83
+ const char* source,
84
+ size_t source_length,
85
+ VALUE destination_value,
86
+ size_t destination_buffer_length)
90
87
  {
91
88
  lzws_result_t result;
92
89
  lzws_ext_result_t ext_result;
93
-
94
- uint8_t* remaining_source = (uint8_t*)source;
95
- size_t remaining_source_length = source_length;
96
-
97
- size_t destination_length = 0;
98
- size_t remaining_destination_buffer_length = destination_buffer_length;
90
+ lzws_ext_byte_t* remaining_source = (lzws_ext_byte_t*) source;
91
+ size_t remaining_source_length = source_length;
92
+ size_t destination_length = 0;
93
+ size_t remaining_destination_buffer_length = destination_buffer_length;
99
94
 
100
95
  BUFFERED_COMPRESS(lzws_compress, state_ptr, &remaining_source, &remaining_source_length);
101
96
  BUFFERED_COMPRESS(lzws_compressor_finish, state_ptr);
@@ -119,10 +114,7 @@ VALUE lzws_ext_compress_string(VALUE LZWS_EXT_UNUSED(self), VALUE source_value,
119
114
 
120
115
  lzws_compressor_state_t* state_ptr;
121
116
 
122
- lzws_result_t result = lzws_compressor_get_initial_state(
123
- &state_ptr,
124
- without_magic_header, max_code_bit_length, block_mode, msb, unaligned_bit_groups, quiet);
125
-
117
+ lzws_result_t result = lzws_compressor_get_initial_state(&state_ptr, &compressor_options);
126
118
  if (result != 0) {
127
119
  switch (result) {
128
120
  case LZWS_COMPRESSOR_ALLOCATE_FAILED:
@@ -146,10 +138,8 @@ VALUE lzws_ext_compress_string(VALUE LZWS_EXT_UNUSED(self), VALUE source_value,
146
138
  lzws_ext_raise_error(LZWS_EXT_ERROR_ALLOCATE_FAILED);
147
139
  }
148
140
 
149
- lzws_ext_result_t ext_result = compress(
150
- state_ptr,
151
- source, source_length,
152
- destination_value, destination_buffer_length);
141
+ lzws_ext_result_t ext_result =
142
+ compress(state_ptr, source, source_length, destination_value, destination_buffer_length);
153
143
 
154
144
  lzws_compressor_free_state(state_ptr);
155
145
 
@@ -164,30 +154,31 @@ VALUE lzws_ext_compress_string(VALUE LZWS_EXT_UNUSED(self), VALUE source_value,
164
154
 
165
155
  static inline lzws_ext_result_t decompress(
166
156
  lzws_decompressor_state_t* state_ptr,
167
- const char* source, size_t source_length,
168
- VALUE destination_value, size_t destination_buffer_length)
157
+ const char* source,
158
+ size_t source_length,
159
+ VALUE destination_value,
160
+ size_t destination_buffer_length)
169
161
  {
170
162
  lzws_result_t result;
171
163
  lzws_ext_result_t ext_result;
172
-
173
- uint8_t* remaining_source = (uint8_t*)source;
174
- size_t remaining_source_length = source_length;
175
-
176
- size_t destination_length = 0;
177
- size_t remaining_destination_buffer_length = destination_buffer_length;
164
+ lzws_ext_byte_t* remaining_source = (lzws_ext_byte_t*) source;
165
+ size_t remaining_source_length = source_length;
166
+ size_t destination_length = 0;
167
+ size_t remaining_destination_buffer_length = destination_buffer_length;
178
168
 
179
169
  while (true) {
180
- uint8_t* remaining_destination_buffer = (uint8_t*)RSTRING_PTR(destination_value) + destination_length;
181
- size_t prev_remaining_destination_buffer_length = remaining_destination_buffer_length;
170
+ lzws_ext_byte_t* remaining_destination_buffer =
171
+ (lzws_ext_byte_t*) RSTRING_PTR(destination_value) + destination_length;
172
+ size_t prev_remaining_destination_buffer_length = remaining_destination_buffer_length;
182
173
 
183
174
  result = lzws_decompress(
184
175
  state_ptr,
185
- &remaining_source, &remaining_source_length,
186
- &remaining_destination_buffer, &remaining_destination_buffer_length);
176
+ &remaining_source,
177
+ &remaining_source_length,
178
+ &remaining_destination_buffer,
179
+ &remaining_destination_buffer_length);
187
180
 
188
- if (
189
- result != 0 &&
190
- result != LZWS_DECOMPRESSOR_NEEDS_MORE_DESTINATION) {
181
+ if (result != 0 && result != LZWS_DECOMPRESSOR_NEEDS_MORE_DESTINATION) {
191
182
  switch (result) {
192
183
  case LZWS_DECOMPRESSOR_INVALID_MAGIC_HEADER:
193
184
  case LZWS_DECOMPRESSOR_INVALID_MAX_CODE_BIT_LENGTH:
@@ -203,8 +194,7 @@ static inline lzws_ext_result_t decompress(
203
194
 
204
195
  if (result == LZWS_DECOMPRESSOR_NEEDS_MORE_DESTINATION) {
205
196
  ext_result = increase_destination_buffer(
206
- destination_value, destination_length,
207
- &remaining_destination_buffer_length, destination_buffer_length);
197
+ destination_value, destination_length, &remaining_destination_buffer_length, destination_buffer_length);
208
198
 
209
199
  if (ext_result != 0) {
210
200
  return ext_result;
@@ -235,10 +225,7 @@ VALUE lzws_ext_decompress_string(VALUE LZWS_EXT_UNUSED(self), VALUE source_value
235
225
 
236
226
  lzws_decompressor_state_t* state_ptr;
237
227
 
238
- lzws_result_t result = lzws_decompressor_get_initial_state(
239
- &state_ptr,
240
- without_magic_header, msb, unaligned_bit_groups, quiet);
241
-
228
+ lzws_result_t result = lzws_decompressor_get_initial_state(&state_ptr, &decompressor_options);
242
229
  if (result != 0) {
243
230
  switch (result) {
244
231
  case LZWS_DECOMPRESSOR_ALLOCATE_FAILED:
@@ -260,10 +247,8 @@ VALUE lzws_ext_decompress_string(VALUE LZWS_EXT_UNUSED(self), VALUE source_value
260
247
  lzws_ext_raise_error(LZWS_EXT_ERROR_ALLOCATE_FAILED);
261
248
  }
262
249
 
263
- lzws_ext_result_t ext_result = decompress(
264
- state_ptr,
265
- source, source_length,
266
- destination_value, destination_buffer_length);
250
+ lzws_ext_result_t ext_result =
251
+ decompress(state_ptr, source, source_length, destination_value, destination_buffer_length);
267
252
 
268
253
  lzws_decompressor_free_state(state_ptr);
269
254