Navigation Menu

Skip to content

Commit

Permalink
mrb: use new() instead of alloc()
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jun 8, 2014
1 parent a717bd4 commit 74e8c18
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/mrb/mrb_converter.c
Expand Up @@ -59,15 +59,16 @@ 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) {
return mrb_nil_value();
}

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
21 changes: 20 additions & 1 deletion lib/mrb/mrb_fixed_size_column.c
@@ -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
Expand All @@ -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)
{
Expand All @@ -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
18 changes: 18 additions & 0 deletions lib/mrb/mrb_procedure.c
Expand Up @@ -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)
{
Expand All @@ -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
19 changes: 19 additions & 0 deletions lib/mrb/mrb_variable_size_column.c
Expand Up @@ -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)
{
Expand All @@ -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

0 comments on commit 74e8c18

Please sign in to comment.