rroonga 3.0.1 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,26 @@
1
1
  h1. NEWS
2
2
 
3
+ h2(#3-0-2). 3.0.2: 2013-05-29
4
+
5
+ h3. Improvements
6
+
7
+ * Required groonga >= 3.0.4.
8
+ * Supported set/get a vector of Time.
9
+ * [grndump] Stopped to dump index only tables. They are needless.
10
+ * Added {Groonga::Record#to_json}.
11
+ * Added {Groonga::IndexColumn#add}.
12
+ * Added {Groonga::IndexColumn#delete}.
13
+ * Added {Groonga::IndexColumn#update}.
14
+ * Deprecated {Groonga::IndexColumn#[]=}. Use {Groonga::IndexColumn#add},
15
+ {Groonga::IndexColumn#delete} or {Groonga::IndexColumn#update} instead.
16
+ * Added {Groonga::Table#have_n_sub_records_space?}.
17
+ * [grndump] Don't dump "register PLUGIN" when schema dump is disabled.
18
+
19
+ h3. Fixes
20
+
21
+ * [grndump]
22
+ Fixed a bug that reference tables may be dumpped before referenced tables.
23
+
3
24
  h2(#3-0-1). 3.0.1: 2013-05-01
4
25
 
5
26
  h3. Improvements
@@ -1,6 +1,6 @@
1
1
  /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
2
  /*
3
- Copyright (C) 2009-2012 Kouhei Sutou <kou@clear-code.com>
3
+ Copyright (C) 2009-2013 Kouhei Sutou <kou@clear-code.com>
4
4
 
5
5
  This library is free software; you can redistribute it and/or
6
6
  modify it under the terms of the GNU Lesser General Public
@@ -157,6 +157,8 @@ rb_grn_index_column_deconstruct (RbGrnIndexColumn *rb_grn_index_column,
157
157
  * 新しい値を指定する。 _value_ を指定した場合と _options_ で
158
158
  * @{:value => value}@ を指定した場合は同じ動作とな
159
159
  * る。
160
+ *
161
+ * @deprecated Since 3.0.2. Use {#add}, {#delete} or {#update} instead.
160
162
  */
161
163
  static VALUE
162
164
  rb_grn_index_column_array_set (VALUE self, VALUE rb_id, VALUE rb_value)
@@ -219,6 +221,349 @@ rb_grn_index_column_array_set (VALUE self, VALUE rb_id, VALUE rb_value)
219
221
  return original_rb_value;
220
222
  }
221
223
 
224
+ /*
225
+ * Adds a record that has @value@ content to inverted index for fast
226
+ * fulltext serach. Normally, this method is not used
227
+ * explicitly. Inverted index for fulltext search is updated
228
+ * automatically by using @:source@ option of
229
+ * {Groonga::Table#define_index_column}.
230
+ *
231
+ * @example Adds sentences of an article to index
232
+ * articles = Groonga::Array.create(:name => "Articles")
233
+ * articles.define_column("title", "ShortText")
234
+ * articles.define_column("content", "Text")
235
+ *
236
+ * terms = Groonga::Hash.create(:name => "Terms",
237
+ * :key_type => "ShortText",
238
+ * :default_tokenizer => "TokenBigram")
239
+ * content_index = terms.define_index_column("content", articles,
240
+ * :with_position => true,
241
+ * :with_section => true)
242
+ *
243
+ * content = <<-CONTENT
244
+ * Groonga is a fast and accurate full text search engine based on
245
+ * inverted index. One of the characteristics of groonga is that a
246
+ * newly registered document instantly appears in search
247
+ * results. Also, groonga allows updates without read locks. These
248
+ * characteristics result in superior performance on real-time
249
+ * applications.
250
+ *
251
+ * Groonga is also a column-oriented database management system
252
+ * (DBMS). Compared with well-known row-oriented systems, such as
253
+ * MySQL and PostgreSQL, column-oriented systems are more suited for
254
+ * aggregate queries. Due to this advantage, groonga can cover
255
+ * weakness of row-oriented systems.
256
+ *
257
+ * The basic functions of groonga are provided in a C library. Also,
258
+ * libraries for using groonga in other languages, such as Ruby, are
259
+ * provided by related projects. In addition, groonga-based storage
260
+ * engines are provided for MySQL and PostgreSQL. These libraries
261
+ * and storage engines allow any application to use groonga. See
262
+ * usage examples.
263
+ * CONTENT
264
+ *
265
+ * groonga = articles.add(:title => "groonga", :content => content)
266
+ *
267
+ * content.split(/\n{2,}/).each_with_index do |sentence, i|
268
+ * content_index.add(groonga, sentence, :section => i + 1)
269
+ * end
270
+ *
271
+ * content_index.search("engine").each do |record|
272
+ * p record.key["title"] # -> "groonga"
273
+ * end
274
+ *
275
+ * @overload add(record, value, options={})
276
+ * @param [Groonga::Record, Integer] record
277
+ * The record that has a @value@ as its value. It can be Integer as
278
+ * record id.
279
+ * @param [String] value
280
+ * The value of the @record@.
281
+ * @param [::Hash] options
282
+ * The options.
283
+ * @option options [Integer] :section (1)
284
+ * The section number. It is one-origin.
285
+ *
286
+ * You must specify @{:with_section => true}@ in
287
+ * {Groonga::Table#define_index_column} to use this option.
288
+ * @return [void]
289
+ *
290
+ * @since 3.0.2
291
+ */
292
+ static VALUE
293
+ rb_grn_index_column_add (int argc, VALUE *argv, VALUE self)
294
+ {
295
+ grn_ctx *context = NULL;
296
+ grn_obj *column, *range;
297
+ grn_rc rc;
298
+ grn_id id;
299
+ unsigned int section;
300
+ grn_obj *new_value;
301
+ VALUE rb_record, rb_value, rb_options, rb_section;
302
+
303
+ rb_scan_args(argc, argv, "21", &rb_record, &rb_value, &rb_options);
304
+
305
+ rb_grn_index_column_deconstruct(SELF(self), &column, &context,
306
+ NULL, NULL,
307
+ &new_value, NULL,
308
+ NULL, &range,
309
+ NULL, NULL);
310
+
311
+ id = RVAL2GRNID(rb_record, context, range, self);
312
+
313
+ GRN_BULK_REWIND(new_value);
314
+ RVAL2GRNBULK(rb_value, context, new_value);
315
+
316
+ rb_grn_scan_options(rb_options,
317
+ "section", &rb_section,
318
+ NULL);
319
+
320
+ if (NIL_P(rb_section)) {
321
+ section = 1;
322
+ } else {
323
+ section = NUM2UINT(rb_section);
324
+ }
325
+
326
+ rc = grn_column_index_update(context, column, id, section, NULL, new_value);
327
+ rb_grn_context_check(context, self);
328
+ rb_grn_rc_check(rc, self);
329
+
330
+ return self;
331
+ }
332
+
333
+ /*
334
+ * Deletes a record that has @value@ content from inverted
335
+ * index. Normally, this method is not used explicitly. Inverted index
336
+ * for fulltext search is updated automatically by using @:source@
337
+ * option of {Groonga::Table#define_index_column}.
338
+ *
339
+ * @example Deletes sentences of an article to index
340
+ * articles = Groonga::Array.create(:name => "Articles")
341
+ * articles.define_column("title", "ShortText")
342
+ * articles.define_column("content", "Text")
343
+ *
344
+ * terms = Groonga::Hash.create(:name => "Terms",
345
+ * :key_type => "ShortText",
346
+ * :default_tokenizer => "TokenBigram")
347
+ * content_index = terms.define_index_column("content", articles,
348
+ * :with_position => true,
349
+ * :with_section => true)
350
+ *
351
+ * content = <<-CONTENT
352
+ * Groonga is a fast and accurate full text search engine based on
353
+ * inverted index. One of the characteristics of groonga is that a
354
+ * newly registered document instantly appears in search
355
+ * results. Also, groonga allows updates without read locks. These
356
+ * characteristics result in superior performance on real-time
357
+ * applications.
358
+ *
359
+ * Groonga is also a column-oriented database management system
360
+ * (DBMS). Compared with well-known row-oriented systems, such as
361
+ * MySQL and PostgreSQL, column-oriented systems are more suited for
362
+ * aggregate queries. Due to this advantage, groonga can cover
363
+ * weakness of row-oriented systems.
364
+ *
365
+ * The basic functions of groonga are provided in a C library. Also,
366
+ * libraries for using groonga in other languages, such as Ruby, are
367
+ * provided by related projects. In addition, groonga-based storage
368
+ * engines are provided for MySQL and PostgreSQL. These libraries
369
+ * and storage engines allow any application to use groonga. See
370
+ * usage examples.
371
+ * CONTENT
372
+ *
373
+ * groonga = articles.add(:title => "groonga", :content => content)
374
+ *
375
+ * content.split(/\n{2,}/).each_with_index do |sentence, i|
376
+ * content_index.add(groonga, sentence, :section => i + 1)
377
+ * end
378
+ *
379
+ * content_index.search("engine").each do |record|
380
+ * p record.key["title"] # -> "groonga"
381
+ * end
382
+ *
383
+ * content.split(/\n{2,}/).each_with_index do |sentence, i|
384
+ * content_index.delete(groonga, sentence, :section => i + 1)
385
+ * end
386
+ *
387
+ * p content_index.search("engine").size # -> 0
388
+ *
389
+ * @overload delete(record, value, options={})
390
+ * @param [Groonga::Record, Integer] record
391
+ * The record that has a @value@ as its value. It can be Integer as
392
+ * record id.
393
+ * @param [String] value
394
+ * The value of the @record@.
395
+ * @param [::Hash] options
396
+ * The options.
397
+ * @option options [Integer] :section (1)
398
+ * The section number. It is one-origin.
399
+ *
400
+ * You must specify @{:with_section => true}@ in
401
+ * {Groonga::Table#define_index_column} to use this option.
402
+ * @return [void]
403
+ *
404
+ * @since 3.0.2
405
+ */
406
+ static VALUE
407
+ rb_grn_index_column_delete (int argc, VALUE *argv, VALUE self)
408
+ {
409
+ grn_ctx *context = NULL;
410
+ grn_obj *column, *range;
411
+ grn_rc rc;
412
+ grn_id id;
413
+ unsigned int section;
414
+ grn_obj *old_value;
415
+ VALUE rb_record, rb_value, rb_options, rb_section;
416
+
417
+ rb_scan_args(argc, argv, "21", &rb_record, &rb_value, &rb_options);
418
+
419
+ rb_grn_index_column_deconstruct(SELF(self), &column, &context,
420
+ NULL, NULL,
421
+ NULL, &old_value,
422
+ NULL, &range,
423
+ NULL, NULL);
424
+
425
+ id = RVAL2GRNID(rb_record, context, range, self);
426
+
427
+ GRN_BULK_REWIND(old_value);
428
+ RVAL2GRNBULK(rb_value, context, old_value);
429
+
430
+ rb_grn_scan_options(rb_options,
431
+ "section", &rb_section,
432
+ NULL);
433
+
434
+ if (NIL_P(rb_section)) {
435
+ section = 1;
436
+ } else {
437
+ section = NUM2UINT(rb_section);
438
+ }
439
+
440
+ rc = grn_column_index_update(context, column, id, section, old_value, NULL);
441
+ rb_grn_context_check(context, self);
442
+ rb_grn_rc_check(rc, self);
443
+
444
+ return self;
445
+ }
446
+
447
+ /*
448
+ * Updates a record that has @new_value@ as new content and
449
+ * @old_value@ as old content in inverted index. Normally, this method
450
+ * is not used explicitly. Inverted index for fulltext search is
451
+ * updated automatically by using @:source@ option of
452
+ * {Groonga::Table#define_index_column}.
453
+ *
454
+ * @example Updates sentences of an article to index
455
+ * articles = Groonga::Array.create(:name => "Articles")
456
+ * articles.define_column("title", "ShortText")
457
+ * articles.define_column("content", "Text")
458
+ *
459
+ * terms = Groonga::Hash.create(:name => "Terms",
460
+ * :key_type => "ShortText",
461
+ * :default_tokenizer => "TokenBigram")
462
+ * content_index = terms.define_index_column("content", articles,
463
+ * :with_position => true,
464
+ * :with_section => true)
465
+ *
466
+ * old_sentence = <<-SENTENCE
467
+ * Groonga is a fast and accurate full text search engine based on
468
+ * inverted index. One of the characteristics of groonga is that a
469
+ * newly registered document instantly appears in search
470
+ * results. Also, groonga allows updates without read locks. These
471
+ * characteristics result in superior performance on real-time
472
+ * applications.
473
+ * SENTENCE
474
+ *
475
+ * new_sentence = <<-SENTENCE
476
+ * Groonga is also a column-oriented database management system
477
+ * (DBMS). Compared with well-known row-oriented systems, such as
478
+ * MySQL and PostgreSQL, column-oriented systems are more suited for
479
+ * aggregate queries. Due to this advantage, groonga can cover
480
+ * weakness of row-oriented systems.
481
+ * SENTENCE
482
+ *
483
+ * groonga = articles.add(:title => "groonga", :content => old_sentence)
484
+ *
485
+ * content_index.add(groonga, old_sentence, :section => 1)
486
+ * p content_index.search("engine").size # -> 1
487
+ * p content_index.search("MySQL").size # -> 0
488
+ *
489
+ * groonga[:content] = new_sentence
490
+ * content_index.update(groonga, old_sentence, new_sentence, :section => 1)
491
+ * p content_index.search("engine").size # -> 0
492
+ * p content_index.search("MySQL").size # -> 1
493
+ *
494
+ * @overload update(record, old_value, new_value, options={})
495
+ * @param [Groonga::Record, Integer] record
496
+ * The record that has a @new_value@ as its new value and
497
+ * @old_value@ as its old value. It can be Integer as record id.
498
+ * @param [String] old_value
499
+ * The old value of the @record@.
500
+ * @param [String] new_value
501
+ * The new value of the @record@.
502
+ * @param [::Hash] options
503
+ * The options.
504
+ * @option options [Integer] :section (1)
505
+ * The section number. It is one-origin.
506
+ *
507
+ * You must specify @{:with_section => true}@ in
508
+ * {Groonga::Table#define_index_column} to use this option.
509
+ * @return [void]
510
+ *
511
+ * @since 3.0.2
512
+ */
513
+ static VALUE
514
+ rb_grn_index_column_update (int argc, VALUE *argv, VALUE self)
515
+ {
516
+ grn_ctx *context = NULL;
517
+ grn_obj *column, *range;
518
+ grn_rc rc;
519
+ grn_id id;
520
+ unsigned int section;
521
+ grn_obj *old_value, *new_value;
522
+ VALUE rb_record, rb_old_value, rb_new_value, rb_options, rb_section;
523
+
524
+ rb_scan_args(argc, argv, "31",
525
+ &rb_record, &rb_old_value, &rb_new_value, &rb_options);
526
+
527
+ rb_grn_index_column_deconstruct(SELF(self), &column, &context,
528
+ NULL, NULL,
529
+ &new_value, &old_value,
530
+ NULL, &range,
531
+ NULL, NULL);
532
+
533
+ id = RVAL2GRNID(rb_record, context, range, self);
534
+
535
+ if (NIL_P(rb_old_value)) {
536
+ old_value = NULL;
537
+ } else {
538
+ GRN_BULK_REWIND(old_value);
539
+ RVAL2GRNBULK(rb_old_value, context, old_value);
540
+ }
541
+
542
+ if (NIL_P(rb_new_value)) {
543
+ new_value = NULL;
544
+ } else {
545
+ GRN_BULK_REWIND(new_value);
546
+ RVAL2GRNBULK(rb_new_value, context, new_value);
547
+ }
548
+
549
+ rb_grn_scan_options(rb_options,
550
+ "section", &rb_section,
551
+ NULL);
552
+
553
+ if (NIL_P(rb_section)) {
554
+ section = 1;
555
+ } else {
556
+ section = NUM2UINT(rb_section);
557
+ }
558
+
559
+ rc = grn_column_index_update(context, column, id, section,
560
+ old_value, new_value);
561
+ rb_grn_context_check(context, self);
562
+ rb_grn_rc_check(rc, self);
563
+
564
+ return self;
565
+ }
566
+
222
567
  /*
223
568
  * インデックス対象となっている {Groonga::Column} の配列を返す。
224
569
  *
@@ -627,6 +972,13 @@ rb_grn_init_index_column (VALUE mGrn)
627
972
  rb_define_method(rb_cGrnIndexColumn, "[]=",
628
973
  rb_grn_index_column_array_set, 2);
629
974
 
975
+ rb_define_method(rb_cGrnIndexColumn, "add",
976
+ rb_grn_index_column_add, -1);
977
+ rb_define_method(rb_cGrnIndexColumn, "delete",
978
+ rb_grn_index_column_delete, -1);
979
+ rb_define_method(rb_cGrnIndexColumn, "update",
980
+ rb_grn_index_column_update, -1);
981
+
630
982
  rb_define_method(rb_cGrnIndexColumn, "sources",
631
983
  rb_grn_index_column_get_sources, 0);
632
984
  rb_define_method(rb_cGrnIndexColumn, "sources=",
@@ -39,126 +39,126 @@ rb_grn_object_from_ruby_object (VALUE object, grn_ctx **context)
39
39
  return NULL;
40
40
 
41
41
  if (context && *context) {
42
- grn_obj *grn_object;
43
- if (RVAL2CBOOL(rb_obj_is_kind_of(object, rb_cString))) {
44
- const char *name;
45
- unsigned int name_size;
46
-
47
- name = StringValuePtr(object);
48
- name_size = RSTRING_LEN(object);
49
- grn_object = rb_grn_context_get_backward_compatibility(*context,
50
- name,
51
- name_size);
52
- rb_grn_context_check(*context, object);
53
- if (!grn_object)
54
- rb_raise(rb_eArgError,
55
- "unregistered groonga object: name: <%s>",
56
- rb_grn_inspect(object));
57
- return grn_object;
58
- } else if (RVAL2CBOOL(rb_obj_is_kind_of(object, rb_cInteger))) {
59
- grn_object = grn_ctx_at(*context, NUM2UINT(object));
60
- rb_grn_context_check(*context, object);
61
- if (!grn_object)
62
- rb_raise(rb_eArgError,
63
- "unregistered groonga object: ID: <%s>",
64
- rb_grn_inspect(object));
65
- return grn_object;
66
- }
42
+ grn_obj *grn_object;
43
+ if (RVAL2CBOOL(rb_obj_is_kind_of(object, rb_cString))) {
44
+ const char *name;
45
+ unsigned int name_size;
46
+
47
+ name = StringValuePtr(object);
48
+ name_size = RSTRING_LEN(object);
49
+ grn_object = rb_grn_context_get_backward_compatibility(*context,
50
+ name,
51
+ name_size);
52
+ rb_grn_context_check(*context, object);
53
+ if (!grn_object)
54
+ rb_raise(rb_eArgError,
55
+ "unregistered groonga object: name: <%s>",
56
+ rb_grn_inspect(object));
57
+ return grn_object;
58
+ } else if (RVAL2CBOOL(rb_obj_is_kind_of(object, rb_cInteger))) {
59
+ grn_object = grn_ctx_at(*context, NUM2UINT(object));
60
+ rb_grn_context_check(*context, object);
61
+ if (!grn_object)
62
+ rb_raise(rb_eArgError,
63
+ "unregistered groonga object: ID: <%s>",
64
+ rb_grn_inspect(object));
65
+ return grn_object;
66
+ }
67
67
  }
68
68
 
69
69
  if (!RVAL2CBOOL(rb_obj_is_kind_of(object, rb_cGrnObject))) {
70
- rb_raise(rb_eTypeError, "not a groonga object: <%s>",
71
- rb_grn_inspect(object));
70
+ rb_raise(rb_eTypeError, "not a groonga object: <%s>",
71
+ rb_grn_inspect(object));
72
72
  }
73
73
 
74
74
  Data_Get_Struct(object, RbGrnObject, rb_grn_object);
75
75
  if (!rb_grn_object)
76
- rb_raise(rb_eGrnError, "groonga object is NULL");
76
+ rb_raise(rb_eGrnError, "groonga object is NULL");
77
77
 
78
78
  if (!rb_grn_object->object) {
79
- rb_raise(rb_eGrnClosed,
79
+ rb_raise(rb_eGrnClosed,
80
80
  "can't access already closed groonga object: %s",
81
81
  rb_grn_inspect(CLASS_OF(rb_grn_object->self)));
82
82
  }
83
83
 
84
84
  if (context && !*context)
85
- *context = rb_grn_object->context;
85
+ *context = rb_grn_object->context;
86
86
 
87
87
  return rb_grn_object->object;
88
88
  }
89
89
 
90
90
  static void
91
91
  rb_grn_object_run_finalizer (grn_ctx *context, grn_obj *grn_object,
92
- RbGrnObject *rb_grn_object)
92
+ RbGrnObject *rb_grn_object)
93
93
  {
94
94
  RbGrnContext *rb_grn_context = NULL;
95
95
 
96
96
  if (rb_grn_exited)
97
- return;
97
+ return;
98
98
 
99
99
  grn_obj_set_finalizer(context, grn_object, NULL);
100
100
 
101
101
  debug("finalize: %p:%p:%p:%p:%p:%p %s(%#x)\n",
102
- context, grn_object, rb_grn_object,
103
- rb_grn_object->context, rb_grn_object->object,
104
- rb_grn_object->rb_grn_context,
105
- rb_grn_inspect_type(grn_object->header.type),
106
- grn_object->header.type);
102
+ context, grn_object, rb_grn_object,
103
+ rb_grn_object->context, rb_grn_object->object,
104
+ rb_grn_object->rb_grn_context,
105
+ rb_grn_inspect_type(grn_object->header.type),
106
+ grn_object->header.type);
107
107
 
108
108
  rb_grn_context = rb_grn_object->rb_grn_context;
109
109
  rb_grn_object->have_finalizer = GRN_FALSE;
110
110
 
111
111
  switch (grn_object->header.type) {
112
112
  case GRN_DB:
113
- rb_grn_database_finalizer(context, rb_grn_context,
114
- grn_object, rb_grn_object);
115
- break;
113
+ rb_grn_database_finalizer(context, rb_grn_context,
114
+ grn_object, rb_grn_object);
115
+ break;
116
116
  case GRN_TYPE:
117
117
  case GRN_PROC:
118
118
  case GRN_CURSOR_TABLE_HASH_KEY:
119
119
  case GRN_CURSOR_TABLE_PAT_KEY:
120
120
  case GRN_CURSOR_TABLE_DAT_KEY:
121
121
  case GRN_CURSOR_TABLE_NO_KEY:
122
- break;
122
+ break;
123
123
  case GRN_TABLE_HASH_KEY:
124
124
  case GRN_TABLE_PAT_KEY:
125
125
  case GRN_TABLE_DAT_KEY:
126
- rb_grn_table_key_support_finalizer(context, grn_object,
127
- RB_GRN_TABLE_KEY_SUPPORT(rb_grn_object));
128
- break;
126
+ rb_grn_table_key_support_finalizer(context, grn_object,
127
+ RB_GRN_TABLE_KEY_SUPPORT(rb_grn_object));
128
+ break;
129
129
  case GRN_TABLE_NO_KEY:
130
- rb_grn_table_finalizer(context, grn_object,
131
- RB_GRN_TABLE(rb_grn_object));
132
- break;
130
+ rb_grn_table_finalizer(context, grn_object,
131
+ RB_GRN_TABLE(rb_grn_object));
132
+ break;
133
133
  case GRN_CURSOR_COLUMN_INDEX:
134
- break;
134
+ break;
135
135
  case GRN_COLUMN_FIX_SIZE:
136
136
  case GRN_COLUMN_VAR_SIZE:
137
- rb_grn_column_finalizer(context, grn_object,
138
- RB_GRN_COLUMN(rb_grn_object));
139
- break;
137
+ rb_grn_column_finalizer(context, grn_object,
138
+ RB_GRN_COLUMN(rb_grn_object));
139
+ break;
140
140
  case GRN_COLUMN_INDEX:
141
- rb_grn_index_column_finalizer(context, grn_object,
142
- RB_GRN_INDEX_COLUMN(rb_grn_object));
143
- break;
141
+ rb_grn_index_column_finalizer(context, grn_object,
142
+ RB_GRN_INDEX_COLUMN(rb_grn_object));
143
+ break;
144
144
  case GRN_ACCESSOR:
145
- rb_grn_accessor_finalizer(context, grn_object,
146
- RB_GRN_ACCESSOR(rb_grn_object));
147
- break;
145
+ rb_grn_accessor_finalizer(context, grn_object,
146
+ RB_GRN_ACCESSOR(rb_grn_object));
147
+ break;
148
148
  case GRN_EXPR:
149
- rb_grn_expression_finalizer(context, grn_object,
150
- RB_GRN_EXPRESSION(rb_grn_object));
151
- break;
149
+ rb_grn_expression_finalizer(context, grn_object,
150
+ RB_GRN_EXPRESSION(rb_grn_object));
151
+ break;
152
152
  case GRN_SNIP:
153
- rb_grn_snippet_finalizer(context, grn_object,
154
- RB_GRN_SNIPPET(rb_grn_object));
155
- break;
153
+ rb_grn_snippet_finalizer(context, grn_object,
154
+ RB_GRN_SNIPPET(rb_grn_object));
155
+ break;
156
156
  default:
157
- rb_raise(rb_eTypeError,
158
- "unsupported groonga object type for finalizer: %s(%#x)",
159
- rb_grn_inspect_type(grn_object->header.type),
160
- grn_object->header.type);
161
- break;
157
+ rb_raise(rb_eTypeError,
158
+ "unsupported groonga object type for finalizer: %s(%#x)",
159
+ rb_grn_inspect_type(grn_object->header.type),
160
+ grn_object->header.type);
161
+ break;
162
162
  }
163
163
 
164
164
  rb_grn_object->rb_grn_context = NULL;
@@ -168,13 +168,13 @@ rb_grn_object_run_finalizer (grn_ctx *context, grn_obj *grn_object,
168
168
 
169
169
  static grn_obj *
170
170
  rb_grn_object_finalizer (grn_ctx *context, int n_args, grn_obj **grn_objects,
171
- grn_user_data *user_data)
171
+ grn_user_data *user_data)
172
172
  {
173
173
  RbGrnObject *rb_grn_object;
174
174
  grn_obj *grn_object = *grn_objects;
175
175
 
176
176
  if (rb_grn_exited)
177
- return NULL;
177
+ return NULL;
178
178
 
179
179
  rb_grn_object = user_data->ptr;
180
180
 
@@ -193,30 +193,30 @@ rb_grn_object_free (RbGrnObject *rb_grn_object)
193
193
  context = rb_grn_object->context;
194
194
  grn_object = rb_grn_object->object;
195
195
  debug("rb-free: %p:%p:%p; %d:%d\n", context, grn_object, rb_grn_object,
196
- rb_grn_object->have_finalizer, rb_grn_object->need_close);
196
+ rb_grn_object->have_finalizer, rb_grn_object->need_close);
197
197
  if (!rb_grn_exited && context && grn_object &&
198
- (rb_grn_object->have_finalizer || rb_grn_object->need_close)) {
199
- grn_user_data *user_data = NULL;
200
-
201
- if (rb_grn_object->have_finalizer) {
202
- user_data = grn_obj_user_data(context, grn_object);
203
- }
204
- debug("type: %s(%#x); need_close: %d; user_data: %p; ptr: %p\n",
205
- rb_grn_inspect_type(grn_object->header.type),
206
- grn_object->header.type,
207
- rb_grn_object->need_close,
208
- user_data,
209
- user_data ? user_data->ptr : NULL);
210
- if (rb_grn_object->have_finalizer) {
211
- if (user_data && user_data->ptr) {
212
- rb_grn_object_finalizer(context, 1, &grn_object, user_data);
213
- } else {
214
- rb_grn_object_run_finalizer(context, grn_object, rb_grn_object);
215
- }
216
- }
217
- if (rb_grn_object->need_close) {
218
- grn_obj_unlink(context, grn_object);
219
- }
198
+ (rb_grn_object->have_finalizer || rb_grn_object->need_close)) {
199
+ grn_user_data *user_data = NULL;
200
+
201
+ if (rb_grn_object->have_finalizer) {
202
+ user_data = grn_obj_user_data(context, grn_object);
203
+ }
204
+ debug("type: %s(%#x); need_close: %d; user_data: %p; ptr: %p\n",
205
+ rb_grn_inspect_type(grn_object->header.type),
206
+ grn_object->header.type,
207
+ rb_grn_object->need_close,
208
+ user_data,
209
+ user_data ? user_data->ptr : NULL);
210
+ if (rb_grn_object->have_finalizer) {
211
+ if (user_data && user_data->ptr) {
212
+ rb_grn_object_finalizer(context, 1, &grn_object, user_data);
213
+ } else {
214
+ rb_grn_object_run_finalizer(context, grn_object, rb_grn_object);
215
+ }
216
+ }
217
+ if (rb_grn_object->need_close) {
218
+ grn_obj_unlink(context, grn_object);
219
+ }
220
220
  }
221
221
  xfree(rb_grn_object);
222
222
  }
@@ -228,61 +228,61 @@ rb_grn_object_to_ruby_class (grn_obj *object)
228
228
 
229
229
  switch (object->header.type) {
230
230
  case GRN_DB:
231
- klass = rb_cGrnDatabase;
232
- break;
231
+ klass = rb_cGrnDatabase;
232
+ break;
233
233
  case GRN_TABLE_HASH_KEY:
234
- klass = rb_cGrnHash;
235
- break;
234
+ klass = rb_cGrnHash;
235
+ break;
236
236
  case GRN_TABLE_PAT_KEY:
237
- klass = rb_cGrnPatriciaTrie;
238
- break;
237
+ klass = rb_cGrnPatriciaTrie;
238
+ break;
239
239
  case GRN_TABLE_DAT_KEY:
240
- klass = rb_cGrnDoubleArrayTrie;
241
- break;
240
+ klass = rb_cGrnDoubleArrayTrie;
241
+ break;
242
242
  case GRN_TABLE_NO_KEY:
243
- klass = rb_cGrnArray;
244
- break;
243
+ klass = rb_cGrnArray;
244
+ break;
245
245
  case GRN_TYPE:
246
- klass = rb_cGrnType;
247
- break;
246
+ klass = rb_cGrnType;
247
+ break;
248
248
  case GRN_ACCESSOR:
249
- klass = rb_cGrnAccessor;
250
- break;
249
+ klass = rb_cGrnAccessor;
250
+ break;
251
251
  case GRN_SNIP:
252
- klass = rb_cGrnSnippet;
253
- break;
252
+ klass = rb_cGrnSnippet;
253
+ break;
254
254
  case GRN_PROC:
255
- klass = rb_cGrnProcedure;
256
- break;
255
+ klass = rb_cGrnProcedure;
256
+ break;
257
257
  case GRN_COLUMN_FIX_SIZE:
258
- klass = rb_cGrnFixSizeColumn;
259
- break;
258
+ klass = rb_cGrnFixSizeColumn;
259
+ break;
260
260
  case GRN_COLUMN_VAR_SIZE:
261
- klass = rb_cGrnVariableSizeColumn;
262
- break;
261
+ klass = rb_cGrnVariableSizeColumn;
262
+ break;
263
263
  case GRN_COLUMN_INDEX:
264
- klass = rb_cGrnIndexColumn;
265
- break;
264
+ klass = rb_cGrnIndexColumn;
265
+ break;
266
266
  case GRN_EXPR:
267
- klass = rb_cGrnExpression;
268
- break;
267
+ klass = rb_cGrnExpression;
268
+ break;
269
269
  case GRN_CURSOR_TABLE_HASH_KEY:
270
- klass = rb_cGrnHashCursor;
271
- break;
270
+ klass = rb_cGrnHashCursor;
271
+ break;
272
272
  case GRN_CURSOR_TABLE_PAT_KEY:
273
- klass = rb_cGrnPatriciaTrieCursor;
274
- break;
273
+ klass = rb_cGrnPatriciaTrieCursor;
274
+ break;
275
275
  case GRN_CURSOR_TABLE_DAT_KEY:
276
- klass = rb_cGrnDoubleArrayTrieCursor;
277
- break;
276
+ klass = rb_cGrnDoubleArrayTrieCursor;
277
+ break;
278
278
  case GRN_CURSOR_TABLE_NO_KEY:
279
- klass = rb_cGrnArrayCursor;
280
- break;
279
+ klass = rb_cGrnArrayCursor;
280
+ break;
281
281
  default:
282
- rb_raise(rb_eTypeError,
283
- "unsupported groonga object type for class detection: 0x%x",
284
- object->header.type);
285
- break;
282
+ rb_raise(rb_eTypeError,
283
+ "unsupported groonga object type for class detection: 0x%x",
284
+ object->header.type);
285
+ break;
286
286
  }
287
287
 
288
288
  return klass;
@@ -290,7 +290,7 @@ rb_grn_object_to_ruby_class (grn_obj *object)
290
290
 
291
291
  VALUE
292
292
  rb_grn_object_to_ruby_object (VALUE klass, grn_ctx *context, grn_obj *object,
293
- grn_bool owner)
293
+ grn_bool owner)
294
294
  {
295
295
  RbGrnContext *rb_grn_context;
296
296
  VALUE rb_object, rb_context = Qnil;
@@ -301,7 +301,7 @@ rb_grn_object_to_ruby_object (VALUE klass, grn_ctx *context, grn_obj *object,
301
301
 
302
302
  user_data = grn_obj_user_data(context, object);
303
303
  if (user_data && user_data->ptr) {
304
- return RB_GRN_OBJECT(user_data->ptr)->self;
304
+ return RB_GRN_OBJECT(user_data->ptr)->self;
305
305
  }
306
306
 
307
307
  if (NIL_P(klass))
@@ -309,7 +309,7 @@ rb_grn_object_to_ruby_object (VALUE klass, grn_ctx *context, grn_obj *object,
309
309
 
310
310
  rb_grn_context = GRN_CTX_USER_DATA(context)->ptr;
311
311
  if (rb_grn_context)
312
- rb_context = rb_grn_context->self;
312
+ rb_context = rb_grn_context->self;
313
313
  rb_object = rb_obj_alloc(klass);
314
314
  rb_grn_object_assign(klass, rb_object, rb_context, context, object);
315
315
 
@@ -324,16 +324,16 @@ rb_grn_object_alloc (VALUE klass)
324
324
 
325
325
  static void
326
326
  rb_grn_object_bind_common (VALUE klass, VALUE self, VALUE rb_context,
327
- RbGrnObject *rb_grn_object,
328
- grn_ctx *context, grn_obj *object)
327
+ RbGrnObject *rb_grn_object,
328
+ grn_ctx *context, grn_obj *object)
329
329
  {
330
330
  grn_user_data *user_data;
331
331
  RbGrnContext *rb_grn_context;
332
332
 
333
333
  debug("bind: %p:%p:%p %s(%#x)\n",
334
- context, object, rb_grn_object,
335
- rb_grn_inspect_type(object->header.type),
336
- object->header.type);
334
+ context, object, rb_grn_object,
335
+ rb_grn_inspect_type(object->header.type),
336
+ object->header.type);
337
337
 
338
338
  Data_Get_Struct(rb_context, RbGrnContext, rb_grn_context);
339
339
  rb_grn_object->rb_grn_context = rb_grn_context;
@@ -346,133 +346,133 @@ rb_grn_object_bind_common (VALUE klass, VALUE self, VALUE rb_context,
346
346
 
347
347
  user_data = grn_obj_user_data(context, object);
348
348
  if (user_data) {
349
- debug("set-finalizer: %p:%p:%p %s(%#x)\n",
350
- context, object, rb_grn_object,
351
- rb_grn_inspect_type(object->header.type),
352
- object->header.type);
353
- user_data->ptr = rb_grn_object;
354
- grn_obj_set_finalizer(context, object, rb_grn_object_finalizer);
355
- rb_grn_object->have_finalizer = GRN_TRUE;
349
+ debug("set-finalizer: %p:%p:%p %s(%#x)\n",
350
+ context, object, rb_grn_object,
351
+ rb_grn_inspect_type(object->header.type),
352
+ object->header.type);
353
+ user_data->ptr = rb_grn_object;
354
+ grn_obj_set_finalizer(context, object, rb_grn_object_finalizer);
355
+ rb_grn_object->have_finalizer = GRN_TRUE;
356
356
  } else if (object->header.type == GRN_ACCESSOR) {
357
- debug("set-finalizer(implicit): %p:%p:%p %s(%#x)\n",
358
- context, object, rb_grn_object,
359
- rb_grn_inspect_type(object->header.type),
360
- object->header.type);
361
- /* TODO: We want to call finalizer for GRN_ACCESSOR. */
362
- rb_grn_object->have_finalizer = GRN_FALSE;
357
+ debug("set-finalizer(implicit): %p:%p:%p %s(%#x)\n",
358
+ context, object, rb_grn_object,
359
+ rb_grn_inspect_type(object->header.type),
360
+ object->header.type);
361
+ /* TODO: We want to call finalizer for GRN_ACCESSOR. */
362
+ rb_grn_object->have_finalizer = GRN_FALSE;
363
363
  }
364
364
 
365
365
  switch (object->header.type) {
366
366
  case GRN_PROC:
367
367
  case GRN_TYPE:
368
368
  case GRN_ACCESSOR: /* TODO: We want to close GRN_ACCESSOR. */
369
- rb_grn_object->need_close = GRN_FALSE;
370
- break;
369
+ rb_grn_object->need_close = GRN_FALSE;
370
+ break;
371
371
  default:
372
- if (klass == rb_cGrnVariable)
373
- rb_grn_object->need_close = GRN_FALSE;
374
- break;
372
+ if (klass == rb_cGrnVariable)
373
+ rb_grn_object->need_close = GRN_FALSE;
374
+ break;
375
375
  }
376
376
 
377
377
  rb_grn_object->domain_id = GRN_ID_NIL;
378
378
  if (object)
379
- rb_grn_object->domain_id = object->header.domain;
379
+ rb_grn_object->domain_id = object->header.domain;
380
380
  if (rb_grn_object->domain_id == GRN_ID_NIL)
381
- rb_grn_object->domain = NULL;
381
+ rb_grn_object->domain = NULL;
382
382
  else
383
- rb_grn_object->domain = grn_ctx_at(context, rb_grn_object->domain_id);
383
+ rb_grn_object->domain = grn_ctx_at(context, rb_grn_object->domain_id);
384
384
 
385
385
  rb_grn_object->range_id = GRN_ID_NIL;
386
386
  if (object && object->header.type != GRN_TYPE)
387
- rb_grn_object->range_id = grn_obj_get_range(context, object);
387
+ rb_grn_object->range_id = grn_obj_get_range(context, object);
388
388
  if (rb_grn_object->range_id == GRN_ID_NIL)
389
- rb_grn_object->range = NULL;
389
+ rb_grn_object->range = NULL;
390
390
  else
391
- rb_grn_object->range = grn_ctx_at(context, rb_grn_object->range_id);
391
+ rb_grn_object->range = grn_ctx_at(context, rb_grn_object->range_id);
392
392
 
393
393
  DATA_PTR(self) = rb_grn_object;
394
394
  }
395
395
 
396
396
  void
397
397
  rb_grn_object_assign (VALUE klass, VALUE self, VALUE rb_context,
398
- grn_ctx *context, grn_obj *object)
398
+ grn_ctx *context, grn_obj *object)
399
399
  {
400
400
  void *rb_grn_object;
401
401
 
402
402
  if (!object)
403
- return;
403
+ return;
404
404
 
405
405
  if (NIL_P(klass))
406
- klass = rb_obj_class(self);
406
+ klass = rb_obj_class(self);
407
407
 
408
408
  if (klass == rb_cGrnDatabase ||
409
- (RVAL2CBOOL(rb_obj_is_kind_of(self, rb_cGrnType))) ||
410
- klass == rb_cGrnHashCursor ||
411
- klass == rb_cGrnPatriciaTrieCursor ||
412
- klass == rb_cGrnDoubleArrayTrieCursor ||
413
- klass == rb_cGrnArrayCursor ||
414
- klass == rb_cGrnIndexCursor ||
415
- klass == rb_cGrnProcedure ||
416
- klass == rb_cGrnVariable) {
417
- rb_grn_object = ALLOC(RbGrnObject);
418
- rb_grn_object_bind_common(klass, self, rb_context, rb_grn_object,
419
- context, object);
409
+ (RVAL2CBOOL(rb_obj_is_kind_of(self, rb_cGrnType))) ||
410
+ klass == rb_cGrnHashCursor ||
411
+ klass == rb_cGrnPatriciaTrieCursor ||
412
+ klass == rb_cGrnDoubleArrayTrieCursor ||
413
+ klass == rb_cGrnArrayCursor ||
414
+ klass == rb_cGrnIndexCursor ||
415
+ klass == rb_cGrnProcedure ||
416
+ klass == rb_cGrnVariable) {
417
+ rb_grn_object = ALLOC(RbGrnObject);
418
+ rb_grn_object_bind_common(klass, self, rb_context, rb_grn_object,
419
+ context, object);
420
420
  } else if (RVAL2CBOOL(rb_obj_is_kind_of(self, rb_mGrnTableKeySupport))) {
421
- rb_grn_object = ALLOC(RbGrnTableKeySupport);
422
- rb_grn_object_bind_common(klass, self, rb_context, rb_grn_object,
423
- context, object);
424
- rb_grn_table_key_support_bind(RB_GRN_TABLE_KEY_SUPPORT(rb_grn_object),
425
- context, object);
421
+ rb_grn_object = ALLOC(RbGrnTableKeySupport);
422
+ rb_grn_object_bind_common(klass, self, rb_context, rb_grn_object,
423
+ context, object);
424
+ rb_grn_table_key_support_bind(RB_GRN_TABLE_KEY_SUPPORT(rb_grn_object),
425
+ context, object);
426
426
  } else if (RVAL2CBOOL(rb_obj_is_kind_of(self, rb_cGrnTable))) {
427
- rb_grn_object = ALLOC(RbGrnTable);
428
- rb_grn_object_bind_common(klass, self, rb_context, rb_grn_object,
429
- context, object);
430
- rb_grn_table_bind(RB_GRN_TABLE(rb_grn_object), context, object);
427
+ rb_grn_object = ALLOC(RbGrnTable);
428
+ rb_grn_object_bind_common(klass, self, rb_context, rb_grn_object,
429
+ context, object);
430
+ rb_grn_table_bind(RB_GRN_TABLE(rb_grn_object), context, object);
431
431
  } else if (RVAL2CBOOL(rb_obj_is_kind_of(self, rb_cGrnIndexColumn))) {
432
- rb_grn_object = ALLOC(RbGrnIndexColumn);
433
- rb_grn_object_bind_common(klass, self, rb_context, rb_grn_object,
434
- context, object);
435
- rb_grn_index_column_bind(RB_GRN_INDEX_COLUMN(rb_grn_object),
436
- context, object);
432
+ rb_grn_object = ALLOC(RbGrnIndexColumn);
433
+ rb_grn_object_bind_common(klass, self, rb_context, rb_grn_object,
434
+ context, object);
435
+ rb_grn_index_column_bind(RB_GRN_INDEX_COLUMN(rb_grn_object),
436
+ context, object);
437
437
  } else if (RVAL2CBOOL(rb_obj_is_kind_of(self, rb_cGrnColumn))) {
438
- rb_grn_object = ALLOC(RbGrnColumn);
439
- rb_grn_object_bind_common(klass, self, rb_context, rb_grn_object,
440
- context, object);
441
- rb_grn_column_bind(RB_GRN_COLUMN(rb_grn_object), context, object);
438
+ rb_grn_object = ALLOC(RbGrnColumn);
439
+ rb_grn_object_bind_common(klass, self, rb_context, rb_grn_object,
440
+ context, object);
441
+ rb_grn_column_bind(RB_GRN_COLUMN(rb_grn_object), context, object);
442
442
  } else if (klass == rb_cGrnAccessor) {
443
- rb_grn_object = ALLOC(RbGrnAccessor);
444
- rb_grn_object_bind_common(klass, self, rb_context, rb_grn_object,
445
- context, object);
446
- rb_grn_accessor_bind(RB_GRN_ACCESSOR(rb_grn_object), context, object);
443
+ rb_grn_object = ALLOC(RbGrnAccessor);
444
+ rb_grn_object_bind_common(klass, self, rb_context, rb_grn_object,
445
+ context, object);
446
+ rb_grn_accessor_bind(RB_GRN_ACCESSOR(rb_grn_object), context, object);
447
447
  } else if (klass == rb_cGrnExpression) {
448
- rb_grn_object = ALLOC(RbGrnExpression);
449
- rb_grn_object_bind_common(klass, self, rb_context, rb_grn_object,
450
- context, object);
451
- rb_grn_expression_bind(RB_GRN_EXPRESSION(rb_grn_object),
452
- context, object);
448
+ rb_grn_object = ALLOC(RbGrnExpression);
449
+ rb_grn_object_bind_common(klass, self, rb_context, rb_grn_object,
450
+ context, object);
451
+ rb_grn_expression_bind(RB_GRN_EXPRESSION(rb_grn_object),
452
+ context, object);
453
453
  } else if (klass == rb_cGrnSnippet) {
454
- rb_grn_object = ALLOC(RbGrnSnippet);
455
- rb_grn_object_bind_common(klass, self, rb_context, rb_grn_object,
456
- context, object);
457
- rb_grn_snippet_bind(RB_GRN_SNIPPET(rb_grn_object),
458
- context, object);
454
+ rb_grn_object = ALLOC(RbGrnSnippet);
455
+ rb_grn_object_bind_common(klass, self, rb_context, rb_grn_object,
456
+ context, object);
457
+ rb_grn_snippet_bind(RB_GRN_SNIPPET(rb_grn_object),
458
+ context, object);
459
459
  } else {
460
- rb_raise(rb_eTypeError,
461
- "unsupported groonga object type for assignment: %s(%#x)",
462
- rb_grn_inspect_type(object->header.type),
463
- object->header.type);
460
+ rb_raise(rb_eTypeError,
461
+ "unsupported groonga object type for assignment: %s(%#x)",
462
+ rb_grn_inspect_type(object->header.type),
463
+ object->header.type);
464
464
  }
465
465
 
466
466
  rb_iv_set(self, "@context", rb_context);
467
467
 
468
468
  debug("assign: %p:%p:%p %s(%#x)\n",
469
- context, object, rb_grn_object,
470
- rb_grn_inspect_type(object->header.type), object->header.type);
469
+ context, object, rb_grn_object,
470
+ rb_grn_inspect_type(object->header.type), object->header.type);
471
471
  }
472
472
 
473
473
  void
474
474
  rb_grn_named_object_bind (RbGrnNamedObject *rb_grn_named_object,
475
- grn_ctx *context, grn_obj *object)
475
+ grn_ctx *context, grn_obj *object)
476
476
  {
477
477
  rb_grn_named_object->name = NULL;
478
478
  rb_grn_named_object->name_size = 0;
@@ -480,35 +480,35 @@ rb_grn_named_object_bind (RbGrnNamedObject *rb_grn_named_object,
480
480
 
481
481
  void
482
482
  rb_grn_named_object_finalizer (grn_ctx *context, grn_obj *grn_object,
483
- RbGrnNamedObject *rb_grn_named_object)
483
+ RbGrnNamedObject *rb_grn_named_object)
484
484
  {
485
485
  if (rb_grn_named_object->name)
486
- xfree(rb_grn_named_object->name);
486
+ xfree(rb_grn_named_object->name);
487
487
  rb_grn_named_object->name = NULL;
488
488
  rb_grn_named_object->name_size = 0;
489
489
  }
490
490
 
491
491
  void
492
492
  rb_grn_named_object_set_name (RbGrnNamedObject *rb_grn_named_object,
493
- const char *name, unsigned name_size)
493
+ const char *name, unsigned name_size)
494
494
  {
495
495
  if (rb_grn_named_object->name) {
496
- xfree(rb_grn_named_object->name);
497
- rb_grn_named_object->name = NULL;
496
+ xfree(rb_grn_named_object->name);
497
+ rb_grn_named_object->name = NULL;
498
498
  }
499
499
  if (name_size > 0) {
500
- RbGrnObject *rb_grn_object;
501
- rb_grn_named_object->name = ALLOC_N(char, name_size + 1);
502
- memcpy(rb_grn_named_object->name, name, name_size);
503
- rb_grn_named_object->name[name_size] = '\0';
504
- rb_grn_object = RB_GRN_OBJECT(rb_grn_named_object);
505
- debug("set-name: %p:%p:%p %s(%#x): <%.*s>\n",
506
- rb_grn_object->context,
507
- rb_grn_object->object,
508
- rb_grn_named_object,
509
- rb_grn_inspect_type(rb_grn_object->object->header.type),
510
- rb_grn_object->object->header.type,
511
- name_size, name);
500
+ RbGrnObject *rb_grn_object;
501
+ rb_grn_named_object->name = ALLOC_N(char, name_size + 1);
502
+ memcpy(rb_grn_named_object->name, name, name_size);
503
+ rb_grn_named_object->name[name_size] = '\0';
504
+ rb_grn_object = RB_GRN_OBJECT(rb_grn_named_object);
505
+ debug("set-name: %p:%p:%p %s(%#x): <%.*s>\n",
506
+ rb_grn_object->context,
507
+ rb_grn_object->object,
508
+ rb_grn_named_object,
509
+ rb_grn_inspect_type(rb_grn_object->object->header.type),
510
+ rb_grn_object->object->header.type,
511
+ name_size, name);
512
512
  }
513
513
  rb_grn_named_object->name_size = name_size;
514
514
  }
@@ -516,28 +516,28 @@ rb_grn_named_object_set_name (RbGrnNamedObject *rb_grn_named_object,
516
516
 
517
517
  void
518
518
  rb_grn_object_deconstruct (RbGrnObject *rb_grn_object,
519
- grn_obj **object,
520
- grn_ctx **context,
521
- grn_id *domain_id,
522
- grn_obj **domain,
523
- grn_id *range_id,
524
- grn_obj **range)
519
+ grn_obj **object,
520
+ grn_ctx **context,
521
+ grn_id *domain_id,
522
+ grn_obj **domain,
523
+ grn_id *range_id,
524
+ grn_obj **range)
525
525
  {
526
526
  if (!rb_grn_object)
527
- return;
527
+ return;
528
528
 
529
529
  if (object)
530
- *object = rb_grn_object->object;
530
+ *object = rb_grn_object->object;
531
531
  if (context)
532
- *context = rb_grn_object->context;
532
+ *context = rb_grn_object->context;
533
533
  if (domain_id)
534
- *domain_id = rb_grn_object->domain_id;
534
+ *domain_id = rb_grn_object->domain_id;
535
535
  if (domain)
536
- *domain = rb_grn_object->domain;
536
+ *domain = rb_grn_object->domain;
537
537
  if (range_id)
538
- *range_id = rb_grn_object->range_id;
538
+ *range_id = rb_grn_object->range_id;
539
539
  if (range)
540
- *range = rb_grn_object->range;
540
+ *range = rb_grn_object->range;
541
541
  }
542
542
 
543
543
  /*
@@ -555,10 +555,10 @@ rb_grn_object_close (VALUE self)
555
555
 
556
556
  rb_grn_object = SELF(self);
557
557
  rb_grn_object_deconstruct(rb_grn_object, &object, &context,
558
- NULL, NULL, NULL, NULL);
558
+ NULL, NULL, NULL, NULL);
559
559
  if (object && context) {
560
- rb_grn_object_run_finalizer(context, object, rb_grn_object);
561
- grn_obj_close(context, object);
560
+ rb_grn_object_run_finalizer(context, object, rb_grn_object);
561
+ grn_obj_close(context, object);
562
562
  }
563
563
 
564
564
  return Qnil;
@@ -578,12 +578,12 @@ rb_grn_object_unlink (VALUE self)
578
578
 
579
579
  rb_grn_object = SELF(self);
580
580
  rb_grn_object_deconstruct(rb_grn_object, &object, &context,
581
- NULL, NULL, NULL, NULL);
581
+ NULL, NULL, NULL, NULL);
582
582
  if (object && context) {
583
- if (!(rb_grn_object->object->header.flags & GRN_OBJ_PERSISTENT)) {
584
- rb_grn_object_run_finalizer(context, object, rb_grn_object);
585
- }
586
- grn_obj_unlink(context, object);
583
+ if (!(rb_grn_object->object->header.flags & GRN_OBJ_PERSISTENT)) {
584
+ rb_grn_object_run_finalizer(context, object, rb_grn_object);
585
+ }
586
+ grn_obj_unlink(context, object);
587
587
  }
588
588
 
589
589
  return Qnil;
@@ -630,16 +630,16 @@ rb_grn_object_inspect_header (VALUE self, VALUE inspected)
630
630
 
631
631
  static VALUE
632
632
  rb_grn_object_inspect_content_id_with_label (VALUE inspected,
633
- grn_ctx *context, grn_obj *object)
633
+ grn_ctx *context, grn_obj *object)
634
634
  {
635
635
  grn_id id;
636
636
 
637
637
  rb_str_cat2(inspected, "id: <");
638
638
  id = grn_obj_id(context, object);
639
639
  if (id == GRN_ID_NIL)
640
- rb_str_cat2(inspected, "nil");
640
+ rb_str_cat2(inspected, "nil");
641
641
  else
642
- rb_str_concat(inspected, rb_obj_as_string(UINT2NUM(id)));
642
+ rb_str_concat(inspected, rb_obj_as_string(UINT2NUM(id)));
643
643
  rb_str_cat2(inspected, ">");
644
644
 
645
645
  return inspected;
@@ -647,24 +647,24 @@ rb_grn_object_inspect_content_id_with_label (VALUE inspected,
647
647
 
648
648
  VALUE
649
649
  rb_grn_object_inspect_object_content_name (VALUE inspected,
650
- grn_ctx *context, grn_obj *object)
650
+ grn_ctx *context, grn_obj *object)
651
651
  {
652
652
  int name_size;
653
653
 
654
654
  name_size = grn_obj_name(context, object, NULL, 0);
655
655
  if (name_size == 0) {
656
- rb_str_cat2(inspected, "(anonymous)");
656
+ rb_str_cat2(inspected, "(anonymous)");
657
657
  } else {
658
- grn_obj name;
659
-
660
- GRN_OBJ_INIT(&name, GRN_BULK, 0, GRN_ID_NIL);
661
- grn_bulk_space(context, &name, name_size);
662
- grn_obj_name(context, object, GRN_BULK_HEAD(&name), name_size);
663
- GRN_TEXT_PUTC(context, &name, '\0');
664
- rb_str_cat2(inspected, "<");
665
- rb_str_cat2(inspected, GRN_BULK_HEAD(&name));
666
- rb_str_cat2(inspected, ">");
667
- grn_obj_unlink(context, &name);
658
+ grn_obj name;
659
+
660
+ GRN_OBJ_INIT(&name, GRN_BULK, 0, GRN_ID_NIL);
661
+ grn_bulk_space(context, &name, name_size);
662
+ grn_obj_name(context, object, GRN_BULK_HEAD(&name), name_size);
663
+ GRN_TEXT_PUTC(context, &name, '\0');
664
+ rb_str_cat2(inspected, "<");
665
+ rb_str_cat2(inspected, GRN_BULK_HEAD(&name));
666
+ rb_str_cat2(inspected, ">");
667
+ grn_obj_unlink(context, &name);
668
668
  }
669
669
 
670
670
  return inspected;
@@ -672,7 +672,7 @@ rb_grn_object_inspect_object_content_name (VALUE inspected,
672
672
 
673
673
  static VALUE
674
674
  rb_grn_object_inspect_content_name_with_label (VALUE inspected,
675
- grn_ctx *context, grn_obj *object)
675
+ grn_ctx *context, grn_obj *object)
676
676
  {
677
677
 
678
678
  rb_str_cat2(inspected, "name: ");
@@ -682,18 +682,18 @@ rb_grn_object_inspect_content_name_with_label (VALUE inspected,
682
682
 
683
683
  static VALUE
684
684
  rb_grn_object_inspect_content_path_with_label (VALUE inspected,
685
- grn_ctx *context, grn_obj *object)
685
+ grn_ctx *context, grn_obj *object)
686
686
  {
687
687
  const char *path;
688
688
 
689
689
  rb_str_cat2(inspected, "path: ");
690
690
  path = grn_obj_path(context, object);
691
691
  if (path) {
692
- rb_str_cat2(inspected, "<");
693
- rb_str_cat2(inspected, path);
694
- rb_str_cat2(inspected, ">");
692
+ rb_str_cat2(inspected, "<");
693
+ rb_str_cat2(inspected, path);
694
+ rb_str_cat2(inspected, ">");
695
695
  } else {
696
- rb_str_cat2(inspected, "(temporary)");
696
+ rb_str_cat2(inspected, "(temporary)");
697
697
  }
698
698
 
699
699
  return inspected;
@@ -701,32 +701,32 @@ rb_grn_object_inspect_content_path_with_label (VALUE inspected,
701
701
 
702
702
  static VALUE
703
703
  rb_grn_object_inspect_content_domain_with_label (VALUE inspected,
704
- grn_ctx *context,
705
- grn_obj *object)
704
+ grn_ctx *context,
705
+ grn_obj *object)
706
706
  {
707
707
  grn_id domain;
708
708
 
709
709
  rb_str_cat2(inspected, "domain: ");
710
710
  domain = object->header.domain;
711
711
  if (domain == GRN_ID_NIL) {
712
- rb_str_cat2(inspected, "(nil)");
712
+ rb_str_cat2(inspected, "(nil)");
713
713
  } else {
714
- grn_obj *domain_object;
715
-
716
- domain_object = grn_ctx_at(context, domain);
717
- if (domain_object) {
718
- if (domain_object == object) {
719
- rb_str_cat2(inspected, "(self)");
720
- } else {
721
- rb_grn_object_inspect_object_content_name(inspected,
722
- context,
723
- domain_object);
724
- }
725
- } else {
726
- rb_str_cat2(inspected, "(");
727
- rb_str_concat(inspected, rb_obj_as_string(UINT2NUM(domain)));
728
- rb_str_cat2(inspected, ")");
729
- }
714
+ grn_obj *domain_object;
715
+
716
+ domain_object = grn_ctx_at(context, domain);
717
+ if (domain_object) {
718
+ if (domain_object == object) {
719
+ rb_str_cat2(inspected, "(self)");
720
+ } else {
721
+ rb_grn_object_inspect_object_content_name(inspected,
722
+ context,
723
+ domain_object);
724
+ }
725
+ } else {
726
+ rb_str_cat2(inspected, "(");
727
+ rb_str_concat(inspected, rb_obj_as_string(UINT2NUM(domain)));
728
+ rb_str_cat2(inspected, ")");
729
+ }
730
730
  }
731
731
 
732
732
  return inspected;
@@ -734,8 +734,8 @@ rb_grn_object_inspect_content_domain_with_label (VALUE inspected,
734
734
 
735
735
  static VALUE
736
736
  rb_grn_object_inspect_content_range_with_label (VALUE inspected,
737
- grn_ctx *context,
738
- grn_obj *object)
737
+ grn_ctx *context,
738
+ grn_obj *object)
739
739
  {
740
740
  grn_id range;
741
741
 
@@ -744,31 +744,31 @@ rb_grn_object_inspect_content_range_with_label (VALUE inspected,
744
744
  range = grn_obj_get_range(context, object);
745
745
  switch (object->header.type) {
746
746
  case GRN_TYPE:
747
- rb_str_cat2(inspected, "<");
748
- rb_str_concat(inspected, rb_inspect(UINT2NUM(range)));
749
- rb_str_cat2(inspected, ">");
750
- break;
747
+ rb_str_cat2(inspected, "<");
748
+ rb_str_concat(inspected, rb_inspect(UINT2NUM(range)));
749
+ rb_str_cat2(inspected, ">");
750
+ break;
751
751
  default:
752
- if (range == GRN_ID_NIL) {
753
- rb_str_cat2(inspected, "(nil)");
754
- } else {
755
- grn_obj *range_object;
756
-
757
- range_object = grn_ctx_at(context, range);
758
- if (range_object) {
759
- if (range_object == object) {
760
- rb_str_cat2(inspected, "(self)");
761
- } else {
762
- rb_grn_object_inspect_object_content_name(inspected,
763
- context,
764
- range_object);
765
- }
766
- } else {
767
- rb_str_cat2(inspected, "(");
768
- rb_str_concat(inspected, rb_obj_as_string(UINT2NUM(range)));
769
- rb_str_cat2(inspected, ")");
770
- }
771
- }
752
+ if (range == GRN_ID_NIL) {
753
+ rb_str_cat2(inspected, "(nil)");
754
+ } else {
755
+ grn_obj *range_object;
756
+
757
+ range_object = grn_ctx_at(context, range);
758
+ if (range_object) {
759
+ if (range_object == object) {
760
+ rb_str_cat2(inspected, "(self)");
761
+ } else {
762
+ rb_grn_object_inspect_object_content_name(inspected,
763
+ context,
764
+ range_object);
765
+ }
766
+ } else {
767
+ rb_str_cat2(inspected, "(");
768
+ rb_str_concat(inspected, rb_obj_as_string(UINT2NUM(range)));
769
+ rb_str_cat2(inspected, ")");
770
+ }
771
+ }
772
772
  }
773
773
 
774
774
  return inspected;
@@ -776,8 +776,8 @@ rb_grn_object_inspect_content_range_with_label (VALUE inspected,
776
776
 
777
777
  static VALUE
778
778
  rb_grn_object_inspect_content_flags_with_label (VALUE inspected,
779
- grn_ctx *context,
780
- grn_obj *object)
779
+ grn_ctx *context,
780
+ grn_obj *object)
781
781
  {
782
782
  grn_obj_flags flags;
783
783
  VALUE inspected_flags;
@@ -789,107 +789,107 @@ rb_grn_object_inspect_content_flags_with_label (VALUE inspected,
789
789
  inspected_flags = rb_ary_new();
790
790
 
791
791
  if (0) {
792
- if (flags & GRN_OBJ_TABLE_HASH_KEY)
793
- rb_ary_push(inspected_flags, rb_str_new2("TABLE_HASH_KEY"));
794
- if (flags & GRN_OBJ_TABLE_PAT_KEY)
795
- rb_ary_push(inspected_flags, rb_str_new2("TABLE_PAT_KEY"));
796
- if (flags & GRN_OBJ_TABLE_DAT_KEY)
797
- rb_ary_push(inspected_flags, rb_str_new2("TABLE_DAT_KEY"));
798
- if (flags & GRN_OBJ_TABLE_NO_KEY)
799
- rb_ary_push(inspected_flags, rb_str_new2("TABLE_NO_KEY"));
792
+ if (flags & GRN_OBJ_TABLE_HASH_KEY)
793
+ rb_ary_push(inspected_flags, rb_str_new2("TABLE_HASH_KEY"));
794
+ if (flags & GRN_OBJ_TABLE_PAT_KEY)
795
+ rb_ary_push(inspected_flags, rb_str_new2("TABLE_PAT_KEY"));
796
+ if (flags & GRN_OBJ_TABLE_DAT_KEY)
797
+ rb_ary_push(inspected_flags, rb_str_new2("TABLE_DAT_KEY"));
798
+ if (flags & GRN_OBJ_TABLE_NO_KEY)
799
+ rb_ary_push(inspected_flags, rb_str_new2("TABLE_NO_KEY"));
800
800
  }
801
801
 
802
802
  switch (object->header.type) {
803
803
  case GRN_COLUMN_FIX_SIZE:
804
804
  case GRN_COLUMN_VAR_SIZE:
805
805
  case GRN_TYPE:
806
- if (flags & GRN_OBJ_KEY_VAR_SIZE) {
807
- rb_ary_push(inspected_flags, rb_str_new2("KEY_VAR_SIZE"));
808
- } else {
809
- switch (flags & GRN_OBJ_KEY_MASK) {
810
- case GRN_OBJ_KEY_UINT:
811
- rb_ary_push(inspected_flags, rb_str_new2("KEY_UINT"));
812
- break;
813
- case GRN_OBJ_KEY_INT:
814
- rb_ary_push(inspected_flags, rb_str_new2("KEY_INT"));
815
- break;
816
- case GRN_OBJ_KEY_FLOAT:
817
- rb_ary_push(inspected_flags, rb_str_new2("KEY_FLOAT"));
818
- break;
819
- case GRN_OBJ_KEY_GEO_POINT:
820
- rb_ary_push(inspected_flags, rb_str_new2("KEY_GEO_POINT"));
821
- break;
822
- default:
823
- break;
824
- }
825
- }
826
- break;
806
+ if (flags & GRN_OBJ_KEY_VAR_SIZE) {
807
+ rb_ary_push(inspected_flags, rb_str_new2("KEY_VAR_SIZE"));
808
+ } else {
809
+ switch (flags & GRN_OBJ_KEY_MASK) {
810
+ case GRN_OBJ_KEY_UINT:
811
+ rb_ary_push(inspected_flags, rb_str_new2("KEY_UINT"));
812
+ break;
813
+ case GRN_OBJ_KEY_INT:
814
+ rb_ary_push(inspected_flags, rb_str_new2("KEY_INT"));
815
+ break;
816
+ case GRN_OBJ_KEY_FLOAT:
817
+ rb_ary_push(inspected_flags, rb_str_new2("KEY_FLOAT"));
818
+ break;
819
+ case GRN_OBJ_KEY_GEO_POINT:
820
+ rb_ary_push(inspected_flags, rb_str_new2("KEY_GEO_POINT"));
821
+ break;
822
+ default:
823
+ break;
824
+ }
825
+ }
826
+ break;
827
827
  default:
828
- break;
828
+ break;
829
829
  }
830
830
 
831
831
  switch (object->header.type) {
832
832
  case GRN_TABLE_HASH_KEY:
833
833
  case GRN_TABLE_PAT_KEY:
834
834
  case GRN_TABLE_DAT_KEY:
835
- if (flags & GRN_OBJ_KEY_WITH_SIS)
836
- rb_ary_push(inspected_flags, rb_str_new2("KEY_WITH_SIS"));
837
- if (flags & GRN_OBJ_KEY_NORMALIZE)
838
- rb_ary_push(inspected_flags, rb_str_new2("KEY_NORMALIZE"));
839
- break;
835
+ if (flags & GRN_OBJ_KEY_WITH_SIS)
836
+ rb_ary_push(inspected_flags, rb_str_new2("KEY_WITH_SIS"));
837
+ if (flags & GRN_OBJ_KEY_NORMALIZE)
838
+ rb_ary_push(inspected_flags, rb_str_new2("KEY_NORMALIZE"));
839
+ break;
840
840
  default:
841
- break;
841
+ break;
842
842
  }
843
843
 
844
844
  if (0) {
845
- if (flags & GRN_OBJ_COLUMN_SCALAR)
846
- rb_ary_push(inspected_flags, rb_str_new2("COLUMN_SCALAR"));
847
- if (flags & GRN_OBJ_COLUMN_VECTOR)
848
- rb_ary_push(inspected_flags, rb_str_new2("COLUMN_VECTOR"));
849
- if (flags & GRN_OBJ_COLUMN_INDEX)
850
- rb_ary_push(inspected_flags, rb_str_new2("COLUMN_INDEX"));
845
+ if (flags & GRN_OBJ_COLUMN_SCALAR)
846
+ rb_ary_push(inspected_flags, rb_str_new2("COLUMN_SCALAR"));
847
+ if (flags & GRN_OBJ_COLUMN_VECTOR)
848
+ rb_ary_push(inspected_flags, rb_str_new2("COLUMN_VECTOR"));
849
+ if (flags & GRN_OBJ_COLUMN_INDEX)
850
+ rb_ary_push(inspected_flags, rb_str_new2("COLUMN_INDEX"));
851
851
  }
852
852
 
853
853
  switch (object->header.type) {
854
854
  case GRN_COLUMN_FIX_SIZE:
855
855
  case GRN_COLUMN_VAR_SIZE:
856
- if (flags & GRN_OBJ_COMPRESS_ZLIB)
857
- rb_ary_push(inspected_flags, rb_str_new2("COMPRESS_ZLIB"));
858
- if (flags & GRN_OBJ_COMPRESS_LZO)
859
- rb_ary_push(inspected_flags, rb_str_new2("COMPRESS_LZO"));
860
- break;
856
+ if (flags & GRN_OBJ_COMPRESS_ZLIB)
857
+ rb_ary_push(inspected_flags, rb_str_new2("COMPRESS_ZLIB"));
858
+ if (flags & GRN_OBJ_COMPRESS_LZO)
859
+ rb_ary_push(inspected_flags, rb_str_new2("COMPRESS_LZO"));
860
+ break;
861
861
  case GRN_COLUMN_INDEX:
862
- if (flags & GRN_OBJ_WITH_SECTION)
863
- rb_ary_push(inspected_flags, rb_str_new2("WITH_SECTION"));
864
- if (flags & GRN_OBJ_WITH_WEIGHT)
865
- rb_ary_push(inspected_flags, rb_str_new2("WITH_WEIGHT"));
866
- if (flags & GRN_OBJ_WITH_POSITION)
867
- rb_ary_push(inspected_flags, rb_str_new2("WITH_POSITION"));
868
- break;
862
+ if (flags & GRN_OBJ_WITH_SECTION)
863
+ rb_ary_push(inspected_flags, rb_str_new2("WITH_SECTION"));
864
+ if (flags & GRN_OBJ_WITH_WEIGHT)
865
+ rb_ary_push(inspected_flags, rb_str_new2("WITH_WEIGHT"));
866
+ if (flags & GRN_OBJ_WITH_POSITION)
867
+ rb_ary_push(inspected_flags, rb_str_new2("WITH_POSITION"));
868
+ break;
869
869
  default:
870
- break;
870
+ break;
871
871
  }
872
872
 
873
873
  if (flags & GRN_OBJ_RING_BUFFER)
874
- rb_ary_push(inspected_flags, rb_str_new2("RING_BUFFER"));
874
+ rb_ary_push(inspected_flags, rb_str_new2("RING_BUFFER"));
875
875
 
876
876
  if (flags & GRN_OBJ_WITH_SUBREC) {
877
- rb_ary_push(inspected_flags, rb_str_new2("WITH_SUBREC"));
878
-
879
- if (flags & GRN_OBJ_UNIT_DOCUMENT_SECTION)
880
- rb_ary_push(inspected_flags, rb_str_new2("UNIT_DOCUMENT_SECTION"));
881
- if (flags & GRN_OBJ_UNIT_DOCUMENT_POSITION)
882
- rb_ary_push(inspected_flags, rb_str_new2("UNIT_DOCUMENT_POSITION"));
883
-
884
- if (flags & GRN_OBJ_UNIT_SECTION_POSITION)
885
- rb_ary_push(inspected_flags, rb_str_new2("UNIT_SECTION_POSITION"));
886
-
887
- if (flags & GRN_OBJ_UNIT_USERDEF_DOCUMENT)
888
- rb_ary_push(inspected_flags, rb_str_new2("UNIT_USERDEF_DOCUMENT"));
889
- if (flags & GRN_OBJ_UNIT_USERDEF_SECTION)
890
- rb_ary_push(inspected_flags, rb_str_new2("UNIT_USERDEF_SECTION"));
891
- if (flags & GRN_OBJ_UNIT_USERDEF_POSITION)
892
- rb_ary_push(inspected_flags, rb_str_new2("UNIT_USERDEF_POSITION"));
877
+ rb_ary_push(inspected_flags, rb_str_new2("WITH_SUBREC"));
878
+
879
+ if (flags & GRN_OBJ_UNIT_DOCUMENT_SECTION)
880
+ rb_ary_push(inspected_flags, rb_str_new2("UNIT_DOCUMENT_SECTION"));
881
+ if (flags & GRN_OBJ_UNIT_DOCUMENT_POSITION)
882
+ rb_ary_push(inspected_flags, rb_str_new2("UNIT_DOCUMENT_POSITION"));
883
+
884
+ if (flags & GRN_OBJ_UNIT_SECTION_POSITION)
885
+ rb_ary_push(inspected_flags, rb_str_new2("UNIT_SECTION_POSITION"));
886
+
887
+ if (flags & GRN_OBJ_UNIT_USERDEF_DOCUMENT)
888
+ rb_ary_push(inspected_flags, rb_str_new2("UNIT_USERDEF_DOCUMENT"));
889
+ if (flags & GRN_OBJ_UNIT_USERDEF_SECTION)
890
+ rb_ary_push(inspected_flags, rb_str_new2("UNIT_USERDEF_SECTION"));
891
+ if (flags & GRN_OBJ_UNIT_USERDEF_POSITION)
892
+ rb_ary_push(inspected_flags, rb_str_new2("UNIT_USERDEF_POSITION"));
893
893
  }
894
894
 
895
895
  rb_str_cat2(inspected, "<");
@@ -901,7 +901,7 @@ rb_grn_object_inspect_content_flags_with_label (VALUE inspected,
901
901
 
902
902
  VALUE
903
903
  rb_grn_object_inspect_object_content (VALUE inspected,
904
- grn_ctx *context, grn_obj *object)
904
+ grn_ctx *context, grn_obj *object)
905
905
  {
906
906
  rb_grn_object_inspect_content_id_with_label(inspected, context, object);
907
907
  rb_str_cat2(inspected, ", ");
@@ -927,18 +927,18 @@ rb_grn_object_inspect_content (VALUE self, VALUE inspected)
927
927
 
928
928
  rb_grn_object = SELF(self);
929
929
  if (!rb_grn_object)
930
- return inspected;
930
+ return inspected;
931
931
 
932
932
  context = rb_grn_object->context;
933
933
  object = rb_grn_object->object;
934
934
 
935
935
  rb_str_cat2(inspected, " ");
936
936
  if (rb_grn_exited) {
937
- rb_str_cat2(inspected, "(finished)");
937
+ rb_str_cat2(inspected, "(finished)");
938
938
  } else if (object) {
939
- rb_grn_object_inspect_object_content(inspected, context, object);
939
+ rb_grn_object_inspect_object_content(inspected, context, object);
940
940
  } else {
941
- rb_str_cat2(inspected, "(closed)");
941
+ rb_str_cat2(inspected, "(closed)");
942
942
  }
943
943
 
944
944
  return inspected;
@@ -986,11 +986,11 @@ rb_grn_object_get_id (VALUE self)
986
986
 
987
987
  rb_grn_object = SELF(self);
988
988
  if (!rb_grn_object->object)
989
- return Qnil;
989
+ return Qnil;
990
990
 
991
991
  id = grn_obj_id(rb_grn_object->context, rb_grn_object->object);
992
992
  if (id == GRN_ID_NIL)
993
- return Qnil;
993
+ return Qnil;
994
994
  else
995
995
  return UINT2NUM(id);
996
996
  }
@@ -1010,14 +1010,14 @@ rb_grn_object_get_path (VALUE self)
1010
1010
 
1011
1011
  rb_grn_object = SELF(self);
1012
1012
  if (!rb_grn_object->object)
1013
- return Qnil;
1013
+ return Qnil;
1014
1014
 
1015
1015
  path = grn_obj_path(rb_grn_object->context, rb_grn_object->object);
1016
1016
 
1017
1017
  if (!path)
1018
- return Qnil;
1018
+ return Qnil;
1019
1019
  else
1020
- return rb_str_new2(path);
1020
+ return rb_str_new2(path);
1021
1021
  }
1022
1022
 
1023
1023
  /*
@@ -1033,7 +1033,7 @@ rb_grn_object_temporary_p (VALUE self)
1033
1033
 
1034
1034
  rb_grn_object = SELF(self);
1035
1035
  if (!rb_grn_object->object)
1036
- return Qnil;
1036
+ return Qnil;
1037
1037
 
1038
1038
  return CBOOL2RVAL(!(rb_grn_object->object->header.flags & GRN_OBJ_PERSISTENT));
1039
1039
  }
@@ -1051,7 +1051,7 @@ rb_grn_object_persistent_p (VALUE self)
1051
1051
 
1052
1052
  rb_grn_object = SELF(self);
1053
1053
  if (!rb_grn_object->object)
1054
- return Qnil;
1054
+ return Qnil;
1055
1055
 
1056
1056
  return CBOOL2RVAL(rb_grn_object->object->header.flags & GRN_OBJ_PERSISTENT);
1057
1057
  }
@@ -1075,20 +1075,20 @@ rb_grn_object_get_domain (VALUE self)
1075
1075
  rb_grn_object = SELF(self);
1076
1076
  object = rb_grn_object->object;
1077
1077
  if (!object)
1078
- return Qnil;
1078
+ return Qnil;
1079
1079
 
1080
1080
  context = rb_grn_object->context;
1081
1081
  domain = object->header.domain;
1082
1082
  if (domain == GRN_ID_NIL) {
1083
- return Qnil;
1083
+ return Qnil;
1084
1084
  } else {
1085
- grn_obj *domain_object;
1085
+ grn_obj *domain_object;
1086
1086
 
1087
- domain_object = grn_ctx_at(context, domain);
1088
- if (domain_object)
1089
- return GRNOBJECT2RVAL(Qnil, context, domain_object, GRN_FALSE);
1090
- else
1091
- return UINT2NUM(domain);
1087
+ domain_object = grn_ctx_at(context, domain);
1088
+ if (domain_object)
1089
+ return GRNOBJECT2RVAL(Qnil, context, domain_object, GRN_FALSE);
1090
+ else
1091
+ return UINT2NUM(domain);
1092
1092
  }
1093
1093
  }
1094
1094
 
@@ -1108,16 +1108,16 @@ rb_grn_object_get_name (VALUE self)
1108
1108
 
1109
1109
  rb_grn_object = SELF(self);
1110
1110
  if (!rb_grn_object->object)
1111
- return Qnil;
1111
+ return Qnil;
1112
1112
 
1113
1113
  name_size = grn_obj_name(rb_grn_object->context, rb_grn_object->object,
1114
- NULL, 0);
1114
+ NULL, 0);
1115
1115
  if (name_size == 0)
1116
- return Qnil;
1116
+ return Qnil;
1117
1117
 
1118
1118
  name = xmalloc(name_size);
1119
1119
  grn_obj_name(rb_grn_object->context, rb_grn_object->object,
1120
- name, name_size);
1120
+ name, name_size);
1121
1121
  rb_name = rb_str_new(name, name_size);
1122
1122
  xfree(name);
1123
1123
 
@@ -1145,20 +1145,20 @@ rb_grn_object_get_range (VALUE self)
1145
1145
  rb_grn_object = SELF(self);
1146
1146
  object = rb_grn_object->object;
1147
1147
  if (!object)
1148
- return Qnil;
1148
+ return Qnil;
1149
1149
 
1150
1150
  context = rb_grn_object->context;
1151
1151
  range = grn_obj_get_range(context, object);
1152
1152
  if (range == GRN_ID_NIL) {
1153
- return Qnil;
1153
+ return Qnil;
1154
1154
  } else {
1155
- grn_obj *range_object;
1155
+ grn_obj *range_object;
1156
1156
 
1157
- range_object = grn_ctx_at(context, range);
1158
- if (range_object)
1159
- return GRNOBJECT2RVAL(Qnil, context, range_object, GRN_FALSE);
1160
- else
1161
- return UINT2NUM(range);
1157
+ range_object = grn_ctx_at(context, range);
1158
+ if (range_object)
1159
+ return GRNOBJECT2RVAL(Qnil, context, range_object, GRN_FALSE);
1160
+ else
1161
+ return UINT2NUM(range);
1162
1162
  }
1163
1163
  }
1164
1164
 
@@ -1210,7 +1210,7 @@ rb_grn_object_array_reference (VALUE self, VALUE rb_id)
1210
1210
  context = rb_grn_object->context;
1211
1211
  object = rb_grn_object->object;
1212
1212
  if (!object)
1213
- return Qnil;
1213
+ return Qnil;
1214
1214
 
1215
1215
  id = NUM2UINT(rb_id);
1216
1216
  range_id = grn_obj_get_range(context, object);
@@ -1221,43 +1221,43 @@ rb_grn_object_array_reference (VALUE self, VALUE rb_id)
1221
1221
  case GRN_TABLE_PAT_KEY:
1222
1222
  case GRN_TABLE_DAT_KEY:
1223
1223
  case GRN_TABLE_NO_KEY:
1224
- GRN_OBJ_INIT(&value, GRN_BULK, 0, GRN_ID_NIL);
1225
- break;
1224
+ GRN_OBJ_INIT(&value, GRN_BULK, 0, GRN_ID_NIL);
1225
+ break;
1226
1226
  case GRN_TYPE:
1227
1227
  case GRN_ACCESSOR: /* FIXME */
1228
- GRN_OBJ_INIT(&value, GRN_BULK, 0, range_id);
1229
- break;
1228
+ GRN_OBJ_INIT(&value, GRN_BULK, 0, range_id);
1229
+ break;
1230
1230
  case GRN_COLUMN_VAR_SIZE:
1231
1231
  case GRN_COLUMN_FIX_SIZE:
1232
- switch (object->header.flags & GRN_OBJ_COLUMN_TYPE_MASK) {
1233
- case GRN_OBJ_COLUMN_VECTOR:
1234
- GRN_OBJ_INIT(&value, GRN_VECTOR, 0, range_id);
1235
- break;
1236
- case GRN_OBJ_COLUMN_SCALAR:
1237
- GRN_OBJ_INIT(&value, GRN_BULK, 0, range_id);
1238
- break;
1239
- default:
1240
- rb_raise(rb_eGrnError, "unsupported column type: %u: %s",
1241
- range_type, rb_grn_inspect(self));
1242
- break;
1243
- }
1244
- break;
1232
+ switch (object->header.flags & GRN_OBJ_COLUMN_TYPE_MASK) {
1233
+ case GRN_OBJ_COLUMN_VECTOR:
1234
+ GRN_OBJ_INIT(&value, GRN_VECTOR, 0, range_id);
1235
+ break;
1236
+ case GRN_OBJ_COLUMN_SCALAR:
1237
+ GRN_OBJ_INIT(&value, GRN_BULK, 0, range_id);
1238
+ break;
1239
+ default:
1240
+ rb_raise(rb_eGrnError, "unsupported column type: %u: %s",
1241
+ range_type, rb_grn_inspect(self));
1242
+ break;
1243
+ }
1244
+ break;
1245
1245
  case GRN_COLUMN_INDEX:
1246
- GRN_UINT32_INIT(&value, 0);
1247
- break;
1246
+ GRN_UINT32_INIT(&value, 0);
1247
+ break;
1248
1248
  default:
1249
- rb_raise(rb_eGrnError,
1250
- "unsupported type: %s", rb_grn_inspect(self));
1251
- break;
1249
+ rb_raise(rb_eGrnError,
1250
+ "unsupported type: %s", rb_grn_inspect(self));
1251
+ break;
1252
1252
  }
1253
1253
 
1254
1254
  grn_obj_get_value(context, object, id, &value);
1255
1255
  exception = rb_grn_context_to_exception(context, self);
1256
1256
  if (NIL_P(exception))
1257
- rb_value = GRNVALUE2RVAL(context, &value, range, self);
1257
+ rb_value = GRNVALUE2RVAL(context, &value, range, self);
1258
1258
  grn_obj_unlink(context, &value);
1259
1259
  if (!NIL_P(exception))
1260
- rb_exc_raise(exception);
1260
+ rb_exc_raise(exception);
1261
1261
 
1262
1262
  return rb_value;
1263
1263
  }
@@ -1269,68 +1269,103 @@ rb_uvector_value_p (RbGrnObject *rb_grn_object, VALUE rb_value)
1269
1269
 
1270
1270
  switch (rb_grn_object->range->header.type) {
1271
1271
  case GRN_TYPE:
1272
- /* TODO: support not sizeof(grn_id) uvector. */
1273
- /*
1274
- if (!(rb_grn_object->range->header.flags | GRN_OBJ_KEY_VAR_SIZE)) {
1275
- return GRN_TRUE;
1276
- }
1277
- */
1278
- break;
1272
+ if (!(rb_grn_object->range->header.flags & GRN_OBJ_KEY_VAR_SIZE)) {
1273
+ return GRN_TRUE;
1274
+ }
1275
+ break;
1279
1276
  case GRN_TABLE_HASH_KEY:
1280
1277
  case GRN_TABLE_PAT_KEY:
1281
1278
  case GRN_TABLE_DAT_KEY:
1282
1279
  case GRN_TABLE_NO_KEY:
1283
- first_element = rb_ary_entry(rb_value, 0);
1284
- if (rb_respond_to(first_element, rb_intern("record_raw_id"))) {
1285
- return GRN_TRUE;
1286
- }
1287
- break;
1280
+ first_element = rb_ary_entry(rb_value, 0);
1281
+ if (rb_respond_to(first_element, rb_intern("record_raw_id"))) {
1282
+ return GRN_TRUE;
1283
+ }
1284
+ break;
1288
1285
  default:
1289
- break;
1286
+ break;
1290
1287
  }
1291
1288
 
1292
1289
  return GRN_FALSE;
1293
1290
  }
1294
1291
 
1295
- VALUE
1296
- rb_grn_object_set_raw (RbGrnObject *rb_grn_object, grn_id id,
1297
- VALUE rb_value, int flags, VALUE related_object)
1292
+ typedef struct {
1293
+ RbGrnObject *rb_grn_object;
1294
+ grn_id id;
1295
+ grn_obj value;
1296
+ VALUE rb_value;
1297
+ int flags;
1298
+ VALUE related_object;
1299
+ } SetRawData;
1300
+
1301
+ static VALUE
1302
+ rb_grn_object_set_raw_body (VALUE user_data)
1298
1303
  {
1304
+ SetRawData *data = (SetRawData *)user_data;
1305
+ RbGrnObject *rb_grn_object;
1299
1306
  grn_ctx *context;
1300
- grn_obj value;
1307
+ grn_obj *value;
1301
1308
  grn_rc rc;
1302
- VALUE exception, rb_values;
1309
+ VALUE rb_value, rb_values;
1310
+ VALUE related_object;
1303
1311
 
1312
+ rb_grn_object = data->rb_grn_object;
1304
1313
  context = rb_grn_object->context;
1314
+ value = &(data->value);
1315
+ rb_value = data->rb_value;
1305
1316
  rb_values = rb_grn_check_convert_to_array(rb_value);
1317
+ related_object = data->related_object;
1306
1318
  if (NIL_P(rb_values)) {
1307
- if (NIL_P(rb_value)) {
1308
- GRN_OBJ_INIT(&value, GRN_BULK, 0, GRN_ID_NIL);
1309
- } else {
1310
- GRN_OBJ_INIT(&value, GRN_BULK, 0, GRN_ID_NIL);
1311
- RVAL2GRNBULK(rb_value, context, &value);
1312
- }
1319
+ if (NIL_P(rb_value)) {
1320
+ GRN_OBJ_INIT(value, GRN_BULK, 0, GRN_ID_NIL);
1321
+ } else {
1322
+ GRN_OBJ_INIT(value, GRN_BULK, 0, GRN_ID_NIL);
1323
+ RVAL2GRNBULK(rb_value, context, value);
1324
+ }
1313
1325
  } else {
1314
- if (rb_uvector_value_p(rb_grn_object, rb_values)) {
1315
- GRN_OBJ_INIT(&value, GRN_UVECTOR, 0,
1316
- rb_grn_object->object->header.domain);
1317
- RVAL2GRNUVECTOR(rb_values, context, &value, related_object);
1318
- } else {
1319
- GRN_OBJ_INIT(&value, GRN_VECTOR, 0, GRN_ID_NIL);
1320
- RVAL2GRNVECTOR(rb_values, context, &value);
1321
- }
1326
+ if (rb_uvector_value_p(rb_grn_object, rb_values)) {
1327
+ GRN_OBJ_INIT(value, GRN_UVECTOR, 0, rb_grn_object->range_id);
1328
+ RVAL2GRNUVECTOR(rb_values, context, value, related_object);
1329
+ } else {
1330
+ GRN_OBJ_INIT(value, GRN_VECTOR, 0, GRN_ID_NIL);
1331
+ RVAL2GRNVECTOR(rb_values, context, value);
1332
+ }
1322
1333
  }
1323
- rc = grn_obj_set_value(context, rb_grn_object->object, id,
1324
- &value, flags);
1325
- exception = rb_grn_context_to_exception(context, related_object);
1326
- grn_obj_unlink(context, &value);
1327
- if (!NIL_P(exception))
1328
- rb_exc_raise(exception);
1334
+ rc = grn_obj_set_value(context, rb_grn_object->object, data->id,
1335
+ value, data->flags);
1336
+ rb_grn_context_check(context, related_object);
1329
1337
  rb_grn_rc_check(rc, related_object);
1330
1338
 
1331
1339
  return Qnil;
1332
1340
  }
1333
1341
 
1342
+ static VALUE
1343
+ rb_grn_object_set_raw_ensure (VALUE user_data)
1344
+ {
1345
+ SetRawData *data = (SetRawData *)user_data;
1346
+
1347
+ grn_obj_unlink(data->rb_grn_object->context, &(data->value));
1348
+
1349
+ return Qnil;
1350
+ }
1351
+
1352
+ VALUE
1353
+ rb_grn_object_set_raw (RbGrnObject *rb_grn_object, grn_id id,
1354
+ VALUE rb_value, int flags, VALUE related_object)
1355
+ {
1356
+ SetRawData data;
1357
+
1358
+ data.rb_grn_object = rb_grn_object;
1359
+ data.id = id;
1360
+ GRN_VOID_INIT(&(data.value));
1361
+ data.rb_value = rb_value;
1362
+ data.flags = flags;
1363
+ data.related_object = related_object;
1364
+
1365
+ return rb_ensure(rb_grn_object_set_raw_body, (VALUE)(&data),
1366
+ rb_grn_object_set_raw_ensure, (VALUE)(&data));
1367
+ }
1368
+
1334
1369
  static VALUE
1335
1370
  rb_grn_object_set (VALUE self, VALUE rb_id, VALUE rb_value, int flags)
1336
1371
  {
@@ -1339,7 +1374,7 @@ rb_grn_object_set (VALUE self, VALUE rb_id, VALUE rb_value, int flags)
1339
1374
 
1340
1375
  rb_grn_object = SELF(self);
1341
1376
  if (!rb_grn_object->object)
1342
- return Qnil;
1377
+ return Qnil;
1343
1378
 
1344
1379
  id = NUM2UINT(rb_id);
1345
1380
 
@@ -1395,7 +1430,7 @@ rb_grn_object_remove (VALUE self)
1395
1430
 
1396
1431
  rb_grn_object = SELF(self);
1397
1432
  if (!rb_grn_object->object)
1398
- return Qnil;
1433
+ return Qnil;
1399
1434
 
1400
1435
  context = rb_grn_object->context;
1401
1436
  rc = grn_obj_remove(context, rb_grn_object->object);
@@ -1414,10 +1449,10 @@ rb_grn_object_builtin_p (VALUE self)
1414
1449
  grn_bool builtin = GRN_FALSE;
1415
1450
 
1416
1451
  rb_grn_object_deconstruct(SELF(self), &object, &context,
1417
- NULL, NULL, NULL, NULL);
1452
+ NULL, NULL, NULL, NULL);
1418
1453
 
1419
1454
  if (context && object) {
1420
- builtin = grn_obj_is_builtin(context, object);
1455
+ builtin = grn_obj_is_builtin(context, object);
1421
1456
  }
1422
1457
 
1423
1458
  return CBOOL2RVAL(builtin);
@@ -1441,7 +1476,7 @@ rb_grn_init_object (VALUE mGrn)
1441
1476
 
1442
1477
  rb_define_method(rb_cGrnObject, "temporary?", rb_grn_object_temporary_p, 0);
1443
1478
  rb_define_method(rb_cGrnObject, "persistent?",
1444
- rb_grn_object_persistent_p, 0);
1479
+ rb_grn_object_persistent_p, 0);
1445
1480
 
1446
1481
  rb_define_method(rb_cGrnObject, "==", rb_grn_object_equal, 1);
1447
1482
 
@@ -1458,5 +1493,4 @@ rb_grn_init_object (VALUE mGrn)
1458
1493
  rb_define_method(rb_cGrnObject, "remove", rb_grn_object_remove, 0);
1459
1494
 
1460
1495
  rb_define_method(rb_cGrnObject, "builtin?", rb_grn_object_builtin_p, 0);
1461
-
1462
1496
  }