extlzham 0.0.1.PROTOTYPE2 → 0.0.1.PROTOTYPE3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38a6dfeed7afbd9178b072cbc682d5d239b396e5
4
- data.tar.gz: a70c0b958bd0b1652830755f20ed86a2df3bc695
3
+ metadata.gz: d819ac9fc3dcfcf43a6667f14bbf27ba1d315d39
4
+ data.tar.gz: 1a5e007e6cbdcada07c80eb9202cd0c4af419840
5
5
  SHA512:
6
- metadata.gz: b2d6760152aac48b4e78646c02ea99fe1f5618a34bda0339de1c00ff955485650adfb389dfc729a02c03bf7d6b59e836f552923ae6810577b8a3acd5d5cebd26
7
- data.tar.gz: 2a4324dd8844f739448e18f0f5654494a7e95d786cc6ee437c98142dd3e03a7179cabe1f402f9562dd260007efc826593c6d52f05540158bd953cb6c4c55d5d9
6
+ metadata.gz: f4fc46857b8a8288263283ca74d21a8876f35d3243a39a1ccba7186e5fc7ece083869451f9e35914d59903682c33cba63c58d18b28263766f4673893d2d51edb
7
+ data.tar.gz: 5e091d4bc1f3639c6bd054f4d1c0ca2a7ad6f00e14c8cf1391c915f1086e86087f6310008ea05af84105999c667b888d786a2bd3dbc7152f3b6dd36ffce6e596
data/README.md CHANGED
@@ -5,16 +5,16 @@
5
5
  This is ruby bindings for compression library
6
6
  [LZHAM (https://github.com/richgel999/lzham\_codec)](https://github.com/richgel999/lzham_codec).
7
7
 
8
- * PACKAGE NAME: extlzham
9
- * AUTHOR: dearblue <dearblue@users.sourceforge.jp>
10
- * VERSION: 0.0.1.PROTOTYPE2
11
- * LICENSING: 2-clause BSD License
12
- * REPORT ISSUE TO: <http://sourceforge.jp/projects/rutsubo/ticket/>
13
- * DEPENDENCY RUBY: ruby-2.0+
14
- * DEPENDENCY RUBY GEMS: (none)
15
- * DEPENDENCY LIBRARY: (none)
16
- * BUNDLED EXTERNAL LIBRARIES:
17
- * LZHAM <https://github.com/richgel999/lzham_codec>
8
+ * package name: extlzham
9
+ * author: dearblue (mailto:dearblue@users.osdn.me)
10
+ * version: 0.0.1.PROTOTYPE2
11
+ * license: 2-clause BSD License (<LICENSE.md>)
12
+ * report issue to: <https://osdn.jp/projects/rutsubo/ticket/>
13
+ * dependency ruby: ruby-2.0+
14
+ * dependency ruby gems: (none)
15
+ * dependency libraries: (none)
16
+ * bundled external libraries:
17
+ * LZHAM-1.0-stable1 <https://github.com/richgel999/lzham_codec/releases/tag/v1_0_stable1>
18
18
 
19
19
 
20
20
  ## HOW TO USE
data/Rakefile CHANGED
@@ -2,13 +2,15 @@
2
2
  require "rake/clean"
3
3
 
4
4
  DOC = FileList["{README,LICENSE,CHANGELOG,Changelog,HISTORY}{,.ja}{,.txt,.rd,.rdoc,.md,.markdown}"] +
5
- FileList["ext/**/{README,LICENSE,CHANGELOG,Changelog,HISTORY}{,.ja}{,.txt,.rd,.rdoc,.md,.markdown}"]
5
+ FileList["{contrib,ext}/**/{README,LICENSE,CHANGELOG,Changelog,HISTORY}{,.ja}{,.txt,.rd,.rdoc,.md,.markdown}"] +
6
+ FileList["ext/**/*.{c,C,cc,cxx,cpp,h,H,hh}"]
6
7
  #EXT = FileList["ext/**/*.{h,hh,c,cc,cpp,cxx}"] +
7
8
  # FileList["ext/externals/**/*"]
8
9
  EXT = FileList["ext/**/*"]
9
10
  BIN = FileList["bin/*"]
10
11
  LIB = FileList["lib/**/*.rb"]
11
12
  SPEC = FileList["spec/**/*"]
13
+ TEST = FileList["test/**/*"]
12
14
  EXAMPLE = FileList["examples/**/*"]
13
15
  GEMSTUB_SRC = "gemstub.rb"
14
16
  RAKEFILE = [File.basename(__FILE__), GEMSTUB_SRC]
@@ -25,9 +27,12 @@ GEMSTUB.executables.sort!
25
27
  GEMFILE = "#{GEMSTUB.name}-#{GEMSTUB.version}.gem"
26
28
  GEMSPEC = "#{GEMSTUB.name}.gemspec"
27
29
 
28
- GEMSTUB.files += DOC + EXT + EXTCONF + BIN + LIB + SPEC + EXAMPLE + RAKEFILE + EXTRA
30
+ GEMSTUB.files += DOC + EXT + EXTCONF + BIN + LIB + SPEC + TEST + EXAMPLE + RAKEFILE + EXTRA
29
31
  GEMSTUB.files.sort!
30
- GEMSTUB.rdoc_options ||= %w(--charset UTF-8)
32
+ if GEMSTUB.rdoc_options.nil? || GEMSTUB.rdoc_options.empty?
33
+ readme = %W(.md .markdown .rd .rdoc .txt #{""}).map { |ext| "README#{ext}" }.find { |m| DOC.find { |n| n == m } }
34
+ GEMSTUB.rdoc_options = %w(--charset UTF-8) + (readme ? %W(-m #{readme}) : [])
35
+ end
31
36
  GEMSTUB.extra_rdoc_files += DOC + LIB + EXT.reject { |n| n.include?("/externals/") || !%w(.h .hh .c .cc .cpp .cxx).include?(File.extname(n)) }
32
37
  GEMSTUB.extra_rdoc_files.sort!
33
38
 
@@ -82,7 +87,7 @@ unless EXTCONF.empty?
82
87
  desc "generate binary gemspec"
83
88
  task "native-gemspec" => GEMSPEC_NATIVE
84
89
 
85
- file GEMFILE_NATIVE => DOC + EXT + EXTCONF + BIN + LIB + SPEC + EXAMPLE + SOFILES + RAKEFILE + [GEMSPEC_NATIVE] do
90
+ file GEMFILE_NATIVE => DOC + EXT + EXTCONF + BIN + LIB + SPEC + TEST + EXAMPLE + SOFILES + RAKEFILE + [GEMSPEC_NATIVE] do
86
91
  sh "gem build #{GEMSPEC_NATIVE}"
87
92
  end
88
93
 
@@ -123,8 +128,8 @@ end
123
128
  task :all => GEMFILE
124
129
 
125
130
  desc "generate local rdoc"
126
- task :rdoc => DOC + EXT + LIB do
127
- sh *(%w(rdoc) + GEMSTUB.rdoc_options + DOC + EXT + LIB)
131
+ task :rdoc => DOC + LIB do
132
+ sh *(%w(rdoc) + GEMSTUB.rdoc_options + DOC + LIB)
128
133
  end
129
134
 
130
135
  desc "launch rspec"
@@ -138,7 +143,7 @@ task gem: GEMFILE
138
143
  desc "generate gemspec"
139
144
  task gemspec: GEMSPEC
140
145
 
141
- file GEMFILE => DOC + EXT + EXTCONF + BIN + LIB + SPEC + EXAMPLE + RAKEFILE + [GEMSPEC] do
146
+ file GEMFILE => DOC + EXT + EXTCONF + BIN + LIB + SPEC + TEST + EXAMPLE + RAKEFILE + [GEMSPEC] do
142
147
  sh "gem build #{GEMSPEC}"
143
148
  end
144
149
 
@@ -83,7 +83,7 @@ written with v1.0. The only thing that could change this are critical bugfixes.<
83
83
 
84
84
  <h3>Platforms/Compiler Support</h3>
85
85
 
86
- LZHAM currently officially supports x86/x64 Linux, iOS, OSX, and Windows x86/x64. At one time the codec compiled and ran fine on Xbox 360 (PPC, big endian). Android support is coming next.
86
+ LZHAM currently officially supports x86/x64 Linux, iOS, OSX, FreeBSD, and Windows x86/x64. At one time the codec compiled and ran fine on Xbox 360 (PPC, big endian). Android support is coming next.
87
87
  It should be easy to retarget by modifying the macros in lzham_core.h.</p>
88
88
 
89
89
  <p>LZHAM has optional support for multithreaded compression. It supports gcc built-ins or MSVC intrinsics for atomic ops. For threading, it supports OSX
data/ext/constants.c CHANGED
@@ -3,8 +3,9 @@
3
3
  VALUE mConsts;
4
4
 
5
5
  void
6
- init_constants(void)
6
+ extlzham_init_constants(void)
7
7
  {
8
+ RDOCFAKE(mLZHAM = rb_define_module("LZHAM"));
8
9
  mConsts = rb_define_module_under(mLZHAM, "Constants");
9
10
  rb_include_module(mLZHAM, mConsts);
10
11
  rb_define_const(mConsts, "NO_FLUSH", INT2FIX(LZHAM_NO_FLUSH));
@@ -13,9 +14,15 @@ init_constants(void)
13
14
  rb_define_const(mConsts, "FINISH", INT2FIX(LZHAM_FINISH));
14
15
  rb_define_const(mConsts, "TABLE_FLUSH", INT2FIX(LZHAM_TABLE_FLUSH));
15
16
  rb_define_const(mConsts, "MIN_DICT_SIZE_LOG2", INT2FIX(LZHAM_MIN_DICT_SIZE_LOG2));
17
+ rb_define_const(mConsts, "MAX_DICT_SIZE_LOG2", INT2FIX(LZHAM_MAX_DICT_SIZE_LOG2_X86));
16
18
  rb_define_const(mConsts, "MAX_DICT_SIZE_LOG2_X86", INT2FIX(LZHAM_MAX_DICT_SIZE_LOG2_X86));
17
19
  rb_define_const(mConsts, "MAX_DICT_SIZE_LOG2_X64", INT2FIX(LZHAM_MAX_DICT_SIZE_LOG2_X64));
18
20
  rb_define_const(mConsts, "MAX_HELPER_THREADS", INT2FIX(LZHAM_MAX_HELPER_THREADS));
21
+ rb_define_const(mConsts, "COMP_LEVEL_FASTEST", INT2FIX(LZHAM_COMP_LEVEL_FASTEST));
22
+ rb_define_const(mConsts, "COMP_LEVEL_FASTER", INT2FIX(LZHAM_COMP_LEVEL_FASTER));
23
+ rb_define_const(mConsts, "COMP_LEVEL_DEFAULT", INT2FIX(LZHAM_COMP_LEVEL_DEFAULT));
24
+ rb_define_const(mConsts, "COMP_LEVEL_BETTER", INT2FIX(LZHAM_COMP_LEVEL_BETTER));
25
+ rb_define_const(mConsts, "COMP_LEVEL_UBER", INT2FIX(LZHAM_COMP_LEVEL_UBER));
19
26
  rb_define_const(mConsts, "COMP_FLAG_EXTREME_PARSING", INT2FIX(LZHAM_COMP_FLAG_EXTREME_PARSING));
20
27
  rb_define_const(mConsts, "COMP_FLAG_DETERMINISTIC_PARSING", INT2FIX(LZHAM_COMP_FLAG_DETERMINISTIC_PARSING));
21
28
  rb_define_const(mConsts, "COMP_FLAG_TRADEOFF_DECOMPRESSION_RATE_FOR_COMP_RATIO", INT2FIX(LZHAM_COMP_FLAG_TRADEOFF_DECOMPRESSION_RATE_FOR_COMP_RATIO));
@@ -27,15 +34,22 @@ init_constants(void)
27
34
  rb_define_const(mConsts, "DECOMP_FLAG_OUTPUT_UNBUFFERED", INT2FIX(LZHAM_DECOMP_FLAG_OUTPUT_UNBUFFERED));
28
35
  rb_define_const(mConsts, "DECOMP_FLAG_COMPUTE_ADLER32", INT2FIX(LZHAM_DECOMP_FLAG_COMPUTE_ADLER32));
29
36
  rb_define_const(mConsts, "DECOMP_FLAG_READ_ZLIB_STREAM", INT2FIX(LZHAM_DECOMP_FLAG_READ_ZLIB_STREAM));
37
+
30
38
  rb_define_const(mConsts, "LZHAM_NO_FLUSH", INT2FIX(LZHAM_NO_FLUSH));
31
39
  rb_define_const(mConsts, "LZHAM_SYNC_FLUSH", INT2FIX(LZHAM_SYNC_FLUSH));
32
40
  rb_define_const(mConsts, "LZHAM_FULL_FLUSH", INT2FIX(LZHAM_FULL_FLUSH));
33
41
  rb_define_const(mConsts, "LZHAM_FINISH", INT2FIX(LZHAM_FINISH));
34
42
  rb_define_const(mConsts, "LZHAM_TABLE_FLUSH", INT2FIX(LZHAM_TABLE_FLUSH));
35
43
  rb_define_const(mConsts, "LZHAM_MIN_DICT_SIZE_LOG2", INT2FIX(LZHAM_MIN_DICT_SIZE_LOG2));
44
+ rb_define_const(mConsts, "LZHAM_MAX_DICT_SIZE_LOG2", INT2FIX(LZHAM_MAX_DICT_SIZE_LOG2_X86));
36
45
  rb_define_const(mConsts, "LZHAM_MAX_DICT_SIZE_LOG2_X86", INT2FIX(LZHAM_MAX_DICT_SIZE_LOG2_X86));
37
46
  rb_define_const(mConsts, "LZHAM_MAX_DICT_SIZE_LOG2_X64", INT2FIX(LZHAM_MAX_DICT_SIZE_LOG2_X64));
38
47
  rb_define_const(mConsts, "LZHAM_MAX_HELPER_THREADS", INT2FIX(LZHAM_MAX_HELPER_THREADS));
48
+ rb_define_const(mConsts, "LZHAM_COMP_LEVEL_FASTEST", INT2FIX(LZHAM_COMP_LEVEL_FASTEST));
49
+ rb_define_const(mConsts, "LZHAM_COMP_LEVEL_FASTER", INT2FIX(LZHAM_COMP_LEVEL_FASTER));
50
+ rb_define_const(mConsts, "LZHAM_COMP_LEVEL_DEFAULT", INT2FIX(LZHAM_COMP_LEVEL_DEFAULT));
51
+ rb_define_const(mConsts, "LZHAM_COMP_LEVEL_BETTER", INT2FIX(LZHAM_COMP_LEVEL_BETTER));
52
+ rb_define_const(mConsts, "LZHAM_COMP_LEVEL_UBER", INT2FIX(LZHAM_COMP_LEVEL_UBER));
39
53
  rb_define_const(mConsts, "LZHAM_COMP_FLAG_EXTREME_PARSING", INT2FIX(LZHAM_COMP_FLAG_EXTREME_PARSING));
40
54
  rb_define_const(mConsts, "LZHAM_COMP_FLAG_DETERMINISTIC_PARSING", INT2FIX(LZHAM_COMP_FLAG_DETERMINISTIC_PARSING));
41
55
  rb_define_const(mConsts, "LZHAM_COMP_FLAG_TRADEOFF_DECOMPRESSION_RATE_FOR_COMP_RATIO", INT2FIX(LZHAM_COMP_FLAG_TRADEOFF_DECOMPRESSION_RATE_FOR_COMP_RATIO));
data/ext/decoder.c CHANGED
@@ -21,13 +21,13 @@ aux_conv_decode_params(VALUE opts)
21
21
  p.m_table_max_update_interval = 0;
22
22
  p.m_table_update_interval_slow_rate = 0;
23
23
  } else {
24
- p.m_dict_size_log2 = aux_hash_lookup_to_u32(opts, IDdictsize, LZHAM_MIN_DICT_SIZE_LOG2);
25
- p.m_table_update_rate = aux_hash_lookup_to_u32(opts, IDtable_update_rate, 0);
26
- p.m_decompress_flags = aux_hash_lookup_to_u32(opts, IDflags, 0);
24
+ p.m_dict_size_log2 = aux_getoptu32(opts, id_dictsize, LZHAM_MIN_DICT_SIZE_LOG2);
25
+ p.m_table_update_rate = aux_getoptu32(opts, id_table_update_rate, 0);
26
+ p.m_decompress_flags = aux_getoptu32(opts, id_flags, 0);
27
27
  p.m_num_seed_bytes = 0;
28
28
  p.m_pSeed_bytes = NULL;
29
- p.m_table_max_update_interval = aux_hash_lookup_to_u32(opts, IDtable_max_update_interval, 0);
30
- p.m_table_update_interval_slow_rate = aux_hash_lookup_to_u32(opts, IDtable_update_interval_slow_rate, 0);
29
+ p.m_table_max_update_interval = aux_getoptu32(opts, id_table_max_update_interval, 0);
30
+ p.m_table_update_interval_slow_rate = aux_getoptu32(opts, id_table_update_interval_slow_rate, 0);
31
31
  }
32
32
 
33
33
  return p;
@@ -38,7 +38,7 @@ aux_conv_decode_params(VALUE opts)
38
38
  * decode(string, max_decoded_size, opts = {}) -> decoded string
39
39
  */
40
40
  static VALUE
41
- ext_s_decode(int argc, VALUE argv[], VALUE mod)
41
+ dec_s_decode(int argc, VALUE argv[], VALUE mod)
42
42
  {
43
43
  VALUE src, size, opts;
44
44
  rb_scan_args(argc, argv, "2:", &src, &size, &opts);
@@ -57,7 +57,7 @@ ext_s_decode(int argc, VALUE argv[], VALUE mod)
57
57
 
58
58
  if (s != LZHAM_DECOMP_STATUS_SUCCESS) {
59
59
  rb_str_resize(dest, 0);
60
- aux_decode_error(s);
60
+ extlzham_decode_error(s);
61
61
  }
62
62
 
63
63
  rb_str_resize(dest, destsize);
@@ -74,7 +74,7 @@ struct decoder
74
74
  };
75
75
 
76
76
  static void
77
- ext_dec_mark(struct decoder *p)
77
+ dec_mark(struct decoder *p)
78
78
  {
79
79
  if (p) {
80
80
  rb_gc_mark(p->outport);
@@ -83,7 +83,7 @@ ext_dec_mark(struct decoder *p)
83
83
  }
84
84
 
85
85
  static void
86
- ext_dec_free(struct decoder *p)
86
+ dec_free(struct decoder *p)
87
87
  {
88
88
  if (p) {
89
89
  if (p->decoder) {
@@ -93,15 +93,15 @@ ext_dec_free(struct decoder *p)
93
93
  }
94
94
 
95
95
  static VALUE
96
- ext_dec_alloc(VALUE klass)
96
+ dec_alloc(VALUE klass)
97
97
  {
98
98
  struct decoder *p;
99
- VALUE obj = Data_Make_Struct(klass, struct decoder, ext_dec_mark, ext_dec_free, p);
99
+ VALUE obj = Data_Make_Struct(klass, struct decoder, dec_mark, dec_free, p);
100
100
  return obj;
101
101
  }
102
102
 
103
103
  static inline struct decoder *
104
- aux_decoder_refp(VALUE obj)
104
+ getdecoderp(VALUE obj)
105
105
  {
106
106
  struct decoder *p;
107
107
  Data_Get_Struct(obj, struct decoder, p);
@@ -109,9 +109,9 @@ aux_decoder_refp(VALUE obj)
109
109
  }
110
110
 
111
111
  static inline struct decoder *
112
- aux_decoder_ref(VALUE obj)
112
+ getdecoder(VALUE obj)
113
113
  {
114
- struct decoder *p = aux_decoder_refp(obj);
114
+ struct decoder *p = getdecoderp(obj);
115
115
  if (!p || !p->decoder) {
116
116
  rb_raise(eError,
117
117
  "not initialized - #<%s:%p>",
@@ -125,7 +125,7 @@ aux_decoder_ref(VALUE obj)
125
125
  * initialize(outport = nil, opts = {})
126
126
  */
127
127
  static VALUE
128
- ext_dec_init(int argc, VALUE argv[], VALUE dec)
128
+ dec_init(int argc, VALUE argv[], VALUE dec)
129
129
  {
130
130
  struct decoder *p = DATA_PTR(dec);
131
131
  if (p->decoder) {
@@ -196,7 +196,7 @@ struct dec_update_args
196
196
  static VALUE
197
197
  dec_update_protected(struct dec_update_args *args)
198
198
  {
199
- struct decoder *p = aux_decoder_ref(args->decoder);
199
+ struct decoder *p = getdecoder(args->decoder);
200
200
  const char *inbuf, *intail;
201
201
 
202
202
  if (NIL_P(args->src)) {
@@ -217,7 +217,7 @@ dec_update_protected(struct dec_update_args *args)
217
217
  (lzham_uint8 *)inbuf, &insize,
218
218
  (lzham_uint8 *)RSTRING_PTR(p->outbuf), &outsize, args->flush);
219
219
  rb_str_unlocktmp(p->outbuf);
220
- //fprintf(stderr, "%s:%d:%s: status=%s (%d), insize=%zu, outsize=%zu\n", __FILE__, __LINE__, __func__, aux_decode_status_str(s), s, insize, outsize);
220
+ //fprintf(stderr, "%s:%d:%s: status=%s (%d), insize=%zu, outsize=%zu\n", __FILE__, __LINE__, __func__, extlzham_decode_status_str(s), s, insize, outsize);
221
221
  if (!NIL_P(args->src)) {
222
222
  inbuf += insize;
223
223
  }
@@ -226,11 +226,11 @@ dec_update_protected(struct dec_update_args *args)
226
226
  s != LZHAM_DECOMP_STATUS_NEEDS_MORE_INPUT &&
227
227
  s != LZHAM_DECOMP_STATUS_SUCCESS) {
228
228
 
229
- aux_decode_error(s);
229
+ extlzham_decode_error(s);
230
230
  }
231
231
  if (outsize > 0) {
232
232
  rb_str_set_len(p->outbuf, outsize);
233
- rb_funcall2(p->outport, ID_op_lshift, 1, &p->outbuf);
233
+ rb_funcall2(p->outport, id_op_lshift, 1, &p->outbuf);
234
234
  }
235
235
  } while (inbuf < intail || s == LZHAM_DECOMP_STATUS_HAS_MORE_OUTPUT);
236
236
 
@@ -238,7 +238,7 @@ dec_update_protected(struct dec_update_args *args)
238
238
  }
239
239
 
240
240
  static inline void
241
- dec_update(VALUE dec, VALUE src, int flush)
241
+ dec_update_common(VALUE dec, VALUE src, int flush)
242
242
  {
243
243
  struct dec_update_args args = { dec, src, flush };
244
244
  if (NIL_P(src)) {
@@ -259,57 +259,55 @@ dec_update(VALUE dec, VALUE src, int flush)
259
259
  * update(src, flush = false) -> self
260
260
  */
261
261
  static VALUE
262
- ext_dec_update(int argc, VALUE argv[], VALUE dec)
262
+ dec_update(int argc, VALUE argv[], VALUE dec)
263
263
  {
264
264
  VALUE src, flush;
265
265
  rb_scan_args(argc, argv, "11", &src, &flush);
266
266
  rb_check_type(src, RUBY_T_STRING);
267
- dec_update(dec, src, RTEST(flush) ? 1 : 0);
267
+ dec_update_common(dec, src, RTEST(flush) ? 1 : 0);
268
268
  return dec;
269
269
  }
270
270
 
271
271
  static VALUE
272
- ext_dec_finish(VALUE dec)
272
+ dec_finish(VALUE dec)
273
273
  {
274
- dec_update(dec, Qnil, 1);
274
+ dec_update_common(dec, Qnil, 1);
275
275
  return dec;
276
276
  }
277
277
 
278
278
  static VALUE
279
- ext_dec_op_lshift(VALUE dec, VALUE src)
279
+ dec_op_lshift(VALUE dec, VALUE src)
280
280
  {
281
281
  rb_check_type(src, RUBY_T_STRING);
282
- dec_update(dec, src, 0);
282
+ dec_update_common(dec, src, 0);
283
283
  return dec;
284
284
  }
285
285
 
286
286
  static VALUE
287
- ext_dec_get_outport(VALUE dec)
287
+ dec_get_outport(VALUE dec)
288
288
  {
289
- struct decoder *p = aux_decoder_ref(dec);
290
- return p->outport;
289
+ return getdecoder(dec)->outport;
291
290
  }
292
291
 
293
292
  static VALUE
294
- ext_dec_set_outport(VALUE dec, VALUE outport)
293
+ dec_set_outport(VALUE dec, VALUE outport)
295
294
  {
296
- struct decoder *p = aux_decoder_ref(dec);
297
- p->outport = outport;
298
- return outport;
295
+ return getdecoder(dec)->outport = outport;
299
296
  }
300
297
 
301
298
  void
302
- init_decoder(void)
299
+ extlzham_init_decoder(void)
303
300
  {
301
+ RDOCFAKE(mLZHAM = rb_define_module("LZHAM"));
304
302
  cDecoder = rb_define_class_under(mLZHAM, "Decoder", rb_cObject);
305
303
  rb_include_module(cDecoder, mConsts);
306
- rb_define_alloc_func(cDecoder, ext_dec_alloc);
307
- rb_define_singleton_method(cDecoder, "decode", RUBY_METHOD_FUNC(ext_s_decode), -1);
308
- rb_define_method(cDecoder, "initialize", RUBY_METHOD_FUNC(ext_dec_init), -1);
309
- rb_define_method(cDecoder, "update", RUBY_METHOD_FUNC(ext_dec_update), -1);
310
- rb_define_method(cDecoder, "finish", RUBY_METHOD_FUNC(ext_dec_finish), 0);
311
- rb_define_method(cDecoder, "<<", RUBY_METHOD_FUNC(ext_dec_op_lshift), 1);
312
- rb_define_method(cDecoder, "outport", RUBY_METHOD_FUNC(ext_dec_get_outport), 0);
313
- rb_define_method(cDecoder, "outport=", RUBY_METHOD_FUNC(ext_dec_set_outport), 1);
304
+ rb_define_alloc_func(cDecoder, dec_alloc);
305
+ rb_define_singleton_method(cDecoder, "decode", RUBY_METHOD_FUNC(dec_s_decode), -1);
306
+ rb_define_method(cDecoder, "initialize", RUBY_METHOD_FUNC(dec_init), -1);
307
+ rb_define_method(cDecoder, "update", RUBY_METHOD_FUNC(dec_update), -1);
308
+ rb_define_method(cDecoder, "finish", RUBY_METHOD_FUNC(dec_finish), 0);
309
+ rb_define_method(cDecoder, "<<", RUBY_METHOD_FUNC(dec_op_lshift), 1);
310
+ rb_define_method(cDecoder, "outport", RUBY_METHOD_FUNC(dec_get_outport), 0);
311
+ rb_define_method(cDecoder, "outport=", RUBY_METHOD_FUNC(dec_set_outport), 1);
314
312
 
315
313
  }
data/ext/encoder.c CHANGED
@@ -19,15 +19,15 @@ scan_encode_params(VALUE opts)
19
19
  p.m_table_max_update_interval = 0;
20
20
  p.m_table_update_interval_slow_rate = 0;
21
21
  } else {
22
- p.m_dict_size_log2 = aux_hash_lookup_to_u32(opts, IDdictsize, LZHAM_MIN_DICT_SIZE_LOG2);
23
- p.m_level = aux_hash_lookup_to_u32(opts, IDlevel, LZHAM_COMP_LEVEL_DEFAULT);
24
- p.m_table_update_rate = aux_hash_lookup_to_u32(opts, IDtable_update_rate, 0);
25
- p.m_max_helper_threads = aux_hash_lookup_to_u32(opts, IDthreads, -1);
26
- p.m_compress_flags = aux_hash_lookup_to_u32(opts, IDflags, 0);
22
+ p.m_dict_size_log2 = aux_getoptu32(opts, id_dictsize, LZHAM_MIN_DICT_SIZE_LOG2);
23
+ p.m_level = aux_getoptu32(opts, id_level, LZHAM_COMP_LEVEL_DEFAULT);
24
+ p.m_table_update_rate = aux_getoptu32(opts, id_table_update_rate, 0);
25
+ p.m_max_helper_threads = aux_getoptu32(opts, id_threads, -1);
26
+ p.m_compress_flags = aux_getoptu32(opts, id_flags, 0);
27
27
  p.m_num_seed_bytes = 0;
28
28
  p.m_pSeed_bytes = NULL;
29
- p.m_table_max_update_interval = aux_hash_lookup_to_u32(opts, IDtable_max_update_interval, 0);
30
- p.m_table_update_interval_slow_rate = aux_hash_lookup_to_u32(opts, IDtable_update_interval_slow_rate, 0);
29
+ p.m_table_max_update_interval = aux_getoptu32(opts, id_table_max_update_interval, 0);
30
+ p.m_table_update_interval_slow_rate = aux_getoptu32(opts, id_table_update_interval_slow_rate, 0);
31
31
  }
32
32
  return p;
33
33
  }
@@ -38,16 +38,13 @@ scan_encode_args(int argc, VALUE argv[], VALUE *src, size_t *srcsize, VALUE *des
38
38
  VALUE opts;
39
39
  rb_scan_args(argc, argv, "11:", src, dest, &opts);
40
40
  rb_check_type(*src, RUBY_T_STRING);
41
- //rb_str_locktmp(src);
42
41
  *srcsize = RSTRING_LEN(*src);
43
42
  *destsize = lzham_z_compressBound(*srcsize);
44
43
  if (NIL_P(*dest)) {
45
44
  *dest = rb_str_buf_new(*destsize);
46
45
  } else {
47
46
  rb_check_type(*dest, RUBY_T_STRING);
48
- rb_str_modify(*dest);
49
- rb_str_set_len(*dest, 0);
50
- rb_str_modify_expand(*dest, *destsize);
47
+ aux_str_reserve(*dest, *destsize);
51
48
  }
52
49
  *params = scan_encode_params(opts);
53
50
  }
@@ -58,7 +55,7 @@ scan_encode_args(int argc, VALUE argv[], VALUE *src, size_t *srcsize, VALUE *des
58
55
  * encode(src, dest, opts = {}) -> encoded string
59
56
  */
60
57
  static VALUE
61
- ext_s_encode(int argc, VALUE argv[], VALUE mod)
58
+ enc_s_encode(int argc, VALUE argv[], VALUE mod)
62
59
  {
63
60
  VALUE src, dest;
64
61
  size_t srcsize, destsize;
@@ -66,16 +63,13 @@ ext_s_encode(int argc, VALUE argv[], VALUE mod)
66
63
  scan_encode_args(argc, argv, &src, &srcsize, &dest, &destsize, &params);
67
64
  lzham_compress_status_t s;
68
65
  s = lzham_compress_memory(&params,
69
- (lzham_uint8 *)RSTRING_PTR(dest), &destsize,
70
- (lzham_uint8 *)RSTRING_PTR(src), srcsize, NULL);
71
- //rb_str_unlocktmp(src);
66
+ (lzham_uint8 *)RSTRING_PTR(dest), &destsize,
67
+ (const lzham_uint8 *)RSTRING_PTR(src), srcsize, NULL);
72
68
 
73
69
  if (s != LZHAM_COMP_STATUS_SUCCESS) {
74
- rb_str_resize(dest, 0);
75
- aux_encode_error(s);
70
+ extlzham_encode_error(s);
76
71
  }
77
72
 
78
- rb_str_resize(dest, destsize);
79
73
  rb_str_set_len(dest, destsize);
80
74
 
81
75
  return dest;
@@ -89,7 +83,7 @@ struct encoder
89
83
  };
90
84
 
91
85
  static void
92
- ext_enc_mark(struct encoder *p)
86
+ enc_mark(struct encoder *p)
93
87
  {
94
88
  if (p) {
95
89
  rb_gc_mark(p->outport);
@@ -98,7 +92,7 @@ ext_enc_mark(struct encoder *p)
98
92
  }
99
93
 
100
94
  static void
101
- ext_enc_free(struct encoder *p)
95
+ enc_free(struct encoder *p)
102
96
  {
103
97
  if (p) {
104
98
  if (p->encoder) {
@@ -108,15 +102,15 @@ ext_enc_free(struct encoder *p)
108
102
  }
109
103
 
110
104
  static VALUE
111
- ext_enc_alloc(VALUE klass)
105
+ enc_alloc(VALUE klass)
112
106
  {
113
107
  struct encoder *p;
114
- VALUE obj = Data_Make_Struct(klass, struct encoder, ext_enc_mark, ext_enc_free, p);
108
+ VALUE obj = Data_Make_Struct(klass, struct encoder, enc_mark, enc_free, p);
115
109
  return obj;
116
110
  }
117
111
 
118
112
  static inline struct encoder *
119
- aux_encoder_refp(VALUE obj)
113
+ getencoderp(VALUE obj)
120
114
  {
121
115
  struct encoder *p;
122
116
  Data_Get_Struct(obj, struct encoder, p);
@@ -124,9 +118,9 @@ aux_encoder_refp(VALUE obj)
124
118
  }
125
119
 
126
120
  static inline struct encoder *
127
- aux_encoder_ref(VALUE obj)
121
+ getencoder(VALUE obj)
128
122
  {
129
- struct encoder *p = aux_encoder_refp(obj);
123
+ struct encoder *p = getencoderp(obj);
130
124
  if (!p || !p->encoder) {
131
125
  rb_raise(eError,
132
126
  "not initialized - #<%s:%p>",
@@ -140,7 +134,7 @@ aux_encoder_ref(VALUE obj)
140
134
  * initialize(outport = nil, opts = {})
141
135
  */
142
136
  static VALUE
143
- ext_enc_init(int argc, VALUE argv[], VALUE enc)
137
+ enc_init(int argc, VALUE argv[], VALUE enc)
144
138
  {
145
139
  struct encoder *p = DATA_PTR(enc);
146
140
  if (p->encoder) {
@@ -212,7 +206,7 @@ aux_lzham_compress2(lzham_compress_state_ptr state,
212
206
  static VALUE
213
207
  enc_update_protected(struct enc_update_args *args)
214
208
  {
215
- struct encoder *p = aux_encoder_ref(args->encoder);
209
+ struct encoder *p = getencoder(args->encoder);
216
210
  const char *inbuf, *intail;
217
211
 
218
212
  if (NIL_P(args->src)) {
@@ -236,17 +230,17 @@ enc_update_protected(struct enc_update_args *args)
236
230
  if (!NIL_P(args->src)) {
237
231
  inbuf += insize;
238
232
  }
239
- //fprintf(stderr, "%s:%d:%s: status=%s (%d), insize=%zu, outsize=%zu\n", __FILE__, __LINE__, __func__, aux_encode_status_str(s), s, insize, outsize);
233
+ //fprintf(stderr, "%s:%d:%s: status=%s (%d), insize=%zu, outsize=%zu\n", __FILE__, __LINE__, __func__, extlzham_encode_status_str(s), s, insize, outsize);
240
234
  if (s != LZHAM_COMP_STATUS_SUCCESS &&
241
235
  s != LZHAM_COMP_STATUS_NEEDS_MORE_INPUT &&
242
236
  s != LZHAM_COMP_STATUS_NOT_FINISHED &&
243
237
  s != LZHAM_COMP_STATUS_HAS_MORE_OUTPUT) {
244
238
 
245
- aux_encode_error(s);
239
+ extlzham_encode_error(s);
246
240
  }
247
241
  if (outsize > 0) {
248
242
  rb_str_set_len(p->outbuf, outsize);
249
- rb_funcall2(p->outport, ID_op_lshift, 1, &p->outbuf);
243
+ rb_funcall2(p->outport, id_op_lshift, 1, &p->outbuf);
250
244
  }
251
245
  } while (inbuf < intail || s == LZHAM_COMP_STATUS_HAS_MORE_OUTPUT);
252
246
 
@@ -254,7 +248,7 @@ enc_update_protected(struct enc_update_args *args)
254
248
  }
255
249
 
256
250
  static inline void
257
- enc_update(VALUE enc, VALUE src, int flush)
251
+ enc_update_common(VALUE enc, VALUE src, int flush)
258
252
  {
259
253
  struct enc_update_args args = { enc, src, flush };
260
254
  if (NIL_P(src)) {
@@ -275,64 +269,104 @@ enc_update(VALUE enc, VALUE src, int flush)
275
269
  * update(src, flush = LZHAM::NO_FLUSH) -> self
276
270
  */
277
271
  static VALUE
278
- ext_enc_update(int argc, VALUE argv[], VALUE enc)
272
+ enc_update(int argc, VALUE argv[], VALUE enc)
279
273
  {
280
274
  VALUE src, flush;
281
275
  rb_scan_args(argc, argv, "11", &src, &flush);
282
276
  rb_check_type(src, RUBY_T_STRING);
283
277
  if (NIL_P(flush)) {
284
- enc_update(enc, src, LZHAM_NO_FLUSH);
278
+ enc_update_common(enc, src, LZHAM_NO_FLUSH);
285
279
  } else {
286
- enc_update(enc, src, NUM2INT(flush));
280
+ enc_update_common(enc, src, NUM2INT(flush));
287
281
  }
288
282
  return enc;
289
283
  }
290
284
 
285
+ /*
286
+ * call-seq:
287
+ * write(src) -> self
288
+ * self << src -> self
289
+ *
290
+ * same as <tt>enc.update(src)</tt>
291
+ */
291
292
  static VALUE
292
- ext_enc_finish(VALUE enc)
293
+ enc_write(VALUE enc, VALUE src)
293
294
  {
294
- enc_update(enc, Qnil, LZHAM_FINISH);
295
+ rb_check_type(src, RUBY_T_STRING);
296
+ enc_update_common(enc, src, LZHAM_NO_FLUSH);
295
297
  return enc;
296
298
  }
297
299
 
298
300
  /*
299
- * same as <tt>enc.update(src)</tt>
301
+ * call-seq:
302
+ * flush(flush = LZHAM::SYNC_FLUSH) -> self
303
+ *
304
+ * Accept flush types: LZHAM::SYNC_FLUSH, LZHAM::FULL_FLUSH, LZHAM::TABLE_FLUSH
300
305
  */
301
306
  static VALUE
302
- ext_enc_op_lshift(VALUE enc, VALUE src)
307
+ enc_flush(int argc, VALUE argv[], VALUE enc)
303
308
  {
304
- rb_check_type(src, RUBY_T_STRING);
305
- enc_update(enc, src, LZHAM_NO_FLUSH);
309
+ int flush;
310
+ switch (argc) {
311
+ case 0:
312
+ flush = LZHAM_SYNC_FLUSH;
313
+ break;
314
+ case 1:
315
+ flush = NUM2INT(argv[0]);
316
+ if (flush != LZHAM_SYNC_FLUSH &&
317
+ flush != LZHAM_FULL_FLUSH &&
318
+ flush != LZHAM_TABLE_FLUSH) {
319
+
320
+ rb_raise(rb_eArgError,
321
+ "wrong flush type (%d for LZHAM::SYNC_FLUSH (%d), LZHAM::FULL_FLUSH (%d) and LZHAM::TABLE_FLUSH (%d))",
322
+ flush, LZHAM_SYNC_FLUSH, LZHAM_FULL_FLUSH, LZHAM_TABLE_FLUSH);
323
+ }
324
+ break;
325
+ default:
326
+ rb_error_arity(argc, 0, 1);
327
+ }
328
+
329
+ enc_update_common(enc, Qnil, flush);
330
+
331
+ return enc;
332
+ }
333
+
334
+ static VALUE
335
+ enc_finish(VALUE enc)
336
+ {
337
+ enc_update_common(enc, Qnil, LZHAM_FINISH);
306
338
  return enc;
307
339
  }
308
340
 
309
341
 
310
342
  static VALUE
311
- ext_enc_get_outport(VALUE enc)
343
+ enc_get_outport(VALUE enc)
312
344
  {
313
- struct encoder *p = aux_encoder_ref(enc);
314
- return p->outport;
345
+ return getencoder(enc)->outport;
315
346
  }
316
347
 
317
348
  static VALUE
318
- ext_enc_set_outport(VALUE enc, VALUE outport)
349
+ enc_set_outport(VALUE enc, VALUE outport)
319
350
  {
320
- struct encoder *p = aux_encoder_ref(enc);
321
- p->outport = outport;
322
- return outport;
351
+ return getencoder(enc)->outport = outport;
323
352
  }
324
353
 
325
354
  void
326
- init_encoder(void)
355
+ extlzham_init_encoder(void)
327
356
  {
357
+ RDOCFAKE(mLZHAM = rb_define_module("LZHAM"));
328
358
  cEncoder = rb_define_class_under(mLZHAM, "Encoder", rb_cObject);
329
359
  rb_include_module(cEncoder, mConsts);
330
- rb_define_alloc_func(cEncoder, ext_enc_alloc);
331
- rb_define_singleton_method(cEncoder, "encode", RUBY_METHOD_FUNC(ext_s_encode), -1);
332
- rb_define_method(cEncoder, "initialize", RUBY_METHOD_FUNC(ext_enc_init), -1);
333
- rb_define_method(cEncoder, "update", RUBY_METHOD_FUNC(ext_enc_update), -1);
334
- rb_define_method(cEncoder, "finish", RUBY_METHOD_FUNC(ext_enc_finish), 0);
335
- rb_define_method(cEncoder, "<<", RUBY_METHOD_FUNC(ext_enc_op_lshift), 1);
336
- rb_define_method(cEncoder, "outport", RUBY_METHOD_FUNC(ext_enc_get_outport), 0);
337
- rb_define_method(cEncoder, "outport=", RUBY_METHOD_FUNC(ext_enc_set_outport), 1);
360
+ rb_define_alloc_func(cEncoder, enc_alloc);
361
+ rb_define_singleton_method(cEncoder, "encode", RUBY_METHOD_FUNC(enc_s_encode), -1);
362
+ rb_define_method(cEncoder, "initialize", RUBY_METHOD_FUNC(enc_init), -1);
363
+ rb_define_method(cEncoder, "update", RUBY_METHOD_FUNC(enc_update), -1);
364
+ rb_define_method(cEncoder, "write", RUBY_METHOD_FUNC(enc_write), 1);
365
+ rb_define_method(cEncoder, "flush", RUBY_METHOD_FUNC(enc_flush), -1);
366
+ rb_define_method(cEncoder, "finish", RUBY_METHOD_FUNC(enc_finish), 0);
367
+ rb_define_method(cEncoder, "outport", RUBY_METHOD_FUNC(enc_get_outport), 0);
368
+ rb_define_method(cEncoder, "outport=", RUBY_METHOD_FUNC(enc_set_outport), 1);
369
+ rb_define_alias(cEncoder, "<<", "write");
370
+ rb_define_alias(cEncoder, "encode", "update");
371
+ rb_define_alias(cEncoder, "compress", "update");
338
372
  }
data/ext/error.c CHANGED
@@ -8,7 +8,7 @@ VALUE eError;
8
8
  break \
9
9
 
10
10
  const char *
11
- aux_encode_status_str(lzham_compress_status_t status)
11
+ extlzham_encode_status_str(lzham_compress_status_t status)
12
12
  {
13
13
  const char *mesg;
14
14
  switch (status) {
@@ -29,15 +29,15 @@ aux_encode_status_str(lzham_compress_status_t status)
29
29
  }
30
30
 
31
31
  void
32
- aux_encode_error(lzham_compress_status_t status)
32
+ extlzham_encode_error(lzham_compress_status_t status)
33
33
  {
34
34
  rb_raise(eError,
35
35
  "LZHAM encode error - %s (0x%04X)",
36
- aux_encode_status_str(status), status);
36
+ extlzham_encode_status_str(status), status);
37
37
  }
38
38
 
39
39
  const char *
40
- aux_decode_status_str(lzham_decompress_status_t status)
40
+ extlzham_decode_status_str(lzham_decompress_status_t status)
41
41
  {
42
42
  const char *mesg;
43
43
  switch (status) {
@@ -66,15 +66,15 @@ aux_decode_status_str(lzham_decompress_status_t status)
66
66
  }
67
67
 
68
68
  void
69
- aux_decode_error(lzham_decompress_status_t status)
69
+ extlzham_decode_error(lzham_decompress_status_t status)
70
70
  {
71
71
  rb_raise(eError,
72
72
  "LZHAM decode error - %s (0x%04X)",
73
- aux_decode_status_str(status), status);
73
+ extlzham_decode_status_str(status), status);
74
74
  }
75
75
 
76
76
  void
77
- init_error(void)
77
+ extlzham_init_error(void)
78
78
  {
79
79
  eError = rb_define_class_under(mLZHAM, "Error", rb_eRuntimeError);
80
80
  }
data/ext/extconf.rb CHANGED
@@ -21,6 +21,7 @@ find_header "lzham_decomp.h", "$(srcdir)/../contrib/lzham/lzhamdecomp" or abort
21
21
 
22
22
  if RbConfig::CONFIG["arch"] =~ /mingw/
23
23
  $CPPFLAGS << " -D__forceinline=__attribute__\\(\\(always_inline\\)\\)"
24
+ $LDFLAGS << " -static-libgcc -static-libstdc++"
24
25
  end
25
26
 
26
27
  try_link "void main(void){}", " -Wl,-Bsymbolic " and $LDFLAGS << " -Wl,-Bsymbolic "
data/ext/extlzham.c CHANGED
@@ -2,33 +2,33 @@
2
2
 
3
3
  VALUE mLZHAM;
4
4
 
5
- ID ID_op_lshift;
6
- ID IDdictsize;
7
- ID IDlevel;
8
- ID IDtable_update_rate;
9
- ID IDthreads;
10
- ID IDflags;
11
- ID IDtable_max_update_interval;
12
- ID IDtable_update_interval_slow_rate;
5
+ ID id_op_lshift;
6
+ ID id_dictsize;
7
+ ID id_level;
8
+ ID id_table_update_rate;
9
+ ID id_threads;
10
+ ID id_flags;
11
+ ID id_table_max_update_interval;
12
+ ID id_table_update_interval_slow_rate;
13
13
 
14
14
  void
15
15
  Init_extlzham(void)
16
16
  {
17
- ID_op_lshift = rb_intern("<<");
18
- IDdictsize = rb_intern("dictsize");
19
- IDlevel = rb_intern("level");
20
- IDtable_update_rate = rb_intern("table_update_rate");
21
- IDthreads = rb_intern("threads");
22
- IDflags = rb_intern("flags");
23
- IDtable_max_update_interval = rb_intern("table_max_update_interval");
24
- IDtable_update_interval_slow_rate = rb_intern("table_update_interval_slow_rate");
17
+ id_op_lshift = rb_intern("<<");
18
+ id_dictsize = rb_intern("dictsize");
19
+ id_level = rb_intern("level");
20
+ id_table_update_rate = rb_intern("table_update_rate");
21
+ id_threads = rb_intern("threads");
22
+ id_flags = rb_intern("flags");
23
+ id_table_max_update_interval = rb_intern("table_max_update_interval");
24
+ id_table_update_interval_slow_rate = rb_intern("table_update_interval_slow_rate");
25
25
 
26
26
  mLZHAM = rb_define_module("LZHAM");
27
27
  rb_define_const(mLZHAM, "LZHAM", mLZHAM);
28
28
  rb_define_const(mLZHAM, "LIBVERSION", UINT2NUM(lzham_get_version()));
29
29
 
30
- init_error();
31
- init_constants();
32
- init_encoder();
33
- init_decoder();
30
+ extlzham_init_error();
31
+ extlzham_init_constants();
32
+ extlzham_init_encoder();
33
+ extlzham_init_decoder();
34
34
  }
data/ext/extlzham.h CHANGED
@@ -6,20 +6,22 @@
6
6
  #include <ruby/thread.h>
7
7
  #include <lzham.h>
8
8
 
9
+ #define RDOCFAKE(STMT)
10
+
9
11
  extern VALUE mLZHAM;
10
12
  extern VALUE eError;
11
13
  extern VALUE cEncoder;
12
14
  extern VALUE cDecoder;
13
15
  extern VALUE mConsts;
14
16
 
15
- extern ID ID_op_lshift;
16
- extern ID IDdictsize;
17
- extern ID IDlevel;
18
- extern ID IDtable_update_rate;
19
- extern ID IDthreads;
20
- extern ID IDflags;
21
- extern ID IDtable_max_update_interval;
22
- extern ID IDtable_update_interval_slow_rate;
17
+ extern ID id_op_lshift;
18
+ extern ID id_dictsize;
19
+ extern ID id_level;
20
+ extern ID id_table_update_rate;
21
+ extern ID id_threads;
22
+ extern ID id_flags;
23
+ extern ID id_table_max_update_interval;
24
+ extern ID id_table_update_interval_slow_rate;
23
25
 
24
26
  enum {
25
27
  //WORKBUF_SIZE = 256 * 1024, /* 256 KiB */
@@ -27,18 +29,18 @@ enum {
27
29
  //WORKBUF_SIZE = 1 << 16, /* 64 KiB */
28
30
  };
29
31
 
30
- const char *aux_encode_status_str(lzham_compress_status_t status);
31
- const char *aux_decode_status_str(lzham_decompress_status_t status);
32
- void aux_encode_error(lzham_compress_status_t status);
33
- void aux_decode_error(lzham_decompress_status_t status);
32
+ const char *extlzham_encode_status_str(lzham_compress_status_t status);
33
+ const char *extlzham_decode_status_str(lzham_decompress_status_t status);
34
+ void extlzham_encode_error(lzham_compress_status_t status);
35
+ void extlzham_decode_error(lzham_decompress_status_t status);
34
36
 
35
- void init_error(void);
36
- void init_constants(void);
37
- void init_encoder(void);
38
- void init_decoder(void);
37
+ void extlzham_init_error(void);
38
+ void extlzham_init_constants(void);
39
+ void extlzham_init_encoder(void);
40
+ void extlzham_init_decoder(void);
39
41
 
40
42
  static inline uint32_t
41
- aux_hash_lookup_to_u32(VALUE hash, ID key, uint32_t defaultvalue)
43
+ aux_getoptu32(VALUE hash, ID key, uint32_t defaultvalue)
42
44
  {
43
45
  VALUE d = rb_hash_lookup2(hash, ID2SYM(key), Qundef);
44
46
  if (d == Qundef) { return defaultvalue; }
@@ -48,9 +50,12 @@ aux_hash_lookup_to_u32(VALUE hash, ID key, uint32_t defaultvalue)
48
50
  static inline VALUE
49
51
  aux_str_reserve(VALUE str, size_t size)
50
52
  {
51
- rb_str_modify(str);
52
- rb_str_set_len(str, 0);
53
- rb_str_modify_expand(str, size);
53
+ if (size > rb_str_capacity(str)) {
54
+ rb_str_modify_expand(str, size - RSTRING_LEN(str));
55
+ } else {
56
+ rb_str_modify(str);
57
+ }
58
+
54
59
  return str;
55
60
  }
56
61
 
data/gemstub.rb CHANGED
@@ -5,14 +5,14 @@ require_relative "lib/extlzham/version"
5
5
  GEMSTUB = Gem::Specification.new do |s|
6
6
  s.name = "extlzham"
7
7
  s.version = LZHAM::VERSION
8
- s.summary = "ruby binding for lzham"
8
+ s.summary = "ruby bindings for lzham"
9
9
  s.description = <<EOS
10
- ruby binding for lzham <https://github.com/richgel999/lzham_codec>.
10
+ ruby bindings for lzham <https://github.com/richgel999/lzham_codec>.
11
11
  EOS
12
- s.homepage = "http://sourceforge.jp/projects/rutsubo/"
12
+ s.homepage = "https://osdn.jp/projects/rutsubo/"
13
13
  s.license = "2-clause BSD License"
14
14
  s.author = "dearblue"
15
- s.email = "dearblue@users.sourceforge.jp"
15
+ s.email = "dearblue@users.osdn.me"
16
16
 
17
17
  s.required_ruby_version = ">= 2.0"
18
18
  s.add_development_dependency "rspec", "~> 2.14"
data/lib/extlzham.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  #vim: set fileencoding:utf-8
2
2
 
3
- require "stringio"
4
-
5
3
  ver = RbConfig::CONFIG["ruby_version"].slice(/\d+\.\d+/)
6
4
  soname = File.basename(__FILE__, ".rb") << ".so"
7
5
  lib = File.join(File.dirname(__FILE__), ver, soname)
@@ -11,6 +9,7 @@ else
11
9
  require_relative soname
12
10
  end
13
11
 
12
+ require "stringio"
14
13
  require_relative "extlzham/version"
15
14
 
16
15
  module LZHAM
@@ -1,5 +1,5 @@
1
1
  require "rubygems"
2
2
 
3
3
  module LZHAM
4
- VERSION = Gem::Version.new("0.0.1.PROTOTYPE2")
4
+ VERSION = Gem::Version.new("0.0.1.PROTOTYPE3")
5
5
  end
@@ -0,0 +1,35 @@
1
+ #!ruby
2
+
3
+ require "test-unit"
4
+ require "openssl"
5
+ require "extlzham"
6
+
7
+ SMALLSIZE = 4000
8
+ BIGSIZE = 12000000
9
+
10
+ SAMPLES = [
11
+ "",
12
+ "\0" * SMALLSIZE,
13
+ "\0" * BIGSIZE,
14
+ "\xaa".b * SMALLSIZE,
15
+ "\xaa".b * BIGSIZE,
16
+ OpenSSL::Random.random_bytes(SMALLSIZE),
17
+ OpenSSL::Random.random_bytes(BIGSIZE),
18
+ ]
19
+
20
+ SAMPLES << File.read("/usr/ports/INDEX-10", mode: "rb") rescue nil # if on FreeBSD
21
+ SAMPLES << File.read("/boot/kernel/kernel", mode: "rb") rescue nil # if on FreeBSD
22
+
23
+ class TestExtlzham < Test::Unit::TestCase
24
+ SAMPLES.size.times do |i|
25
+ class_eval <<-EOS, __FILE__, __LINE__ + 1
26
+ def test_encode1_decode_#{i}
27
+ assert { LZHAM.decode(LZHAM.encode(SAMPLES[#{i}])) == SAMPLES[#{i}] }
28
+ end
29
+
30
+ def test_encode2_decode_#{i}
31
+ assert { LZHAM.decode(LZHAM::Encoder.encode(SAMPLES[#{i}])) == SAMPLES[#{i}] }
32
+ end
33
+ EOS
34
+ end
35
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: extlzham
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.PROTOTYPE2
4
+ version: 0.0.1.PROTOTYPE3
5
5
  platform: ruby
6
6
  authors:
7
7
  - dearblue
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-26 00:00:00.000000000 Z
11
+ date: 2015-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -39,14 +39,16 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  description: |
42
- ruby binding for lzham <https://github.com/richgel999/lzham_codec>.
43
- email: dearblue@users.sourceforge.jp
42
+ ruby bindings for lzham <https://github.com/richgel999/lzham_codec>.
43
+ email: dearblue@users.osdn.me
44
44
  executables: []
45
45
  extensions:
46
46
  - ext/extconf.rb
47
47
  extra_rdoc_files:
48
48
  - LICENSE.md
49
49
  - README.md
50
+ - contrib/lzham/LICENSE
51
+ - contrib/lzham/README.md
50
52
  - ext/constants.c
51
53
  - ext/decoder.c
52
54
  - ext/encoder.c
@@ -119,12 +121,17 @@ files:
119
121
  - gemstub.rb
120
122
  - lib/extlzham.rb
121
123
  - lib/extlzham/version.rb
122
- homepage: http://sourceforge.jp/projects/rutsubo/
124
+ - test/test_extlzham.rb
125
+ homepage: https://osdn.jp/projects/rutsubo/
123
126
  licenses:
124
127
  - 2-clause BSD License
125
128
  metadata: {}
126
129
  post_install_message:
127
- rdoc_options: []
130
+ rdoc_options:
131
+ - "--charset"
132
+ - UTF-8
133
+ - "-m"
134
+ - README.md
128
135
  require_paths:
129
136
  - lib
130
137
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -139,8 +146,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
146
  version: 1.3.1
140
147
  requirements: []
141
148
  rubyforge_project:
142
- rubygems_version: 2.4.6
149
+ rubygems_version: 2.4.8
143
150
  signing_key:
144
151
  specification_version: 4
145
- summary: ruby binding for lzham
152
+ summary: ruby bindings for lzham
146
153
  test_files: []