groonga 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. data/AUTHORS +1 -0
  2. data/NEWS.ja.rdoc +5 -0
  3. data/NEWS.rdoc +5 -0
  4. data/README.ja.rdoc +53 -0
  5. data/README.rdoc +54 -0
  6. data/Rakefile +209 -0
  7. data/TUTORIAL.ja.rdoc +160 -0
  8. data/benchmark/small-many-items.rb +175 -0
  9. data/example/bookmark.rb +38 -0
  10. data/ext/.gitignore +2 -0
  11. data/ext/rb-grn-accessor.c +52 -0
  12. data/ext/rb-grn-array-cursor.c +28 -0
  13. data/ext/rb-grn-array.c +168 -0
  14. data/ext/rb-grn-column.c +273 -0
  15. data/ext/rb-grn-context.c +333 -0
  16. data/ext/rb-grn-database.c +128 -0
  17. data/ext/rb-grn-encoding.c +163 -0
  18. data/ext/rb-grn-exception.c +1014 -0
  19. data/ext/rb-grn-hash-cursor.c +30 -0
  20. data/ext/rb-grn-hash.c +40 -0
  21. data/ext/rb-grn-logger.c +277 -0
  22. data/ext/rb-grn-object.c +985 -0
  23. data/ext/rb-grn-patricia-trie-cursor.c +30 -0
  24. data/ext/rb-grn-patricia-trie.c +40 -0
  25. data/ext/rb-grn-procedure.c +52 -0
  26. data/ext/rb-grn-query.c +207 -0
  27. data/ext/rb-grn-record.c +33 -0
  28. data/ext/rb-grn-snippet.c +274 -0
  29. data/ext/rb-grn-table-cursor-key-support.c +55 -0
  30. data/ext/rb-grn-table-cursor.c +294 -0
  31. data/ext/rb-grn-table-key-support.c +299 -0
  32. data/ext/rb-grn-table.c +706 -0
  33. data/ext/rb-grn-type.c +114 -0
  34. data/ext/rb-grn-utils.c +578 -0
  35. data/ext/rb-grn.h +346 -0
  36. data/ext/rb-groonga.c +98 -0
  37. data/extconf.rb +171 -0
  38. data/html/bar.svg +153 -0
  39. data/html/developer.html +121 -0
  40. data/html/developer.svg +469 -0
  41. data/html/download.svg +253 -0
  42. data/html/footer.html.erb +28 -0
  43. data/html/head.html.erb +4 -0
  44. data/html/header.html.erb +17 -0
  45. data/html/index.html +153 -0
  46. data/html/install.svg +636 -0
  47. data/html/logo.xcf +0 -0
  48. data/html/ranguba.css +248 -0
  49. data/html/tutorial.svg +559 -0
  50. data/lib/groonga.rb +50 -0
  51. data/lib/groonga/record.rb +98 -0
  52. data/license/GPL +340 -0
  53. data/license/LGPL +504 -0
  54. data/license/RUBY +59 -0
  55. data/pkg-config.rb +328 -0
  56. data/test-unit/Rakefile +35 -0
  57. data/test-unit/TODO +5 -0
  58. data/test-unit/bin/testrb +5 -0
  59. data/test-unit/html/classic.html +15 -0
  60. data/test-unit/html/index.html +25 -0
  61. data/test-unit/html/index.html.ja +27 -0
  62. data/test-unit/lib/test/unit.rb +342 -0
  63. data/test-unit/lib/test/unit/assertionfailederror.rb +14 -0
  64. data/test-unit/lib/test/unit/assertions.rb +1149 -0
  65. data/test-unit/lib/test/unit/attribute.rb +125 -0
  66. data/test-unit/lib/test/unit/autorunner.rb +306 -0
  67. data/test-unit/lib/test/unit/collector.rb +43 -0
  68. data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
  69. data/test-unit/lib/test/unit/collector/dir.rb +108 -0
  70. data/test-unit/lib/test/unit/collector/load.rb +135 -0
  71. data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
  72. data/test-unit/lib/test/unit/color-scheme.rb +86 -0
  73. data/test-unit/lib/test/unit/color.rb +96 -0
  74. data/test-unit/lib/test/unit/diff.rb +538 -0
  75. data/test-unit/lib/test/unit/error.rb +124 -0
  76. data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
  77. data/test-unit/lib/test/unit/failure.rb +110 -0
  78. data/test-unit/lib/test/unit/fixture.rb +176 -0
  79. data/test-unit/lib/test/unit/notification.rb +125 -0
  80. data/test-unit/lib/test/unit/omission.rb +143 -0
  81. data/test-unit/lib/test/unit/pending.rb +146 -0
  82. data/test-unit/lib/test/unit/priority.rb +161 -0
  83. data/test-unit/lib/test/unit/runner/console.rb +52 -0
  84. data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
  85. data/test-unit/lib/test/unit/testcase.rb +360 -0
  86. data/test-unit/lib/test/unit/testresult.rb +89 -0
  87. data/test-unit/lib/test/unit/testsuite.rb +110 -0
  88. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
  89. data/test-unit/lib/test/unit/ui/console/testrunner.rb +220 -0
  90. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +49 -0
  91. data/test-unit/lib/test/unit/ui/testrunner.rb +20 -0
  92. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
  93. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
  94. data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
  95. data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
  96. data/test-unit/lib/test/unit/util/observable.rb +90 -0
  97. data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
  98. data/test-unit/lib/test/unit/version.rb +7 -0
  99. data/test-unit/sample/adder.rb +13 -0
  100. data/test-unit/sample/subtracter.rb +12 -0
  101. data/test-unit/sample/tc_adder.rb +18 -0
  102. data/test-unit/sample/tc_subtracter.rb +18 -0
  103. data/test-unit/sample/test_user.rb +22 -0
  104. data/test-unit/sample/ts_examples.rb +7 -0
  105. data/test-unit/test/collector/test-descendant.rb +135 -0
  106. data/test-unit/test/collector/test-load.rb +333 -0
  107. data/test-unit/test/collector/test_dir.rb +406 -0
  108. data/test-unit/test/collector/test_objectspace.rb +98 -0
  109. data/test-unit/test/run-test.rb +13 -0
  110. data/test-unit/test/test-attribute.rb +86 -0
  111. data/test-unit/test/test-color-scheme.rb +56 -0
  112. data/test-unit/test/test-color.rb +47 -0
  113. data/test-unit/test/test-diff.rb +477 -0
  114. data/test-unit/test/test-emacs-runner.rb +60 -0
  115. data/test-unit/test/test-fixture.rb +287 -0
  116. data/test-unit/test/test-notification.rb +33 -0
  117. data/test-unit/test/test-omission.rb +81 -0
  118. data/test-unit/test/test-pending.rb +70 -0
  119. data/test-unit/test/test-priority.rb +119 -0
  120. data/test-unit/test/test_assertions.rb +1082 -0
  121. data/test-unit/test/test_error.rb +26 -0
  122. data/test-unit/test/test_failure.rb +33 -0
  123. data/test-unit/test/test_testcase.rb +478 -0
  124. data/test-unit/test/test_testresult.rb +113 -0
  125. data/test-unit/test/test_testsuite.rb +129 -0
  126. data/test-unit/test/testunit-test-util.rb +14 -0
  127. data/test-unit/test/ui/test_testrunmediator.rb +20 -0
  128. data/test-unit/test/util/test-method-owner-finder.rb +38 -0
  129. data/test-unit/test/util/test_backtracefilter.rb +41 -0
  130. data/test-unit/test/util/test_observable.rb +102 -0
  131. data/test-unit/test/util/test_procwrapper.rb +36 -0
  132. data/test/.gitignore +1 -0
  133. data/test/groonga-test-utils.rb +90 -0
  134. data/test/run-test.rb +54 -0
  135. data/test/test-column.rb +190 -0
  136. data/test/test-context.rb +90 -0
  137. data/test/test-database.rb +62 -0
  138. data/test/test-encoding.rb +33 -0
  139. data/test/test-exception.rb +85 -0
  140. data/test/test-procedure.rb +35 -0
  141. data/test/test-query.rb +22 -0
  142. data/test/test-record.rb +188 -0
  143. data/test/test-snippet.rb +121 -0
  144. data/test/test-table-cursor.rb +51 -0
  145. data/test/test-table.rb +447 -0
  146. data/test/test-type.rb +52 -0
  147. data/test/test-version.rb +31 -0
  148. metadata +213 -0
data/ext/rb-grn.h ADDED
@@ -0,0 +1,346 @@
1
+ /* -*- c-file-style: "ruby" -*- */
2
+ /*
3
+ Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
4
+
5
+ This library is free software; you can redistribute it and/or
6
+ modify it under the terms of the GNU Lesser General Public
7
+ License version 2.1 as published by the Free Software Foundation.
8
+
9
+ This library is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public
15
+ License along with this library; if not, write to the Free Software
16
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+ */
18
+
19
+ #ifndef __RB_GRN_H__
20
+ #define __RB_GRN_H__
21
+
22
+ #include <ruby.h>
23
+
24
+ #include <groonga.h>
25
+
26
+ #if defined(__cplusplus)
27
+ # define RB_GRN_BEGIN_DECLS extern "C" {
28
+ # define RB_GRN_END_DECLS }
29
+ #else
30
+ # define RB_GRN_BEGIN_DECLS
31
+ # define RB_GRN_END_DECLS
32
+ #endif
33
+
34
+ RB_GRN_BEGIN_DECLS
35
+
36
+ #if __GNUC__ >= 4
37
+ # define RB_GRN_GNUC_NULL_TERMINATED __attribute__((__sentinel__))
38
+ #else
39
+ # define RB_GRN_GNUC_NULL_TERMINATED
40
+ #endif
41
+
42
+ #if defined(RUBY_GRN_PLATFORM_WIN32) && !defined(RB_GRN_PLATFORM_WIN32)
43
+ # define RB_GRN_PLATFORM_WIN32 RUBY_GRN_PLATFORM_WIN32
44
+ #endif
45
+
46
+ #if defined(RUBY_GRN_STATIC_COMPILATION) && !defined(RB_GRN_STATIC_COMPILATION)
47
+ # define RB_GRN_STATIC_COMPILATION RUBY_GRN_STATIC_COMPILATION
48
+ #endif
49
+
50
+ #if defined(RB_GRN_PLATFORM_WIN32) && !defined(RB_GRN_STATIC_COMPILATION)
51
+ # ifdef RB_GRN_COMPILATION
52
+ # define RB_GRN_VAR __declspec(dllexport)
53
+ # else
54
+ # define RB_GRN_VAR extern __declspec(dllimport)
55
+ # endif
56
+ #else
57
+ # define RB_GRN_VAR extern
58
+ #endif
59
+
60
+ #define RB_GRN_MAJOR_VERSION 0
61
+ #define RB_GRN_MINOR_VERSION 0
62
+ #define RB_GRN_MICRO_VERSION 1
63
+
64
+ typedef int rb_grn_boolean;
65
+ #define RB_GRN_FALSE (0)
66
+ #define RB_GRN_TRUE (!RB_GRN_FALSE)
67
+
68
+ #define RB_GRN_QUERY_DEFAULT_MAX_EXPRESSIONS 32
69
+
70
+ #include <stdint.h>
71
+
72
+ typedef struct {
73
+ int32_t tv_sec;
74
+ int32_t tv_usec;
75
+ } grn_timeval;
76
+
77
+
78
+ RB_GRN_VAR VALUE rb_eGrnError;
79
+ RB_GRN_VAR VALUE rb_cGrnObject;
80
+ RB_GRN_VAR VALUE rb_cGrnDatabase;
81
+ RB_GRN_VAR VALUE rb_cGrnTable;
82
+ RB_GRN_VAR VALUE rb_mGrnTableKeySupport;
83
+ RB_GRN_VAR VALUE rb_cGrnHash;
84
+ RB_GRN_VAR VALUE rb_cGrnPatriciaTrie;
85
+ RB_GRN_VAR VALUE rb_cGrnArray;
86
+ RB_GRN_VAR VALUE rb_cGrnTableCursor;
87
+ RB_GRN_VAR VALUE rb_mGrnTableCursorKeySupport;
88
+ RB_GRN_VAR VALUE rb_cGrnHashCursor;
89
+ RB_GRN_VAR VALUE rb_cGrnPatriciaTrieCursor;
90
+ RB_GRN_VAR VALUE rb_cGrnArrayCursor;
91
+ RB_GRN_VAR VALUE rb_cGrnType;
92
+ RB_GRN_VAR VALUE rb_cGrnProcedure;
93
+ RB_GRN_VAR VALUE rb_cGrnColumn;
94
+ RB_GRN_VAR VALUE rb_cGrnFixSizeColumn;
95
+ RB_GRN_VAR VALUE rb_cGrnVarSizeColumn;
96
+ RB_GRN_VAR VALUE rb_cGrnIndexColumn;
97
+ RB_GRN_VAR VALUE rb_cGrnAccessor;
98
+ RB_GRN_VAR VALUE rb_cGrnRecord;
99
+ RB_GRN_VAR VALUE rb_cGrnQuery;
100
+ RB_GRN_VAR VALUE rb_cGrnLogger;
101
+ RB_GRN_VAR VALUE rb_cGrnSnippet;
102
+
103
+ void rb_grn_init_utils (VALUE mGrn);
104
+ void rb_grn_init_exception (VALUE mGrn);
105
+ void rb_grn_init_encoding (VALUE mGrn);
106
+ void rb_grn_init_context (VALUE mGrn);
107
+ void rb_grn_init_object (VALUE mGrn);
108
+ void rb_grn_init_database (VALUE mGrn);
109
+ void rb_grn_init_table (VALUE mGrn);
110
+ void rb_grn_init_table_key_support (VALUE mGrn);
111
+ void rb_grn_init_array (VALUE mGrn);
112
+ void rb_grn_init_hash (VALUE mGrn);
113
+ void rb_grn_init_patricia_trie (VALUE mGrn);
114
+ void rb_grn_init_table_cursor (VALUE mGrn);
115
+ void rb_grn_init_table_cursor_key_support (VALUE mGrn);
116
+ void rb_grn_init_array_cursor (VALUE mGrn);
117
+ void rb_grn_init_hash_cursor (VALUE mGrn);
118
+ void rb_grn_init_patricia_trie_cursor (VALUE mGrn);
119
+ void rb_grn_init_type (VALUE mGrn);
120
+ void rb_grn_init_procedure (VALUE mGrn);
121
+ void rb_grn_init_column (VALUE mGrn);
122
+ void rb_grn_init_accessor (VALUE mGrn);
123
+ void rb_grn_init_record (VALUE mGrn);
124
+ void rb_grn_init_query (VALUE mGrn);
125
+ void rb_grn_init_logger (VALUE mGrn);
126
+ void rb_grn_init_snippet (VALUE mGrn);
127
+
128
+ VALUE rb_grn_rc_to_exception (grn_rc rc);
129
+ const char *rb_grn_rc_to_message (grn_rc rc);
130
+ void rb_grn_rc_check (grn_rc rc,
131
+ VALUE related_object);
132
+
133
+ grn_ctx *rb_grn_context_ensure (VALUE context);
134
+ VALUE rb_grn_context_get_default (void);
135
+ VALUE rb_grn_context_to_exception (grn_ctx *context,
136
+ VALUE related_object);
137
+ void rb_grn_context_check (grn_ctx *context,
138
+ VALUE related_object);
139
+
140
+ const char *rb_grn_inspect (VALUE object);
141
+ void rb_grn_scan_options (VALUE options, ...)
142
+ RB_GRN_GNUC_NULL_TERMINATED;
143
+ rb_grn_boolean rb_grn_equal_option (VALUE option,
144
+ const char *key);
145
+
146
+ VALUE rb_grn_object_alloc (VALUE klass);
147
+ void rb_grn_object_initialize (VALUE self,
148
+ grn_ctx *context,
149
+ grn_obj *object);
150
+ VALUE rb_grn_object_array_reference (VALUE object,
151
+ VALUE rb_id);
152
+ VALUE rb_grn_object_close (VALUE object);
153
+ VALUE rb_grn_object_inspect_object (VALUE inspected,
154
+ grn_ctx *context,
155
+ grn_obj *object);
156
+ VALUE rb_grn_object_inspect_object_content (VALUE inspected,
157
+ grn_ctx *context,
158
+ grn_obj *object);
159
+ VALUE rb_grn_object_inspect_header (VALUE object,
160
+ VALUE inspected);
161
+ VALUE rb_grn_object_inspect_content (VALUE object,
162
+ VALUE inspected);
163
+ VALUE rb_grn_object_inspect_footer (VALUE object,
164
+ VALUE inspected);
165
+
166
+ VALUE rb_grn_table_s_create (int argc,
167
+ VALUE *argv,
168
+ VALUE klass,
169
+ grn_obj_flags key_store);
170
+ grn_ctx *rb_grn_table_cursor_ensure_context (VALUE cursor,
171
+ VALUE rb_context);
172
+ VALUE rb_grn_table_cursor_close (VALUE object);
173
+
174
+ VALUE rb_grn_record_new (VALUE table,
175
+ grn_id id);
176
+
177
+
178
+ #define RB_GRN_INTERN(string) (ID2SYM(rb_intern(string)))
179
+
180
+ #define RVAL2CBOOL(object) (RTEST(object))
181
+ #define CBOOL2RVAL(boolean) ((boolean) ? Qtrue : Qfalse)
182
+
183
+ #define RVAL2GRNENCODING(object, context) \
184
+ (rb_grn_encoding_from_ruby_object(object, context))
185
+ #define GRNENCODING2RVAL(encoding) (rb_grn_encoding_to_ruby_object(encoding))
186
+
187
+ #define RVAL2GRNCONTEXT(object) (rb_grn_context_from_ruby_object(object))
188
+ #define GRNCONTEXT2RVAL(context) (rb_grn_context_to_ruby_object(context))
189
+
190
+ #define RVAL2GRNOBJECT(rb_object, context) \
191
+ (rb_grn_object_from_ruby_object(rb_object, context))
192
+ #define GRNOBJECT2RVAL(klass, context, object, owner) \
193
+ (rb_grn_object_to_ruby_object(klass, context, object, owner))
194
+ #define GRNOBJECT2RCLASS(object) (rb_grn_object_to_ruby_class(object))
195
+
196
+ #define RVAL2GRNDB(object) (rb_grn_database_from_ruby_object(object))
197
+ #define GRNDB2RVAL(context, db, owner) \
198
+ (rb_grn_database_to_ruby_object(context, db, owner))
199
+
200
+ #define RVAL2GRNTABLE(object, context)(rb_grn_table_from_ruby_object(object, context))
201
+ #define GRNTABLE2RVAL(context, table, owner) \
202
+ (rb_grn_table_to_ruby_object(context, table, owner))
203
+
204
+ #define RVAL2GRNTABLECURSOR(object) (rb_grn_table_cursor_from_ruby_object(object))
205
+ #define GRNTABLECURSOR2RVAL(klass, context, cursor) \
206
+ (rb_grn_table_cursor_to_ruby_object(klass, context, cursor))
207
+ #define GRNTABLECURSOR2RCLASS(object) (rb_grn_table_cursor_to_ruby_class(object))
208
+
209
+ #define RVAL2GRNCOLUMN(object, context) \
210
+ (rb_grn_column_from_ruby_object(object, context))
211
+ #define GRNCOLUMN2RVAL(klass, context, column, owner) \
212
+ (rb_grn_column_to_ruby_object(klass, context, column, owner))
213
+
214
+ #define RVAL2GRNQUERY(object) (rb_grn_query_from_ruby_object(object))
215
+ #define GRNQUERY2RVAL(context, column)(rb_grn_query_to_ruby_object(context, column))
216
+
217
+ #define RVAL2GRNSELECTOPERATOR(object)(rb_grn_select_operator_from_ruby_object(object))
218
+
219
+ #define RVAL2GRNLOGGER(object) (rb_grn_logger_from_ruby_object(object))
220
+
221
+ #define RVAL2GRNBULK(object, context, bulk) \
222
+ (rb_grn_bulk_from_ruby_object(object, context, bulk))
223
+ #define RVAL2GRNBULK_WITH_TYPE(object, context, bulk, type) \
224
+ (rb_grn_bulk_from_ruby_object_with_type(object, context, bulk, type))
225
+ #define GRNBULK2RVAL(context, bulk, related_object) \
226
+ (rb_grn_bulk_to_ruby_object(context, bulk, related_object))
227
+
228
+ #define RVAL2GRNVECTOR(object, context, vector) \
229
+ (rb_grn_vector_from_ruby_object(object, context, vector))
230
+ #define GRNVECTOR2RVAL(context, vector) \
231
+ (rb_grn_vector_to_ruby_object(context, vector))
232
+
233
+ #define RVAL2GRNUVECTOR(object, context, uvector) \
234
+ (rb_grn_uvector_from_ruby_object(object, context, uvector))
235
+ #define GRNUVECTOR2RVAL(context, uvector) \
236
+ (rb_grn_uvector_to_ruby_object(context, uvector))
237
+
238
+ #define GRNVALUE2RVAL(context, value, range, related_object) \
239
+ (rb_grn_value_to_ruby_object(context, value, range, related_object))
240
+
241
+ #define RVAL2GRNID(object, context, table, related_object) \
242
+ (rb_grn_id_from_ruby_object(object, context, table, related_object))
243
+
244
+ #define GRNKEY2RVAL(context, key, key_size, table, related_object) \
245
+ (rb_grn_key_to_ruby_object(context, key, key_size, table, related_object))
246
+ #define RVAL2GRNKEY(object, context, key, domain, related_object) \
247
+ (rb_grn_key_from_ruby_object(object, context, key, domain, related_object))
248
+
249
+
250
+ grn_encoding rb_grn_encoding_from_ruby_object (VALUE object,
251
+ grn_ctx *context);
252
+ VALUE rb_grn_encoding_to_ruby_object (grn_encoding encoding);
253
+
254
+ grn_ctx *rb_grn_context_from_ruby_object (VALUE object);
255
+ VALUE rb_grn_context_to_ruby_object (grn_ctx *context);
256
+
257
+ grn_obj *rb_grn_object_from_ruby_object (VALUE object,
258
+ grn_ctx **context);
259
+ VALUE rb_grn_object_to_ruby_object (VALUE klass,
260
+ grn_ctx *context,
261
+ grn_obj *object,
262
+ rb_grn_boolean owner);
263
+ VALUE rb_grn_object_to_ruby_class (grn_obj *object);
264
+
265
+ grn_obj *rb_grn_database_from_ruby_object (VALUE object);
266
+ VALUE rb_grn_database_to_ruby_object (grn_ctx *context,
267
+ grn_obj *db,
268
+ rb_grn_boolean owner);
269
+
270
+ grn_obj *rb_grn_table_from_ruby_object (VALUE object,
271
+ grn_ctx **context);
272
+ VALUE rb_grn_table_to_ruby_object (grn_ctx *context,
273
+ grn_obj *table,
274
+ rb_grn_boolean owner);
275
+
276
+ grn_table_cursor *
277
+ rb_grn_table_cursor_from_ruby_object (VALUE object);
278
+ VALUE rb_grn_table_cursor_to_ruby_object (VALUE klass,
279
+ grn_ctx *context,
280
+ grn_table_cursor *cursor);
281
+ VALUE rb_grn_table_cursor_to_ruby_class (grn_table_cursor *cursor);
282
+
283
+ grn_obj *rb_grn_column_from_ruby_object (VALUE object,
284
+ grn_ctx **context);
285
+ VALUE rb_grn_column_to_ruby_object (VALUE klass,
286
+ grn_ctx *context,
287
+ grn_obj *column,
288
+ rb_grn_boolean owner);
289
+
290
+ grn_query *rb_grn_query_from_ruby_object (VALUE object);
291
+ VALUE rb_grn_query_to_ruby_object (grn_ctx *context,
292
+ grn_query *query);
293
+
294
+ grn_sel_operator
295
+ rb_grn_select_operator_from_ruby_object
296
+ (VALUE object);
297
+
298
+ grn_logger_info *
299
+ rb_grn_logger_from_ruby_object (VALUE object);
300
+
301
+ grn_obj *rb_grn_bulk_from_ruby_object (VALUE object,
302
+ grn_ctx *context,
303
+ grn_obj *bulk);
304
+ grn_obj *rb_grn_bulk_from_ruby_object_with_type
305
+ (VALUE object,
306
+ grn_ctx *context,
307
+ grn_obj *bulk,
308
+ grn_id type);
309
+ VALUE rb_grn_bulk_to_ruby_object (grn_ctx *context,
310
+ grn_obj *bulk,
311
+ VALUE related_object);
312
+ grn_obj *rb_grn_vector_from_ruby_object (VALUE object,
313
+ grn_ctx *context,
314
+ grn_obj *vector);
315
+ VALUE rb_grn_vector_to_ruby_object (grn_ctx *context,
316
+ grn_obj *vector);
317
+ grn_obj *rb_grn_uvector_from_ruby_object (VALUE object,
318
+ grn_ctx *context,
319
+ grn_obj *uvector);
320
+ VALUE rb_grn_uvector_to_ruby_object (grn_ctx *context,
321
+ grn_obj *uvector);
322
+
323
+ VALUE rb_grn_value_to_ruby_object (grn_ctx *context,
324
+ grn_obj *value,
325
+ grn_obj *range,
326
+ VALUE related_object);
327
+
328
+ grn_id rb_grn_id_from_ruby_object (VALUE object,
329
+ grn_ctx *context,
330
+ grn_obj *table,
331
+ VALUE related_object);
332
+
333
+ VALUE rb_grn_key_to_ruby_object (grn_ctx *context,
334
+ const void *key,
335
+ int key_size,
336
+ grn_obj *table,
337
+ VALUE related_object);
338
+ grn_obj *rb_grn_key_from_ruby_object (VALUE rb_key,
339
+ grn_ctx *context,
340
+ grn_obj *key,
341
+ grn_id domain_id,
342
+ VALUE related_object);
343
+
344
+ RB_GRN_END_DECLS
345
+
346
+ #endif
data/ext/rb-groonga.c ADDED
@@ -0,0 +1,98 @@
1
+ /* -*- c-file-style: "ruby" -*- */
2
+ /*
3
+ Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
4
+
5
+ This library is free software; you can redistribute it and/or
6
+ modify it under the terms of the GNU Lesser General Public
7
+ License version 2.1 as published by the Free Software Foundation.
8
+
9
+ This library is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public
15
+ License along with this library; if not, write to the Free Software
16
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+ */
18
+
19
+ #include "rb-grn.h"
20
+
21
+ extern grn_ctx grn_gctx;
22
+
23
+ static void
24
+ finish_groonga (VALUE data)
25
+ {
26
+ grn_ctx *context;
27
+
28
+ context = grn_gctx.next;
29
+ while (RB_GRN_TRUE) {
30
+ grn_ctx *next_context = context->next;
31
+
32
+ grn_ctx_fin(context);
33
+ if (next_context == &grn_gctx)
34
+ break;
35
+ context = next_context;
36
+ }
37
+ grn_fin();
38
+ }
39
+
40
+ void
41
+ Init_groonga (void)
42
+ {
43
+ VALUE mGrn;
44
+ VALUE cGrnBuildVersion, cGrnBindingsVersion;
45
+
46
+ mGrn = rb_define_module("Groonga");
47
+
48
+ cGrnBuildVersion = rb_ary_new3(3,
49
+ INT2NUM(GRN_MAJOR_VERSION),
50
+ INT2NUM(GRN_MINOR_VERSION),
51
+ INT2NUM(GRN_MICRO_VERSION));
52
+ rb_obj_freeze(cGrnBuildVersion);
53
+ /*
54
+ * ビルドしたgroongaのバージョン。<tt>[メジャーバージョン,
55
+ * マイナーバージョン, マイクロバージョン]</tt>の配列。
56
+ */
57
+ rb_define_const(mGrn, "BUILD_VERSION", cGrnBuildVersion);
58
+
59
+ /* FIXME: API to get runtime groonga version doesn't exist */
60
+
61
+ /*
62
+ * 利用しているgroongaのバージョン(にしたい。現在は
63
+ * BUILD_VERSIONと同じ)。<tt>[メジャーバージョ
64
+ * ン, マイナーバージョン, マイクロバージョン]</tt>の配列。
65
+ */
66
+ rb_define_const(mGrn, "VERSION", cGrnBuildVersion);
67
+
68
+ cGrnBindingsVersion = rb_ary_new3(3,
69
+ INT2NUM(RB_GRN_MAJOR_VERSION),
70
+ INT2NUM(RB_GRN_MINOR_VERSION),
71
+ INT2NUM(RB_GRN_MICRO_VERSION));
72
+ rb_obj_freeze(cGrnBindingsVersion);
73
+ /*
74
+ * Ruby/groongaのバージョン。<tt>[メジャーバージョン, マ
75
+ * イナーバージョン, マイクロバージョン]</tt>の配列。
76
+ */
77
+ rb_define_const(mGrn, "BINDINGS_VERSION", cGrnBindingsVersion);
78
+
79
+ rb_grn_init_utils(mGrn);
80
+ rb_grn_init_exception(mGrn);
81
+ rb_grn_init_encoding(mGrn);
82
+ rb_grn_init_context(mGrn);
83
+ rb_grn_init_object(mGrn);
84
+ rb_grn_init_database(mGrn);
85
+ rb_grn_init_table(mGrn);
86
+ rb_grn_init_table_cursor(mGrn);
87
+ rb_grn_init_type(mGrn);
88
+ rb_grn_init_procedure(mGrn);
89
+ rb_grn_init_column(mGrn);
90
+ rb_grn_init_accessor(mGrn);
91
+ rb_grn_init_record(mGrn);
92
+ rb_grn_init_query(mGrn);
93
+ rb_grn_init_logger(mGrn);
94
+ rb_grn_init_snippet(mGrn);
95
+
96
+ rb_grn_rc_check(grn_init(), Qnil);
97
+ rb_set_end_proc(finish_groonga, Qnil);
98
+ }
data/extconf.rb ADDED
@@ -0,0 +1,171 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License version 2.1 as published by the Free Software Foundation.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+
18
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
19
+
20
+ require 'English'
21
+ require 'mkmf'
22
+ require 'pkg-config'
23
+ require 'fileutils'
24
+
25
+ checking_for(checking_message("GCC")) do
26
+ if macro_defined?("__GNUC__", "")
27
+ $CFLAGS += ' -Wall'
28
+ true
29
+ else
30
+ false
31
+ end
32
+ end
33
+
34
+ package_name = "groonga"
35
+ module_name = "groonga"
36
+ ext_dir_name = "ext"
37
+ src_dir = File.join(File.expand_path(File.dirname(__FILE__)), ext_dir_name)
38
+ major, minor, micro = 0, 0, 4
39
+
40
+ def install_groonga_locally(major, minor, micro)
41
+ require 'open-uri'
42
+ require 'shellwords'
43
+
44
+ tar_gz = "groonga-#{major}.#{minor}.#{micro}.tar.gz"
45
+ base_dir = File.join(File.dirname(__FILE__), "vendor")
46
+ install_dir = File.expand_path(File.join(base_dir, "local"))
47
+ FileUtils.mkdir_p(base_dir)
48
+
49
+ Dir.chdir(base_dir) do
50
+ url = "http://groonga.org/files/groonga/#{tar_gz}"
51
+ message("downloading %s...", url)
52
+ open(url, "rb") do |input|
53
+ File.open(tar_gz, "wb") do |output|
54
+ while (buffer = input.read(1024))
55
+ output.print(buffer)
56
+ end
57
+ end
58
+ end
59
+ message(" done\n")
60
+
61
+ message("extracting...")
62
+ if xsystem("tar xfz #{tar_gz}")
63
+ message(" done\n")
64
+ else
65
+ message(" failed\n")
66
+ exit 1
67
+ end
68
+
69
+ groonga_source_dir = "groonga-#{major}.#{minor}.#{micro}"
70
+ Dir.chdir(groonga_source_dir) do
71
+ message("configuring...")
72
+ if xsystem("./configure --prefix=#{Shellwords.escape(install_dir)}")
73
+ message(" done\n")
74
+ else
75
+ message(" failed\n")
76
+ exit 1
77
+ end
78
+
79
+ message("building (maybe long time)...")
80
+ if xsystem("make")
81
+ message(" done\n")
82
+ else
83
+ message(" failed\n")
84
+ exit 1
85
+ end
86
+
87
+ message("installing...")
88
+ if xsystem("make install")
89
+ message(" done\n")
90
+ else
91
+ message(" failed\n")
92
+ exit 1
93
+ end
94
+ end
95
+ end
96
+
97
+ pkg_config_dir = File.join(install_dir, "lib", "pkgconfig")
98
+ PackageConfig.prepend_default_path(pkg_config_dir)
99
+
100
+ lib_dir = File.join(install_dir, "lib")
101
+ $LDFLAGS += " -Wl,-rpath,#{Shellwords.escape(lib_dir)}"
102
+ end
103
+
104
+ unless PKGConfig.have_package(package_name, major, minor, micro)
105
+ install_groonga_locally(major, minor, micro)
106
+ PKGConfig.have_package(package_name, major, minor, micro) or exit 1
107
+ end
108
+
109
+ real_version = PKGConfig.modversion(package_name)
110
+ real_major, real_minor, real_micro = real_version.split(/\./)
111
+ $defs << "-DGRN_MAJOR_VERSION=#{real_major}"
112
+ $defs << "-DGRN_MINOR_VERSION=#{real_minor}"
113
+ $defs << "-DGRN_MICRO_VERSION=#{real_micro}"
114
+
115
+ have_header("ruby/st.h") unless have_macro("HAVE_RUBY_ST_H", "ruby.h")
116
+ have_func("rb_errinfo", "ruby.h")
117
+ have_type("enum ruby_value_type", "ruby.h")
118
+
119
+ create_makefile(module_name, src_dir)
120
+
121
+ makefile = File.read("Makefile")
122
+ File.open("Makefile", "w") do |f|
123
+ objs = []
124
+ co = nil
125
+ makefile.each_line do |line|
126
+ case line
127
+ when /^DLLIB\s*=\s*/
128
+ dllib = $POSTMATCH
129
+ f.puts("DLLIB = #{ext_dir_name}/#{dllib}")
130
+ f.puts("IMPLIB = #{ext_dir_name}/libruby-#{dllib.gsub(/\..+?$/, '.lib')}")
131
+ when /^(SRCS)\s*=\s*/
132
+ name = $1
133
+ vars = $POSTMATCH.split.collect {|var| "$(srcdir)/#{var}"}.join(" ")
134
+ f.puts("#{name} = #{vars}")
135
+ when /^(OBJS|CLEANLIBS|CLEANOBJS)\s*=\s*/
136
+ name = $1
137
+ vars = $POSTMATCH.split.collect {|var| "#{ext_dir_name}/#{var}"}
138
+ objs = vars if name == "OBJS"
139
+ vars = vars.join(" ")
140
+ f.puts("#{name} = #{vars}")
141
+ when /^\t\$\(CC\)/
142
+ if PKGConfig.msvc?
143
+ output_option = "-Fo"
144
+ else
145
+ output_option = "-o"
146
+ end
147
+ unless /#{Regexp.escape(output_option)}/ =~ line
148
+ line = "#{line.chomp} #{output_option}$@"
149
+ end
150
+ co = line
151
+ f.puts(line)
152
+ else
153
+ f.puts(line)
154
+ end
155
+ end
156
+
157
+ if co and !objs.empty?
158
+ f.puts
159
+ if PKGConfig.msvc?
160
+ f.puts "{$(srcdir)}.c{#{ext_dir_name}}.obj:"
161
+ f.puts co
162
+ else
163
+ objs.each do |obj|
164
+ f.puts "#{obj}: $(srcdir)/#{File.basename(obj).sub(/\..+?$/, '.c')}"
165
+ f.puts co
166
+ end
167
+ end
168
+ end
169
+ end
170
+
171
+ FileUtils.mkdir_p(ext_dir_name)