ferret 0.11.6 → 0.11.8.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README +10 -22
- data/RELEASE_CHANGES +137 -0
- data/RELEASE_NOTES +60 -0
- data/Rakefile +379 -274
- data/TODO +100 -8
- data/bin/ferret-browser +0 -0
- data/ext/BZLIB_blocksort.c +1094 -0
- data/ext/BZLIB_bzlib.c +1578 -0
- data/ext/BZLIB_compress.c +672 -0
- data/ext/BZLIB_crctable.c +104 -0
- data/ext/BZLIB_decompress.c +626 -0
- data/ext/BZLIB_huffman.c +205 -0
- data/ext/BZLIB_randtable.c +84 -0
- data/ext/{api.c → STEMMER_api.c} +7 -10
- data/ext/{libstemmer.c → STEMMER_libstemmer.c} +3 -2
- data/ext/{stem_ISO_8859_1_danish.c → STEMMER_stem_ISO_8859_1_danish.c} +123 -124
- data/ext/{stem_ISO_8859_1_dutch.c → STEMMER_stem_ISO_8859_1_dutch.c} +177 -188
- data/ext/STEMMER_stem_ISO_8859_1_english.c +1117 -0
- data/ext/{stem_ISO_8859_1_finnish.c → STEMMER_stem_ISO_8859_1_finnish.c} +276 -306
- data/ext/STEMMER_stem_ISO_8859_1_french.c +1246 -0
- data/ext/{stem_ISO_8859_1_german.c → STEMMER_stem_ISO_8859_1_german.c} +161 -170
- data/ext/STEMMER_stem_ISO_8859_1_hungarian.c +1230 -0
- data/ext/STEMMER_stem_ISO_8859_1_italian.c +1065 -0
- data/ext/STEMMER_stem_ISO_8859_1_norwegian.c +297 -0
- data/ext/{stem_ISO_8859_1_porter.c → STEMMER_stem_ISO_8859_1_porter.c} +263 -290
- data/ext/{stem_ISO_8859_1_portuguese.c → STEMMER_stem_ISO_8859_1_portuguese.c} +362 -380
- data/ext/STEMMER_stem_ISO_8859_1_spanish.c +1093 -0
- data/ext/STEMMER_stem_ISO_8859_1_swedish.c +307 -0
- data/ext/STEMMER_stem_ISO_8859_2_romanian.c +998 -0
- data/ext/{stem_KOI8_R_russian.c → STEMMER_stem_KOI8_R_russian.c} +244 -245
- data/ext/STEMMER_stem_UTF_8_danish.c +339 -0
- data/ext/{stem_UTF_8_dutch.c → STEMMER_stem_UTF_8_dutch.c} +192 -211
- data/ext/STEMMER_stem_UTF_8_english.c +1125 -0
- data/ext/{stem_UTF_8_finnish.c → STEMMER_stem_UTF_8_finnish.c} +284 -324
- data/ext/STEMMER_stem_UTF_8_french.c +1256 -0
- data/ext/{stem_UTF_8_german.c → STEMMER_stem_UTF_8_german.c} +170 -187
- data/ext/STEMMER_stem_UTF_8_hungarian.c +1234 -0
- data/ext/STEMMER_stem_UTF_8_italian.c +1073 -0
- data/ext/STEMMER_stem_UTF_8_norwegian.c +299 -0
- data/ext/{stem_UTF_8_porter.c → STEMMER_stem_UTF_8_porter.c} +271 -310
- data/ext/STEMMER_stem_UTF_8_portuguese.c +1023 -0
- data/ext/STEMMER_stem_UTF_8_romanian.c +1004 -0
- data/ext/STEMMER_stem_UTF_8_russian.c +694 -0
- data/ext/STEMMER_stem_UTF_8_spanish.c +1097 -0
- data/ext/STEMMER_stem_UTF_8_swedish.c +309 -0
- data/ext/STEMMER_stem_UTF_8_turkish.c +2205 -0
- data/ext/{utilities.c → STEMMER_utilities.c} +100 -68
- data/ext/analysis.c +276 -121
- data/ext/analysis.h +190 -143
- data/ext/api.h +3 -4
- data/ext/array.c +5 -3
- data/ext/array.h +52 -43
- data/ext/bitvector.c +38 -482
- data/ext/bitvector.h +446 -124
- data/ext/bzlib.h +282 -0
- data/ext/bzlib_private.h +503 -0
- data/ext/compound_io.c +23 -22
- data/ext/config.h +21 -11
- data/ext/document.c +43 -40
- data/ext/document.h +31 -21
- data/ext/except.c +20 -38
- data/ext/except.h +89 -76
- data/ext/extconf.rb +3 -2
- data/ext/ferret.c +49 -35
- data/ext/ferret.h +14 -11
- data/ext/field_index.c +262 -0
- data/ext/field_index.h +52 -0
- data/ext/filter.c +11 -10
- data/ext/fs_store.c +65 -47
- data/ext/global.c +245 -165
- data/ext/global.h +252 -54
- data/ext/hash.c +200 -243
- data/ext/hash.h +205 -163
- data/ext/hashset.c +118 -96
- data/ext/hashset.h +110 -82
- data/ext/header.h +19 -19
- data/ext/helper.c +11 -10
- data/ext/helper.h +14 -6
- data/ext/index.c +745 -366
- data/ext/index.h +503 -529
- data/ext/internal.h +1020 -0
- data/ext/lang.c +10 -0
- data/ext/lang.h +35 -15
- data/ext/mempool.c +5 -4
- data/ext/mempool.h +30 -22
- data/ext/modules.h +35 -7
- data/ext/multimapper.c +43 -2
- data/ext/multimapper.h +32 -23
- data/ext/posh.c +0 -0
- data/ext/posh.h +4 -38
- data/ext/priorityqueue.c +10 -12
- data/ext/priorityqueue.h +33 -21
- data/ext/q_boolean.c +22 -9
- data/ext/q_const_score.c +3 -2
- data/ext/q_filtered_query.c +15 -12
- data/ext/q_fuzzy.c +147 -135
- data/ext/q_match_all.c +3 -2
- data/ext/q_multi_term.c +28 -32
- data/ext/q_parser.c +451 -173
- data/ext/q_phrase.c +158 -79
- data/ext/q_prefix.c +16 -18
- data/ext/q_range.c +363 -31
- data/ext/q_span.c +130 -141
- data/ext/q_term.c +21 -21
- data/ext/q_wildcard.c +19 -23
- data/ext/r_analysis.c +369 -242
- data/ext/r_index.c +421 -434
- data/ext/r_qparser.c +142 -92
- data/ext/r_search.c +790 -407
- data/ext/r_store.c +44 -44
- data/ext/r_utils.c +264 -96
- data/ext/ram_store.c +29 -23
- data/ext/scanner.c +895 -0
- data/ext/scanner.h +36 -0
- data/ext/scanner_mb.c +6701 -0
- data/ext/scanner_utf8.c +4415 -0
- data/ext/search.c +210 -87
- data/ext/search.h +556 -488
- data/ext/similarity.c +17 -16
- data/ext/similarity.h +51 -44
- data/ext/sort.c +157 -354
- data/ext/stem_ISO_8859_1_hungarian.h +16 -0
- data/ext/stem_ISO_8859_2_romanian.h +16 -0
- data/ext/stem_UTF_8_hungarian.h +16 -0
- data/ext/stem_UTF_8_romanian.h +16 -0
- data/ext/stem_UTF_8_turkish.h +16 -0
- data/ext/stopwords.c +287 -278
- data/ext/store.c +57 -51
- data/ext/store.h +308 -286
- data/ext/symbol.c +10 -0
- data/ext/symbol.h +23 -0
- data/ext/term_vectors.c +14 -293
- data/ext/threading.h +22 -22
- data/ext/win32.h +12 -4
- data/lib/ferret.rb +2 -1
- data/lib/ferret/browser.rb +1 -1
- data/lib/ferret/field_symbol.rb +94 -0
- data/lib/ferret/index.rb +221 -34
- data/lib/ferret/number_tools.rb +6 -6
- data/lib/ferret/version.rb +3 -0
- data/test/{unit → long_running}/largefile/tc_largefile.rb +1 -1
- data/test/test_helper.rb +7 -2
- data/test/test_installed.rb +1 -0
- data/test/threading/thread_safety_index_test.rb +10 -1
- data/test/threading/thread_safety_read_write_test.rb +4 -7
- data/test/threading/thread_safety_test.rb +0 -0
- data/test/unit/analysis/tc_analyzer.rb +29 -27
- data/test/unit/analysis/tc_token_stream.rb +23 -16
- data/test/unit/index/tc_index.rb +116 -11
- data/test/unit/index/tc_index_reader.rb +27 -27
- data/test/unit/index/tc_index_writer.rb +10 -0
- data/test/unit/index/th_doc.rb +38 -21
- data/test/unit/search/tc_filter.rb +31 -10
- data/test/unit/search/tc_index_searcher.rb +6 -0
- data/test/unit/search/tm_searcher.rb +53 -1
- data/test/unit/store/tc_fs_store.rb +40 -2
- data/test/unit/store/tc_ram_store.rb +0 -0
- data/test/unit/store/tm_store.rb +0 -0
- data/test/unit/store/tm_store_lock.rb +7 -6
- data/test/unit/tc_field_symbol.rb +26 -0
- data/test/unit/ts_analysis.rb +0 -0
- data/test/unit/ts_index.rb +0 -0
- data/test/unit/ts_store.rb +0 -0
- data/test/unit/ts_utils.rb +0 -0
- data/test/unit/utils/tc_number_tools.rb +0 -0
- data/test/utils/content_generator.rb +226 -0
- metadata +262 -221
- data/ext/inc/lang.h +0 -48
- data/ext/inc/threading.h +0 -31
- data/ext/stem_ISO_8859_1_english.c +0 -1156
- data/ext/stem_ISO_8859_1_french.c +0 -1276
- data/ext/stem_ISO_8859_1_italian.c +0 -1091
- data/ext/stem_ISO_8859_1_norwegian.c +0 -296
- data/ext/stem_ISO_8859_1_spanish.c +0 -1119
- data/ext/stem_ISO_8859_1_swedish.c +0 -307
- data/ext/stem_UTF_8_danish.c +0 -344
- data/ext/stem_UTF_8_english.c +0 -1176
- data/ext/stem_UTF_8_french.c +0 -1296
- data/ext/stem_UTF_8_italian.c +0 -1113
- data/ext/stem_UTF_8_norwegian.c +0 -302
- data/ext/stem_UTF_8_portuguese.c +0 -1055
- data/ext/stem_UTF_8_russian.c +0 -709
- data/ext/stem_UTF_8_spanish.c +0 -1137
- data/ext/stem_UTF_8_swedish.c +0 -313
- data/lib/ferret_version.rb +0 -3
data/ext/except.h
CHANGED
@@ -3,34 +3,39 @@
|
|
3
3
|
*
|
4
4
|
* Exception Handling looks something like this;
|
5
5
|
*
|
6
|
+
* ### NOTE ###
|
7
|
+
* You must use a FINALLY block if you use "default:" block. Otherwise the
|
8
|
+
* default: block will get called in place of the FINALLY block.
|
9
|
+
*
|
10
|
+
*
|
6
11
|
* <pre>
|
7
|
-
*
|
8
|
-
*
|
12
|
+
* FRT_TRY
|
13
|
+
* FRT_RAISE(FRT_EXCEPTION, msg1);
|
9
14
|
* break;
|
10
|
-
* case
|
15
|
+
* case FRT_EXCEPTION:
|
11
16
|
* // This should be called
|
12
17
|
* exception_handled = true;
|
13
|
-
*
|
18
|
+
* FRT_HANDLED();
|
14
19
|
* break;
|
15
20
|
* default:
|
16
21
|
* // shouldn't enter here
|
17
22
|
* break;
|
18
|
-
*
|
23
|
+
* FRT_XFINALLY
|
19
24
|
* // this code will always be run
|
20
25
|
* if (close_widget_one(arg) == 0) {
|
21
|
-
*
|
26
|
+
* FRT_RAISE(EXCEPTION_CODE, msg);
|
22
27
|
* }
|
23
28
|
* // this code will also always run, even if the above exception is
|
24
29
|
* // raised
|
25
30
|
* if (close_widget_two(arg) == 0) {
|
26
|
-
*
|
31
|
+
* FRT_RAISE(EXCEPTION_CODE, msg);
|
27
32
|
* }
|
28
|
-
*
|
33
|
+
* FRT_XENDTRY
|
29
34
|
* </pre>
|
30
35
|
*
|
31
36
|
* Basically exception handling uses the following macros;
|
32
37
|
*
|
33
|
-
*
|
38
|
+
* FRT_TRY
|
34
39
|
* Sets up the exception handler and need be placed before any expected
|
35
40
|
* exceptions would be raised.
|
36
41
|
*
|
@@ -39,130 +44,138 @@
|
|
39
44
|
* statement with the appropriate error code to catch Exceptions. Hence, if
|
40
45
|
* you want to catch all exceptions, use the default keyword.
|
41
46
|
*
|
42
|
-
*
|
47
|
+
* FRT_HANDLED
|
43
48
|
* If you catch and handle an exception you need to explicitely call
|
44
|
-
*
|
49
|
+
* FRT_HANDLED(); or the exeption will be re-raised once the current exception
|
45
50
|
* handling context is left.
|
46
51
|
*
|
47
|
-
* case
|
52
|
+
* case FRT_FINALLY:
|
48
53
|
* Code in this block is always called. Use this block to close any
|
49
54
|
* resources opened in the Exception handling body.
|
50
55
|
*
|
51
|
-
*
|
56
|
+
* FRT_ENDTRY
|
52
57
|
* Must be placed at the end of all exception handling code.
|
53
58
|
*
|
54
|
-
*
|
55
|
-
* Similar to case
|
59
|
+
* FRT_XFINALLY
|
60
|
+
* Similar to case FRT_FINALLY: except that it uses a fall through (ie, you must
|
56
61
|
* not use a break before it) instead of a jump to get to it. This saves a
|
57
|
-
* jump. It must be used in combination with
|
62
|
+
* jump. It must be used in combination with FRT_XENDTRY and must not have any
|
58
63
|
* other catches. This is an optimization so should probably be not be used
|
59
64
|
* in most cases.
|
60
65
|
*
|
61
|
-
*
|
62
|
-
* Like
|
63
|
-
* Must use in combination with
|
66
|
+
* FRT_XCATCHALL
|
67
|
+
* Like FRT_XFINALLY but the block is only called when an exception is raised.
|
68
|
+
* Must use in combination with FRT_XENDTRY and do not have any other FRT_FINALLY or
|
64
69
|
* catch block.
|
65
70
|
*
|
66
|
-
*
|
67
|
-
* Must use in combination with
|
68
|
-
* jump to
|
71
|
+
* FRT_XENDTRY
|
72
|
+
* Must use in combination with FRT_XFINALLY or FRT_XCATCHALL. Simply, it doesn't
|
73
|
+
* jump to FRT_FINALLY, making it more efficient.
|
69
74
|
*/
|
70
75
|
#ifndef FRT_EXCEPT_H
|
71
76
|
#define FRT_EXCEPT_H
|
72
77
|
|
78
|
+
#ifdef __cplusplus
|
79
|
+
extern "C" {
|
80
|
+
#endif
|
81
|
+
|
73
82
|
#include <setjmp.h>
|
74
83
|
#include "config.h"
|
75
84
|
|
76
|
-
|
77
|
-
#define
|
78
|
-
#define
|
79
|
-
#define
|
80
|
-
#define
|
81
|
-
#define
|
82
|
-
#define
|
83
|
-
#define
|
84
|
-
#define
|
85
|
-
#define
|
86
|
-
#define
|
87
|
-
#define
|
88
|
-
#define
|
89
|
-
#define
|
90
|
-
|
91
|
-
|
92
|
-
extern char *const
|
93
|
-
extern
|
94
|
-
|
95
|
-
typedef struct
|
85
|
+
/* TODO make this an enum */
|
86
|
+
#define FRT_BODY 0
|
87
|
+
#define FRT_FINALLY 1
|
88
|
+
#define FRT_EXCEPTION 2
|
89
|
+
#define FRT_FERRET_ERROR 2
|
90
|
+
#define FRT_IO_ERROR 3
|
91
|
+
#define FRT_FILE_NOT_FOUND_ERROR 4
|
92
|
+
#define FRT_ARG_ERROR 5
|
93
|
+
#define FRT_EOF_ERROR 6
|
94
|
+
#define FRT_UNSUPPORTED_ERROR 7
|
95
|
+
#define FRT_STATE_ERROR 8
|
96
|
+
#define FRT_PARSE_ERROR 9
|
97
|
+
#define FRT_MEM_ERROR 10
|
98
|
+
#define FRT_INDEX_ERROR 11
|
99
|
+
#define FRT_LOCK_ERROR 12
|
100
|
+
|
101
|
+
extern char *const FRT_UNSUPPORTED_ERROR_MSG;
|
102
|
+
extern char *const FRT_EOF_ERROR_MSG;
|
103
|
+
|
104
|
+
typedef struct frt_xcontext_t
|
96
105
|
{
|
97
106
|
jmp_buf jbuf;
|
98
|
-
struct
|
107
|
+
struct frt_xcontext_t *next;
|
99
108
|
const char *msg;
|
100
109
|
volatile int excode;
|
101
110
|
unsigned int handled : 1;
|
102
111
|
unsigned int in_finally : 1;
|
103
|
-
}
|
112
|
+
} frt_xcontext_t;
|
104
113
|
|
105
|
-
#define
|
114
|
+
#define FRT_TRY\
|
106
115
|
do {\
|
107
|
-
|
108
|
-
|
116
|
+
frt_xcontext_t xcontext;\
|
117
|
+
frt_xpush_context(&xcontext);\
|
109
118
|
switch (setjmp(xcontext.jbuf)) {\
|
110
|
-
case
|
119
|
+
case FRT_BODY:
|
111
120
|
|
112
121
|
|
113
|
-
#define
|
122
|
+
#define FRT_XENDTRY\
|
114
123
|
}\
|
115
|
-
|
124
|
+
frt_xpop_context();\
|
116
125
|
} while (0);
|
117
126
|
|
118
|
-
#define
|
127
|
+
#define FRT_ENDTRY\
|
119
128
|
}\
|
120
129
|
if (!xcontext.in_finally) {\
|
121
|
-
|
130
|
+
frt_xpop_context();\
|
122
131
|
xcontext.in_finally = 1;\
|
123
|
-
longjmp(xcontext.jbuf,
|
132
|
+
longjmp(xcontext.jbuf, FRT_FINALLY);\
|
124
133
|
}\
|
125
134
|
} while (0);
|
126
135
|
|
127
|
-
#define
|
136
|
+
#define FRT_RETURN_EARLY() frt_xpop_context()
|
128
137
|
|
129
138
|
|
130
|
-
#define
|
139
|
+
#define FRT_XFINALLY default: xcontext.in_finally = 1;
|
131
140
|
|
132
|
-
#define
|
141
|
+
#define FRT_XCATCHALL break; default: xcontext.in_finally = 1;
|
133
142
|
|
134
|
-
#define
|
143
|
+
#define FRT_HANDLED() xcontext.handled = 1; /* true */
|
135
144
|
|
136
|
-
#define
|
145
|
+
#define FRT_XMSG_BUFFER_SIZE 2048
|
137
146
|
|
138
147
|
#ifdef FRT_HAS_ISO_VARARGS
|
139
|
-
# define
|
140
|
-
snprintf(
|
141
|
-
snprintf(
|
142
|
-
"Error occured in %s:%d - %s\n\t%s
|
143
|
-
__FILE__, __LINE__, __func__,
|
144
|
-
|
148
|
+
# define FRT_RAISE(excode, ...) do {\
|
149
|
+
snprintf(frt_xmsg_buffer, FRT_XMSG_BUFFER_SIZE, __VA_ARGS__);\
|
150
|
+
snprintf(frt_xmsg_buffer_final, FRT_XMSG_BUFFER_SIZE,\
|
151
|
+
"Error occured in %s:%d - %s\n\t%s",\
|
152
|
+
__FILE__, __LINE__, __func__, frt_xmsg_buffer);\
|
153
|
+
frt_xraise(excode, frt_xmsg_buffer_final);\
|
145
154
|
} while (0)
|
146
155
|
#elif defined(FRT_HAS_GNUC_VARARGS)
|
147
|
-
# define
|
148
|
-
snprintf(
|
149
|
-
snprintf(
|
156
|
+
# define FRT_RAISE(excode, args...) do {\
|
157
|
+
snprintf(frt_xmsg_buffer, FRT_XMSG_BUFFER_SIZE, ##args);\
|
158
|
+
snprintf(frt_xmsg_buffer_final, FRT_XMSG_BUFFER_SIZE,\
|
150
159
|
"Error occured in %s:%d - %s\n\t%s\n",\
|
151
|
-
__FILE__, __LINE__, __func__,
|
152
|
-
|
160
|
+
__FILE__, __LINE__, __func__, frt_xmsg_buffer);\
|
161
|
+
frt_xraise(excode, frt_xmsg_buffer_final);\
|
153
162
|
} while (0)
|
154
163
|
|
155
164
|
#else
|
156
|
-
extern void
|
165
|
+
extern void FRT_RAISE(int excode, const char *fmt, ...);
|
157
166
|
#endif
|
158
|
-
#define RAISE_HELL()
|
167
|
+
#define RAISE_HELL() FRT_RAISE(FRT_FERRET_ERROR, "Hell")
|
168
|
+
|
159
169
|
|
170
|
+
extern void frt_xraise(int excode, const char *const msg);
|
171
|
+
extern void frt_xpush_context(frt_xcontext_t *context);
|
172
|
+
extern void frt_xpop_context();
|
160
173
|
|
161
|
-
extern
|
162
|
-
extern
|
163
|
-
extern void xpop_context();
|
174
|
+
extern char frt_xmsg_buffer[FRT_XMSG_BUFFER_SIZE];
|
175
|
+
extern char frt_xmsg_buffer_final[FRT_XMSG_BUFFER_SIZE];
|
164
176
|
|
165
|
-
|
166
|
-
extern
|
177
|
+
#ifdef __cplusplus
|
178
|
+
} // extern "C"
|
179
|
+
#endif
|
167
180
|
|
168
181
|
#endif
|
data/ext/extconf.rb
CHANGED
@@ -5,10 +5,11 @@ if (/mswin/ =~ RUBY_PLATFORM) and ENV['make'].nil?
|
|
5
5
|
create_makefile("ferret_ext")
|
6
6
|
elsif ENV['FERRET_DEV']
|
7
7
|
require 'mkmf'
|
8
|
-
$CFLAGS
|
8
|
+
$CFLAGS = " -g -Wall -fno-stack-protector -fno-common -D_FILE_OFFSET_BITS=64 -D_XOPEN_SOURCE=500"
|
9
|
+
puts $CFLAGS
|
9
10
|
create_makefile("ferret_ext")
|
10
11
|
else
|
11
12
|
require 'mkmf'
|
12
|
-
$CFLAGS += " -D_FILE_OFFSET_BITS=64"
|
13
|
+
$CFLAGS += " -Wall -D_FILE_OFFSET_BITS=64 -D_XOPEN_SOURCE=500"
|
13
14
|
create_makefile("ferret_ext")
|
14
15
|
end
|
data/ext/ferret.c
CHANGED
@@ -4,9 +4,11 @@
|
|
4
4
|
#include "hash.h"
|
5
5
|
#include "hashset.h"
|
6
6
|
#include "threading.h"
|
7
|
+
#include "symbol.h"
|
8
|
+
#include "internal.h"
|
7
9
|
|
8
10
|
/* Object Map */
|
9
|
-
static
|
11
|
+
static Hash *object_map;
|
10
12
|
|
11
13
|
/* IDs */
|
12
14
|
ID id_new;
|
@@ -84,30 +86,30 @@ void
|
|
84
86
|
//object_del(void *key)
|
85
87
|
object_del2(void *key, const char *file, int line)
|
86
88
|
{
|
87
|
-
if (object_get(key) == Qnil)
|
89
|
+
if (object_get(key) == Qnil)
|
88
90
|
printf("failed deleting %ld. %s:%d\n", (long)key, file, line);
|
89
91
|
//printf("deleting %ld. now contains %ld, %s:%d\n", (long)key, --hash_cnt, file, line);
|
90
92
|
h_del(object_map, key);
|
91
93
|
}
|
92
94
|
|
93
|
-
void
|
95
|
+
void frb_gc_mark(void *key)
|
94
96
|
{
|
95
97
|
VALUE val = (VALUE)h_get(object_map, key);
|
96
98
|
if (val)
|
97
99
|
rb_gc_mark(val);
|
98
100
|
}
|
99
101
|
|
100
|
-
VALUE
|
102
|
+
VALUE frb_data_alloc(VALUE klass)
|
101
103
|
{
|
102
104
|
return Frt_Make_Struct(klass);
|
103
105
|
}
|
104
106
|
|
105
|
-
void
|
107
|
+
void frb_deref_free(void *p)
|
106
108
|
{
|
107
109
|
object_del(p);
|
108
110
|
}
|
109
111
|
|
110
|
-
void
|
112
|
+
void frb_thread_once(int *once_control, void (*init_routine) (void))
|
111
113
|
{
|
112
114
|
if (*once_control) {
|
113
115
|
init_routine();
|
@@ -115,45 +117,45 @@ void frt_thread_once(int *once_control, void (*init_routine) (void))
|
|
115
117
|
}
|
116
118
|
}
|
117
119
|
|
118
|
-
void
|
120
|
+
void frb_thread_key_create(thread_key_t *key, void (*destr_function)(void *))
|
119
121
|
{
|
120
122
|
*key = h_new(&value_hash, &value_eq, NULL, destr_function);
|
121
123
|
}
|
122
124
|
|
123
|
-
void
|
125
|
+
void frb_thread_key_delete(thread_key_t key)
|
124
126
|
{
|
125
127
|
h_destroy(key);
|
126
128
|
}
|
127
129
|
|
128
|
-
void
|
130
|
+
void frb_thread_setspecific(thread_key_t key, const void *pointer)
|
129
131
|
{
|
130
132
|
h_set(key, (void *)rb_thread_current(), (void *)pointer);
|
131
133
|
}
|
132
134
|
|
133
|
-
void *
|
135
|
+
void *frb_thread_getspecific(thread_key_t key)
|
134
136
|
{
|
135
137
|
return h_get(key, (void *)rb_thread_current());
|
136
138
|
}
|
137
139
|
|
138
|
-
void
|
140
|
+
void frb_create_dir(VALUE rpath)
|
139
141
|
{
|
140
142
|
VALUE mFileUtils;
|
141
|
-
rb_require("fileutils");
|
142
143
|
mFileUtils = rb_define_module("FileUtils");
|
143
144
|
rb_funcall(mFileUtils, id_mkdir_p, 1, rpath);
|
144
145
|
}
|
145
146
|
|
146
|
-
VALUE
|
147
|
+
VALUE frb_hs_to_rb_ary(HashSet *hs)
|
147
148
|
{
|
148
|
-
|
149
|
+
HashSetEntry *hse;
|
149
150
|
VALUE ary = rb_ary_new();
|
150
|
-
|
151
|
-
|
151
|
+
|
152
|
+
for (hse = hs->first; hse; hse = hse->next) {
|
153
|
+
rb_ary_push(ary, rb_str_new2(hse->elem));
|
152
154
|
}
|
153
155
|
return ary;
|
154
156
|
}
|
155
157
|
|
156
|
-
void *
|
158
|
+
void *frb_rb_data_ptr(VALUE val)
|
157
159
|
{
|
158
160
|
Check_Type(val, T_DATA);
|
159
161
|
return DATA_PTR(val);
|
@@ -162,31 +164,38 @@ void *frt_rb_data_ptr(VALUE val)
|
|
162
164
|
char *
|
163
165
|
rs2s(VALUE rstr)
|
164
166
|
{
|
165
|
-
return (char *)(
|
167
|
+
return (char *)(RSTRING_PTR(rstr) ? RSTRING_PTR(rstr) : EMPTY_STRING);
|
166
168
|
}
|
167
169
|
|
168
170
|
char *
|
169
|
-
|
171
|
+
rstrdup(VALUE rstr)
|
170
172
|
{
|
171
173
|
char *old = rs2s(rstr);
|
172
|
-
int len =
|
174
|
+
int len = RSTRING_LEN(rstr);
|
173
175
|
char *new = ALLOC_N(char, len + 1);
|
174
176
|
memcpy(new, old, len + 1);
|
175
177
|
return new;
|
176
178
|
}
|
177
179
|
|
178
|
-
|
179
|
-
|
180
|
+
Symbol
|
181
|
+
rintern(VALUE rstr)
|
182
|
+
{
|
183
|
+
char *old = rs2s(rstr);
|
184
|
+
return frt_intern(old);
|
185
|
+
}
|
186
|
+
|
187
|
+
Symbol
|
188
|
+
frb_field(VALUE rfield)
|
180
189
|
{
|
181
190
|
switch (TYPE(rfield)) {
|
182
191
|
case T_SYMBOL:
|
183
|
-
return
|
192
|
+
return SYM2FSYM(rfield);
|
184
193
|
case T_STRING:
|
185
|
-
return rs2s(rfield);
|
194
|
+
return I(rs2s(rfield));
|
186
195
|
default:
|
187
196
|
rb_raise(rb_eArgError, "field name must be a symbol");
|
197
|
+
return NULL;
|
188
198
|
}
|
189
|
-
return NULL;
|
190
199
|
}
|
191
200
|
|
192
201
|
/*
|
@@ -216,7 +225,7 @@ json_concat_string(char *s, char *field)
|
|
216
225
|
|
217
226
|
static VALUE error_map;
|
218
227
|
|
219
|
-
VALUE
|
228
|
+
VALUE frb_get_error(const char *err_type)
|
220
229
|
{
|
221
230
|
VALUE error_class;
|
222
231
|
if (Qnil != (error_class = rb_hash_aref(error_map, rb_intern(err_type)))) {
|
@@ -251,11 +260,11 @@ void V_FRT_EXIT(const char *err_type, const char *fmt, va_list args)
|
|
251
260
|
}
|
252
261
|
|
253
262
|
snprintf(buf + so_far, FRT_BUF_SIZ - so_far, "\n");
|
254
|
-
rb_raise(
|
263
|
+
rb_raise(frb_get_error(err_type), "%s", buf);
|
255
264
|
}
|
256
265
|
|
257
266
|
#ifdef FRT_HAS_VARARGS
|
258
|
-
void
|
267
|
+
void frb_rb_raise(const char *file, int line_num, const char *func,
|
259
268
|
const char *err_type, const char *fmt, ...)
|
260
269
|
#else
|
261
270
|
void FRT_EXIT(const char *err_type, const char *fmt, ...)
|
@@ -279,23 +288,23 @@ void FRT_EXIT(const char *err_type, const char *fmt, ...)
|
|
279
288
|
static ID id_field;
|
280
289
|
static ID id_text;
|
281
290
|
|
282
|
-
VALUE
|
291
|
+
VALUE frb_get_term(Symbol field, const char *text)
|
283
292
|
{
|
284
293
|
return rb_struct_new(cTerm,
|
285
|
-
|
294
|
+
FSYM2SYM(field),
|
286
295
|
rb_str_new2(text),
|
287
296
|
NULL);
|
288
297
|
}
|
289
298
|
|
290
|
-
static VALUE
|
299
|
+
static VALUE frb_term_to_s(VALUE self)
|
291
300
|
{
|
292
301
|
VALUE rstr;
|
293
|
-
VALUE rfield = rb_funcall(self, id_field, 0);
|
294
|
-
VALUE rtext = rb_funcall(self, id_text, 0);
|
302
|
+
VALUE rfield = rb_funcall(self, id_field, 0);
|
303
|
+
VALUE rtext = rb_funcall(self, id_text, 0);
|
295
304
|
char *field = StringValuePtr(rfield);
|
296
305
|
char *text = StringValuePtr(rtext);
|
297
306
|
char *term_str = ALLOC_N(char,
|
298
|
-
5 +
|
307
|
+
5 + RSTRING_LEN(rfield) + RSTRING_LEN(rtext));
|
299
308
|
sprintf(term_str, "%s:%s", field, text);
|
300
309
|
rstr = rb_str_new2(term_str);
|
301
310
|
free(term_str);
|
@@ -314,7 +323,7 @@ void Init_Term(void)
|
|
314
323
|
cTerm = rb_struct_define(term_class, "field", "text", NULL);
|
315
324
|
rb_set_class_path(cTerm, mFerret, term_class);
|
316
325
|
rb_const_set(mFerret, rb_intern(term_class), cTerm);
|
317
|
-
rb_define_method(cTerm, "to_s",
|
326
|
+
rb_define_method(cTerm, "to_s", frb_term_to_s, 0);
|
318
327
|
id_field = rb_intern("field");
|
319
328
|
id_text = rb_intern("text");
|
320
329
|
}
|
@@ -328,6 +337,7 @@ void Init_Ferret(void)
|
|
328
337
|
{
|
329
338
|
mFerret = rb_define_module("Ferret");
|
330
339
|
Init_Term();
|
340
|
+
rb_require("fileutils");
|
331
341
|
}
|
332
342
|
|
333
343
|
void Init_ferret_ext(void)
|
@@ -336,6 +346,10 @@ void Init_ferret_ext(void)
|
|
336
346
|
VALUE cStateError;
|
337
347
|
VALUE cFileNotFoundError;
|
338
348
|
|
349
|
+
const char *const progname[] = {"ruby"};
|
350
|
+
|
351
|
+
frt_init(1, progname);
|
352
|
+
|
339
353
|
/* initialize object map */
|
340
354
|
object_map = h_new(&value_hash, &value_eq, NULL, NULL);
|
341
355
|
|