Kouhei Sutou
null+****@clear*****
Sun Jun 8 15:07:41 JST 2014
Kouhei Sutou 2014-06-08 15:07:41 +0900 (Sun, 08 Jun 2014) New Revision: 74e8c188ddd9f1212bd78e1cee7d296fc9f7a734 https://github.com/groonga/groonga/commit/74e8c188ddd9f1212bd78e1cee7d296fc9f7a734 Message: mrb: use new() instead of alloc() Modified files: lib/mrb/mrb_converter.c lib/mrb/mrb_fixed_size_column.c lib/mrb/mrb_procedure.c lib/mrb/mrb_variable_size_column.c Modified: lib/mrb/mrb_converter.c (+3 -2) =================================================================== --- lib/mrb/mrb_converter.c 2014-06-08 14:52:50 +0900 (d0367a4) +++ lib/mrb/mrb_converter.c 2014-06-08 15:07:41 +0900 (3a2097a) @@ -59,6 +59,7 @@ mrb_value grn_mrb_value_from_grn_obj(mrb_state *mrb, grn_obj *object) { struct RClass *mrb_class; + mrb_value mrb_new_arguments[1]; mrb_value mrb_object; if (!object) { @@ -66,8 +67,8 @@ grn_mrb_value_from_grn_obj(mrb_state *mrb, grn_obj *object) } mrb_class = grn_mrb_class_from_grn_obj(mrb, object); - mrb_object = mrb_obj_value(mrb_obj_alloc(mrb, MRB_TT_DATA, mrb_class)); - DATA_PTR(mrb_object) = object; + mrb_new_arguments[0] = mrb_cptr_value(mrb, object); + mrb_object = mrb_obj_new(mrb, mrb_class, 1, mrb_new_arguments); return mrb_object; } #endif Modified: lib/mrb/mrb_fixed_size_column.c (+20 -1) =================================================================== --- lib/mrb/mrb_fixed_size_column.c 2014-06-08 14:52:50 +0900 (5f343a1) +++ lib/mrb/mrb_fixed_size_column.c 2014-06-08 15:07:41 +0900 (d8df913) @@ -1,6 +1,6 @@ /* -*- c-basic-offset: 2 -*- */ /* - Copyright(C) 2013 Brazil + Copyright(C) 2013-2014 Brazil This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -21,9 +21,26 @@ #ifdef GRN_WITH_MRUBY #include <mruby.h> #include <mruby/class.h> +#include <mruby/data.h> #include "mrb_fixed_size_column.h" +static struct mrb_data_type mrb_grn_fixed_size_column_type = { + "Groonga::FixedSizeColumn", + NULL +}; + +static mrb_value +mrb_grn_fixed_size_column_initialize(mrb_state *mrb, mrb_value self) +{ + mrb_value mrb_fixed_size_column_ptr; + + mrb_get_args(mrb, "o", &mrb_fixed_size_column_ptr); + DATA_TYPE(self) = &mrb_grn_fixed_size_column_type; + DATA_PTR(self) = mrb_cptr(mrb_fixed_size_column_ptr); + return self; +} + void grn_mrb_fixed_size_column_init(grn_ctx *ctx) { @@ -36,5 +53,7 @@ grn_mrb_fixed_size_column_init(grn_ctx *ctx) column_class = mrb_class_get_under(mrb, module, "Column"); klass = mrb_define_class_under(mrb, module, "FixedSizeColumn", column_class); MRB_SET_INSTANCE_TT(klass, MRB_TT_DATA); + mrb_define_method(mrb, klass, "initialize", + mrb_grn_fixed_size_column_initialize, MRB_ARGS_REQ(1)); } #endif Modified: lib/mrb/mrb_procedure.c (+18 -0) =================================================================== --- lib/mrb/mrb_procedure.c 2014-06-08 14:52:50 +0900 (ad4b4db) +++ lib/mrb/mrb_procedure.c 2014-06-08 15:07:41 +0900 (ecc177e) @@ -26,6 +26,22 @@ #include "mrb_procedure.h" #include "mrb_index_info.h" +static struct mrb_data_type mrb_grn_procedure_type = { + "Groonga::Procedure", + NULL +}; + +static mrb_value +mrb_grn_procedure_initialize(mrb_state *mrb, mrb_value self) +{ + mrb_value mrb_procedure_ptr; + + mrb_get_args(mrb, "o", &mrb_procedure_ptr); + DATA_TYPE(self) = &mrb_grn_procedure_type; + DATA_PTR(self) = mrb_cptr(mrb_procedure_ptr); + return self; +} + void grn_mrb_procedure_init(grn_ctx *ctx) { @@ -37,5 +53,7 @@ grn_mrb_procedure_init(grn_ctx *ctx) klass = mrb_define_class_under(mrb, module, "Procedure", object_class); MRB_SET_INSTANCE_TT(klass, MRB_TT_DATA); + mrb_define_method(mrb, klass, "initialize", + mrb_grn_procedure_initialize, MRB_ARGS_REQ(1)); } #endif Modified: lib/mrb/mrb_variable_size_column.c (+19 -0) =================================================================== --- lib/mrb/mrb_variable_size_column.c 2014-06-08 14:52:50 +0900 (b782ad6) +++ lib/mrb/mrb_variable_size_column.c 2014-06-08 15:07:41 +0900 (9073b32) @@ -21,9 +21,26 @@ #ifdef GRN_WITH_MRUBY #include <mruby.h> #include <mruby/class.h> +#include <mruby/data.h> #include "mrb_variable_size_column.h" +static struct mrb_data_type mrb_grn_variable_size_column_type = { + "Groonga::VariableSizeColumn", + NULL +}; + +static mrb_value +mrb_grn_variable_size_column_initialize(mrb_state *mrb, mrb_value self) +{ + mrb_value mrb_variable_size_column_ptr; + + mrb_get_args(mrb, "o", &mrb_variable_size_column_ptr); + DATA_TYPE(self) = &mrb_grn_variable_size_column_type; + DATA_PTR(self) = mrb_cptr(mrb_variable_size_column_ptr); + return self; +} + void grn_mrb_variable_size_column_init(grn_ctx *ctx) { @@ -37,5 +54,7 @@ grn_mrb_variable_size_column_init(grn_ctx *ctx) klass = mrb_define_class_under(mrb, module, "VariableSizeColumn", column_class); MRB_SET_INSTANCE_TT(klass, MRB_TT_DATA); + mrb_define_method(mrb, klass, "initialize", + mrb_grn_variable_size_column_initialize, MRB_ARGS_REQ(1)); } #endif -------------- next part -------------- HTML����������������������������...다운로드