mmapscanner 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
data/ext/mmapscanner.c CHANGED
@@ -3,7 +3,17 @@
3
3
  #include <unistd.h>
4
4
  #include <sys/mman.h>
5
5
  #include <ruby.h>
6
+ #ifdef HAVE_RUBY_RUBY_H
6
7
  #include <ruby/io.h>
8
+ #include <ruby/regex.h>
9
+ #else
10
+ #include <re.h>
11
+ #endif
12
+
13
+ #ifndef NUM2SIZET
14
+ #define NUM2SIZET NUM2ULONG
15
+ #define SIZET2NUM ULONG2NUM
16
+ #endif
7
17
 
8
18
  static VALUE cMmapScanner;
9
19
  static VALUE cMmap;
@@ -56,7 +66,7 @@ static VALUE mmap_initialize(int argc, VALUE *argv, VALUE obj)
56
66
  rb_raise(rb_eRangeError, "offset out of range: %lld", NUM2LL(voffset));
57
67
  if (vlength != Qnil && NUM2LL(vlength) < 0)
58
68
  rb_raise(rb_eRangeError, "length out of range: %lld", NUM2LL(vlength));
59
- int fd = RFILE(file)->fptr->fd;
69
+ int fd = FIX2INT(rb_funcall(file, rb_intern("fileno"), 0));
60
70
  struct stat st;
61
71
  if (fstat(fd, &st) < 0)
62
72
  rb_sys_fail("fstat");
@@ -94,7 +104,11 @@ static VALUE mmap_unmap(VALUE obj)
94
104
 
95
105
  static void mmapscanner_free(mmapscanner_t *ms)
96
106
  {
107
+ #ifdef HAVE_RUBY_ONIGURUMA_H
97
108
  onig_region_free(&ms->regs, 0);
109
+ #else
110
+ re_free_registers(&ms->regs);
111
+ #endif
98
112
  xfree(ms);
99
113
  }
100
114
 
@@ -113,7 +127,11 @@ VALUE allocate(VALUE klass)
113
127
  ms->pos = 0;
114
128
  ms->matched = 0;
115
129
  ms->matched_pos = 0;
130
+ #ifdef HAVE_RUBY_ONIGURUMA_H
116
131
  onig_region_init(&ms->regs);
132
+ #else
133
+ memset(&ms->regs, 0, sizeof ms->regs);
134
+ #endif
117
135
  ms->data = Qnil;
118
136
  ms->dummy_str = Qnil;
119
137
  return Data_Wrap_Struct(klass, mark, mmapscanner_free, ms);
@@ -281,6 +299,7 @@ static VALUE scan_sub(VALUE obj, VALUE re, int forward, int headonly, int sizeon
281
299
  }
282
300
  ptr += ms->offset;
283
301
 
302
+ #ifdef HAVE_RUBY_ONIGURUMA_H
284
303
  if (ms->dummy_str == Qnil)
285
304
  ms->dummy_str = rb_str_new("", 0);
286
305
  reg = rb_reg_prepare_re(re, ms->dummy_str);
@@ -308,6 +327,20 @@ static VALUE scan_sub(VALUE obj, VALUE re, int forward, int headonly, int sizeon
308
327
  RREGEXP(re)->ptr = reg;
309
328
  }
310
329
  }
330
+ #else
331
+ if (headonly) {
332
+ result = re_match(RREGEXP(re)->ptr,
333
+ ptr+ms->pos, ms->size,
334
+ 0,
335
+ &(ms->regs));
336
+ } else {
337
+ result = re_search(RREGEXP(re)->ptr,
338
+ ptr+ms->pos, ms->size,
339
+ 0,
340
+ ms->size,
341
+ &(ms->regs));
342
+ }
343
+ #endif
311
344
  if (result < 0)
312
345
  return Qnil;
313
346
  old_pos = ms->pos;
@@ -7,6 +7,7 @@ describe MmapScanner::Mmap do
7
7
  before do
8
8
  tmpf = Tempfile.new 'mmapscanner'
9
9
  tmpf.write '0123456789'*1000
10
+ tmpf.flush
10
11
  @file = File.open(tmpf.path)
11
12
  end
12
13
  subject{MmapScanner::Mmap.new(@file)}
@@ -186,7 +187,11 @@ describe MmapScanner do
186
187
  end
187
188
  describe '.new with position' do
188
189
  it '#size is length of rest data' do
189
- MmapScanner.new(src, 4096).size.should == src.size-4096
190
+ if src.respond_to? :size
191
+ MmapScanner.new(src, 4096).size.should == src.size-4096
192
+ else
193
+ MmapScanner.new(src, 4096).size.should == File.size(src.path)-4096
194
+ end
190
195
  end
191
196
  end
192
197
  describe '.new with length' do
@@ -204,6 +209,7 @@ describe MmapScanner do
204
209
  before do
205
210
  tmpf = Tempfile.new 'mmapscanner'
206
211
  tmpf.write '0123456789'*1000
212
+ tmpf.flush
207
213
  @file = File.open(tmpf.path)
208
214
  end
209
215
  let(:src){@file}
@@ -242,6 +248,7 @@ describe MmapScanner do
242
248
  before do
243
249
  tmpf = Tempfile.new 'mmapscanner'
244
250
  tmpf.write '0123456789'*1020
251
+ tmpf.flush
245
252
  @file = File.open(tmpf.path)
246
253
  end
247
254
  let(:src){MmapScanner::Mmap.new(@file)}
@@ -284,6 +291,7 @@ describe MmapScanner do
284
291
  before do
285
292
  tmpf = Tempfile.new 'mmapscanner'
286
293
  tmpf.write '0123456789'*1020
294
+ tmpf.flush
287
295
  @file = File.open(tmpf.path)
288
296
  end
289
297
  let(:src){MmapScanner.new(@file)}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mmapscanner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-30 00:00:00.000000000 Z
12
+ date: 2011-11-18 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: tommy@tmtm.org
@@ -34,7 +34,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
34
34
  requirements:
35
35
  - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
- version: 1.9.2
37
+ version: '0'
38
38
  required_rubygems_version: !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
@@ -43,7 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
43
43
  version: '0'
44
44
  requirements: []
45
45
  rubyforge_project:
46
- rubygems_version: 1.8.10
46
+ rubygems_version: 1.8.11
47
47
  signing_key:
48
48
  specification_version: 3
49
49
  summary: MmapScanner like StringScanner but it use mmap(2)-ed data