gnista 0.0.5 → 1.0.0

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: ceb37e2f495af129a1626ca3cc184252378a2200
4
- data.tar.gz: a61becb74a8c88c437e918c9ac5771fe3e06134e
3
+ metadata.gz: d47bb0cb81b09f7ec00ad3f9af92538158afcdec
4
+ data.tar.gz: 839bc1ef781bedc07e258da534cadde3629102b8
5
5
  SHA512:
6
- metadata.gz: 76b51e8b8e8764535b94cb7c163519c6e6024e8a7d8cb165f23a73283e2bcf8994f11cf36fde211c922a924f88f0639a0c3be8fb7567b4d4ca7d50423bb02e1a
7
- data.tar.gz: 60320d0666a4bd17a27290f2aebbf15eff3f2cac1909ec4f4bd9026dd20f5d65631107f9f968529a0d98c82bcedf1a5cf02e37b8fac1f0952a7063188ff91c42
6
+ metadata.gz: 0ac005d6a3316c3f2dfe7ec3d8f1eea9f3e57ca43d70f5fe3cc5aa92cd898c27bd84f81c0f6664bac07211af3a93cbec4df007b994d1fb91d2d374e7f018cb02
7
+ data.tar.gz: 528360e116b17fb6a4472c5f5ce850b0fed5eec588804cdaa17eb109be3eb11de1cfd8e5c0588ef4b2c5d3d913520a65847a322026b363c14e4553f76af344a8
data/HISTORY.md CHANGED
@@ -1,3 +1,11 @@
1
+ # Version 1.0.0
2
+
3
+ Release date 2014-05-28
4
+
5
+ ### Fixed
6
+
7
+ * SEGFAULT on close during iteration.
8
+
1
9
  # Version 0.0.5
2
10
 
3
11
  Release date 2014-03-26
@@ -228,6 +228,10 @@ static VALUE method_logreader_each(VALUE self) {
228
228
  instance_logreader *i_logreader = get_logreader(self);
229
229
  check_open(i_logreader->open);
230
230
 
231
+ if (!rb_block_given_p()) {
232
+ return rb_funcall(self, rb_intern("to_enum"), 0);
233
+ }
234
+
231
235
  returncode = sparkey_logiter_create(&logiter, i_logreader->logreader);
232
236
 
233
237
  if (returncode != SPARKEY_SUCCESS) {
@@ -238,7 +242,7 @@ static VALUE method_logreader_each(VALUE self) {
238
242
  VALUE del_sym = ID2SYM(rb_intern("delete"));
239
243
  uint8_t *keybuf = malloc(sparkey_logreader_maxkeylen(i_logreader->logreader));
240
244
  uint8_t *valuebuf = malloc(sparkey_logreader_maxvaluelen(i_logreader->logreader));
241
- while (true) {
245
+ while (i_logreader->open) {
242
246
  returncode = sparkey_logiter_next(logiter, i_logreader->logreader);
243
247
 
244
248
  if (sparkey_logiter_state(logiter) != SPARKEY_ITER_ACTIVE) {
@@ -284,7 +288,9 @@ static VALUE method_logreader_each(VALUE self) {
284
288
  free(valuebuf);
285
289
  sparkey_logiter_close(&logiter);
286
290
 
287
- return Qnil;
291
+ check_open(i_logreader->open);
292
+
293
+ return self;
288
294
  }
289
295
 
290
296
  static VALUE method_logreader_open(VALUE self) {
@@ -402,8 +408,12 @@ static VALUE method_hash_each(VALUE self) {
402
408
  instance_hashreader *i_hashreader = get_hashreader(self);
403
409
  sparkey_logiter *logiter;
404
410
  check_open(i_hashreader->open);
405
- sparkey_logreader *logreader = sparkey_hash_getreader(i_hashreader->hashreader);
406
411
 
412
+ if (!rb_block_given_p()) {
413
+ return rb_funcall(self, rb_intern("to_enum"), 0);
414
+ }
415
+
416
+ sparkey_logreader *logreader = sparkey_hash_getreader(i_hashreader->hashreader);
407
417
  returncode = sparkey_logiter_create(&logiter, logreader);
408
418
 
409
419
  if (returncode != SPARKEY_SUCCESS) {
@@ -412,7 +422,7 @@ static VALUE method_hash_each(VALUE self) {
412
422
 
413
423
  uint8_t *keybuf = malloc(sparkey_logreader_maxkeylen(logreader));
414
424
  uint8_t *valuebuf = malloc(sparkey_logreader_maxvaluelen(logreader));
415
- while (true) {
425
+ while (i_hashreader->open) {
416
426
  returncode = sparkey_logiter_hashnext(logiter, i_hashreader->hashreader);
417
427
 
418
428
  if (sparkey_logiter_state(logiter) != SPARKEY_ITER_ACTIVE) {
@@ -448,14 +458,15 @@ static VALUE method_hash_each(VALUE self) {
448
458
  }
449
459
 
450
460
  rb_yield_values(2, rb_str_new((char *)keybuf, actual_keylen), rb_str_new((char *)valuebuf, actual_valuelen));
451
-
452
461
  }
453
462
 
454
463
  free(keybuf);
455
464
  free(valuebuf);
456
465
  sparkey_logiter_close(&logiter);
457
466
 
458
- return Qnil;
467
+ check_open(i_hashreader->open);
468
+
469
+ return self;
459
470
  }
460
471
 
461
472
  static VALUE method_hash_get(VALUE self, VALUE key) {
@@ -1,3 +1,3 @@
1
1
  module Gnista
2
- VERSION = "0.0.5"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -36,10 +36,10 @@ describe Gnista do
36
36
  @logwriter.delete "key2"
37
37
  @logwriter.flush
38
38
 
39
- lograder = Gnista::Logreader.new log_path
39
+ logreader = Gnista::Logreader.new log_path
40
40
 
41
41
  a = true
42
- lograder.each do |key,value,type|
42
+ logreader.each do |key,value,type|
43
43
  if a
44
44
  key.must_equal "key1"
45
45
  value.must_equal "value1"
@@ -54,7 +54,31 @@ describe Gnista do
54
54
 
55
55
  a.must_equal false
56
56
 
57
- lograder.close
57
+ assert_raises GnistaException do
58
+ logreader.each do
59
+ logreader.close
60
+ end
61
+ end
62
+ end
63
+
64
+ it "can iterate each log with an enumerator" do
65
+ @logwriter.put "key1", "value1"
66
+ @logwriter.delete "key2"
67
+ @logwriter.flush
68
+
69
+ logreader = Gnista::Logreader.new log_path
70
+
71
+ iter = logreader.each
72
+ iter.next.must_equal ["key1", "value1", :put]
73
+ iter.next.must_equal ["key2", nil, :delete]
74
+
75
+ iter = logreader.each
76
+ iter.next.must_equal ["key1", "value1", :put]
77
+ logreader.close
78
+
79
+ assert_raises GnistaException do
80
+ iter.next.must_equal ["key2", nil, :delete]
81
+ end
58
82
  end
59
83
 
60
84
  it "can read hash max key/value length" do
@@ -92,7 +116,35 @@ describe Gnista do
92
116
 
93
117
  a.must_equal false
94
118
 
119
+ assert_raises GnistaException do
120
+ hash.each do
121
+ hash.close
122
+ end
123
+ end
124
+
125
+ FileUtils.rm hash_path
126
+ end
127
+
128
+ it "can iterate each hash with an enumerator" do
129
+ @logwriter.put "key1", "value1"
130
+ @logwriter.put "key2", "value2"
131
+ @logwriter.flush
132
+ Gnista::Hash.write hash_path, log_path
133
+
134
+ hash = Gnista::Hash.new hash_path, log_path
135
+
136
+ iter = hash.each
137
+ iter.next.must_equal ["key1", "value1"]
138
+ iter.next.must_equal ["key2", "value2"]
139
+
140
+ iter = hash.each
141
+ iter.next.must_equal ["key1", "value1"]
95
142
  hash.close
143
+
144
+ assert_raises GnistaException do
145
+ iter.next.must_equal ["key2", "value2"]
146
+ end
147
+
96
148
  FileUtils.rm hash_path
97
149
  end
98
150
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gnista
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emanuel Andersson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-26 00:00:00.000000000 Z
11
+ date: 2014-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler