ruby-lzws 1.0.0 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,30 @@
1
+ // Ruby bindings for lzws library.
2
+ // Copyright (c) 2019 AUTHORS, MIT License.
3
+
4
+ #include "lzws_ext/buffer.h"
5
+
6
+ #include <lzws/buffer.h>
7
+
8
+ #include "ruby.h"
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
+
22
+ void lzws_ext_buffer_exports(VALUE root_module)
23
+ {
24
+ VALUE module = rb_define_module_under(root_module, "Buffer");
25
+
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));
30
+ }
@@ -0,0 +1,23 @@
1
+ // Ruby bindings for lzws library.
2
+ // Copyright (c) 2019 AUTHORS, MIT License.
3
+
4
+ #if !defined(LZWS_EXT_BUFFER_H)
5
+ #define LZWS_EXT_BUFFER_H
6
+
7
+ #include "ruby.h"
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
+
21
+ void lzws_ext_buffer_exports(VALUE root_module);
22
+
23
+ #endif // LZWS_EXT_BUFFER_H
@@ -4,6 +4,13 @@
4
4
  #if !defined(LZWS_EXT_COMMON_H)
5
5
  #define LZWS_EXT_COMMON_H
6
6
 
7
+ #include <stdint.h>
8
+
7
9
  #define LZWS_EXT_MODULE_NAME "LZWS"
8
10
 
11
+ typedef uint_fast8_t lzws_ext_result_t;
12
+
13
+ typedef uint8_t lzws_ext_byte_t;
14
+ typedef uint_fast8_t lzws_ext_byte_fast_t;
15
+
9
16
  #endif // LZWS_EXT_COMMON_H
@@ -1,14 +1,43 @@
1
1
  // Ruby bindings for lzws library.
2
2
  // Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
- #include "ruby.h"
5
-
6
- #include "lzws_ext/common.h"
7
4
  #include "lzws_ext/error.h"
8
5
 
9
- void lzws_ext_raise_error(const char* name, const char* description)
6
+ #include "ruby.h"
7
+
8
+ static inline NORETURN(void raise(const char* name, const char* description))
10
9
  {
11
10
  VALUE module = rb_define_module(LZWS_EXT_MODULE_NAME);
12
11
  VALUE error = rb_const_get(module, rb_intern(name));
13
12
  rb_raise(error, "%s", description);
14
13
  }
14
+
15
+ void lzws_ext_raise_error(lzws_ext_result_t ext_result)
16
+ {
17
+ switch (ext_result) {
18
+ case LZWS_EXT_ERROR_ALLOCATE_FAILED:
19
+ raise("AllocateError", "allocate error");
20
+ case LZWS_EXT_ERROR_VALIDATE_FAILED:
21
+ raise("ValidateError", "validate error");
22
+
23
+ case LZWS_EXT_ERROR_USED_AFTER_CLOSE:
24
+ raise("UsedAfterCloseError", "used after closed");
25
+ case LZWS_EXT_ERROR_NOT_ENOUGH_SOURCE_BUFFER:
26
+ raise("NotEnoughSourceBufferError", "not enough source buffer");
27
+ case LZWS_EXT_ERROR_NOT_ENOUGH_DESTINATION_BUFFER:
28
+ raise("NotEnoughDestinationBufferError", "not enough destination buffer");
29
+ case LZWS_EXT_ERROR_DECOMPRESSOR_CORRUPTED_SOURCE:
30
+ raise("DecompressorCorruptedSourceError", "decompressor received corrupted source");
31
+
32
+ case LZWS_EXT_ERROR_ACCESS_IO:
33
+ raise("AccessIOError", "failed to access IO");
34
+ case LZWS_EXT_ERROR_READ_IO:
35
+ raise("ReadIOError", "failed to read IO");
36
+ case LZWS_EXT_ERROR_WRITE_IO:
37
+ raise("WriteIOError", "failed to write IO");
38
+
39
+ default:
40
+ // LZWS_EXT_ERROR_UNEXPECTED
41
+ raise("UnexpectedError", "unexpected error");
42
+ }
43
+ }
@@ -4,8 +4,27 @@
4
4
  #if !defined(LZWS_EXT_ERROR_H)
5
5
  #define LZWS_EXT_ERROR_H
6
6
 
7
+ #include "lzws_ext/common.h"
7
8
  #include "ruby.h"
8
9
 
9
- NORETURN(void lzws_ext_raise_error(const char* name, const char* description));
10
+ // Results for errors listed in "lib/lzws/error" used in c extension.
11
+
12
+ enum {
13
+ LZWS_EXT_ERROR_ALLOCATE_FAILED = 1,
14
+ LZWS_EXT_ERROR_VALIDATE_FAILED,
15
+
16
+ LZWS_EXT_ERROR_USED_AFTER_CLOSE,
17
+ LZWS_EXT_ERROR_NOT_ENOUGH_SOURCE_BUFFER,
18
+ LZWS_EXT_ERROR_NOT_ENOUGH_DESTINATION_BUFFER,
19
+ LZWS_EXT_ERROR_DECOMPRESSOR_CORRUPTED_SOURCE,
20
+
21
+ LZWS_EXT_ERROR_ACCESS_IO,
22
+ LZWS_EXT_ERROR_READ_IO,
23
+ LZWS_EXT_ERROR_WRITE_IO,
24
+
25
+ LZWS_EXT_ERROR_UNEXPECTED
26
+ };
27
+
28
+ NORETURN(void lzws_ext_raise_error(lzws_ext_result_t ext_result));
10
29
 
11
30
  #endif // LZWS_EXT_ERROR_H
@@ -1,52 +1,69 @@
1
1
  // Ruby bindings for lzws library.
2
2
  // Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
- #include <lzws/file.h>
5
-
6
- #include "ruby.h"
7
4
  #include "ruby/io.h"
8
5
 
6
+ #include <lzws/common.h>
7
+ #include <lzws/file.h>
8
+
9
9
  #include "lzws_ext/error.h"
10
10
  #include "lzws_ext/io.h"
11
11
  #include "lzws_ext/macro.h"
12
12
  #include "lzws_ext/option.h"
13
+ #include "ruby.h"
13
14
 
14
- #define GET_FILE(target) \
15
- Check_Type(target, T_FILE); \
16
- \
17
- rb_io_t *target##_io; \
18
- GetOpenFile(target, target##_io); \
19
- \
20
- FILE *target##_file = rb_io_stdio_file(target##_io); \
21
- if (target##_file == NULL) { \
22
- lzws_ext_raise_error("AccessIOError", "failed to access IO"); \
15
+ #define GET_FILE(target) \
16
+ Check_Type(target, T_FILE); \
17
+ \
18
+ rb_io_t* target##_io; \
19
+ GetOpenFile(target, target##_io); \
20
+ \
21
+ FILE* target##_file = rb_io_stdio_file(target##_io); \
22
+ if (target##_file == NULL) { \
23
+ lzws_ext_raise_error(LZWS_EXT_ERROR_ACCESS_IO); \
23
24
  }
24
25
 
26
+ static inline lzws_ext_result_t get_file_error(lzws_result_t result)
27
+ {
28
+ switch (result) {
29
+ case LZWS_FILE_ALLOCATE_FAILED:
30
+ return LZWS_EXT_ERROR_ALLOCATE_FAILED;
31
+ case LZWS_FILE_VALIDATE_FAILED:
32
+ return LZWS_EXT_ERROR_VALIDATE_FAILED;
33
+
34
+ case LZWS_FILE_NOT_ENOUGH_SOURCE_BUFFER:
35
+ return LZWS_EXT_ERROR_NOT_ENOUGH_SOURCE_BUFFER;
36
+ case LZWS_FILE_NOT_ENOUGH_DESTINATION_BUFFER:
37
+ return LZWS_EXT_ERROR_NOT_ENOUGH_DESTINATION_BUFFER;
38
+ case LZWS_FILE_DECOMPRESSOR_CORRUPTED_SOURCE:
39
+ return LZWS_EXT_ERROR_DECOMPRESSOR_CORRUPTED_SOURCE;
40
+
41
+ case LZWS_FILE_READ_FAILED:
42
+ return LZWS_EXT_ERROR_READ_IO;
43
+ case LZWS_FILE_WRITE_FAILED:
44
+ return LZWS_EXT_ERROR_WRITE_IO;
45
+
46
+ default:
47
+ return LZWS_EXT_ERROR_UNEXPECTED;
48
+ }
49
+ }
50
+
25
51
  VALUE lzws_ext_compress_io(VALUE LZWS_EXT_UNUSED(self), VALUE source, VALUE destination, VALUE options)
26
52
  {
27
53
  GET_FILE(source);
28
54
  GET_FILE(destination);
55
+ Check_Type(options, T_HASH);
29
56
  LZWS_EXT_GET_COMPRESSOR_OPTIONS(options);
57
+ LZWS_EXT_GET_BUFFER_LENGTH_OPTION(options, source_buffer_length);
58
+ LZWS_EXT_GET_BUFFER_LENGTH_OPTION(options, destination_buffer_length);
30
59
 
31
60
  lzws_result_t result = lzws_compress_file(
32
- source_file, buffer_length,
33
- destination_file, buffer_length,
61
+ source_file, source_buffer_length,
62
+ destination_file, destination_buffer_length,
34
63
  without_magic_header, max_code_bit_length, block_mode, msb, unaligned_bit_groups, quiet);
35
64
 
36
- if (result == LZWS_FILE_ALLOCATE_FAILED) {
37
- lzws_ext_raise_error("AllocateError", "allocate error");
38
- }
39
- else if (result == LZWS_FILE_VALIDATE_FAILED) {
40
- lzws_ext_raise_error("ValidateError", "validate error");
41
- }
42
- else if (result == LZWS_FILE_READ_FAILED) {
43
- lzws_ext_raise_error("ReadIOError", "failed to read IO");
44
- }
45
- else if (result == LZWS_FILE_WRITE_FAILED) {
46
- lzws_ext_raise_error("WriteIOError", "failed to write IO");
47
- }
48
- else if (result != 0) {
49
- lzws_ext_raise_error("UnexpectedError", "unexpected error");
65
+ if (result != 0) {
66
+ lzws_ext_raise_error(get_file_error(result));
50
67
  }
51
68
 
52
69
  // Ruby itself won't flush stdio file before closing fd, flush is required.
@@ -59,30 +76,18 @@ VALUE lzws_ext_decompress_io(VALUE LZWS_EXT_UNUSED(self), VALUE source, VALUE de
59
76
  {
60
77
  GET_FILE(source);
61
78
  GET_FILE(destination);
79
+ Check_Type(options, T_HASH);
62
80
  LZWS_EXT_GET_DECOMPRESSOR_OPTIONS(options);
81
+ LZWS_EXT_GET_BUFFER_LENGTH_OPTION(options, source_buffer_length);
82
+ LZWS_EXT_GET_BUFFER_LENGTH_OPTION(options, destination_buffer_length);
63
83
 
64
84
  lzws_result_t result = lzws_decompress_file(
65
- source_file, buffer_length,
66
- destination_file, buffer_length,
85
+ source_file, source_buffer_length,
86
+ destination_file, destination_buffer_length,
67
87
  without_magic_header, msb, unaligned_bit_groups, quiet);
68
88
 
69
- if (result == LZWS_FILE_ALLOCATE_FAILED) {
70
- lzws_ext_raise_error("AllocateError", "allocate error");
71
- }
72
- else if (result == LZWS_FILE_VALIDATE_FAILED) {
73
- lzws_ext_raise_error("ValidateError", "validate error");
74
- }
75
- else if (result == LZWS_FILE_DECOMPRESSOR_CORRUPTED_SOURCE) {
76
- lzws_ext_raise_error("DecompressorCorruptedSourceError", "decompressor received corrupted source");
77
- }
78
- else if (result == LZWS_FILE_READ_FAILED) {
79
- lzws_ext_raise_error("ReadIOError", "failed to read IO");
80
- }
81
- else if (result == LZWS_FILE_WRITE_FAILED) {
82
- lzws_ext_raise_error("WriteIOError", "failed to write IO");
83
- }
84
- else if (result != 0) {
85
- lzws_ext_raise_error("UnexpectedError", "unexpected error");
89
+ if (result != 0) {
90
+ lzws_ext_raise_error(get_file_error(result));
86
91
  }
87
92
 
88
93
  // Ruby itself won't flush stdio file before closing fd, flush is required.
@@ -90,3 +95,9 @@ VALUE lzws_ext_decompress_io(VALUE LZWS_EXT_UNUSED(self), VALUE source, VALUE de
90
95
 
91
96
  return Qnil;
92
97
  }
98
+
99
+ void lzws_ext_io_exports(VALUE root_module)
100
+ {
101
+ rb_define_module_function(root_module, "_native_compress_io", RUBY_METHOD_FUNC(lzws_ext_compress_io), 3);
102
+ rb_define_module_function(root_module, "_native_decompress_io", RUBY_METHOD_FUNC(lzws_ext_decompress_io), 3);
103
+ }
@@ -9,4 +9,6 @@
9
9
  VALUE lzws_ext_compress_io(VALUE self, VALUE source, VALUE destination, VALUE options);
10
10
  VALUE lzws_ext_decompress_io(VALUE self, VALUE source, VALUE destination, VALUE options);
11
11
 
12
+ void lzws_ext_io_exports(VALUE root_module);
13
+
12
14
  #endif // LZWS_EXT_IO_H
@@ -10,6 +10,4 @@
10
10
  #define LZWS_EXT_UNUSED(x) x
11
11
  #endif
12
12
 
13
- #define LZWS_EXT_UNUSED_VARIABLE(x) (void)(x)
14
-
15
13
  #endif // LZWS_EXT_MACRO_H
@@ -1,42 +1,20 @@
1
1
  // Ruby bindings for lzws library.
2
2
  // Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
- #include "ruby.h"
5
-
6
- #include "lzws_ext/common.h"
4
+ #include "lzws_ext/buffer.h"
7
5
  #include "lzws_ext/io.h"
8
6
  #include "lzws_ext/stream/compressor.h"
9
7
  #include "lzws_ext/stream/decompressor.h"
10
8
  #include "lzws_ext/string.h"
9
+ #include "ruby.h"
11
10
 
12
11
  void Init_lzws_ext()
13
12
  {
14
- VALUE root = rb_define_module(LZWS_EXT_MODULE_NAME);
15
-
16
- // It is better to use these functions internally and prepare pretty wrappers for public usage.
17
- rb_define_module_function(root, "_native_compress_io", RUBY_METHOD_FUNC(lzws_ext_compress_io), 3);
18
- rb_define_module_function(root, "_native_decompress_io", RUBY_METHOD_FUNC(lzws_ext_decompress_io), 3);
19
- rb_define_module_function(root, "_native_compress_string", RUBY_METHOD_FUNC(lzws_ext_compress_string), 2);
20
- rb_define_module_function(root, "_native_decompress_string", RUBY_METHOD_FUNC(lzws_ext_decompress_string), 2);
21
-
22
- // -----
23
-
24
- VALUE stream = rb_define_module_under(root, "Stream");
25
-
26
- VALUE compressor = rb_define_class_under(stream, "NativeCompressor", rb_cObject);
27
- rb_define_alloc_func(compressor, lzws_ext_allocate_compressor);
28
- rb_define_method(compressor, "initialize", lzws_ext_initialize_compressor, 1);
29
- rb_define_method(compressor, "write_magic_header", lzws_ext_compressor_write_magic_header, 0);
30
- rb_define_method(compressor, "write", lzws_ext_compress, 1);
31
- rb_define_method(compressor, "flush", lzws_ext_flush_compressor, 0);
32
- rb_define_method(compressor, "read_result", lzws_ext_compressor_read_result, 0);
33
- rb_define_method(compressor, "close", lzws_ext_compressor_close, 0);
13
+ VALUE root_module = rb_define_module(LZWS_EXT_MODULE_NAME);
34
14
 
35
- VALUE decompressor = rb_define_class_under(stream, "NativeDecompressor", rb_cObject);
36
- rb_define_alloc_func(decompressor, lzws_ext_allocate_decompressor);
37
- rb_define_method(decompressor, "initialize", lzws_ext_initialize_decompressor, 1);
38
- rb_define_method(decompressor, "read_magic_header", lzws_ext_decompressor_read_magic_header, 1);
39
- rb_define_method(decompressor, "read", lzws_ext_decompress, 1);
40
- rb_define_method(decompressor, "read_result", lzws_ext_decompressor_read_result, 0);
41
- rb_define_method(decompressor, "close", lzws_ext_decompressor_close, 0);
15
+ lzws_ext_buffer_exports(root_module);
16
+ lzws_ext_io_exports(root_module);
17
+ lzws_ext_compressor_exports(root_module);
18
+ lzws_ext_decompressor_exports(root_module);
19
+ lzws_ext_string_exports(root_module);
42
20
  }
@@ -1,22 +1,42 @@
1
1
  // Ruby bindings for lzws library.
2
2
  // Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
- #include "ruby.h"
5
-
6
4
  #include "lzws_ext/option.h"
7
5
 
8
- VALUE lzws_ext_get_option(VALUE options, const char* name)
6
+ #include "lzws_ext/error.h"
7
+ #include "ruby.h"
8
+
9
+ static inline VALUE get_raw_option_value(VALUE options, const char* name)
9
10
  {
10
- VALUE name_symbol = ID2SYM(rb_intern(name));
11
- return rb_funcall(options, rb_intern("[]"), 1, name_symbol);
11
+ return rb_funcall(options, rb_intern("[]"), 1, ID2SYM(rb_intern(name)));
12
12
  }
13
13
 
14
- void lzws_ext_check_bool_type(VALUE option, const char* name)
14
+ bool lzws_ext_get_bool_option_value(VALUE options, const char* name)
15
15
  {
16
- int type = TYPE(option);
16
+ VALUE raw_value = get_raw_option_value(options, name);
17
17
 
18
- if (type != T_TRUE && type != T_FALSE) {
19
- VALUE message = rb_sprintf("wrong value for \"%s\" (expected true or false)", name);
20
- rb_exc_raise(rb_exc_new_str(rb_eFatal, message));
18
+ int raw_type = TYPE(raw_value);
19
+ if (raw_type != T_TRUE && raw_type != T_FALSE) {
20
+ lzws_ext_raise_error(LZWS_EXT_ERROR_VALIDATE_FAILED);
21
21
  }
22
+
23
+ return raw_type == T_TRUE;
24
+ }
25
+
26
+ unsigned int lzws_ext_get_uint_option_value(VALUE options, const char* name)
27
+ {
28
+ VALUE raw_value = get_raw_option_value(options, name);
29
+
30
+ Check_Type(raw_value, T_FIXNUM);
31
+
32
+ return NUM2UINT(raw_value);
33
+ }
34
+
35
+ size_t lzws_ext_get_size_option_value(VALUE options, const char* name)
36
+ {
37
+ VALUE raw_value = get_raw_option_value(options, name);
38
+
39
+ Check_Type(raw_value, T_FIXNUM);
40
+
41
+ return NUM2SIZET(raw_value);
22
42
  }
@@ -4,57 +4,40 @@
4
4
  #if !defined(LZWS_EXT_OPTIONS_H)
5
5
  #define LZWS_EXT_OPTIONS_H
6
6
 
7
+ #include <stdbool.h>
8
+ #include <stdlib.h>
9
+
10
+ #include "lzws_ext/common.h"
7
11
  #include "ruby.h"
8
12
 
9
- VALUE lzws_ext_get_option(VALUE options, const char* name);
10
- void lzws_ext_check_bool_type(VALUE option, const char* name);
11
-
12
- #define LZWS_EXT_GET_COMPRESSOR_OPTIONS(options) \
13
- Check_Type(options, T_HASH); \
14
- \
15
- VALUE buffer_length_value = lzws_ext_get_option(options, "buffer_length"); \
16
- VALUE without_magic_header_value = lzws_ext_get_option(options, "without_magic_header"); \
17
- VALUE max_code_bit_length_value = lzws_ext_get_option(options, "max_code_bit_length"); \
18
- VALUE block_mode_value = lzws_ext_get_option(options, "block_mode"); \
19
- VALUE msb_value = lzws_ext_get_option(options, "msb"); \
20
- VALUE unaligned_bit_groups_value = lzws_ext_get_option(options, "unaligned_bit_groups"); \
21
- VALUE quiet_value = lzws_ext_get_option(options, "quiet"); \
22
- \
23
- Check_Type(buffer_length_value, T_FIXNUM); \
24
- lzws_ext_check_bool_type(without_magic_header_value, "without_magic_header"); \
25
- Check_Type(max_code_bit_length_value, T_FIXNUM); \
26
- lzws_ext_check_bool_type(block_mode_value, "block_mode"); \
27
- lzws_ext_check_bool_type(msb_value, "msb"); \
28
- lzws_ext_check_bool_type(unaligned_bit_groups_value, "unaligned_bit_groups"); \
29
- lzws_ext_check_bool_type(quiet_value, "quiet"); \
30
- \
31
- size_t buffer_length = rb_num2uint(buffer_length_value); \
32
- bool without_magic_header = TYPE(without_magic_header_value) == T_TRUE; \
33
- uint_fast8_t max_code_bit_length = rb_num2uint(max_code_bit_length_value); \
34
- bool block_mode = TYPE(block_mode_value) == T_TRUE; \
35
- bool msb = TYPE(msb_value) == T_TRUE; \
36
- bool unaligned_bit_groups = TYPE(unaligned_bit_groups_value) == T_TRUE; \
37
- bool quiet = TYPE(quiet_value) == T_TRUE;
38
-
39
- #define LZWS_EXT_GET_DECOMPRESSOR_OPTIONS(options) \
40
- Check_Type(options, T_HASH); \
41
- \
42
- VALUE buffer_length_value = lzws_ext_get_option(options, "buffer_length"); \
43
- VALUE without_magic_header_value = lzws_ext_get_option(options, "without_magic_header"); \
44
- VALUE msb_value = lzws_ext_get_option(options, "msb"); \
45
- VALUE unaligned_bit_groups_value = lzws_ext_get_option(options, "unaligned_bit_groups"); \
46
- VALUE quiet_value = lzws_ext_get_option(options, "quiet"); \
47
- \
48
- Check_Type(buffer_length_value, T_FIXNUM); \
49
- lzws_ext_check_bool_type(without_magic_header_value, "without_magic_header"); \
50
- lzws_ext_check_bool_type(msb_value, "msb"); \
51
- lzws_ext_check_bool_type(unaligned_bit_groups_value, "unaligned_bit_groups"); \
52
- lzws_ext_check_bool_type(quiet_value, "quiet"); \
53
- \
54
- size_t buffer_length = rb_num2uint(buffer_length_value); \
55
- bool without_magic_header = TYPE(without_magic_header_value) == T_TRUE; \
56
- bool msb = TYPE(msb_value) == T_TRUE; \
57
- bool unaligned_bit_groups = TYPE(unaligned_bit_groups_value) == T_TRUE; \
58
- bool quiet = TYPE(quiet_value) == T_TRUE;
13
+ bool lzws_ext_get_bool_option_value(VALUE options, const char* name);
14
+ unsigned int lzws_ext_get_uint_option_value(VALUE options, const char* name);
15
+ size_t lzws_ext_get_size_option_value(VALUE options, const char* name);
16
+
17
+ #define LZWS_EXT_GET_BOOL_OPTION(options, name) \
18
+ bool name = lzws_ext_get_bool_option_value(options, #name);
19
+
20
+ #define LZWS_EXT_GET_UINT_OPTION(options, type, name) \
21
+ type name = lzws_ext_get_uint_option_value(options, #name);
22
+
23
+ #define LZWS_EXT_GET_SIZE_OPTION(options, name) \
24
+ size_t name = lzws_ext_get_size_option_value(options, #name);
25
+
26
+ #define LZWS_EXT_GET_COMPRESSOR_OPTIONS(options) \
27
+ LZWS_EXT_GET_BOOL_OPTION(options, without_magic_header); \
28
+ LZWS_EXT_GET_UINT_OPTION(options, lzws_ext_byte_fast_t, max_code_bit_length); \
29
+ LZWS_EXT_GET_BOOL_OPTION(options, block_mode); \
30
+ LZWS_EXT_GET_BOOL_OPTION(options, msb); \
31
+ LZWS_EXT_GET_BOOL_OPTION(options, unaligned_bit_groups); \
32
+ LZWS_EXT_GET_BOOL_OPTION(options, quiet);
33
+
34
+ #define LZWS_EXT_GET_DECOMPRESSOR_OPTIONS(options) \
35
+ LZWS_EXT_GET_BOOL_OPTION(options, without_magic_header); \
36
+ LZWS_EXT_GET_BOOL_OPTION(options, msb); \
37
+ LZWS_EXT_GET_BOOL_OPTION(options, unaligned_bit_groups); \
38
+ LZWS_EXT_GET_BOOL_OPTION(options, quiet);
39
+
40
+ #define LZWS_EXT_GET_BUFFER_LENGTH_OPTION(options, name) \
41
+ LZWS_EXT_GET_SIZE_OPTION(options, name);
59
42
 
60
43
  #endif // LZWS_EXT_OPTIONS_H