Kouhei Sutou
null+****@clear*****
Thu Feb 18 22:38:06 JST 2016
Kouhei Sutou 2016-02-18 22:38:06 +0900 (Thu, 18 Feb 2016) New Revision: 8e69e2e04317c3417eabbd0680c25c0d330c8f8a https://github.com/groonga/groonga/commit/8e69e2e04317c3417eabbd0680c25c0d330c8f8a Message: mrb: support GRN_PTR Added files: lib/mrb/mrb_pointer.c lib/mrb/mrb_pointer.h Modified files: lib/ctx_impl_mrb.c lib/mrb/mrb_converter.c lib/mrb/sources.am Modified: lib/ctx_impl_mrb.c (+2 -0) =================================================================== --- lib/ctx_impl_mrb.c 2016-02-18 22:25:47 +0900 (0888c91) +++ lib/ctx_impl_mrb.c 2016-02-18 22:38:06 +0900 (e63f0e1) @@ -34,6 +34,7 @@ # include "mrb/mrb_query_logger.h" # include "mrb/mrb_void.h" # include "mrb/mrb_bulk.h" +# include "mrb/mrb_pointer.h" # include "mrb/mrb_cache.h" # include "mrb/mrb_object.h" # include "mrb/mrb_object_flags.h" @@ -146,6 +147,7 @@ mrb_groonga_init(mrb_state *mrb, mrb_value self) grn_mrb_query_logger_init(ctx); grn_mrb_void_init(ctx); grn_mrb_bulk_init(ctx); + grn_mrb_pointer_init(ctx); grn_mrb_cache_init(ctx); grn_mrb_object_init(ctx); grn_mrb_object_flags_init(ctx); Modified: lib/mrb/mrb_converter.c (+3 -0) =================================================================== --- lib/mrb/mrb_converter.c 2016-02-18 22:25:47 +0900 (eb37004) +++ lib/mrb/mrb_converter.c 2016-02-18 22:38:06 +0900 (4dae6ba) @@ -206,6 +206,9 @@ grn_mrb_class_from_grn_obj(mrb_state *mrb, grn_obj *object) case GRN_BULK : klass = mrb_class_get_under(mrb, data->module, "Bulk"); break; + case GRN_PTR : + klass = mrb_class_get_under(mrb, data->module, "Pointer"); + break; case GRN_ACCESSOR : klass = mrb_class_get_under(mrb, data->module, "Accessor"); break; Added: lib/mrb/mrb_pointer.c (+77 -0) 100644 =================================================================== --- /dev/null +++ lib/mrb/mrb_pointer.c 2016-02-18 22:38:06 +0900 (7440dc0) @@ -0,0 +1,77 @@ +/* -*- c-basic-offset: 2 -*- */ +/* + Copyright(C) 2016 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" +#include <string.h> + +#ifdef GRN_WITH_MRUBY +#include <mruby.h> +#include <mruby/class.h> +#include <mruby/data.h> + +#include "mrb_pointer.h" +#include "mrb_object.h" +#include "mrb_converter.h" + +static struct mrb_data_type mrb_grn_pointer_type = { + "Groonga::Pointer", + NULL +}; + +static mrb_value +mrb_grn_pointer_initialize(mrb_state *mrb, mrb_value self) +{ + mrb_value mrb_pointer_ptr; + + mrb_get_args(mrb, "o", &mrb_pointer_ptr); + DATA_TYPE(self) = &mrb_grn_pointer_type; + DATA_PTR(self) = mrb_cptr(mrb_pointer_ptr); + return self; +} + +static mrb_value +mrb_grn_pointer_get_value(mrb_state *mrb, mrb_value self) +{ + grn_obj *pointer; + + pointer = DATA_PTR(self); + if (GRN_BULK_VSIZE(pointer) == 0) { + return mrb_nil_value(); + } + + return grn_mrb_value_from_grn_obj(mrb, GRN_PTR_VALUE(pointer)); +} + +void +grn_mrb_pointer_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, "Pointer", mrb->object_class); + MRB_SET_INSTANCE_TT(klass, MRB_TT_DATA); + mrb_define_method(mrb, klass, "initialize", + mrb_grn_pointer_initialize, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, klass, "value", + mrb_grn_pointer_get_value, MRB_ARGS_NONE()); + mrb_define_method(mrb, klass, "inspect", + grn_mrb_object_inspect, MRB_ARGS_NONE()); +} +#endif Added: lib/mrb/mrb_pointer.h (+31 -0) 100644 =================================================================== --- /dev/null +++ lib/mrb/mrb_pointer.h 2016-02-18 22:38:06 +0900 (2ee7fba) @@ -0,0 +1,31 @@ +/* -*- c-basic-offset: 2 -*- */ +/* + Copyright(C) 2016 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 +*/ + +#pragma once + +#include "../grn_ctx.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void grn_mrb_pointer_init(grn_ctx *ctx); + +#ifdef __cplusplus +} +#endif Modified: lib/mrb/sources.am (+2 -0) =================================================================== --- lib/mrb/sources.am 2016-02-18 22:25:47 +0900 (db19eb2) +++ lib/mrb/sources.am 2016-02-18 22:38:06 +0900 (997b0b6) @@ -55,6 +55,8 @@ libgrnmrb_la_SOURCES = \ mrb_options.h \ mrb_patricia_trie.c \ mrb_patricia_trie.h \ + mrb_pointer.c \ + mrb_pointer.h \ mrb_procedure.c \ mrb_procedure.h \ mrb_query_logger.c \ -------------- next part -------------- HTML����������������������������...Download