extlzma2 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7f84d15806e0cb31f8e0b59e2947b4f8de9bd471ba8943ad5e4cc664593169d3
4
+ data.tar.gz: 6750dc99dfb4b9213017cb47fde94e64b9876f2e289686825c29836fa632b539
5
+ SHA512:
6
+ metadata.gz: 64e5f7d38cca11899c5940d2e27977c29fd6f644d4196a14f2a72719233938c582c374cd4a4e3182d32c745f06476ce53e68dbbb6a921dd0d799f9b192068a5c
7
+ data.tar.gz: 86a2001fc1452cde9c38efac27cb4345a09eac91ac0eaed8b4752502778de88359fcb80fd30a5cf4aa9e04044011883dc337a414dcc57380a92e633b1e9e440b
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rspec_status ADDED
@@ -0,0 +1,17 @@
1
+ example_id | status | run_time |
2
+ ----------------------------------- | ------ | --------------- |
3
+ ./spec/decode_args_spec.rb[1:1:1] | passed | 0.00158 seconds |
4
+ ./spec/decode_args_spec.rb[1:2:1] | passed | 0.0001 seconds |
5
+ ./spec/decode_args_spec.rb[1:3:1] | passed | 0.0001 seconds |
6
+ ./spec/encode_args_spec.rb[1:1:1] | passed | 0.00074 seconds |
7
+ ./spec/encode_args_spec.rb[1:2:1] | passed | 0.0001 seconds |
8
+ ./spec/encode_args_spec.rb[1:3:1] | passed | 0.0001 seconds |
9
+ ./spec/encode_args_spec.rb[1:4:1] | passed | 0.00065 seconds |
10
+ ./spec/encode_args_spec.rb[1:5:1] | passed | 0.0001 seconds |
11
+ ./spec/encode_decode_spec.rb[1:1:1] | passed | 0.00174 seconds |
12
+ ./spec/encode_decode_spec.rb[1:2:1] | passed | 0.00014 seconds |
13
+ ./spec/encode_decode_spec.rb[1:3:1] | passed | 0.41257 seconds |
14
+ ./spec/encode_decode_spec.rb[1:4:1] | passed | 0.0002 seconds |
15
+ ./spec/encode_decode_spec.rb[1:5:1] | passed | 0.41836 seconds |
16
+ ./spec/encode_decode_spec.rb[1:6:1] | passed | 0.00096 seconds |
17
+ ./spec/encode_decode_spec.rb[1:7:1] | passed | 3.92 seconds |
data/.rubocop.yml ADDED
@@ -0,0 +1,42 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Metrics/AbcSize:
5
+ Max: 170
6
+
7
+ Metrics/BlockLength:
8
+ Max: 250
9
+
10
+ Metrics/ClassLength:
11
+ Max: 1000
12
+
13
+ Metrics/CyclomaticComplexity:
14
+ Max: 70
15
+
16
+ Metrics/MethodLength:
17
+ Max: 100
18
+
19
+ Metrics/ModuleLength:
20
+ Max: 1000
21
+
22
+ Metrics/ParameterLists:
23
+ Max: 50
24
+
25
+ Metrics/PerceivedComplexity:
26
+ Max: 80
27
+
28
+ Layout/SpaceInsideBlockBraces:
29
+ EnforcedStyle: no_space
30
+ SpaceBeforeBlockParameters: false
31
+
32
+ Style/Documentation:
33
+ Enabled: false
34
+
35
+ Style/NumericPredicate:
36
+ EnforcedStyle: comparison
37
+
38
+ Style/MultilineBlockChain:
39
+ Enabled: false
40
+
41
+ Style/SpecialGlobalVars:
42
+ EnforcedStyle: use_perl_names
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in extlzma2.gemspec
6
+ gemspec
7
+
8
+ gem 'rake'
9
+ gem 'rake-compiler'
10
+ gem 'rspec'
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ extlzma2 (2.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.5.0)
10
+ rake (13.0.6)
11
+ rake-compiler (1.2.0)
12
+ rake
13
+ rspec (3.12.0)
14
+ rspec-core (~> 3.12.0)
15
+ rspec-expectations (~> 3.12.0)
16
+ rspec-mocks (~> 3.12.0)
17
+ rspec-core (3.12.0)
18
+ rspec-support (~> 3.12.0)
19
+ rspec-expectations (3.12.0)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.12.0)
22
+ rspec-mocks (3.12.0)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.12.0)
25
+ rspec-support (3.12.0)
26
+
27
+ PLATFORMS
28
+ arm64-darwin-22
29
+
30
+ DEPENDENCIES
31
+ extlzma2!
32
+ rake
33
+ rake-compiler
34
+ rspec
35
+
36
+ BUNDLED WITH
37
+ 2.4.0.dev
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ extlzma license (2-clause BSD License)
2
+
3
+ Copyright (c) 2011, dearblue. All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or
6
+ without modification, are permitted provided that the following
7
+ conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright
10
+ notice, this list of conditions and the following disclaimer.
11
+ 2. Redistributions in binary form must reproduce the above copyright
12
+ notice, this list of conditions and the following disclaimer in
13
+ the documentation and/or other materials provided with the
14
+ distribution.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
+ HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,9 @@
1
+ This is a Ruby-3.2-compatible fork of [extlzma](https://rubygems.org/gems/extlzma)
2
+
3
+ # extlzma - lzma for Ruby
4
+
5
+ A Ruby binding of liblzma.
6
+
7
+ ## License
8
+
9
+ This gem is provided under the BSD 2-clause License.
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/extensiontask'
5
+ require 'rspec/core/rake_task'
6
+
7
+ task build: :compile
8
+
9
+ Rake::ExtensionTask.new('extlzma2') do |ext|
10
+ ext.lib_dir = 'lib/extlzma2'
11
+ end
12
+
13
+ task default: %i[clobber compile]
14
+
15
+ RSpec::Core::RakeTask.new(:spec)
@@ -0,0 +1,66 @@
1
+ #include "extlzma2.h"
2
+
3
+ // SECTION: LZMA::Constants
4
+
5
+ static VALUE mConstants;
6
+
7
+ void extlzma_init_Constants(void)
8
+ {
9
+ mConstants = rb_define_module_under(extlzma_mLZMA, "Constants");
10
+ rb_include_module(extlzma_mLZMA, mConstants);
11
+
12
+ // TODO: マクロを展開した状態で記述する。
13
+ // TODO: 目的は rdoc や yard で文書化できるようにするため。
14
+
15
+ #define DEFINE_CONSTANT(NAME, VALUE) \
16
+ { \
17
+ rb_define_const(mConstants, #NAME, VALUE); \
18
+ rb_define_const(mConstants, "LZMA_" #NAME, VALUE); \
19
+ }
20
+
21
+ DEFINE_CONSTANT(NICE_DEFAULT, SIZET2NUM(64));
22
+ DEFINE_CONSTANT(DEPTH_DEFAULT, SIZET2NUM(0));
23
+
24
+ DEFINE_CONSTANT(PRESET_DEFAULT, UINT2NUM(LZMA_PRESET_DEFAULT));
25
+ DEFINE_CONSTANT(PRESET_LEVEL_MASK, UINT2NUM(LZMA_PRESET_LEVEL_MASK));
26
+ DEFINE_CONSTANT(PRESET_EXTREME, UINT2NUM(LZMA_PRESET_EXTREME));
27
+ DEFINE_CONSTANT(DICT_SIZE_MIN, UINT2NUM(LZMA_DICT_SIZE_MIN));
28
+ DEFINE_CONSTANT(DICT_SIZE_DEFAULT, UINT2NUM(LZMA_DICT_SIZE_DEFAULT));
29
+ DEFINE_CONSTANT(LCLP_MIN, UINT2NUM(LZMA_LCLP_MIN));
30
+ DEFINE_CONSTANT(LCLP_MAX, UINT2NUM(LZMA_LCLP_MAX));
31
+ DEFINE_CONSTANT(LC_DEFAULT, UINT2NUM(LZMA_LC_DEFAULT));
32
+ DEFINE_CONSTANT(LP_DEFAULT, UINT2NUM(LZMA_LP_DEFAULT));
33
+ DEFINE_CONSTANT(PB_MIN, UINT2NUM(LZMA_PB_MIN));
34
+ DEFINE_CONSTANT(PB_MAX, UINT2NUM(LZMA_PB_MAX));
35
+ DEFINE_CONSTANT(PB_DEFAULT, UINT2NUM(LZMA_PB_DEFAULT));
36
+ DEFINE_CONSTANT(MODE_FAST, UINT2NUM(LZMA_MODE_FAST));
37
+ DEFINE_CONSTANT(MODE_NORMAL, UINT2NUM(LZMA_MODE_NORMAL));
38
+ DEFINE_CONSTANT(MF_HC3, UINT2NUM(LZMA_MF_HC3));
39
+ DEFINE_CONSTANT(MF_HC4, UINT2NUM(LZMA_MF_HC4));
40
+ DEFINE_CONSTANT(MF_BT2, UINT2NUM(LZMA_MF_BT2));
41
+ DEFINE_CONSTANT(MF_BT3, UINT2NUM(LZMA_MF_BT3));
42
+ DEFINE_CONSTANT(MF_BT4, UINT2NUM(LZMA_MF_BT4));
43
+
44
+ DEFINE_CONSTANT(CHECK_NONE, UINT2NUM(LZMA_CHECK_NONE));
45
+ DEFINE_CONSTANT(CHECK_CRC32, UINT2NUM(LZMA_CHECK_CRC32));
46
+ DEFINE_CONSTANT(CHECK_CRC64, UINT2NUM(LZMA_CHECK_CRC64));
47
+ DEFINE_CONSTANT(CHECK_SHA256, UINT2NUM(LZMA_CHECK_SHA256));
48
+
49
+ DEFINE_CONSTANT(RUN, UINT2NUM(LZMA_RUN));
50
+ DEFINE_CONSTANT(FULL_FLUSH, UINT2NUM(LZMA_FULL_FLUSH));
51
+ DEFINE_CONSTANT(SYNC_FLUSH, UINT2NUM(LZMA_SYNC_FLUSH));
52
+ DEFINE_CONSTANT(FINISH, UINT2NUM(LZMA_FINISH));
53
+
54
+ DEFINE_CONSTANT(OK, UINT2NUM(LZMA_OK));
55
+ DEFINE_CONSTANT(STREAM_END, UINT2NUM(LZMA_STREAM_END));
56
+ DEFINE_CONSTANT(NO_CHECK, UINT2NUM(LZMA_NO_CHECK));
57
+ DEFINE_CONSTANT(UNSUPPORTED_CHECK, UINT2NUM(LZMA_UNSUPPORTED_CHECK));
58
+ DEFINE_CONSTANT(GET_CHECK, UINT2NUM(LZMA_GET_CHECK));
59
+ DEFINE_CONSTANT(MEM_ERROR, UINT2NUM(LZMA_MEM_ERROR));
60
+ DEFINE_CONSTANT(MEMLIMIT_ERROR, UINT2NUM(LZMA_MEMLIMIT_ERROR));
61
+ DEFINE_CONSTANT(FORMAT_ERROR, UINT2NUM(LZMA_FORMAT_ERROR));
62
+ DEFINE_CONSTANT(OPTIONS_ERROR, UINT2NUM(LZMA_OPTIONS_ERROR));
63
+ DEFINE_CONSTANT(DATA_ERROR, UINT2NUM(LZMA_DATA_ERROR));
64
+ DEFINE_CONSTANT(BUF_ERROR, UINT2NUM(LZMA_BUF_ERROR));
65
+ DEFINE_CONSTANT(PROG_ERROR, UINT2NUM(LZMA_PROG_ERROR));
66
+ }
@@ -0,0 +1,87 @@
1
+ #include "extlzma2.h"
2
+
3
+ // TODO: 例外を整理して数を減らす。
4
+
5
+ VALUE extlzma_mExceptions;
6
+ VALUE extlzma_eBasicException;
7
+ VALUE extlzma_eStreamEnd;
8
+ VALUE extlzma_eNoCheck;
9
+ VALUE extlzma_eUnsupportedCheck;
10
+ VALUE extlzma_eGetCheck;
11
+ VALUE extlzma_eMemError;
12
+ VALUE extlzma_eMemlimitError;
13
+ VALUE extlzma_eFormatError;
14
+ VALUE extlzma_eOptionsError;
15
+ VALUE extlzma_eDataError;
16
+ VALUE extlzma_eBufError;
17
+ VALUE extlzma_eProgError;
18
+ VALUE extlzma_eFilterTooLong;
19
+ VALUE extlzma_eBadPreset;
20
+
21
+ static inline VALUE lookup_exception(lzma_ret status)
22
+ {
23
+ switch (status)
24
+ {
25
+ case LZMA_OK:
26
+ return Qnil;
27
+ case LZMA_STREAM_END:
28
+ return extlzma_eStreamEnd;
29
+ case LZMA_NO_CHECK:
30
+ return extlzma_eNoCheck;
31
+ case LZMA_UNSUPPORTED_CHECK:
32
+ return extlzma_eUnsupportedCheck;
33
+ case LZMA_GET_CHECK:
34
+ return extlzma_eGetCheck;
35
+ case LZMA_MEM_ERROR:
36
+ return extlzma_eMemError;
37
+ case LZMA_MEMLIMIT_ERROR:
38
+ return extlzma_eMemlimitError;
39
+ case LZMA_FORMAT_ERROR:
40
+ return extlzma_eFormatError;
41
+ case LZMA_OPTIONS_ERROR:
42
+ return extlzma_eOptionsError;
43
+ case LZMA_DATA_ERROR:
44
+ return extlzma_eDataError;
45
+ case LZMA_BUF_ERROR:
46
+ return extlzma_eBufError;
47
+ case LZMA_PROG_ERROR:
48
+ return extlzma_eProgError;
49
+ default:
50
+ return rb_eRuntimeError;
51
+ }
52
+ }
53
+
54
+ VALUE extlzma_lookup_error(lzma_ret status)
55
+ {
56
+ return lookup_exception(status);
57
+ }
58
+
59
+ void extlzma_init_Exceptions(void)
60
+ {
61
+ extlzma_mExceptions = rb_define_module_under(extlzma_mLZMA, "Exceptions");
62
+ rb_include_module(extlzma_mLZMA, extlzma_mExceptions);
63
+
64
+ extlzma_eBasicException = rb_define_class_under(extlzma_mExceptions, "BasicException", rb_eStandardError);
65
+ rb_define_class_under(extlzma_mExceptions, "FilterTooLong", extlzma_eBasicException);
66
+ rb_define_class_under(extlzma_mExceptions, "BadPreset", extlzma_eBasicException);
67
+
68
+ #define DEFINE_EXCEPTION(CLASS, STATUS) \
69
+ { \
70
+ extlzma_e##CLASS = \
71
+ rb_define_class_under(extlzma_mExceptions, \
72
+ #CLASS, extlzma_eBasicException); \
73
+ rb_define_const(extlzma_e##CLASS, "STATUS", SIZET2NUM(STATUS)); \
74
+ }
75
+
76
+ DEFINE_EXCEPTION(StreamEnd, LZMA_STREAM_END);
77
+ DEFINE_EXCEPTION(NoCheck, LZMA_NO_CHECK);
78
+ DEFINE_EXCEPTION(UnsupportedCheck, LZMA_UNSUPPORTED_CHECK);
79
+ DEFINE_EXCEPTION(GetCheck, LZMA_GET_CHECK);
80
+ DEFINE_EXCEPTION(MemError, LZMA_MEM_ERROR);
81
+ DEFINE_EXCEPTION(MemlimitError, LZMA_MEMLIMIT_ERROR);
82
+ DEFINE_EXCEPTION(FormatError, LZMA_FORMAT_ERROR);
83
+ DEFINE_EXCEPTION(OptionsError, LZMA_OPTIONS_ERROR);
84
+ DEFINE_EXCEPTION(DataError, LZMA_DATA_ERROR);
85
+ DEFINE_EXCEPTION(BufError, LZMA_BUF_ERROR);
86
+ DEFINE_EXCEPTION(ProgError, LZMA_PROG_ERROR);
87
+ }
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mkmf'
4
+
5
+ # needlist = []
6
+
7
+ dir_config('liblzma')
8
+
9
+ have_header('lzma.h')
10
+ have_library('lzma')
11
+
12
+ # abort "#{$0}: dependency files are not found (#{needlist.join(' ')})." unless needlist.empty?
13
+
14
+ staticlink = arg_config('--liblzma-static-link', false)
15
+
16
+ if staticlink
17
+ # 静的ライブラリリンクを優先する
18
+ $libs = ['-Wl,-llzma', $libs].join(' ')
19
+ end
20
+
21
+ if RbConfig::CONFIG['arch'] =~ (/mingw/) && (try_link 'void main(void){}', ' -static-libgcc ')
22
+ $LDFLAGS << ' -static-libgcc '
23
+ end
24
+
25
+ $LDFLAGS << ' -Wl,-Bsymbolic ' if try_link 'void main(void){}', ' -Wl,-Bsymbolic '
26
+
27
+ create_makefile 'extlzma2/extlzma2'
@@ -0,0 +1,89 @@
1
+ /*
2
+ * liblzma.c -
3
+ * - Author: dearblue <dearblue@users.osdn.me>
4
+ * - Copyright: Copyright (c) 2010 dearblue
5
+ * - License: Distributed under the 2-clause BSD License
6
+ */
7
+
8
+ #include "extlzma2.h"
9
+
10
+ VALUE extlzma_mLZMA;
11
+
12
+ ID extlzma_id_dictsize;
13
+ ID extlzma_id_predict;
14
+ ID extlzma_id_lc;
15
+ ID extlzma_id_lp;
16
+ ID extlzma_id_pb;
17
+ ID extlzma_id_mode;
18
+ ID extlzma_id_nice;
19
+ ID extlzma_id_mf;
20
+ ID extlzma_id_depth;
21
+ ID extlzma_id_check;
22
+ ID extlzma_id_none;
23
+ ID extlzma_id_crc32;
24
+ ID extlzma_id_crc64;
25
+ ID extlzma_id_sha256;
26
+
27
+ static VALUE libver_major(VALUE obj)
28
+ {
29
+ return INT2FIX(LZMA_VERSION_MAJOR);
30
+ }
31
+
32
+ static VALUE libver_minor(VALUE obj)
33
+ {
34
+ return INT2FIX(LZMA_VERSION_MINOR);
35
+ }
36
+
37
+ static VALUE libver_patch(VALUE obj)
38
+ {
39
+ return INT2FIX(LZMA_VERSION_PATCH);
40
+ }
41
+
42
+ static VALUE libver_to_s(VALUE obj)
43
+ {
44
+ return rb_str_new_cstr(LZMA_VERSION_STRING);
45
+ }
46
+
47
+ static void extlzma_init_LIBVER(void)
48
+ {
49
+ VALUE vers[] = {
50
+ INT2FIX(LZMA_VERSION_MAJOR),
51
+ INT2FIX(LZMA_VERSION_MINOR),
52
+ INT2FIX(LZMA_VERSION_PATCH)};
53
+
54
+ VALUE libver = rb_ary_new4(ELEMENTOF(vers), vers);
55
+ rb_define_singleton_method(libver, "major", RUBY_METHOD_FUNC(libver_major), 0);
56
+ rb_define_singleton_method(libver, "minor", RUBY_METHOD_FUNC(libver_minor), 0);
57
+ rb_define_singleton_method(libver, "patch", RUBY_METHOD_FUNC(libver_patch), 0);
58
+ rb_define_singleton_method(libver, "to_s", RUBY_METHOD_FUNC(libver_to_s), 0);
59
+ rb_define_const(extlzma_mLZMA, "LIBRARY_VERSION", rb_ary_freeze(libver));
60
+ }
61
+
62
+ void Init_extlzma2(void)
63
+ {
64
+ extlzma_id_dictsize = rb_intern("dictsize");
65
+ extlzma_id_predict = rb_intern("predict");
66
+ extlzma_id_lc = rb_intern("lc");
67
+ extlzma_id_lp = rb_intern("lp");
68
+ extlzma_id_pb = rb_intern("pb");
69
+ extlzma_id_mode = rb_intern("mode");
70
+ extlzma_id_nice = rb_intern("nice");
71
+ extlzma_id_mf = rb_intern("mf");
72
+ extlzma_id_depth = rb_intern("depth");
73
+ extlzma_id_check = rb_intern("check");
74
+ extlzma_id_none = rb_intern("none");
75
+ extlzma_id_crc32 = rb_intern("crc32");
76
+ extlzma_id_crc64 = rb_intern("crc64");
77
+ extlzma_id_sha256 = rb_intern("sha256");
78
+
79
+ extlzma_mLZMA = rb_define_module("LZMA");
80
+ rb_define_const(extlzma_mLZMA, "LZMA", extlzma_mLZMA);
81
+
82
+ extlzma_init_Utils();
83
+ extlzma_init_Constants();
84
+ extlzma_init_Exceptions();
85
+ extlzma_init_Filter();
86
+ extlzma_init_Stream();
87
+ extlzma_init_Index();
88
+ extlzma_init_LIBVER();
89
+ }
@@ -0,0 +1,171 @@
1
+ #ifndef EXTLZMA_H
2
+ #define EXTLZMA_H 1
3
+
4
+ #include <stdarg.h>
5
+ #include <lzma.h>
6
+ #include <ruby.h>
7
+ #include <ruby/thread.h>
8
+ #include <ruby/intern.h>
9
+
10
+ #define LOG \
11
+ { \
12
+ fprintf(stderr, "%s:%d:%s\n", __FILE__, __LINE__, __func__); \
13
+ }
14
+
15
+ #define LOGF(FORMAT, ...) \
16
+ { \
17
+ fprintf(stderr, "%s:%d:%s: " FORMAT "\n", \
18
+ __FILE__, __LINE__, __func__, ##__VA_ARGS__); \
19
+ }
20
+
21
+ #define ELEMENTOF(VECT) (sizeof(VECT) / sizeof((VECT)[0]))
22
+
23
+ #define AUX_FUNCALL(RECV, METHOD, ...) \
24
+ ({ \
25
+ VALUE args__aux_funcall__[] = {__VA_ARGS__}; \
26
+ rb_funcall2((RECV), (METHOD), \
27
+ ELEMENTOF(args__aux_funcall__), \
28
+ args__aux_funcall__); \
29
+ })
30
+
31
+ extern VALUE extlzma_mLZMA;
32
+ extern VALUE extlzma_cFilter;
33
+ extern VALUE extlzma_cStream;
34
+ extern VALUE extlzma_mExceptions;
35
+
36
+ extern VALUE extlzma_eBasicException;
37
+ extern VALUE extlzma_eStreamEnd;
38
+ extern VALUE extlzma_eNoCheck;
39
+ extern VALUE extlzma_eUnsupportedCheck;
40
+ extern VALUE extlzma_eGetCheck;
41
+ extern VALUE extlzma_eMemError;
42
+ extern VALUE extlzma_eMemlimitError;
43
+ extern VALUE extlzma_eFormatError;
44
+ extern VALUE extlzma_eOptionsError;
45
+ extern VALUE extlzma_eDataError;
46
+ extern VALUE extlzma_eBufError;
47
+ extern VALUE extlzma_eProgError;
48
+ extern VALUE extlzma_eFilterTooLong;
49
+ extern VALUE extlzma_eBadPreset;
50
+
51
+ extern ID extlzma_id_dictsize;
52
+ extern ID extlzma_id_predict;
53
+ extern ID extlzma_id_lc;
54
+ extern ID extlzma_id_lp;
55
+ extern ID extlzma_id_pb;
56
+ extern ID extlzma_id_mode;
57
+ extern ID extlzma_id_nice;
58
+ extern ID extlzma_id_mf;
59
+ extern ID extlzma_id_depth;
60
+ extern ID extlzma_id_check;
61
+ extern ID extlzma_id_none;
62
+ extern ID extlzma_id_crc32;
63
+ extern ID extlzma_id_crc64;
64
+ extern ID extlzma_id_sha256;
65
+
66
+ extern void extlzma_init_Stream(void);
67
+ extern void extlzma_init_Utils(void);
68
+ extern void extlzma_init_Constants(void);
69
+ extern void extlzma_init_Exceptions(void);
70
+ extern void extlzma_init_Filter(void);
71
+ extern void extlzma_init_Index(void);
72
+ extern VALUE extlzma_lookup_error(lzma_ret status);
73
+
74
+ static inline int aux_lzma_isfailed(lzma_ret status)
75
+ {
76
+ return status != 0;
77
+ }
78
+
79
+ static inline void aux_lzma_test(lzma_ret status)
80
+ {
81
+ if (aux_lzma_isfailed(status))
82
+ {
83
+ VALUE exc = extlzma_lookup_error(status);
84
+ exc = rb_exc_new2(exc, "failed lzma processing");
85
+ rb_exc_raise(exc);
86
+ }
87
+ }
88
+
89
+ #define AUX_LZMA_TEST(STATUS) aux_lzma_test((STATUS))
90
+
91
+ static inline void *checkref(VALUE obj, void *p)
92
+ {
93
+ if (!p)
94
+ {
95
+ rb_raise(rb_eArgError,
96
+ "not initialized yet - #<%s:%p>",
97
+ rb_obj_classname(obj), (void *)obj);
98
+ }
99
+
100
+ return p;
101
+ }
102
+
103
+ static inline void *check_notref(VALUE obj, void *p)
104
+ {
105
+ if (p)
106
+ {
107
+ rb_raise(rb_eArgError,
108
+ "already initialized - #<%s:%p>",
109
+ rb_obj_classname(obj), (void *)obj);
110
+ }
111
+
112
+ return p;
113
+ }
114
+
115
+ static inline void *getrefp(VALUE obj)
116
+ {
117
+ void *p;
118
+ Data_Get_Struct(obj, void, p);
119
+ return p;
120
+ }
121
+
122
+ static inline void *getref(VALUE obj)
123
+ {
124
+ return checkref(obj, getrefp(obj));
125
+ }
126
+
127
+ static inline lzma_filter *getfilterp(VALUE obj)
128
+ {
129
+ return getrefp(obj);
130
+ }
131
+
132
+ static inline lzma_filter *extlzma_getfilter(VALUE obj)
133
+ {
134
+ return getref(obj);
135
+ }
136
+
137
+ // rdoc に対して定義されているものと錯覚させるマクロ
138
+ #define RDOCFAKE(...)
139
+
140
+ #define EXTLZMA_NOT_REACHABLE \
141
+ rb_bug("NOT REACHABLE HERE - %s:%d(%s)", \
142
+ __FILE__, __LINE__, __func__);
143
+
144
+ static inline void *aux_thread_call_without_gvl_main(void *pp)
145
+ {
146
+ va_list *p = (va_list *)pp;
147
+ void *(*func)(void *) = va_arg(*p, void *(*)(void *));
148
+ va_list *va2 = va_arg(*p, va_list *);
149
+ return func(va2);
150
+ }
151
+
152
+ static inline void *aux_thread_call_without_gvl_dummy(void *dummy, ...)
153
+ {
154
+ va_list va;
155
+ va_start(va, dummy);
156
+ void *p = rb_thread_call_without_gvl(
157
+ aux_thread_call_without_gvl_main, &va, RUBY_UBF_PROCESS, 0);
158
+ va_end(va);
159
+ return p;
160
+ }
161
+
162
+ static inline void *aux_thread_call_without_gvl(void *(*func)(va_list *), ...)
163
+ {
164
+ va_list va;
165
+ va_start(va, func);
166
+ void *p = aux_thread_call_without_gvl_dummy(0, func, &va);
167
+ va_end(va);
168
+ return p;
169
+ }
170
+
171
+ #endif /* EXTLZMA_H */