[Groonga-commit] groonga/groonga at c2a65be [master] mrb: support converting time bulk to mruby

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Feb 4 16:16:34 JST 2015


Kouhei Sutou	2015-02-04 16:16:34 +0900 (Wed, 04 Feb 2015)

  New Revision: c2a65bedfc0b5d1cc15006d2f2f72e7d3a8c3772
  https://github.com/groonga/groonga/commit/c2a65bedfc0b5d1cc15006d2f2f72e7d3a8c3772

  Message:
    mrb: support converting time bulk to mruby

  Modified files:
    lib/ctx_impl_mrb.c
    lib/grn_ctx_impl.h
    lib/mrb/mrb_bulk.c

  Modified: lib/ctx_impl_mrb.c (+7 -2)
===================================================================
--- lib/ctx_impl_mrb.c    2015-02-04 13:06:12 +0900 (68c239a)
+++ lib/ctx_impl_mrb.c    2015-02-04 16:16:34 +0900 (e5c6b7b)
@@ -142,18 +142,23 @@ grn_ctx_impl_mrb_init(grn_ctx *ctx)
     ctx->impl->mrb.object_class = NULL;
     ctx->impl->mrb.checked_procs = NULL;
     ctx->impl->mrb.registered_plugins = NULL;
+    ctx->impl->mrb.builtin.time_class = NULL;
   } else {
-    ctx->impl->mrb.state = mrb_open();
+    mrb_state *mrb;
+
+    mrb = mrb_open();
+    ctx->impl->mrb.state = mrb;
     ctx->impl->mrb.base_directory[0] = '\0';
     grn_ctx_impl_mrb_init_bindings(ctx);
     /* TODO: Implement better error handling on init. */
     if (ctx->impl->mrb.state->exc) {
-      mrb_print_error(ctx->impl->mrb.state);
+      mrb_print_error(mrb);
     }
     ctx->impl->mrb.checked_procs =
       grn_hash_create(ctx, NULL, sizeof(grn_id), 0, GRN_HASH_TINY);
     ctx->impl->mrb.registered_plugins =
       grn_hash_create(ctx, NULL, sizeof(grn_id), 0, GRN_HASH_TINY);
+    ctx->impl->mrb.builtin.time_class = mrb_class_get(mrb, "Time");
   }
 }
 

  Modified: lib/grn_ctx_impl.h (+4 -1)
===================================================================
--- lib/grn_ctx_impl.h    2015-02-04 13:06:12 +0900 (1c41fe1)
+++ lib/grn_ctx_impl.h    2015-02-04 16:16:34 +0900 (1741b89)
@@ -1,6 +1,6 @@
 /* -*- c-basic-offset: 2 -*- */
 /*
-  Copyright(C) 2009-2014 Brazil
+  Copyright(C) 2009-2015 Brazil
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -101,6 +101,9 @@ struct _grn_mrb_data {
   struct RClass *object_class;
   grn_hash *checked_procs;
   grn_hash *registered_plugins;
+  struct {
+    struct RClass *time_class;
+  } builtin;
 };
 #endif
 

  Modified: lib/mrb/mrb_bulk.c (+17 -1)
===================================================================
--- lib/mrb/mrb_bulk.c    2015-02-04 13:06:12 +0900 (41647c3)
+++ lib/mrb/mrb_bulk.c    2015-02-04 16:16:34 +0900 (41f19c8)
@@ -58,6 +58,7 @@ mrb_grn_bulk_get_value(mrb_state *mrb, mrb_value self)
 {
   grn_obj *bulk;
   mrb_value mrb_value_;
+  grn_ctx *ctx = (grn_ctx *)mrb->ud;
 
   bulk = DATA_PTR(self);
   switch (bulk->header.domain) {
@@ -81,11 +82,26 @@ mrb_grn_bulk_get_value(mrb_state *mrb, mrb_value self)
       mrb_value_ = mrb_fixnum_value(value);
     }
     break;
+  case GRN_DB_TIME :
+    {
+      int64_t value;
+      int32_t sec;
+      int32_t usec;
+
+      value = GRN_TIME_VALUE(bulk);
+      GRN_TIME_UNPACK(value, sec, usec);
+      mrb_value_ = mrb_funcall(mrb,
+                               mrb_obj_value(ctx->impl->mrb.builtin.time_class),
+                               "at",
+                               2,
+                               mrb_fixnum_value(sec),
+                               mrb_fixnum_value(usec));
+    }
+    break;
   default :
     {
 #define MESSAGE_SIZE 4096
       char message[MESSAGE_SIZE];
-      grn_ctx *ctx = (grn_ctx *)mrb->ud;
       grn_obj *domain;
       char domain_name[GRN_TABLE_MAX_KEY_SIZE];
       int domain_name_size;
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index