[Groonga-commit] groonga/groonga at 63c0938 [master] mrb: bind grn_cache

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Jul 16 17:22:21 JST 2015


Kouhei Sutou	2015-07-16 17:22:21 +0900 (Thu, 16 Jul 2015)

  New Revision: 63c093817d465e5e719d4b847d1efb5f4e45de6b
  https://github.com/groonga/groonga/commit/63c093817d465e5e719d4b847d1efb5f4e45de6b

  Message:
    mrb: bind grn_cache

  Added files:
    lib/mrb/mrb_cache.c
    lib/mrb/mrb_cache.h
  Modified files:
    lib/ctx_impl_mrb.c
    lib/mrb/sources.am

  Modified: lib/ctx_impl_mrb.c (+2 -0)
===================================================================
--- lib/ctx_impl_mrb.c    2015-07-16 17:21:01 +0900 (f352ea8)
+++ lib/ctx_impl_mrb.c    2015-07-16 17:22:21 +0900 (5db89a3)
@@ -33,6 +33,7 @@
 # include "mrb/mrb_logger.h"
 # include "mrb/mrb_void.h"
 # include "mrb/mrb_bulk.h"
+# include "mrb/mrb_cache.h"
 # include "mrb/mrb_object.h"
 # include "mrb/mrb_object_flags.h"
 # include "mrb/mrb_database.h"
@@ -141,6 +142,7 @@ grn_ctx_impl_mrb_init_bindings(grn_ctx *ctx)
   grn_mrb_logger_init(ctx);
   grn_mrb_void_init(ctx);
   grn_mrb_bulk_init(ctx);
+  grn_mrb_cache_init(ctx);
   grn_mrb_object_init(ctx);
   grn_mrb_object_flags_init(ctx);
   grn_mrb_database_init(ctx);

  Added: lib/mrb/mrb_cache.c (+122 -0) 100644
===================================================================
--- /dev/null
+++ lib/mrb/mrb_cache.c    2015-07-16 17:22:21 +0900 (71aa7fb)
@@ -0,0 +1,122 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2015 Brazil
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include "../grn_ctx_impl.h"
+
+#ifdef GRN_WITH_MRUBY
+#include <mruby.h>
+#include <mruby/class.h>
+#include <mruby/data.h>
+
+#include "../grn_db.h"
+#include "mrb_bulk.h"
+#include "mrb_cache.h"
+
+static struct mrb_data_type mrb_grn_cache_type = {
+  "Groonga::Cache",
+  NULL
+};
+
+static mrb_value
+mrb_grn_cache_initialize(mrb_state *mrb, mrb_value self)
+{
+  mrb_value mrb_cache_ptr;
+
+  mrb_get_args(mrb, "o", &mrb_cache_ptr);
+  DATA_TYPE(self) = &mrb_grn_cache_type;
+  DATA_PTR(self) = mrb_cptr(mrb_cache_ptr);
+  return self;
+}
+
+static mrb_value
+mrb_grn_cache_fetch(mrb_state *mrb, mrb_value self)
+{
+  grn_ctx *ctx = (grn_ctx *)mrb->ud;
+  grn_cache *cache;
+  char *key;
+  mrb_int key_size;
+  grn_obj *value;
+
+  cache = DATA_PTR(self);
+  mrb_get_args(mrb, "s", &key, &key_size);
+
+  value = grn_cache_fetch(ctx, cache, key, key_size);
+
+  return grn_mrb_value_from_bulk(mrb, value);
+}
+
+static mrb_value
+mrb_grn_cache_unref(mrb_state *mrb, mrb_value self)
+{
+  grn_ctx *ctx = (grn_ctx *)mrb->ud;
+  grn_cache *cache;
+  char *key;
+  mrb_int key_size;
+
+  cache = DATA_PTR(self);
+  mrb_get_args(mrb, "s", &key, &key_size);
+
+  grn_cache_unref(ctx, cache, key, key_size);
+
+  return mrb_nil_value();
+}
+
+static mrb_value
+mrb_grn_cache_update(mrb_state *mrb, mrb_value self)
+{
+  grn_ctx *ctx = (grn_ctx *)mrb->ud;
+  grn_cache *cache;
+  char *key;
+  mrb_int key_size;
+  char *value;
+  mrb_int value_size;
+  grn_obj value_buffer;
+
+  cache = DATA_PTR(self);
+  mrb_get_args(mrb, "ss", &key, &key_size, &value, &value_size);
+
+  GRN_TEXT_INIT(&value_buffer, GRN_OBJ_REFER);
+  GRN_TEXT_SET(ctx, &value_buffer, value, value_size);
+  grn_cache_update(ctx, cache, key, key_size, &value_buffer);
+  GRN_OBJ_FIN(ctx, &value_buffer);
+
+  return mrb_nil_value();
+}
+
+void
+grn_mrb_cache_init(grn_ctx *ctx)
+{
+  grn_mrb_data *data = &(ctx->impl->mrb);
+  mrb_state *mrb = data->state;
+  struct RClass *module = data->module;
+  struct RClass *klass;
+
+  klass = mrb_define_class_under(mrb, module, "Cache", mrb->object_class);
+  MRB_SET_INSTANCE_TT(klass, MRB_TT_DATA);
+
+  mrb_define_method(mrb, klass, "initialize",
+                    mrb_grn_cache_initialize, MRB_ARGS_REQ(1));
+
+  mrb_define_method(mrb, klass, "fetch",
+                    mrb_grn_cache_fetch, MRB_ARGS_REQ(1));
+  mrb_define_method(mrb, klass, "unref",
+                    mrb_grn_cache_unref, MRB_ARGS_REQ(1));
+  mrb_define_method(mrb, klass, "update",
+                    mrb_grn_cache_update, MRB_ARGS_REQ(2));
+}
+#endif

  Added: lib/mrb/mrb_cache.h (+35 -0) 100644
===================================================================
--- /dev/null
+++ lib/mrb/mrb_cache.h    2015-07-16 17:22:21 +0900 (dc18c6e)
@@ -0,0 +1,35 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2015 Brazil
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#ifndef GRN_MRB_CACHE_H
+#define GRN_MRB_CACHE_H
+
+#include "../grn_ctx.h"
+#include "../grn_db.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void grn_mrb_cache_init(grn_ctx *ctx);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GRN_MRB_CACHE_H */

  Modified: lib/mrb/sources.am (+2 -0)
===================================================================
--- lib/mrb/sources.am    2015-07-16 17:21:01 +0900 (dc1a78d)
+++ lib/mrb/sources.am    2015-07-16 17:22:21 +0900 (9433781)
@@ -5,6 +5,8 @@ libgrnmrb_la_SOURCES =				\
 	mrb_array.h				\
 	mrb_bulk.c				\
 	mrb_bulk.h				\
+	mrb_cache.c				\
+	mrb_cache.h				\
 	mrb_column.c				\
 	mrb_column.h				\
 	mrb_command.c				\
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index