brianmario-bzip2-ruby 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,21 @@
1
+ == 0.2.5 ???
2
+
3
+ * initial conversion of original tests over to rspec
4
+
5
+ == 0.2.4 2009-05-02
6
+
7
+ * renamed BZ2 module/namespace to Bzip2
8
+
9
+ == 0.2.3 2009-05-02
10
+
11
+ * renamed gem to bzip2-ruby from bz2
12
+ * initial conversion to jeweler
13
+ * bundling gemspec
14
+ * README and file structure organization updates
15
+ * updated Init_*() ruby initializer function to match new gem name
16
+
17
+ == 0.2.2 2008-12-22
18
+
19
+ * 1 major enhancement:
20
+ * Gemify bz2 library from http://moulon.inra.fr/ruby/bz2.html
21
+ * All credit goes to Guy Decoux <ts@moulon.inra.fr>
@@ -8,13 +8,9 @@ You may need to specify:
8
8
 
9
9
  --with-bz2-dir=<include file directory for libbzip2>
10
10
 
11
- == Documentation:
11
+ == TODO
12
12
 
13
- coming soon...
14
-
15
- == Spec Tests:
16
-
17
- coming soon...
13
+ * 1.9 compatibility - I could use some help with this as I think it's gonna require some Makefile trickery
18
14
 
19
15
  == Copying
20
16
 
@@ -28,3 +24,4 @@ You may need to specify:
28
24
  * Renamed BZ2 module/namespace to Bzip2
29
25
  * Renamed compiled binary from "bz2" to "bzip2"
30
26
  * Renamed gem from "bz2" to "bzip2-ruby"
27
+ * Converted original tests to rspec
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ begin
7
7
  gem.email = "seniorlopez@gmail.com"
8
8
  gem.homepage = "http://github.com/brianmario/bzip2-ruby"
9
9
  gem.authors = ["Guy Decoux", "Brian Lopez"]
10
- gem.require_paths = ["ext"]
10
+ gem.require_paths = ["lib", "ext"]
11
11
  gem.extra_rdoc_files = `git ls-files *.rdoc`.split("\n")
12
12
  gem.files = `git ls-files`.split("\n")
13
13
  gem.extensions = ["ext/extconf.rb"]
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 4
3
2
  :major: 0
4
3
  :minor: 2
4
+ :patch: 5
@@ -2,40 +2,41 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{bzip2-ruby}
5
- s.version = "0.2.4"
5
+ s.version = "0.2.5"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Guy Decoux", "Brian Lopez"]
9
- s.date = %q{2009-05-02}
9
+ s.date = %q{2009-05-18}
10
10
  s.email = %q{seniorlopez@gmail.com}
11
11
  s.extensions = ["ext/extconf.rb"]
12
12
  s.extra_rdoc_files = [
13
- "README.rdoc"
13
+ "CHANGELOG.rdoc",
14
+ "README.rdoc"
14
15
  ]
15
16
  s.files = [
16
- "History.txt",
17
- "README.rdoc",
18
- "Rakefile",
19
- "VERSION.yml",
20
- "bzip2-ruby.gemspec",
21
- "ext/bz2.c",
22
- "ext/extconf.rb",
23
- "tasks/extconf.rake",
24
- "tasks/extconf/bz2.rake",
25
- "test/reader.rb",
26
- "test/runit_.rb",
27
- "test/writer.rb"
17
+ "CHANGELOG.rdoc",
18
+ "README.rdoc",
19
+ "Rakefile",
20
+ "VERSION.yml",
21
+ "bzip2-ruby.gemspec",
22
+ "ext/bzip2.c",
23
+ "ext/extconf.rb",
24
+ "lib/bzip2.rb",
25
+ "spec/reader_spec.rb",
26
+ "spec/spec_helper.rb",
27
+ "spec/writer_spec.rb",
28
+ "tasks/extconf.rake",
29
+ "tasks/extconf/bz2.rake"
28
30
  ]
29
- s.has_rdoc = true
30
31
  s.homepage = %q{http://github.com/brianmario/bzip2-ruby}
31
32
  s.rdoc_options = ["--charset=UTF-8"]
32
- s.require_paths = ["ext"]
33
- s.rubygems_version = %q{1.3.2}
33
+ s.require_paths = ["lib", "ext"]
34
+ s.rubygems_version = %q{1.3.3}
34
35
  s.summary = %q{Ruby C bindings to libbzip2.}
35
36
  s.test_files = [
36
- "test/reader.rb",
37
- "test/runit_.rb",
38
- "test/writer.rb"
37
+ "spec/reader_spec.rb",
38
+ "spec/spec_helper.rb",
39
+ "spec/writer_spec.rb"
39
40
  ]
40
41
 
41
42
  if s.respond_to? :specification_version then
@@ -1,7 +1,11 @@
1
1
  #include <ruby.h>
2
- #include <rubyio.h>
3
2
  #include <bzlib.h>
3
+ #ifndef RUBY_19_COMPATIBILITY
4
+ #include <rubyio.h>
4
5
  #include <version.h>
6
+ #else
7
+ #include <ruby/io.h>
8
+ #endif
5
9
 
6
10
  static VALUE bz_cWriter, bz_cReader, bz_cInternal;
7
11
  static VALUE bz_eError, bz_eConfigError, bz_eEOZError;
@@ -109,18 +113,20 @@ bz_find_struct(obj, ptr, posp)
109
113
  struct bz_iv *bziv;
110
114
  int i;
111
115
 
112
- for (i = 0; i < RARRAY(bz_internal_ary)->len; i++) {
113
- Data_Get_Struct(RARRAY(bz_internal_ary)->ptr[i], struct bz_iv, bziv);
116
+ for (i = 0; i < RARRAY_LEN(bz_internal_ary); i++) {
117
+ Data_Get_Struct(RARRAY_PTR(bz_internal_ary)[i], struct bz_iv, bziv);
114
118
  if (ptr) {
115
- if (TYPE(bziv->io) == T_FILE &&
116
- RFILE(bziv->io)->fptr == (OpenFile *)ptr) {
117
- if (posp) *posp = i;
118
- return bziv;
119
+ #ifndef RUBY_19_COMPATIBILITY
120
+ if (TYPE(bziv->io) == T_FILE && RFILE(bziv->io)->fptr == (OpenFile *)ptr) {
121
+ #else
122
+ if (TYPE(bziv->io) == T_FILE && RFILE(bziv->io)->fptr == (rb_io_t *)ptr) {
123
+ #endif
124
+ if (posp) *posp = i;
125
+ return bziv;
119
126
  }
120
- else if (TYPE(bziv->io) == T_DATA &&
121
- DATA_PTR(bziv->io) == ptr) {
122
- if (posp) *posp = i;
123
- return bziv;
127
+ else if (TYPE(bziv->io) == T_DATA && DATA_PTR(bziv->io) == ptr) {
128
+ if (posp) *posp = i;
129
+ return bziv;
124
130
  }
125
131
  }
126
132
  else if (bziv->io == obj) {
@@ -215,8 +221,8 @@ bz_internal_finalize(ary, obj)
215
221
  struct bz_iv *bziv;
216
222
  struct bz_file *bzf;
217
223
 
218
- for (i = 0; i < RARRAY(bz_internal_ary)->len; i++) {
219
- elem = RARRAY(bz_internal_ary)->ptr[i];
224
+ for (i = 0; i < RARRAY_LEN(bz_internal_ary); i++) {
225
+ elem = RARRAY_PTR(bz_internal_ary)[i];
220
226
  Data_Get_Struct(elem, struct bz_iv, bziv);
221
227
  if (bziv->bz2) {
222
228
  RDATA(bziv->bz2)->dfree = ruby_xfree;
@@ -293,24 +299,35 @@ bz_io_data_finalize(ptr)
293
299
 
294
300
  bziv = bz_find_struct(0, ptr, &pos);
295
301
  if (bziv) {
296
- rb_ary_delete_at(bz_internal_ary, pos);
297
- Data_Get_Struct(bziv->bz2, struct bz_file, bzf);
298
- rb_protect(bz_writer_internal_flush, (VALUE)bzf, 0);
299
- RDATA(bziv->bz2)->dfree = ruby_xfree;
300
- if (bziv->finalize) {
301
- (*bziv->finalize)(ptr);
302
- }
303
- else if (TYPE(bzf->io) == T_FILE) {
304
- OpenFile *file = (OpenFile *)ptr;
305
- if (file->f) {
306
- fclose(file->f);
307
- file->f = 0;
308
- }
309
- if (file->f2) {
310
- fclose(file->f2);
311
- file->f2 = 0;
312
- }
313
- }
302
+ rb_ary_delete_at(bz_internal_ary, pos);
303
+ Data_Get_Struct(bziv->bz2, struct bz_file, bzf);
304
+ rb_protect(bz_writer_internal_flush, (VALUE)bzf, 0);
305
+ RDATA(bziv->bz2)->dfree = ruby_xfree;
306
+ if (bziv->finalize) {
307
+ (*bziv->finalize)(ptr);
308
+ } else if (TYPE(bzf->io) == T_FILE) {
309
+ #ifndef RUBY_19_COMPATIBILITY
310
+ OpenFile *file = (OpenFile *)ptr;
311
+ if (file->f) {
312
+ fclose(file->f);
313
+ file->f = 0;
314
+ }
315
+ if (file->f2) {
316
+ fclose(file->f2);
317
+ file->f2 = 0;
318
+ }
319
+ #else
320
+ rb_io_t *file = (rb_io_t *)ptr;
321
+ if (file->fd) {
322
+ fclose(file->fd);
323
+ file->fd = 0;
324
+ }
325
+ if (file->stdio_file) {
326
+ fclose(file->stdio_file);
327
+ file->stdio_file = 0;
328
+ }
329
+ #endif
330
+ }
314
331
  }
315
332
  }
316
333
 
@@ -396,8 +413,8 @@ bz_str_write(obj, str)
396
413
  if (TYPE(str) != T_STRING) {
397
414
  rb_raise(rb_eArgError, "expected a String");
398
415
  }
399
- if (RSTRING(str)->len) {
400
- rb_str_cat(obj, RSTRING(str)->ptr, RSTRING(str)->len);
416
+ if (RSTRING_LEN(str)) {
417
+ rb_str_cat(obj, RSTRING_PTR(str), RSTRING_LEN(str));
401
418
  }
402
419
  return str;
403
420
  }
@@ -436,7 +453,11 @@ bz_writer_init(argc, argv, obj)
436
453
  else {
437
454
  VALUE iv;
438
455
  struct bz_iv *bziv;
439
- OpenFile *fptr;
456
+ #ifndef RUBY_19_COMPATIBILITY
457
+ OpenFile *fptr;
458
+ #else
459
+ rb_io_t *fptr;
460
+ #endif
440
461
 
441
462
  rb_io_taint_check(a);
442
463
  if (!rb_respond_to(a, id_write)) {
@@ -507,8 +528,8 @@ bz_writer_write(obj, a)
507
528
  bzf->buflen = BZ_RB_BLOCKSIZE;
508
529
  bzf->buf[0] = bzf->buf[bzf->buflen] = '\0';
509
530
  }
510
- bzf->bzs.next_in = RSTRING(a)->ptr;
511
- bzf->bzs.avail_in = RSTRING(a)->len;
531
+ bzf->bzs.next_in = RSTRING_PTR(a);
532
+ bzf->bzs.avail_in = RSTRING_LEN(a);
512
533
  while (bzf->bzs.avail_in) {
513
534
  bzf->bzs.next_out = bzf->buf;
514
535
  bzf->bzs.avail_out = bzf->buflen;
@@ -523,7 +544,7 @@ bz_writer_write(obj, a)
523
544
  rb_funcall(bzf->io, id_write, 1, rb_str_new(bzf->buf, n));
524
545
  }
525
546
  }
526
- return INT2NUM(RSTRING(a)->len);
547
+ return INT2NUM(RSTRING_LEN(a));
527
548
  }
528
549
 
529
550
  static VALUE
@@ -614,7 +635,11 @@ bz_reader_init(argc, argv, obj)
614
635
  }
615
636
  if (rb_respond_to(a, id_read)) {
616
637
  if (TYPE(a) == T_FILE) {
617
- OpenFile *fptr;
638
+ #ifndef RUBY_19_COMPATIBILITY
639
+ OpenFile *fptr;
640
+ #else
641
+ rb_io_t *fptr;
642
+ #endif
618
643
 
619
644
  GetOpenFile(a, fptr);
620
645
  rb_io_check_readable(fptr);
@@ -691,14 +716,14 @@ bz_next_available(bzf, in)
691
716
  }
692
717
  if (!bzf->bzs.avail_in) {
693
718
  bzf->in = rb_funcall(bzf->io, id_read, 1, INT2FIX(1024));
694
- if (TYPE(bzf->in) != T_STRING || RSTRING(bzf->in)->len == 0) {
719
+ if (TYPE(bzf->in) != T_STRING || RSTRING_LEN(bzf->in) == 0) {
695
720
  BZ2_bzDecompressEnd(&(bzf->bzs));
696
721
  bzf->bzs.avail_out = 0;
697
722
  bzf->state = BZ_UNEXPECTED_EOF;
698
723
  bz_raise(bzf->state);
699
724
  }
700
- bzf->bzs.next_in = RSTRING(bzf->in)->ptr;
701
- bzf->bzs.avail_in = RSTRING(bzf->in)->len;
725
+ bzf->bzs.next_in = RSTRING_PTR(bzf->in);
726
+ bzf->bzs.avail_in = RSTRING_LEN(bzf->in);
702
727
  }
703
728
  if ((bzf->buflen - in) < (BZ_RB_BLOCKSIZE / 2)) {
704
729
  bzf->buf = REALLOC_N(bzf->buf, char, bzf->buflen+BZ_RB_BLOCKSIZE+1);
@@ -780,7 +805,7 @@ bz_read_until(bzf, str, len, td1)
780
805
  if (nex) {
781
806
  res = rb_str_cat(res, bzf->buf, nex);
782
807
  }
783
- if (RSTRING(res)->len) {
808
+ if (RSTRING_LEN(res)) {
784
809
  return res;
785
810
  }
786
811
  return Qnil;
@@ -845,8 +870,8 @@ bz_reader_read(argc, argv, obj)
845
870
  }
846
871
  while (1) {
847
872
  total = bzf->bzs.avail_out;
848
- if (n != -1 && (RSTRING(res)->len + total) >= n) {
849
- n -= RSTRING(res)->len;
873
+ if (n != -1 && (RSTRING_LEN(res) + total) >= n) {
874
+ n -= RSTRING_LEN(res);
850
875
  res = rb_str_cat(res, bzf->bzs.next_out, n);
851
876
  bzf->bzs.next_out += n;
852
877
  bzf->bzs.avail_out -= n;
@@ -868,10 +893,10 @@ bz_getc(obj)
868
893
  {
869
894
  VALUE length = INT2FIX(1);
870
895
  VALUE res = bz_reader_read(1, &length, obj);
871
- if (NIL_P(res) || RSTRING(res)->len == 0) {
896
+ if (NIL_P(res) || RSTRING_LEN(res) == 0) {
872
897
  return EOF;
873
898
  }
874
- return RSTRING(res)->ptr[0];
899
+ return RSTRING_PTR(res)[0];
875
900
  }
876
901
 
877
902
  static VALUE
@@ -911,15 +936,15 @@ bz_reader_ungets(obj, a)
911
936
  if (!bzf->buf) {
912
937
  bz_raise(BZ_SEQUENCE_ERROR);
913
938
  }
914
- if ((bzf->bzs.avail_out + RSTRING(a)->len) < bzf->buflen) {
915
- bzf->bzs.next_out -= RSTRING(a)->len;
916
- MEMCPY(bzf->bzs.next_out, RSTRING(a)->ptr, char, RSTRING(a)->len);
917
- bzf->bzs.avail_out += RSTRING(a)->len;
939
+ if ((bzf->bzs.avail_out + RSTRING_LEN(a)) < bzf->buflen) {
940
+ bzf->bzs.next_out -= RSTRING_LEN(a);
941
+ MEMCPY(bzf->bzs.next_out, RSTRING_PTR(a), char, RSTRING_LEN(a));
942
+ bzf->bzs.avail_out += RSTRING_LEN(a);
918
943
  }
919
944
  else {
920
- bzf->buf = REALLOC_N(bzf->buf, char, bzf->buflen + RSTRING(a)->len + 1);
921
- MEMCPY(bzf->buf + bzf->buflen, RSTRING(a)->ptr, char,RSTRING(a)->len);
922
- bzf->buflen += RSTRING(a)->len;
945
+ bzf->buf = REALLOC_N(bzf->buf, char, bzf->buflen + RSTRING_LEN(a) + 1);
946
+ MEMCPY(bzf->buf + bzf->buflen, RSTRING_PTR(a), char,RSTRING_LEN(a));
947
+ bzf->buflen += RSTRING_LEN(a);
923
948
  bzf->buf[bzf->buflen] = '\0';
924
949
  bzf->bzs.next_out = bzf->buf;
925
950
  bzf->bzs.avail_out = bzf->buflen;
@@ -966,8 +991,8 @@ bz_reader_gets_internal(argc, argv, obj, td, init)
966
991
  if (NIL_P(rs)) {
967
992
  return bz_reader_read(1, &rs, obj);
968
993
  }
969
- rslen = RSTRING(rs)->len;
970
- if (rs == rb_default_rs || (rslen == 1 && RSTRING(rs)->ptr[0] == '\n')) {
994
+ rslen = RSTRING_LEN(rs);
995
+ if (rs == rb_default_rs || (rslen == 1 && RSTRING_PTR(rs)[0] == '\n')) {
971
996
  return bz_reader_gets(obj);
972
997
  }
973
998
 
@@ -977,7 +1002,7 @@ bz_reader_gets_internal(argc, argv, obj, td, init)
977
1002
  rspara = 1;
978
1003
  }
979
1004
  else {
980
- rsptr = RSTRING(rs)->ptr;
1005
+ rsptr = RSTRING_PTR(rs);
981
1006
  rspara = 0;
982
1007
  }
983
1008
 
@@ -1024,13 +1049,13 @@ bz_reader_set_unused(obj, a)
1024
1049
  Check_Type(a, T_STRING);
1025
1050
  Get_BZ2(obj, bzf);
1026
1051
  if (!bzf->in) {
1027
- bzf->in = rb_str_new(RSTRING(a)->ptr, RSTRING(a)->len);
1052
+ bzf->in = rb_str_new(RSTRING_PTR(a), RSTRING_LEN(a));
1028
1053
  }
1029
1054
  else {
1030
- bzf->in = rb_str_cat(bzf->in, RSTRING(a)->ptr, RSTRING(a)->len);
1055
+ bzf->in = rb_str_cat(bzf->in, RSTRING_PTR(a), RSTRING_LEN(a));
1031
1056
  }
1032
- bzf->bzs.next_in = RSTRING(bzf->in)->ptr;
1033
- bzf->bzs.avail_in = RSTRING(bzf->in)->len;
1057
+ bzf->bzs.next_in = RSTRING_PTR(bzf->in);
1058
+ bzf->bzs.avail_in = RSTRING_LEN(bzf->in);
1034
1059
  return Qnil;
1035
1060
  }
1036
1061
 
@@ -1042,10 +1067,10 @@ bz_reader_getc(obj)
1042
1067
  VALUE len = INT2FIX(1);
1043
1068
 
1044
1069
  str = bz_reader_read(1, &len, obj);
1045
- if (NIL_P(str) || RSTRING(str)->len == 0) {
1070
+ if (NIL_P(str) || RSTRING_LEN(str) == 0) {
1046
1071
  return Qnil;
1047
1072
  }
1048
- return INT2FIX(RSTRING(str)->ptr[0] & 0xff);
1073
+ return INT2FIX(RSTRING_PTR(str)[0] & 0xff);
1049
1074
  }
1050
1075
 
1051
1076
  static void
@@ -1411,7 +1436,7 @@ bz_str_read(argc, argv, obj)
1411
1436
  Data_Get_Struct(obj, struct bz_str, bzs);
1412
1437
  rb_scan_args(argc, argv, "01", &len);
1413
1438
  if (NIL_P(len)) {
1414
- count = RSTRING(bzs->str)->len;
1439
+ count = RSTRING_LEN(bzs->str);
1415
1440
  }
1416
1441
  else {
1417
1442
  count = NUM2INT(len);
@@ -1422,13 +1447,13 @@ bz_str_read(argc, argv, obj)
1422
1447
  if (!count || bzs->pos == -1) {
1423
1448
  return Qnil;
1424
1449
  }
1425
- if ((bzs->pos + count) >= RSTRING(bzs->str)->len) {
1426
- res = rb_str_new(RSTRING(bzs->str)->ptr + bzs->pos,
1427
- RSTRING(bzs->str)->len - bzs->pos);
1450
+ if ((bzs->pos + count) >= RSTRING_LEN(bzs->str)) {
1451
+ res = rb_str_new(RSTRING_PTR(bzs->str) + bzs->pos,
1452
+ RSTRING_LEN(bzs->str) - bzs->pos);
1428
1453
  bzs->pos = -1;
1429
1454
  }
1430
1455
  else {
1431
- res = rb_str_new(RSTRING(bzs->str)->ptr + bzs->pos, count);
1456
+ res = rb_str_new(RSTRING_PTR(bzs->str) + bzs->pos, count);
1432
1457
  bzs->pos += count;
1433
1458
  }
1434
1459
  return res;
@@ -1471,12 +1496,12 @@ bz_proc_new(func, val)
1471
1496
  rb_intern("to_proc"), 0, 0);
1472
1497
  }
1473
1498
 
1474
- void Init_bzip2()
1499
+ void Init_bzip2_ext()
1475
1500
  {
1476
1501
  VALUE bz_mBzip2;
1477
1502
 
1478
1503
  if (rb_const_defined_at(rb_cObject, rb_intern("Bzip2"))) {
1479
- rb_raise(rb_eNameError, "module already defined");
1504
+ rb_raise(rb_eNameError, "module already defined");
1480
1505
  }
1481
1506
 
1482
1507
  bz_internal_ary = rb_ary_new();
@@ -7,7 +7,12 @@ if have_library("bz2", "BZ2_bzWriteOpen")
7
7
  if enable_config("shared", true)
8
8
  $static = nil
9
9
  end
10
- create_makefile("bzip2")
10
+
11
+ if RUBY_VERSION =~ /1.9/
12
+ $CFLAGS << ' -DRUBY_19_COMPATIBILITY'
13
+ end
14
+
15
+ create_makefile("bzip2_ext")
11
16
  else
12
17
  puts "libbz2 not found, maybe try manually specifying --with-bz2-dir to find it?"
13
18
  end