From 14c95993b8fed43b4b8cc2bb39bcad7111cd2705 Mon Sep 17 00:00:00 2001 From: Kouhei Sutou Date: Wed, 16 Jan 2013 16:47:14 +0900 Subject: [PATCH] mruby: extract mruby related code to another file --- lib/ctx.c | 9 +++------ lib/ctx_impl.h | 2 -- lib/mrb.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/mrb.h | 36 ++++++++++++++++++++++++++++++++++++ lib/sources.am | 2 ++ 5 files changed, 90 insertions(+), 8 deletions(-) create mode 100644 lib/mrb.c create mode 100644 lib/mrb.h diff --git a/lib/ctx.c b/lib/ctx.c index 332f95b8fc..29e2c095fd 100644 --- a/lib/ctx.c +++ b/lib/ctx.c @@ -25,6 +25,7 @@ #include "snip.h" #include "output.h" #include "normalizer_in.h" +#include "mrb.h" #include #include #include @@ -508,9 +509,7 @@ grn_ctx_impl_init(grn_ctx *ctx) msgpack_packer_init(&ctx->impl->msgpacker, ctx, grn_msgpack_buffer_write); #endif -#ifdef WITH_MRUBY - ctx->impl->mrb = mrb_open(); -#endif + grn_ctx_impl_mrb_init(ctx); } void @@ -596,9 +595,7 @@ grn_ctx_fin(grn_ctx *ctx) if (ctx->impl->finalizer) { ctx->impl->finalizer(ctx, 0, NULL, &(ctx->user_data)); } -#ifdef WITH_MRUBY - mrb_close(ctx->impl->mrb); -#endif + grn_ctx_impl_mrb_fin(ctx); grn_ctx_loader_clear(ctx); if (ctx->impl->parser) { grn_expr_parser_close(ctx); diff --git a/lib/ctx_impl.h b/lib/ctx_impl.h index d1e92924ef..e63ac38a1e 100644 --- a/lib/ctx_impl.h +++ b/lib/ctx_impl.h @@ -32,8 +32,6 @@ #ifdef WITH_MRUBY # include -# include -# include #endif #ifdef __cplusplus diff --git a/lib/mrb.c b/lib/mrb.c new file mode 100644 index 0000000000..0b3655bd5e --- /dev/null +++ b/lib/mrb.c @@ -0,0 +1,49 @@ +/* -*- c-basic-offset: 2 -*- */ +/* + Copyright(C) 2013 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 "mrb.h" +#include "ctx_impl.h" + +#ifdef WITH_MRUBY +# include +# include +#endif + +#ifdef WITH_MRUBY +void +grn_ctx_impl_mrb_init(grn_ctx *ctx) +{ + ctx->impl->mrb = mrb_open(); +} + +void +grn_ctx_impl_mrb_fin(grn_ctx *ctx) +{ + mrb_close(ctx->impl->mrb); +} +#else +void +grn_ctx_impl_mrb_init(grn_ctx *ctx) +{ +} + +void +grn_ctx_impl_mrb_fin(grn_ctx *ctx) +{ +} +#endif diff --git a/lib/mrb.h b/lib/mrb.h new file mode 100644 index 0000000000..800aab6199 --- /dev/null +++ b/lib/mrb.h @@ -0,0 +1,36 @@ +/* -*- c-basic-offset: 2 -*- */ +/* + Copyright(C) 2013 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_H +#define GRN_MRB_H + +#include "groonga_in.h" +#include "ctx.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void grn_ctx_impl_mrb_init(grn_ctx *ctx); +void grn_ctx_impl_mrb_fin(grn_ctx *ctx); + +#ifdef __cplusplus +} +#endif + +#endif /* GRN_MRB_H */ diff --git a/lib/sources.am b/lib/sources.am index b1db3aba9a..f1b6ceb33b 100644 --- a/lib/sources.am +++ b/lib/sources.am @@ -18,6 +18,8 @@ libgroonga_la_SOURCES = \ ii.h \ io.c \ io.h \ + mrb.c \ + mrb.h \ nfkc.c \ nfkc.h \ normalizer.c \