[Groonga-commit] groonga/groonga at 9105fb3 [master] Group output related variables

Zurück zum Archiv-Index

Kouhei Sutou null+****@clear*****
Mon Nov 23 15:44:48 JST 2015


Kouhei Sutou	2015-11-23 15:44:48 +0900 (Mon, 23 Nov 2015)

  New Revision: 9105fb3e135daff97271c3e90c705707c062a935
  https://github.com/groonga/groonga/commit/9105fb3e135daff97271c3e90c705707c062a935

  Message:
    Group output related variables

  Modified files:
    lib/com.c
    lib/ctx.c
    lib/grn_ctx_impl.h
    lib/mrb/mrb_ctx.c
    lib/output.c
    lib/proc.c
    lib/ts.c
    src/groonga.c

  Modified: lib/com.c (+1 -1)
===================================================================
--- lib/com.c    2015-11-22 23:16:20 +0900 (a16a446)
+++ lib/com.c    2015-11-23 15:44:48 +0900 (ff14f60)
@@ -201,7 +201,7 @@ grn_msg_send(grn_ctx *ctx, grn_obj *msg, int flags)
       {
         if ((flags & GRN_CTX_MORE)) { flags |= GRN_CTX_QUIET; }
         if (ctx->stat == GRN_CTX_QUIT) { flags |= GRN_CTX_QUIT; }
-        header->qtype = (uint8_t) ctx->impl->output_type;
+        header->qtype = (uint8_t) ctx->impl->output.type;
         header->keylen = 0;
         header->level = 0;
         header->flags = flags;

  Modified: lib/ctx.c (+113 -81)
===================================================================
--- lib/ctx.c    2015-11-22 23:16:20 +0900 (5e7e6d8)
+++ lib/ctx.c    2015-11-23 15:44:48 +0900 (1be1bd4)
@@ -528,7 +528,7 @@ static int
 grn_msgpack_buffer_write(void *data, const char *buf, msgpack_size_t len)
 {
   grn_ctx *ctx = (grn_ctx *)data;
-  return grn_bulk_write(ctx, ctx->impl->outbuf, buf, len);
+  return grn_bulk_write(ctx, ctx->impl->output.buf, buf, len);
 }
 #endif
 
@@ -585,8 +585,8 @@ grn_ctx_impl_init(grn_ctx *ctx)
   ctx->impl->qe_next = NULL;
   ctx->impl->parser = NULL;
 
-  GRN_TEXT_INIT(&ctx->impl->names, GRN_OBJ_VECTOR);
-  GRN_UINT32_INIT(&ctx->impl->levels, GRN_OBJ_VECTOR);
+  GRN_TEXT_INIT(&ctx->impl->output.names, GRN_OBJ_VECTOR);
+  GRN_UINT32_INIT(&ctx->impl->output.levels, GRN_OBJ_VECTOR);
 
   if (ctx == &grn_gctx) {
     ctx->impl->command_version = GRN_COMMAND_VERSION_STABLE;
@@ -605,9 +605,13 @@ grn_ctx_impl_init(grn_ctx *ctx)
   ctx->impl->finalizer = NULL;
 
   ctx->impl->com = NULL;
-  ctx->impl->outbuf = grn_obj_open(ctx, GRN_BULK, 0, GRN_DB_TEXT);
-  ctx->impl->output = NULL;
-  ctx->impl->data.ptr = NULL;
+  ctx->impl->output.buf = grn_obj_open(ctx, GRN_BULK, 0, GRN_DB_TEXT);
+  ctx->impl->output.func = NULL;
+  ctx->impl->output.data.ptr = NULL;
+#ifdef GRN_WITH_MESSAGE_PACK
+  msgpack_packer_init(&ctx->impl->output.msgpacker,
+                      ctx, grn_msgpack_buffer_write);
+#endif
   ctx->impl->tv.tv_sec = 0;
   ctx->impl->tv.tv_nsec = 0;
   ctx->impl->edge = NULL;
@@ -619,10 +623,6 @@ grn_ctx_impl_init(grn_ctx *ctx)
   ctx->impl->previous_errbuf[0] = '\0';
   ctx->impl->n_same_error_messages = 0;
 
-#ifdef GRN_WITH_MESSAGE_PACK
-  msgpack_packer_init(&ctx->impl->msgpacker, ctx, grn_msgpack_buffer_write);
-#endif
-
   grn_ctx_impl_mrb_init(ctx);
 
   return ctx->rc;
@@ -787,10 +787,10 @@ grn_ctx_fin(grn_ctx *ctx)
       grn_ctx_send(ctx, "ACK", 3, GRN_CTX_HEAD);
       rc = grn_com_close(ctx, ctx->impl->com);
     }
-    GRN_OBJ_FIN(ctx, &ctx->impl->names);
-    GRN_OBJ_FIN(ctx, &ctx->impl->levels);
     GRN_OBJ_FIN(ctx, &ctx->impl->query_log_buf);
-    rc = grn_obj_close(ctx, ctx->impl->outbuf);
+    GRN_OBJ_FIN(ctx, &ctx->impl->output.names);
+    GRN_OBJ_FIN(ctx, &ctx->impl->output.levels);
+    rc = grn_obj_close(ctx, ctx->impl->output.buf);
     {
       grn_hash **vp;
       grn_obj *value;
@@ -1154,7 +1154,7 @@ grn_content_type
 grn_ctx_get_output_type(grn_ctx *ctx)
 {
   if (ctx->impl) {
-    return ctx->impl->output_type;
+    return ctx->impl->output.type;
   } else {
     return GRN_CONTENT_NONE;
   }
@@ -1166,25 +1166,25 @@ grn_ctx_set_output_type(grn_ctx *ctx, grn_content_type type)
   grn_rc rc = GRN_SUCCESS;
 
   if (ctx->impl) {
-    ctx->impl->output_type = type;
-    switch (ctx->impl->output_type) {
+    ctx->impl->output.type = type;
+    switch (ctx->impl->output.type) {
     case GRN_CONTENT_NONE :
-      ctx->impl->mime_type = "application/octet-stream";
+      ctx->impl->output.mime_type = "application/octet-stream";
       break;
     case GRN_CONTENT_TSV :
-      ctx->impl->mime_type = "text/tab-separated-values";
+      ctx->impl->output.mime_type = "text/tab-separated-values";
       break;
     case GRN_CONTENT_JSON :
-      ctx->impl->mime_type = "application/json";
+      ctx->impl->output.mime_type = "application/json";
       break;
     case GRN_CONTENT_XML :
-      ctx->impl->mime_type = "text/xml";
+      ctx->impl->output.mime_type = "text/xml";
       break;
     case GRN_CONTENT_MSGPACK :
-      ctx->impl->mime_type = "application/x-msgpack";
+      ctx->impl->output.mime_type = "application/x-msgpack";
       break;
     case GRN_CONTENT_GROONGA_COMMAND_LIST :
-      ctx->impl->mime_type = "text/x-groonga-command-list";
+      ctx->impl->output.mime_type = "text/x-groonga-command-list";
       break;
     }
   } else {
@@ -1198,7 +1198,7 @@ const char *
 grn_ctx_get_mime_type(grn_ctx *ctx)
 {
   if (ctx->impl) {
-    return ctx->impl->mime_type;
+    return ctx->impl->output.mime_type;
   } else {
     return NULL;
   }
@@ -1249,70 +1249,70 @@ grn_get_ctype(grn_obj *var)
 static void
 get_content_mime_type(grn_ctx *ctx, const char *p, const char *pe)
 {
-  ctx->impl->output_type = GRN_CONTENT_NONE;
-  ctx->impl->mime_type = "application/octet-stream";
+  ctx->impl->output.type = GRN_CONTENT_NONE;
+  ctx->impl->output.mime_type = "application/octet-stream";
 
   if (p + 2 <= pe) {
     switch (*p) {
     case 'c' :
       if (p + 3 == pe && !memcmp(p, "css", 3)) {
-        ctx->impl->output_type = GRN_CONTENT_NONE;
-        ctx->impl->mime_type = "text/css";
+        ctx->impl->output.type = GRN_CONTENT_NONE;
+        ctx->impl->output.mime_type = "text/css";
       }
       break;
     case 'g' :
       if (p + 3 == pe && !memcmp(p, "gif", 3)) {
-        ctx->impl->output_type = GRN_CONTENT_NONE;
-        ctx->impl->mime_type = "image/gif";
+        ctx->impl->output.type = GRN_CONTENT_NONE;
+        ctx->impl->output.mime_type = "image/gif";
       }
       break;
     case 'h' :
       if (p + 4 == pe && !memcmp(p, "html", 4)) {
-        ctx->impl->output_type = GRN_CONTENT_NONE;
-        ctx->impl->mime_type = "text/html";
+        ctx->impl->output.type = GRN_CONTENT_NONE;
+        ctx->impl->output.mime_type = "text/html";
       }
       break;
     case 'j' :
       if (!memcmp(p, "js", 2)) {
         if (p + 2 == pe) {
-          ctx->impl->output_type = GRN_CONTENT_NONE;
-          ctx->impl->mime_type = "text/javascript";
+          ctx->impl->output.type = GRN_CONTENT_NONE;
+          ctx->impl->output.mime_type = "text/javascript";
         } else if (p + 4 == pe && !memcmp(p + 2, "on", 2)) {
-          ctx->impl->output_type = GRN_CONTENT_JSON;
-          ctx->impl->mime_type = "application/json";
+          ctx->impl->output.type = GRN_CONTENT_JSON;
+          ctx->impl->output.mime_type = "application/json";
         }
       } else if (p + 3 == pe && !memcmp(p, "jpg", 3)) {
-        ctx->impl->output_type = GRN_CONTENT_NONE;
-        ctx->impl->mime_type = "image/jpeg";
+        ctx->impl->output.type = GRN_CONTENT_NONE;
+        ctx->impl->output.mime_type = "image/jpeg";
       }
       break;
 #ifdef GRN_WITH_MESSAGE_PACK
     case 'm' :
       if (p + 7 == pe && !memcmp(p, "msgpack", 7)) {
-        ctx->impl->output_type = GRN_CONTENT_MSGPACK;
-        ctx->impl->mime_type = "application/x-msgpack";
+        ctx->impl->output.type = GRN_CONTENT_MSGPACK;
+        ctx->impl->output.mime_type = "application/x-msgpack";
       }
       break;
 #endif
     case 'p' :
       if (p + 3 == pe && !memcmp(p, "png", 3)) {
-        ctx->impl->output_type = GRN_CONTENT_NONE;
-        ctx->impl->mime_type = "image/png";
+        ctx->impl->output.type = GRN_CONTENT_NONE;
+        ctx->impl->output.mime_type = "image/png";
       }
       break;
     case 't' :
       if (p + 3 == pe && !memcmp(p, "txt", 3)) {
-        ctx->impl->output_type = GRN_CONTENT_NONE;
-        ctx->impl->mime_type = "text/plain";
+        ctx->impl->output.type = GRN_CONTENT_NONE;
+        ctx->impl->output.mime_type = "text/plain";
       } else if (p + 3 == pe && !memcmp(p, "tsv", 3)) {
-        ctx->impl->output_type = GRN_CONTENT_TSV;
-        ctx->impl->mime_type = "text/tab-separated-values";
+        ctx->impl->output.type = GRN_CONTENT_TSV;
+        ctx->impl->output.mime_type = "text/tab-separated-values";
       }
       break;
     case 'x':
       if (p + 3 == pe && !memcmp(p, "xml", 3)) {
-        ctx->impl->output_type = GRN_CONTENT_XML;
-        ctx->impl->mime_type = "text/xml";
+        ctx->impl->output.type = GRN_CONTENT_XML;
+        ctx->impl->output.mime_type = "text/xml";
       }
       break;
     }
@@ -1617,8 +1617,8 @@ grn_ctx_send(grn_ctx *ctx, const char *str, unsigned int str_len, int flags)
         grn_expr_exec(ctx, expr, 0);
       } else {
         if (comment_command_p(str, str_len)) { goto output; };
-        ctx->impl->mime_type = "application/json";
-        ctx->impl->output_type = GRN_CONTENT_JSON;
+        ctx->impl->output.type = GRN_CONTENT_JSON;
+        ctx->impl->output.mime_type = "application/json";
         grn_timeval_now(ctx, &ctx->impl->tv);
         GRN_QUERY_LOG(ctx, GRN_QUERY_LOG_COMMAND,
                       ">", "%.*s", str_len, str);
@@ -1637,8 +1637,8 @@ grn_ctx_send(grn_ctx *ctx, const char *str, unsigned int str_len, int flags)
       }
     output :
       if (!ERRP(ctx, GRN_CRIT)) {
-        if (!(flags & GRN_CTX_QUIET) && ctx->impl->output) {
-          ctx->impl->output(ctx, GRN_CTX_TAIL, ctx->impl->data.ptr);
+        if (!(flags & GRN_CTX_QUIET) && ctx->impl->output.func) {
+          ctx->impl->output.func(ctx, GRN_CTX_TAIL, ctx->impl->output.data.ptr);
         }
       }
       if (expr) { grn_expr_clear_vars(ctx, expr); }
@@ -1664,20 +1664,20 @@ grn_ctx_recv(grn_ctx *ctx, char **str, unsigned int *str_len, int *flags)
   if (ctx->impl) {
     if (ctx->impl->com) {
       grn_com_header header;
-      if (grn_com_recv(ctx, ctx->impl->com, &header, ctx->impl->outbuf)) {
+      if (grn_com_recv(ctx, ctx->impl->com, &header, ctx->impl->output.buf)) {
         *str = NULL;
         *str_len = 0;
         *flags = 0;
       } else {
-        *str = GRN_BULK_HEAD(ctx->impl->outbuf);
-        *str_len = GRN_BULK_VSIZE(ctx->impl->outbuf);
+        *str = GRN_BULK_HEAD(ctx->impl->output.buf);
+        *str_len = GRN_BULK_VSIZE(ctx->impl->output.buf);
         if (header.flags & GRN_CTX_QUIT) {
           ctx->stat = GRN_CTX_QUIT;
           *flags = GRN_CTX_QUIT;
         } else {
           *flags = (header.flags & GRN_CTX_TAIL) ? 0 : GRN_CTX_MORE;
         }
-        ctx->impl->output_type = header.qtype;
+        ctx->impl->output.type = header.qtype;
         ctx->rc = (int16_t)ntohs(header.status);
         ctx->errbuf[0] = '\0';
         ctx->errline = 0;
@@ -1686,11 +1686,11 @@ grn_ctx_recv(grn_ctx *ctx, char **str, unsigned int *str_len, int *flags)
       }
       goto exit;
     } else {
-      grn_obj *buf = ctx->impl->outbuf;
+      grn_obj *buf = ctx->impl->output.buf;
       unsigned int head = 0, tail = GRN_BULK_VSIZE(buf);
       *str = GRN_BULK_HEAD(buf) + head;
       *str_len = tail - head;
-      GRN_BULK_REWIND(ctx->impl->outbuf);
+      GRN_BULK_REWIND(ctx->impl->output.buf);
       goto exit;
     }
   }
@@ -1703,7 +1703,7 @@ void
 grn_ctx_stream_out_func(grn_ctx *ctx, int flags, void *stream)
 {
   if (ctx && ctx->impl) {
-    grn_obj *buf = ctx->impl->outbuf;
+    grn_obj *buf = ctx->impl->output.buf;
     uint32_t size = GRN_BULK_VSIZE(buf);
     if (size) {
       if (fwrite(GRN_BULK_HEAD(buf), 1, size, (FILE *)stream)) {
@@ -1719,8 +1719,8 @@ void
 grn_ctx_recv_handler_set(grn_ctx *ctx, void (*func)(grn_ctx *, int, void *), void *func_arg)
 {
   if (ctx && ctx->impl) {
-    ctx->impl->output = func;
-    ctx->impl->data.ptr = func_arg;
+    ctx->impl->output.func = func;
+    ctx->impl->output.data.ptr = func_arg;
   }
 }
 
@@ -1731,12 +1731,12 @@ grn_ctx_info_get(grn_ctx *ctx, grn_ctx_info *info)
   if (ctx->impl->com) {
     info->fd = ctx->impl->com->fd;
     info->com_status = ctx->impl->com_status;
-    info->outbuf = ctx->impl->outbuf;
+    info->outbuf = ctx->impl->output.buf;
     info->stat = ctx->stat;
   } else {
     info->fd = -1;
     info->com_status = 0;
-    info->outbuf = ctx->impl->outbuf;
+    info->outbuf = ctx->impl->output.buf;
     info->stat = ctx->stat;
   }
   return GRN_SUCCESS;
@@ -2757,91 +2757,123 @@ grn_ctx_output_flush(grn_ctx *ctx, int flags)
   if (flags & GRN_CTX_QUIET) {
     return;
   }
-  if (!ctx->impl->output) {
+  if (!ctx->impl->output.func) {
     return;
   }
-  ctx->impl->output(ctx, 0, ctx->impl->data.ptr);
+  ctx->impl->output.func(ctx, 0, ctx->impl->output.data.ptr);
 }
 
 void
 grn_ctx_output_array_open(grn_ctx *ctx, const char *name, int nelements)
 {
-  grn_output_array_open(ctx, ctx->impl->outbuf, ctx->impl->output_type,
+  grn_output_array_open(ctx,
+                        ctx->impl->output.buf,
+                        ctx->impl->output.type,
                         name, nelements);
 }
 
 void
 grn_ctx_output_array_close(grn_ctx *ctx)
 {
-  grn_output_array_close(ctx, ctx->impl->outbuf, ctx->impl->output_type);
+  grn_output_array_close(ctx,
+                         ctx->impl->output.buf,
+                         ctx->impl->output.type);
 }
 
 void
 grn_ctx_output_map_open(grn_ctx *ctx, const char *name, int nelements)
 {
-  grn_output_map_open(ctx, ctx->impl->outbuf, ctx->impl->output_type,
+  grn_output_map_open(ctx,
+                      ctx->impl->output.buf,
+                      ctx->impl->output.type,
                       name, nelements);
 }
 
 void
 grn_ctx_output_map_close(grn_ctx *ctx)
 {
-  grn_output_map_close(ctx, ctx->impl->outbuf, ctx->impl->output_type);
+  grn_output_map_close(ctx,
+                       ctx->impl->output.buf,
+                       ctx->impl->output.type);
 }
 
 void
 grn_ctx_output_null(grn_ctx *ctx)
 {
-  grn_output_null(ctx, ctx->impl->outbuf, ctx->impl->output_type);
+  grn_output_null(ctx,
+                  ctx->impl->output.buf,
+                  ctx->impl->output.type);
 }
 
 void
 grn_ctx_output_int32(grn_ctx *ctx, int value)
 {
-  grn_output_int32(ctx, ctx->impl->outbuf, ctx->impl->output_type, value);
+  grn_output_int32(ctx,
+                   ctx->impl->output.buf,
+                   ctx->impl->output.type,
+                   value);
 }
 
 void
 grn_ctx_output_int64(grn_ctx *ctx, int64_t value)
 {
-  grn_output_int64(ctx, ctx->impl->outbuf, ctx->impl->output_type, value);
+  grn_output_int64(ctx,
+                   ctx->impl->output.buf,
+                   ctx->impl->output.type,
+                   value);
 }
 
 void
 grn_ctx_output_uint64(grn_ctx *ctx, uint64_t value)
 {
-  grn_output_uint64(ctx, ctx->impl->outbuf, ctx->impl->output_type, value);
+  grn_output_uint64(ctx,
+                    ctx->impl->output.buf,
+                    ctx->impl->output.type,
+                    value);
 }
 
 void
 grn_ctx_output_float(grn_ctx *ctx, double value)
 {
-  grn_output_float(ctx, ctx->impl->outbuf, ctx->impl->output_type, value);
+  grn_output_float(ctx,
+                   ctx->impl->output.buf,
+                   ctx->impl->output.type,
+                   value);
 }
 
 void
 grn_ctx_output_cstr(grn_ctx *ctx, const char *value)
 {
-  grn_output_cstr(ctx, ctx->impl->outbuf, ctx->impl->output_type, value);
+  grn_output_cstr(ctx,
+                  ctx->impl->output.buf,
+                  ctx->impl->output.type,
+                  value);
 }
 
 void
 grn_ctx_output_str(grn_ctx *ctx, const char *value, unsigned int value_len)
 {
-  grn_output_str(ctx, ctx->impl->outbuf, ctx->impl->output_type,
+  grn_output_str(ctx,
+                 ctx->impl->output.buf,
+                 ctx->impl->output.type,
                  value, value_len);
 }
 
 void
 grn_ctx_output_bool(grn_ctx *ctx, grn_bool value)
 {
-  grn_output_bool(ctx, ctx->impl->outbuf, ctx->impl->output_type, value);
+  grn_output_bool(ctx,
+                  ctx->impl->output.buf,
+                  ctx->impl->output.type,
+                  value);
 }
 
 void
 grn_ctx_output_obj(grn_ctx *ctx, grn_obj *value, grn_obj_format *format)
 {
-  grn_output_obj(ctx, ctx->impl->outbuf, ctx->impl->output_type,
+  grn_output_obj(ctx,
+                 ctx->impl->output.buf,
+                 ctx->impl->output.type,
                  value, format);
 }
 
@@ -2850,8 +2882,8 @@ grn_ctx_output_table_columns(grn_ctx *ctx, grn_obj *table,
                              grn_obj_format *format)
 {
   grn_output_table_columns(ctx,
-                           ctx->impl->outbuf,
-                           ctx->impl->output_type,
+                           ctx->impl->output.buf,
+                           ctx->impl->output.type,
                            table,
                            format);
 }
@@ -2861,8 +2893,8 @@ grn_ctx_output_table_records(grn_ctx *ctx, grn_obj *table,
                              grn_obj_format *format)
 {
   grn_output_table_records(ctx,
-                           ctx->impl->outbuf,
-                           ctx->impl->output_type,
+                           ctx->impl->output.buf,
+                           ctx->impl->output.type,
                            table,
                            format);
 }

  Modified: lib/grn_ctx_impl.h (+17 -15)
===================================================================
--- lib/grn_ctx_impl.h    2015-11-22 23:16:20 +0900 (fb3e032)
+++ lib/grn_ctx_impl.h    2015-11-23 15:44:48 +0900 (2f4e7f3)
@@ -155,10 +155,23 @@ struct _grn_ctx_impl {
   const char *plugin_path;
 
   /* output portion */
-  grn_content_type output_type;
-  const char *mime_type;
-  grn_obj names;
-  grn_obj levels;
+  struct {
+    grn_obj *buf;
+    void (*func)(grn_ctx *, int, void *);
+    union {
+      void *ptr;
+      int fd;
+      uint32_t u32;
+      uint64_t u64;
+    } data;
+    grn_content_type type;
+    const char *mime_type;
+    grn_obj names;
+    grn_obj levels;
+#ifdef GRN_WITH_MESSAGE_PACK
+    msgpack_packer msgpacker;
+#endif
+  } output;
 
   /* command portion */
   grn_command_version command_version;
@@ -173,25 +186,14 @@ struct _grn_ctx_impl {
   grn_array *values;        /* temporary objects */
   grn_pat *temporary_columns;
   grn_hash *ios;        /* IOs */
-  grn_obj *outbuf;
-  void (*output)(grn_ctx *, int, void *);
   grn_com *com;
   unsigned int com_status;
-  union {
-    void *ptr;
-    int fd;
-    uint32_t u32;
-    uint64_t u64;
-  } data;
 
   grn_obj query_log_buf;
 
   char previous_errbuf[GRN_CTX_MSGSIZE];
   unsigned int n_same_error_messages;
 
-#ifdef GRN_WITH_MESSAGE_PACK
-  msgpack_packer msgpacker;
-#endif
 #ifdef GRN_WITH_MRUBY
   grn_mrb_data mrb;
 #endif

  Modified: lib/mrb/mrb_ctx.c (+2 -2)
===================================================================
--- lib/mrb/mrb_ctx.c    2015-11-22 23:16:20 +0900 (eef70ca)
+++ lib/mrb/mrb_ctx.c    2015-11-23 15:44:48 +0900 (228e4c6)
@@ -227,7 +227,7 @@ ctx_get_output(mrb_state *mrb, mrb_value self)
 {
   grn_ctx *ctx = (grn_ctx *)mrb->ud;
 
-  return grn_mrb_value_from_bulk(mrb, ctx->impl->outbuf);
+  return grn_mrb_value_from_bulk(mrb, ctx->impl->output.buf);
 }
 
 static mrb_value
@@ -237,7 +237,7 @@ ctx_set_output(mrb_state *mrb, mrb_value self)
   mrb_value mrb_value_;
 
   mrb_get_args(mrb, "S", &mrb_value_);
-  GRN_TEXT_SET(ctx, ctx->impl->outbuf,
+  GRN_TEXT_SET(ctx, ctx->impl->output.buf,
                RSTRING_PTR(mrb_value_),
                RSTRING_LEN(mrb_value_));
 

  Modified: lib/output.c (+32 -21)
===================================================================
--- lib/output.c    2015-11-22 23:16:20 +0900 (55d8634)
+++ lib/output.c    2015-11-23 15:44:48 +0900 (e398e3e)
@@ -24,7 +24,7 @@
 #include "grn_util.h"
 #include "grn_output.h"
 
-#define LEVELS (&ctx->impl->levels)
+#define LEVELS (&ctx->impl->output.levels)
 #define DEPTH (GRN_BULK_VSIZE(LEVELS)>>2)
 #define CURR_LEVEL (DEPTH ? (GRN_UINT32_VALUE_AT(LEVELS, (DEPTH - 1))) : 0)
 #define INCR_DEPTH(i) GRN_UINT32_PUT(ctx, LEVELS, i)
@@ -75,7 +75,10 @@ grn_output_array_open(grn_ctx *ctx, grn_obj *outbuf, grn_content_type output_typ
     GRN_TEXT_PUTC(ctx, outbuf, '<');
     GRN_TEXT_PUTS(ctx, outbuf, name);
     GRN_TEXT_PUTC(ctx, outbuf, '>');
-    grn_vector_add_element(ctx, &ctx->impl->names, name, strlen(name), 0, GRN_DB_SHORT_TEXT);
+    grn_vector_add_element(ctx,
+                           &ctx->impl->output.names,
+                           name, strlen(name),
+                           0, GRN_DB_SHORT_TEXT);
     break;
   case GRN_CONTENT_TSV:
     if (DEPTH > 2) { GRN_TEXT_PUTS(ctx, outbuf, "[\t"); }
@@ -88,7 +91,7 @@ grn_output_array_open(grn_ctx *ctx, grn_obj *outbuf, grn_content_type output_typ
               nelements,
               name);
     }
-    msgpack_pack_array(&ctx->impl->msgpacker, nelements);
+    msgpack_pack_array(&ctx->impl->output.msgpacker, nelements);
 #endif
     break;
   case GRN_CONTENT_GROONGA_COMMAND_LIST :
@@ -115,7 +118,10 @@ grn_output_array_close(grn_ctx *ctx, grn_obj *outbuf, grn_content_type output_ty
   case GRN_CONTENT_XML:
     {
       const char *name;
-      unsigned int name_len = grn_vector_pop_element(ctx, &ctx->impl->names, &name, NULL, NULL);
+      unsigned int name_len;
+      name_len = grn_vector_pop_element(ctx,
+                                        &ctx->impl->output.names,
+                                        &name, NULL, NULL);
       GRN_TEXT_PUTS(ctx, outbuf, "</");
       GRN_TEXT_PUT(ctx, outbuf, name, name_len);
       GRN_TEXT_PUTC(ctx, outbuf, '>');
@@ -146,7 +152,9 @@ grn_output_map_open(grn_ctx *ctx, grn_obj *outbuf, grn_content_type output_type,
     GRN_TEXT_PUTC(ctx, outbuf, '<');
     GRN_TEXT_PUTS(ctx, outbuf, name);
     GRN_TEXT_PUTC(ctx, outbuf, '>');
-    grn_vector_add_element(ctx, &ctx->impl->names, name, strlen(name), 0, GRN_DB_SHORT_TEXT);
+    grn_vector_add_element(ctx,
+                           &ctx->impl->output.names,
+                           name, strlen(name), 0, GRN_DB_SHORT_TEXT);
     break;
   case GRN_CONTENT_TSV:
     if (DEPTH > 2) { GRN_TEXT_PUTS(ctx, outbuf, "{\t"); }
@@ -159,7 +167,7 @@ grn_output_map_open(grn_ctx *ctx, grn_obj *outbuf, grn_content_type output_type,
               nelements,
               name);
     }
-    msgpack_pack_map(&ctx->impl->msgpacker, nelements);
+    msgpack_pack_map(&ctx->impl->output.msgpacker, nelements);
 #endif
     break;
   case GRN_CONTENT_GROONGA_COMMAND_LIST :
@@ -186,7 +194,10 @@ grn_output_map_close(grn_ctx *ctx, grn_obj *outbuf, grn_content_type output_type
   case GRN_CONTENT_XML:
     {
       const char *name;
-      unsigned int name_len = grn_vector_pop_element(ctx, &ctx->impl->names, &name, NULL, NULL);
+      unsigned int name_len;
+      name_len = grn_vector_pop_element(ctx,
+                                        &ctx->impl->output.names,
+                                        &name, NULL, NULL);
       GRN_TEXT_PUTS(ctx, outbuf, "</");
       GRN_TEXT_PUT(ctx, outbuf, name, name_len);
       GRN_TEXT_PUTC(ctx, outbuf, '>');
@@ -222,7 +233,7 @@ grn_output_int32(grn_ctx *ctx, grn_obj *outbuf, grn_content_type output_type, in
     break;
   case GRN_CONTENT_MSGPACK :
 #ifdef GRN_WITH_MESSAGE_PACK
-    msgpack_pack_int32(&ctx->impl->msgpacker, value);
+    msgpack_pack_int32(&ctx->impl->output.msgpacker, value);
 #endif
     break;
   case GRN_CONTENT_GROONGA_COMMAND_LIST :
@@ -252,7 +263,7 @@ grn_output_int64(grn_ctx *ctx, grn_obj *outbuf, grn_content_type output_type, in
     break;
   case GRN_CONTENT_MSGPACK :
 #ifdef GRN_WITH_MESSAGE_PACK
-    msgpack_pack_int64(&ctx->impl->msgpacker, value);
+    msgpack_pack_int64(&ctx->impl->output.msgpacker, value);
 #endif
     break;
   case GRN_CONTENT_GROONGA_COMMAND_LIST :
@@ -282,7 +293,7 @@ grn_output_uint64(grn_ctx *ctx, grn_obj *outbuf, grn_content_type output_type, u
     break;
   case GRN_CONTENT_MSGPACK :
 #ifdef GRN_WITH_MESSAGE_PACK
-    msgpack_pack_uint64(&ctx->impl->msgpacker, value);
+    msgpack_pack_uint64(&ctx->impl->output.msgpacker, value);
 #endif
     break;
   case GRN_CONTENT_GROONGA_COMMAND_LIST :
@@ -312,7 +323,7 @@ grn_output_float(grn_ctx *ctx, grn_obj *outbuf, grn_content_type output_type, do
     break;
   case GRN_CONTENT_MSGPACK :
 #ifdef GRN_WITH_MESSAGE_PACK
-    msgpack_pack_double(&ctx->impl->msgpacker, value);
+    msgpack_pack_double(&ctx->impl->output.msgpacker, value);
 #endif
     break;
   case GRN_CONTENT_GROONGA_COMMAND_LIST :
@@ -343,8 +354,8 @@ grn_output_str(grn_ctx *ctx, grn_obj *outbuf, grn_content_type output_type,
     break;
   case GRN_CONTENT_MSGPACK :
 #ifdef GRN_WITH_MESSAGE_PACK
-    msgpack_pack_str(&ctx->impl->msgpacker, value_len);
-    msgpack_pack_str_body(&ctx->impl->msgpacker, value, value_len);
+    msgpack_pack_str(&ctx->impl->output.msgpacker, value_len);
+    msgpack_pack_str_body(&ctx->impl->output.msgpacker, value, value_len);
 #endif
     break;
   case GRN_CONTENT_GROONGA_COMMAND_LIST :
@@ -382,9 +393,9 @@ grn_output_bool(grn_ctx *ctx, grn_obj *outbuf, grn_content_type output_type, grn
   case GRN_CONTENT_MSGPACK :
 #ifdef GRN_WITH_MESSAGE_PACK
     if (value) {
-      msgpack_pack_true(&ctx->impl->msgpacker);
+      msgpack_pack_true(&ctx->impl->output.msgpacker);
     } else {
-      msgpack_pack_false(&ctx->impl->msgpacker);
+      msgpack_pack_false(&ctx->impl->output.msgpacker);
     }
 #endif
     break;
@@ -412,7 +423,7 @@ grn_output_null(grn_ctx *ctx, grn_obj *outbuf, grn_content_type output_type)
     break;
   case GRN_CONTENT_MSGPACK :
 #ifdef GRN_WITH_MESSAGE_PACK
-    msgpack_pack_nil(&ctx->impl->msgpacker);
+    msgpack_pack_nil(&ctx->impl->output.msgpacker);
 #endif
     break;
   case GRN_CONTENT_GROONGA_COMMAND_LIST :
@@ -454,7 +465,7 @@ grn_output_time(grn_ctx *ctx, grn_obj *outbuf, grn_content_type output_type, int
     break;
   case GRN_CONTENT_MSGPACK :
 #ifdef GRN_WITH_MESSAGE_PACK
-    msgpack_pack_double(&ctx->impl->msgpacker, dv);
+    msgpack_pack_double(&ctx->impl->output.msgpacker, dv);
 #endif
     break;
   case GRN_CONTENT_GROONGA_COMMAND_LIST :
@@ -511,13 +522,13 @@ grn_output_geo_point(grn_ctx *ctx, grn_obj *outbuf, grn_content_type output_type
       grn_text_itoa(ctx, &buf, value->latitude);
       GRN_TEXT_PUTC(ctx, &buf, 'x');
       grn_text_itoa(ctx, &buf, value->longitude);
-      msgpack_pack_str(&ctx->impl->msgpacker, GRN_TEXT_LEN(&buf));
-      msgpack_pack_str_body(&ctx->impl->msgpacker,
+      msgpack_pack_str(&ctx->impl->output.msgpacker, GRN_TEXT_LEN(&buf));
+      msgpack_pack_str_body(&ctx->impl->output.msgpacker,
                             GRN_TEXT_VALUE(&buf),
                             GRN_TEXT_LEN(&buf));
       grn_obj_close(ctx, &buf);
     } else {
-      msgpack_pack_nil(&ctx->impl->msgpacker);
+      msgpack_pack_nil(&ctx->impl->output.msgpacker);
     }
 #endif
     break;
@@ -1826,7 +1837,7 @@ grn_output_envelope(grn_ctx *ctx,
   finished += tv_now.tv_nsec / GRN_TIME_NSEC_PER_SEC_F;
   elapsed = finished - started;
 
-  switch (ctx->impl->output_type) {
+  switch (ctx->impl->output.type) {
   case GRN_CONTENT_JSON:
     expr = ctx->impl->curr_expr;
     if (expr) {

  Modified: lib/proc.c (+5 -5)
===================================================================
--- lib/proc.c    2015-11-22 23:16:20 +0900 (082d66d)
+++ lib/proc.c    2015-11-23 15:44:48 +0900 (3b71ad2)
@@ -898,8 +898,8 @@ grn_select(grn_ctx *ctx, const char *table, unsigned int table_len,
   uint32_t nkeys, nhits;
   uint16_t cacheable = 1, taintable = 0;
   grn_table_sort_key *keys;
-  grn_obj *outbuf = ctx->impl->outbuf;
-  grn_content_type output_type = ctx->impl->output_type;
+  grn_obj *outbuf = ctx->impl->output.buf;
+  grn_content_type output_type = ctx->impl->output.type;
   grn_obj *table_, *match_columns_ = NULL, *cond = NULL, *scorer_, *res = NULL, *sorted;
   char cache_key[GRN_CACHE_MAX_KEY_SIZE];
   uint32_t cache_key_size;
@@ -1012,7 +1012,7 @@ grn_select(grn_ctx *ctx, const char *table, unsigned int table_len,
   if ((table_ = grn_ctx_get(ctx, table, table_len))) {
     // match_columns_ = grn_obj_column(ctx, table_, match_columns, match_columns_len);
     if (filter_len && (filter[0] == '?') &&
-        (ctx->impl->output_type == GRN_CONTENT_JSON)) {
+        (ctx->impl->output.type == GRN_CONTENT_JSON)) {
       ctx->rc = grn_ts_select(ctx, table_, filter + 1, filter_len - 1,
                               scorer, scorer_len,
                               output_columns, output_columns_len,
@@ -2457,7 +2457,7 @@ static grn_obj *
 proc_missing(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
 {
   uint32_t plen;
-  grn_obj *outbuf = ctx->impl->outbuf;
+  grn_obj *outbuf = ctx->impl->output.buf;
   static int grn_document_root_len = -1;
   if (!grn_document_root) { return NULL; }
   if (grn_document_root_len < 0) {
@@ -3608,7 +3608,7 @@ bool_option_value(grn_obj *option, grn_bool default_value)
 static grn_obj *
 proc_dump(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
 {
-  grn_obj *outbuf = ctx->impl->outbuf;
+  grn_obj *outbuf = ctx->impl->output.buf;
   grn_obj *tables = VAR(0);
   grn_obj *dump_plugins_raw = VAR(1);
   grn_obj *dump_schema_raw = VAR(2);

  Modified: lib/ts.c (+24 -24)
===================================================================
--- lib/ts.c    2015-11-22 23:16:20 +0900 (63d7d3d)
+++ lib/ts.c    2015-11-23 15:44:48 +0900 (b797760)
@@ -43,9 +43,9 @@ static grn_rc
 grn_ts_bool_output(grn_ctx *ctx, grn_ts_bool value)
 {
   if (value) {
-    return grn_bulk_write(ctx, ctx->impl->outbuf, "true", 4);
+    return grn_bulk_write(ctx, ctx->impl->output.buf, "true", 4);
   } else {
-    return grn_bulk_write(ctx, ctx->impl->outbuf, "false", 5);
+    return grn_bulk_write(ctx, ctx->impl->output.buf, "false", 5);
   }
 }
 
@@ -53,62 +53,62 @@ grn_ts_bool_output(grn_ctx *ctx, grn_ts_bool value)
 static grn_rc
 grn_ts_int_output(grn_ctx *ctx, grn_ts_int value)
 {
-  return grn_text_lltoa(ctx, ctx->impl->outbuf, value);
+  return grn_text_lltoa(ctx, ctx->impl->output.buf, value);
 }
 
 /* grn_ts_float_output() outputs a value. */
 static grn_rc
 grn_ts_float_output(grn_ctx *ctx, grn_ts_float value)
 {
-  return grn_text_ftoa(ctx, ctx->impl->outbuf, value);
+  return grn_text_ftoa(ctx, ctx->impl->output.buf, value);
 }
 
 /* grn_ts_time_output() outputs a value. */
 static grn_rc
 grn_ts_time_output(grn_ctx *ctx, grn_ts_time value)
 {
-  return grn_text_ftoa(ctx, ctx->impl->outbuf, value * 0.000001);
+  return grn_text_ftoa(ctx, ctx->impl->output.buf, value * 0.000001);
 }
 
 /* grn_ts_text_output() outputs a value. */
 static grn_rc
 grn_ts_text_output(grn_ctx *ctx, grn_ts_text value)
 {
-  return grn_text_esc(ctx, ctx->impl->outbuf, value.ptr, value.size);
+  return grn_text_esc(ctx, ctx->impl->output.buf, value.ptr, value.size);
 }
 
 /* grn_ts_geo_output() outputs a value. */
 static grn_rc
 grn_ts_geo_output(grn_ctx *ctx, grn_ts_geo value)
 {
-  grn_rc rc = grn_bulk_write(ctx, ctx->impl->outbuf, "\"", 1);
+  grn_rc rc = grn_bulk_write(ctx, ctx->impl->output.buf, "\"", 1);
   if (rc != GRN_SUCCESS) {
     return rc;
   }
-  rc = grn_text_itoa(ctx, ctx->impl->outbuf, value.latitude);
+  rc = grn_text_itoa(ctx, ctx->impl->output.buf, value.latitude);
   if (rc != GRN_SUCCESS) {
     return rc;
   }
-  rc = grn_bulk_write(ctx, ctx->impl->outbuf, "x", 1);
+  rc = grn_bulk_write(ctx, ctx->impl->output.buf, "x", 1);
   if (rc != GRN_SUCCESS) {
     return rc;
   }
-  rc = grn_text_itoa(ctx, ctx->impl->outbuf, value.longitude);
+  rc = grn_text_itoa(ctx, ctx->impl->output.buf, value.longitude);
   if (rc != GRN_SUCCESS) {
     return rc;
   }
-  return grn_bulk_write(ctx, ctx->impl->outbuf, "\"", 1);
+  return grn_bulk_write(ctx, ctx->impl->output.buf, "\"", 1);
 }
 
 #define GRN_TS_VECTOR_OUTPUT(kind)\
   size_t i;\
-  grn_rc rc = grn_bulk_write(ctx, ctx->impl->outbuf, "[", 1);\
+  grn_rc rc = grn_bulk_write(ctx, ctx->impl->output.buf, "[", 1);\
   if (rc != GRN_SUCCESS) {\
     return rc;\
   }\
   for (i = 0; i < value.size; ++i) {\
     if (i) {\
-      rc = grn_bulk_write(ctx, ctx->impl->outbuf, ",", 1);\
+      rc = grn_bulk_write(ctx, ctx->impl->output.buf, ",", 1);\
       if (rc != GRN_SUCCESS) {\
         return rc;\
       }\
@@ -118,7 +118,7 @@ grn_ts_geo_output(grn_ctx *ctx, grn_ts_geo value)
       return rc;\
     }\
   }\
-  return grn_bulk_write(ctx, ctx->impl->outbuf, "]", 1);
+  return grn_bulk_write(ctx, ctx->impl->output.buf, "]", 1);
 /* grn_ts_bool_vector_output() outputs a value. */
 static grn_rc
 grn_ts_bool_vector_output(grn_ctx *ctx, grn_ts_bool_vector value)
@@ -460,7 +460,7 @@ grn_ts_writer_close(grn_ctx *ctx, grn_ts_writer *writer)
 
 #define GRN_TS_WRITER_OUTPUT_HEADER_CASE(TYPE, name)\
   case GRN_DB_ ## TYPE: {\
-    GRN_TEXT_PUTS(ctx, ctx->impl->outbuf, name);\
+    GRN_TEXT_PUTS(ctx, ctx->impl->output.buf, name);\
     break;\
   }
 /* grn_ts_writer_output_header() outputs names and data types. */
@@ -471,18 +471,18 @@ grn_ts_writer_output_header(grn_ctx *ctx, grn_ts_writer *writer)
   GRN_OUTPUT_ARRAY_OPEN("COLUMNS", writer->n_exprs);
   for (size_t i = 0; i < writer->n_exprs; ++i) {
     GRN_OUTPUT_ARRAY_OPEN("COLUMN", 2);
-    rc = grn_text_esc(ctx, ctx->impl->outbuf,
+    rc = grn_text_esc(ctx, ctx->impl->output.buf,
                       writer->names[i].ptr, writer->names[i].size);
     if (rc != GRN_SUCCESS) {
       return rc;
     }
-    GRN_TEXT_PUT(ctx, ctx->impl->outbuf, ",\"", 2);
+    GRN_TEXT_PUT(ctx, ctx->impl->output.buf, ",\"", 2);
     switch (writer->exprs[i]->data_type) {
       case GRN_DB_VOID: {
         if (writer->exprs[i]->data_kind == GRN_TS_GEO) {
-          GRN_TEXT_PUTS(ctx, ctx->impl->outbuf, "GeoPoint");
+          GRN_TEXT_PUTS(ctx, ctx->impl->output.buf, "GeoPoint");
         } else {
-          GRN_TEXT_PUTS(ctx, ctx->impl->outbuf, "Void");
+          GRN_TEXT_PUTS(ctx, ctx->impl->output.buf, "Void");
         }
         break;
       }
@@ -516,12 +516,12 @@ grn_ts_writer_output_header(grn_ctx *ctx, grn_ts_writer *writer)
                             writer->exprs[i]->data_type);
         }
         name_size = grn_obj_name(ctx, obj, name_buf, sizeof(name_buf));
-        GRN_TEXT_PUT(ctx, ctx->impl->outbuf, name_buf, name_size);
+        GRN_TEXT_PUT(ctx, ctx->impl->output.buf, name_buf, name_size);
         grn_obj_unlink(ctx, obj);
         break;
       }
     }
-    GRN_TEXT_PUTC(ctx, ctx->impl->outbuf, '"');
+    GRN_TEXT_PUTC(ctx, ctx->impl->output.buf, '"');
     GRN_OUTPUT_ARRAY_CLOSE();
   }
   GRN_OUTPUT_ARRAY_CLOSE(); /* COLUMNS. */
@@ -570,7 +570,7 @@ grn_ts_writer_output_body(grn_ctx *ctx, grn_ts_writer *writer,
       GRN_OUTPUT_ARRAY_OPEN("HIT", writer->n_exprs);
       for (j = 0; j < writer->n_exprs; ++j) {
         if (j) {
-          GRN_TEXT_PUTC(ctx, ctx->impl->outbuf, ',');
+          GRN_TEXT_PUTC(ctx, ctx->impl->output.buf, ',');
         }
         switch (writer->exprs[j]->data_kind) {
           GRN_TS_WRITER_OUTPUT_BODY_CASE(BOOL, bool);
@@ -608,7 +608,7 @@ grn_ts_writer_output(grn_ctx *ctx, grn_ts_writer *writer,
   GRN_OUTPUT_ARRAY_OPEN("RESULT", 1);
   GRN_OUTPUT_ARRAY_OPEN("RESULTSET", 2 + n_in);
   GRN_OUTPUT_ARRAY_OPEN("NHITS", 1);
-  rc = grn_text_ulltoa(ctx, ctx->impl->outbuf, n_hits);
+  rc = grn_text_ulltoa(ctx, ctx->impl->output.buf, n_hits);
   if (rc != GRN_SUCCESS) {
     return rc;
   }
@@ -816,7 +816,7 @@ grn_ts_select(grn_ctx *ctx, grn_obj *table,
     GRN_FREE(records);
   }
   if (rc != GRN_SUCCESS) {
-    GRN_BULK_REWIND(ctx->impl->outbuf);
+    GRN_BULK_REWIND(ctx->impl->output.buf);
     if ((ctx->rc == GRN_SUCCESS) || !ctx->errbuf[0]) {
       ERR(rc, "error message is missing");
     } else if (ctx->errlvl < GRN_LOG_ERROR) {

  Modified: src/groonga.c (+7 -6)
===================================================================
--- src/groonga.c    2015-11-22 23:16:20 +0900 (537e189)
+++ src/groonga.c    2015-11-23 15:44:48 +0900 (880e104)
@@ -2117,18 +2117,18 @@ g_output(grn_ctx *ctx, int flags, void *arg)
 {
   grn_edge *edge = arg;
   grn_com *com = edge->com;
-  grn_msg *req = edge->msg, *msg = (grn_msg *)ctx->impl->outbuf;
+  grn_msg *req = edge->msg, *msg = (grn_msg *)ctx->impl->output.buf;
   msg->edge_id = req->edge_id;
   msg->header.proto = req->header.proto == GRN_COM_PROTO_MBREQ
     ? GRN_COM_PROTO_MBRES : req->header.proto;
-  if (ctx->rc != GRN_SUCCESS && GRN_BULK_VSIZE(ctx->impl->outbuf) == 0) {
-    GRN_TEXT_PUTS(ctx, ctx->impl->outbuf, ctx->errbuf);
+  if (ctx->rc != GRN_SUCCESS && GRN_BULK_VSIZE(ctx->impl->output.buf) == 0) {
+    GRN_TEXT_PUTS(ctx, ctx->impl->output.buf, ctx->errbuf);
   }
   if (grn_msg_send(ctx, (grn_obj *)msg,
                    (flags & GRN_CTX_MORE) ? GRN_CTX_MORE : GRN_CTX_TAIL)) {
     edge->stat = EDGE_ABORT;
   }
-  ctx->impl->outbuf = grn_msg_open(ctx, com, &edge->send_old);
+  ctx->impl->output.buf = grn_msg_open(ctx, com, &edge->send_old);
 }
 
 static void
@@ -2160,8 +2160,9 @@ g_handler(grn_ctx *ctx, grn_obj *msg)
       grn_ctx_use(&edge->ctx, (grn_obj *)com->ev->opaque);
       grn_ctx_recv_handler_set(&edge->ctx, g_output, edge);
       com->opaque = edge;
-      grn_obj_close(&edge->ctx, edge->ctx.impl->outbuf);
-      edge->ctx.impl->outbuf = grn_msg_open(&edge->ctx, com, &edge->send_old);
+      grn_obj_close(&edge->ctx, edge->ctx.impl->output.buf);
+      edge->ctx.impl->output.buf =
+        grn_msg_open(&edge->ctx, com, &edge->send_old);
       edge->com = com;
       edge->stat = EDGE_IDLE;
       edge->flags = GRN_EDGE_WORKER;
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Zurück zum Archiv-Index