isomorfeus-ferret 0.12.7 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +101 -19
  3. data/README.md +54 -1
  4. data/ext/isomorfeus_ferret_ext/bm_bitvector.c +22 -30
  5. data/ext/isomorfeus_ferret_ext/bm_hash.c +6 -12
  6. data/ext/isomorfeus_ferret_ext/bm_micro_string.c +3 -6
  7. data/ext/isomorfeus_ferret_ext/bm_store.c +11 -22
  8. data/ext/isomorfeus_ferret_ext/brotli_common_dictionary.c +1 -1
  9. data/ext/isomorfeus_ferret_ext/brotli_dec_decode.c +1 -1
  10. data/ext/isomorfeus_ferret_ext/bzip_blocksort.c +1094 -0
  11. data/ext/isomorfeus_ferret_ext/bzip_huffman.c +205 -0
  12. data/ext/isomorfeus_ferret_ext/bzlib.c +1572 -0
  13. data/ext/isomorfeus_ferret_ext/bzlib.h +282 -0
  14. data/ext/isomorfeus_ferret_ext/bzlib_compress.c +672 -0
  15. data/ext/isomorfeus_ferret_ext/bzlib_crctable.c +104 -0
  16. data/ext/isomorfeus_ferret_ext/bzlib_decompress.c +652 -0
  17. data/ext/isomorfeus_ferret_ext/bzlib_private.h +509 -0
  18. data/ext/isomorfeus_ferret_ext/bzlib_randtable.c +84 -0
  19. data/ext/isomorfeus_ferret_ext/fio_tmpfile.h +53 -53
  20. data/ext/isomorfeus_ferret_ext/frb_analysis.c +785 -1192
  21. data/ext/isomorfeus_ferret_ext/frb_index.c +492 -474
  22. data/ext/isomorfeus_ferret_ext/frb_qparser.c +48 -60
  23. data/ext/isomorfeus_ferret_ext/frb_search.c +1520 -1002
  24. data/ext/isomorfeus_ferret_ext/frb_store.c +96 -96
  25. data/ext/isomorfeus_ferret_ext/frb_threading.h +0 -1
  26. data/ext/isomorfeus_ferret_ext/frb_utils.c +147 -196
  27. data/ext/isomorfeus_ferret_ext/frt_analysis.c +695 -1090
  28. data/ext/isomorfeus_ferret_ext/frt_analysis.h +174 -170
  29. data/ext/isomorfeus_ferret_ext/frt_array.c +2 -4
  30. data/ext/isomorfeus_ferret_ext/frt_bitvector.c +9 -16
  31. data/ext/isomorfeus_ferret_ext/frt_bitvector.h +32 -81
  32. data/ext/isomorfeus_ferret_ext/frt_document.c +15 -20
  33. data/ext/isomorfeus_ferret_ext/frt_document.h +10 -10
  34. data/ext/isomorfeus_ferret_ext/frt_except.c +5 -12
  35. data/ext/isomorfeus_ferret_ext/frt_field_index.c +3 -3
  36. data/ext/isomorfeus_ferret_ext/frt_field_index.h +6 -7
  37. data/ext/isomorfeus_ferret_ext/frt_filter.c +35 -46
  38. data/ext/isomorfeus_ferret_ext/frt_fs_store.c +1 -0
  39. data/ext/isomorfeus_ferret_ext/frt_global.c +105 -63
  40. data/ext/isomorfeus_ferret_ext/frt_global.h +7 -3
  41. data/ext/isomorfeus_ferret_ext/frt_hash.c +1 -2
  42. data/ext/isomorfeus_ferret_ext/frt_ind.c +32 -35
  43. data/ext/isomorfeus_ferret_ext/frt_ind.h +9 -9
  44. data/ext/isomorfeus_ferret_ext/frt_index.c +580 -399
  45. data/ext/isomorfeus_ferret_ext/frt_index.h +272 -291
  46. data/ext/isomorfeus_ferret_ext/frt_mempool.c +1 -2
  47. data/ext/isomorfeus_ferret_ext/frt_multimapper.c +4 -7
  48. data/ext/isomorfeus_ferret_ext/frt_q_boolean.c +67 -91
  49. data/ext/isomorfeus_ferret_ext/frt_q_const_score.c +35 -38
  50. data/ext/isomorfeus_ferret_ext/frt_q_filtered_query.c +53 -72
  51. data/ext/isomorfeus_ferret_ext/frt_q_fuzzy.c +25 -32
  52. data/ext/isomorfeus_ferret_ext/frt_q_match_all.c +21 -23
  53. data/ext/isomorfeus_ferret_ext/frt_q_multi_term.c +66 -103
  54. data/ext/isomorfeus_ferret_ext/frt_q_parser.c +207 -195
  55. data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +20 -16
  56. data/ext/isomorfeus_ferret_ext/frt_q_prefix.c +17 -14
  57. data/ext/isomorfeus_ferret_ext/frt_q_range.c +102 -131
  58. data/ext/isomorfeus_ferret_ext/frt_q_span.c +179 -178
  59. data/ext/isomorfeus_ferret_ext/frt_q_term.c +47 -60
  60. data/ext/isomorfeus_ferret_ext/frt_q_wildcard.c +18 -16
  61. data/ext/isomorfeus_ferret_ext/frt_ram_store.c +45 -84
  62. data/ext/isomorfeus_ferret_ext/frt_search.c +105 -146
  63. data/ext/isomorfeus_ferret_ext/frt_search.h +331 -320
  64. data/ext/isomorfeus_ferret_ext/frt_similarity.c +5 -13
  65. data/ext/isomorfeus_ferret_ext/frt_similarity.h +7 -12
  66. data/ext/isomorfeus_ferret_ext/frt_sort.c +105 -149
  67. data/ext/isomorfeus_ferret_ext/frt_store.c +13 -7
  68. data/ext/isomorfeus_ferret_ext/frt_store.h +10 -2
  69. data/ext/isomorfeus_ferret_ext/frt_threading.h +0 -1
  70. data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.c +21 -109
  71. data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.h +2 -32
  72. data/ext/isomorfeus_ferret_ext/lz4.c +2495 -0
  73. data/ext/isomorfeus_ferret_ext/lz4.h +774 -0
  74. data/ext/isomorfeus_ferret_ext/lz4frame.c +1899 -0
  75. data/ext/isomorfeus_ferret_ext/lz4frame.h +623 -0
  76. data/ext/isomorfeus_ferret_ext/lz4hc.c +1615 -0
  77. data/ext/isomorfeus_ferret_ext/lz4hc.h +413 -0
  78. data/ext/isomorfeus_ferret_ext/lz4xxhash.c +1030 -0
  79. data/ext/isomorfeus_ferret_ext/lz4xxhash.h +328 -0
  80. data/ext/isomorfeus_ferret_ext/stem_modules.h +0 -86
  81. data/ext/isomorfeus_ferret_ext/test.c +1 -2
  82. data/ext/isomorfeus_ferret_ext/test_1710.c +11 -12
  83. data/ext/isomorfeus_ferret_ext/test_analysis.c +590 -583
  84. data/ext/isomorfeus_ferret_ext/test_compound_io.c +1 -1
  85. data/ext/isomorfeus_ferret_ext/test_document.c +19 -15
  86. data/ext/isomorfeus_ferret_ext/test_except.c +1 -2
  87. data/ext/isomorfeus_ferret_ext/test_fields.c +59 -60
  88. data/ext/isomorfeus_ferret_ext/test_file_deleter.c +10 -27
  89. data/ext/isomorfeus_ferret_ext/test_filter.c +11 -8
  90. data/ext/isomorfeus_ferret_ext/test_hash.c +2 -2
  91. data/ext/isomorfeus_ferret_ext/test_hashset.c +1 -1
  92. data/ext/isomorfeus_ferret_ext/test_highlighter.c +15 -11
  93. data/ext/isomorfeus_ferret_ext/test_index.c +372 -365
  94. data/ext/isomorfeus_ferret_ext/test_q_const_score.c +5 -3
  95. data/ext/isomorfeus_ferret_ext/test_q_filtered.c +5 -3
  96. data/ext/isomorfeus_ferret_ext/test_q_fuzzy.c +13 -10
  97. data/ext/isomorfeus_ferret_ext/test_q_parser.c +45 -7
  98. data/ext/isomorfeus_ferret_ext/test_q_span.c +15 -12
  99. data/ext/isomorfeus_ferret_ext/test_ram_store.c +3 -3
  100. data/ext/isomorfeus_ferret_ext/test_search.c +60 -62
  101. data/ext/isomorfeus_ferret_ext/test_segments.c +5 -4
  102. data/ext/isomorfeus_ferret_ext/test_sort.c +17 -14
  103. data/ext/isomorfeus_ferret_ext/test_store.c +2 -0
  104. data/ext/isomorfeus_ferret_ext/test_term.c +3 -1
  105. data/ext/isomorfeus_ferret_ext/test_term_vectors.c +9 -10
  106. data/ext/isomorfeus_ferret_ext/test_test.c +1 -2
  107. data/ext/isomorfeus_ferret_ext/test_threading.c +9 -10
  108. data/ext/isomorfeus_ferret_ext/testhelper.c +1 -2
  109. data/lib/isomorfeus/ferret/version.rb +1 -1
  110. metadata +27 -57
  111. data/ext/isomorfeus_ferret_ext/email.rl +0 -21
  112. data/ext/isomorfeus_ferret_ext/frt_scanner.c +0 -900
  113. data/ext/isomorfeus_ferret_ext/frt_scanner.h +0 -28
  114. data/ext/isomorfeus_ferret_ext/frt_scanner_mb.c +0 -6706
  115. data/ext/isomorfeus_ferret_ext/frt_scanner_utf8.c +0 -4420
  116. data/ext/isomorfeus_ferret_ext/scanner.h +0 -28
  117. data/ext/isomorfeus_ferret_ext/scanner.in +0 -43
  118. data/ext/isomorfeus_ferret_ext/scanner.rl +0 -84
  119. data/ext/isomorfeus_ferret_ext/scanner_mb.rl +0 -200
  120. data/ext/isomorfeus_ferret_ext/scanner_utf8.rl +0 -85
  121. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_basque.c +0 -1167
  122. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_basque.h +0 -6
  123. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_catalan.c +0 -1433
  124. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_catalan.h +0 -6
  125. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.c +0 -301
  126. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.h +0 -6
  127. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.c +0 -590
  128. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.h +0 -6
  129. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.c +0 -1049
  130. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.h +0 -6
  131. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.c +0 -705
  132. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.h +0 -6
  133. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.c +0 -1239
  134. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.h +0 -6
  135. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.c +0 -477
  136. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.h +0 -6
  137. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.c +0 -1217
  138. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.h +0 -7
  139. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_indonesian.c +0 -394
  140. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_indonesian.h +0 -6
  141. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_irish.c +0 -457
  142. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_irish.h +0 -6
  143. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.c +0 -1009
  144. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.h +0 -6
  145. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.c +0 -259
  146. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.h +0 -6
  147. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.c +0 -704
  148. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.h +0 -6
  149. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.c +0 -948
  150. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.h +0 -6
  151. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.c +0 -1028
  152. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.h +0 -6
  153. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.c +0 -275
  154. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.h +0 -6
  155. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_hungarian.c +0 -849
  156. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_hungarian.h +0 -6
  157. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.c +0 -952
  158. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.h +0 -6
  159. data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.c +0 -669
  160. data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.h +0 -6
  161. data/ext/isomorfeus_ferret_ext/stem_modules.txt +0 -63
  162. data/ext/isomorfeus_ferret_ext/uchar-ucs4.rl +0 -1854
  163. data/ext/isomorfeus_ferret_ext/uchar-utf8.rl +0 -1999
  164. data/ext/isomorfeus_ferret_ext/url.rl +0 -27
@@ -2,6 +2,8 @@
2
2
  #include "isomorfeus_ferret.h"
3
3
  #include <time.h>
4
4
 
5
+ #undef rename
6
+
5
7
  static ID id_ref_cnt;
6
8
  VALUE cLock;
7
9
  VALUE cLockError;
@@ -10,41 +12,52 @@ VALUE cRAMDirectory;
10
12
  VALUE cFSDirectory;
11
13
 
12
14
  /****************************************************************************
13
- *
14
15
  * Lock Methods
15
- *
16
16
  ****************************************************************************/
17
17
 
18
- void
19
- frb_unwrap_locks(FrtStore *store)
20
- {
18
+ void frb_unwrap_locks(FrtStore *store) {
21
19
  FrtHashSetEntry *hse = store->locks->first;
22
20
  for (; hse; hse = hse->next) {
23
- void *lock = hse->elem;
24
- VALUE rlock = object_get(lock);
25
- if (rlock != Qnil) {
26
- object_del(lock);
27
- Frt_Unwrap_Struct(rlock);
21
+ FrtLock *lock = hse->elem;
22
+ if (lock->rlock != Qnil && lock->rlock != 0) {
23
+ ((struct RData *)(lock->rlock))->data = NULL;
24
+ ((struct RData *)(lock->rlock))->dmark = NULL;
25
+ ((struct RData *)(lock->rlock))->dfree = NULL;
28
26
  }
29
27
  }
30
28
  }
31
29
 
32
- void
33
- frb_lock_free(void *p)
34
- {
30
+ void frb_lock_free(void *p) {
35
31
  FrtLock *lock = (FrtLock *)p;
36
- object_del(p);
37
32
  frt_close_lock(lock);
38
33
  }
39
34
 
40
- void
41
- frb_lock_mark(void *p)
42
- {
35
+ void frb_lock_mark(void *p) {
43
36
  FrtLock *lock = (FrtLock *)p;
44
- frb_gc_mark(lock->store);
37
+ if (lock->store->rstore)
38
+ rb_gc_mark(lock->store->rstore);
45
39
  }
46
40
 
47
- #define GET_LOCK(lock, self) Data_Get_Struct(self, FrtLock, lock)
41
+ static size_t frb_lock_size(const void *p) {
42
+ return sizeof(FrtLock);
43
+ (void)p;
44
+ }
45
+
46
+ const rb_data_type_t frb_lock_t = {
47
+ .wrap_struct_name = "FrbLock",
48
+ .function = {
49
+ .dmark = frb_lock_mark,
50
+ .dfree = frb_lock_free,
51
+ .dsize = frb_lock_size,
52
+ .dcompact = NULL,
53
+ .reserved = {0},
54
+ },
55
+ .parent = NULL,
56
+ .data = NULL,
57
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
58
+ };
59
+
60
+ #define GET_LOCK(lock, self) TypedData_Get_Struct(self, FrtLock, &frb_lock_t, lock)
48
61
 
49
62
  /*
50
63
  * call-seq:
@@ -64,9 +77,7 @@ frb_lock_mark(void *p)
64
77
  * return:: true if lock was successfully obtained. Raises a
65
78
  * Lock::LockError otherwise.
66
79
  */
67
- static VALUE
68
- frb_lock_obtain(int argc, VALUE *argv, VALUE self)
69
- {
80
+ static VALUE frb_lock_obtain(int argc, VALUE *argv, VALUE self) {
70
81
  VALUE rtimeout;
71
82
  int timeout = 1;
72
83
  FrtLock *lock;
@@ -110,9 +121,7 @@ frb_lock_obtain(int argc, VALUE *argv, VALUE self)
110
121
  * return:: true if lock was successfully obtained. Raises a
111
122
  * Lock::LockError otherwise.
112
123
  */
113
- static VALUE
114
- frb_lock_while_locked(int argc, VALUE *argv, VALUE self)
115
- {
124
+ static VALUE frb_lock_while_locked(int argc, VALUE *argv, VALUE self) {
116
125
  VALUE rtimeout;
117
126
  int timeout = 1;
118
127
  FrtLock *lock;
@@ -150,9 +159,7 @@ frb_lock_while_locked(int argc, VALUE *argv, VALUE self)
150
159
  *
151
160
  * Returns true if the lock has been obtained.
152
161
  */
153
- static VALUE
154
- frb_lock_is_locked(VALUE self)
155
- {
162
+ static VALUE frb_lock_is_locked(VALUE self) {
156
163
  FrtLock *lock;
157
164
  GET_LOCK(lock, self);
158
165
  return lock->is_locked(lock) ? Qtrue : Qfalse;
@@ -165,9 +172,7 @@ frb_lock_is_locked(VALUE self)
165
172
  * Release the lock. This should only be called by the process which obtains
166
173
  * the lock.
167
174
  */
168
- static VALUE
169
- frb_lock_release(VALUE self)
170
- {
175
+ static VALUE frb_lock_release(VALUE self) {
171
176
  FrtLock *lock;
172
177
  GET_LOCK(lock, self);
173
178
  lock->release(lock);
@@ -180,11 +185,9 @@ frb_lock_release(VALUE self)
180
185
  *
181
186
  ****************************************************************************/
182
187
 
183
- void
184
- frb_dir_free(FrtStore *store)
185
- {
188
+ void frb_dir_free(void *p) {
189
+ FrtStore *store = (FrtStore *)p;
186
190
  frb_unwrap_locks(store);
187
- object_del(store);
188
191
  frt_store_deref(store);
189
192
  }
190
193
 
@@ -196,15 +199,14 @@ frb_dir_free(FrtStore *store)
196
199
  * Although the garbage collector will currently handle this for you, this
197
200
  * behaviour may change in future.
198
201
  */
199
- static VALUE
200
- frb_dir_close(VALUE self)
201
- {
202
+ static VALUE frb_dir_close(VALUE self) {
202
203
  FrtStore *store = DATA_PTR(self);
203
204
  int ref_cnt = FIX2INT(rb_ivar_get(self, id_ref_cnt)) - 1;
204
205
  rb_ivar_set(self, id_ref_cnt, INT2FIX(ref_cnt));
205
206
  if (ref_cnt < 0) {
206
- Frt_Unwrap_Struct(self);
207
- object_del(store);
207
+ ((struct RData *)(self))->data = NULL;
208
+ ((struct RData *)(self))->dmark = NULL;
209
+ ((struct RData *)(self))->dfree = NULL;
208
210
  frb_unwrap_locks(store);
209
211
  frt_store_deref(store);
210
212
  }
@@ -217,9 +219,7 @@ frb_dir_close(VALUE self)
217
219
  *
218
220
  * Return true if a file with the name +file_name+ exists in the directory.
219
221
  */
220
- static VALUE
221
- frb_dir_exists(VALUE self, VALUE rfname)
222
- {
222
+ static VALUE frb_dir_exists(VALUE self, VALUE rfname) {
223
223
  FrtStore *store = DATA_PTR(self);
224
224
  StringValue(rfname);
225
225
  return store->exists(store, rs2s(rfname)) ? Qtrue : Qfalse;
@@ -231,9 +231,7 @@ frb_dir_exists(VALUE self, VALUE rfname)
231
231
  *
232
232
  * Create an empty file in the directory with the name +file_name+.
233
233
  */
234
- static VALUE
235
- frb_dir_touch(VALUE self, VALUE rfname)
236
- {
234
+ static VALUE frb_dir_touch(VALUE self, VALUE rfname) {
237
235
  FrtStore *store = DATA_PTR(self);
238
236
  StringValue(rfname);
239
237
  store->touch(store, rs2s(rfname));
@@ -246,9 +244,7 @@ frb_dir_touch(VALUE self, VALUE rfname)
246
244
  *
247
245
  * Remove file +file_name+ from the directory. Returns true if successful.
248
246
  */
249
- static VALUE
250
- frb_dir_delete(VALUE self, VALUE rfname)
251
- {
247
+ static VALUE frb_dir_delete(VALUE self, VALUE rfname) {
252
248
  FrtStore *store = DATA_PTR(self);
253
249
  StringValue(rfname);
254
250
  return (store->remove(store, rs2s(rfname)) == 0) ? Qtrue : Qfalse;
@@ -260,9 +256,7 @@ frb_dir_delete(VALUE self, VALUE rfname)
260
256
  *
261
257
  * Return a count of the number of files in the directory.
262
258
  */
263
- static VALUE
264
- frb_dir_file_count(VALUE self)
265
- {
259
+ static VALUE frb_dir_file_count(VALUE self) {
266
260
  FrtStore *store = DATA_PTR(self);
267
261
  return INT2FIX(store->count(store));
268
262
  }
@@ -273,9 +267,7 @@ frb_dir_file_count(VALUE self)
273
267
  *
274
268
  * Delete all files in the directory. It gives you a clean slate.
275
269
  */
276
- static VALUE
277
- frb_dir_refresh(VALUE self)
278
- {
270
+ static VALUE frb_dir_refresh(VALUE self) {
279
271
  FrtStore *store = DATA_PTR(self);
280
272
  store->clear_all(store);
281
273
  return self;
@@ -288,9 +280,7 @@ frb_dir_refresh(VALUE self)
288
280
  * Rename a file from +from+ to +to+. An error will be raised if the file
289
281
  * doesn't exist or there is some other type of IOError.
290
282
  */
291
- static VALUE
292
- frb_dir_rename(VALUE self, VALUE rfrom, VALUE rto)
293
- {
283
+ static VALUE frb_dir_rename(VALUE self, VALUE rfrom, VALUE rto) {
294
284
  FrtStore *store = DATA_PTR(self);
295
285
  StringValue(rfrom);
296
286
  StringValue(rto);
@@ -307,19 +297,43 @@ frb_dir_rename(VALUE self, VALUE rfrom, VALUE rto)
307
297
  * should avoid using files with a .lck extension as this extension is
308
298
  * reserved for lock files
309
299
  */
310
- static VALUE
311
- frb_dir_make_lock(VALUE self, VALUE rlock_name)
312
- {
300
+ static VALUE frb_dir_make_lock(VALUE self, VALUE rlock_name) {
313
301
  VALUE rlock;
314
302
  FrtLock *lock;
315
303
  FrtStore *store = DATA_PTR(self);
316
304
  StringValue(rlock_name);
317
305
  lock = frt_open_lock(store, rs2s(rlock_name));
318
- rlock = Data_Wrap_Struct(cLock, &frb_lock_mark, &frb_lock_free, lock);
319
- object_add(lock, rlock);
306
+ rlock = TypedData_Wrap_Struct(cLock, &frb_lock_t, lock);
307
+ lock->rlock = rlock;
320
308
  return rlock;
321
309
  }
322
310
 
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
+
323
337
  /****************************************************************************
324
338
  *
325
339
  * RAMDirectory Methods
@@ -338,22 +352,21 @@ frb_dir_make_lock(VALUE self, VALUE rlock_name)
338
352
  *
339
353
  * dir:: Directory to load into memory
340
354
  */
341
- static VALUE
342
- frb_ramdir_init(int argc, VALUE *argv, VALUE self)
343
- {
355
+
356
+ static VALUE frb_ramdir_init(int argc, VALUE *argv, VALUE self) {
344
357
  VALUE rdir;
345
358
  FrtStore *store;
359
+ TypedData_Get_Struct(self, FrtStore, &frb_store_t, store);
346
360
  switch (rb_scan_args(argc, argv, "01", &rdir)) {
347
361
  case 1: {
348
362
  FrtStore *ostore;
349
- Data_Get_Struct(rdir, FrtStore, ostore);
350
- store = frt_open_ram_store_and_copy(ostore, false);
363
+ TypedData_Get_Struct(rdir, FrtStore, &frb_store_t, ostore);
364
+ frt_open_ram_store_and_copy(store, ostore, false);
351
365
  break;
352
366
  }
353
- default: store = frt_open_ram_store();
367
+ default: frt_open_ram_store(store);
354
368
  }
355
- Frt_Wrap_Struct(self, NULL, &frb_dir_free, store);
356
- object_add(store, self);
369
+ store->rstore = self;
357
370
  rb_ivar_set(self, id_ref_cnt, INT2FIX(0));
358
371
  return self;
359
372
  }
@@ -378,9 +391,7 @@ frb_ramdir_init(int argc, VALUE *argv, VALUE self)
378
391
  * create:: set to true if you want any existing files in the directory to be
379
392
  * deleted
380
393
  */
381
- static VALUE
382
- frb_fsdir_new(int argc, VALUE *argv, VALUE klass)
383
- {
394
+ static VALUE frb_fsdir_new(int argc, VALUE *argv, VALUE klass) {
384
395
  VALUE self, rpath, rcreate;
385
396
  FrtStore *store;
386
397
  bool create;
@@ -397,12 +408,11 @@ frb_fsdir_new(int argc, VALUE *argv, VALUE klass)
397
408
  }
398
409
  store = frt_open_fs_store(rs2s(rpath));
399
410
  if (create) store->clear_all(store);
400
- if ((self = object_get(store)) == Qnil) {
401
- self = Data_Wrap_Struct(klass, NULL, &frb_dir_free, store);
402
- object_add(store, self);
411
+ if ((self = store->rstore) == Qnil) {
412
+ self = TypedData_Wrap_Struct(klass, &frb_store_t, store);
413
+ store->rstore = self;
403
414
  rb_ivar_set(self, id_ref_cnt, INT2FIX(0));
404
- }
405
- else {
415
+ } else {
406
416
  int ref_cnt = FIX2INT(rb_ivar_get(self, id_ref_cnt)) + 1;
407
417
  rb_ivar_set(self, id_ref_cnt, INT2FIX(ref_cnt));
408
418
  FRT_DEREF(store);
@@ -434,9 +444,7 @@ frb_fsdir_new(int argc, VALUE *argv, VALUE klass)
434
444
  * called _open_input_ If there is a risk of simultaneous modifications of
435
445
  * the files then locks should be used. See Lock to find out how.
436
446
  */
437
- void
438
- Init_Directory(void)
439
- {
447
+ void Init_Directory(void) {
440
448
  cDirectory = rb_define_class_under(mStore, "Directory", rb_cObject);
441
449
  rb_define_const(cDirectory, "LOCK_PREFIX", rb_str_new2(FRT_LOCK_PREFIX));
442
450
  rb_define_method(cDirectory, "close", frb_dir_close, 0);
@@ -472,9 +480,7 @@ Init_Directory(void)
472
480
  * ... # Do your file modifications # ...
473
481
  * end
474
482
  */
475
- void
476
- Init_Lock(void)
477
- {
483
+ void Init_Lock(void) {
478
484
  cLock = rb_define_class_under(mStore, "Lock", rb_cObject);
479
485
  rb_define_method(cLock, "obtain", frb_lock_obtain, -1);
480
486
  rb_define_method(cLock, "while_locked", frb_lock_while_locked, -1);
@@ -493,11 +499,9 @@ Init_Lock(void)
493
499
  * operating systems there won't be much difference so it wouldn't be worth
494
500
  * your trouble.
495
501
  */
496
- void
497
- Init_RAMDirectory(void)
498
- {
502
+ void Init_RAMDirectory(void) {
499
503
  cRAMDirectory = rb_define_class_under(mStore, "RAMDirectory", cDirectory);
500
- rb_define_alloc_func(cRAMDirectory, frb_data_alloc);
504
+ rb_define_alloc_func(cRAMDirectory, frb_store_alloc);
501
505
  rb_define_method(cRAMDirectory, "initialize", frb_ramdir_init, -1);
502
506
  }
503
507
 
@@ -510,11 +514,9 @@ Init_RAMDirectory(void)
510
514
  * the index. The one exception to this rule is you may need to delete stale
511
515
  * lock files which have a ".lck" extension.
512
516
  */
513
- void
514
- Init_FSDirectory(void)
515
- {
517
+ void Init_FSDirectory(void) {
516
518
  cFSDirectory = rb_define_class_under(mStore, "FSDirectory", cDirectory);
517
- rb_define_alloc_func(cFSDirectory, frb_data_alloc);
519
+ rb_define_alloc_func(cFSDirectory, frb_store_alloc);
518
520
  rb_define_singleton_method(cFSDirectory, "new", frb_fsdir_new, -1);
519
521
  }
520
522
 
@@ -532,9 +534,7 @@ extern VALUE mFerret = rb_define_module("Ferret");
532
534
  * you want to add a different type of Directory, like a database Directory
533
535
  * for instance, you will to implement it in C.
534
536
  */
535
- void
536
- Init_Store(void)
537
- {
537
+ void Init_Store(void) {
538
538
  id_ref_cnt = rb_intern("@id_ref_cnt");
539
539
  mStore = rb_define_module_under(mFerret, "Store");
540
540
  Init_Directory();
@@ -18,7 +18,6 @@ typedef int frt_thread_once_t;
18
18
  #define frt_thread_key_delete(a) frb_thread_key_delete(a)
19
19
  #define frt_thread_setspecific(a, b) frb_thread_setspecific(a, b)
20
20
  #define frt_thread_getspecific(a) frb_thread_getspecific(a)
21
- #define frt_thread_exit(a)
22
21
  #define frt_thread_once(a, b) frb_thread_once(a, b)
23
22
 
24
23
  void frb_thread_once(int *once_control, void (*init_routine)(void));