diff --git a/examples/arif_rime.c b/examples/arif_rime.c index 617b3db..a939dea 100644 --- a/examples/arif_rime.c +++ b/examples/arif_rime.c @@ -104,9 +104,7 @@ arif_rime_finalize ( free_candidates(ctx); if (rime_api != NULL) { - if (ctx->session != 0) { - rime_api->destroy_session(ctx->session); - } + rime_api->destroy_session(ctx->session); } free(ctx); @@ -140,7 +138,7 @@ arif_rime_init ( assert(ctx != NULL); *ctx = (struct engine_ctx) { - .session = rime_api->create_session(), + .session = 0, }; *engine_data_ptr = ctx; return 0; diff --git a/src/arif.c b/src/arif.c index 19d3b35..d5ed463 100644 --- a/src/arif.c +++ b/src/arif.c @@ -60,7 +60,6 @@ struct arif_ctx { // Forward declaration start static struct cand_page * choose_candidate (struct cand_page *, int); -static void clear_old_line (struct arif_ctx *); static int compare_text (char const *, int, char const *, int); static void copy_candidate (struct arif_cand *, struct arif_cand const *, int, arif_cand_disp_func *); @@ -77,6 +76,7 @@ static struct cand_page * static void new_pages (struct arif_cand const *, int, int, arif_cand_disp_func *, struct cand_page **, struct cand_page **); +static void set_old_line (struct arif_ctx *, char const *, int, int); // Forward declaration end static struct cand_page * @@ -105,16 +105,6 @@ choose_candidate ( return new_page; } -static inline void -clear_old_line ( - struct arif_ctx *ctx -) { - free((char *) ctx->old_line); - ctx->old_line = NULL; - ctx->old_offset = 0; - ctx->old_len = 0; -} - static inline int compare_text ( char const *text1, @@ -213,14 +203,14 @@ free_page_list ( if (head == NULL) { return; } - struct cand_page *prev = head->prev; + struct cand_page *next, *prev = head->prev; // free forward - for (struct cand_page *next, *page = head; page != NULL; page = next) { + for (struct cand_page *page = head; page != NULL; page = next) { next = page->next; free_page(page); } // free backward - for (struct cand_page *next, *page = prev; page != NULL; page = next) { + for (struct cand_page *page = prev; page != NULL; page = next) { next = page->prev; free_page(page); } @@ -398,11 +388,7 @@ arif_query ( char *saved_line = malloc(sizeof(char) * (offset + len)); assert(saved_line != NULL); - free((char *) ctx->old_line); - ctx->old_line = memcpy(saved_line, line, offset + len); - ctx->old_offset = offset; - ctx->old_len = len; - + set_old_line(ctx, memcpy(saved_line, line, offset + len), offset, len); first_candidates(ctx, saved_line, offset, len); } else { // same text as old query @@ -426,7 +412,7 @@ arif_query ( ctx->page_num = 1; ctx->no_more_pages = false; - clear_old_line(ctx); + set_old_line(ctx, NULL, 0, 0); } finish: @@ -482,8 +468,21 @@ arif_set_engine ( ctx->page_num = 0; ctx->no_more_pages = false; - clear_old_line(ctx); + set_old_line(ctx, NULL, 0, 0); ctx->engine = engine; ctx->engine_data = engine_data; } + +static inline void +set_old_line ( + struct arif_ctx *ctx, + char const *old_line, + int old_offset, + int old_len +) { + free((char *) ctx->old_line); + ctx->old_line = old_line; + ctx->old_offset = old_offset; + ctx->old_len = old_len; +} diff --git a/tests/Makefile.am b/tests/Makefile.am index 723415b..35dcbce 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -20,9 +20,9 @@ arif_test_SOURCES = arif_test.c arif_dummy_engine.c libarifdummy_la_CPPFLAGS = -I$(top_srcdir)/include libarifdummy_la_SOURCES = arif_dummy_engine.c -EXTRA_DIST = lib/arif.exp \ - arif/000-query.exp \ - arif/001-select-page.exp \ +EXTRA_DIST = lib/arif.exp \ + arif/000-query.exp \ + arif/001-select-page.exp \ arif/002-fetch.exp RUNTESTFLAGS = ARIF_TEST_BIN=$(builddir)/arif-test