extzstd 0.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +5 -5
  2. data/HISTORY.ja.md +39 -0
  3. data/README.md +38 -56
  4. data/contrib/zstd/CHANGELOG +613 -0
  5. data/contrib/zstd/CODE_OF_CONDUCT.md +5 -0
  6. data/contrib/zstd/CONTRIBUTING.md +406 -0
  7. data/contrib/zstd/COPYING +339 -0
  8. data/contrib/zstd/Makefile +420 -0
  9. data/contrib/zstd/README.md +179 -41
  10. data/contrib/zstd/TESTING.md +44 -0
  11. data/contrib/zstd/appveyor.yml +292 -0
  12. data/contrib/zstd/lib/BUCK +234 -0
  13. data/contrib/zstd/lib/Makefile +451 -0
  14. data/contrib/zstd/lib/README.md +207 -0
  15. data/contrib/zstd/{common → lib/common}/bitstream.h +187 -138
  16. data/contrib/zstd/lib/common/compiler.h +288 -0
  17. data/contrib/zstd/lib/common/cpu.h +213 -0
  18. data/contrib/zstd/lib/common/debug.c +24 -0
  19. data/contrib/zstd/lib/common/debug.h +107 -0
  20. data/contrib/zstd/lib/common/entropy_common.c +362 -0
  21. data/contrib/zstd/{common → lib/common}/error_private.c +25 -12
  22. data/contrib/zstd/{common → lib/common}/error_private.h +14 -10
  23. data/contrib/zstd/{common → lib/common}/fse.h +173 -92
  24. data/contrib/zstd/{common → lib/common}/fse_decompress.c +149 -85
  25. data/contrib/zstd/lib/common/huf.h +361 -0
  26. data/contrib/zstd/{common → lib/common}/mem.h +115 -59
  27. data/contrib/zstd/lib/common/pool.c +350 -0
  28. data/contrib/zstd/lib/common/pool.h +84 -0
  29. data/contrib/zstd/lib/common/threading.c +122 -0
  30. data/contrib/zstd/lib/common/threading.h +155 -0
  31. data/contrib/zstd/{common → lib/common}/xxhash.c +55 -96
  32. data/contrib/zstd/{common → lib/common}/xxhash.h +23 -47
  33. data/contrib/zstd/lib/common/zstd_common.c +83 -0
  34. data/contrib/zstd/lib/common/zstd_deps.h +111 -0
  35. data/contrib/zstd/lib/common/zstd_errors.h +95 -0
  36. data/contrib/zstd/lib/common/zstd_internal.h +478 -0
  37. data/contrib/zstd/{compress → lib/compress}/fse_compress.c +214 -319
  38. data/contrib/zstd/lib/compress/hist.c +181 -0
  39. data/contrib/zstd/lib/compress/hist.h +75 -0
  40. data/contrib/zstd/lib/compress/huf_compress.c +913 -0
  41. data/contrib/zstd/lib/compress/zstd_compress.c +5208 -0
  42. data/contrib/zstd/lib/compress/zstd_compress_internal.h +1203 -0
  43. data/contrib/zstd/lib/compress/zstd_compress_literals.c +158 -0
  44. data/contrib/zstd/lib/compress/zstd_compress_literals.h +29 -0
  45. data/contrib/zstd/lib/compress/zstd_compress_sequences.c +433 -0
  46. data/contrib/zstd/lib/compress/zstd_compress_sequences.h +54 -0
  47. data/contrib/zstd/lib/compress/zstd_compress_superblock.c +849 -0
  48. data/contrib/zstd/lib/compress/zstd_compress_superblock.h +32 -0
  49. data/contrib/zstd/lib/compress/zstd_cwksp.h +561 -0
  50. data/contrib/zstd/lib/compress/zstd_double_fast.c +521 -0
  51. data/contrib/zstd/lib/compress/zstd_double_fast.h +38 -0
  52. data/contrib/zstd/lib/compress/zstd_fast.c +496 -0
  53. data/contrib/zstd/lib/compress/zstd_fast.h +37 -0
  54. data/contrib/zstd/lib/compress/zstd_lazy.c +1412 -0
  55. data/contrib/zstd/lib/compress/zstd_lazy.h +87 -0
  56. data/contrib/zstd/lib/compress/zstd_ldm.c +660 -0
  57. data/contrib/zstd/lib/compress/zstd_ldm.h +116 -0
  58. data/contrib/zstd/lib/compress/zstd_opt.c +1345 -0
  59. data/contrib/zstd/lib/compress/zstd_opt.h +56 -0
  60. data/contrib/zstd/lib/compress/zstdmt_compress.c +1811 -0
  61. data/contrib/zstd/lib/compress/zstdmt_compress.h +110 -0
  62. data/contrib/zstd/lib/decompress/huf_decompress.c +1350 -0
  63. data/contrib/zstd/lib/decompress/zstd_ddict.c +244 -0
  64. data/contrib/zstd/lib/decompress/zstd_ddict.h +44 -0
  65. data/contrib/zstd/lib/decompress/zstd_decompress.c +1930 -0
  66. data/contrib/zstd/lib/decompress/zstd_decompress_block.c +1540 -0
  67. data/contrib/zstd/lib/decompress/zstd_decompress_block.h +62 -0
  68. data/contrib/zstd/lib/decompress/zstd_decompress_internal.h +190 -0
  69. data/contrib/zstd/{common → lib/deprecated}/zbuff.h +68 -45
  70. data/contrib/zstd/lib/deprecated/zbuff_common.c +26 -0
  71. data/contrib/zstd/lib/deprecated/zbuff_compress.c +147 -0
  72. data/contrib/zstd/lib/deprecated/zbuff_decompress.c +75 -0
  73. data/contrib/zstd/lib/dictBuilder/cover.c +1245 -0
  74. data/contrib/zstd/lib/dictBuilder/cover.h +157 -0
  75. data/contrib/zstd/{dictBuilder → lib/dictBuilder}/divsufsort.c +3 -3
  76. data/contrib/zstd/{dictBuilder → lib/dictBuilder}/divsufsort.h +0 -0
  77. data/contrib/zstd/lib/dictBuilder/fastcover.c +758 -0
  78. data/contrib/zstd/{dictBuilder → lib/dictBuilder}/zdict.c +318 -194
  79. data/contrib/zstd/lib/dictBuilder/zdict.h +305 -0
  80. data/contrib/zstd/{legacy → lib/legacy}/zstd_legacy.h +171 -15
  81. data/contrib/zstd/{legacy → lib/legacy}/zstd_v01.c +191 -124
  82. data/contrib/zstd/{legacy → lib/legacy}/zstd_v01.h +19 -5
  83. data/contrib/zstd/{legacy → lib/legacy}/zstd_v02.c +125 -125
  84. data/contrib/zstd/{legacy → lib/legacy}/zstd_v02.h +19 -5
  85. data/contrib/zstd/{legacy → lib/legacy}/zstd_v03.c +125 -124
  86. data/contrib/zstd/{legacy → lib/legacy}/zstd_v03.h +20 -6
  87. data/contrib/zstd/{legacy → lib/legacy}/zstd_v04.c +151 -299
  88. data/contrib/zstd/{legacy → lib/legacy}/zstd_v04.h +19 -5
  89. data/contrib/zstd/{legacy → lib/legacy}/zstd_v05.c +237 -243
  90. data/contrib/zstd/{legacy → lib/legacy}/zstd_v05.h +19 -6
  91. data/contrib/zstd/{legacy → lib/legacy}/zstd_v06.c +130 -143
  92. data/contrib/zstd/{legacy → lib/legacy}/zstd_v06.h +18 -5
  93. data/contrib/zstd/{legacy → lib/legacy}/zstd_v07.c +158 -157
  94. data/contrib/zstd/{legacy → lib/legacy}/zstd_v07.h +19 -5
  95. data/contrib/zstd/lib/libzstd.pc.in +15 -0
  96. data/contrib/zstd/lib/zstd.h +2391 -0
  97. data/ext/depend +2 -0
  98. data/ext/extconf.rb +15 -6
  99. data/ext/extzstd.c +76 -145
  100. data/ext/extzstd.h +80 -31
  101. data/ext/extzstd_stream.c +417 -142
  102. data/ext/libzstd_conf.h +8 -0
  103. data/ext/zstd_common.c +10 -7
  104. data/ext/zstd_compress.c +14 -5
  105. data/ext/zstd_decompress.c +5 -4
  106. data/ext/zstd_dictbuilder.c +9 -4
  107. data/ext/zstd_dictbuilder_fastcover.c +3 -0
  108. data/ext/zstd_legacy_v01.c +3 -1
  109. data/ext/zstd_legacy_v02.c +3 -1
  110. data/ext/zstd_legacy_v03.c +3 -1
  111. data/ext/zstd_legacy_v04.c +3 -1
  112. data/ext/zstd_legacy_v05.c +3 -1
  113. data/ext/zstd_legacy_v06.c +3 -1
  114. data/ext/zstd_legacy_v07.c +3 -1
  115. data/gemstub.rb +10 -24
  116. data/lib/extzstd.rb +64 -179
  117. data/lib/extzstd/version.rb +6 -1
  118. data/test/test_basic.rb +9 -6
  119. metadata +113 -57
  120. data/HISTORY.ja +0 -5
  121. data/contrib/zstd/common/entropy_common.c +0 -225
  122. data/contrib/zstd/common/huf.h +0 -228
  123. data/contrib/zstd/common/zstd_common.c +0 -83
  124. data/contrib/zstd/common/zstd_errors.h +0 -60
  125. data/contrib/zstd/common/zstd_internal.h +0 -267
  126. data/contrib/zstd/compress/huf_compress.c +0 -533
  127. data/contrib/zstd/compress/zbuff_compress.c +0 -319
  128. data/contrib/zstd/compress/zstd_compress.c +0 -3264
  129. data/contrib/zstd/compress/zstd_opt.h +0 -900
  130. data/contrib/zstd/decompress/huf_decompress.c +0 -883
  131. data/contrib/zstd/decompress/zbuff_decompress.c +0 -252
  132. data/contrib/zstd/decompress/zstd_decompress.c +0 -1842
  133. data/contrib/zstd/dictBuilder/zdict.h +0 -111
  134. data/contrib/zstd/zstd.h +0 -640
data/ext/depend ADDED
@@ -0,0 +1,2 @@
1
+ extzstd.o: extzstd.c extzstd.h
2
+ extzstd_stream.o: extzstd_stream.c extzstd.h extzstd_nogvls.h
data/ext/extconf.rb CHANGED
@@ -4,10 +4,10 @@ require "mkmf"
4
4
 
5
5
  $INCFLAGS = %w(
6
6
  -I$(srcdir)/../contrib
7
- -I$(srcdir)/../contrib/zstd
8
- -I$(srcdir)/../contrib/zstd/common
9
- -I$(srcdir)/../contrib/zstd/dictBuilder
10
- -I$(srcdir)/../contrib/zstd/legacy
7
+ -I$(srcdir)/../contrib/zstd/lib
8
+ -I$(srcdir)/../contrib/zstd/lib/common
9
+ -I$(srcdir)/../contrib/zstd/lib/dictBuilder
10
+ -I$(srcdir)/../contrib/zstd/lib/legacy
11
11
  ).join(" ") + " #$INCFLAGS"
12
12
 
13
13
  #dir = File.dirname(__FILE__).gsub(/[\[\{\?\*]/, "[\\0]")
@@ -17,8 +17,17 @@ $INCFLAGS = %w(
17
17
  #$srcs = files
18
18
  #$VPATH.push "$(srcdir)/../contrib/zstd", "$(srcdir)/../contrib/zstd/legacy"
19
19
 
20
- if RbConfig::CONFIG["arch"] =~ /mingw/
21
- $LDFLAGS << " -static-libgcc"
20
+ if RbConfig::CONFIG["arch"] =~ /mingw/i
21
+ $LDFLAGS << " -static-libgcc" if try_ldflags("-static-libgcc")
22
+ else
23
+ if try_compile(<<-"VISIBILITY")
24
+ __attribute__ ((visibility("hidden"))) int conftest(void) { return 0; }
25
+ VISIBILITY
26
+ if try_cflags("-fvisibility=hidden")
27
+ $CFLAGS << " -fvisibility=hidden"
28
+ $defs << %('-DRBEXT_API=__attribute__ ((visibility("default")))')
29
+ end
30
+ end
22
31
  end
23
32
 
24
33
  create_makefile File.join(RUBY_VERSION.slice(/\d+\.\d+/), "extzstd")
data/ext/extzstd.c CHANGED
@@ -1,38 +1,17 @@
1
1
  #include "extzstd.h"
2
- #include <zstd/common/mem.h>
2
+ #include <zstd/lib/common/mem.h>
3
3
  #include <zstd_errors.h>
4
4
  #include <zdict.h>
5
5
 
6
- static void
7
- aux_string_pointer(VALUE str, const char **ptr, size_t *size)
8
- {
9
- rb_check_type(str, RUBY_T_STRING);
10
- RSTRING_GETMEM(str, *ptr, *size);
11
- }
12
-
13
- static void
14
- aux_string_pointer_with_nil(VALUE str, const char **ptr, size_t *size)
15
- {
16
- if (NIL_P(str)) {
17
- *ptr = NULL;
18
- *size = 0;
19
- } else {
20
- aux_string_pointer(str, ptr, size);
21
- }
22
- }
23
-
24
- static void
25
- aux_string_expand_pointer(VALUE str, char **ptr, size_t size)
26
- {
27
- rb_check_type(str, RUBY_T_STRING);
28
- rb_str_modify(str);
29
- rb_str_set_len(str, 0);
30
- rb_str_modify_expand(str, size);
31
- *ptr = RSTRING_PTR(str);
32
- }
6
+ #ifndef RB_EXT_RACTOR_SAFE
7
+ # define RB_EXT_RACTOR_SAFE(FEATURE) ((void)(FEATURE))
8
+ #endif
33
9
 
34
10
  VALUE extzstd_mZstd;
35
11
 
12
+ static ID id_initialize;
13
+ static ID id_error_code;
14
+
36
15
  /*
37
16
  * constant Zstd::LIBRARY_VERSION
38
17
  */
@@ -83,25 +62,6 @@ init_libver(void)
83
62
  VALUE extzstd_mExceptions;
84
63
 
85
64
  VALUE extzstd_eError;
86
- VALUE extzstd_eError;
87
- VALUE extzstd_eGenericError;
88
- VALUE extzstd_ePrefixUnknownError;
89
- VALUE extzstd_eFrameParameterUnsupportedError;
90
- VALUE extzstd_eFrameParameterUnsupportedBy32bitsError;
91
- VALUE extzstd_eCompressionParameterUnsupportedError;
92
- VALUE extzstd_eInitMissingError;
93
- VALUE extzstd_eMemoryAllocationError;
94
- VALUE extzstd_eStageWrongError;
95
- VALUE extzstd_eDstSizeTooSmallError;
96
- VALUE extzstd_eSrcSizeWrongError;
97
- VALUE extzstd_eCorruptionDetectedError;
98
- VALUE extzstd_eChecksumWrongError;
99
- VALUE extzstd_eTableLogTooLargeError;
100
- VALUE extzstd_eMaxSymbolValueTooLargeError;
101
- VALUE extzstd_eMaxSymbolValueTooSmallError;
102
- VALUE extzstd_eDictionaryCorruptedError;
103
- VALUE extzstd_eDictionaryWrongError;
104
-
105
65
 
106
66
  void
107
67
  extzstd_check_error(ssize_t errcode)
@@ -118,16 +78,20 @@ extzstd_error(ssize_t errcode)
118
78
  }
119
79
 
120
80
  VALUE
121
- extzstd_make_errorf(VALUE exc, const char *fmt, ...)
81
+ extzstd_make_errorf(ssize_t errcode, const char *fmt, ...)
122
82
  {
83
+ VALUE e;
84
+
123
85
  if (fmt && strlen(fmt) > 0) {
86
+ VALUE args[] = { SSIZET2NUM(errcode), Qnil };
124
87
  va_list va;
125
88
  va_start(va, fmt);
126
- VALUE mesg = rb_vsprintf(fmt, va);
89
+ args[1] = rb_vsprintf(fmt, va);
127
90
  va_end(va);
128
- return rb_exc_new3(exc, mesg);
91
+ return rb_class_new_instance(2, args, extzstd_eError);
129
92
  } else {
130
- return rb_exc_new2(exc, "");
93
+ VALUE args[] = { SSIZET2NUM(errcode) };
94
+ return rb_class_new_instance(1, args, extzstd_eError);
131
95
  }
132
96
  }
133
97
 
@@ -136,33 +100,34 @@ extzstd_make_error(ssize_t errcode)
136
100
  {
137
101
  if (!ZSTD_isError(errcode)) { return Qnil; }
138
102
 
139
- #define CASE_ERROR(zstderr, extzstderr, ...) \
140
- case zstderr: return extzstd_make_errorf(extzstderr, __VA_ARGS__); \
141
-
142
- switch (-errcode) {
143
- CASE_ERROR(ZSTD_error_GENERIC, extzstd_eGenericError, NULL);
144
- CASE_ERROR(ZSTD_error_prefix_unknown, extzstd_ePrefixUnknownError, NULL);
145
- CASE_ERROR(ZSTD_error_frameParameter_unsupported, extzstd_eFrameParameterUnsupportedError, NULL);
146
- CASE_ERROR(ZSTD_error_frameParameter_unsupportedBy32bits, extzstd_eFrameParameterUnsupportedBy32bitsError, NULL);
147
- CASE_ERROR(ZSTD_error_compressionParameter_unsupported, extzstd_eCompressionParameterUnsupportedError, NULL);
148
- CASE_ERROR(ZSTD_error_init_missing, extzstd_eInitMissingError, NULL);
149
- CASE_ERROR(ZSTD_error_memory_allocation, extzstd_eMemoryAllocationError, NULL);
150
- CASE_ERROR(ZSTD_error_stage_wrong, extzstd_eStageWrongError, NULL);
151
- CASE_ERROR(ZSTD_error_dstSize_tooSmall, extzstd_eDstSizeTooSmallError, NULL);
152
- CASE_ERROR(ZSTD_error_srcSize_wrong, extzstd_eSrcSizeWrongError, NULL);
153
- CASE_ERROR(ZSTD_error_corruption_detected, extzstd_eCorruptionDetectedError, NULL);
154
- CASE_ERROR(ZSTD_error_checksum_wrong, extzstd_eChecksumWrongError, NULL);
155
- CASE_ERROR(ZSTD_error_tableLog_tooLarge, extzstd_eTableLogTooLargeError, NULL);
156
- CASE_ERROR(ZSTD_error_maxSymbolValue_tooLarge, extzstd_eMaxSymbolValueTooLargeError, NULL);
157
- CASE_ERROR(ZSTD_error_maxSymbolValue_tooSmall, extzstd_eMaxSymbolValueTooSmallError, NULL);
158
- CASE_ERROR(ZSTD_error_dictionary_corrupted, extzstd_eDictionaryCorruptedError, NULL);
159
- CASE_ERROR(ZSTD_error_dictionary_wrong, extzstd_eDictionaryWrongError, NULL);
160
- default:
161
- return extzstd_make_errorf(extzstd_eError,
162
- "unknown zstd error code (%d)", errcode);
163
- }
103
+ return extzstd_make_errorf(ZSTD_getErrorCode(errcode), NULL);
104
+ }
105
+
106
+ static VALUE
107
+ err_initialize(int argc, VALUE argv[], VALUE err)
108
+ {
109
+ VALUE errcode;
110
+
111
+ rb_scan_args(argc, argv, "1*", &errcode, NULL);
112
+ rb_call_super(argc - 1, argv + 1);
113
+ rb_ivar_set(err, id_error_code, errcode);
114
+
115
+ return err;
116
+ }
164
117
 
165
- #undef CASE_ERROR
118
+ static VALUE
119
+ err_errcode(VALUE err)
120
+ {
121
+ return rb_ivar_get(err, id_error_code);
122
+ }
123
+
124
+ static VALUE
125
+ err_to_s(VALUE err)
126
+ {
127
+ ZSTD_ErrorCode code = (ZSTD_ErrorCode)NUM2SSIZET(rb_ivar_get(err, id_error_code));
128
+ VALUE mesg = rb_call_super(0, NULL);
129
+ VALUE mesg2 = rb_sprintf(" - %s (errcode: %d)", ZSTD_getErrorString(code), (int)code);
130
+ return rb_str_plus(mesg, mesg2);
166
131
  }
167
132
 
168
133
  static void
@@ -172,57 +137,10 @@ init_error(void)
172
137
 
173
138
  extzstd_eError = rb_define_class_under(extzstd_mZstd, "Error", rb_eRuntimeError);
174
139
  rb_include_module(extzstd_eError, extzstd_mExceptions);
175
-
176
- extzstd_eGenericError = rb_define_class_under(extzstd_mZstd, "GenericError", rb_eRuntimeError);
177
- rb_include_module(extzstd_eGenericError, extzstd_mExceptions);
178
-
179
- extzstd_ePrefixUnknownError = rb_define_class_under(extzstd_mZstd, "PrefixUnknownError", rb_eArgError);
180
- rb_include_module(extzstd_ePrefixUnknownError, extzstd_mExceptions);
181
-
182
- extzstd_eFrameParameterUnsupportedError = rb_define_class_under(extzstd_mZstd, "FrameParameterUnsupportedError", rb_eRuntimeError);
183
- rb_include_module(extzstd_eFrameParameterUnsupportedError, extzstd_mExceptions);
184
-
185
- extzstd_eFrameParameterUnsupportedBy32bitsError = rb_define_class_under(extzstd_mZstd, "FrameParameterUnsupportedBy32bitsImplementationError", rb_eRuntimeError);
186
- rb_include_module(extzstd_eFrameParameterUnsupportedBy32bitsError, extzstd_mExceptions);
187
-
188
- extzstd_eCompressionParameterUnsupportedError = rb_define_class_under(extzstd_mZstd, "CompressionParameterUnsupportedError", rb_eRuntimeError);
189
- rb_include_module(extzstd_eCompressionParameterUnsupportedError, extzstd_mExceptions);
190
-
191
- extzstd_eInitMissingError = rb_define_class_under(extzstd_mZstd, "InitMissingError", rb_eRuntimeError);
192
- rb_include_module(extzstd_eInitMissingError, extzstd_mExceptions);
193
-
194
- extzstd_eMemoryAllocationError = rb_define_class_under(extzstd_mZstd, "MemoryAllocationError", aux_const_dig_str(rb_cObject, "Errno", "ENOMEM"));
195
- rb_include_module(extzstd_eMemoryAllocationError, extzstd_mExceptions);
196
-
197
- extzstd_eStageWrongError = rb_define_class_under(extzstd_mZstd, "StageWrongError", rb_eRuntimeError);
198
- rb_include_module(extzstd_eStageWrongError, extzstd_mExceptions);
199
-
200
- extzstd_eDstSizeTooSmallError = rb_define_class_under(extzstd_mZstd, "DstSizeTooSmallError", rb_eArgError);
201
- rb_include_module(extzstd_eDstSizeTooSmallError, extzstd_mExceptions);
202
-
203
- extzstd_eSrcSizeWrongError = rb_define_class_under(extzstd_mZstd, "SrcSizeWrongError", rb_eArgError);
204
- rb_include_module(extzstd_eSrcSizeWrongError, extzstd_mExceptions);
205
-
206
- extzstd_eCorruptionDetectedError = rb_define_class_under(extzstd_mZstd, "CorruptionDetectedError", rb_eRuntimeError);
207
- rb_include_module(extzstd_eCorruptionDetectedError, extzstd_mExceptions);
208
-
209
- extzstd_eChecksumWrongError = rb_define_class_under(extzstd_mZstd, "ChecksumWrongError", rb_eRuntimeError);
210
- rb_include_module(extzstd_eChecksumWrongError, extzstd_mExceptions);
211
-
212
- extzstd_eTableLogTooLargeError = rb_define_class_under(extzstd_mZstd, "TableLogTooLargeError", rb_eArgError);
213
- rb_include_module(extzstd_eTableLogTooLargeError, extzstd_mExceptions);
214
-
215
- extzstd_eMaxSymbolValueTooLargeError = rb_define_class_under(extzstd_mZstd, "MaxSymbolValueTooLargeError", rb_eArgError);
216
- rb_include_module(extzstd_eMaxSymbolValueTooLargeError, extzstd_mExceptions);
217
-
218
- extzstd_eMaxSymbolValueTooSmallError = rb_define_class_under(extzstd_mZstd, "MaxSymbolValueTooSmallError", rb_eArgError);
219
- rb_include_module(extzstd_eMaxSymbolValueTooSmallError, extzstd_mExceptions);
220
-
221
- extzstd_eDictionaryCorruptedError = rb_define_class_under(extzstd_mZstd, "DictionaryCorruptedError", rb_eRuntimeError);
222
- rb_include_module(extzstd_eDictionaryCorruptedError, extzstd_mExceptions);
223
-
224
- extzstd_eDictionaryWrongError = rb_define_class_under(extzstd_mZstd, "DictionaryWrongError", rb_eRuntimeError);
225
- rb_include_module(extzstd_eDictionaryWrongError, extzstd_mExceptions);
140
+ rb_define_method(extzstd_eError, "initialize", err_initialize, -1);
141
+ rb_define_method(extzstd_eError, "error_code", err_errcode, 0);
142
+ rb_define_method(extzstd_eError, "to_s", err_to_s, 0);
143
+ rb_define_alias(extzstd_eError, "errcode", "error_code");
226
144
  }
227
145
 
228
146
  /*
@@ -245,6 +163,8 @@ init_constants(void)
245
163
  rb_define_const(mConstants, "ZSTD_LAZY2", INT2NUM(ZSTD_lazy2));
246
164
  rb_define_const(mConstants, "ZSTD_BTLAZY2", INT2NUM(ZSTD_btlazy2));
247
165
  rb_define_const(mConstants, "ZSTD_BTOPT", INT2NUM(ZSTD_btopt));
166
+ rb_define_const(mConstants, "ZSTD_BTULTRA", INT2NUM(ZSTD_btultra));
167
+ rb_define_const(mConstants, "ZSTD_BTULTRA2", INT2NUM(ZSTD_btultra2));
248
168
  rb_define_const(mConstants, "ZSTD_WINDOWLOG_MAX", INT2NUM(ZSTD_WINDOWLOG_MAX));
249
169
  rb_define_const(mConstants, "ZSTD_WINDOWLOG_MIN", INT2NUM(ZSTD_WINDOWLOG_MIN));
250
170
  rb_define_const(mConstants, "ZSTD_HASHLOG_MAX", INT2NUM(ZSTD_HASHLOG_MAX));
@@ -254,10 +174,10 @@ init_constants(void)
254
174
  rb_define_const(mConstants, "ZSTD_HASHLOG3_MAX", INT2NUM(ZSTD_HASHLOG3_MAX));
255
175
  rb_define_const(mConstants, "ZSTD_SEARCHLOG_MAX", INT2NUM(ZSTD_SEARCHLOG_MAX));
256
176
  rb_define_const(mConstants, "ZSTD_SEARCHLOG_MIN", INT2NUM(ZSTD_SEARCHLOG_MIN));
257
- rb_define_const(mConstants, "ZSTD_SEARCHLENGTH_MAX", INT2NUM(ZSTD_SEARCHLENGTH_MAX));
258
- rb_define_const(mConstants, "ZSTD_SEARCHLENGTH_MIN", INT2NUM(ZSTD_SEARCHLENGTH_MIN));
259
- rb_define_const(mConstants, "ZSTD_TARGETLENGTH_MAX", INT2NUM(ZSTD_TARGETLENGTH_MAX));
260
- rb_define_const(mConstants, "ZSTD_TARGETLENGTH_MIN", INT2NUM(ZSTD_TARGETLENGTH_MIN));
177
+ //rb_define_const(mConstants, "ZSTD_SEARCHLENGTH_MAX", INT2NUM(ZSTD_SEARCHLENGTH_MAX));
178
+ //rb_define_const(mConstants, "ZSTD_SEARCHLENGTH_MIN", INT2NUM(ZSTD_SEARCHLENGTH_MIN));
179
+ //rb_define_const(mConstants, "ZSTD_TARGETLENGTH_MAX", INT2NUM(ZSTD_TARGETLENGTH_MAX));
180
+ //rb_define_const(mConstants, "ZSTD_TARGETLENGTH_MIN", INT2NUM(ZSTD_TARGETLENGTH_MIN));
261
181
 
262
182
  rb_define_const(mConstants, "FAST", INT2NUM(ZSTD_fast));
263
183
  rb_define_const(mConstants, "DFAST", INT2NUM(ZSTD_dfast));
@@ -266,6 +186,8 @@ init_constants(void)
266
186
  rb_define_const(mConstants, "LAZY2", INT2NUM(ZSTD_lazy2));
267
187
  rb_define_const(mConstants, "BTLAZY2", INT2NUM(ZSTD_btlazy2));
268
188
  rb_define_const(mConstants, "BTOPT", INT2NUM(ZSTD_btopt));
189
+ rb_define_const(mConstants, "BTULTRA", INT2NUM(ZSTD_btultra));
190
+ rb_define_const(mConstants, "BTULTRA2", INT2NUM(ZSTD_btultra2));
269
191
  rb_define_const(mConstants, "WINDOWLOG_MAX", INT2NUM(ZSTD_WINDOWLOG_MAX));
270
192
  rb_define_const(mConstants, "WINDOWLOG_MIN", INT2NUM(ZSTD_WINDOWLOG_MIN));
271
193
  rb_define_const(mConstants, "HASHLOG_MAX", INT2NUM(ZSTD_HASHLOG_MAX));
@@ -275,10 +197,10 @@ init_constants(void)
275
197
  rb_define_const(mConstants, "HASHLOG3_MAX", INT2NUM(ZSTD_HASHLOG3_MAX));
276
198
  rb_define_const(mConstants, "SEARCHLOG_MAX", INT2NUM(ZSTD_SEARCHLOG_MAX));
277
199
  rb_define_const(mConstants, "SEARCHLOG_MIN", INT2NUM(ZSTD_SEARCHLOG_MIN));
278
- rb_define_const(mConstants, "SEARCHLENGTH_MAX", INT2NUM(ZSTD_SEARCHLENGTH_MAX));
279
- rb_define_const(mConstants, "SEARCHLENGTH_MIN", INT2NUM(ZSTD_SEARCHLENGTH_MIN));
280
- rb_define_const(mConstants, "TARGETLENGTH_MAX", INT2NUM(ZSTD_TARGETLENGTH_MAX));
281
- rb_define_const(mConstants, "TARGETLENGTH_MIN", INT2NUM(ZSTD_TARGETLENGTH_MIN));
200
+ //rb_define_const(mConstants, "SEARCHLENGTH_MAX", INT2NUM(ZSTD_SEARCHLENGTH_MAX));
201
+ //rb_define_const(mConstants, "SEARCHLENGTH_MIN", INT2NUM(ZSTD_SEARCHLENGTH_MIN));
202
+ //rb_define_const(mConstants, "TARGETLENGTH_MAX", INT2NUM(ZSTD_TARGETLENGTH_MAX));
203
+ //rb_define_const(mConstants, "TARGETLENGTH_MIN", INT2NUM(ZSTD_TARGETLENGTH_MIN));
282
204
  }
283
205
 
284
206
  /*
@@ -329,7 +251,7 @@ extzstd_params_alloc(ZSTD_parameters **p)
329
251
  * [opts contentlog: nil]
330
252
  * [opts hashlog: nil]
331
253
  * [opts searchlog: nil]
332
- * [opts searchlength: nil]
254
+ * [opts minmatch: nil]
333
255
  * [opts targetlength: nil]
334
256
  * [opts strategy: nil]
335
257
  */
@@ -362,9 +284,12 @@ params_init(int argc, VALUE argv[], VALUE v)
362
284
  SETUP_PARAM(p->cParams.chainLog, opts, "chainlog", NUM2UINT);
363
285
  SETUP_PARAM(p->cParams.hashLog, opts, "hashlog", NUM2UINT);
364
286
  SETUP_PARAM(p->cParams.searchLog, opts, "searchlog", NUM2UINT);
365
- SETUP_PARAM(p->cParams.searchLength, opts, "searchlength", NUM2UINT);
287
+ SETUP_PARAM(p->cParams.minMatch, opts, "minmatch", NUM2UINT);
366
288
  SETUP_PARAM(p->cParams.targetLength, opts, "targetlength", NUM2UINT);
367
289
  SETUP_PARAM(p->cParams.strategy, opts, "strategy", NUM2UINT);
290
+ SETUP_PARAM(p->fParams.contentSizeFlag, opts, "contentsize", RTEST);
291
+ SETUP_PARAM(p->fParams.checksumFlag, opts, "checksum", RTEST);
292
+ SETUP_PARAM(p->fParams.noDictIDFlag, opts, "nodictid", RTEST);
368
293
  #undef SETUP_PARAM
369
294
  }
370
295
 
@@ -408,7 +333,7 @@ IMP_PARAMS(params_windowlog, params_set_windowlog, windowLog);
408
333
  IMP_PARAMS(params_chainlog, params_set_chainlog, chainLog);
409
334
  IMP_PARAMS(params_hashlog, params_set_hashlog, hashLog);
410
335
  IMP_PARAMS(params_searchlog, params_set_searchlog, searchLog);
411
- IMP_PARAMS(params_searchlength, params_set_searchlength, searchLength);
336
+ IMP_PARAMS(params_minmatch, params_set_minmatch, minMatch);
412
337
  IMP_PARAMS(params_targetlength, params_set_targetlength, targetLength);
413
338
  IMP_PARAMS(params_strategy, params_set_strategy, strategy);
414
339
 
@@ -461,8 +386,8 @@ params_s_get_preset(int argc, VALUE argv[], VALUE mod)
461
386
  * Document-method: Zstd::Parameters#hashlog=
462
387
  * Document-method: Zstd::Parameters#searchlog
463
388
  * Document-method: Zstd::Parameters#searchlog=
464
- * Document-method: Zstd::Parameters#searchlength
465
- * Document-method: Zstd::Parameters#searchlength=
389
+ * Document-method: Zstd::Parameters#minmatch
390
+ * Document-method: Zstd::Parameters#minmatch=
466
391
  * Document-method: Zstd::Parameters#targetlength
467
392
  * Document-method: Zstd::Parameters#targetlength=
468
393
  * Document-method: Zstd::Parameters#strategy
@@ -489,8 +414,8 @@ init_params(void)
489
414
  rb_define_method(extzstd_cParams, "hashlog=", RUBY_METHOD_FUNC(params_set_hashlog), 1);
490
415
  rb_define_method(extzstd_cParams, "searchlog", RUBY_METHOD_FUNC(params_searchlog), 0);
491
416
  rb_define_method(extzstd_cParams, "searchlog=", RUBY_METHOD_FUNC(params_set_searchlog), 1);
492
- rb_define_method(extzstd_cParams, "searchlength", RUBY_METHOD_FUNC(params_searchlength), 0);
493
- rb_define_method(extzstd_cParams, "searchlength=", RUBY_METHOD_FUNC(params_set_searchlength), 1);
417
+ rb_define_method(extzstd_cParams, "minmatch", RUBY_METHOD_FUNC(params_minmatch), 0);
418
+ rb_define_method(extzstd_cParams, "minmatch=", RUBY_METHOD_FUNC(params_set_minmatch), 1);
494
419
  rb_define_method(extzstd_cParams, "targetlength", RUBY_METHOD_FUNC(params_targetlength), 0);
495
420
  rb_define_method(extzstd_cParams, "targetlength=", RUBY_METHOD_FUNC(params_set_targetlength), 1);
496
421
  rb_define_method(extzstd_cParams, "strategy", RUBY_METHOD_FUNC(params_strategy), 0);
@@ -518,7 +443,8 @@ dict_s_train_from_buffer(VALUE mod, VALUE src, VALUE dict_capacity)
518
443
  size_t capa = NUM2SIZET(dict_capacity);
519
444
  VALUE dict = rb_str_buf_new(capa);
520
445
  size_t srcsize = RSTRING_LEN(src);
521
- size_t s = ZDICT_trainFromBuffer(RSTRING_PTR(dict), capa, RSTRING_PTR(src), &srcsize, 1);
446
+ const ZDICT_legacy_params_t params = { 0 };
447
+ size_t s = ZDICT_trainFromBuffer_legacy(RSTRING_PTR(dict), capa, RSTRING_PTR(src), &srcsize, 1, params);
522
448
  extzstd_check_error(s);
523
449
  rb_str_set_len(dict, s);
524
450
  return dict;
@@ -688,9 +614,14 @@ init_contextless(void)
688
614
  * library initializer
689
615
  */
690
616
 
691
- void
617
+ RBEXT_API void
692
618
  Init_extzstd(void)
693
619
  {
620
+ RB_EXT_RACTOR_SAFE(true);
621
+
622
+ id_initialize = rb_intern("initialize");
623
+ id_error_code = rb_intern("error_code");
624
+
694
625
  extzstd_mZstd = rb_define_module("Zstd");
695
626
 
696
627
  init_libver();
data/ext/extzstd.h CHANGED
@@ -3,11 +3,14 @@
3
3
 
4
4
  #define ZSTD_LEGACY_SUPPORT 1
5
5
  #define ZDICT_STATIC_LINKING_ONLY 1
6
- #define ZSTD_STATIC_LINKING_ONLY 1
6
+ //#define ZSTD_STATIC_LINKING_ONLY 1
7
+ #include <common/zstd_internal.h> /* for MIN() */
7
8
  #include <zstd.h>
8
9
  #include <stdarg.h>
10
+ #include <stdbool.h>
9
11
  #include <ruby.h>
10
12
  #include <ruby/thread.h>
13
+ #include <ruby/version.h>
11
14
 
12
15
  #define ELEMENTOF(ARRAY) (sizeof(ARRAY) / sizeof(ARRAY[0]))
13
16
  #define ENDOF(ARRAY) (ARRAY + ELEMENTOF(ARRAY))
@@ -28,24 +31,6 @@ RDOCFAKE(extzstd_cParams = rb_define_class_under(extzstd_mZstd, "Parameters", rb
28
31
 
29
32
  extern VALUE extzstd_mExceptions;
30
33
  extern VALUE extzstd_eError;
31
- extern VALUE extzstd_eGenericError;
32
- extern VALUE extzstd_ePrefixUnknownError;
33
- extern VALUE extzstd_eFrameParameterUnsupportedError;
34
- extern VALUE extzstd_eFrameParameterUnsupportedBy32bitsError;
35
- extern VALUE extzstd_eCompressionParameterUnsupportedError;
36
- extern VALUE extzstd_eInitMissingError;
37
- extern VALUE extzstd_eMemoryAllocationError;
38
- extern VALUE extzstd_eStageWrongError;
39
- extern VALUE extzstd_eDstSizeTooSmallError;
40
- extern VALUE extzstd_eSrcSizeWrongError;
41
- extern VALUE extzstd_eCorruptionDetectedError;
42
- extern VALUE extzstd_eChecksumWrongError;
43
- extern VALUE extzstd_eTableLogTooLargeError;
44
- extern VALUE extzstd_eMaxSymbolValueTooLargeError;
45
- extern VALUE extzstd_eMaxSymbolValueTooSmallError;
46
- extern VALUE extzstd_eDictionaryCorruptedError;
47
- extern VALUE extzstd_eDictionaryWrongError;
48
-
49
34
 
50
35
  extern void init_extzstd_stream(void);
51
36
  extern void extzstd_init_buffered(void);
@@ -53,7 +38,7 @@ extern void extzstd_init_stream(void);
53
38
  extern void extzstd_error(ssize_t errcode);
54
39
  extern void extzstd_check_error(ssize_t errcode);
55
40
  extern VALUE extzstd_make_error(ssize_t errcode);
56
- extern VALUE extzstd_make_errorf(VALUE exc, const char *fmt, ...);
41
+ extern VALUE extzstd_make_errorf(ssize_t errcode, const char *fmt, ...);
57
42
 
58
43
  extern ZSTD_parameters *extzstd_getparams(VALUE v);
59
44
  extern int extzstd_params_p(VALUE v);
@@ -171,16 +156,80 @@ aux_const_dig_str_0(VALUE obj, const char *p[], const char **pp)
171
156
  return obj;
172
157
  }
173
158
 
174
- #define aux_const_dig_str(OBJ, ...) \
175
- ({ \
176
- const char *names__[] = { __VA_ARGS__ }; \
177
- aux_const_dig_str_0((OBJ), names__, ENDOF(names__)); \
178
- }) \
179
-
180
- #define AUX_TUPLE(...) \
181
- ({ \
182
- VALUE v__[] = { __VA_ARGS__ }; \
183
- rb_ary_new4(ELEMENTOF(v__), v__); \
184
- }) \
159
+ #define aux_const_dig_str(OBJ, ...) \
160
+ aux_const_dig_str_0((OBJ), \
161
+ ((const char *[]){ __VA_ARGS__ }), \
162
+ ENDOF(((const char *[]){ __VA_ARGS__ }))) \
163
+
164
+ #define AUX_TUPLE(...) \
165
+ rb_ary_new4(ELEMENTOF(((VALUE[]) { __VA_ARGS__ })), \
166
+ ((VALUE[]) { __VA_ARGS__ })) \
167
+
168
+ #define AUX_FUNCALL(RECV, MID, ...) \
169
+ rb_funcall2((RECV), (MID), \
170
+ ELEMENTOF(((const VALUE[]){ __VA_ARGS__ })), \
171
+ ((const VALUE[]){ __VA_ARGS__ })) \
172
+
173
+ #define AUX_TRY_WITH_GC(cond, mesg) \
174
+ do { \
175
+ if (!(cond)) { \
176
+ rb_gc(); \
177
+ if (!(cond)) { \
178
+ errno = ENOMEM; \
179
+ rb_sys_fail(mesg); \
180
+ } \
181
+ } \
182
+ } while (0) \
183
+
184
+ #if defined _WIN32 || defined __CYGWIN__
185
+ # define RBEXT_IMPORT __declspec(dllimport)
186
+ # define RBEXT_EXPORT __declspec(dllexport)
187
+ # define RBEXT_LOCAL
188
+ #elif defined(__GNUC__) && __GNUC__ >= 4 || defined(__clang__)
189
+ # define RBEXT_IMPORT __attribute__((visibility("default")))
190
+ # define RBEXT_EXPORT __attribute__((visibility("default")))
191
+ # define RBEXT_LOCAL __attribute__((visibility("hidden")))
192
+ #else
193
+ # define RBEXT_IMPORT
194
+ # define RBEXT_EXPORT
195
+ # define RBEXT_LOCAL
196
+ #endif
197
+
198
+ #ifndef RBEXT_API
199
+ # define RBEXT_API RBEXT_EXPORT
200
+ #endif
201
+
202
+
203
+ static void
204
+ aux_string_pointer(VALUE str, const char **ptr, size_t *size)
205
+ {
206
+ rb_check_type(str, RUBY_T_STRING);
207
+ RSTRING_GETMEM(str, *ptr, *size);
208
+ }
209
+
210
+ static void
211
+ aux_string_pointer_with_nil(VALUE str, const char **ptr, size_t *size)
212
+ {
213
+ if (NIL_P(str)) {
214
+ *ptr = NULL;
215
+ *size = 0;
216
+ } else {
217
+ aux_string_pointer(str, ptr, size);
218
+ }
219
+ }
220
+
221
+ static void
222
+ aux_string_expand_pointer(VALUE str, char **ptr, size_t size)
223
+ {
224
+ rb_check_type(str, RUBY_T_STRING);
225
+ rb_str_modify(str);
226
+ rb_str_set_len(str, 0);
227
+ rb_str_modify_expand(str, size);
228
+ *ptr = RSTRING_PTR(str);
229
+ }
230
+
231
+ #if RUBY_API_VERSION_CODE >= 30000
232
+ # define rb_obj_infect(dest, src) ((void)(dest), (void)(src))
233
+ #endif
185
234
 
186
235
  #endif /* EXTZSTD_H */