isomorfeus-ferret 0.13.8 → 0.13.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/ext/isomorfeus_ferret_ext/frb_index.c +15 -21
  3. data/ext/isomorfeus_ferret_ext/frb_search.c +1 -4
  4. data/ext/isomorfeus_ferret_ext/frb_store.c +32 -34
  5. data/ext/isomorfeus_ferret_ext/frt_analysis.c +2 -2
  6. data/ext/isomorfeus_ferret_ext/frt_analysis.h +5 -5
  7. data/ext/isomorfeus_ferret_ext/frt_bitvector.c +1 -1
  8. data/ext/isomorfeus_ferret_ext/frt_bitvector.h +1 -1
  9. data/ext/isomorfeus_ferret_ext/frt_compound_io.c +34 -59
  10. data/ext/isomorfeus_ferret_ext/frt_except.c +1 -0
  11. data/ext/isomorfeus_ferret_ext/frt_filter.c +2 -4
  12. data/ext/isomorfeus_ferret_ext/frt_fs_store.c +11 -12
  13. data/ext/isomorfeus_ferret_ext/frt_global.c +6 -4
  14. data/ext/isomorfeus_ferret_ext/frt_global.h +1 -1
  15. data/ext/isomorfeus_ferret_ext/frt_hash.c +40 -48
  16. data/ext/isomorfeus_ferret_ext/frt_hash.h +14 -16
  17. data/ext/isomorfeus_ferret_ext/frt_ind.c +2 -3
  18. data/ext/isomorfeus_ferret_ext/frt_index.c +120 -193
  19. data/ext/isomorfeus_ferret_ext/frt_index.h +13 -13
  20. data/ext/isomorfeus_ferret_ext/frt_lang.c +1 -4
  21. data/ext/isomorfeus_ferret_ext/frt_multimapper.c +8 -9
  22. data/ext/isomorfeus_ferret_ext/frt_multimapper.h +1 -1
  23. data/ext/isomorfeus_ferret_ext/frt_q_boolean.c +6 -6
  24. data/ext/isomorfeus_ferret_ext/frt_q_match_all.c +8 -3
  25. data/ext/isomorfeus_ferret_ext/frt_q_parser.c +1742 -1742
  26. data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +1 -2
  27. data/ext/isomorfeus_ferret_ext/frt_q_span.c +11 -10
  28. data/ext/isomorfeus_ferret_ext/frt_ram_store.c +18 -34
  29. data/ext/isomorfeus_ferret_ext/frt_search.c +29 -28
  30. data/ext/isomorfeus_ferret_ext/frt_search.h +18 -19
  31. data/ext/isomorfeus_ferret_ext/frt_store.c +40 -33
  32. data/ext/isomorfeus_ferret_ext/frt_store.h +24 -26
  33. data/ext/isomorfeus_ferret_ext/frt_threading.h +12 -5
  34. data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.c +4 -3
  35. data/ext/isomorfeus_ferret_ext/test_1710.c +1 -2
  36. data/ext/isomorfeus_ferret_ext/test_compound_io.c +8 -8
  37. data/ext/isomorfeus_ferret_ext/test_fields.c +7 -7
  38. data/ext/isomorfeus_ferret_ext/test_file_deleter.c +1 -1
  39. data/ext/isomorfeus_ferret_ext/test_filter.c +4 -3
  40. data/ext/isomorfeus_ferret_ext/test_fs_store.c +1 -1
  41. data/ext/isomorfeus_ferret_ext/test_highlighter.c +3 -1
  42. data/ext/isomorfeus_ferret_ext/test_index.c +59 -59
  43. data/ext/isomorfeus_ferret_ext/test_q_const_score.c +2 -1
  44. data/ext/isomorfeus_ferret_ext/test_q_filtered.c +3 -2
  45. data/ext/isomorfeus_ferret_ext/test_q_fuzzy.c +3 -1
  46. data/ext/isomorfeus_ferret_ext/test_q_span.c +8 -1
  47. data/ext/isomorfeus_ferret_ext/test_ram_store.c +4 -4
  48. data/ext/isomorfeus_ferret_ext/test_search.c +9 -4
  49. data/ext/isomorfeus_ferret_ext/test_segments.c +4 -3
  50. data/ext/isomorfeus_ferret_ext/test_sort.c +17 -9
  51. data/ext/isomorfeus_ferret_ext/test_term.c +4 -2
  52. data/ext/isomorfeus_ferret_ext/test_term_vectors.c +2 -2
  53. data/ext/isomorfeus_ferret_ext/test_threading.c +5 -4
  54. data/lib/isomorfeus/ferret/index/index.rb +8 -3
  55. data/lib/isomorfeus/ferret/version.rb +1 -1
  56. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e6a7a9c17cc344699bee0c8116188f86da73e11fa2a4eed02eea1c4647b6a99
4
- data.tar.gz: c94c9a2735b010c02c8d5a793057b94abf8950117153415a731347c21fadf66e
3
+ metadata.gz: 744efe9c78deef0c563e39ae29eb4e755f8afb493be0fe80416a55987db97ce7
4
+ data.tar.gz: d1f814f14b5a6ef18f612e545b54b0a113544f994c22901e7204ae191ebb644e
5
5
  SHA512:
6
- metadata.gz: 549a2d3b09dc535278f6c9735f55a47203166df046e5a75ff55589085336bcf2cb7c25cdf491c07eca68da25682316c4bb15e5079f09df95f8a494558fe22260
7
- data.tar.gz: e188f428fd881a0285ece69807f13c07dfd1eee131edcad3e38a713ffa820364992bb9068d5f94f567bd7769c7882441ce8eb67199b95b491528fecdd34503f4
6
+ metadata.gz: 3fd11e3b3f0f04625c14b9b709d69ef6f1a1abdfdf5c50ad5e151a3fd87e300595e29639ac9455c66f8db5452d9569bb1585f6b2f9f57ac5c3103f2ff09bb8d1
7
+ data.tar.gz: 27ace1a41fcc7557490865e740dfbe9906ce999288bb31306efa9b02f519552f9092391ff64a3ededc6a2285a0e78533a80d43ad48e85abc97c1a154e0060a67
@@ -536,7 +536,7 @@ frb_fis_add_field(int argc, VALUE *argv, VALUE self)
536
536
  {
537
537
  FrtFieldInfos *fis = (FrtFieldInfos *)DATA_PTR(self);
538
538
  FrtFieldInfo *fi;
539
- FrtStoreValue store = fis->store;
539
+ FrtStoreValue store_val = fis->store_val;
540
540
  FrtCompressionType compression = fis->compression;
541
541
  FrtIndexValue index = fis->index;
542
542
  FrtTermVectorValue term_vector = fis->term_vector;
@@ -545,9 +545,9 @@ frb_fis_add_field(int argc, VALUE *argv, VALUE self)
545
545
 
546
546
  rb_scan_args(argc, argv, "11", &rname, &roptions);
547
547
  if (argc > 1) {
548
- frb_fi_get_params(roptions, &store, &compression, &index, &term_vector, &boost);
548
+ frb_fi_get_params(roptions, &store_val, &compression, &index, &term_vector, &boost);
549
549
  }
550
- fi = frt_fi_new(frb_field(rname), store, compression, index, term_vector);
550
+ fi = frt_fi_new(frb_field(rname), store_val, compression, index, term_vector);
551
551
  fi->boost = boost;
552
552
  frt_fis_add_field(fis, fi);
553
553
  return self;
@@ -593,9 +593,7 @@ frb_fis_to_s(VALUE self)
593
593
  *
594
594
  * Return the number of fields in the FieldInfos object.
595
595
  */
596
- static VALUE
597
- frb_fis_size(VALUE self)
598
- {
596
+ static VALUE frb_fis_size(VALUE self) {
599
597
  FrtFieldInfos *fis = (FrtFieldInfos *)DATA_PTR(self);
600
598
  return INT2FIX(fis->size);
601
599
  }
@@ -610,21 +608,19 @@ frb_fis_size(VALUE self)
610
608
  * existing index (or other files for that matter) will be deleted from the
611
609
  * directory and overwritten by the new index.
612
610
  */
613
- static VALUE
614
- frb_fis_create_index(VALUE self, VALUE rdir)
615
- {
611
+ static VALUE frb_fis_create_index(VALUE self, VALUE rdir) {
616
612
  FrtFieldInfos *fis = (FrtFieldInfos *)DATA_PTR(self);
617
613
  FrtStore *store = NULL;
618
614
  if (TYPE(rdir) == T_DATA) {
619
615
  store = DATA_PTR(rdir);
620
- FRT_REF(store);
616
+ frt_index_create(store, fis);
621
617
  } else {
622
618
  StringValue(rdir);
623
619
  frb_create_dir(rdir);
624
620
  store = frt_open_fs_store(rs2s(rdir));
621
+ frt_index_create(store, fis);
622
+ frt_store_close(store);
625
623
  }
626
- frt_index_create(store, fis);
627
- frt_store_deref(store);
628
624
  return self;
629
625
  }
630
626
 
@@ -1344,6 +1340,8 @@ static VALUE frb_iw_alloc(VALUE rclass) {
1344
1340
  return TypedData_Wrap_Struct(rclass, &frb_index_writer_t, iw);
1345
1341
  }
1346
1342
 
1343
+ extern rb_data_type_t frb_store_t;
1344
+
1347
1345
  static VALUE frb_iw_init(int argc, VALUE *argv, VALUE self) {
1348
1346
  VALUE roptions, rval;
1349
1347
  bool create = false;
@@ -1363,12 +1361,11 @@ static VALUE frb_iw_init(int argc, VALUE *argv, VALUE self) {
1363
1361
 
1364
1362
  if ((rval = rb_hash_aref(roptions, sym_dir)) != Qnil) {
1365
1363
  // Check_Type(rval, T_DATA);
1366
- store = DATA_PTR(rval);
1364
+ TypedData_Get_Struct(rval, FrtStore, &frb_store_t, store);
1367
1365
  } else if ((rval = rb_hash_aref(roptions, sym_path)) != Qnil) {
1368
1366
  StringValue(rval);
1369
1367
  frb_create_dir(rval);
1370
1368
  store = frt_open_fs_store(rs2s(rval));
1371
- FRT_DEREF(store);
1372
1369
  }
1373
1370
  /* use_compound_file defaults to true */
1374
1371
  config.use_compound_file =
@@ -1393,7 +1390,6 @@ static VALUE frb_iw_init(int argc, VALUE *argv, VALUE self) {
1393
1390
  }
1394
1391
  if (NULL == store) {
1395
1392
  store = frt_open_ram_store(NULL);
1396
- FRT_DEREF(store);
1397
1393
  }
1398
1394
  if (!create && create_if_missing && !store->exists(store, "segments")) {
1399
1395
  create = true;
@@ -1411,7 +1407,7 @@ static VALUE frb_iw_init(int argc, VALUE *argv, VALUE self) {
1411
1407
  }
1412
1408
 
1413
1409
  TypedData_Get_Struct(self, FrtIndexWriter, &frb_index_writer_t, iw);
1414
- iw = frt_iw_open(iw, store, analyzer, &config);
1410
+ frt_iw_open(iw, store, analyzer, &config);
1415
1411
  FRT_XCATCHALL
1416
1412
  ex_code = xcontext.excode;
1417
1413
  msg = xcontext.msg;
@@ -1598,9 +1594,9 @@ void frb_ir_free(void *p) {
1598
1594
 
1599
1595
  void frb_ir_mark(void *p) {
1600
1596
  FrtIndexReader *ir = (FrtIndexReader *)p;
1601
- FrtMultiReader *mr = (FrtMultiReader *)p;
1602
1597
 
1603
1598
  if (ir->type == FRT_MULTI_READER) {
1599
+ FrtMultiReader *mr = (FrtMultiReader *)p;
1604
1600
  int i;
1605
1601
  for (i = 0; i < mr->r_cnt; i++) {
1606
1602
  if (mr->sub_readers[i]->rir)
@@ -1652,6 +1648,7 @@ static VALUE frb_iw_add_readers(VALUE self, VALUE rreaders) {
1652
1648
  while (i-- > 0) {
1653
1649
  FrtIndexReader *ir;
1654
1650
  TypedData_Get_Struct(RARRAY_PTR(rreaders)[i], FrtIndexReader, &frb_index_reader_t, ir);
1651
+ FRT_REF(ir);
1655
1652
  irs[i] = ir;
1656
1653
  }
1657
1654
  frt_iw_add_readers(iw, irs, RARRAY_LEN(rreaders));
@@ -2157,7 +2154,6 @@ static VALUE frb_ir_init(VALUE self, VALUE rdir) {
2157
2154
  VALUE rfield_num_map = rb_hash_new();
2158
2155
  int ex_code = 0;
2159
2156
  const char *msg = NULL;
2160
-
2161
2157
  FRT_TRY
2162
2158
  if (TYPE(rdir) == T_ARRAY) {
2163
2159
  VALUE rdirs = rdir;
@@ -2170,7 +2166,6 @@ static VALUE frb_ir_init(VALUE self, VALUE rdir) {
2170
2166
  case T_DATA:
2171
2167
  if (CLASS_OF(rdir) == cIndexReader) {
2172
2168
  TypedData_Get_Struct(rdir, FrtIndexReader, &frb_index_reader_t, sub_readers[i]);
2173
- FRT_REF(sub_readers[i]);
2174
2169
  continue;
2175
2170
  } else if (RTEST(rb_obj_is_kind_of(rdir, cDirectory))) {
2176
2171
  store = DATA_PTR(rdir);
@@ -2185,7 +2180,6 @@ static VALUE frb_ir_init(VALUE self, VALUE rdir) {
2185
2180
  case T_STRING:
2186
2181
  frb_create_dir(rdir);
2187
2182
  store = frt_open_fs_store(rs2s(rdir));
2188
- FRT_DEREF(store);
2189
2183
  break;
2190
2184
  default:
2191
2185
  FRT_RAISE(FRT_ARG_ERROR, "%s isn't a valid directory "
@@ -2195,6 +2189,7 @@ static VALUE frb_ir_init(VALUE self, VALUE rdir) {
2195
2189
  break;
2196
2190
  }
2197
2191
  sub_readers[i] = frt_ir_open(NULL, store);
2192
+ FRT_DEREF(sub_readers[i]);
2198
2193
  }
2199
2194
  TypedData_Get_Struct(self, FrtIndexReader, &frb_index_reader_t, ir);
2200
2195
  ir = frt_mr_open(ir, sub_readers, reader_cnt);
@@ -2206,7 +2201,6 @@ static VALUE frb_ir_init(VALUE self, VALUE rdir) {
2206
2201
  case T_STRING:
2207
2202
  frb_create_dir(rdir);
2208
2203
  store = frt_open_fs_store(rs2s(rdir));
2209
- FRT_DEREF(store);
2210
2204
  break;
2211
2205
  default:
2212
2206
  FRT_RAISE(FRT_ARG_ERROR, "%s isn't a valid directory argument. "
@@ -3606,7 +3606,6 @@ static VALUE frb_sea_init(VALUE self, VALUE obj) {
3606
3606
  frb_create_dir(obj);
3607
3607
  store = frt_open_fs_store(rs2s(obj));
3608
3608
  ir = frt_ir_open(NULL, store);
3609
- FRT_DEREF(store);
3610
3609
  ir->rir = TypedData_Wrap_Struct(cIndexReader, &frb_index_reader_t, ir);
3611
3610
  } else {
3612
3611
  // Check_Type(obj, T_DATA);
@@ -3616,14 +3615,12 @@ static VALUE frb_sea_init(VALUE self, VALUE obj) {
3616
3615
  ir->rir = TypedData_Wrap_Struct(cIndexReader, &frb_index_reader_t, ir);
3617
3616
  } else if (rb_obj_is_kind_of(obj, cIndexReader) == Qtrue) {
3618
3617
  TypedData_Get_Struct(obj, FrtIndexReader, &frb_index_reader_t, ir);
3619
- ir->rir = obj;
3620
3618
  } else {
3621
3619
  rb_raise(rb_eArgError, "Unknown type for argument to IndexSearcher.new");
3622
3620
  }
3623
3621
  }
3624
3622
  TypedData_Get_Struct(self, FrtSearcher, &frb_index_searcher_t, sea);
3625
3623
  frt_isea_init(sea, ir);
3626
- ((FrtIndexSearcher *)sea)->close_ir = false;
3627
3624
  sea->rsea = self;
3628
3625
  return self;
3629
3626
  }
@@ -3710,7 +3707,7 @@ static VALUE frb_ms_init(int argc, VALUE *argv, VALUE self) {
3710
3707
  }
3711
3708
  }
3712
3709
  TypedData_Get_Struct(self, FrtSearcher, &frb_multi_searcher_t, sea);
3713
- frt_msea_init(sea, searchers, top, false);
3710
+ frt_msea_init(sea, searchers, top);
3714
3711
  sea->rsea = self;
3715
3712
  return self;
3716
3713
  }
@@ -185,10 +185,35 @@ static VALUE frb_lock_release(VALUE self) {
185
185
  *
186
186
  ****************************************************************************/
187
187
 
188
+ /*** FrbStore ****************************************************************/
189
+
190
+ static size_t frb_store_size(const void *p) {
191
+ return sizeof(FrtStore);
192
+ (void)p;
193
+ }
194
+
188
195
  void frb_dir_free(void *p) {
189
- FrtStore *store = (FrtStore *)p;
190
- frb_unwrap_locks(store);
191
- frt_store_deref(store);
196
+ frb_unwrap_locks((FrtStore *)p);
197
+ frt_store_close((FrtStore *)p);
198
+ }
199
+
200
+ const rb_data_type_t frb_store_t = {
201
+ .wrap_struct_name = "FrbStore",
202
+ .function = {
203
+ .dmark = NULL,
204
+ .dfree = frb_dir_free,
205
+ .dsize = frb_store_size,
206
+ .dcompact = NULL,
207
+ .reserved = {0},
208
+ },
209
+ .parent = NULL,
210
+ .data = NULL,
211
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
212
+ };
213
+
214
+ static VALUE frb_store_alloc(VALUE rclass) {
215
+ FrtStore *st = frt_store_alloc();
216
+ return TypedData_Wrap_Struct(rclass, &frb_store_t, st);
192
217
  }
193
218
 
194
219
  /*
@@ -208,7 +233,7 @@ static VALUE frb_dir_close(VALUE self) {
208
233
  ((struct RData *)(self))->dmark = NULL;
209
234
  ((struct RData *)(self))->dfree = NULL;
210
235
  frb_unwrap_locks(store);
211
- frt_store_deref(store);
236
+ frt_store_close(store);
212
237
  }
213
238
  return Qnil;
214
239
  }
@@ -308,32 +333,6 @@ static VALUE frb_dir_make_lock(VALUE self, VALUE rlock_name) {
308
333
  return rlock;
309
334
  }
310
335
 
311
- /*** FrbStore ****************************************************************/
312
-
313
- static size_t frb_store_size(const void *p) {
314
- return sizeof(FrtStore);
315
- (void)p;
316
- }
317
-
318
- const rb_data_type_t frb_store_t = {
319
- .wrap_struct_name = "FrbStore",
320
- .function = {
321
- .dmark = NULL,
322
- .dfree = frb_dir_free,
323
- .dsize = frb_store_size,
324
- .dcompact = NULL,
325
- .reserved = {0},
326
- },
327
- .parent = NULL,
328
- .data = NULL,
329
- .flags = RUBY_TYPED_FREE_IMMEDIATELY
330
- };
331
-
332
- static VALUE frb_store_alloc(VALUE rclass) {
333
- FrtStore *st = frt_store_alloc();
334
- return TypedData_Wrap_Struct(rclass, &frb_store_t, st);
335
- }
336
-
337
336
  /****************************************************************************
338
337
  *
339
338
  * RAMDirectory Methods
@@ -403,19 +402,18 @@ static VALUE frb_fsdir_new(int argc, VALUE *argv, VALUE klass) {
403
402
  frb_create_dir(rpath);
404
403
  }
405
404
  if (!rb_funcall(rb_cFile, id_is_directory, 1, rpath)) {
406
- rb_raise(rb_eIOError, "No directory <%s> found. Use :create => true"
407
- " to create one.", rs2s(rpath));
405
+ rb_raise(rb_eIOError, "No directory <%s> found. Use :create => true to create one.", rs2s(rpath));
408
406
  }
409
407
  store = frt_open_fs_store(rs2s(rpath));
410
408
  if (create) store->clear_all(store);
411
- if ((self = store->rstore) == Qnil) {
409
+ self = store->rstore;
410
+ if (self == Qnil || DATA_PTR(self) == NULL) {
412
411
  self = TypedData_Wrap_Struct(klass, &frb_store_t, store);
413
412
  store->rstore = self;
414
413
  rb_ivar_set(self, id_ref_cnt, INT2FIX(0));
415
414
  } else {
416
415
  int ref_cnt = FIX2INT(rb_ivar_get(self, id_ref_cnt)) + 1;
417
416
  rb_ivar_set(self, id_ref_cnt, INT2FIX(ref_cnt));
418
- FRT_DEREF(store);
419
417
  }
420
418
  return self;
421
419
  }
@@ -133,7 +133,7 @@ FrtToken *frt_tk_new(void) {
133
133
  /*****************************************************************************/
134
134
 
135
135
  void frt_ts_deref(FrtTokenStream *ts) {
136
- if (--ts->ref_cnt <= 0)
136
+ if (FRT_DEREF(ts) == 0)
137
137
  ts->destroy_i(ts);
138
138
  }
139
139
 
@@ -1089,7 +1089,7 @@ FrtTokenStream *frt_stem_filter_new(FrtTokenStream *sub_ts, const char *algorith
1089
1089
  /*****************************************************************************/
1090
1090
 
1091
1091
  void frt_a_deref(FrtAnalyzer *a) {
1092
- if (--a->ref_cnt <= 0)
1092
+ if (FRT_DEREF(a) == 0)
1093
1093
  a->destroy_i(a);
1094
1094
  }
1095
1095
 
@@ -33,15 +33,15 @@ typedef struct FrtTokenStream FrtTokenStream;
33
33
  struct FrtTokenStream {
34
34
  char *t; /* ptr used to scan text */
35
35
  char *text;
36
- int length;
36
+ int length;
37
37
  rb_encoding *encoding;
38
38
  FrtToken *(*next)(FrtTokenStream *ts);
39
39
  FrtTokenStream *(*reset)(FrtTokenStream *ts, char *text, rb_encoding *encoding);
40
40
  FrtTokenStream *(*clone_i)(FrtTokenStream *ts);
41
41
  void (*destroy_i)(FrtTokenStream *ts);
42
- int ref_cnt;
43
- VALUE rts;
44
- FrtToken token;
42
+ _Atomic unsigned int ref_cnt;
43
+ VALUE rts;
44
+ FrtToken token;
45
45
  };
46
46
 
47
47
  extern FrtTokenStream *frt_ts_new_i(size_t size);
@@ -184,7 +184,7 @@ typedef struct FrtAnalyzer {
184
184
  FrtTokenStream *current_ts;
185
185
  FrtTokenStream *(*get_ts)(struct FrtAnalyzer *a, ID field, char *text, rb_encoding *encoding);
186
186
  void (*destroy_i)(struct FrtAnalyzer *a);
187
- int ref_cnt;
187
+ _Atomic unsigned int ref_cnt;
188
188
  VALUE ranalyzer;
189
189
  } FrtAnalyzer;
190
190
 
@@ -19,7 +19,7 @@ FrtBitVector *frt_bv_new(void) {
19
19
  }
20
20
 
21
21
  void frt_bv_destroy(FrtBitVector *bv) {
22
- if (--(bv->ref_cnt) == 0) {
22
+ if (FRT_DEREF(bv) == 0) {
23
23
  free(bv->bits);
24
24
  free(bv);
25
25
  }
@@ -24,7 +24,7 @@ typedef struct FrtBitVector {
24
24
  int curr_bit;
25
25
 
26
26
  bool extends_as_ones : 1;
27
- int ref_cnt;
27
+ _Atomic unsigned int ref_cnt;
28
28
  VALUE rbv;
29
29
  } FrtBitVector;
30
30
 
@@ -1,7 +1,7 @@
1
1
  #include "frt_index.h"
2
2
  #include "frt_array.h"
3
3
 
4
- extern void frt_store_destroy(FrtStore *store);
4
+ extern void frt_store_close(FrtStore *store);
5
5
  extern FrtInStream *frt_is_new();
6
6
  extern FrtStore *frt_store_new();
7
7
 
@@ -16,45 +16,37 @@ typedef struct FileEntry {
16
16
  off_t length;
17
17
  } FileEntry;
18
18
 
19
- static void cmpd_touch(FrtStore *store, const char *file_name)
20
- {
19
+ static void cmpd_touch(FrtStore *store, const char *file_name) {
21
20
  store->dir.cmpd->store->touch(store->dir.cmpd->store, file_name);
22
21
  }
23
22
 
24
- static int cmpd_exists(FrtStore *store, const char *file_name)
25
- {
23
+ static int cmpd_exists(FrtStore *store, const char *file_name) {
26
24
  if (frt_h_get(store->dir.cmpd->entries, file_name) != NULL) {
27
25
  return true;
28
- }
29
- else {
26
+ } else {
30
27
  return false;
31
28
  }
32
29
  }
33
30
 
34
- static int cmpd_remove(FrtStore *store, const char *file_name)
35
- {
31
+ static int cmpd_remove(FrtStore *store, const char *file_name) {
36
32
  (void)store;
37
33
  (void)file_name;
38
34
  FRT_RAISE(FRT_UNSUPPORTED_ERROR, "%s", FRT_UNSUPPORTED_ERROR_MSG);
39
35
  return 0;
40
36
  }
41
37
 
42
- static void cmpd_rename(FrtStore *store, const char *from, const char *to)
43
- {
38
+ static void cmpd_rename(FrtStore *store, const char *from, const char *to) {
44
39
  (void)store;
45
40
  (void)from;
46
41
  (void)to;
47
42
  FRT_RAISE(FRT_UNSUPPORTED_ERROR, "%s", FRT_UNSUPPORTED_ERROR_MSG);
48
43
  }
49
44
 
50
- static int cmpd_count(FrtStore *store)
51
- {
45
+ static int cmpd_count(FrtStore *store) {
52
46
  return store->dir.cmpd->entries->size;
53
47
  }
54
48
 
55
- static void cmpd_each(FrtStore *store,
56
- void (*func)(const char *fname, void *arg), void *arg)
57
- {
49
+ static void cmpd_each(FrtStore *store, void (*func)(const char *fname, void *arg), void *arg) {
58
50
  FrtHash *ht = store->dir.cmpd->entries;
59
51
  int i;
60
52
  for (i = 0; i <= ht->mask; i++) {
@@ -65,15 +57,12 @@ static void cmpd_each(FrtStore *store,
65
57
  }
66
58
  }
67
59
 
68
-
69
- static void cmpd_clear(FrtStore *store)
70
- {
60
+ static void cmpd_clear(FrtStore *store) {
71
61
  (void)store;
72
62
  FRT_RAISE(FRT_UNSUPPORTED_ERROR, "%s", FRT_UNSUPPORTED_ERROR_MSG);
73
63
  }
74
64
 
75
- static void cmpd_close_i(FrtStore *store)
76
- {
65
+ static void cmpd_close_i(FrtStore *store) {
77
66
  FrtCompoundStore *cmpd = store->dir.cmpd;
78
67
  if (cmpd->stream == NULL) {
79
68
  FRT_RAISE(FRT_IO_ERROR, "Tried to close already closed compound store");
@@ -83,42 +72,37 @@ static void cmpd_close_i(FrtStore *store)
83
72
 
84
73
  frt_is_close(cmpd->stream);
85
74
  cmpd->stream = NULL;
75
+ frt_store_close(cmpd->store);
86
76
  free(store->dir.cmpd);
87
- frt_store_destroy(store);
88
77
  }
89
78
 
90
- static off_t cmpd_length(FrtStore *store, const char *file_name)
91
- {
79
+ static off_t cmpd_length(FrtStore *store, const char *file_name) {
92
80
  FileEntry *fe = (FileEntry *)frt_h_get(store->dir.cmpd->entries, file_name);
93
81
  if (fe != NULL) {
94
82
  return fe->length;
95
- }
96
- else {
83
+ } else {
97
84
  return 0;
98
85
  }
99
86
  }
100
87
 
101
- static void cmpdi_seek_i(FrtInStream *is, off_t pos)
102
- {
88
+ static void cmpdi_seek_i(FrtInStream *is, off_t pos) {
103
89
  (void)is;
104
90
  (void)pos;
105
91
  }
106
92
 
107
- static void cmpdi_close_i(FrtInStream *is)
108
- {
93
+ static void cmpdi_close_i(FrtInStream *is) {
94
+ frt_is_close(is->d.cis->sub);
109
95
  free(is->d.cis);
110
96
  }
111
97
 
112
- static off_t cmpdi_length_i(FrtInStream *is)
113
- {
98
+ static off_t cmpdi_length_i(FrtInStream *is) {
114
99
  return (is->d.cis->length);
115
100
  }
116
101
 
117
102
  /*
118
103
  * raises: FRT_EOF_ERROR
119
104
  */
120
- static void cmpdi_read_i(FrtInStream *is, frt_uchar *b, int len)
121
- {
105
+ static void cmpdi_read_i(FrtInStream *is, frt_uchar *b, int len) {
122
106
  FrtCompoundInStream *cis = is->d.cis;
123
107
  off_t start = frt_is_pos(is);
124
108
 
@@ -139,12 +123,12 @@ static const struct FrtInStreamMethods CMPD_IN_STREAM_METHODS = {
139
123
  cmpdi_close_i
140
124
  };
141
125
 
142
- static FrtInStream *cmpd_create_input(FrtInStream *sub_is, off_t offset, off_t length)
143
- {
126
+ static FrtInStream *cmpd_create_input(FrtInStream *sub_is, off_t offset, off_t length) {
144
127
  FrtInStream *is = frt_is_new();
145
128
  FrtCompoundInStream *cis = FRT_ALLOC(FrtCompoundInStream);
146
129
 
147
130
  cis->sub = sub_is;
131
+ FRT_REF(sub_is);
148
132
  cis->offset = offset;
149
133
  cis->length = length;
150
134
  is->d.cis = cis;
@@ -153,8 +137,7 @@ static FrtInStream *cmpd_create_input(FrtInStream *sub_is, off_t offset, off_t l
153
137
  return is;
154
138
  }
155
139
 
156
- static FrtInStream *cmpd_open_input(FrtStore *store, const char *file_name)
157
- {
140
+ static FrtInStream *cmpd_open_input(FrtStore *store, const char *file_name) {
158
141
  FileEntry *entry;
159
142
  FrtCompoundStore *cmpd = store->dir.cmpd;
160
143
  FrtInStream *is;
@@ -178,30 +161,26 @@ static FrtInStream *cmpd_open_input(FrtStore *store, const char *file_name)
178
161
  return is;
179
162
  }
180
163
 
181
- static FrtOutStream *cmpd_new_output(FrtStore *store, const char *file_name)
182
- {
164
+ static FrtOutStream *cmpd_new_output(FrtStore *store, const char *file_name) {
183
165
  (void)store;
184
166
  (void)file_name;
185
167
  FRT_RAISE(FRT_UNSUPPORTED_ERROR, "%s", FRT_UNSUPPORTED_ERROR_MSG);
186
168
  return NULL;
187
169
  }
188
170
 
189
- static FrtLock *cmpd_open_lock_i(FrtStore *store, const char *lock_name)
190
- {
171
+ static FrtLock *cmpd_open_lock_i(FrtStore *store, const char *lock_name) {
191
172
  (void)store;
192
173
  (void)lock_name;
193
174
  FRT_RAISE(FRT_UNSUPPORTED_ERROR, "%s", FRT_UNSUPPORTED_ERROR_MSG);
194
175
  return NULL;
195
176
  }
196
177
 
197
- static void cmpd_close_lock_i(FrtLock *lock)
198
- {
178
+ static void cmpd_close_lock_i(FrtLock *lock) {
199
179
  (void)lock;
200
180
  FRT_RAISE(FRT_UNSUPPORTED_ERROR, "%s", FRT_UNSUPPORTED_ERROR_MSG);
201
181
  }
202
182
 
203
- FrtStore *frt_open_cmpd_store(FrtStore *store, const char *name)
204
- {
183
+ FrtStore *frt_open_cmpd_store(FrtStore *store, const char *name) {
205
184
  int count, i;
206
185
  off_t offset;
207
186
  char *fname;
@@ -214,6 +193,7 @@ FrtStore *frt_open_cmpd_store(FrtStore *store, const char *name)
214
193
  cmpd = FRT_ALLOC_AND_ZERO(FrtCompoundStore);
215
194
 
216
195
  cmpd->store = store;
196
+ FRT_REF(store);
217
197
  cmpd->name = name;
218
198
  cmpd->entries = frt_h_new_str(&free, &free);
219
199
  is = cmpd->stream = store->open_input(store, cmpd->name);
@@ -235,6 +215,7 @@ FrtStore *frt_open_cmpd_store(FrtStore *store, const char *name)
235
215
  frt_h_set(cmpd->entries, fname, entry);
236
216
  }
237
217
  FRT_XCATCHALL
218
+ frt_store_close(store);
238
219
  if (is) frt_is_close(is);
239
220
  if (cmpd->entries) frt_h_destroy(cmpd->entries);
240
221
  free(cmpd);
@@ -270,18 +251,17 @@ FrtStore *frt_open_cmpd_store(FrtStore *store, const char *name)
270
251
  *
271
252
  ****************************************************************************/
272
253
 
273
- FrtCompoundWriter *frt_open_cw(FrtStore *store, char *name)
274
- {
254
+ FrtCompoundWriter *frt_open_cw(FrtStore *store, char *name) {
275
255
  FrtCompoundWriter *cw = FRT_ALLOC(FrtCompoundWriter);
276
256
  cw->store = store;
257
+ FRT_REF(store);
277
258
  cw->name = name;
278
259
  cw->ids = frt_hs_new_str(&free);
279
260
  cw->file_entries = frt_ary_new_type_capa(FrtCWFileEntry, FRT_CW_INIT_CAPA);
280
261
  return cw;
281
262
  }
282
263
 
283
- void frt_cw_add_file(FrtCompoundWriter *cw, char *id)
284
- {
264
+ void frt_cw_add_file(FrtCompoundWriter *cw, char *id) {
285
265
  id = frt_estrdup(id);
286
266
  if (frt_hs_add(cw->ids, id) != FRT_HASH_KEY_DOES_NOT_EXIST) {
287
267
  FRT_RAISE(FRT_IO_ERROR, "Tried to add file \"%s\" which has already been "
@@ -292,8 +272,7 @@ void frt_cw_add_file(FrtCompoundWriter *cw, char *id)
292
272
  frt_ary_last(cw->file_entries).name = id;
293
273
  }
294
274
 
295
- static void cw_copy_file(FrtCompoundWriter *cw, FrtCWFileEntry *src, FrtOutStream *os)
296
- {
275
+ static void cw_copy_file(FrtCompoundWriter *cw, FrtCWFileEntry *src, FrtOutStream *os) {
297
276
  off_t start_ptr = frt_os_pos(os);
298
277
  off_t end_ptr;
299
278
  off_t remainder, length, len;
@@ -329,8 +308,7 @@ static void cw_copy_file(FrtCompoundWriter *cw, FrtCWFileEntry *src, FrtOutStrea
329
308
  frt_is_close(is);
330
309
  }
331
310
 
332
- void frt_cw_close(FrtCompoundWriter *cw, FrtDeleter *dlr)
333
- {
311
+ void frt_cw_close(FrtCompoundWriter *cw, FrtDeleter *dlr) {
334
312
  FrtOutStream *os = NULL;
335
313
  int i;
336
314
 
@@ -366,12 +344,9 @@ void frt_cw_close(FrtCompoundWriter *cw, FrtDeleter *dlr)
366
344
  frt_os_seek(os, cw->file_entries[i].dir_offset);
367
345
  frt_os_write_u64(os, cw->file_entries[i].data_offset);
368
346
  }
369
-
370
- if (os) {
371
- frt_os_close(os);
372
- }
373
-
347
+ frt_os_close(os);
374
348
  frt_hs_destroy(cw->ids);
375
349
  frt_ary_free(cw->file_entries);
350
+ frt_store_close(cw->store);
376
351
  free(cw);
377
352
  }
@@ -33,6 +33,7 @@ static frt_thread_once_t exception_stack_key_once = FRT_THREAD_ONCE_INIT;
33
33
 
34
34
  static void exception_stack_alloc(void) {
35
35
  frt_thread_key_create(&exception_stack_key, NULL);
36
+ frt_thread_setspecific(exception_stack_key, NULL);
36
37
  }
37
38
 
38
39
  void frt_xpush_context(frt_xcontext_t *context) {
@@ -14,9 +14,7 @@ void frt_filt_destroy_i(FrtFilter *filt) {
14
14
  }
15
15
 
16
16
  void frt_filt_deref(FrtFilter *filt) {
17
- if (--(filt->ref_cnt) == 0) {
18
- filt->destroy_i(filt);
19
- }
17
+ if (FRT_DEREF(filt) == 0) filt->destroy_i(filt);
20
18
  }
21
19
 
22
20
  FrtBitVector *frt_filt_get_bv(FrtFilter *filt, FrtIndexReader *ir) {
@@ -97,7 +95,7 @@ static FrtBitVector *qfilt_get_bv_i(FrtFilter *filt, FrtIndexReader *ir) {
97
95
  scorer->destroy(scorer);
98
96
  }
99
97
  weight->destroy(weight);
100
- free(sea);
98
+ frt_searcher_close(sea);
101
99
  return bv;
102
100
  }
103
101