rroonga 10.0.1 → 11.0.6

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 (51) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/Rakefile +30 -28
  4. data/doc/text/news.md +51 -5
  5. data/doc/text/tutorial.md +1 -1
  6. data/ext/groonga/extconf.rb +18 -3
  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 +82 -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 +2 -1
  20. data/ext/groonga/rb-grn-hash.c +2 -2
  21. data/ext/groonga/rb-grn-index-column.c +3 -3
  22. data/ext/groonga/rb-grn-index-cursor.c +2 -2
  23. data/ext/groonga/rb-grn-inverted-index-cursor.c +3 -3
  24. data/ext/groonga/rb-grn-object.c +30 -9
  25. data/ext/groonga/rb-grn-operator.c +100 -259
  26. data/ext/groonga/rb-grn-patricia-trie.c +2 -2
  27. data/ext/groonga/rb-grn-plugin.c +34 -22
  28. data/ext/groonga/rb-grn-request-timer-id.c +2 -2
  29. data/ext/groonga/rb-grn-snippet.c +3 -3
  30. data/ext/groonga/rb-grn-table-cursor-key-support.c +2 -2
  31. data/ext/groonga/rb-grn-table-cursor.c +3 -3
  32. data/ext/groonga/rb-grn-table-key-support.c +6 -4
  33. data/ext/groonga/rb-grn-table.c +63 -45
  34. data/ext/groonga/rb-grn-type.c +5 -1
  35. data/ext/groonga/rb-grn-utils.c +17 -1
  36. data/ext/groonga/rb-grn-variable-size-column.c +2 -2
  37. data/ext/groonga/rb-grn-variable.c +2 -2
  38. data/ext/groonga/rb-grn.h +10 -5
  39. data/ext/groonga/rb-groonga.c +6 -2
  40. data/lib/groonga/context.rb +32 -0
  41. data/rroonga-build.rb +5 -4
  42. data/rroonga.gemspec +5 -2
  43. data/test/groonga-test-utils.rb +9 -0
  44. data/test/run-test.rb +1 -1
  45. data/test/test-column.rb +12 -1
  46. data/test/test-index-column.rb +3 -3
  47. data/test/test-logger.rb +2 -0
  48. data/test/test-ractor.rb +65 -0
  49. data/test/test-remote.rb +16 -0
  50. data/test/test-table-arrow.rb +20 -11
  51. metadata +84 -68
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d4f0e0fdf1d23daf834ebb866894d0f05955af7187e07821154e151090273e06
4
- data.tar.gz: e1bff6c3547943e270b04f1c2674845ef26bf2f1a64f40ec72f682a0d3b30843
3
+ metadata.gz: 0bd3a26cbf30ec083561fea23d5aa458ce1a53e5644caedfb646f6717e197f34
4
+ data.tar.gz: ae0004a24279a953a311606da7b58f9d8960b703897af7aa868b2b4980a9cddd
5
5
  SHA512:
6
- metadata.gz: ee1389b602d9544eb31a7273bf313f83da7599bb6317ffd9e83614bfd334af52d2fad638f23790095a4c2f56e8c70f66dc38a43d968e777e0c2fd0c0fa2e33a1
7
- data.tar.gz: 3de057e696486314205762ea1bc6160c892d422cc04dbc8a98e5458ce2cf3404ba28901668158eb65e8b0af0493e5dad1bb5fd4f3ff7c32d02a7cdec65f22e11
6
+ metadata.gz: '0290bfd09da3231a50c2ec4e691efac8c2f2f4b5f9c807507c5aa17540867a8db7060e44c4f0804093c7e6d802679a248b5edfb7038e5b00968bbf4547a4bc43'
7
+ data.tar.gz: 679af8fcbdb4f88efa9b58bfa339a5d2f4af7f044301ff8028ac2aa65d14f97f7ee7b231186ccda9ce632b9f1483d90eb3b01eb63f60f2d90797d565fe9b5f17
data/.yardopts CHANGED
@@ -1,6 +1,7 @@
1
1
  --output-dir doc/reference/en
2
2
  --markup markdown
3
3
  --markup-provider kramdown
4
+ --asset doc/images:images
4
5
  lib/**/*.rb
5
6
  ext/**/*.c
6
7
  -
data/Rakefile CHANGED
@@ -46,28 +46,6 @@ Packnga::ReleaseTask.new(spec) do |task|
46
46
  task.index_html_dir = ranguba_org_dir
47
47
  end
48
48
 
49
- module YARD
50
- module CodeObjects
51
- class Proxy
52
- alias_method :initialize_original, :initialize
53
- def initialize(namespace, name, type=nil)
54
- name = name.to_s.gsub(/\AGrn(.*)\z/) do
55
- suffix = $1
56
- case suffix
57
- when ""
58
- "Groonga"
59
- when "TableKeySupport"
60
- "Groonga::Table::KeySupport"
61
- else
62
- "Groonga::#{suffix}"
63
- end
64
- end
65
- initialize_original(namespace, name, type)
66
- end
67
- end
68
- end
69
- end
70
-
71
49
  file "Makefile" => ["extconf.rb", "ext/groonga/extconf.rb"] do
72
50
  extconf_args = []
73
51
  if ENV["TRAVIS"]
@@ -85,15 +63,39 @@ task :test => :configure do
85
63
  end
86
64
 
87
65
  namespace :test do
88
- task :install do
89
- gemspec_helper = Rake.application.jeweler.gemspec_helper
90
- ruby("-S gem install --user-install #{gemspec_helper.gem_path}")
91
-
92
- gem_spec = Gem.source_index.find_name("rroonga").last
93
- installed_path = gem_spec.full_gem_path
66
+ task :install => "install" do
67
+ rroonga_specs = Gem.source_index.find_name("rroonga")
68
+ target_rroonga_spec = rroonga_specs.find do |rroonga_spec|
69
+ rroonga_spec.version == helper.gemspec.version
70
+ end
71
+ installed_path = target_rroonga_spec.full_gem_path
94
72
  ENV["NO_MAKE"] = "yes"
95
73
  ruby("#{installed_path}/test/run-test.rb")
96
74
  end
97
75
  end
98
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
+
99
101
  task :default => :test
data/doc/text/news.md CHANGED
@@ -1,5 +1,47 @@
1
1
  # NEWS
2
2
 
3
+ ## 11.0.6: 2021-09-24 {#version-11-0-6}
4
+
5
+ ### Improvements
6
+
7
+ * Installed Groonga automatically when native package isn't
8
+ installed automatically.
9
+ [GitHub#204][Patch by skawaji]
10
+
11
+ ### Thanks
12
+
13
+ * skawaji
14
+
15
+ ## 11.0.0: 2021-02-09 {#version-11-0-0}
16
+
17
+ ### Improvements
18
+
19
+ * {Groonga::ConnectionReset} Added.
20
+
21
+ * {Groonga::Context.open} Added.
22
+
23
+ * Added support for Ractor.
24
+
25
+ * {Groonga::Database} Accept path like object in .open/.create.
26
+
27
+ ## 10.0.6: 2020-09-01 {#version-10-0-6}
28
+
29
+ ### Fixes
30
+
31
+ * Fixed a bug that failed `gem install rroonga` in Windows version.
32
+
33
+ ## 10.0.2: 2020-04-29 {#version-10-0-2}
34
+
35
+ ### Improvements
36
+
37
+ * Added support for Float32 in Groonga 10.0.2.
38
+
39
+ * [doc] Fixed markup of a image in tutorial [GitHub#192][Patched by takahashim]
40
+
41
+ ### Thanks
42
+
43
+ * takahashim
44
+
3
45
  ## 10.0.1: 2020-04-02 {#version-10-0-1}
4
46
 
5
47
  ### Improvements
@@ -22,11 +64,15 @@
22
64
 
23
65
  * {Groonga::IndexColumn} Added support "INDEX_LARGE".
24
66
 
25
- * {Groonga::IndexCursor.min_enable?/min_enable=} Added.
67
+ * {Groonga::IndexCursor#set_min?} Added.
68
+
69
+ * {Groonga::IndexCursor#set_min=} Added.
70
+
71
+ * {Groonga::Context#force_match_escalation?} Added.
26
72
 
27
- * {Groonga::Context#match_escalation?/match_escalation=} Added.
73
+ * {Groonga::Context#force_match_escalation=} Added.
28
74
 
29
- * {Groona::Object#id_accessor?} Added.
75
+ * {Groonga::Object#id_accessor?} Added.
30
76
 
31
77
  * {Groonga::Logger.flags} Added support for thread id option.
32
78
 
@@ -36,7 +82,7 @@
36
82
 
37
83
  * {Groonga::Table} Delegate support_score? from Groonga::Record to Groonga::Table.
38
84
 
39
- * {Groonga::Flashable} Added support dependent option.
85
+ * Groonga::Flashable Added support dependent option.
40
86
 
41
87
  * {Groonga::Object#score_accessor?} Added.
42
88
 
@@ -59,7 +105,7 @@
59
105
  * Added support for "--with-groonga-configure-options".
60
106
  [GitHub#146][Reported by Tomás Pollak]
61
107
 
62
- * {Groonga::RegexpExpressionBuilder}: Added support (?-mix:XXX) for searching of regular expression.
108
+ * Groonga::RegexpExpressionBuilder: Added support (?-mix:XXX) for searching of regular expression.
63
109
  [groonga-dev,04694][Reported by Masatoshi SEKI]
64
110
 
65
111
  * Use "groonga-latest.tar.gz" for build Groonga.
data/doc/text/tutorial.md CHANGED
@@ -178,7 +178,7 @@ bookmarks.
178
178
 
179
179
  First, you add tables for users and for comments like below:
180
180
 
181
- !http://qwik.jp/senna/senna2.files/rect4605.png!
181
+ ![Sample schema](images/sample-schema.png)
182
182
 
183
183
  Let's add the table for users, `Users`.
184
184
 
@@ -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,18 @@ 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
+ else
235
+ need_auto_groonga_install = true
236
+ end
237
+ end
238
+ if need_auto_groonga_install
227
239
  install_local_groonga(package_name, major, minor, micro)
228
240
  end
229
241
 
@@ -267,7 +279,7 @@ end
267
279
 
268
280
  def enable_debug_build_flag(flags)
269
281
  if gcc?
270
- flags.gsub(/(^|\s)?-g\d?(\s|$)?/, '\\1-ggdb3\\2')
282
+ flags.gsub(/(^|\s)?-g\d?(\s|$)/, '\\1-ggdb3\\2')
271
283
  else
272
284
  flags
273
285
  end
@@ -279,6 +291,9 @@ checking_for(checking_message("--enable-debug-build option")) do
279
291
  $CFLAGS = disable_optimization_build_flag($CFLAGS)
280
292
  $CFLAGS = enable_debug_build_flag($CFLAGS)
281
293
 
294
+ CONFIG["optflags"] = disable_optimization_build_flag(CONFIG["optflags"])
295
+ CONFIG["debugflags"] = enable_debug_build_flag(CONFIG["debugflags"])
296
+
282
297
  CONFIG["CXXFLAGS"] = disable_optimization_build_flag(CONFIG["CXXFLAGS"])
283
298
  CONFIG["CXXFLAGS"] = enable_debug_build_flag(CONFIG["CXXFLAGS"])
284
299
  end
@@ -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