bzip2-ruby 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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,14 +8,6 @@ You may need to specify:
8
8
 
9
9
  --with-bz2-dir=<include file directory for libbzip2>
10
10
 
11
- == Documentation:
12
-
13
- coming soon...
14
-
15
- == Spec Tests:
16
-
17
- coming soon...
18
-
19
11
  == Copying
20
12
 
21
13
  This extension module is copyrighted free software by Guy Decoux
@@ -28,3 +20,5 @@ You may need to specify:
28
20
  * Renamed BZ2 module/namespace to Bzip2
29
21
  * Renamed compiled binary from "bz2" to "bzip2"
30
22
  * Renamed gem from "bz2" to "bzip2-ruby"
23
+ * Converted original tests to rspec
24
+ * 1.9 compatibility
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;
@@ -33,11 +37,11 @@ struct bz_iv {
33
37
  void (*finalize)();
34
38
  };
35
39
 
36
- #define Get_BZ2(obj, bzf) \
37
- rb_io_taint_check(obj); \
38
- Data_Get_Struct(obj, struct bz_file, bzf); \
39
- if (!RTEST(bzf->io)) { \
40
- rb_raise(rb_eIOError, "closed IO"); \
40
+ #define Get_BZ2(obj, bzf) \
41
+ rb_io_taint_check(obj); \
42
+ Data_Get_Struct(obj, struct bz_file, bzf); \
43
+ if (!RTEST(bzf->io)) { \
44
+ rb_raise(rb_eIOError, "closed IO"); \
41
45
  }
42
46
 
43
47
  static VALUE
@@ -50,37 +54,37 @@ bz_raise(error)
50
54
  exc = bz_eError;
51
55
  switch (error) {
52
56
  case BZ_SEQUENCE_ERROR:
53
- msg = "uncorrect sequence";
54
- break;
57
+ msg = "incorrect sequence";
58
+ break;
55
59
  case BZ_PARAM_ERROR:
56
- msg = "parameter out of range";
57
- break;
60
+ msg = "parameter out of range";
61
+ break;
58
62
  case BZ_MEM_ERROR:
59
- msg = "not enough memory is available";
60
- break;
63
+ msg = "not enough memory is available";
64
+ break;
61
65
  case BZ_DATA_ERROR:
62
- msg = "data integrity error is detected";
63
- break;
66
+ msg = "data integrity error is detected";
67
+ break;
64
68
  case BZ_DATA_ERROR_MAGIC:
65
- msg = "compressed stream does not start with the correct magic bytes";
66
- break;
69
+ msg = "compressed stream does not start with the correct magic bytes";
70
+ break;
67
71
  case BZ_IO_ERROR:
68
- msg = "error reading or writing";
69
- break;
72
+ msg = "error reading or writing";
73
+ break;
70
74
  case BZ_UNEXPECTED_EOF:
71
- exc = bz_eEOZError;
72
- msg = "compressed file finishes before the logical end of stream is detected";
73
- break;
75
+ exc = bz_eEOZError;
76
+ msg = "compressed file finishes before the logical end of stream is detected";
77
+ break;
74
78
  case BZ_OUTBUFF_FULL:
75
- msg = "output buffer full";
76
- break;
79
+ msg = "output buffer full";
80
+ break;
77
81
  case BZ_CONFIG_ERROR:
78
- exc = bz_eConfigError;
79
- msg = "library has been improperly compiled on your platform";
80
- break;
82
+ exc = bz_eConfigError;
83
+ msg = "library has been improperly compiled on your platform";
84
+ break;
81
85
  default:
82
- msg = "unknown error";
83
- exc = bz_eError;
86
+ msg = "unknown error";
87
+ exc = bz_eError;
84
88
  }
85
89
  rb_raise(exc, msg);
86
90
  }
@@ -109,24 +113,26 @@ 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);
114
- 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
- }
120
- else if (TYPE(bziv->io) == T_DATA &&
121
- DATA_PTR(bziv->io) == ptr) {
122
- if (posp) *posp = i;
123
- return bziv;
124
- }
125
- }
126
- else if (bziv->io == obj) {
127
- if (posp) *posp = i;
128
- return bziv;
129
- }
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);
118
+ if (ptr) {
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;
126
+ }
127
+ else if (TYPE(bziv->io) == T_DATA && DATA_PTR(bziv->io) == ptr) {
128
+ if (posp) *posp = i;
129
+ return bziv;
130
+ }
131
+ }
132
+ else if (bziv->io == obj) {
133
+ if (posp) *posp = i;
134
+ return bziv;
135
+ }
130
136
  }
131
137
  if (posp) *posp = -1;
132
138
  return 0;
@@ -139,34 +145,34 @@ bz_writer_internal_flush(bzf)
139
145
  int closed = 1;
140
146
 
141
147
  if (rb_respond_to(bzf->io, id_closed)) {
142
- closed = RTEST(rb_funcall2(bzf->io, id_closed, 0, 0));
148
+ closed = RTEST(rb_funcall2(bzf->io, id_closed, 0, 0));
143
149
  }
144
150
  if (bzf->buf) {
145
- if (!closed && bzf->state == BZ_OK) {
146
- bzf->bzs.next_in = NULL;
147
- bzf->bzs.avail_in = 0;
148
- do {
149
- bzf->bzs.next_out = bzf->buf;
150
- bzf->bzs.avail_out = bzf->buflen;
151
- bzf->state = BZ2_bzCompress(&(bzf->bzs), BZ_FINISH);
152
- if (bzf->state != BZ_FINISH_OK &&
153
- bzf->state != BZ_STREAM_END) {
154
- break;
155
- }
156
- if (bzf->bzs.avail_out < bzf->buflen) {
157
- rb_funcall(bzf->io, id_write, 1,
158
- rb_str_new(bzf->buf,
159
- bzf->buflen - bzf->bzs.avail_out));
160
- }
161
- } while (bzf->state != BZ_STREAM_END);
162
- }
163
- free(bzf->buf);
164
- bzf->buf = 0;
165
- BZ2_bzCompressEnd(&(bzf->bzs));
166
- bzf->state = BZ_OK;
167
- if (!closed && rb_respond_to(bzf->io, id_flush)) {
168
- rb_funcall2(bzf->io, id_flush, 0, 0);
169
- }
151
+ if (!closed && bzf->state == BZ_OK) {
152
+ bzf->bzs.next_in = NULL;
153
+ bzf->bzs.avail_in = 0;
154
+ do {
155
+ bzf->bzs.next_out = bzf->buf;
156
+ bzf->bzs.avail_out = bzf->buflen;
157
+ bzf->state = BZ2_bzCompress(&(bzf->bzs), BZ_FINISH);
158
+ if (bzf->state != BZ_FINISH_OK &&
159
+ bzf->state != BZ_STREAM_END) {
160
+ break;
161
+ }
162
+ if (bzf->bzs.avail_out < bzf->buflen) {
163
+ rb_funcall(bzf->io, id_write, 1,
164
+ rb_str_new(bzf->buf,
165
+ bzf->buflen - bzf->bzs.avail_out));
166
+ }
167
+ } while (bzf->state != BZ_STREAM_END);
168
+ }
169
+ free(bzf->buf);
170
+ bzf->buf = 0;
171
+ BZ2_bzCompressEnd(&(bzf->bzs));
172
+ bzf->state = BZ_OK;
173
+ if (!closed && rb_respond_to(bzf->io, id_flush)) {
174
+ rb_funcall2(bzf->io, id_flush, 0, 0);
175
+ }
170
176
  }
171
177
  return closed;
172
178
  }
@@ -182,25 +188,25 @@ bz_writer_internal_close(bzf)
182
188
  closed = bz_writer_internal_flush(bzf);
183
189
  bziv = bz_find_struct(bzf->io, 0, &pos);
184
190
  if (bziv) {
185
- if (TYPE(bzf->io) == T_FILE) {
186
- RFILE(bzf->io)->fptr->finalize = bziv->finalize;
187
- }
188
- else if (TYPE(bziv->io) == T_DATA) {
189
- RDATA(bziv->io)->dfree = bziv->finalize;
190
- }
191
- RDATA(bziv->bz2)->dfree = ruby_xfree;
192
- bziv->bz2 = 0;
193
- rb_ary_delete_at(bz_internal_ary, pos);
191
+ if (TYPE(bzf->io) == T_FILE) {
192
+ RFILE(bzf->io)->fptr->finalize = bziv->finalize;
193
+ }
194
+ else if (TYPE(bziv->io) == T_DATA) {
195
+ RDATA(bziv->io)->dfree = bziv->finalize;
196
+ }
197
+ RDATA(bziv->bz2)->dfree = ruby_xfree;
198
+ bziv->bz2 = 0;
199
+ rb_ary_delete_at(bz_internal_ary, pos);
194
200
  }
195
201
  if (bzf->flags & BZ2_RB_CLOSE) {
196
- bzf->flags &= ~BZ2_RB_CLOSE;
197
- if (!closed && rb_respond_to(bzf->io, id_close)) {
198
- rb_funcall2(bzf->io, id_close, 0, 0);
199
- }
200
- res = Qnil;
202
+ bzf->flags &= ~BZ2_RB_CLOSE;
203
+ if (!closed && rb_respond_to(bzf->io, id_close)) {
204
+ rb_funcall2(bzf->io, id_close, 0, 0);
205
+ }
206
+ res = Qnil;
201
207
  }
202
208
  else {
203
- res = bzf->io;
209
+ res = bzf->io;
204
210
  }
205
211
  bzf->io = Qnil;
206
212
  return res;
@@ -215,26 +221,26 @@ 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];
220
- Data_Get_Struct(elem, struct bz_iv, bziv);
221
- if (bziv->bz2) {
222
- RDATA(bziv->bz2)->dfree = ruby_xfree;
223
- if (TYPE(bziv->io) == T_FILE) {
224
- RFILE(bziv->io)->fptr->finalize = bziv->finalize;
225
- }
226
- else if (TYPE(bziv->io) == T_DATA) {
227
- RDATA(bziv->io)->dfree = bziv->finalize;
228
- }
229
- Data_Get_Struct(bziv->bz2, struct bz_file, bzf);
230
- closed = bz_writer_internal_flush(bzf);
231
- if (bzf->flags & BZ2_RB_CLOSE) {
232
- bzf->flags &= ~BZ2_RB_CLOSE;
233
- if (!closed && rb_respond_to(bzf->io, id_close)) {
234
- rb_funcall2(bzf->io, id_close, 0, 0);
235
- }
236
- }
237
- }
224
+ for (i = 0; i < RARRAY_LEN(bz_internal_ary); i++) {
225
+ elem = RARRAY_PTR(bz_internal_ary)[i];
226
+ Data_Get_Struct(elem, struct bz_iv, bziv);
227
+ if (bziv->bz2) {
228
+ RDATA(bziv->bz2)->dfree = ruby_xfree;
229
+ if (TYPE(bziv->io) == T_FILE) {
230
+ RFILE(bziv->io)->fptr->finalize = bziv->finalize;
231
+ }
232
+ else if (TYPE(bziv->io) == T_DATA) {
233
+ RDATA(bziv->io)->dfree = bziv->finalize;
234
+ }
235
+ Data_Get_Struct(bziv->bz2, struct bz_file, bzf);
236
+ closed = bz_writer_internal_flush(bzf);
237
+ if (bzf->flags & BZ2_RB_CLOSE) {
238
+ bzf->flags &= ~BZ2_RB_CLOSE;
239
+ if (!closed && rb_respond_to(bzf->io, id_close)) {
240
+ rb_funcall2(bzf->io, id_close, 0, 0);
241
+ }
242
+ }
243
+ }
238
244
  }
239
245
  return Qnil;
240
246
  }
@@ -249,7 +255,7 @@ bz_writer_close(obj)
249
255
  Get_BZ2(obj, bzf);
250
256
  res = bz_writer_internal_close(bzf);
251
257
  if (!NIL_P(res) && (bzf->flags & BZ2_RB_INTERNAL)) {
252
- RBASIC(res)->klass = rb_cString;
258
+ RBASIC(res)->klass = rb_cString;
253
259
  }
254
260
  return res;
255
261
  }
@@ -265,12 +271,12 @@ bz_writer_close_bang(obj)
265
271
  closed = bzf->flags & (BZ2_RB_INTERNAL|BZ2_RB_CLOSE);
266
272
  bz_writer_close(obj);
267
273
  if (!closed && rb_respond_to(bzf->io, id_close)) {
268
- if (rb_respond_to(bzf->io, id_closed)) {
269
- closed = RTEST(rb_funcall2(bzf->io, id_closed, 0, 0));
270
- }
271
- if (!closed) {
272
- rb_funcall2(bzf->io, id_close, 0, 0);
273
- }
274
+ if (rb_respond_to(bzf->io, id_closed)) {
275
+ closed = RTEST(rb_funcall2(bzf->io, id_closed, 0, 0));
276
+ }
277
+ if (!closed) {
278
+ rb_funcall2(bzf->io, id_close, 0, 0);
279
+ }
274
280
  }
275
281
  return Qnil;
276
282
  }
@@ -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
 
@@ -338,7 +355,7 @@ bz_writer_s_alloc(obj)
338
355
  struct bz_file *bzf;
339
356
  VALUE res;
340
357
  res = Data_Make_Struct(obj, struct bz_file, bz_file_mark,
341
- bz_writer_free, bzf);
358
+ bz_writer_free, bzf);
342
359
  bzf->bzs.bzalloc = bz_malloc;
343
360
  bzf->bzs.bzfree = bz_free;
344
361
  bzf->blocks = DEFAULT_BLOCKS;
@@ -354,7 +371,7 @@ bz_writer_flush(obj)
354
371
 
355
372
  Get_BZ2(obj, bzf);
356
373
  if (bzf->flags & BZ2_RB_INTERNAL) {
357
- return bz_writer_close(obj);
374
+ return bz_writer_close(obj);
358
375
  }
359
376
  bz_writer_internal_flush(bzf);
360
377
  return Qnil;
@@ -369,22 +386,22 @@ bz_writer_s_open(argc, argv, obj)
369
386
  struct bz_file *bzf;
370
387
 
371
388
  if (argc < 1) {
372
- rb_raise(rb_eArgError, "invalid number of arguments");
389
+ rb_raise(rb_eArgError, "invalid number of arguments");
373
390
  }
374
391
  if (argc == 1) {
375
- argv[0] = rb_funcall(rb_mKernel, id_open, 2, argv[0],
376
- rb_str_new2("wb"));
392
+ argv[0] = rb_funcall(rb_mKernel, id_open, 2, argv[0],
393
+ rb_str_new2("wb"));
377
394
  }
378
395
  else {
379
- argv[1] = rb_funcall2(rb_mKernel, id_open, 2, argv);
380
- argv += 1;
381
- argc -= 1;
396
+ argv[1] = rb_funcall2(rb_mKernel, id_open, 2, argv);
397
+ argv += 1;
398
+ argc -= 1;
382
399
  }
383
400
  res = rb_funcall2(obj, id_new, argc, argv);
384
401
  Data_Get_Struct(res, struct bz_file, bzf);
385
402
  bzf->flags |= BZ2_RB_CLOSE;
386
403
  if (rb_block_given_p()) {
387
- return rb_ensure(rb_yield, res, bz_writer_close, res);
404
+ return rb_ensure(rb_yield, res, bz_writer_close, res);
388
405
  }
389
406
  return res;
390
407
  }
@@ -394,10 +411,10 @@ bz_str_write(obj, str)
394
411
  VALUE obj, str;
395
412
  {
396
413
  if (TYPE(str) != T_STRING) {
397
- rb_raise(rb_eArgError, "expected a String");
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
  }
@@ -421,60 +438,64 @@ bz_writer_init(argc, argv, obj)
421
438
 
422
439
  switch(rb_scan_args(argc, argv, "03", &a, &b, &c)) {
423
440
  case 3:
424
- work = NUM2INT(c);
425
- /* ... */
441
+ work = NUM2INT(c);
442
+ /* ... */
426
443
  case 2:
427
- blocks = NUM2INT(b);
444
+ blocks = NUM2INT(b);
428
445
  }
429
446
  Data_Get_Struct(obj, struct bz_file, bzf);
430
447
  if (NIL_P(a)) {
431
- a = rb_str_new(0, 0);
432
- rb_define_method(rb_singleton_class(a), "write", bz_str_write, 1);
433
- rb_define_method(rb_singleton_class(a), "closed?", bz_str_closed, 0);
434
- bzf->flags |= BZ2_RB_INTERNAL;
448
+ a = rb_str_new(0, 0);
449
+ rb_define_method(rb_singleton_class(a), "write", bz_str_write, 1);
450
+ rb_define_method(rb_singleton_class(a), "closed?", bz_str_closed, 0);
451
+ bzf->flags |= BZ2_RB_INTERNAL;
435
452
  }
436
453
  else {
437
- VALUE iv;
438
- struct bz_iv *bziv;
439
- OpenFile *fptr;
440
-
441
- rb_io_taint_check(a);
442
- if (!rb_respond_to(a, id_write)) {
443
- rb_raise(rb_eArgError, "first argument must respond to #write");
444
- }
445
- if (TYPE(a) == T_FILE) {
446
- GetOpenFile(a, fptr);
447
- rb_io_check_writable(fptr);
448
- }
449
- else if (rb_respond_to(a, id_closed)) {
450
- iv = rb_funcall2(a, id_closed, 0, 0);
451
- if (RTEST(iv)) {
452
- rb_raise(rb_eArgError, "closed object");
453
- }
454
- }
455
- bziv = bz_find_struct(a, 0, 0);
456
- if (bziv) {
457
- if (RTEST(bziv->bz2)) {
458
- rb_raise(rb_eArgError, "invalid data type");
459
- }
460
- bziv->bz2 = obj;
461
- }
462
- else {
463
- iv = Data_Make_Struct(rb_cData, struct bz_iv, 0, free, bziv);
464
- bziv->io = a;
465
- bziv->bz2 = obj;
466
- rb_ary_push(bz_internal_ary, iv);
467
- }
468
- switch (TYPE(a)) {
469
- case T_FILE:
470
- bziv->finalize = RFILE(a)->fptr->finalize;
471
- RFILE(a)->fptr->finalize = bz_io_data_finalize;
472
- break;
473
- case T_DATA:
474
- bziv->finalize = RDATA(a)->dfree;
475
- RDATA(a)->dfree = bz_io_data_finalize;
476
- break;
477
- }
454
+ VALUE iv;
455
+ struct bz_iv *bziv;
456
+ #ifndef RUBY_19_COMPATIBILITY
457
+ OpenFile *fptr;
458
+ #else
459
+ rb_io_t *fptr;
460
+ #endif
461
+
462
+ rb_io_taint_check(a);
463
+ if (!rb_respond_to(a, id_write)) {
464
+ rb_raise(rb_eArgError, "first argument must respond to #write");
465
+ }
466
+ if (TYPE(a) == T_FILE) {
467
+ GetOpenFile(a, fptr);
468
+ rb_io_check_writable(fptr);
469
+ }
470
+ else if (rb_respond_to(a, id_closed)) {
471
+ iv = rb_funcall2(a, id_closed, 0, 0);
472
+ if (RTEST(iv)) {
473
+ rb_raise(rb_eArgError, "closed object");
474
+ }
475
+ }
476
+ bziv = bz_find_struct(a, 0, 0);
477
+ if (bziv) {
478
+ if (RTEST(bziv->bz2)) {
479
+ rb_raise(rb_eArgError, "invalid data type");
480
+ }
481
+ bziv->bz2 = obj;
482
+ }
483
+ else {
484
+ iv = Data_Make_Struct(rb_cData, struct bz_iv, 0, free, bziv);
485
+ bziv->io = a;
486
+ bziv->bz2 = obj;
487
+ rb_ary_push(bz_internal_ary, iv);
488
+ }
489
+ switch (TYPE(a)) {
490
+ case T_FILE:
491
+ bziv->finalize = RFILE(a)->fptr->finalize;
492
+ RFILE(a)->fptr->finalize = bz_io_data_finalize;
493
+ break;
494
+ case T_DATA:
495
+ bziv->finalize = RDATA(a)->dfree;
496
+ RDATA(a)->dfree = bz_io_data_finalize;
497
+ break;
498
+ }
478
499
  }
479
500
  bzf->io = a;
480
501
  bzf->blocks = blocks;
@@ -494,36 +515,36 @@ bz_writer_write(obj, a)
494
515
  a = rb_obj_as_string(a);
495
516
  Get_BZ2(obj, bzf);
496
517
  if (!bzf->buf) {
497
- if (bzf->state != BZ_OK) {
498
- bz_raise(bzf->state);
499
- }
500
- bzf->state = BZ2_bzCompressInit(&(bzf->bzs), bzf->blocks,
501
- 0, bzf->work);
502
- if (bzf->state != BZ_OK) {
503
- bz_writer_internal_flush(bzf);
504
- bz_raise(bzf->state);
505
- }
506
- bzf->buf = ALLOC_N(char, BZ_RB_BLOCKSIZE + 1);
507
- bzf->buflen = BZ_RB_BLOCKSIZE;
508
- bzf->buf[0] = bzf->buf[bzf->buflen] = '\0';
509
- }
510
- bzf->bzs.next_in = RSTRING(a)->ptr;
511
- bzf->bzs.avail_in = RSTRING(a)->len;
518
+ if (bzf->state != BZ_OK) {
519
+ bz_raise(bzf->state);
520
+ }
521
+ bzf->state = BZ2_bzCompressInit(&(bzf->bzs), bzf->blocks,
522
+ 0, bzf->work);
523
+ if (bzf->state != BZ_OK) {
524
+ bz_writer_internal_flush(bzf);
525
+ bz_raise(bzf->state);
526
+ }
527
+ bzf->buf = ALLOC_N(char, BZ_RB_BLOCKSIZE + 1);
528
+ bzf->buflen = BZ_RB_BLOCKSIZE;
529
+ bzf->buf[0] = bzf->buf[bzf->buflen] = '\0';
530
+ }
531
+ bzf->bzs.next_in = RSTRING_PTR(a);
532
+ bzf->bzs.avail_in = RSTRING_LEN(a);
512
533
  while (bzf->bzs.avail_in) {
513
- bzf->bzs.next_out = bzf->buf;
514
- bzf->bzs.avail_out = bzf->buflen;
515
- bzf->state = BZ2_bzCompress(&(bzf->bzs), BZ_RUN);
516
- if (bzf->state == BZ_SEQUENCE_ERROR || bzf->state == BZ_PARAM_ERROR) {
517
- bz_writer_internal_flush(bzf);
518
- bz_raise(bzf->state);
519
- }
520
- bzf->state = BZ_OK;
521
- if (bzf->bzs.avail_out < bzf->buflen) {
522
- n = bzf->buflen - bzf->bzs.avail_out;
523
- rb_funcall(bzf->io, id_write, 1, rb_str_new(bzf->buf, n));
524
- }
525
- }
526
- return INT2NUM(RSTRING(a)->len);
534
+ bzf->bzs.next_out = bzf->buf;
535
+ bzf->bzs.avail_out = bzf->buflen;
536
+ bzf->state = BZ2_bzCompress(&(bzf->bzs), BZ_RUN);
537
+ if (bzf->state == BZ_SEQUENCE_ERROR || bzf->state == BZ_PARAM_ERROR) {
538
+ bz_writer_internal_flush(bzf);
539
+ bz_raise(bzf->state);
540
+ }
541
+ bzf->state = BZ_OK;
542
+ if (bzf->bzs.avail_out < bzf->buflen) {
543
+ n = bzf->buflen - bzf->bzs.avail_out;
544
+ rb_funcall(bzf->io, id_write, 1, rb_str_new(bzf->buf, n));
545
+ }
546
+ }
547
+ return INT2NUM(RSTRING_LEN(a));
527
548
  }
528
549
 
529
550
  static VALUE
@@ -542,15 +563,15 @@ bz_compress(argc, argv, obj)
542
563
  VALUE bz2, str;
543
564
 
544
565
  if (!argc) {
545
- rb_raise(rb_eArgError, "need a String to compress");
566
+ rb_raise(rb_eArgError, "need a String to compress");
546
567
  }
547
568
  str = rb_str_to_str(argv[0]);
548
569
  argv[0] = Qnil;
549
570
  bz2 = rb_funcall2(bz_cWriter, id_new, argc, argv);
550
571
  if (OBJ_TAINTED(str)) {
551
- struct bz_file *bzf;
552
- Data_Get_Struct(bz2, struct bz_file, bzf);
553
- OBJ_TAINT(bzf->io);
572
+ struct bz_file *bzf;
573
+ Data_Get_Struct(bz2, struct bz_file, bzf);
574
+ OBJ_TAINT(bzf->io);
554
575
  }
555
576
  bz_writer_write(bz2, str);
556
577
  return bz_writer_close(bz2);
@@ -563,7 +584,7 @@ bz_reader_s_alloc(obj)
563
584
  struct bz_file *bzf;
564
585
  VALUE res;
565
586
  res = Data_Make_Struct(obj, struct bz_file, bz_file_mark,
566
- ruby_xfree, bzf);
587
+ ruby_xfree, bzf);
567
588
  bzf->bzs.bzalloc = bz_malloc;
568
589
  bzf->bzs.bzfree = bz_free;
569
590
  bzf->blocks = DEFAULT_BLOCKS;
@@ -582,7 +603,7 @@ bz_reader_s_open(argc, argv, obj)
582
603
  struct bz_file *bzf;
583
604
 
584
605
  if (argc < 1) {
585
- rb_raise(rb_eArgError, "invalid number of arguments");
606
+ rb_raise(rb_eArgError, "invalid number of arguments");
586
607
  }
587
608
  argv[0] = rb_funcall2(rb_mKernel, id_open, 1, argv);
588
609
  if (NIL_P(argv[0])) return Qnil;
@@ -590,7 +611,7 @@ bz_reader_s_open(argc, argv, obj)
590
611
  Data_Get_Struct(res, struct bz_file, bzf);
591
612
  bzf->flags |= BZ2_RB_CLOSE;
592
613
  if (rb_block_given_p()) {
593
- return rb_ensure(rb_yield, res, bz_reader_close, res);
614
+ return rb_ensure(rb_yield, res, bz_reader_close, res);
594
615
  }
595
616
  return res;
596
617
  }
@@ -606,42 +627,46 @@ bz_reader_init(argc, argv, obj)
606
627
  int internal = 0;
607
628
 
608
629
  if (rb_scan_args(argc, argv, "11", &a, &b) == 2) {
609
- small = RTEST(b);
630
+ small = RTEST(b);
610
631
  }
611
632
  rb_io_taint_check(a);
612
633
  if (OBJ_TAINTED(a)) {
613
- OBJ_TAINT(obj);
634
+ OBJ_TAINT(obj);
614
635
  }
615
636
  if (rb_respond_to(a, id_read)) {
616
- if (TYPE(a) == T_FILE) {
617
- OpenFile *fptr;
618
-
619
- GetOpenFile(a, fptr);
620
- rb_io_check_readable(fptr);
621
- }
622
- else if (rb_respond_to(a, id_closed)) {
623
- VALUE iv = rb_funcall2(a, id_closed, 0, 0);
624
- if (RTEST(iv)) {
625
- rb_raise(rb_eArgError, "closed object");
626
- }
627
- }
637
+ if (TYPE(a) == T_FILE) {
638
+ #ifndef RUBY_19_COMPATIBILITY
639
+ OpenFile *fptr;
640
+ #else
641
+ rb_io_t *fptr;
642
+ #endif
643
+
644
+ GetOpenFile(a, fptr);
645
+ rb_io_check_readable(fptr);
646
+ }
647
+ else if (rb_respond_to(a, id_closed)) {
648
+ VALUE iv = rb_funcall2(a, id_closed, 0, 0);
649
+ if (RTEST(iv)) {
650
+ rb_raise(rb_eArgError, "closed object");
651
+ }
652
+ }
628
653
  }
629
654
  else {
630
- struct bz_str *bzs;
631
- VALUE res;
632
-
633
- if (!rb_respond_to(a, id_str)) {
634
- rb_raise(rb_eArgError, "first argument must respond to #read");
635
- }
636
- a = rb_funcall2(a, id_str, 0, 0);
637
- if (TYPE(a) != T_STRING) {
638
- rb_raise(rb_eArgError, "#to_str must return a String");
639
- }
640
- res = Data_Make_Struct(bz_cInternal, struct bz_str,
641
- bz_str_mark, ruby_xfree, bzs);
642
- bzs->str = a;
643
- a = res;
644
- internal = BZ2_RB_INTERNAL;
655
+ struct bz_str *bzs;
656
+ VALUE res;
657
+
658
+ if (!rb_respond_to(a, id_str)) {
659
+ rb_raise(rb_eArgError, "first argument must respond to #read");
660
+ }
661
+ a = rb_funcall2(a, id_str, 0, 0);
662
+ if (TYPE(a) != T_STRING) {
663
+ rb_raise(rb_eArgError, "#to_str must return a String");
664
+ }
665
+ res = Data_Make_Struct(bz_cInternal, struct bz_str,
666
+ bz_str_mark, ruby_xfree, bzs);
667
+ bzs->str = a;
668
+ a = res;
669
+ internal = BZ2_RB_INTERNAL;
645
670
  }
646
671
  Data_Get_Struct(obj, struct bz_file, bzf);
647
672
  bzf->io = a;
@@ -658,23 +683,23 @@ bz_get_bzf(obj)
658
683
 
659
684
  Get_BZ2(obj, bzf);
660
685
  if (!bzf->buf) {
661
- if (bzf->state != BZ_OK) {
662
- bz_raise(bzf->state);
663
- }
664
- bzf->state = BZ2_bzDecompressInit(&(bzf->bzs), 0, bzf->small);
665
- if (bzf->state != BZ_OK) {
666
- BZ2_bzDecompressEnd(&(bzf->bzs));
667
- bz_raise(bzf->state);
668
- }
669
- bzf->buf = ALLOC_N(char, BZ_RB_BLOCKSIZE + 1);
670
- bzf->buflen = BZ_RB_BLOCKSIZE;
671
- bzf->buf[0] = bzf->buf[bzf->buflen] = '\0';
672
- bzf->bzs.total_out_hi32 = bzf->bzs.total_out_lo32 = 0;
673
- bzf->bzs.next_out = bzf->buf;
674
- bzf->bzs.avail_out = 0;
686
+ if (bzf->state != BZ_OK) {
687
+ bz_raise(bzf->state);
688
+ }
689
+ bzf->state = BZ2_bzDecompressInit(&(bzf->bzs), 0, bzf->small);
690
+ if (bzf->state != BZ_OK) {
691
+ BZ2_bzDecompressEnd(&(bzf->bzs));
692
+ bz_raise(bzf->state);
693
+ }
694
+ bzf->buf = ALLOC_N(char, BZ_RB_BLOCKSIZE + 1);
695
+ bzf->buflen = BZ_RB_BLOCKSIZE;
696
+ bzf->buf[0] = bzf->buf[bzf->buflen] = '\0';
697
+ bzf->bzs.total_out_hi32 = bzf->bzs.total_out_lo32 = 0;
698
+ bzf->bzs.next_out = bzf->buf;
699
+ bzf->bzs.avail_out = 0;
675
700
  }
676
701
  if (bzf->state == BZ_STREAM_END && !bzf->bzs.avail_out) {
677
- return 0;
702
+ return 0;
678
703
  }
679
704
  return bzf;
680
705
  }
@@ -687,33 +712,33 @@ bz_next_available(bzf, in)
687
712
  bzf->bzs.next_out = bzf->buf;
688
713
  bzf->bzs.avail_out = 0;
689
714
  if (bzf->state == BZ_STREAM_END) {
690
- return BZ_STREAM_END;
715
+ return BZ_STREAM_END;
691
716
  }
692
717
  if (!bzf->bzs.avail_in) {
693
- bzf->in = rb_funcall(bzf->io, id_read, 1, INT2FIX(1024));
694
- if (TYPE(bzf->in) != T_STRING || RSTRING(bzf->in)->len == 0) {
695
- BZ2_bzDecompressEnd(&(bzf->bzs));
696
- bzf->bzs.avail_out = 0;
697
- bzf->state = BZ_UNEXPECTED_EOF;
698
- bz_raise(bzf->state);
699
- }
700
- bzf->bzs.next_in = RSTRING(bzf->in)->ptr;
701
- bzf->bzs.avail_in = RSTRING(bzf->in)->len;
718
+ bzf->in = rb_funcall(bzf->io, id_read, 1, INT2FIX(1024));
719
+ if (TYPE(bzf->in) != T_STRING || RSTRING_LEN(bzf->in) == 0) {
720
+ BZ2_bzDecompressEnd(&(bzf->bzs));
721
+ bzf->bzs.avail_out = 0;
722
+ bzf->state = BZ_UNEXPECTED_EOF;
723
+ bz_raise(bzf->state);
724
+ }
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
- bzf->buf = REALLOC_N(bzf->buf, char, bzf->buflen+BZ_RB_BLOCKSIZE+1);
705
- bzf->buflen += BZ_RB_BLOCKSIZE;
706
- bzf->buf[bzf->buflen] = '\0';
729
+ bzf->buf = REALLOC_N(bzf->buf, char, bzf->buflen+BZ_RB_BLOCKSIZE+1);
730
+ bzf->buflen += BZ_RB_BLOCKSIZE;
731
+ bzf->buf[bzf->buflen] = '\0';
707
732
  }
708
733
  bzf->bzs.avail_out = bzf->buflen - in;
709
734
  bzf->bzs.next_out = bzf->buf + in;
710
735
  bzf->state = BZ2_bzDecompress(&(bzf->bzs));
711
736
  if (bzf->state != BZ_OK) {
712
- BZ2_bzDecompressEnd(&(bzf->bzs));
713
- if (bzf->state != BZ_STREAM_END) {
714
- bzf->bzs.avail_out = 0;
715
- bz_raise(bzf->state);
716
- }
737
+ BZ2_bzDecompressEnd(&(bzf->bzs));
738
+ if (bzf->state != BZ_STREAM_END) {
739
+ bzf->bzs.avail_out = 0;
740
+ bz_raise(bzf->state);
741
+ }
717
742
  }
718
743
  bzf->bzs.avail_out = bzf->buflen - bzf->bzs.avail_out;
719
744
  bzf->bzs.next_out = bzf->buf;
@@ -735,56 +760,56 @@ bz_read_until(bzf, str, len, td1)
735
760
 
736
761
  res = rb_str_new(0, 0);
737
762
  while (1) {
738
- total = bzf->bzs.avail_out;
739
- if (len == 1) {
740
- tx = memchr(bzf->bzs.next_out, *str, bzf->bzs.avail_out);
741
- if (tx) {
742
- i = tx - bzf->bzs.next_out + len;
743
- res = rb_str_cat(res, bzf->bzs.next_out, i);
744
- bzf->bzs.next_out += i;
745
- bzf->bzs.avail_out -= i;
746
- return res;
747
- }
748
- }
749
- else {
750
- tx = bzf->bzs.next_out;
751
- end = bzf->bzs.next_out + bzf->bzs.avail_out;
752
- while (tx + len <= end) {
753
- for (p = str, t = tx; p != pend; ++p, ++t) {
754
- if (*p != *t) break;
755
- }
756
- if (p == pend) {
757
- i = tx - bzf->bzs.next_out + len;
758
- res = rb_str_cat(res, bzf->bzs.next_out, i);
759
- bzf->bzs.next_out += i;
760
- bzf->bzs.avail_out -= i;
761
- return res;
762
- }
763
- if (td1) {
764
- tx += td1[(int)*(tx + len)];
765
- }
766
- else {
767
- tx += 1;
768
- }
769
- }
770
- }
771
- nex = 0;
772
- if (total) {
773
- nex = len - 1;
774
- res = rb_str_cat(res, bzf->bzs.next_out, total - nex);
775
- if (nex) {
776
- MEMMOVE(bzf->buf, bzf->bzs.next_out + total - nex, char, nex);
777
- }
778
- }
779
- if (bz_next_available(bzf, nex) == BZ_STREAM_END) {
780
- if (nex) {
781
- res = rb_str_cat(res, bzf->buf, nex);
782
- }
783
- if (RSTRING(res)->len) {
784
- return res;
785
- }
786
- return Qnil;
787
- }
763
+ total = bzf->bzs.avail_out;
764
+ if (len == 1) {
765
+ tx = memchr(bzf->bzs.next_out, *str, bzf->bzs.avail_out);
766
+ if (tx) {
767
+ i = tx - bzf->bzs.next_out + len;
768
+ res = rb_str_cat(res, bzf->bzs.next_out, i);
769
+ bzf->bzs.next_out += i;
770
+ bzf->bzs.avail_out -= i;
771
+ return res;
772
+ }
773
+ }
774
+ else {
775
+ tx = bzf->bzs.next_out;
776
+ end = bzf->bzs.next_out + bzf->bzs.avail_out;
777
+ while (tx + len <= end) {
778
+ for (p = str, t = tx; p != pend; ++p, ++t) {
779
+ if (*p != *t) break;
780
+ }
781
+ if (p == pend) {
782
+ i = tx - bzf->bzs.next_out + len;
783
+ res = rb_str_cat(res, bzf->bzs.next_out, i);
784
+ bzf->bzs.next_out += i;
785
+ bzf->bzs.avail_out -= i;
786
+ return res;
787
+ }
788
+ if (td1) {
789
+ tx += td1[(int)*(tx + len)];
790
+ }
791
+ else {
792
+ tx += 1;
793
+ }
794
+ }
795
+ }
796
+ nex = 0;
797
+ if (total) {
798
+ nex = len - 1;
799
+ res = rb_str_cat(res, bzf->bzs.next_out, total - nex);
800
+ if (nex) {
801
+ MEMMOVE(bzf->buf, bzf->bzs.next_out + total - nex, char, nex);
802
+ }
803
+ }
804
+ if (bz_next_available(bzf, nex) == BZ_STREAM_END) {
805
+ if (nex) {
806
+ res = rb_str_cat(res, bzf->buf, nex);
807
+ }
808
+ if (RSTRING_LEN(res)) {
809
+ return res;
810
+ }
811
+ return Qnil;
812
+ }
788
813
  }
789
814
  return Qnil;
790
815
  }
@@ -797,17 +822,17 @@ bz_read_while(bzf, c)
797
822
  char *end;
798
823
 
799
824
  while (1) {
800
- end = bzf->bzs.next_out + bzf->bzs.avail_out;
801
- while (bzf->bzs.next_out < end) {
802
- if (c != *bzf->bzs.next_out) {
803
- bzf->bzs.avail_out = end - bzf->bzs.next_out;
804
- return *bzf->bzs.next_out;
805
- }
806
- ++bzf->bzs.next_out;
807
- }
808
- if (bz_next_available(bzf, 0) == BZ_STREAM_END) {
809
- return EOF;
810
- }
825
+ end = bzf->bzs.next_out + bzf->bzs.avail_out;
826
+ while (bzf->bzs.next_out < end) {
827
+ if (c != *bzf->bzs.next_out) {
828
+ bzf->bzs.avail_out = end - bzf->bzs.next_out;
829
+ return *bzf->bzs.next_out;
830
+ }
831
+ ++bzf->bzs.next_out;
832
+ }
833
+ if (bz_next_available(bzf, 0) == BZ_STREAM_END) {
834
+ return EOF;
835
+ }
811
836
  }
812
837
  return EOF;
813
838
  }
@@ -824,40 +849,40 @@ bz_reader_read(argc, argv, obj)
824
849
 
825
850
  rb_scan_args(argc, argv, "01", &length);
826
851
  if (NIL_P(length)) {
827
- n = -1;
852
+ n = -1;
828
853
  }
829
854
  else {
830
- n = NUM2INT(length);
831
- if (n < 0) {
832
- rb_raise(rb_eArgError, "negative length %d given", n);
833
- }
855
+ n = NUM2INT(length);
856
+ if (n < 0) {
857
+ rb_raise(rb_eArgError, "negative length %d given", n);
858
+ }
834
859
  }
835
860
  bzf = bz_get_bzf(obj);
836
861
  if (!bzf) {
837
- return Qnil;
862
+ return Qnil;
838
863
  }
839
864
  res = rb_str_new(0, 0);
840
865
  if (OBJ_TAINTED(obj)) {
841
- OBJ_TAINT(res);
866
+ OBJ_TAINT(res);
842
867
  }
843
868
  if (n == 0) {
844
- return res;
869
+ return res;
845
870
  }
846
871
  while (1) {
847
- total = bzf->bzs.avail_out;
848
- if (n != -1 && (RSTRING(res)->len + total) >= n) {
849
- n -= RSTRING(res)->len;
850
- res = rb_str_cat(res, bzf->bzs.next_out, n);
851
- bzf->bzs.next_out += n;
852
- bzf->bzs.avail_out -= n;
853
- return res;
854
- }
855
- if (total) {
856
- res = rb_str_cat(res, bzf->bzs.next_out, total);
857
- }
858
- if (bz_next_available(bzf, 0) == BZ_STREAM_END) {
859
- return res;
860
- }
872
+ total = bzf->bzs.avail_out;
873
+ if (n != -1 && (RSTRING_LEN(res) + total) >= n) {
874
+ n -= RSTRING_LEN(res);
875
+ res = rb_str_cat(res, bzf->bzs.next_out, n);
876
+ bzf->bzs.next_out += n;
877
+ bzf->bzs.avail_out -= n;
878
+ return res;
879
+ }
880
+ if (total) {
881
+ res = rb_str_cat(res, bzf->bzs.next_out, total);
882
+ }
883
+ if (bz_next_available(bzf, 0) == BZ_STREAM_END) {
884
+ return res;
885
+ }
861
886
  }
862
887
  return Qnil;
863
888
  }
@@ -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) {
872
- return EOF;
896
+ if (NIL_P(res) || RSTRING_LEN(res) == 0) {
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
@@ -883,19 +908,19 @@ bz_reader_ungetc(obj, a)
883
908
 
884
909
  Get_BZ2(obj, bzf);
885
910
  if (!bzf->buf) {
886
- bz_raise(BZ_SEQUENCE_ERROR);
911
+ bz_raise(BZ_SEQUENCE_ERROR);
887
912
  }
888
913
  if (bzf->bzs.avail_out < bzf->buflen) {
889
- bzf->bzs.next_out -= 1;
890
- bzf->bzs.next_out[0] = c;
891
- bzf->bzs.avail_out += 1;
914
+ bzf->bzs.next_out -= 1;
915
+ bzf->bzs.next_out[0] = c;
916
+ bzf->bzs.avail_out += 1;
892
917
  }
893
918
  else {
894
- bzf->buf = REALLOC_N(bzf->buf, char, bzf->buflen + 2);
895
- bzf->buf[bzf->buflen++] = c;
896
- bzf->buf[bzf->buflen] = '\0';
897
- bzf->bzs.next_out = bzf->buf;
898
- bzf->bzs.avail_out = bzf->buflen;
919
+ bzf->buf = REALLOC_N(bzf->buf, char, bzf->buflen + 2);
920
+ bzf->buf[bzf->buflen++] = c;
921
+ bzf->buf[bzf->buflen] = '\0';
922
+ bzf->bzs.next_out = bzf->buf;
923
+ bzf->bzs.avail_out = bzf->buflen;
899
924
  }
900
925
  return Qnil;
901
926
  }
@@ -909,20 +934,20 @@ bz_reader_ungets(obj, a)
909
934
  Check_Type(a, T_STRING);
910
935
  Get_BZ2(obj, bzf);
911
936
  if (!bzf->buf) {
912
- bz_raise(BZ_SEQUENCE_ERROR);
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;
923
- bzf->buf[bzf->buflen] = '\0';
924
- bzf->bzs.next_out = bzf->buf;
925
- bzf->bzs.avail_out = bzf->buflen;
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);
948
+ bzf->buf[bzf->buflen] = '\0';
949
+ bzf->bzs.next_out = bzf->buf;
950
+ bzf->bzs.avail_out = bzf->buflen;
926
951
  }
927
952
  return Qnil;
928
953
  }
@@ -936,11 +961,11 @@ bz_reader_gets(obj)
936
961
 
937
962
  bzf = bz_get_bzf(obj);
938
963
  if (bzf) {
939
- str = bz_read_until(bzf, "\n", 1, 0);
940
- if (!NIL_P(str)) {
941
- bzf->lineno++;
942
- OBJ_TAINT(str);
943
- }
964
+ str = bz_read_until(bzf, "\n", 1, 0);
965
+ if (!NIL_P(str)) {
966
+ bzf->lineno++;
967
+ OBJ_TAINT(str);
968
+ }
944
969
  }
945
970
  return str;
946
971
  }
@@ -958,59 +983,59 @@ bz_reader_gets_internal(argc, argv, obj, td, init)
958
983
 
959
984
  rs = rb_rs;
960
985
  if (argc) {
961
- rb_scan_args(argc, argv, "1", &rs);
962
- if (!NIL_P(rs)) {
963
- Check_Type(rs, T_STRING);
964
- }
986
+ rb_scan_args(argc, argv, "1", &rs);
987
+ if (!NIL_P(rs)) {
988
+ Check_Type(rs, T_STRING);
989
+ }
965
990
  }
966
991
  if (NIL_P(rs)) {
967
- return bz_reader_read(1, &rs, obj);
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')) {
971
- return bz_reader_gets(obj);
994
+ rslen = RSTRING_LEN(rs);
995
+ if (rs == rb_default_rs || (rslen == 1 && RSTRING_PTR(rs)[0] == '\n')) {
996
+ return bz_reader_gets(obj);
972
997
  }
973
998
 
974
999
  if (rslen == 0) {
975
- rsptr = "\n\n";
976
- rslen = 2;
977
- rspara = 1;
1000
+ rsptr = "\n\n";
1001
+ rslen = 2;
1002
+ rspara = 1;
978
1003
  }
979
1004
  else {
980
- rsptr = RSTRING(rs)->ptr;
981
- rspara = 0;
1005
+ rsptr = RSTRING_PTR(rs);
1006
+ rspara = 0;
982
1007
  }
983
1008
 
984
1009
  bzf = bz_get_bzf(obj);
985
1010
  if (!bzf) {
986
- return Qnil;
1011
+ return Qnil;
987
1012
  }
988
1013
  if (rspara) {
989
- bz_read_while(bzf, '\n');
1014
+ bz_read_while(bzf, '\n');
990
1015
  }
991
1016
  td1 = 0;
992
1017
  if (rslen != 1) {
993
- if (init) {
994
- int i;
1018
+ if (init) {
1019
+ int i;
995
1020
 
996
- for (i = 0; i < ASIZE; i++) {
997
- td[i] = rslen + 1;
998
- }
999
- for (i = 0; i < rslen; i++) {
1000
- td[(int)*(rsptr + i)] = rslen - i;
1001
- }
1002
- }
1003
- td1 = td;
1021
+ for (i = 0; i < ASIZE; i++) {
1022
+ td[i] = rslen + 1;
1023
+ }
1024
+ for (i = 0; i < rslen; i++) {
1025
+ td[(int)*(rsptr + i)] = rslen - i;
1026
+ }
1027
+ }
1028
+ td1 = td;
1004
1029
  }
1005
1030
 
1006
1031
  res = bz_read_until(bzf, rsptr, rslen, td1);
1007
1032
  if (rspara) {
1008
- bz_read_while(bzf, '\n');
1033
+ bz_read_while(bzf, '\n');
1009
1034
  }
1010
1035
 
1011
1036
  if (!NIL_P(res)) {
1012
- bzf->lineno++;
1013
- OBJ_TAINT(res);
1037
+ bzf->lineno++;
1038
+ OBJ_TAINT(res);
1014
1039
  }
1015
1040
  return res;
1016
1041
  }
@@ -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) {
1046
- return Qnil;
1070
+ if (NIL_P(str) || RSTRING_LEN(str) == 0) {
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
@@ -1061,7 +1086,7 @@ bz_reader_readchar(obj)
1061
1086
  VALUE res = bz_reader_getc(obj);
1062
1087
 
1063
1088
  if (NIL_P(res)) {
1064
- bz_eoz_error();
1089
+ bz_eoz_error();
1065
1090
  }
1066
1091
  return res;
1067
1092
  }
@@ -1075,7 +1100,7 @@ bz_reader_gets_m(argc, argv, obj)
1075
1100
  VALUE str = bz_reader_gets_internal(argc, argv, obj, td, Qtrue);
1076
1101
 
1077
1102
  if (!NIL_P(str)) {
1078
- rb_lastline_set(str);
1103
+ rb_lastline_set(str);
1079
1104
  }
1080
1105
  return str;
1081
1106
  }
@@ -1088,7 +1113,7 @@ bz_reader_readline(argc, argv, obj)
1088
1113
  VALUE res = bz_reader_gets_m(argc, argv, obj);
1089
1114
 
1090
1115
  if (NIL_P(res)) {
1091
- bz_eoz_error();
1116
+ bz_eoz_error();
1092
1117
  }
1093
1118
  return res;
1094
1119
  }
@@ -1104,8 +1129,8 @@ bz_reader_readlines(argc, argv, obj)
1104
1129
  in = Qtrue;
1105
1130
  ary = rb_ary_new();
1106
1131
  while (!NIL_P(line = bz_reader_gets_internal(argc, argv, obj, td, in))) {
1107
- in = Qfalse;
1108
- rb_ary_push(ary, line);
1132
+ in = Qfalse;
1133
+ rb_ary_push(ary, line);
1109
1134
  }
1110
1135
  return ary;
1111
1136
  }
@@ -1120,8 +1145,8 @@ bz_reader_each_line(argc, argv, obj)
1120
1145
 
1121
1146
  in = Qtrue;
1122
1147
  while (!NIL_P(line = bz_reader_gets_internal(argc, argv, obj, td, in))) {
1123
- in = Qfalse;
1124
- rb_yield(line);
1148
+ in = Qfalse;
1149
+ rb_yield(line);
1125
1150
  }
1126
1151
  return obj;
1127
1152
  }
@@ -1133,7 +1158,7 @@ bz_reader_each_byte(obj)
1133
1158
  int c;
1134
1159
 
1135
1160
  while ((c = bz_getc(obj)) != EOF) {
1136
- rb_yield(INT2FIX(c & 0xff));
1161
+ rb_yield(INT2FIX(c & 0xff));
1137
1162
  }
1138
1163
  return obj;
1139
1164
  }
@@ -1147,14 +1172,14 @@ bz_reader_unused(obj)
1147
1172
 
1148
1173
  Get_BZ2(obj, bzf);
1149
1174
  if (!bzf->in || bzf->state != BZ_STREAM_END) {
1150
- return Qnil;
1175
+ return Qnil;
1151
1176
  }
1152
1177
  if (bzf->bzs.avail_in) {
1153
- res = rb_tainted_str_new(bzf->bzs.next_in, bzf->bzs.avail_in);
1154
- bzf->bzs.avail_in = 0;
1178
+ res = rb_tainted_str_new(bzf->bzs.next_in, bzf->bzs.avail_in);
1179
+ bzf->bzs.avail_in = 0;
1155
1180
  }
1156
1181
  else {
1157
- res = rb_tainted_str_new(0, 0);
1182
+ res = rb_tainted_str_new(0, 0);
1158
1183
  }
1159
1184
  return res;
1160
1185
  }
@@ -1167,10 +1192,10 @@ bz_reader_eoz(obj)
1167
1192
 
1168
1193
  Get_BZ2(obj, bzf);
1169
1194
  if (!bzf->in || !bzf->buf) {
1170
- return Qnil;
1195
+ return Qnil;
1171
1196
  }
1172
1197
  if (bzf->state == BZ_STREAM_END && !bzf->bzs.avail_out) {
1173
- return Qtrue;
1198
+ return Qtrue;
1174
1199
  }
1175
1200
  return Qfalse;
1176
1201
  }
@@ -1184,20 +1209,20 @@ bz_reader_eof(obj)
1184
1209
 
1185
1210
  res = bz_reader_eoz(obj);
1186
1211
  if (RTEST(res)) {
1187
- Get_BZ2(obj, bzf);
1188
- if (bzf->bzs.avail_in) {
1189
- res = Qfalse;
1190
- }
1191
- else {
1192
- res = bz_reader_getc(obj);
1193
- if (NIL_P(res)) {
1194
- res = Qtrue;
1195
- }
1196
- else {
1197
- bz_reader_ungetc(res);
1198
- res = Qfalse;
1199
- }
1200
- }
1212
+ Get_BZ2(obj, bzf);
1213
+ if (bzf->bzs.avail_in) {
1214
+ res = Qfalse;
1215
+ }
1216
+ else {
1217
+ res = bz_reader_getc(obj);
1218
+ if (NIL_P(res)) {
1219
+ res = Qtrue;
1220
+ }
1221
+ else {
1222
+ bz_reader_ungetc(res);
1223
+ res = Qfalse;
1224
+ }
1225
+ }
1201
1226
  }
1202
1227
  return res;
1203
1228
  }
@@ -1221,27 +1246,27 @@ bz_reader_close(obj)
1221
1246
 
1222
1247
  Get_BZ2(obj, bzf);
1223
1248
  if (bzf->buf) {
1224
- free(bzf->buf);
1225
- bzf->buf = 0;
1249
+ free(bzf->buf);
1250
+ bzf->buf = 0;
1226
1251
  }
1227
1252
  if (bzf->state == BZ_OK) {
1228
- BZ2_bzDecompressEnd(&(bzf->bzs));
1253
+ BZ2_bzDecompressEnd(&(bzf->bzs));
1229
1254
  }
1230
1255
  if (bzf->flags & BZ2_RB_CLOSE) {
1231
- int closed = 0;
1232
- if (rb_respond_to(bzf->io, id_closed)) {
1233
- VALUE iv = rb_funcall2(bzf->io, id_closed, 0, 0);
1234
- closed = RTEST(iv);
1235
- }
1236
- if (!closed && rb_respond_to(bzf->io, id_close)) {
1237
- rb_funcall2(bzf->io, id_close, 0, 0);
1238
- }
1256
+ int closed = 0;
1257
+ if (rb_respond_to(bzf->io, id_closed)) {
1258
+ VALUE iv = rb_funcall2(bzf->io, id_closed, 0, 0);
1259
+ closed = RTEST(iv);
1260
+ }
1261
+ if (!closed && rb_respond_to(bzf->io, id_close)) {
1262
+ rb_funcall2(bzf->io, id_close, 0, 0);
1263
+ }
1239
1264
  }
1240
1265
  if (bzf->flags & (BZ2_RB_CLOSE|BZ2_RB_INTERNAL)) {
1241
- res = Qnil;
1266
+ res = Qnil;
1242
1267
  }
1243
1268
  else {
1244
- res = bzf->io;
1269
+ res = bzf->io;
1245
1270
  }
1246
1271
  bzf->io = 0;
1247
1272
  return res;
@@ -1255,8 +1280,8 @@ bz_reader_finish(obj)
1255
1280
 
1256
1281
  Get_BZ2(obj, bzf);
1257
1282
  if (bzf->buf) {
1258
- rb_funcall2(obj, id_read, 0, 0);
1259
- free(bzf->buf);
1283
+ rb_funcall2(obj, id_read, 0, 0);
1284
+ free(bzf->buf);
1260
1285
  }
1261
1286
  bzf->buf = 0;
1262
1287
  bzf->state = BZ_OK;
@@ -1274,12 +1299,12 @@ bz_reader_close_bang(obj)
1274
1299
  closed = bzf->flags & (BZ2_RB_CLOSE|BZ2_RB_INTERNAL);
1275
1300
  bz_reader_close(obj);
1276
1301
  if (!closed && rb_respond_to(bzf->io, id_close)) {
1277
- if (rb_respond_to(bzf->io, id_closed)) {
1278
- closed = RTEST(rb_funcall2(bzf->io, id_closed, 0, 0));
1279
- }
1280
- if (!closed) {
1281
- rb_funcall2(bzf->io, id_close, 0, 0);
1282
- }
1302
+ if (rb_respond_to(bzf->io, id_closed)) {
1303
+ closed = RTEST(rb_funcall2(bzf->io, id_closed, 0, 0));
1304
+ }
1305
+ if (!closed) {
1306
+ rb_funcall2(bzf->io, id_close, 0, 0);
1307
+ }
1283
1308
  }
1284
1309
  return Qnil;
1285
1310
  }
@@ -1299,9 +1324,9 @@ bz_reader_foreach_line(arg)
1299
1324
 
1300
1325
  in = Qtrue;
1301
1326
  while (!NIL_P(str = bz_reader_gets_internal(arg->argc, &arg->sep,
1302
- arg->obj, td, in))) {
1303
- in = Qfalse;
1304
- rb_yield(str);
1327
+ arg->obj, td, in))) {
1328
+ in = Qfalse;
1329
+ rb_yield(str);
1305
1330
  }
1306
1331
  return Qnil;
1307
1332
  }
@@ -1316,7 +1341,7 @@ bz_reader_s_foreach(argc, argv, obj)
1316
1341
  struct bz_file *bzf;
1317
1342
 
1318
1343
  if (!rb_block_given_p()) {
1319
- rb_raise(rb_eArgError, "call out of a block");
1344
+ rb_raise(rb_eArgError, "call out of a block");
1320
1345
  }
1321
1346
  rb_scan_args(argc, argv, "11", &fname, &sep);
1322
1347
  Check_SafeStr(fname);
@@ -1340,9 +1365,9 @@ bz_reader_i_readlines(arg)
1340
1365
  in = Qtrue;
1341
1366
  res = rb_ary_new();
1342
1367
  while (!NIL_P(str = bz_reader_gets_internal(arg->argc, &arg->sep,
1343
- arg->obj, td, in))) {
1344
- in = Qfalse;
1345
- rb_ary_push(res, str);
1368
+ arg->obj, td, in))) {
1369
+ in = Qfalse;
1370
+ rb_ary_push(res, str);
1346
1371
  }
1347
1372
  return res;
1348
1373
  }
@@ -1411,25 +1436,25 @@ 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
- count = NUM2INT(len);
1418
- if (count < 0) {
1419
- rb_raise(rb_eArgError, "negative length %d given", count);
1420
- }
1442
+ count = NUM2INT(len);
1443
+ if (count < 0) {
1444
+ rb_raise(rb_eArgError, "negative length %d given", count);
1445
+ }
1421
1446
  }
1422
1447
  if (!count || bzs->pos == -1) {
1423
- return Qnil;
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);
1428
- bzs->pos = -1;
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);
1453
+ bzs->pos = -1;
1429
1454
  }
1430
1455
  else {
1431
- res = rb_str_new(RSTRING(bzs->str)->ptr + bzs->pos, count);
1432
- bzs->pos += count;
1456
+ res = rb_str_new(RSTRING_PTR(bzs->str) + bzs->pos, count);
1457
+ bzs->pos += count;
1433
1458
  }
1434
1459
  return res;
1435
1460
  }
@@ -1442,7 +1467,7 @@ bz_uncompress(argc, argv, obj)
1442
1467
  VALUE bz2, nilv = Qnil;
1443
1468
 
1444
1469
  if (!argc) {
1445
- rb_raise(rb_eArgError, "need a String to Uncompress");
1470
+ rb_raise(rb_eArgError, "need a String to Uncompress");
1446
1471
  }
1447
1472
  argv[0] = rb_str_to_str(argv[0]);
1448
1473
  bz2 = rb_funcall2(bz_cReader, id_new, argc, argv);
@@ -1471,19 +1496,19 @@ 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();
1483
1508
  rb_global_variable(&bz_internal_ary);
1484
1509
  rb_funcall(rb_const_get(rb_cObject, rb_intern("ObjectSpace")),
1485
- rb_intern("define_finalizer"), 2, bz_internal_ary,
1486
- bz_proc_new(bz_internal_finalize, 0));
1510
+ rb_intern("define_finalizer"), 2, bz_internal_ary,
1511
+ bz_proc_new(bz_internal_finalize, 0));
1487
1512
 
1488
1513
  id_new = rb_intern("new");
1489
1514
  id_write = rb_intern("write");