[Groonga-commit] groonga/groonga at 6550539 [master] Hide grn_snip struct

アーカイブの一覧に戻る

Kouhei Sutou null+****@clear*****
Mon Feb 3 12:08:54 JST 2014


Kouhei Sutou	2014-02-03 12:08:54 +0900 (Mon, 03 Feb 2014)

  New Revision: 65505391e1a9ca9207de4facb14d9f1422a416cd
  https://github.com/groonga/groonga/commit/65505391e1a9ca9207de4facb14d9f1422a416cd

  Message:
    Hide grn_snip struct
    
    It is a backward incompatible change.
    
    Here is migration guide:
    
      * Rename grn_snip to grn_obj:
    
        Before:
    
            grn_snip *snip;
    
        After:
    
            grn_obj *snip;
    
      * Use grn_obj_close() instead of grn_snip_close():
    
        Before:
    
            grn_snip_close(ctx, snip);
    
        After:
    
            grn_obj_close(ctx, snip);

  Modified files:
    include/groonga.h
    lib/db.c
    lib/expr.c
    lib/proc.c
    lib/snip.c
    lib/snip.h
    test/unit/core/test-expr-parse.c
    test/unit/util/test-snip.c

  Modified: include/groonga.h (+17 -25)
===================================================================
--- include/groonga.h    2014-01-30 18:42:51 +0900 (ce956ab)
+++ include/groonga.h    2014-02-03 12:08:54 +0900 (d846a40)
@@ -990,9 +990,6 @@ GRN_API grn_posting *grn_geo_cursor_next(grn_ctx *ctx, grn_obj *cursor);
 #define GRN_QUERY_COLUMN ':'
 #endif /* GRN_QUERY_COLUMN */
 
-/* grn_snip should be removed.
- * TODO: 3.0 */
-typedef struct _grn_snip grn_snip;
 typedef struct _grn_snip_mapping grn_snip_mapping;
 
 struct _grn_snip_mapping {
@@ -1005,27 +1002,22 @@ struct _grn_snip_mapping {
 
 #define GRN_SNIP_MAPPING_HTML_ESCAPE   ((grn_snip_mapping *)-1)
 
-/* grn_snip_open() should return grn_obj * instead.
- * TODO: 3.0 */
-GRN_API grn_snip *grn_snip_open(grn_ctx *ctx, int flags, unsigned int width,
-                                unsigned int max_results,
-                                const char *defaultopentag, unsigned int defaultopentag_len,
-                                const char *defaultclosetag, unsigned int defaultclosetag_len,
-                                grn_snip_mapping *mapping);
-/* grn_snip_close() should be removed. Use grn_obj_close() instead.
- * TODO: 3.0 */
-GRN_API grn_rc grn_snip_close(grn_ctx *ctx, grn_snip *snip);
-GRN_API grn_rc grn_snip_add_cond(grn_ctx *ctx, grn_snip *snip,
+GRN_API grn_obj *grn_snip_open(grn_ctx *ctx, int flags, unsigned int width,
+                               unsigned int max_results,
+                               const char *defaultopentag, unsigned int defaultopentag_len,
+                               const char *defaultclosetag, unsigned int defaultclosetag_len,
+                               grn_snip_mapping *mapping);
+GRN_API grn_rc grn_snip_add_cond(grn_ctx *ctx, grn_obj *snip,
                                  const char *keyword, unsigned int keyword_len,
                                  const char *opentag, unsigned int opentag_len,
                                  const char *closetag, unsigned int closetag_len);
-GRN_API grn_rc grn_snip_set_normalizer(grn_ctx *ctx, grn_snip *snip,
+GRN_API grn_rc grn_snip_set_normalizer(grn_ctx *ctx, grn_obj *snip,
                                        grn_obj *normalizer);
-GRN_API grn_obj *grn_snip_get_normalizer(grn_ctx *ctx, grn_snip *snip);
-GRN_API grn_rc grn_snip_exec(grn_ctx *ctx, grn_snip *snip,
+GRN_API grn_obj *grn_snip_get_normalizer(grn_ctx *ctx, grn_obj *snip);
+GRN_API grn_rc grn_snip_exec(grn_ctx *ctx, grn_obj *snip,
                              const char *string, unsigned int string_len,
                              unsigned int *nresults, unsigned int *max_tagged_len);
-GRN_API grn_rc grn_snip_get_result(grn_ctx *ctx, grn_snip *snip, const unsigned int index,
+GRN_API grn_rc grn_snip_get_result(grn_ctx *ctx, grn_obj *snip, const unsigned int index,
                                    char *result, unsigned int *result_len);
 
 /* log */
@@ -1709,15 +1701,15 @@ GRN_API grn_rc grn_expr_parse(grn_ctx *ctx, grn_obj *expr,
                               grn_obj *default_column, grn_operator default_mode,
                               grn_operator default_op, grn_expr_flags flags);
 
-GRN_API grn_snip *grn_expr_snip(grn_ctx *ctx, grn_obj *expr, int flags,
-                                unsigned int width, unsigned int max_results,
-                                unsigned int n_tags,
-                                const char **opentags, unsigned int *opentag_lens,
-                                const char **closetags, unsigned int *closetag_lens,
-                                grn_snip_mapping *mapping);
+GRN_API grn_obj *grn_expr_snip(grn_ctx *ctx, grn_obj *expr, int flags,
+                               unsigned int width, unsigned int max_results,
+                               unsigned int n_tags,
+                               const char **opentags, unsigned int *opentag_lens,
+                               const char **closetags, unsigned int *closetag_lens,
+                               grn_snip_mapping *mapping);
 GRN_API grn_rc grn_expr_snip_add_conditions(grn_ctx *ctx,
                                             grn_obj *expr,
-                                            grn_snip *snip,
+                                            grn_obj *snip,
                                             unsigned int n_tags,
                                             const char **opentags,
                                             unsigned int *opentag_lens,

  Modified: lib/db.c (+1 -1)
===================================================================
--- lib/db.c    2014-01-30 18:42:51 +0900 (621c57e)
+++ lib/db.c    2014-02-03 12:08:54 +0900 (25ea056)
@@ -7738,7 +7738,7 @@ grn_obj_close(grn_ctx *ctx, grn_obj *obj)
       rc = GRN_SUCCESS;
       break;
     case GRN_SNIP :
-      rc = grn_snip_close_real(ctx, (grn_snip *)obj);
+      rc = grn_snip_close(ctx, (grn_snip *)obj);
       break;
     case GRN_STRING :
       rc = grn_string_close(ctx, obj);

  Modified: lib/expr.c (+3 -3)
===================================================================
--- lib/expr.c    2014-01-30 18:42:51 +0900 (b966d57)
+++ lib/expr.c    2014-02-03 12:08:54 +0900 (a9afff2)
@@ -6518,7 +6518,7 @@ grn_expr_parser_close(grn_ctx *ctx)
 }
 
 grn_rc
-grn_expr_snip_add_conditions(grn_ctx *ctx, grn_obj *expr, grn_snip *snip,
+grn_expr_snip_add_conditions(grn_ctx *ctx, grn_obj *expr, grn_obj *snip,
                              unsigned int n_tags,
                              const char **opentags, unsigned int *opentag_lens,
                              const char **closetags, unsigned int *closetag_lens)
@@ -6581,7 +6581,7 @@ grn_expr_snip_add_conditions(grn_ctx *ctx, grn_obj *expr, grn_snip *snip,
   GRN_API_RETURN(GRN_SUCCESS);
 }
 
-grn_snip *
+grn_obj *
 grn_expr_snip(grn_ctx *ctx, grn_obj *expr, int flags,
               unsigned int width, unsigned int max_results,
               unsigned int n_tags,
@@ -6589,7 +6589,7 @@ grn_expr_snip(grn_ctx *ctx, grn_obj *expr, int flags,
               const char **closetags, unsigned int *closetag_lens,
               grn_snip_mapping *mapping)
 {
-  grn_snip *res = NULL;
+  grn_obj *res = NULL;
   GRN_API_ENTER;
   if ((res = grn_snip_open(ctx, flags, width, max_results,
                            NULL, 0, NULL, 0, mapping))) {

  Modified: lib/proc.c (+3 -3)
===================================================================
--- lib/proc.c    2014-01-30 18:42:51 +0900 (c677f69)
+++ lib/proc.c    2014-02-03 12:08:54 +0900 (24a4674)
@@ -3639,7 +3639,7 @@ selector_all_records(grn_ctx *ctx, grn_obj *table, grn_obj *index,
 }
 
 static grn_obj *
-snippet_exec(grn_ctx *ctx, grn_snip *snip, grn_obj *text,
+snippet_exec(grn_ctx *ctx, grn_obj *snip, grn_obj *text,
              grn_user_data *user_data)
 {
   grn_rc rc;
@@ -3695,7 +3695,7 @@ func_snippet_html(grn_ctx *ctx, int nargs, grn_obj **args,
     grn_obj *expression = NULL;
     grn_obj *condition_ptr = NULL;
     grn_obj *condition = NULL;
-    grn_snip *snip = NULL;
+    grn_obj *snip = NULL;
     int flags = GRN_SNIP_SKIP_LEADING_SPACES;
     unsigned int width = 200;
     unsigned int max_n_results = 3;
@@ -3725,7 +3725,7 @@ func_snippet_html(grn_ctx *ctx, int nargs, grn_obj **args,
 
     if (snip) {
       snippets = snippet_exec(ctx, snip, text, user_data);
-      grn_snip_close(ctx, snip);
+      grn_obj_close(ctx, snip);
     }
   }
 

  Modified: lib/snip.c (+96 -92)
===================================================================
--- lib/snip.c    2014-01-30 18:42:51 +0900 (9940623)
+++ lib/snip.c    2014-02-03 12:08:54 +0900 (f5ed677)
@@ -338,25 +338,34 @@ grn_snip_cond_set_tag(grn_ctx *ctx,
 }
 
 grn_rc
-grn_snip_set_normalizer(grn_ctx *ctx, grn_snip *snip,
+grn_snip_set_normalizer(grn_ctx *ctx, grn_obj *snip,
                         grn_obj *normalizer)
 {
+  grn_snip *snip_;
   if (!snip) {
     return GRN_INVALID_ARGUMENT;
   }
 
-  snip->normalizer = normalizer;
+  snip_ = (grn_snip *)snip;
+  snip_->normalizer = normalizer;
   return GRN_SUCCESS;
 }
 
 grn_obj *
-grn_snip_get_normalizer(grn_ctx *ctx, grn_snip *snip)
+grn_snip_get_normalizer(grn_ctx *ctx, grn_obj *snip)
 {
-  return snip->normalizer;
+  grn_snip *snip_;
+
+  if (!snip) {
+    return NULL;
+  }
+
+  snip_ = (grn_snip *)snip;
+  return snip_->normalizer;
 }
 
 grn_rc
-grn_snip_add_cond(grn_ctx *ctx, grn_snip *snip,
+grn_snip_add_cond(grn_ctx *ctx, grn_obj *snip,
                   const char *keyword, unsigned int keyword_len,
                   const char *opentag, unsigned int opentag_len,
                   const char *closetag, unsigned int closetag_len)
@@ -365,26 +374,29 @@ grn_snip_add_cond(grn_ctx *ctx, grn_snip *snip,
   int copy_tag;
   snip_cond *cond;
   unsigned int norm_blen;
+  grn_snip *snip_;
 
-  if (!snip || !keyword || !keyword_len || snip->cond_len >= MAX_SNIP_COND_COUNT) {
+  snip_ = (grn_snip *)snip;
+  if (!snip_ || !keyword || !keyword_len || snip_->cond_len >= MAX_SNIP_COND_COUNT) {
     return GRN_INVALID_ARGUMENT;
   }
-  cond = snip->cond + snip->cond_len;
+
+  cond = snip_->cond + snip_->cond_len;
   if ((rc = grn_snip_cond_init(ctx, cond, keyword, keyword_len,
-                               snip->encoding, snip->normalizer, snip->flags))) {
+                               snip_->encoding, snip_->normalizer, snip_->flags))) {
     return rc;
   }
   grn_string_get_normalized(ctx, cond->keyword, NULL, &norm_blen, NULL);
-  if (norm_blen > snip->width) {
+  if (norm_blen > snip_->width) {
     grn_snip_cond_close(ctx, cond);
     return GRN_INVALID_ARGUMENT;
   }
 
-  copy_tag = snip->flags & GRN_SNIP_COPY_TAG;
+  copy_tag = snip_->flags & GRN_SNIP_COPY_TAG;
   rc = grn_snip_cond_set_tag(ctx,
                              &(cond->opentag), &(cond->opentag_len),
                              opentag, opentag_len,
-                             snip->defaultopentag, snip->defaultopentag_len,
+                             snip_->defaultopentag, snip_->defaultopentag_len,
                              copy_tag);
   if (rc) {
     grn_snip_cond_close(ctx, cond);
@@ -394,7 +406,7 @@ grn_snip_add_cond(grn_ctx *ctx, grn_snip *snip,
   rc = grn_snip_cond_set_tag(ctx,
                              &(cond->closetag), &(cond->closetag_len),
                              closetag, closetag_len,
-                             snip->defaultclosetag, snip->defaultclosetag_len,
+                             snip_->defaultclosetag, snip_->defaultclosetag_len,
                              copy_tag);
   if (rc) {
     if (opentag && copy_tag) {
@@ -404,7 +416,7 @@ grn_snip_add_cond(grn_ctx *ctx, grn_snip *snip,
     return rc;
   }
 
-  snip->cond_len++;
+  snip_->cond_len++;
   return GRN_SUCCESS;
 }
 
@@ -451,7 +463,7 @@ grn_snip_set_default_tag(grn_ctx *ctx,
   return GRN_SUCCESS;
 }
 
-grn_snip *
+grn_obj *
 grn_snip_open(grn_ctx *ctx, int flags, unsigned int width,
               unsigned int max_results,
               const char *defaultopentag, unsigned int defaultopentag_len,
@@ -521,7 +533,7 @@ grn_snip_open(grn_ctx *ctx, int flags, unsigned int width,
     grn_db_obj_init(ctx, db, id, DB_OBJ(ret));
   }
 
-  GRN_API_RETURN(ret);
+  GRN_API_RETURN((grn_obj *)ret);
 }
 
 static grn_rc
@@ -541,10 +553,8 @@ exec_clean(grn_ctx *ctx, grn_snip *snip)
   return GRN_SUCCESS;
 }
 
-/* It should be renamed to grn_snip_close() and marked as internal.
- * TODO: 3.0 */
 grn_rc
-grn_snip_close_real(grn_ctx *ctx, grn_snip *snip)
+grn_snip_close(grn_ctx *ctx, grn_snip *snip)
 {
   snip_cond *cond, *cond_end;
   if (!snip) { return GRN_INVALID_ARGUMENT; }
@@ -571,43 +581,35 @@ grn_snip_close_real(grn_ctx *ctx, grn_snip *snip)
   GRN_API_RETURN(GRN_SUCCESS);
 }
 
-/* Just for backward compatibility. It should be replaced with
- * grn_snip_close_real() when groonga 3.0.
- * TODO: 3.0 */
-grn_rc
-grn_snip_close(grn_ctx *ctx, grn_snip *snip)
-{
-  return grn_obj_close(ctx, (grn_obj *)snip);
-}
-
-
 grn_rc
-grn_snip_exec(grn_ctx *ctx, grn_snip *snip, const char *string, unsigned int string_len,
+grn_snip_exec(grn_ctx *ctx, grn_obj *snip, const char *string, unsigned int string_len,
               unsigned int *nresults, unsigned int *max_tagged_len)
 {
   size_t i;
+  grn_snip *snip_;
   int f = GRN_STR_WITH_CHECKS|GRN_STR_REMOVEBLANK;
   if (!snip || !string || !nresults || !max_tagged_len) {
     return GRN_INVALID_ARGUMENT;
   }
   GRN_API_ENTER;
-  exec_clean(ctx, snip);
+  snip_ = (grn_snip *)snip;
+  exec_clean(ctx, snip_);
   *nresults = 0;
-  snip->nstr = grn_string_open(ctx, string, string_len, snip->normalizer, f);
-  if (!snip->nstr) {
-    exec_clean(ctx, snip);
+  snip_->nstr = grn_string_open(ctx, string, string_len, snip_->normalizer, f);
+  if (!snip_->nstr) {
+    exec_clean(ctx, snip_);
     GRN_LOG(ctx, GRN_LOG_ALERT, "grn_string_open on grn_snip_exec failed !");
     GRN_API_RETURN(ctx->rc);
   }
-  for (i = 0; i < snip->cond_len; i++) {
-    grn_bm_tunedbm(ctx, snip->cond + i, snip->nstr, snip->flags);
+  for (i = 0; i < snip_->cond_len; i++) {
+    grn_bm_tunedbm(ctx, snip_->cond + i, snip_->nstr, snip_->flags);
   }
 
   {
-    _snip_tag_result *tag_result = snip->tag_result;
-    _snip_result *snip_result = snip->snip_result;
+    _snip_tag_result *tag_result = snip_->tag_result;
+    _snip_result *snip_result = snip_->snip_result;
     size_t last_end_offset = 0, last_last_end_offset = 0;
-    unsigned int unfound_cond_count = snip->cond_len;
+    unsigned int unfound_cond_count = snip_->cond_len;
 
     *max_tagged_len = 0;
     while (1) {
@@ -621,14 +623,14 @@ grn_snip_exec(grn_ctx *ctx, grn_snip *snip, const char *string, unsigned int str
         snip_cond *cond = NULL;
 
         /* get condition which have minimum offset and is not stopped */
-        for (i = 0; i < snip->cond_len; i++) {
-          if (snip->cond[i].stopflag == SNIPCOND_NONSTOP &&
-              (min_start_offset > snip->cond[i].start_offset ||
-               (min_start_offset == snip->cond[i].start_offset &&
-                max_end_offset < snip->cond[i].end_offset))) {
-            min_start_offset = snip->cond[i].start_offset;
-            max_end_offset = snip->cond[i].end_offset;
-            cond = &snip->cond[i];
+        for (i = 0; i < snip_->cond_len; i++) {
+          if (snip_->cond[i].stopflag == SNIPCOND_NONSTOP &&
+              (min_start_offset > snip_->cond[i].start_offset ||
+               (min_start_offset == snip_->cond[i].start_offset &&
+                max_end_offset < snip_->cond[i].end_offset))) {
+            min_start_offset = snip_->cond[i].start_offset;
+            max_end_offset = snip_->cond[i].end_offset;
+            cond = &snip_->cond[i];
           }
         }
         if (!cond) {
@@ -638,38 +640,38 @@ grn_snip_exec(grn_ctx *ctx, grn_snip *snip, const char *string, unsigned int str
         if (snip_result->tag_count == 0) {
           /* skip condition if the number of rest snippet field is smaller than */
           /* the number of unfound keywords. */
-          if (snip->max_results - *nresults <= unfound_cond_count && cond->count > 0) {
+          if (snip_->max_results - *nresults <= unfound_cond_count && cond->count > 0) {
             int_least8_t exclude_other_cond = 1;
-            for (i = 0; i < snip->cond_len; i++) {
-              if ((snip->cond + i) != cond
-                  && snip->cond[i].end_offset <= cond->start_offset + snip->width
-                  && snip->cond[i].count == 0) {
+            for (i = 0; i < snip_->cond_len; i++) {
+              if ((snip_->cond + i) != cond
+                  && snip_->cond[i].end_offset <= cond->start_offset + snip_->width
+                  && snip_->cond[i].count == 0) {
                 exclude_other_cond = 0;
               }
             }
             if (exclude_other_cond) {
-              grn_bm_tunedbm(ctx, cond, snip->nstr, snip->flags);
+              grn_bm_tunedbm(ctx, cond, snip_->nstr, snip_->flags);
               continue;
             }
           }
           snip_result->start_offset = cond->start_offset;
-          snip_result->first_tag_result_idx = snip->tag_count;
+          snip_result->first_tag_result_idx = snip_->tag_count;
         } else {
-          if (cond->start_offset >= snip_result->start_offset + snip->width) {
+          if (cond->start_offset >= snip_result->start_offset + snip_->width) {
             break;
           }
           /* check nesting to make valid HTML */
           /* ToDo: allow <test><te>te</te><st>st</st></test> */
           if (cond->start_offset < last_tag_end) {
-            grn_bm_tunedbm(ctx, cond, snip->nstr, snip->flags);
+            grn_bm_tunedbm(ctx, cond, snip_->nstr, snip_->flags);
             continue;
           }
         }
-        if (cond->end_offset > snip_result->start_offset + snip->width) {
+        if (cond->end_offset > snip_result->start_offset + snip_->width) {
           /* If a keyword gets across a snippet, */
           /* it was skipped and never to be tagged. */
           cond->stopflag = SNIPCOND_ACROSS;
-          grn_bm_tunedbm(ctx, cond, snip->nstr, snip->flags);
+          grn_bm_tunedbm(ctx, cond, snip_->nstr, snip_->flags);
         } else {
           found_cond = 1;
           if (cond->count == 0) {
@@ -685,36 +687,36 @@ grn_snip_exec(grn_ctx *ctx, grn_snip *snip, const char *string, unsigned int str
           snip_result->tag_count++;
           tag_result++;
           tagged_len += cond->opentag_len + cond->closetag_len;
-          if (++snip->tag_count >= MAX_SNIP_TAG_COUNT) {
+          if (++snip_->tag_count >= MAX_SNIP_TAG_COUNT) {
             break;
           }
-          grn_bm_tunedbm(ctx, cond, snip->nstr, snip->flags);
+          grn_bm_tunedbm(ctx, cond, snip_->nstr, snip_->flags);
         }
       }
       if (!found_cond) {
         break;
       }
-      if (snip_result->start_offset + last_end_offset < snip->width) {
+      if (snip_result->start_offset + last_end_offset < snip_->width) {
         snip_result->start_offset = 0;
       } else {
         snip_result->start_offset =
           MAX(MIN
-              ((snip_result->start_offset + last_end_offset - snip->width) / 2,
-               string_len - snip->width), last_last_end_offset);
+              ((snip_result->start_offset + last_end_offset - snip_->width) / 2,
+               string_len - snip_->width), last_last_end_offset);
       }
       snip_result->start_offset =
-        grn_snip_find_firstbyte(string, snip->encoding, snip_result->start_offset, 1);
+        grn_snip_find_firstbyte(string, snip_->encoding, snip_result->start_offset, 1);
 
-      snip_result->end_offset = snip_result->start_offset + snip->width;
+      snip_result->end_offset = snip_result->start_offset + snip_->width;
       if (snip_result->end_offset < string_len) {
         snip_result->end_offset =
-          grn_snip_find_firstbyte(string, snip->encoding, snip_result->end_offset, -1);
+          grn_snip_find_firstbyte(string, snip_->encoding, snip_result->end_offset, -1);
       } else {
         snip_result->end_offset = string_len;
       }
       last_last_end_offset = snip_result->end_offset;
 
-      if (snip->mapping == (grn_snip_mapping *) -1) {
+      if (snip_->mapping == (grn_snip_mapping *) -1) {
         tagged_len +=
           count_mapped_chars(&string[snip_result->start_offset],
                              &string[snip_result->end_offset]) + 1;
@@ -724,17 +726,17 @@ grn_snip_exec(grn_ctx *ctx, grn_snip *snip, const char *string, unsigned int str
 
       *max_tagged_len = MAX(*max_tagged_len, tagged_len);
 
-      snip_result->last_tag_result_idx = snip->tag_count - 1;
+      snip_result->last_tag_result_idx = snip_->tag_count - 1;
       (*nresults)++;
       snip_result++;
 
-      if (*nresults == snip->max_results || snip->tag_count == MAX_SNIP_TAG_COUNT) {
+      if (*nresults == snip_->max_results || snip_->tag_count == MAX_SNIP_TAG_COUNT) {
         break;
       }
-      for (i = 0; i < snip->cond_len; i++) {
-        if (snip->cond[i].stopflag != SNIPCOND_STOP) {
+      for (i = 0; i < snip_->cond_len; i++) {
+        if (snip_->cond[i].stopflag != SNIPCOND_STOP) {
           all_stop = 0;
-          snip->cond[i].stopflag = SNIPCOND_NONSTOP;
+          snip_->cond[i].stopflag = SNIPCOND_NONSTOP;
         }
       }
       if (all_stop) {
@@ -742,41 +744,43 @@ grn_snip_exec(grn_ctx *ctx, grn_snip *snip, const char *string, unsigned int str
       }
     }
   }
-  snip->snip_count = *nresults;
-  snip->string = string;
+  snip_->snip_count = *nresults;
+  snip_->string = string;
 
-  snip->max_tagged_len = *max_tagged_len;
+  snip_->max_tagged_len = *max_tagged_len;
 
   GRN_API_RETURN(ctx->rc);
 }
 
 grn_rc
-grn_snip_get_result(grn_ctx *ctx, grn_snip *snip, const unsigned int index, char *result, unsigned int *result_len)
+grn_snip_get_result(grn_ctx *ctx, grn_obj *snip, const unsigned int index, char *result, unsigned int *result_len)
 {
   char *p;
   size_t i, j, k;
   _snip_result *sres;
+  grn_snip *snip_;
 
-  if (snip->snip_count <= index || !snip->nstr) {
+  snip_ = (grn_snip *)snip;
+  if (snip_->snip_count <= index || !snip_->nstr) {
     return GRN_INVALID_ARGUMENT;
   }
 
-  GRN_ASSERT(snip->snip_count != 0 && snip->tag_count != 0);
+  GRN_ASSERT(snip_->snip_count != 0 && snip_->tag_count != 0);
 
   GRN_API_ENTER;
-  sres = &snip->snip_result[index];
+  sres = &snip_->snip_result[index];
   j = sres->first_tag_result_idx;
   for (p = result, i = sres->start_offset; i < sres->end_offset; i++) {
-    for (; j <= sres->last_tag_result_idx && snip->tag_result[j].start_offset == i; j++) {
-      if (snip->tag_result[j].end_offset > sres->end_offset) {
+    for (; j <= sres->last_tag_result_idx && snip_->tag_result[j].start_offset == i; j++) {
+      if (snip_->tag_result[j].end_offset > sres->end_offset) {
         continue;
       }
-      memcpy(p, snip->tag_result[j].cond->opentag, snip->tag_result[j].cond->opentag_len);
-      p += snip->tag_result[j].cond->opentag_len;
+      memcpy(p, snip_->tag_result[j].cond->opentag, snip_->tag_result[j].cond->opentag_len);
+      p += snip_->tag_result[j].cond->opentag_len;
     }
 
-    if (snip->mapping == GRN_SNIP_MAPPING_HTML_ESCAPE) {
-      switch (snip->string[i]) {
+    if (snip_->mapping == GRN_SNIP_MAPPING_HTML_ESCAPE) {
+      switch (snip_->string[i]) {
       case '<':
         *p++ = '&';
         *p++ = 'l';
@@ -805,20 +809,20 @@ grn_snip_get_result(grn_ctx *ctx, grn_snip *snip, const unsigned int index, char
         *p++ = ';';
         break;
       default:
-        *p++ = snip->string[i];
+        *p++ = snip_->string[i];
         break;
       }
     } else {
-      *p++ = snip->string[i];
+      *p++ = snip_->string[i];
     }
 
     for (k = sres->last_tag_result_idx;
-         snip->tag_result[k].end_offset <= sres->end_offset; k--) {
+         snip_->tag_result[k].end_offset <= sres->end_offset; k--) {
       /* TODO: avoid all loop */
-      if (snip->tag_result[k].end_offset == i + 1) {
-        memcpy(p, snip->tag_result[k].cond->closetag,
-               snip->tag_result[k].cond->closetag_len);
-        p += snip->tag_result[k].cond->closetag_len;
+      if (snip_->tag_result[k].end_offset == i + 1) {
+        memcpy(p, snip_->tag_result[k].cond->closetag,
+               snip_->tag_result[k].cond->closetag_len);
+        p += snip_->tag_result[k].cond->closetag_len;
       }
       if (k <= sres->first_tag_result_idx) {
         break;
@@ -828,7 +832,7 @@ grn_snip_get_result(grn_ctx *ctx, grn_snip *snip, const unsigned int index, char
   *p = '\0';
 
   if(result_len) { *result_len = (unsigned int)(p - result); }
-  GRN_ASSERT((unsigned int)(p - result) <= snip->max_tagged_len);
+  GRN_ASSERT((unsigned int)(p - result) <= snip_->max_tagged_len);
 
   GRN_API_RETURN(ctx->rc);
 }

  Modified: lib/snip.h (+3 -3)
===================================================================
--- lib/snip.h    2014-01-30 18:42:51 +0900 (c626922)
+++ lib/snip.h    2014-02-03 12:08:54 +0900 (7a25292)
@@ -87,7 +87,7 @@ typedef struct
   unsigned int tag_count;
 } _snip_result;
 
-struct _grn_snip
+typedef struct _grn_snip
 {
   grn_db_obj obj;
   grn_encoding encoding;
@@ -116,9 +116,9 @@ struct _grn_snip
   size_t max_tagged_len;
 
   grn_obj *normalizer;
-};
+} grn_snip;
 
-grn_rc grn_snip_close_real(grn_ctx *ctx, grn_snip *snip);
+grn_rc grn_snip_close(grn_ctx *ctx, grn_snip *snip);
 grn_rc grn_snip_cond_init(grn_ctx *ctx, snip_cond *sc, const char *keyword, unsigned int keyword_len,
                           grn_encoding enc, grn_obj *normalizer, int flags);
 void grn_snip_cond_reinit(snip_cond *cond);

  Modified: test/unit/core/test-expr-parse.c (+5 -5)
===================================================================
--- test/unit/core/test-expr-parse.c    2014-01-30 18:42:51 +0900 (1d3c9e9)
+++ test/unit/core/test-expr-parse.c    2014-02-03 12:08:54 +0900 (8cf8522)
@@ -1,5 +1,5 @@
 /* -*- c-basic-offset: 2; coding: utf-8 -*- */
-/* Copyright(C) 2009 Brazil
+/* Copyright(C) 2009-2014 Brazil
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -662,7 +662,7 @@ test_snip(void)
         GRN_EXPR_SYNTAX_QUERY|GRN_EXPR_ALLOW_PRAGMA);
 
   {
-    grn_snip *snip;
+    grn_obj *snip;
     int flags = 0;
     unsigned int width, max_results;
     const char *open_tags[] = {"[[", "<"};
@@ -709,7 +709,7 @@ test_snip(void)
                             result);
     cut_assert_equal_uint(49, result_len);
 
-    grn_test_assert(grn_snip_close(&context, snip));
+    grn_test_assert(grn_obj_close(&context, snip));
   }
 }
 
@@ -727,7 +727,7 @@ test_snip_without_tags(void)
         GRN_EXPR_SYNTAX_QUERY|GRN_EXPR_ALLOW_PRAGMA);
 
   {
-    grn_snip *snip;
+    grn_obj *snip;
     int flags = 0;
     unsigned int width, max_results;
     unsigned int n_results;
@@ -770,7 +770,7 @@ test_snip_without_tags(void)
                             result);
     cut_assert_equal_uint(45, result_len);
 
-    grn_test_assert(grn_snip_close(&context, snip));
+    grn_test_assert(grn_obj_close(&context, snip));
   }
 }
 

  Modified: test/unit/util/test-snip.c (+3 -3)
===================================================================
--- test/unit/util/test-snip.c    2014-01-30 18:42:51 +0900 (5a18f1d)
+++ test/unit/util/test-snip.c    2014-02-03 12:08:54 +0900 (0435553)
@@ -49,7 +49,7 @@ void test_normalizer_accessor(void);
 
 static grn_ctx context;
 static grn_obj *database;
-static grn_snip *snip;
+static grn_obj *snip;
 static gchar *keyword;
 static gchar *result;
 
@@ -222,7 +222,7 @@ void
 cut_teardown(void)
 {
   if (snip) {
-    grn_obj_close(&context, (grn_obj *)snip);
+    grn_obj_close(&context, snip);
   }
   if (keyword) {
     g_free(keyword);
@@ -242,7 +242,7 @@ cut_teardown(void)
   grn_ctx_fin(&context);
 }
 
-static grn_snip *
+static grn_obj *
 open_snip(void)
 {
   if (snip) {
-------------- next part --------------
HTML����������������������������...
ダウンロード 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る