null+****@clear*****
null+****@clear*****
2010年 7月 9日 (金) 14:58:28 JST
Daijiro MORI 2010-07-09 05:58:28 +0000 (Fri, 09 Jul 2010) New Revision: fd08e415ff38080c96a086ca83066e8ec7028aa5 Log: Stopped raising error in grn_normalize_offset_and_limit(). Modified files: groonga.h lib/db.c lib/proc.c lib/util.c Modified: groonga.h (+3 -0) =================================================================== --- groonga.h 2010-07-08 14:23:11 +0000 (2361034) +++ groonga.h 2010-07-09 05:58:28 +0000 (9d6febf) @@ -106,6 +106,9 @@ typedef enum { GRN_RETRY_MAX = -64, GRN_INCOMPATIBLE_FILE_FORMAT = -65, GRN_UPDATE_NOT_ALLOWED = -66, + GRN_TOO_SMALL_OFFSET = -67, + GRN_TOO_LARGE_OFFSET = -68, + GRN_TOO_SMALL_LIMIT = -69 } grn_rc; GRN_API grn_rc grn_init(void); Modified: lib/db.c (+9 -3) =================================================================== --- lib/db.c 2010-07-08 14:23:11 +0000 (8030a77) +++ lib/db.c 2010-07-09 05:58:28 +0000 (0b22830) @@ -1739,10 +1739,14 @@ grn_table_cursor_open(grn_ctx *ctx, grn_obj *table, const void *max, unsigned max_size, int offset, int limit, int flags) { + grn_rc rc; grn_table_cursor *tc = NULL; + if (!table) { return tc; } GRN_API_ENTER; - if (table && !grn_normalize_offset_and_limit(ctx, grn_table_size(ctx, table), - &offset, &limit)) { + rc = grn_normalize_offset_and_limit(ctx, grn_table_size(ctx, table), &offset, &limit); + if (rc) { + ERR(rc, "grn_normalize_offset_and_limit failed"); + } else { switch (table->header.type) { case GRN_DB : tc = (grn_table_cursor *)grn_pat_cursor_open(ctx, ((grn_db *)table)->keys, @@ -6529,6 +6533,7 @@ int grn_table_sort(grn_ctx *ctx, grn_obj *table, int offset, int limit, grn_obj *result, grn_table_sort_key *keys, int n_keys) { + grn_rc rc; grn_obj *index; int n, e, i = 0; sort_entry *array, *ep; @@ -6550,7 +6555,8 @@ grn_table_sort(grn_ctx *ctx, grn_obj *table, int offset, int limit, goto exit; } n = grn_table_size(ctx, table); - if (grn_normalize_offset_and_limit(ctx, n, &offset, &limit)) { + if ((rc = grn_normalize_offset_and_limit(ctx, n, &offset, &limit))) { + ERR(rc, "grn_normalize_offset_and_limit failed"); goto exit; } else { e = offset + limit; Modified: lib/proc.c (+0 -2) =================================================================== --- lib/proc.c 2010-07-08 14:23:11 +0000 (4e9ebec) +++ lib/proc.c 2010-07-09 05:58:28 +0000 (d024590) @@ -190,7 +190,6 @@ grn_select(grn_ctx *ctx, const char *table, unsigned table_len, } grn_normalize_offset_and_limit(ctx, nhits, &offset, &limit); - ERRCLR(ctx); if (sortby_len) { if ((sorted = grn_table_create(ctx, NULL, 0, NULL, @@ -237,7 +236,6 @@ grn_select(grn_ctx *ctx, const char *table, unsigned table_len, grn_normalize_offset_and_limit(ctx, nhits, &n_drilldown_offset, &n_drilldown_limit); - ERRCLR(ctx); if (drilldown_sortby_len) { if ((keys = grn_table_sort_key_from_str(ctx, Modified: lib/util.c (+9 -10) =================================================================== --- lib/util.c 2010-07-08 14:23:11 +0000 (21f2d42) +++ lib/util.c 2010-07-09 05:58:28 +0000 (26c3237) @@ -30,19 +30,22 @@ grn_normalize_offset_and_limit(grn_ctx *ctx, int size, int *p_offset, int *p_lim if (offset < 0) { offset += size; if (offset < 0) { - ERR(GRN_INVALID_ARGUMENT, "too small offset"); - goto exit; + *p_offset = 0; + *p_limit = 0; + return GRN_TOO_SMALL_OFFSET; } } else if (offset != 0 && offset >= size) { - ERR(GRN_INVALID_ARGUMENT, "too large offset"); - goto exit; + *p_offset = 0; + *p_limit = 0; + return GRN_TOO_LARGE_OFFSET; } if (limit < 0) { limit += size + 1; if (limit < 0) { - ERR(GRN_INVALID_ARGUMENT, "too small limit"); - goto exit; + *p_offset = 0; + *p_limit = 0; + return GRN_TOO_SMALL_LIMIT; } } else if (limit > size) { limit = size; @@ -56,10 +59,6 @@ grn_normalize_offset_and_limit(grn_ctx *ctx, int size, int *p_offset, int *p_lim *p_offset = offset; *p_limit = limit; return GRN_SUCCESS; -exit: - *p_offset = 0; - *p_limit = 0; - return ctx->rc; } static grn_rc