rroonga 10.0.6 → 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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +24 -0
  3. data/doc/text/news.md +12 -0
  4. data/ext/groonga/extconf.rb +12 -2
  5. data/ext/groonga/rb-grn-accessor.c +2 -2
  6. data/ext/groonga/rb-grn-column-cache.c +3 -3
  7. data/ext/groonga/rb-grn-column.c +4 -4
  8. data/ext/groonga/rb-grn-context.c +82 -58
  9. data/ext/groonga/rb-grn-data-column.c +4 -4
  10. data/ext/groonga/rb-grn-database.c +45 -26
  11. data/ext/groonga/rb-grn-double-array-trie.c +2 -2
  12. data/ext/groonga/rb-grn-encoding-support.c +2 -2
  13. data/ext/groonga/rb-grn-exception.c +14 -0
  14. data/ext/groonga/rb-grn-expression.c +3 -3
  15. data/ext/groonga/rb-grn-fix-size-column.c +2 -2
  16. data/ext/groonga/rb-grn-flushable.c +2 -1
  17. data/ext/groonga/rb-grn-hash.c +2 -2
  18. data/ext/groonga/rb-grn-index-column.c +3 -3
  19. data/ext/groonga/rb-grn-index-cursor.c +2 -2
  20. data/ext/groonga/rb-grn-inverted-index-cursor.c +3 -3
  21. data/ext/groonga/rb-grn-object.c +30 -9
  22. data/ext/groonga/rb-grn-operator.c +100 -259
  23. data/ext/groonga/rb-grn-patricia-trie.c +2 -2
  24. data/ext/groonga/rb-grn-plugin.c +34 -22
  25. data/ext/groonga/rb-grn-request-timer-id.c +2 -2
  26. data/ext/groonga/rb-grn-snippet.c +3 -3
  27. data/ext/groonga/rb-grn-table-cursor-key-support.c +2 -2
  28. data/ext/groonga/rb-grn-table-cursor.c +3 -3
  29. data/ext/groonga/rb-grn-table-key-support.c +3 -3
  30. data/ext/groonga/rb-grn-table.c +63 -45
  31. data/ext/groonga/rb-grn-variable-size-column.c +2 -2
  32. data/ext/groonga/rb-grn-variable.c +2 -2
  33. data/ext/groonga/rb-grn.h +7 -4
  34. data/ext/groonga/rb-groonga.c +5 -1
  35. data/lib/groonga/context.rb +32 -0
  36. data/rroonga-build.rb +5 -4
  37. data/rroonga.gemspec +5 -2
  38. data/test/groonga-test-utils.rb +3 -0
  39. data/test/test-index-column.rb +3 -3
  40. data/test/test-ractor.rb +65 -0
  41. data/test/test-remote.rb +2 -0
  42. data/test/test-table-arrow.rb +21 -9
  43. metadata +85 -69
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2dda7dccd26063c5e82e93255c933215a21a37e0c31838eec124b3f12ce3892
4
- data.tar.gz: 472fed29e2ba91ff00dd71981ff59a6866c9a292ea7ac83dc5881bd1069536e1
3
+ metadata.gz: d2e5c28e453fae2876164e7ea4ef8e3e24b0e789bec2c6cd270850905296a9c5
4
+ data.tar.gz: 8f8cac4d824bc94e0f89dd8ee60e8b2a0fd0fb92b1e666dfbb7732ef43c7bb96
5
5
  SHA512:
6
- metadata.gz: 0f4c1aa03b1efc04321588d3dfac9a208dafc35c2a1a84724e47a035a1a3eb7cabeaa6d58655fe6e324c1fbfa706812a5c0cdb817686cbde2a947659c3231c76
7
- data.tar.gz: fe41f7d510f5ddb1cdd88a8d6de87d477f0f45714f09691b01b2a750bd89c31dd2a60ae334f15e216bfa4fa7752f10f765112efce4c75ecd7084a42b27af837f
6
+ metadata.gz: e23a7b4d5aaa7375ee7347fdce6706d90311f8447ec41d7ecf7d0864258f9992cbba7a9521d5afd5589197a25e3b3acece7c7c515ecfb2980daa8329639a678b
7
+ data.tar.gz: cefd86c0fc0053aa34d669b4cb94f78d38dc63ee4faea9c32b1a5519fc231f99bc1146e8f54bb50d38a60d89e1129a7e5145bc03107f05cf3925cd8687cf98fa
data/Rakefile CHANGED
@@ -74,4 +74,28 @@ namespace :test do
74
74
  end
75
75
  end
76
76
 
77
+ def update_version(new_version)
78
+ splitted_new_version = new_version.split(".")
79
+ type_order = ["MAJOR", "MINOR", "MICRO"]
80
+ File.open("ext/groonga/rb-grn.h", "rb+") do |rb_grn_h|
81
+ content = rb_grn_h.read
82
+ content.gsub!(/(RB_GRN_(MAJOR|MINOR|MICRO)_VERSION) \d+/) do
83
+ name = $1
84
+ type = $2
85
+ "#{name} #{splitted_new_version[type_order.index(type)]}"
86
+ end
87
+ rb_grn_h.rewind
88
+ rb_grn_h.write(content)
89
+ end
90
+ end
91
+
92
+ namespace :version do
93
+ desc "Update version"
94
+ task :update do |_, args|
95
+ new_version = ENV["NEW_VERSION"]
96
+ raise "NEW_VERSION must be specified" if new_version.nil?
97
+ update_version(new_version)
98
+ end
99
+ end
100
+
77
101
  task :default => :test
data/doc/text/news.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # NEWS
2
2
 
3
+ ## 11.0.0: 2021-02-09 {#version-11-0-0}
4
+
5
+ ### Improvements
6
+
7
+ * {Groonga::ConnectionReset} Added.
8
+
9
+ * {Groonga::Context.open} Added.
10
+
11
+ * Added support for Ractor.
12
+
13
+ * {Groonga::Database} Accept path like object in .open/.create.
14
+
3
15
  ## 10.0.6: 2020-09-01 {#version-10-0-6}
4
16
 
5
17
  ### Fixes
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
- # Copyright (C) 2009-2020 Sutou Kouhei <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
@@ -23,6 +23,7 @@ require "shellwords"
23
23
  require "open-uri"
24
24
  require "uri"
25
25
 
26
+ require "native-package-installer"
26
27
  require "pkg-config"
27
28
 
28
29
  base_dir = Pathname(__FILE__).dirname.parent.parent.expand_path
@@ -77,7 +78,7 @@ def download(url)
77
78
  ]
78
79
  end
79
80
  end
80
- open(url, "rb", options) do |input|
81
+ URI.open(url, "rb", *options) do |input|
81
82
  File.open(base_name, "wb") do |output|
82
83
  while (buffer = input.read(1024))
83
84
  output.print(buffer)
@@ -223,7 +224,16 @@ def install_local_groonga(package_name, major, minor, micro)
223
224
  add_rpath_for_local_groonga
224
225
  end
225
226
 
227
+ need_auto_groonga_install = false
226
228
  unless PKGConfig.have_package(package_name, major, minor, micro)
229
+ if NativePackageInstaller.install(debian: "libgroonga-dev",
230
+ homebrew: "groonga",
231
+ msys2: "groonga")
232
+ need_auto_groonga_install =
233
+ !PKGConfig.have_package(package_name, major, minor, micro)
234
+ end
235
+ end
236
+ if need_auto_groonga_install
227
237
  install_local_groonga(package_name, major, minor, micro)
228
238
  end
229
239
 
@@ -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,6 +1,6 @@
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
5
  Copyright (C) 2019 Horimoto Yasuhiro <horimoto@clear-code.com>
6
6
 
@@ -18,12 +18,6 @@
18
18
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
19
  */
20
20
 
21
- #include "rb-grn.h"
22
-
23
- #define SELF(object) (RVAL2GRNCONTEXT(object))
24
-
25
- static VALUE cGrnContext;
26
-
27
21
  /*
28
22
  * Document-class: Groonga::Context
29
23
  *
@@ -45,23 +39,11 @@ static VALUE cGrnContext;
45
39
  * する。
46
40
  */
47
41
 
48
- grn_ctx *
49
- rb_grn_context_from_ruby_object (VALUE object)
50
- {
51
- RbGrnContext *rb_grn_context;
42
+ #include "rb-grn.h"
52
43
 
53
- if (!RVAL2CBOOL(rb_obj_is_kind_of(object, cGrnContext))) {
54
- rb_raise(rb_eTypeError, "not a Groonga context");
55
- }
44
+ #define SELF(object) (RVAL2GRNCONTEXT(object))
56
45
 
57
- Data_Get_Struct(object, RbGrnContext, rb_grn_context);
58
- if (!rb_grn_context)
59
- rb_raise(rb_eGrnError, "Groonga context is NULL");
60
- if (!rb_grn_context->context)
61
- rb_raise(rb_eGrnClosed,
62
- "can't access already closed Groonga context");
63
- return rb_grn_context->context;
64
- }
46
+ static VALUE cGrnContext;
65
47
 
66
48
  void
67
49
  rb_grn_context_register_floating_object (RbGrnObject *rb_grn_object)
@@ -210,10 +192,48 @@ rb_grn_context_free (void *pointer)
210
192
  xfree(rb_grn_context);
211
193
  }
212
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
+
213
233
  static VALUE
214
234
  rb_grn_context_alloc (VALUE klass)
215
235
  {
216
- return Data_Wrap_Struct(klass, NULL, rb_grn_context_free, NULL);
236
+ return TypedData_Wrap_Struct(klass, &data_type, NULL);
217
237
  }
218
238
 
219
239
  static grn_obj *
@@ -426,41 +446,50 @@ rb_grn_context_s_set_default_options (VALUE self, VALUE options)
426
446
  }
427
447
 
428
448
  /*
429
- * コンテキストを作成する。
430
- * @overload new(options=nil)
431
- * @param [::Hash] options The name and value
432
- * pairs. Omitted names are initialized as the default value.
433
- * @option options [Groonga::Encoding] :encoding The encoding
434
- * エンコーディングを指定する。エンコーディングの指定方法
435
- * {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.
436
456
  */
437
457
  static VALUE
438
458
  rb_grn_context_initialize (int argc, VALUE *argv, VALUE self)
439
459
  {
440
- RbGrnContext *rb_grn_context;
441
- grn_ctx *context;
442
- int flags = 0; /* TODO: GRN_CTX_PER_DB */
443
- VALUE options, default_options;
444
- VALUE rb_encoding;
445
-
446
- rb_scan_args(argc, argv, "01", &options);
447
- default_options = rb_grn_context_s_get_default_options(rb_obj_class(self));
448
- if (NIL_P(default_options))
449
- default_options = rb_hash_new();
460
+ VALUE options;
461
+ rb_scan_args(argc, argv, ":", &options);
450
462
 
451
- if (NIL_P(options))
452
- options = rb_hash_new();
453
- options = rb_funcall(default_options, rb_intern("merge"), 1, options);
454
-
455
- rb_grn_scan_options(options,
456
- "encoding", &rb_encoding,
457
- 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
+ }
458
484
 
459
- rb_grn_context = ALLOC(RbGrnContext);
460
- DATA_PTR(self) = rb_grn_context;
485
+ RbGrnContext *rb_grn_context = ALLOC(RbGrnContext);
486
+ RTYPEDDATA_DATA(self) = rb_grn_context;
461
487
  rb_grn_context->self = self;
488
+ int flags = 0; /* TODO: GRN_CTX_PER_DB */
462
489
  grn_ctx_init(&(rb_grn_context->context_entity), flags);
463
- 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);
464
493
  rb_grn_context_check(context, self);
465
494
 
466
495
  GRN_CTX_USER_DATA(context)->ptr = rb_grn_context;
@@ -491,9 +520,7 @@ rb_grn_context_initialize (int argc, VALUE *argv, VALUE self)
491
520
  static VALUE
492
521
  rb_grn_context_close (VALUE self)
493
522
  {
494
- RbGrnContext *rb_grn_context;
495
-
496
- Data_Get_Struct(self, RbGrnContext, rb_grn_context);
523
+ RbGrnContext *rb_grn_context = RTYPEDDATA_DATA(self);
497
524
  if (rb_grn_context->context) {
498
525
  rb_grn_context_fin(rb_grn_context);
499
526
  }
@@ -509,10 +536,7 @@ rb_grn_context_close (VALUE self)
509
536
  static VALUE
510
537
  rb_grn_context_closed_p (VALUE self)
511
538
  {
512
- RbGrnContext *rb_grn_context;
513
-
514
- Data_Get_Struct(self, RbGrnContext, rb_grn_context);
515
-
539
+ RbGrnContext *rb_grn_context = RTYPEDDATA_DATA(self);
516
540
  return CBOOL2RVAL(rb_grn_context->context == NULL);
517
541
  }
518
542
 
@@ -1035,7 +1059,7 @@ rb_grn_context_object_created (VALUE rb_context, VALUE rb_object)
1035
1059
  void
1036
1060
  rb_grn_init_context (VALUE mGrn)
1037
1061
  {
1038
- cGrnContext = rb_define_class_under(mGrn, "Context", rb_cData);
1062
+ cGrnContext = rb_define_class_under(mGrn, "Context", rb_cObject);
1039
1063
  rb_define_alloc_func(cGrnContext, rb_grn_context_alloc);
1040
1064
 
1041
1065
  rb_cv_set(cGrnContext, "@@default", Qnil);
@@ -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,