extzstd 0.0.2.CONCEPT-x86-mingw32 → 0.0.3.CONCEPT-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +72 -22
  3. data/Rakefile +73 -19
  4. data/contrib/zstd/README.md +68 -0
  5. data/contrib/zstd/common/bitstream.h +414 -0
  6. data/contrib/zstd/common/entropy_common.c +231 -0
  7. data/contrib/zstd/common/error_private.h +125 -0
  8. data/contrib/zstd/common/error_public.h +77 -0
  9. data/contrib/zstd/common/fse.h +628 -0
  10. data/contrib/zstd/common/fse_decompress.c +331 -0
  11. data/contrib/zstd/common/huf.h +228 -0
  12. data/contrib/zstd/common/mem.h +377 -0
  13. data/contrib/zstd/common/xxhash.c +854 -0
  14. data/contrib/zstd/common/xxhash.h +273 -0
  15. data/contrib/zstd/common/zbuff.h +197 -0
  16. data/contrib/zstd/common/zstd.h +475 -0
  17. data/contrib/zstd/common/zstd_common.c +91 -0
  18. data/contrib/zstd/common/zstd_internal.h +238 -0
  19. data/contrib/zstd/compress/fse_compress.c +807 -0
  20. data/contrib/zstd/compress/huf_compress.c +577 -0
  21. data/contrib/zstd/compress/zbuff_compress.c +327 -0
  22. data/contrib/zstd/compress/zstd_compress.c +3074 -0
  23. data/contrib/zstd/compress/zstd_opt.h +1046 -0
  24. data/contrib/zstd/decompress/huf_decompress.c +894 -0
  25. data/contrib/zstd/decompress/zbuff_decompress.c +294 -0
  26. data/contrib/zstd/decompress/zstd_decompress.c +1362 -0
  27. data/contrib/zstd/dictBuilder/divsufsort.c +1913 -0
  28. data/contrib/zstd/dictBuilder/divsufsort.h +67 -0
  29. data/contrib/zstd/dictBuilder/zdict.c +1045 -0
  30. data/contrib/zstd/dictBuilder/zdict.h +113 -0
  31. data/contrib/zstd/legacy/zstd_legacy.h +140 -0
  32. data/contrib/zstd/legacy/zstd_v01.c +2178 -0
  33. data/contrib/zstd/{zstd.h → legacy/zstd_v01.h} +46 -39
  34. data/contrib/zstd/legacy/zstd_v02.c +3748 -0
  35. data/contrib/zstd/legacy/zstd_v02.h +99 -0
  36. data/contrib/zstd/legacy/zstd_v03.c +3389 -0
  37. data/contrib/zstd/legacy/zstd_v03.h +99 -0
  38. data/contrib/zstd/legacy/zstd_v04.c +4056 -0
  39. data/contrib/zstd/legacy/zstd_v04.h +148 -0
  40. data/contrib/zstd/legacy/zstd_v05.c +4325 -0
  41. data/contrib/zstd/legacy/zstd_v05.h +171 -0
  42. data/contrib/zstd/legacy/zstd_v06.c +4581 -0
  43. data/contrib/zstd/legacy/zstd_v06.h +185 -0
  44. data/ext/extconf.rb +10 -12
  45. data/ext/extzstd.c +497 -144
  46. data/ext/extzstd.h +127 -22
  47. data/ext/extzstd_buffered.c +265 -0
  48. data/ext/extzstd_nogvls.h +174 -0
  49. data/ext/zstd_amalgam.c +18 -0
  50. data/ext/zstd_legacy_v01.c +1 -0
  51. data/ext/zstd_legacy_v02.c +1 -0
  52. data/ext/zstd_legacy_v03.c +1 -0
  53. data/ext/zstd_legacy_v04.c +1 -0
  54. data/ext/zstd_legacy_v05.c +1 -0
  55. data/ext/zstd_legacy_v06.c +1 -0
  56. data/gemstub.rb +17 -1
  57. data/lib/2.0/extzstd.so +0 -0
  58. data/lib/2.1/extzstd.so +0 -0
  59. data/lib/2.2/extzstd.so +0 -0
  60. data/lib/2.3/extzstd.so +0 -0
  61. data/lib/extzstd.rb +197 -77
  62. data/lib/extzstd/version.rb +1 -1
  63. data/test/test_basic.rb +41 -0
  64. metadata +71 -20
  65. data/contrib/zstd/Makefile +0 -115
  66. data/contrib/zstd/fse.c +0 -2466
  67. data/contrib/zstd/fse.h +0 -320
  68. data/contrib/zstd/fse_static.h +0 -282
  69. data/contrib/zstd/libzstd.pc.in +0 -14
  70. data/contrib/zstd/zstd.c +0 -1768
  71. data/contrib/zstd/zstd_static.h +0 -89
  72. data/ext/extzstd-stream.c +0 -398
@@ -1,18 +1,61 @@
1
1
  #ifndef EXTZSTD_H
2
2
  #define EXTZSTD_H 1
3
3
 
4
+ #define ZSTD_LEGACY_SUPPORT 1
5
+ #define ZBUFF_STATIC_LINKING_ONLY 1
6
+ #include <zbuff.h>
4
7
  #include <stdarg.h>
5
8
  #include <ruby.h>
6
9
  #include <ruby/thread.h>
7
- #include <zstd.h>
8
- #include <zstd_static.h>
10
+
11
+ #define ELEMENTOF(ARRAY) (sizeof(ARRAY) / sizeof(ARRAY[0]))
12
+ #define ENDOF(ARRAY) (ARRAY + ELEMENTOF(ARRAY))
13
+
14
+ #define LOGF(MESG, ...) \
15
+ do { \
16
+ fprintf(stderr, "%s:%d:%s: " MESG "\n", \
17
+ __FILE__, __LINE__, __func__, ## __VA_ARGS__); \
18
+ } while (0) \
9
19
 
10
20
  #define RDOCFAKE(DUMMY_CODE)
11
21
 
12
- extern VALUE mZstd;
13
- extern VALUE eError;
22
+ extern VALUE extzstd_mZstd;
23
+ RDOCFAKE(extzstd_mZstd = rb_define_module("Zstd"));
24
+
25
+ extern VALUE extzstd_cParams;
26
+ RDOCFAKE(extzstd_cParams = rb_define_class_under(extzstd_mZstd, "EncodeParameters", rb_cObject));
27
+
28
+ extern VALUE extzstd_mExceptions;
29
+ extern VALUE extzstd_eError;
30
+ extern VALUE extzstd_eGenericError;
31
+ extern VALUE extzstd_ePrefixUnknownError;
32
+ extern VALUE extzstd_eFrameParameterUnsupportedError;
33
+ extern VALUE extzstd_eFrameParameterUnsupportedBy32bitsError;
34
+ extern VALUE extzstd_eCompressionParameterUnsupportedError;
35
+ extern VALUE extzstd_eInitMissingError;
36
+ extern VALUE extzstd_eMemoryAllocationError;
37
+ extern VALUE extzstd_eStageWrongError;
38
+ extern VALUE extzstd_eDstSizeTooSmallError;
39
+ extern VALUE extzstd_eSrcSizeWrongError;
40
+ extern VALUE extzstd_eCorruptionDetectedError;
41
+ extern VALUE extzstd_eChecksumWrongError;
42
+ extern VALUE extzstd_eTableLogTooLargeError;
43
+ extern VALUE extzstd_eMaxSymbolValueTooLargeError;
44
+ extern VALUE extzstd_eMaxSymbolValueTooSmallError;
45
+ extern VALUE extzstd_eDictionaryCorruptedError;
46
+ extern VALUE extzstd_eDictionaryWrongError;
47
+
48
+
49
+ extern void init_extzstd_stream(void);
50
+ extern void extzstd_init_buffered(void);
51
+ extern void extzstd_error(ssize_t errcode);
52
+ extern void extzstd_check_error(ssize_t errcode);
53
+ extern VALUE extzstd_make_error(ssize_t errcode);
54
+ extern VALUE extzstd_make_errorf(VALUE exc, const char *fmt, ...);
14
55
 
15
- void init_extzstd_stream(void);
56
+ extern ZSTD_parameters *extzstd_getencparams(VALUE v);
57
+ extern int extzstd_encparams_p(VALUE v);
58
+ extern VALUE extzstd_params_alloc(ZSTD_parameters **p);
16
59
 
17
60
  static inline void
18
61
  referror(VALUE v)
@@ -51,29 +94,91 @@ getref(VALUE v, const rb_data_type_t *type)
51
94
  return checkref(v, getrefp(v, type));
52
95
  }
53
96
 
97
+ #define AUX_IMPLEMENT_CONTEXT(TYPE, TYPEDDATANAME, STRUCTNAME, ALLOCNAME, \
98
+ MARKFUNC, FREEFUNC, SIZEFUNC, \
99
+ GETREFP, GETREF, REF_P) \
100
+ static const rb_data_type_t TYPEDDATANAME = { \
101
+ .wrap_struct_name = STRUCTNAME, \
102
+ .function.dmark = MARKFUNC, \
103
+ .function.dfree = FREEFUNC, \
104
+ .function.dsize = SIZEFUNC, \
105
+ }; \
106
+ \
107
+ static VALUE \
108
+ ALLOCNAME(VALUE klass) \
109
+ { \
110
+ return TypedData_Wrap_Struct(klass, &TYPEDDATANAME, NULL); \
111
+ } \
112
+ \
113
+ static inline TYPE * \
114
+ GETREFP(VALUE v) \
115
+ { \
116
+ return getrefp(v, &TYPEDDATANAME); \
117
+ } \
118
+ \
119
+ static inline TYPE * \
120
+ GETREF(VALUE v) \
121
+ { \
122
+ return getref(v, &TYPEDDATANAME); \
123
+ } \
124
+ \
125
+ static inline int \
126
+ REF_P(VALUE v) \
127
+ { \
128
+ return rb_typeddata_is_kind_of(v, &TYPEDDATANAME); \
129
+ } \
130
+
54
131
  static inline VALUE
55
- aux_str_modify_expand(VALUE s, size_t z)
132
+ aux_str_modify_expand(VALUE str, size_t size)
56
133
  {
57
- rb_check_type(s, RUBY_T_STRING);
58
- size_t size = RSTRING_LEN(s);
59
- if (z > size) {
60
- rb_str_modify_expand(s, z - size);
134
+ size_t capa = rb_str_capacity(str);
135
+ if (capa < size) {
136
+ rb_str_modify_expand(str, size - RSTRING_LEN(str));
61
137
  } else {
62
- rb_str_modify(s);
138
+ rb_str_modify(str);
63
139
  }
64
- return s;
140
+ return str;
65
141
  }
66
142
 
67
- static inline void *
68
- aux_thread_call_without_gvl(void *(*func)(void *), void (*cancel)(void *), ...)
143
+ static inline int
144
+ aux_num2int(VALUE v, int default_value)
69
145
  {
70
- va_list va1, va2;
71
- va_start(va1, cancel);
72
- va_start(va2, cancel);
73
- void *p = rb_thread_call_without_gvl(func, &va1, cancel, &va2);
74
- va_end(va1);
75
- va_end(va2);
76
- return p;
146
+ if (NIL_P(v)) {
147
+ return default_value;
148
+ } else {
149
+ return NUM2INT(v);
150
+ }
77
151
  }
78
152
 
79
- #endif /* !EXTZSTD_H */
153
+ static inline uint64_t
154
+ aux_num2int_u64(VALUE v, uint64_t default_value)
155
+ {
156
+ if (NIL_P(v)) {
157
+ return default_value;
158
+ } else {
159
+ return NUM2ULL(v);
160
+ }
161
+ }
162
+
163
+ static inline VALUE
164
+ aux_const_dig_str_0(VALUE obj, const char *p[], const char *pp)
165
+ {
166
+ for (; p < pp; p ++) {
167
+ obj = rb_const_get(obj, rb_intern(*p));
168
+ }
169
+ return obj;
170
+ }
171
+
172
+ #define aux_const_dig_str(OBJ, ...) \
173
+ ({ \
174
+ const char *names__[] = { __VA_ARGS__ }; \
175
+ aux_const_dig_str_0((OBJ), names__, ENDOF(names__)); \
176
+ }) \
177
+
178
+ #define AUX_TUPLE(...) \
179
+ ({ \
180
+ VALUE v__[] = { __VA_ARGS__ }; \
181
+ rb_ary_new4(ELEMENTOF(v__), v__); \
182
+ }) \
183
+
184
+ #endif /* EXTZSTD_H */
@@ -0,0 +1,265 @@
1
+ #include "extzstd.h"
2
+ #include "extzstd_nogvls.h"
3
+
4
+ /*
5
+ * class Zstd::BufferedEncoder
6
+ */
7
+
8
+ static void
9
+ bufenc_free(void *p)
10
+ {
11
+ ZBUFF_freeCCtx(p);
12
+ }
13
+
14
+ AUX_IMPLEMENT_CONTEXT(
15
+ ZBUFF_CCtx, bufenc_datatype, "extzstd.BufferedEncoder",
16
+ bufenc_alloc_dummy, NULL, bufenc_free, NULL,
17
+ getbufencp, getbufenc, bufenc_p);
18
+
19
+ static VALUE
20
+ bufenc_alloc(VALUE mod)
21
+ {
22
+ ZBUFF_CCtx *p = ZBUFF_createCCtx();
23
+ if (!p) {
24
+ rb_gc();
25
+ p = ZBUFF_createCCtx();
26
+ if (!p) {
27
+ rb_raise(extzstd_eError, "failed ZBUFF_createCCtx()");
28
+ }
29
+ }
30
+
31
+ return TypedData_Wrap_Struct(mod, &bufenc_datatype, p);
32
+ }
33
+
34
+ static VALUE
35
+ bufenc_init(VALUE enc, VALUE params, VALUE dict)
36
+ {
37
+ ZBUFF_CCtx *p = getbufenc(enc);
38
+ const void *dictp;
39
+ size_t dictsize;
40
+ if (NIL_P(dict)) {
41
+ dictp = NULL;
42
+ dictsize = 0;
43
+ } else {
44
+ rb_check_type(dict, RUBY_T_STRING);
45
+ RSTRING_GETMEM(dict, dictp, dictsize);
46
+ }
47
+ if (extzstd_encparams_p(params)) {
48
+ ZSTD_parameters *paramsp = extzstd_getencparams(params);
49
+ size_t s = aux_ZBUFF_compressInit_advanced(p, dictp, dictsize, paramsp, 0);
50
+ extzstd_check_error(s);
51
+ } else {
52
+ size_t s = aux_ZBUFF_compressInitDictionary(p, dictp, dictsize, aux_num2int(params, 1));
53
+ extzstd_check_error(s);
54
+ }
55
+
56
+ return enc;
57
+ }
58
+
59
+ static VALUE
60
+ bufenc_continue(VALUE v, VALUE src, VALUE srcoff, VALUE dest, VALUE maxsize)
61
+ {
62
+ ZBUFF_CCtx *p = getbufenc(v);
63
+ rb_check_type(src, RUBY_T_STRING);
64
+ char *srcp;
65
+ size_t srcsize;
66
+ RSTRING_GETMEM(src, srcp, srcsize);
67
+ size_t srcoff1 = NUM2SIZET(srcoff);
68
+ if ((srcsize > 0 && srcoff1 >= srcsize) || srcoff1 > srcsize) {
69
+ rb_raise(rb_eArgError,
70
+ "``srcoff'' is out of src size (%"PRIuSIZE" for 0...%"PRIuSIZE")",
71
+ srcoff1, srcsize);
72
+ }
73
+ srcp += srcoff1;
74
+ srcsize -= srcoff1;
75
+ size_t destsize = NUM2SIZET(maxsize);
76
+ rb_check_type(dest, RUBY_T_STRING);
77
+ aux_str_modify_expand(dest, destsize);
78
+ rb_obj_infect(v, src);
79
+ rb_obj_infect(dest, v);
80
+ size_t s = aux_ZBUFF_compressContinue(p, RSTRING_PTR(dest), &destsize, srcp, &srcsize);
81
+ extzstd_check_error(s);
82
+ rb_str_set_len(dest, destsize);
83
+ if (srcsize > 0) {
84
+ return SIZET2NUM(srcoff1 + srcsize);
85
+ } else {
86
+ return Qnil;
87
+ }
88
+ }
89
+
90
+ static VALUE
91
+ bufenc_flush(VALUE v, VALUE dest, VALUE maxsize)
92
+ {
93
+ ZBUFF_CCtx *p = getbufenc(v);
94
+ size_t destsize = NUM2SIZET(maxsize);
95
+ rb_check_type(dest, RUBY_T_STRING);
96
+ aux_str_modify_expand(dest, destsize);
97
+ size_t s = aux_ZBUFF_compressFlush(p, RSTRING_PTR(dest), &destsize);
98
+ extzstd_check_error(s);
99
+ rb_str_set_len(dest, destsize);
100
+ return dest;
101
+ }
102
+
103
+ static VALUE
104
+ bufenc_end(VALUE v, VALUE dest, VALUE maxsize)
105
+ {
106
+ ZBUFF_CCtx *p = getbufenc(v);
107
+ size_t destsize = NUM2SIZET(maxsize);
108
+ rb_check_type(dest, RUBY_T_STRING);
109
+ aux_str_modify_expand(dest, destsize);
110
+ size_t s = aux_ZBUFF_compressEnd(p, RSTRING_PTR(dest), &destsize);
111
+ extzstd_check_error(s);
112
+ rb_str_set_len(dest, destsize);
113
+ return dest;
114
+ }
115
+
116
+ static VALUE
117
+ bufenc_s_recommended_insize(VALUE mod)
118
+ {
119
+ return SIZET2NUM(ZBUFF_recommendedCInSize());
120
+ }
121
+
122
+ static VALUE
123
+ bufenc_s_recommended_outsize(VALUE mod)
124
+ {
125
+ return SIZET2NUM(ZBUFF_recommendedCOutSize());
126
+ }
127
+
128
+ static void
129
+ init_buffered_encoder(void)
130
+ {
131
+ VALUE cBufEncoder = rb_define_class_under(extzstd_mZstd, "BufferedEncoder", rb_cObject);
132
+ rb_define_alloc_func(cBufEncoder, bufenc_alloc);
133
+ rb_define_method(cBufEncoder, "initialize", RUBY_METHOD_FUNC(bufenc_init), 2);
134
+ rb_define_method(cBufEncoder, "continue", RUBY_METHOD_FUNC(bufenc_continue), 4);
135
+ rb_define_method(cBufEncoder, "flush", RUBY_METHOD_FUNC(bufenc_flush), 2);
136
+ rb_define_method(cBufEncoder, "end", RUBY_METHOD_FUNC(bufenc_end), 2);
137
+ rb_define_singleton_method(cBufEncoder, "recommended_insize", RUBY_METHOD_FUNC(bufenc_s_recommended_insize), 0);
138
+ rb_define_singleton_method(cBufEncoder, "recommended_outsize", RUBY_METHOD_FUNC(bufenc_s_recommended_outsize), 0);
139
+ }
140
+
141
+ /*
142
+ * class Zstd::BufferedDecoder
143
+ */
144
+
145
+ static void
146
+ bufdec_free(void *p)
147
+ {
148
+ ZBUFF_freeDCtx(p);
149
+ }
150
+
151
+ AUX_IMPLEMENT_CONTEXT(
152
+ ZBUFF_DCtx, bufdec_datatype, "extzstd.BufferedDecoder",
153
+ bufdec_alloc_dummy, NULL, bufdec_free, NULL,
154
+ getbufdecp, getbufdec, bufdec_p);
155
+
156
+ static VALUE
157
+ bufdec_alloc(VALUE mod)
158
+ {
159
+ ZBUFF_DCtx *p = ZBUFF_createDCtx();
160
+ if (!p) {
161
+ rb_gc();
162
+ p = ZBUFF_createDCtx();
163
+ if (!p) {
164
+ rb_raise(extzstd_eError, "failed ZBUFF_createDCtx()");
165
+ }
166
+ }
167
+
168
+ return TypedData_Wrap_Struct(mod, &bufdec_datatype, p);
169
+ }
170
+
171
+ static VALUE
172
+ bufdec_init(VALUE dec, VALUE dict)
173
+ {
174
+ /*
175
+ * ZSTDLIB_API size_t ZBUFF_decompressInitDictionary(ZBUFF_DCtx* dctx, const void* dict, size_t dictSize);
176
+ */
177
+
178
+ ZBUFF_DCtx *p = getbufdec(dec);
179
+ if (!NIL_P(dict)) {
180
+ rb_check_type(dict, RUBY_T_STRING);
181
+ if (RSTRING_LEN(dict) > 0) {
182
+ dict = rb_str_new_frozen(dict);
183
+ rb_obj_infect(dec, dict);
184
+ size_t s = ZBUFF_decompressInitDictionary(p, RSTRING_PTR(dict), RSTRING_LEN(dict));
185
+ extzstd_check_error(s);
186
+ rb_iv_set(dec, "extzstd.dictionary for gc-guard", dict);
187
+ return dec;
188
+ }
189
+ }
190
+
191
+ size_t s = aux_ZBUFF_decompressInit(p);
192
+ extzstd_check_error(s);
193
+
194
+ return dec;
195
+ }
196
+
197
+ /*
198
+ * call-seq:
199
+ * continue(src, srcoff, dest, maxdestsize) -> srcoff or nil
200
+ */
201
+ static VALUE
202
+ bufdec_continue(VALUE dec, VALUE src, VALUE srcoff, VALUE dest, VALUE maxdest)
203
+ {
204
+ ZBUFF_DCtx *p = getbufdec(dec);
205
+ rb_check_type(src, RUBY_T_STRING);
206
+ rb_check_type(dest, RUBY_T_STRING);
207
+ const char *srcp;
208
+ size_t srcsize;
209
+ RSTRING_GETMEM(src, srcp, srcsize);
210
+ size_t srcoff1 = NUM2SIZET(srcoff);
211
+ if (srcoff1 >= srcsize) {
212
+ rb_raise(rb_eArgError,
213
+ "``srcoff'' is out of src size (%"PRIuSIZE" for 0...%"PRIuSIZE")",
214
+ srcoff1, srcsize);
215
+ }
216
+ srcp += srcoff1;
217
+ srcsize -= srcoff1;
218
+ size_t destsize = NUM2SIZET(maxdest);
219
+ aux_str_modify_expand(dest, destsize);
220
+ char *destp = RSTRING_PTR(dest);
221
+ rb_obj_infect(dec, src);
222
+ rb_obj_infect(dest, dec);
223
+ size_t s = aux_ZBUFF_decompressContinue(p, destp, &destsize, srcp, &srcsize);
224
+ extzstd_check_error(s);
225
+ rb_str_set_len(dest, destsize);
226
+ if (srcsize == 0) {
227
+ return Qnil;
228
+ } else {
229
+ return SIZET2NUM(srcoff1 + srcsize);
230
+ }
231
+ }
232
+
233
+ static VALUE
234
+ bufdec_s_recommended_insize(VALUE mod)
235
+ {
236
+ return SIZET2NUM(ZBUFF_recommendedDInSize());
237
+ }
238
+
239
+ static VALUE
240
+ bufdec_s_recommended_outsize(VALUE mod)
241
+ {
242
+ return SIZET2NUM(ZBUFF_recommendedDOutSize());
243
+ }
244
+
245
+ static void
246
+ init_buffered_decoder(void)
247
+ {
248
+ VALUE cBufDecoder = rb_define_class_under(extzstd_mZstd, "BufferedDecoder", rb_cObject);
249
+ rb_define_alloc_func(cBufDecoder, bufdec_alloc);
250
+ rb_define_method(cBufDecoder, "initialize", RUBY_METHOD_FUNC(bufdec_init), 1);
251
+ rb_define_method(cBufDecoder, "continue", RUBY_METHOD_FUNC(bufdec_continue), 4);
252
+ rb_define_singleton_method(cBufDecoder, "recommended_insize", RUBY_METHOD_FUNC(bufdec_s_recommended_insize), 0);
253
+ rb_define_singleton_method(cBufDecoder, "recommended_outsize", RUBY_METHOD_FUNC(bufdec_s_recommended_outsize), 0);
254
+ }
255
+
256
+ /*
257
+ * generic
258
+ */
259
+
260
+ void
261
+ extzstd_init_buffered(void)
262
+ {
263
+ init_buffered_encoder();
264
+ init_buffered_decoder();
265
+ }
@@ -0,0 +1,174 @@
1
+ #ifndef EXTZSTD_NOGVLS_H
2
+ #define EXTZSTD_NOGVLS_H 1
3
+
4
+ #include "extzstd.h"
5
+
6
+ static inline void *
7
+ aux_thread_call_without_gvl(void *(*func)(va_list *), void (*cancel)(va_list *), ...)
8
+ {
9
+ va_list va1, va2;
10
+ va_start(va1, cancel);
11
+ va_start(va2, cancel);
12
+ void *p = rb_thread_call_without_gvl(
13
+ (void *(*)(void *))func, &va1,
14
+ (void (*)(void *))cancel, &va2);
15
+ va_end(va2);
16
+ va_end(va1);
17
+ return p;
18
+ }
19
+
20
+ static void *
21
+ aux_ZSTD_compress_nogvl(va_list *vp)
22
+ {
23
+ char *dest = va_arg(*vp, char *);
24
+ size_t destsize = va_arg(*vp, size_t);
25
+ const char *src = va_arg(*vp, const char *);
26
+ size_t srcsize = va_arg(*vp, size_t);
27
+ int level = va_arg(*vp, int);
28
+ return (void *)ZSTD_compress(dest, destsize, src, srcsize, level);
29
+ }
30
+
31
+ static inline size_t
32
+ aux_ZSTD_compress(char *dest, size_t destsize, const char *src, size_t srcsize, int level)
33
+ {
34
+ return (size_t)aux_thread_call_without_gvl(
35
+ aux_ZSTD_compress_nogvl, NULL,
36
+ dest, destsize, src, srcsize, level);
37
+ }
38
+
39
+ static void *
40
+ aux_ZSTD_decompress_nogvl(va_list *vp)
41
+ {
42
+ char *dest = va_arg(*vp, char *);
43
+ size_t destsize = va_arg(*vp, size_t);
44
+ const char *src = va_arg(*vp, const char *);
45
+ size_t srcsize = va_arg(*vp, size_t);
46
+ return (void *)ZSTD_decompress(dest, destsize, src, srcsize);
47
+ }
48
+
49
+ static inline size_t
50
+ aux_ZSTD_decompress(char *dest, size_t destsize, const char *src, size_t srcsize)
51
+ {
52
+ return (size_t)aux_thread_call_without_gvl(
53
+ aux_ZSTD_decompress_nogvl, NULL,
54
+ dest, destsize, src, srcsize);
55
+ }
56
+
57
+ static void *
58
+ aux_ZBUFF_compressInit_nogvl(va_list *vp)
59
+ {
60
+ ZBUFF_CCtx *p = va_arg(*vp, ZBUFF_CCtx *);
61
+ const void *dict = va_arg(*vp, const void *);
62
+ size_t dictsize = va_arg(*vp, size_t);
63
+ int level = va_arg(*vp, int);
64
+ return (void *)ZBUFF_compressInitDictionary(p, dict, dictsize, level);
65
+ }
66
+
67
+ static inline size_t
68
+ aux_ZBUFF_compressInitDictionary(ZBUFF_CCtx *p, const void* dict, size_t dictsize, int level)
69
+ {
70
+ return (size_t)aux_thread_call_without_gvl(
71
+ aux_ZBUFF_compressInit_nogvl, NULL, p, dict, dictsize, level);
72
+ }
73
+
74
+ static inline void *
75
+ aux_ZBUFF_compressInit_advanced_nogvl(va_list *vp)
76
+ {
77
+ ZBUFF_CCtx *p = va_arg(*vp, ZBUFF_CCtx *);
78
+ const void *dict = va_arg(*vp, const void *);
79
+ size_t dictsize = va_arg(*vp, size_t);
80
+ const ZSTD_parameters *q = va_arg(*vp, const ZSTD_parameters *);
81
+ unsigned long long pledgedsrcsize = va_arg(*vp, unsigned long long);
82
+ return (void *)ZBUFF_compressInit_advanced(p, dict, dictsize, *q, pledgedsrcsize);
83
+ }
84
+
85
+ static inline size_t
86
+ aux_ZBUFF_compressInit_advanced(ZBUFF_CCtx *p, const void *dict, size_t dictsize, const ZSTD_parameters *q, unsigned long long pledgedsrcsize)
87
+ {
88
+ return (size_t)aux_thread_call_without_gvl(
89
+ aux_ZBUFF_compressInit_advanced_nogvl, NULL, p, dict, dictsize, q, pledgedsrcsize);
90
+ }
91
+
92
+ static inline void *
93
+ aux_ZBUFF_compressContinue_nogvl(va_list *vp)
94
+ {
95
+ ZBUFF_CCtx *p = va_arg(*vp, ZBUFF_CCtx *);
96
+ char *destp = va_arg(*vp, char *);
97
+ size_t *destsize = va_arg(*vp, size_t *);
98
+ const char *srcp = va_arg(*vp, const char *);
99
+ size_t *srcsize = va_arg(*vp, size_t *);
100
+ return (void *)ZBUFF_compressContinue(p, destp, destsize, srcp, srcsize);
101
+ }
102
+
103
+ static inline size_t
104
+ aux_ZBUFF_compressContinue(ZBUFF_CCtx *p, char *destp, size_t *destsize, const char *srcp, size_t *srcsize)
105
+ {
106
+ return (size_t)aux_thread_call_without_gvl(
107
+ aux_ZBUFF_compressContinue_nogvl, NULL, p, destp, destsize, srcp, srcsize);
108
+ }
109
+
110
+ static inline void *
111
+ aux_ZBUFF_compressFlush_nogvl(va_list *vp)
112
+ {
113
+ ZBUFF_CCtx *p = va_arg(*vp, ZBUFF_CCtx *);
114
+ char *destp = va_arg(*vp, char *);
115
+ size_t *destsize = va_arg(*vp, size_t *);
116
+ return (void *)ZBUFF_compressFlush(p, destp, destsize);
117
+ }
118
+
119
+ static inline size_t
120
+ aux_ZBUFF_compressFlush(ZBUFF_CCtx *p, char *destp, size_t *destsize)
121
+ {
122
+ return (size_t)aux_thread_call_without_gvl(
123
+ aux_ZBUFF_compressFlush_nogvl, NULL, p, destp, destsize);
124
+ }
125
+
126
+ static inline void *
127
+ aux_ZBUFF_compressEnd_nogvl(va_list *vp)
128
+ {
129
+ ZBUFF_CCtx *p = va_arg(*vp, ZBUFF_CCtx *);
130
+ char *destp = va_arg(*vp, char *);
131
+ size_t *destsize = va_arg(*vp, size_t *);
132
+ return (void *)ZBUFF_compressEnd(p, destp, destsize);
133
+ }
134
+
135
+ static inline size_t
136
+ aux_ZBUFF_compressEnd(ZBUFF_CCtx *p, char *destp, size_t *destsize)
137
+ {
138
+ return (size_t)aux_thread_call_without_gvl(
139
+ aux_ZBUFF_compressEnd_nogvl, NULL, p, destp, destsize);
140
+ }
141
+
142
+ static inline void *
143
+ aux_ZBUFF_decompressInit_nogvl(va_list *vp)
144
+ {
145
+ ZBUFF_DCtx *p = va_arg(*vp, ZBUFF_DCtx *);
146
+ return (void *)ZBUFF_decompressInit(p);
147
+ }
148
+
149
+ static inline size_t
150
+ aux_ZBUFF_decompressInit(ZBUFF_DCtx *p)
151
+ {
152
+ return (size_t)aux_thread_call_without_gvl(
153
+ aux_ZBUFF_decompressInit_nogvl, NULL, p);
154
+ }
155
+
156
+ static inline void *
157
+ aux_ZBUFF_decompressContinue_nogvl(va_list *vp)
158
+ {
159
+ ZBUFF_DCtx *p = va_arg(*vp, ZBUFF_DCtx *);
160
+ char *destp = va_arg(*vp, char *);
161
+ size_t *destsize = va_arg(*vp, size_t *);
162
+ const char *srcp = va_arg(*vp, const char *);
163
+ size_t *srcsize = va_arg(*vp, size_t *);
164
+ return (void *)ZBUFF_decompressContinue(p, destp, destsize, srcp, srcsize);
165
+ }
166
+
167
+ static inline size_t
168
+ aux_ZBUFF_decompressContinue(ZBUFF_DCtx *p, char *destp, size_t *destsize, const char *srcp, size_t *srcsize)
169
+ {
170
+ return (size_t)aux_thread_call_without_gvl(
171
+ aux_ZBUFF_decompressContinue_nogvl, NULL, p, destp, destsize, srcp, srcsize);
172
+ }
173
+
174
+ #endif /* EXTZSTD_NOGVLS_H */