rroonga 9.0.3 → 11.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/Rakefile +26 -135
  4. data/doc/text/news.md +79 -1
  5. data/doc/text/tutorial.md +1 -1
  6. data/ext/groonga/extconf.rb +19 -74
  7. data/ext/groonga/rb-grn-accessor.c +2 -2
  8. data/ext/groonga/rb-grn-column-cache.c +3 -3
  9. data/ext/groonga/rb-grn-column.c +4 -4
  10. data/ext/groonga/rb-grn-context.c +109 -58
  11. data/ext/groonga/rb-grn-data-column.c +4 -4
  12. data/ext/groonga/rb-grn-database.c +45 -26
  13. data/ext/groonga/rb-grn-double-array-trie.c +2 -2
  14. data/ext/groonga/rb-grn-encoding-support.c +2 -2
  15. data/ext/groonga/rb-grn-exception.c +14 -0
  16. data/ext/groonga/rb-grn-expression-builder.c +3 -3
  17. data/ext/groonga/rb-grn-expression.c +3 -3
  18. data/ext/groonga/rb-grn-fix-size-column.c +2 -2
  19. data/ext/groonga/rb-grn-flushable.c +9 -1
  20. data/ext/groonga/rb-grn-hash.c +2 -2
  21. data/ext/groonga/rb-grn-index-column.c +30 -2
  22. data/ext/groonga/rb-grn-index-cursor.c +21 -2
  23. data/ext/groonga/rb-grn-inverted-index-cursor.c +3 -3
  24. data/ext/groonga/rb-grn-logger.c +17 -3
  25. data/ext/groonga/rb-grn-object.c +266 -31
  26. data/ext/groonga/rb-grn-operator.c +100 -259
  27. data/ext/groonga/rb-grn-patricia-trie.c +2 -2
  28. data/ext/groonga/rb-grn-plugin.c +34 -22
  29. data/ext/groonga/rb-grn-request-timer-id.c +2 -2
  30. data/ext/groonga/rb-grn-snippet.c +3 -3
  31. data/ext/groonga/rb-grn-table-cursor-key-support.c +2 -2
  32. data/ext/groonga/rb-grn-table-cursor.c +3 -3
  33. data/ext/groonga/rb-grn-table-key-support.c +28 -9
  34. data/ext/groonga/rb-grn-table.c +180 -130
  35. data/ext/groonga/rb-grn-type.c +5 -1
  36. data/ext/groonga/rb-grn-utils.c +17 -1
  37. data/ext/groonga/rb-grn-variable-size-column.c +2 -2
  38. data/ext/groonga/rb-grn-variable.c +2 -2
  39. data/ext/groonga/rb-grn.h +11 -14
  40. data/ext/groonga/rb-groonga.c +6 -2
  41. data/lib/groonga.rb +3 -7
  42. data/lib/groonga/context.rb +32 -0
  43. data/lib/groonga/dumper.rb +3 -0
  44. data/lib/groonga/record.rb +2 -2
  45. data/rroonga-build.rb +5 -4
  46. data/rroonga.gemspec +8 -6
  47. data/test/groonga-test-utils.rb +37 -5
  48. data/test/run-test.rb +1 -3
  49. data/test/test-accessor.rb +63 -7
  50. data/test/test-column.rb +12 -1
  51. data/test/test-context.rb +25 -0
  52. data/test/test-exception.rb +5 -0
  53. data/test/test-flushable.rb +51 -6
  54. data/test/test-index-column.rb +70 -9
  55. data/test/test-index-cursor.rb +26 -0
  56. data/test/test-logger.rb +56 -11
  57. data/test/test-plugin.rb +1 -0
  58. data/test/test-query-logger.rb +4 -3
  59. data/test/test-ractor.rb +65 -0
  60. data/test/test-record.rb +2 -1
  61. data/test/test-remote.rb +58 -10
  62. data/test/test-schema-dumper.rb +13 -0
  63. data/test/test-schema.rb +9 -1
  64. data/test/test-table-arrow.rb +22 -10
  65. data/test/test-table.rb +21 -1
  66. data/test/test-variable.rb +23 -7
  67. metadata +72 -97
@@ -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 Kouhei Sutou <kou@clear-code.com>
3
+ Copyright (C) 2009-2021 Sutou Kouhei <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
@@ -18,7 +18,7 @@
18
18
 
19
19
  #include "rb-grn.h"
20
20
 
21
- #define SELF(object) ((RbGrnAccessor *)DATA_PTR(object))
21
+ #define SELF(object) ((RbGrnAccessor *)RTYPEDDATA_DATA(object))
22
22
 
23
23
  VALUE rb_cGrnAccessor;
24
24
 
@@ -1,7 +1,7 @@
1
1
  /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
2
  /* vim: set sts=4 sw=4 ts=8 noet: */
3
3
  /*
4
- Copyright (C) 2018 Kouhei Sutou <kou@clear-code.com>
4
+ Copyright (C) 2018-2021 Sutou Kouhei <kou@clear-code.com>
5
5
 
6
6
  This library is free software; you can redistribute it and/or
7
7
  modify it under the terms of the GNU Lesser General Public
@@ -120,7 +120,7 @@ rb_grn_column_cache_initialize (VALUE self, VALUE rb_column)
120
120
  rb_grn_column_cache->context = NULL;
121
121
  rb_grn_column_cache->rb_column = rb_column;
122
122
  rb_grn_column_cache->column_cache = NULL;
123
- DATA_PTR(self) = rb_grn_column_cache;
123
+ RTYPEDDATA_DATA(self) = rb_grn_column_cache;
124
124
 
125
125
  column = RVAL2GRNCOLUMN(rb_column, &(rb_grn_column_cache->context));
126
126
  context = rb_grn_column_cache->context;
@@ -216,7 +216,7 @@ void
216
216
  rb_grn_init_column_cache (VALUE mGrn)
217
217
  {
218
218
  rb_cGrnColumnCache =
219
- rb_define_class_under(mGrn, "ColumnCache", rb_cData);
219
+ rb_define_class_under(mGrn, "ColumnCache", rb_cObject);
220
220
 
221
221
  rb_define_alloc_func(rb_cGrnColumnCache, rb_grn_column_cache_allocate);
222
222
 
@@ -1,7 +1,7 @@
1
1
  /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
2
  /* vim: set sts=4 sw=4 ts=8 noet: */
3
3
  /*
4
- Copyright (C) 2009-2015 Kouhei Sutou <kou@clear-code.com>
4
+ Copyright (C) 2009-2021 Sutou Kouhei <kou@clear-code.com>
5
5
  Copyright (C) 2016 Masafumi Yokoyama <yokoyama@clear-code.com>
6
6
 
7
7
  This library is free software; you can redistribute it and/or
@@ -20,7 +20,7 @@
20
20
 
21
21
  #include "rb-grn.h"
22
22
 
23
- #define SELF(object) ((RbGrnColumn *)DATA_PTR(object))
23
+ #define SELF(object) ((RbGrnColumn *)RTYPEDDATA_DATA(object))
24
24
 
25
25
  VALUE rb_cGrnColumn;
26
26
 
@@ -388,7 +388,7 @@ rb_grn_column_select (int argc, VALUE *argv, VALUE self)
388
388
  rb_funcall(builder, rb_intern("allow_leading_not="), 1, rb_allow_leading_not);
389
389
  rb_expression = rb_grn_column_expression_builder_build(builder);
390
390
  }
391
- rb_grn_object_deconstruct(RB_GRN_OBJECT(DATA_PTR(rb_expression)),
391
+ rb_grn_object_deconstruct(RB_GRN_OBJECT(RTYPEDDATA_DATA(rb_expression)),
392
392
  &expression, NULL,
393
393
  NULL, NULL, NULL, NULL);
394
394
 
@@ -831,7 +831,7 @@ rb_grn_column_rename (VALUE self, VALUE rb_name)
831
831
  rc = grn_column_rename(context, column, name, name_size);
832
832
  rb_grn_context_check(context, self);
833
833
  rb_grn_rc_check(rc, self);
834
- rb_grn_named_object_set_name(RB_GRN_NAMED_OBJECT(DATA_PTR(self)),
834
+ rb_grn_named_object_set_name(RB_GRN_NAMED_OBJECT(RTYPEDDATA_DATA(self)),
835
835
  name, name_size);
836
836
  return self;
837
837
  }
@@ -1,7 +1,8 @@
1
1
  /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
2
  /*
3
- Copyright (C) 2010-2018 Kouhei Sutou <kou@clear-code.com>
3
+ Copyright (C) 2010-2021 Sutou Kouhei <kou@clear-code.com>
4
4
  Copyright (C) 2016 Masafumi Yokoyama <yokoyama@clear-code.com>
5
+ Copyright (C) 2019 Horimoto Yasuhiro <horimoto@clear-code.com>
5
6
 
6
7
  This library is free software; you can redistribute it and/or
7
8
  modify it under the terms of the GNU Lesser General Public
@@ -17,12 +18,6 @@
17
18
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19
  */
19
20
 
20
- #include "rb-grn.h"
21
-
22
- #define SELF(object) (RVAL2GRNCONTEXT(object))
23
-
24
- static VALUE cGrnContext;
25
-
26
21
  /*
27
22
  * Document-class: Groonga::Context
28
23
  *
@@ -44,23 +39,11 @@ static VALUE cGrnContext;
44
39
  * する。
45
40
  */
46
41
 
47
- grn_ctx *
48
- rb_grn_context_from_ruby_object (VALUE object)
49
- {
50
- RbGrnContext *rb_grn_context;
42
+ #include "rb-grn.h"
51
43
 
52
- if (!RVAL2CBOOL(rb_obj_is_kind_of(object, cGrnContext))) {
53
- rb_raise(rb_eTypeError, "not a Groonga context");
54
- }
44
+ #define SELF(object) (RVAL2GRNCONTEXT(object))
55
45
 
56
- Data_Get_Struct(object, RbGrnContext, rb_grn_context);
57
- if (!rb_grn_context)
58
- rb_raise(rb_eGrnError, "Groonga context is NULL");
59
- if (!rb_grn_context->context)
60
- rb_raise(rb_eGrnClosed,
61
- "can't access already closed Groonga context");
62
- return rb_grn_context->context;
63
- }
46
+ static VALUE cGrnContext;
64
47
 
65
48
  void
66
49
  rb_grn_context_register_floating_object (RbGrnObject *rb_grn_object)
@@ -209,10 +192,48 @@ rb_grn_context_free (void *pointer)
209
192
  xfree(rb_grn_context);
210
193
  }
211
194
 
195
+ static rb_data_type_t data_type = {
196
+ "Groonga::Context",
197
+ {
198
+ NULL,
199
+ rb_grn_context_free,
200
+ NULL,
201
+ },
202
+ NULL,
203
+ NULL,
204
+ RUBY_TYPED_FREE_IMMEDIATELY
205
+ };
206
+
207
+ RbGrnContext *
208
+ rb_grn_context_get_struct (VALUE rb_context)
209
+ {
210
+ if (!RVAL2CBOOL(rb_obj_is_kind_of(rb_context, cGrnContext))) {
211
+ rb_raise(rb_eTypeError,
212
+ "not a Groonga context: %" PRIsVALUE,
213
+ rb_context);
214
+ }
215
+
216
+ RbGrnContext *rb_grn_context;
217
+ TypedData_Get_Struct(rb_context, RbGrnContext, &data_type, rb_grn_context);
218
+ return rb_grn_context;
219
+ }
220
+
221
+ grn_ctx *
222
+ rb_grn_context_from_ruby_object (VALUE rb_context)
223
+ {
224
+ RbGrnContext *rb_grn_context = rb_grn_context_get_struct(rb_context);
225
+ if (!rb_grn_context)
226
+ rb_raise(rb_eGrnError, "Groonga context is NULL");
227
+ if (!rb_grn_context->context)
228
+ rb_raise(rb_eGrnClosed,
229
+ "can't access already closed Groonga context");
230
+ return rb_grn_context->context;
231
+ }
232
+
212
233
  static VALUE
213
234
  rb_grn_context_alloc (VALUE klass)
214
235
  {
215
- return Data_Wrap_Struct(klass, NULL, rb_grn_context_free, NULL);
236
+ return TypedData_Wrap_Struct(klass, &data_type, NULL);
216
237
  }
217
238
 
218
239
  static grn_obj *
@@ -425,41 +446,50 @@ rb_grn_context_s_set_default_options (VALUE self, VALUE options)
425
446
  }
426
447
 
427
448
  /*
428
- * コンテキストを作成する。
429
- * @overload new(options=nil)
430
- * @param [::Hash] options The name and value
431
- * pairs. Omitted names are initialized as the default value.
432
- * @option options [Groonga::Encoding] :encoding The encoding
433
- * エンコーディングを指定する。エンコーディングの指定方法
434
- * {Groonga::Encoding} を参照。
449
+ * Creates a new context.
450
+ *
451
+ * @overload new(encoding: nil)
452
+ * @param encoding [Groonga::Encoding] The encoding to be used in
453
+ * the newly created context. See {Groonga::Encoding} how to specify
454
+ * encoding.
455
+ * @return [Groonga::Context] The newly created context.
435
456
  */
436
457
  static VALUE
437
458
  rb_grn_context_initialize (int argc, VALUE *argv, VALUE self)
438
459
  {
439
- RbGrnContext *rb_grn_context;
440
- grn_ctx *context;
441
- int flags = 0; /* TODO: GRN_CTX_PER_DB */
442
- VALUE options, default_options;
443
- VALUE rb_encoding;
460
+ VALUE options;
461
+ rb_scan_args(argc, argv, ":", &options);
444
462
 
445
- rb_scan_args(argc, argv, "01", &options);
446
- default_options = rb_grn_context_s_get_default_options(rb_obj_class(self));
447
- if (NIL_P(default_options))
448
- default_options = rb_hash_new();
449
-
450
- if (NIL_P(options))
451
- options = rb_hash_new();
452
- options = rb_funcall(default_options, rb_intern("merge"), 1, options);
453
-
454
- rb_grn_scan_options(options,
455
- "encoding", &rb_encoding,
456
- NULL);
463
+ static ID keyword_ids[1];
464
+ if (!keyword_ids[0]) {
465
+ CONST_ID(keyword_ids[0], "encoding");
466
+ }
467
+ VALUE kwargs[1];
468
+ VALUE rb_encoding = Qundef;
469
+ if (!NIL_P(options)) {
470
+ rb_get_kwargs(options, keyword_ids, 0, 1, kwargs);
471
+ rb_encoding = kwargs[0];
472
+ }
473
+ if (rb_encoding == Qundef) {
474
+ VALUE default_options =
475
+ rb_grn_context_s_get_default_options(rb_obj_class(self));
476
+ if (!NIL_P(default_options)) {
477
+ rb_get_kwargs(default_options, keyword_ids, 0, 1, kwargs);
478
+ rb_encoding = kwargs[0];
479
+ }
480
+ if (rb_encoding == Qundef) {
481
+ rb_encoding = Qnil;
482
+ }
483
+ }
457
484
 
458
- rb_grn_context = ALLOC(RbGrnContext);
459
- DATA_PTR(self) = rb_grn_context;
485
+ RbGrnContext *rb_grn_context = ALLOC(RbGrnContext);
486
+ RTYPEDDATA_DATA(self) = rb_grn_context;
460
487
  rb_grn_context->self = self;
488
+ int flags = 0; /* TODO: GRN_CTX_PER_DB */
461
489
  grn_ctx_init(&(rb_grn_context->context_entity), flags);
462
- context = rb_grn_context->context = &(rb_grn_context->context_entity);
490
+ grn_ctx *context =
491
+ rb_grn_context->context =
492
+ &(rb_grn_context->context_entity);
463
493
  rb_grn_context_check(context, self);
464
494
 
465
495
  GRN_CTX_USER_DATA(context)->ptr = rb_grn_context;
@@ -490,9 +520,7 @@ rb_grn_context_initialize (int argc, VALUE *argv, VALUE self)
490
520
  static VALUE
491
521
  rb_grn_context_close (VALUE self)
492
522
  {
493
- RbGrnContext *rb_grn_context;
494
-
495
- Data_Get_Struct(self, RbGrnContext, rb_grn_context);
523
+ RbGrnContext *rb_grn_context = RTYPEDDATA_DATA(self);
496
524
  if (rb_grn_context->context) {
497
525
  rb_grn_context_fin(rb_grn_context);
498
526
  }
@@ -508,10 +536,7 @@ rb_grn_context_close (VALUE self)
508
536
  static VALUE
509
537
  rb_grn_context_closed_p (VALUE self)
510
538
  {
511
- RbGrnContext *rb_grn_context;
512
-
513
- Data_Get_Struct(self, RbGrnContext, rb_grn_context);
514
-
539
+ RbGrnContext *rb_grn_context = RTYPEDDATA_DATA(self);
515
540
  return CBOOL2RVAL(rb_grn_context->context == NULL);
516
541
  }
517
542
 
@@ -604,6 +629,27 @@ rb_grn_context_get_ruby_encoding (VALUE self)
604
629
  return rb_grn_encoding_to_ruby_encoding_object(encoding);
605
630
  }
606
631
 
632
+ /*
633
+ * @overload force_match_escalation?
634
+ * @return [Bool]
635
+ */
636
+ static VALUE
637
+ rb_grn_context_force_match_escalation_p (VALUE self)
638
+ {
639
+ return CBOOL2RVAL(grn_ctx_get_force_match_escalation(SELF(self)));
640
+ }
641
+
642
+ /*
643
+ * @overload force_match_escalation=(force_match_escalation)
644
+ */
645
+ static VALUE
646
+ rb_grn_context_set_force_match_escalation (VALUE self, VALUE force_match_escalation)
647
+ {
648
+ grn_ctx_set_force_match_escalation(SELF(self),
649
+ RVAL2CBOOL(force_match_escalation));
650
+ return force_match_escalation;
651
+ }
652
+
607
653
  /*
608
654
  * このコンテキストを使って検索したときに検索の挙動をエスカレー
609
655
  * ションする閾値を返します。
@@ -1013,7 +1059,7 @@ rb_grn_context_object_created (VALUE rb_context, VALUE rb_object)
1013
1059
  void
1014
1060
  rb_grn_init_context (VALUE mGrn)
1015
1061
  {
1016
- cGrnContext = rb_define_class_under(mGrn, "Context", rb_cData);
1062
+ cGrnContext = rb_define_class_under(mGrn, "Context", rb_cObject);
1017
1063
  rb_define_alloc_func(cGrnContext, rb_grn_context_alloc);
1018
1064
 
1019
1065
  rb_cv_set(cGrnContext, "@@default", Qnil);
@@ -1039,6 +1085,11 @@ rb_grn_init_context (VALUE mGrn)
1039
1085
  rb_define_method(cGrnContext, "encoding=", rb_grn_context_set_encoding, 1);
1040
1086
  rb_define_method(cGrnContext, "ruby_encoding",
1041
1087
  rb_grn_context_get_ruby_encoding, 0);
1088
+
1089
+ rb_define_method(cGrnContext, "force_match_escalation?",
1090
+ rb_grn_context_force_match_escalation_p, 0);
1091
+ rb_define_method(cGrnContext, "force_match_escalation=",
1092
+ rb_grn_context_set_force_match_escalation, 1);
1042
1093
  rb_define_method(cGrnContext, "match_escalation_threshold",
1043
1094
  rb_grn_context_get_match_escalation_threshold, 0);
1044
1095
  rb_define_method(cGrnContext, "match_escalation_threshold=",
@@ -1,7 +1,7 @@
1
1
  /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
2
  /* vim: set sts=4 sw=4 ts=8 noet: */
3
3
  /*
4
- Copyright (C) 2016 Kouhei Sutou <kou@clear-code.com>
4
+ Copyright (C) 2016-2021 Sutou Kouhei <kou@clear-code.com>
5
5
 
6
6
  This library is free software; you can redistribute it and/or
7
7
  modify it under the terms of the GNU Lesser General Public
@@ -19,7 +19,7 @@
19
19
 
20
20
  #include "rb-grn.h"
21
21
 
22
- #define SELF(object) ((RbGrnColumn *)DATA_PTR(object))
22
+ #define SELF(object) ((RbGrnColumn *)RTYPEDDATA_DATA(object))
23
23
 
24
24
  VALUE rb_cGrnDataColumn;
25
25
 
@@ -152,7 +152,7 @@ rb_grn_data_column_apply_window_function (int argc, VALUE *argv, VALUE self)
152
152
  rb_builder = rb_grn_record_expression_builder_new(rb_table, Qnil);
153
153
  rb_window_function_call =
154
154
  rb_grn_record_expression_builder_build(rb_builder);
155
- rb_grn_object_deconstruct(RB_GRN_OBJECT(DATA_PTR(rb_window_function_call)),
155
+ rb_grn_object_deconstruct(RB_GRN_OBJECT(RTYPEDDATA_DATA(rb_window_function_call)),
156
156
  &window_function_call, NULL,
157
157
  NULL, NULL, NULL, NULL);
158
158
 
@@ -231,7 +231,7 @@ rb_grn_data_column_apply_expression (VALUE self)
231
231
 
232
232
  rb_builder = rb_grn_record_expression_builder_new(rb_table, Qnil);
233
233
  rb_expression = rb_grn_record_expression_builder_build(rb_builder);
234
- rb_grn_object_deconstruct(RB_GRN_OBJECT(DATA_PTR(rb_expression)),
234
+ rb_grn_object_deconstruct(RB_GRN_OBJECT(RTYPEDDATA_DATA(rb_expression)),
235
235
  &expression, NULL,
236
236
  NULL, NULL, NULL, NULL);
237
237
 
@@ -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-2015 Kouhei Sutou <kou@clear-code.com>
3
+ Copyright (C) 2009-2021 Sutou Kouhei <kou@clear-code.com>
4
4
  Copyright (C) 2016 Masafumi Yokoyama <yokoyama@clear-code.com>
5
5
 
6
6
  This library is free software; you can redistribute it and/or
@@ -17,12 +17,6 @@
17
17
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
  */
19
19
 
20
- #include "rb-grn.h"
21
-
22
- #define SELF(object) ((RbGrnObject *)DATA_PTR(object))
23
-
24
- VALUE rb_cGrnDatabase;
25
-
26
20
  /*
27
21
  * Document-class: Groonga::Database
28
22
  *
@@ -34,22 +28,11 @@ VALUE rb_cGrnDatabase;
34
28
  * に作成されないので明示的に作成する必要がある。
35
29
  */
36
30
 
37
- grn_obj *
38
- rb_grn_database_from_ruby_object (VALUE object)
39
- {
40
- if (!RVAL2CBOOL(rb_obj_is_kind_of(object, rb_cGrnDatabase))) {
41
- rb_raise(rb_eTypeError, "not a groonga database");
42
- }
31
+ #include "rb-grn.h"
43
32
 
44
- return RVAL2GRNOBJECT(object, NULL);
45
- }
33
+ #define SELF(object) ((RbGrnObject *)RTYPEDDATA_DATA(object))
46
34
 
47
- VALUE
48
- rb_grn_database_to_ruby_object (grn_ctx *context, grn_obj *database,
49
- grn_bool owner)
50
- {
51
- return GRNOBJECT2RVAL(rb_cGrnDatabase, context, database, owner);
52
- }
35
+ VALUE rb_cGrnDatabase;
53
36
 
54
37
  static void
55
38
  rb_grn_database_mark_existing_ruby_object (grn_ctx *context, grn_obj *database)
@@ -86,11 +69,45 @@ rb_grn_database_mark (void *data)
86
69
  rb_grn_database_mark_existing_ruby_object(context, database);
87
70
  }
88
71
 
72
+ static void
73
+ rb_grn_database_free (void *pointer)
74
+ {
75
+ rb_grn_object_free(pointer);
76
+ }
77
+
78
+ static rb_data_type_t data_type = {
79
+ "Groonga::Database",
80
+ {
81
+ rb_grn_database_mark,
82
+ rb_grn_database_free,
83
+ NULL,
84
+ },
85
+ &rb_grn_object_data_type,
86
+ NULL,
87
+ RUBY_TYPED_FREE_IMMEDIATELY
88
+ };
89
+
90
+ grn_obj *
91
+ rb_grn_database_from_ruby_object (VALUE object)
92
+ {
93
+ if (!RVAL2CBOOL(rb_obj_is_kind_of(object, rb_cGrnDatabase))) {
94
+ rb_raise(rb_eTypeError, "not a Rroonga database");
95
+ }
96
+
97
+ return RVAL2GRNOBJECT(object, NULL);
98
+ }
99
+
100
+ VALUE
101
+ rb_grn_database_to_ruby_object (grn_ctx *context, grn_obj *database,
102
+ grn_bool owner)
103
+ {
104
+ return GRNOBJECT2RVAL(rb_cGrnDatabase, context, database, owner);
105
+ }
106
+
89
107
  static VALUE
90
108
  rb_grn_database_alloc (VALUE klass)
91
109
  {
92
- return Data_Wrap_Struct(klass, rb_grn_database_mark, rb_grn_object_free,
93
- NULL);
110
+ return TypedData_Wrap_Struct(klass, &data_type, NULL);
94
111
  }
95
112
 
96
113
  static void
@@ -143,8 +160,7 @@ rb_grn_database_close (VALUE self)
143
160
  static void
144
161
  reset_floating_objects (VALUE rb_context)
145
162
  {
146
- RbGrnContext *rb_grn_context;
147
- Data_Get_Struct(rb_context, RbGrnContext, rb_grn_context);
163
+ RbGrnContext *rb_grn_context = rb_grn_context_get_struct(rb_context);
148
164
  rb_grn_context_reset_floating_objects(rb_grn_context);
149
165
  }
150
166
 
@@ -189,8 +205,10 @@ rb_grn_database_s_create (int argc, VALUE *argv, VALUE klass)
189
205
  "builtin_type_names", &builtin_type_names,
190
206
  NULL);
191
207
 
192
- if (!NIL_P(rb_path))
208
+ if (!NIL_P(rb_path)) {
209
+ FilePathValue(rb_path);
193
210
  path = StringValuePtr(rb_path);
211
+ }
194
212
  context = rb_grn_context_ensure(&rb_context);
195
213
 
196
214
  create_args.builtin_type_names = NULL;
@@ -245,6 +263,7 @@ rb_grn_database_initialize (int argc, VALUE *argv, VALUE self)
245
263
 
246
264
  rb_scan_args(argc, argv, "11", &rb_path, &options);
247
265
 
266
+ FilePathValue(rb_path);
248
267
  path = StringValuePtr(rb_path);
249
268
  rb_grn_scan_options(options,
250
269
  "context", &rb_context,