Skip to content

Commit

Permalink
mruby: extract mruby related code to another file
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jan 16, 2013
1 parent 0234e8c commit 14c9599
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 8 deletions.
9 changes: 3 additions & 6 deletions lib/ctx.c
Expand Up @@ -25,6 +25,7 @@
#include "snip.h"
#include "output.h"
#include "normalizer_in.h"
#include "mrb.h"
#include <stdio.h>
#include <stdarg.h>
#include <time.h>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions lib/ctx_impl.h
Expand Up @@ -32,8 +32,6 @@

#ifdef WITH_MRUBY
# include <mruby.h>
# include <mruby/proc.h>
# include <mruby/compile.h>
#endif

#ifdef __cplusplus
Expand Down
49 changes: 49 additions & 0 deletions 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 <mruby/proc.h>
# include <mruby/compile.h>
#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
36 changes: 36 additions & 0 deletions 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 */
2 changes: 2 additions & 0 deletions lib/sources.am
Expand Up @@ -18,6 +18,8 @@ libgroonga_la_SOURCES = \
ii.h \
io.c \
io.h \
mrb.c \
mrb.h \
nfkc.c \
nfkc.h \
normalizer.c \
Expand Down

0 comments on commit 14c9599

Please sign in to comment.