From 468bd5dc1e9d74fd32ab818c88a7cce686793b3c Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Fri, 10 Jan 2025 16:26:06 +0900 Subject: [PATCH] Reapply "ii: use C++" This reverts commit 75593f28445466bbc5f19837915457c948b24954. This didn't reduce performance. --- .pre-commit-config.yaml | 2 +- lib/c_sources.am | 1 - lib/cpp_sources.am | 1 + lib/{ii.c => ii.cpp} | 460 +++++++++++++++++++++------------------- 4 files changed, 243 insertions(+), 221 deletions(-) rename lib/{ii.c => ii.cpp} (98%) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c1a75f5a91..6b93674ace 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -120,7 +120,7 @@ repos: ?lib/grn_vector\.h| ?lib/h3\.c| ?lib/highlighter\.c| - ?lib/ii\.c| + ?lib/ii\.cpp| ?lib/index_column\.c| ?lib/language_model\.cpp| ?lib/load\.c| diff --git a/lib/c_sources.am b/lib/c_sources.am index 210d84191b..616a2961c1 100644 --- a/lib/c_sources.am +++ b/lib/c_sources.am @@ -113,7 +113,6 @@ libgroonga_c_sources = \ hash.c \ highlighter.c \ id.c \ - ii.c \ index_column.c \ index_cursor.c \ io.c \ diff --git a/lib/cpp_sources.am b/lib/cpp_sources.am index 59e18524e5..385f663b02 100644 --- a/lib/cpp_sources.am +++ b/lib/cpp_sources.am @@ -15,6 +15,7 @@ libgroonga_cpp_source = \ grn_distance_instantiation.hpp \ grn_language_model.hpp \ grn_task_executor.hpp \ + ii.cpp \ language_model.cpp \ portability.cpp \ token_column.cpp \ diff --git a/lib/ii.c b/lib/ii.cpp similarity index 98% rename from lib/ii.c rename to lib/ii.cpp index 734ea0b0a9..379d118d91 100644 --- a/lib/ii.c +++ b/lib/ii.cpp @@ -113,7 +113,7 @@ static uint32_t grn_ii_max_n_chunks_small = GRN_II_MAX_CHUNK_SMALL; static int64_t grn_ii_reduce_expire_threshold = 32; static bool grn_ii_dump_index_source_on_merge = false; -void +extern "C" void grn_ii_init_from_env(void) { { @@ -260,13 +260,13 @@ grn_ii_init_from_env(void) } } -void +extern "C" void grn_ii_cursor_set_min_enable_set(bool enable) { grn_ii_cursor_set_min_enable = enable; } -bool +extern "C" bool grn_ii_cursor_set_min_enable_get(void) { return grn_ii_cursor_set_min_enable; @@ -370,9 +370,8 @@ segment_get(grn_ctx *ctx, grn_ii *ii) if (!pseg) { uint32_t i; uint32_t pmax = 0; - char *used; const uint32_t max_segment = ii->seg->header->max_segment; - used = GRN_CALLOC(max_segment); + auto used = static_cast(GRN_CALLOC(max_segment)); if (!used) { return max_segment; } @@ -732,13 +731,13 @@ chunk_new(grn_ctx *ctx, grn_ii *ii, uint32_t *res, uint32_t size) } grn_ii_header_common *header = ii->header.common; if (header->ngarbages[m - GRN_II_W_LEAST_CHUNK] > N_GARBAGES_TH) { - grn_ii_ginfo *ginfo; uint32_t *gseg; grn_io_win iw, iw_; iw_.addr = NULL; gseg = &header->garbages[m - GRN_II_W_LEAST_CHUNK]; while (*gseg != GRN_II_PSEG_NOT_ASSIGNED) { - ginfo = WIN_MAP(ctx, ii->chunk, &iw, *gseg, 0, S_GARBAGE, GRN_IO_RDWR); + auto ginfo = static_cast( + WIN_MAP(ctx, ii->chunk, &iw, *gseg, 0, S_GARBAGE, GRN_IO_RDWR)); // GRN_IO_SEG_MAP2(ii->chunk, *gseg, ginfo); if (!ginfo) { if (iw_.addr) { @@ -855,7 +854,8 @@ chunk_free(grn_ctx *ctx, grn_ii *ii, uint32_t offset, uint32_t size) gseg = &ii->header.common->garbages[m - GRN_II_W_LEAST_CHUNK]; iw_.addr = NULL; while (*gseg != GRN_II_PSEG_NOT_ASSIGNED) { - ginfo = WIN_MAP(ctx, ii->chunk, &iw, *gseg, 0, S_GARBAGE, GRN_IO_RDWR); + ginfo = static_cast( + WIN_MAP(ctx, ii->chunk, &iw, *gseg, 0, S_GARBAGE, GRN_IO_RDWR)); // GRN_IO_SEG_MAP2(ii->chunk, *gseg, ginfo); if (!ginfo) { if (iw_.addr) { @@ -880,7 +880,8 @@ chunk_free(grn_ctx *ctx, grn_ii *ii, uint32_t offset, uint32_t size) } return rc; } - ginfo = WIN_MAP(ctx, ii->chunk, &iw, *gseg, 0, S_GARBAGE, GRN_IO_RDWR); + ginfo = static_cast( + WIN_MAP(ctx, ii->chunk, &iw, *gseg, 0, S_GARBAGE, GRN_IO_RDWR)); /* uint32_t i = 0; while (HEADER_CHUNK_AT(ii, i)) { @@ -934,7 +935,8 @@ datavec_reset( if (dv[0].data) { GRN_FREE(dv[0].data); } - if (!(dv[0].data = GRN_MALLOC(totalsize * sizeof(uint32_t)))) { + if (!(dv[0].data = static_cast( + GRN_MALLOC(totalsize * sizeof(uint32_t))))) { MERR("[ii][data-vector][reset] failed to allocate data: " "length:<%u>, " "unit-size:<%" GRN_FMT_SIZE ">, " @@ -960,7 +962,8 @@ datavec_init( if (totalsize == 0) { memset(dv, 0, sizeof(datavec) * (ii->n_elements + 1)); } else { - if (!(dv[0].data = GRN_MALLOC(totalsize * sizeof(uint32_t)))) { + if (!(dv[0].data = static_cast( + GRN_MALLOC(totalsize * sizeof(uint32_t))))) { MERR("[ii][data-vector][init] failed to allocate data: " "length:<%u>, " "unit-size:<%" GRN_FMT_SIZE ">, " @@ -2670,7 +2673,7 @@ grn_encv(grn_ctx *ctx, if (!(df = dv[0].data_size)) { return 0; } - grn_codec_data codec_data = {0}; + grn_codec_data codec_data = {}; codec_data.ii = ii; codec_data.term_id = term_id; uint32_t use_p_for_enc_flags = 0; @@ -2785,7 +2788,7 @@ grn_decv(grn_ctx *ctx, dv[0].data_size = 0; return 0; } - grn_codec_data codec_data = {0}; + grn_codec_data codec_data = {}; codec_data.ii = ii; codec_data.term_id = term_id; codec_data.offset = 0; @@ -2803,7 +2806,8 @@ grn_decv(grn_ctx *ctx, GRN_FREE(dv[0].data); dv[0].data = NULL; } - if (!(rp = GRN_MALLOC(size * sizeof(uint32_t)))) { + if (!(rp = + static_cast(GRN_MALLOC(size * sizeof(uint32_t))))) { grn_obj term; GRN_DEFINE_NAME(ii); GRN_TEXT_INIT(&term, 0); @@ -2878,7 +2882,8 @@ grn_decv(grn_ctx *ctx, GRN_FREE(dv[0].data); dv[0].data = NULL; } - if (!(rp = GRN_MALLOC(size * sizeof(uint32_t)))) { + if (!(rp = + static_cast(GRN_MALLOC(size * sizeof(uint32_t))))) { grn_obj term; GRN_DEFINE_NAME(ii); GRN_TEXT_INIT(&term, 0); @@ -2949,12 +2954,13 @@ grn_decv(grn_ctx *ctx, return rp - dv[0].data; } -int +extern "C" int grn_b_enc(grn_ctx *ctx, uint32_t *data, uint32_t data_size, uint8_t **res) { uint8_t *rp; uint32_t *dp, i; - *res = rp = GRN_MALLOC(data_size * sizeof(uint32_t) * 2); + *res = rp = + static_cast(GRN_MALLOC(data_size * sizeof(uint32_t) * 2)); GRN_B_ENC(data_size, rp); for (i = data_size, dp = data; i; i--, dp++) { GRN_B_ENC(*dp, rp); @@ -2962,13 +2968,13 @@ grn_b_enc(grn_ctx *ctx, uint32_t *data, uint32_t data_size, uint8_t **res) return rp - *res; } -int +extern "C" int grn_b_dec(grn_ctx *ctx, uint8_t *data, uint32_t data_size, uint32_t **res) { uint32_t i, *rp, orig_size; uint8_t *dp = data; GRN_B_DEC(orig_size, dp); - *res = rp = GRN_MALLOC(orig_size * sizeof(uint32_t)); + *res = rp = static_cast(GRN_MALLOC(orig_size * sizeof(uint32_t))); for (i = orig_size; i; i--, rp++) { GRN_B_DEC(*rp, dp); } @@ -3083,7 +3089,7 @@ buffer_open( const uint32_t lseg = grn_ii_pos_lseg(ii, pos); const uint32_t pseg = grn_ii_get_buffer_pseg_inline(ii, lseg); if (pseg != GRN_II_PSEG_NOT_ASSIGNED) { - byte *p = grn_io_seg_ref(ctx, ii->seg, pseg); + auto p = static_cast(grn_io_seg_ref(ctx, ii->seg, pseg)); if (!p) { return GRN_II_PSEG_NOT_ASSIGNED; } @@ -3445,7 +3451,7 @@ array_at(grn_ctx *ctx, grn_ii *ii, uint32_t id) if (pseg == GRN_II_PSEG_NOT_ASSIGNED) { return NULL; } - byte *p = grn_io_seg_ref(ctx, ii->seg, pseg); + auto p = static_cast(grn_io_seg_ref(ctx, ii->seg, pseg)); if (!p) { return NULL; } @@ -3470,7 +3476,7 @@ array_get(grn_ctx *ctx, grn_ii *ii, uint32_t id) ii->header.common->amax = seg + 1; } } - p = grn_io_seg_ref(ctx, ii->seg, pseg); + p = static_cast(grn_io_seg_ref(ctx, ii->seg, pseg)); if (!p) { return NULL; } @@ -3486,11 +3492,11 @@ array_unref(grn_ctx *ctx, grn_ii *ii, uint32_t id) /* updspec */ -grn_ii_updspec * +extern "C" grn_ii_updspec * grn_ii_updspec_open(grn_ctx *ctx, uint32_t rid, uint32_t sid) { - grn_ii_updspec *u; - if (!(u = GRN_CALLOC(sizeof(grn_ii_updspec)))) { + auto u = static_cast(GRN_CALLOC(sizeof(grn_ii_updspec))); + if (!u) { return NULL; } u->rid = rid; @@ -3504,15 +3510,15 @@ grn_ii_updspec_open(grn_ctx *ctx, uint32_t rid, uint32_t sid) return u; } -grn_rc +extern "C" grn_rc grn_ii_updspec_add(grn_ctx *ctx, grn_ii_updspec *u, int pos, int32_t weight) { - struct _grn_ii_pos *p; u->atf++; if (u->tf >= GRN_II_MAX_TF) { return GRN_SUCCESS; } - if (!(p = GRN_CALLOC(sizeof(struct _grn_ii_pos)))) { + auto p = static_cast<_grn_ii_pos *>(GRN_CALLOC(sizeof(struct _grn_ii_pos))); + if (!p) { return GRN_NO_MEMORY_AVAILABLE; } u->weight += weight; @@ -3528,7 +3534,7 @@ grn_ii_updspec_add(grn_ctx *ctx, grn_ii_updspec *u, int pos, int32_t weight) return GRN_SUCCESS; } -int +extern "C" int grn_ii_updspec_cmp(grn_ii_updspec *a, grn_ii_updspec *b) { struct _grn_ii_pos *pa, *pb; @@ -3558,7 +3564,7 @@ grn_ii_updspec_cmp(grn_ii_updspec *a, grn_ii_updspec *b) return 0; } -grn_rc +extern "C" grn_rc grn_ii_updspec_close(grn_ctx *ctx, grn_ii_updspec *u) { struct _grn_ii_pos *p = u->pos, *q; @@ -3575,7 +3581,6 @@ static inline uint8_t * encode_rec( grn_ctx *ctx, grn_ii *ii, grn_ii_updspec *u, unsigned int *size, int deletep) { - uint8_t *br, *p; struct _grn_ii_pos *pp; uint32_t lpos, tf, weight; if (deletep) { @@ -3585,10 +3590,11 @@ encode_rec( tf = u->tf; weight = u->weight; } - if (!(br = GRN_MALLOC((tf + 4) * 5))) { + auto br = static_cast(GRN_MALLOC((tf + 4) * 5)); + if (!br) { return NULL; } - p = br; + auto p = br; GRN_B_ENC(u->rid, p); if ((ii->header.common->flags & GRN_OBJ_WITH_SECTION)) { GRN_B_ENC(u->sid, p); @@ -3669,7 +3675,7 @@ typedef struct { uint32_t flags; } docinfo; -static docinfo null_docinfo = {0}; +static docinfo null_docinfo = {}; typedef struct { uint32_t segno; @@ -3943,14 +3949,13 @@ merge_dump_source_chunk(grn_ctx *ctx, merge_dump_source_data *data) } { grn_io_win iw; - uint8_t *sub_chunk; - sub_chunk = WIN_MAP(ctx, - data->ii->chunk, - &iw, - info.segno, - 0, - info.size, - GRN_IO_RDONLY); + auto sub_chunk = static_cast(WIN_MAP(ctx, + data->ii->chunk, + &iw, + info.segno, + 0, + info.size, + GRN_IO_RDONLY)); if (!sub_chunk) { GRN_LOG(ctx, data->log_level, @@ -4609,13 +4614,14 @@ static grn_rc chunk_flush( grn_ctx *ctx, grn_ii *ii, chunk_info *cinfo, uint8_t *enc, uint32_t encsize) { - uint8_t *dc; uint32_t dcn; grn_io_win dw; if (encsize) { chunk_new(ctx, ii, &dcn, encsize); if (ctx->rc == GRN_SUCCESS) { - if ((dc = WIN_MAP(ctx, ii->chunk, &dw, dcn, 0, encsize, GRN_IO_WRONLY))) { + auto dc = static_cast( + WIN_MAP(ctx, ii->chunk, &dw, dcn, 0, encsize, GRN_IO_WRONLY)); + if (dc) { grn_memcpy(dc, enc, encsize); grn_io_win_unmap(ctx, &dw); cinfo->segno = dcn; @@ -4657,8 +4663,8 @@ chunk_merge(grn_ctx *ctx, uint32_t segno = cinfo->segno; uint32_t size = cinfo->size; uint32_t ndf = 0; - const uint8_t *scp = - WIN_MAP(ctx, ii->chunk, &sw, segno, 0, size, GRN_IO_RDONLY); + auto scp = static_cast( + WIN_MAP(ctx, ii->chunk, &sw, segno, 0, size, GRN_IO_RDONLY)); datavec rdv[MAX_N_ELEMENTS + 1]; size_t bufsize = S_SEGMENT * ii->n_elements; @@ -4843,7 +4849,7 @@ chunk_merge(grn_ctx *ctx, if (encsize_estimated == 0) { chunk_flush(ctx, ii, cinfo, NULL, 0); } else { - uint8_t *enc = GRN_MALLOC(encsize_estimated); + auto enc = static_cast(GRN_MALLOC(encsize_estimated)); if (!enc) { grn_obj term; GRN_DEFINE_NAME(ii); @@ -4994,7 +5000,7 @@ buffer_merge_ensure_dc(grn_ctx *ctx, while (required_size > (new_dc_size - dc_used_size)) { new_dc_size *= 2; } - uint8_t *new_dc = GRN_REALLOC(*dc, new_dc_size); + auto new_dc = static_cast(GRN_REALLOC(*dc, new_dc_size)); if (new_dc) { GRN_DEFINE_NAME(ii); GRN_LOG(ctx, @@ -5040,7 +5046,6 @@ buffer_merge_internal(grn_ctx *ctx, grn_merging_data *merging_data) { buffer_term *bt; - uint8_t *dc = NULL; uint8_t *dcp = NULL; datavec dv[MAX_N_ELEMENTS + 1]; datavec rdv[MAX_N_ELEMENTS + 1]; @@ -5077,7 +5082,7 @@ buffer_merge_internal(grn_ctx *ctx, } size_t dc_size = (sb->header.chunk_size + S_SEGMENT) * 2; - dc = GRN_MALLOC(dc_size); + auto dc = static_cast(GRN_MALLOC(dc_size)); if (!dc) { grn_rc rc = ctx->rc; if (rc == GRN_SUCCESS) { @@ -5095,7 +5100,7 @@ buffer_merge_internal(grn_ctx *ctx, dcp = dc; for (bt = db->terms; n; n--, bt++) { - merger_data data = {0}; + merger_data data = {}; merger_buffer_data *buffer_data = &(data.source.buffer); merger_chunk_data *chunk_data = &(data.source.chunk); int32_t balance = 0; @@ -5611,7 +5616,7 @@ static inline grn_rc buffer_flush_internal(grn_ctx *ctx, grn_ii *ii, uint32_t lseg, grn_hash *h) { grn_io_win sw, dw; - buffer *sb, *db = NULL; + buffer *sb; uint32_t ds, pseg, scn, dcn = 0; if (grn_ii_get_buffer_pseg_inline(ii, lseg) == GRN_II_PSEG_NOT_ASSIGNED) { GRN_DEFINE_NAME(ii); @@ -5662,17 +5667,17 @@ buffer_flush_internal(grn_ctx *ctx, grn_ii *ii, uint32_t lseg, grn_hash *h) return ctx->rc; } { - db = grn_io_seg_ref(ctx, ii->seg, ds); + auto db = static_cast(grn_io_seg_ref(ctx, ii->seg, ds)); if (db) { const uint8_t *sc = NULL; if ((scn = sb->header.chunk) == GRN_II_PSEG_NOT_ASSIGNED || - (sc = WIN_MAP(ctx, - ii->chunk, - &sw, - scn, - 0, - sb->header.chunk_size, - GRN_IO_RDONLY))) { + (sc = static_cast(WIN_MAP(ctx, + ii->chunk, + &sw, + scn, + 0, + sb->header.chunk_size, + GRN_IO_RDONLY)))) { uint16_t n = sb->header.nterms; memset(db, 0, S_SEGMENT); grn_memcpy(db->terms, sb->terms, n * sizeof(buffer_term)); @@ -5781,7 +5786,7 @@ buffer_flush(grn_ctx *ctx, grn_ii *ii, uint32_t lseg, grn_hash *h) return rc; } -void +extern "C" void grn_ii_buffer_check(grn_ctx *ctx, grn_ii *ii, uint32_t lseg) { grn_io_win sw; @@ -5817,13 +5822,13 @@ grn_ii_buffer_check(grn_ctx *ctx, grn_ii *ii, uint32_t lseg) GRN_OUTPUT_CSTR("void chunk size"); GRN_OUTPUT_INT64(sb->header.chunk_size); } else { - if ((sc = WIN_MAP(ctx, - ii->chunk, - &sw, - scn, - 0, - sb->header.chunk_size, - GRN_IO_RDONLY))) { + if ((sc = static_cast(WIN_MAP(ctx, + ii->chunk, + &sw, + scn, + 0, + sb->header.chunk_size, + GRN_IO_RDONLY)))) { GRN_OUTPUT_CSTR("chunk size"); GRN_OUTPUT_INT64(sb->header.chunk_size); } else { @@ -5842,7 +5847,7 @@ grn_ii_buffer_check(grn_ctx *ctx, grn_ii *ii, uint32_t lseg) uint32_t nchunks = 0; chunk_info *cinfo = NULL; grn_id crid = GRN_ID_NIL; - merger_data data = {0}; + merger_data data = {}; merger_chunk_data *chunk_data = &(data.source.chunk); if (!bt->tid && !bt->pos_in_buffer && !bt->size_in_buffer) { @@ -6013,7 +6018,8 @@ term_split(grn_ctx *ctx, grn_obj *lexicon, buffer *sb, buffer *db0, buffer *db1) uint16_t i, n, *nt; buffer_term *bt; uint32_t s, th = (sb->header.chunk_size + sb->header.nterms) >> 1; - term_sort *ts = GRN_MALLOC(sb->header.nterms * sizeof(term_sort)); + auto ts = + static_cast(GRN_MALLOC(sb->header.nterms * sizeof(term_sort))); if (!ts) { return GRN_NO_MEMORY_AVAILABLE; } @@ -6114,19 +6120,19 @@ buffer_split_internal(grn_ctx *ctx, grn_ii *ii, uint32_t lseg, grn_hash *h) grn_ii_pos_pack(ii, lseg, 0), ii->seg->header->max_segment); } else { - db0 = grn_io_seg_ref(ctx, ii->seg, dps0); + db0 = static_cast(grn_io_seg_ref(ctx, ii->seg, dps0)); if (db0) { - db1 = grn_io_seg_ref(ctx, ii->seg, dps1); + db1 = static_cast(grn_io_seg_ref(ctx, ii->seg, dps1)); if (db1) { const uint8_t *sc = NULL; if ((scn = sb->header.chunk) == GRN_II_PSEG_NOT_ASSIGNED || - (sc = WIN_MAP(ctx, - ii->chunk, - &sw, - scn, - 0, - sb->header.chunk_size, - GRN_IO_RDONLY))) { + (sc = static_cast(WIN_MAP(ctx, + ii->chunk, + &sw, + scn, + 0, + sb->header.chunk_size, + GRN_IO_RDONLY)))) { term_split(ctx, ii->lexicon, sb, db0, db1); uint8_t *dc0 = NULL; grn_merging_data merging_data; @@ -6716,7 +6722,7 @@ _grn_ii_create( grn_io_remove(ctx, path); return NULL; } - header = grn_io_header(seg); + header = static_cast(grn_io_header(seg)); grn_io_set_type(seg, GRN_COLUMN_INDEX); for (i = 0; i < GRN_II_MAX_LSEG; i++) { header->ainfo[i] = GRN_II_PSEG_NOT_ASSIGNED; @@ -6754,11 +6760,11 @@ _grn_ii_create( return ii; } -grn_ii * +extern "C" grn_ii * grn_ii_create(grn_ctx *ctx, const char *path, grn_obj *lexicon, uint32_t flags) { - grn_ii *ii = NULL; - if (!(ii = GRN_CALLOC(sizeof(grn_ii)))) { + auto ii = static_cast(GRN_CALLOC(sizeof(grn_ii))); + if (!ii) { return NULL; } GRN_DB_OBJ_SET_TYPE(ii, GRN_COLUMN_INDEX); @@ -6769,7 +6775,7 @@ grn_ii_create(grn_ctx *ctx, const char *path, grn_obj *lexicon, uint32_t flags) return ii; } -grn_rc +extern "C" grn_rc grn_ii_remove(grn_ctx *ctx, const char *path) { grn_rc rc; @@ -6790,7 +6796,7 @@ grn_ii_remove(grn_ctx *ctx, const char *path) return rc; } -grn_rc +extern "C" grn_rc grn_ii_truncate(grn_ctx *ctx, grn_ii *ii) { grn_rc rc; @@ -6831,11 +6837,10 @@ grn_ii_truncate(grn_ctx *ctx, grn_ii *ii) return rc; } -grn_ii * +extern "C" grn_ii * grn_ii_open(grn_ctx *ctx, const char *path, grn_obj *lexicon) { grn_io *seg, *chunk; - grn_ii *ii; char path2[PATH_MAX]; grn_ii_header_common *header; uint32_t io_type; @@ -6865,7 +6870,7 @@ grn_ii_open(grn_ctx *ctx, const char *path, grn_obj *lexicon) grn_io_close(ctx, seg); return NULL; } - header = grn_io_header(seg); + header = static_cast(grn_io_header(seg)); io_type = grn_io_get_type(seg); if (io_type != GRN_COLUMN_INDEX) { ERR(GRN_INVALID_FORMAT, @@ -6876,7 +6881,8 @@ grn_ii_open(grn_ctx *ctx, const char *path, grn_obj *lexicon) grn_io_close(ctx, chunk); return NULL; } - if (!(ii = GRN_CALLOC(sizeof(grn_ii)))) { + auto ii = static_cast(GRN_CALLOC(sizeof(grn_ii))); + if (!ii) { grn_io_close(ctx, seg); grn_io_close(ctx, chunk); return NULL; @@ -6902,7 +6908,7 @@ grn_ii_open(grn_ctx *ctx, const char *path, grn_obj *lexicon) return ii; } -grn_rc +extern "C" grn_rc grn_ii_close(grn_ctx *ctx, grn_ii *ii) { grn_rc rc = GRN_SUCCESS; @@ -6940,7 +6946,7 @@ grn_ii_close(grn_ctx *ctx, grn_ii *ii) return rc; } -grn_rc +extern "C" grn_rc grn_ii_info(grn_ctx *ctx, grn_ii *ii, uint64_t *seg_size, uint64_t *chunk_size) { grn_rc rc; @@ -6960,7 +6966,7 @@ grn_ii_info(grn_ctx *ctx, grn_ii *ii, uint64_t *seg_size, uint64_t *chunk_size) return GRN_SUCCESS; } -grn_column_flags +extern "C" grn_column_flags grn_ii_get_flags(grn_ctx *ctx, grn_ii *ii) { if (!ii) { @@ -6970,7 +6976,7 @@ grn_ii_get_flags(grn_ctx *ctx, grn_ii *ii) return ii->header.common->flags; } -uint32_t +extern "C" uint32_t grn_ii_get_n_elements(grn_ctx *ctx, grn_ii *ii) { if (!ii) { @@ -6980,7 +6986,7 @@ grn_ii_get_n_elements(grn_ctx *ctx, grn_ii *ii) return ii->n_elements; } -grn_obj * +extern "C" grn_obj * grn_ii_get_lexicon(grn_ctx *ctx, grn_ii *ii) { if (!ii) { @@ -6990,7 +6996,7 @@ grn_ii_get_lexicon(grn_ctx *ctx, grn_ii *ii) return ii->lexicon; } -void +extern "C" void grn_ii_expire(grn_ctx *ctx, grn_ii *ii) { int64_t threshold = ii->chunk->max_map_seg / 2; @@ -7006,7 +7012,7 @@ grn_ii_expire(grn_ctx *ctx, grn_ii *ii) } } -grn_rc +extern "C" grn_rc grn_ii_flush(grn_ctx *ctx, grn_ii *ii) { grn_rc rc; @@ -7023,7 +7029,7 @@ grn_ii_flush(grn_ctx *ctx, grn_ii *ii) return rc; } -size_t +extern "C" size_t grn_ii_get_disk_usage(grn_ctx *ctx, grn_ii *ii) { size_t usage; @@ -7034,7 +7040,7 @@ grn_ii_get_disk_usage(grn_ctx *ctx, grn_ii *ii) return usage; } -void +extern "C" void grn_ii_set_visibility(grn_ctx *ctx, grn_ii *ii, bool is_visible) { if (is_visible) { @@ -7523,7 +7529,7 @@ grn_ii_update_one_internal( return ctx->rc; } -grn_rc +extern "C" grn_rc grn_ii_update_one( grn_ctx *ctx, grn_ii *ii, grn_id tid, grn_ii_updspec *u, grn_hash *h) { @@ -7764,7 +7770,7 @@ grn_ii_delete_one_internal( return ctx->rc; } -grn_rc +extern "C" grn_rc grn_ii_delete_one( grn_ctx *ctx, grn_ii *ii, grn_id tid, grn_ii_updspec *u, grn_hash *h) { @@ -7889,8 +7895,8 @@ chunk_is_reused( gseg = ii->header.common->garbages[m - GRN_II_W_LEAST_CHUNK]; while (gseg != GRN_II_PSEG_NOT_ASSIGNED) { grn_io_win iw; - grn_ii_ginfo *ginfo = - WIN_MAP(ctx, ii->chunk, &iw, gseg, 0, S_GARBAGE, GRN_IO_RDWR); + auto ginfo = static_cast( + WIN_MAP(ctx, ii->chunk, &iw, gseg, 0, S_GARBAGE, GRN_IO_RDWR)); if (!ginfo) { break; } @@ -7915,7 +7921,7 @@ chunk_is_reused( (((c1)->post->sid == (c2)->post->sid) && \ ((c1)->post->pos > (c2)->post->pos))))) -grn_ii_cursor * +extern "C" grn_ii_cursor * grn_ii_cursor_open(grn_ctx *ctx, grn_ii *ii, grn_id tid, @@ -7934,7 +7940,8 @@ grn_ii_cursor_open(grn_ctx *ctx, if (!(pos = a[0])) { goto exit; } - if (!(c = GRN_CALLOC(sizeof(grn_ii_cursor)))) { + c = static_cast(GRN_CALLOC(sizeof(grn_ii_cursor))); + if (!c) { goto exit; } c->ctx = ctx; @@ -7976,13 +7983,13 @@ grn_ii_cursor_open(grn_ctx *ctx, c->ppseg = grn_ii_get_buffer_pseg_address_inline(ii, lseg); if (bt->size_in_chunk && (chunk = c->buf->header.chunk) != GRN_II_PSEG_NOT_ASSIGNED) { - if (!(c->cp = WIN_MAP(ctx, - ii->chunk, - &c->iw, - chunk, - bt->pos_in_chunk, - bt->size_in_chunk, - GRN_IO_RDONLY))) { + if (!(c->cp = static_cast(WIN_MAP(ctx, + ii->chunk, + &c->iw, + chunk, + bt->pos_in_chunk, + bt->size_in_chunk, + GRN_IO_RDONLY)))) { buffer_close(ctx, ii, c->buffer_pseg); GRN_FREE(c); c = NULL; @@ -8037,7 +8044,7 @@ grn_ii_cursor_open(grn_ctx *ctx, return c; } -grn_ii * +extern "C" grn_ii * grn_ii_cursor_get_ii(grn_ctx *ctx, grn_ii_cursor *cursor) { return cursor->ii; @@ -8059,7 +8066,7 @@ grn_ii_cursor_resolve_scale(grn_ctx *ctx, } } -grn_rc +extern "C" grn_rc grn_ii_cursor_set_scale(grn_ctx *ctx, grn_ii_cursor *cursor, float scale) { cursor->scale = scale; @@ -8071,7 +8078,7 @@ grn_ii_cursor_set_scale(grn_ctx *ctx, grn_ii_cursor *cursor, float scale) return ctx->rc; } -grn_rc +extern "C" grn_rc grn_ii_cursor_set_scales(grn_ctx *ctx, grn_ii_cursor *cursor, float *scales, @@ -8310,13 +8317,14 @@ grn_ii_cursor_next_internal(grn_ctx *ctx, uint8_t *cp; grn_io_win iw; uint32_t size = c->cinfo[c->curr_chunk].size; - if (size && (cp = WIN_MAP(ctx, - c->ii->chunk, - &iw, - c->cinfo[c->curr_chunk].segno, - 0, - size, - GRN_IO_RDONLY))) { + if (size && (cp = static_cast( + WIN_MAP(ctx, + c->ii->chunk, + &iw, + c->cinfo[c->curr_chunk].segno, + 0, + size, + GRN_IO_RDONLY)))) { int decoded_size; decoded_size = grn_decv(ctx, c->ii, c->id, cp, size, c->rdv); grn_io_win_unmap(ctx, &iw); @@ -8597,14 +8605,14 @@ grn_ii_cursor_next_internal(grn_ctx *ctx, return c->post; } -grn_posting * +extern "C" grn_posting * grn_ii_cursor_next(grn_ctx *ctx, grn_ii_cursor *c) { grn_ii_cursor_next_options options = {/* .include_garbage = */ false}; return grn_ii_cursor_next_internal(ctx, c, &options); } -grn_posting * +extern "C" grn_posting * grn_ii_cursor_next_pos(grn_ctx *ctx, grn_ii_cursor *c) { uint32_t gap; @@ -8667,7 +8675,7 @@ grn_ii_cursor_next_pos(grn_ctx *ctx, grn_ii_cursor *c) return c->post; } -grn_rc +extern "C" grn_rc grn_ii_cursor_close(grn_ctx *ctx, grn_ii_cursor *c) { if (!c) { @@ -8687,7 +8695,7 @@ grn_ii_cursor_close(grn_ctx *ctx, grn_ii_cursor *c) return GRN_SUCCESS; } -uint32_t +extern "C" uint32_t grn_ii_get_chunksize(grn_ctx *ctx, grn_ii *ii, grn_id tid) { uint32_t res, pos, *a; @@ -8722,7 +8730,7 @@ grn_ii_get_chunksize(grn_ctx *ctx, grn_ii *ii, grn_id tid) * have deleted tokens. One record may use multiple buffers. (To be * confirmed.) So the estimated size may not match the number of * records. */ -uint32_t +extern "C" uint32_t grn_ii_estimate_size(grn_ctx *ctx, grn_ii *ii, grn_id tid) { uint32_t res, pos, *a; @@ -8752,7 +8760,7 @@ grn_ii_estimate_size(grn_ctx *ctx, grn_ii *ii, grn_id tid) return res; } -int +extern "C" int grn_ii_entry_info(grn_ctx *ctx, grn_ii *ii, grn_id tid, @@ -8801,31 +8809,31 @@ grn_ii_entry_info(grn_ctx *ctx, return 4; } -uint32_t +extern "C" uint32_t grn_ii_get_array_pseg(grn_ii *ii, uint32_t lseg) { return grn_ii_get_array_pseg_inline(ii, lseg); } -uint32_t +extern "C" uint32_t grn_ii_get_buffer_pseg(grn_ii *ii, uint32_t lseg) { return grn_ii_get_buffer_pseg_inline(ii, lseg); } -uint32_t +extern "C" uint32_t grn_ii_n_logical_segments(grn_ii *ii) { return grn_ii_n_logical_segments_inline(ii); } -const char * +extern "C" const char * grn_ii_path(grn_ii *ii) { return grn_io_path(ii->seg); } -uint32_t +extern "C" uint32_t grn_ii_max_section(grn_ii *ii) { return ii->header.common->smax; @@ -8841,7 +8849,7 @@ typedef struct { grn_ii_cursor **bins; } cursor_heap; -void +extern "C" void grn_inspect_cursor_heap(grn_ctx *ctx, grn_obj *buffer, cursor_heap *heap) { grn_text_printf(ctx, @@ -8862,11 +8870,12 @@ grn_inspect_cursor_heap(grn_ctx *ctx, grn_obj *buffer, cursor_heap *heap) static inline cursor_heap * cursor_heap_open(grn_ctx *ctx, int max) { - cursor_heap *h = GRN_CALLOC(sizeof(cursor_heap)); + auto h = static_cast(GRN_CALLOC(sizeof(cursor_heap))); if (!h) { return NULL; } - h->bins = GRN_MALLOC(sizeof(grn_ii_cursor *) * max); + h->bins = + static_cast(GRN_MALLOC(sizeof(grn_ii_cursor *) * max)); if (!h->bins) { GRN_FREE(h); return NULL; @@ -8889,7 +8898,8 @@ cursor_heap_push(grn_ctx *ctx, grn_ii_cursor *c, *c2; if (h->n_entries >= h->n_bins) { int max = h->n_bins * 2; - grn_ii_cursor **bins = GRN_REALLOC(h->bins, sizeof(grn_ii_cursor *) * max); + auto bins = static_cast( + GRN_REALLOC(h->bins, sizeof(grn_ii_cursor *) * max)); GRN_LOG(ctx, GRN_LOG_DEBUG, "expanded cursor_heap to %d,%p", max, bins); if (!bins) { return GRN_NO_MEMORY_AVAILABLE; @@ -9846,7 +9856,7 @@ grn_ii_column_update_internal(grn_ctx *ctx, return ctx->rc; } -grn_rc +extern "C" grn_rc grn_ii_column_update(grn_ctx *ctx, grn_ii *ii, grn_id rid, @@ -9931,7 +9941,7 @@ typedef struct { bool must_last; } token_info; -void +extern "C" void grn_inspect_token_info(grn_ctx *ctx, grn_obj *buffer, token_info *info) { grn_text_printf(ctx, buffer, "#"); } -void +extern "C" void grn_p_token_info(grn_ctx *ctx, token_info *info) { grn_obj inspected; @@ -9982,7 +9992,7 @@ grn_p_token_info(grn_ctx *ctx, token_info *info) GRN_OBJ_FIN(ctx, &inspected); } -void +extern "C" void grn_inspect_token_infos(grn_ctx *ctx, grn_obj *buffer, token_info **infos, @@ -9998,7 +10008,7 @@ grn_inspect_token_infos(grn_ctx *ctx, } } -void +extern "C" void grn_p_token_infos(grn_ctx *ctx, token_info **infos, uint32_t n) { grn_obj inspected; @@ -10237,12 +10247,12 @@ token_info_open(grn_ctx *ctx, { uint32_t s = 0; grn_hash *h; - token_info *ti; grn_id *tp; if (tid == GRN_ID_NIL && !key) { return NULL; } - if (!(ti = GRN_CALLOC(sizeof(token_info)))) { + auto ti = static_cast(GRN_CALLOC(sizeof(token_info))); + if (!ti) { return NULL; } ti->cursors = NULL; @@ -10576,8 +10586,8 @@ token_candidate_init(grn_ctx *ctx, { data->select_data = select_data; size_t size = TOKEN_CANDIDATE_NODE_SIZE; - data->nodes = - GRN_MALLOC(TOKEN_CANDIDATE_NODE_SIZE * sizeof(token_candidate_node)); + data->nodes = static_cast( + GRN_MALLOC(TOKEN_CANDIDATE_NODE_SIZE * sizeof(token_candidate_node))); if (!data->nodes) { return GRN_NO_MEMORY_AVAILABLE; } @@ -10616,10 +10626,10 @@ token_candidate_init(grn_ctx *ctx, while (token_cursor->status == GRN_TOKEN_CURSOR_DOING) { if ((size_t)(curr - top) >= size) { - token_candidate_node *nodes = + auto nodes = static_cast( GRN_REALLOC(data->nodes, (curr - top + TOKEN_CANDIDATE_NODE_SIZE) * - sizeof(token_candidate_node)); + sizeof(token_candidate_node))); if (!nodes) { GRN_FREE(data->nodes); data->nodes = NULL; @@ -10656,7 +10666,8 @@ token_candidate_queue_init(grn_ctx *ctx, token_candidate_queue *q) q->rear = 0; q->size = TOKEN_CANDIDATE_QUEUE_SIZE; - q->candidates = GRN_MALLOC(TOKEN_CANDIDATE_QUEUE_SIZE * sizeof(uint32_t)); + q->candidates = static_cast( + GRN_MALLOC(TOKEN_CANDIDATE_QUEUE_SIZE * sizeof(uint32_t))); if (!q->candidates) { q->size = 0; return GRN_NO_MEMORY_AVAILABLE; @@ -10670,9 +10681,9 @@ token_candidate_enqueue(grn_ctx *ctx, uint32_t candidate) { if (q->rear >= q->size) { - if (!(q->candidates = GRN_REALLOC(q->candidates, - (q->rear + TOKEN_CANDIDATE_QUEUE_SIZE) * - sizeof(uint32_t)))) { + if (!(q->candidates = static_cast(GRN_REALLOC( + q->candidates, + (q->rear + TOKEN_CANDIDATE_QUEUE_SIZE) * sizeof(uint32_t))))) { q->size = 0; return GRN_NO_MEMORY_AVAILABLE; } @@ -10747,13 +10758,13 @@ token_candidate_select(grn_ctx *ctx, if (rc != GRN_SUCCESS) { return rc; } + uint32_t candidate; + uint64_t max_score = 0; + uint32_t min_n_nodes = 0; rc = token_candidate_enqueue(ctx, &q, 1); if (rc != GRN_SUCCESS) { goto exit; } - uint32_t candidate; - uint64_t max_score = 0; - uint32_t min_n_nodes = 0; while (token_candidate_dequeue(ctx, &q, &candidate) != GRN_END_OF_DATA) { token_candidate_node *candidate_last_node = token_candidate_last_node(ctx, data, candidate, offset); @@ -10812,20 +10823,21 @@ token_candidate_build(grn_ctx *ctx, token_candidate_data *data, int offset) ti = token_info_open(ctx, data->select_data, node->tid, - node->source_token, + reinterpret_cast(node->source_token), node->source_token_size, node->pos, EX_NONE); break; case GRN_TOKEN_CURSOR_DONE: if (node->tid != GRN_ID_NIL) { - ti = token_info_open(ctx, - data->select_data, - node->tid, - (const char *)(node->source_token), - node->source_token_size, - node->pos, - node->ef & EX_PREFIX); + ti = + token_info_open(ctx, + data->select_data, + node->tid, + reinterpret_cast(node->source_token), + node->source_token_size, + node->pos, + node->ef & EX_PREFIX); break; } /* else fallthru */ default: @@ -10943,7 +10955,7 @@ token_info_build_phrase(grn_ctx *ctx, goto exit; } token = grn_token_cursor_get_token(ctx, token_cursor); - const char *key = NULL; + const unsigned char *key = NULL; uint32_t size = 0; if (tid == GRN_ID_NIL) { key = token_cursor->orig; @@ -10963,14 +10975,20 @@ token_info_build_phrase(grn_ctx *ctx, ti = token_info_open(ctx, data, tid, - key, + reinterpret_cast(key), size, token_cursor->pos, ef & EX_SUFFIX); break; case GRN_TOKEN_CURSOR_DONE: case GRN_TOKEN_CURSOR_NOT_FOUND: - ti = token_info_open(ctx, data, tid, key, size, 0, ef); + ti = token_info_open(ctx, + data, + tid, + reinterpret_cast(key), + size, + 0, + ef); break; case GRN_TOKEN_CURSOR_DONE_SKIP: data->only_skip_token = true; @@ -10992,7 +11010,7 @@ token_info_build_phrase(grn_ctx *ctx, grn_token *token; tid = grn_token_cursor_next(ctx, token_cursor); token = grn_token_cursor_get_token(ctx, token_cursor); - const char *key = NULL; + const unsigned char *key = NULL; uint32_t size = 0; if (tid == GRN_ID_NIL) { key = token_cursor->curr; @@ -11014,7 +11032,7 @@ token_info_build_phrase(grn_ctx *ctx, ti = token_info_open(ctx, data, tid, - key, + reinterpret_cast(key), size, token_cursor->pos, EX_NONE); @@ -11023,7 +11041,7 @@ token_info_build_phrase(grn_ctx *ctx, ti = token_info_open(ctx, data, tid, - key, + reinterpret_cast(key), size, token_cursor->pos, ef & EX_PREFIX); @@ -11104,7 +11122,7 @@ token_info_build_fuzzy(grn_ctx *ctx, grn_ii_select_data *data) data->token_infos[data->n_token_infos++] = ti; while (token_cursor->status == GRN_TOKEN_CURSOR_DOING) { tid = grn_token_cursor_next(ctx, token_cursor); - const char *key = NULL; + const unsigned char *key = NULL; uint32_t key_size = 0; if (tid == GRN_ID_NIL) { key = token_cursor->curr; @@ -11124,7 +11142,7 @@ token_info_build_fuzzy(grn_ctx *ctx, grn_ii_select_data *data) ti = token_info_open(ctx, data, tid, - key, + reinterpret_cast(key), key_size, token_cursor->pos, EX_FUZZY); @@ -11527,10 +11545,11 @@ bt_zap(btr *bt) static inline btr * bt_open(grn_ctx *ctx, int size) { - btr *bt = GRN_CALLOC(sizeof(btr)); + auto bt = static_cast(GRN_CALLOC(sizeof(btr))); if (bt) { bt_zap(bt); - if (!(bt->nodes = GRN_MALLOC(sizeof(btr_node) * size))) { + bt->nodes = static_cast(GRN_MALLOC(sizeof(btr_node) * size)); + if (!bt->nodes) { GRN_FREE(bt); bt = NULL; } @@ -11743,7 +11762,7 @@ grn_rset_add_record(grn_ctx *ctx, * example, we can stop min ID search when we find an ID that is less * than grn_table_size(ctx, grn_ctx_at(ctx, * result_set->header.domain))/100. */ -grn_id +extern "C" grn_id grn_result_set_get_min_id(grn_ctx *ctx, grn_hash *result_set) { GRN_API_ENTER; @@ -11767,7 +11786,7 @@ grn_result_set_get_min_id(grn_ctx *ctx, grn_hash *result_set) GRN_API_RETURN(min_id); } -grn_rc +extern "C" grn_rc grn_result_set_add_record(grn_ctx *ctx, grn_hash *result_set, grn_posting *posting, @@ -11782,7 +11801,7 @@ grn_result_set_add_record(grn_ctx *ctx, GRN_API_RETURN(ctx->rc); } -grn_rc +extern "C" grn_rc grn_result_set_add_table(grn_ctx *ctx, grn_hash *result_set, grn_obj *table, @@ -11800,7 +11819,7 @@ grn_result_set_add_table(grn_ctx *ctx, GRN_API_RETURN(ctx->rc); } -grn_rc +extern "C" grn_rc grn_result_set_add_table_cursor(grn_ctx *ctx, grn_hash *result_set, grn_table_cursor *cursor, @@ -11832,7 +11851,7 @@ grn_result_set_add_table_cursor(grn_ctx *ctx, if (op == GRN_OP_OR || op == GRN_OP_AND) { rc = grn_hash_add_table_cursor(ctx, result_set, cursor, score, op); } else { - grn_rset_posinfo posinfo = {0}; + grn_rset_posinfo posinfo = {}; while ((posinfo.rid = grn_table_cursor_next(ctx, cursor))) { grn_rset_add_record(ctx, result_set, &posinfo, score, op); if (ctx->rc != GRN_SUCCESS) { @@ -11844,7 +11863,7 @@ grn_result_set_add_table_cursor(grn_ctx *ctx, GRN_API_RETURN(rc); } -grn_rc +extern "C" grn_rc grn_result_set_add_index_cursor(grn_ctx *ctx, grn_hash *result_set, grn_obj *cursor, @@ -11904,7 +11923,7 @@ grn_result_set_add_index_cursor(grn_ctx *ctx, GRN_API_RETURN(rc); } -grn_rc +extern "C" grn_rc grn_result_set_add_ii_cursor(grn_ctx *ctx, grn_hash *result_set, grn_ii_cursor *cursor, @@ -11963,7 +11982,7 @@ grn_result_set_add_ii_cursor(grn_ctx *ctx, GRN_API_RETURN(rc); } -grn_rc +extern "C" grn_rc grn_result_set_add_ii_select_cursor(grn_ctx *ctx, grn_hash *result_set, grn_ii_select_cursor *cursor, @@ -12012,7 +12031,7 @@ grn_result_set_add_ii_select_cursor(grn_ctx *ctx, GRN_API_RETURN(rc); } -grn_rc +extern "C" grn_rc grn_result_set_copy(grn_ctx *ctx, grn_hash *result_set, grn_hash *output_result_set) @@ -12039,8 +12058,8 @@ grn_result_set_copy(grn_ctx *ctx, break; } } - grn_rset_recinfo *ri = value; - grn_rset_recinfo *output_ri = output_value; + grn_rset_recinfo *ri = static_cast(value); + grn_rset_recinfo *output_ri = static_cast(output_value); grn_memcpy(output_ri, ri, (output_result_set)->value_size); output_ri->score = 0; } @@ -12059,14 +12078,14 @@ res_add(grn_ctx *ctx, grn_rset_add_record(ctx, s, pi, score, op); } -grn_rc +extern "C" grn_rc grn_ii_posting_add(grn_ctx *ctx, grn_posting *pos, grn_hash *s, grn_operator op) { grn_rset_add_record(ctx, s, (grn_rset_posinfo *)(pos), pos->weight, op); return ctx->rc; } -grn_rc +extern "C" grn_rc grn_ii_posting_add_float(grn_ctx *ctx, grn_posting *pos, grn_hash *s, @@ -12207,7 +12226,8 @@ grn_ii_select_data_init_token_infos(grn_ctx *ctx, return false; } - data->token_infos = GRN_MALLOC(sizeof(token_info *) * data->query_len * 2); + data->token_infos = static_cast( + GRN_MALLOC(sizeof(token_info *) * data->query_len * 2)); if (!data->token_infos) { char errbuf[GRN_CTX_MSGSIZE]; grn_strcpy(errbuf, GRN_CTX_MSGSIZE, ctx->errbuf); @@ -12245,8 +12265,8 @@ grn_ii_select_data_init_token_infos(grn_ctx *ctx, if (data->mode == GRN_OP_NEAR_PHRASE_PRODUCT || data->mode == GRN_OP_ORDERED_NEAR_PHRASE_PRODUCT) { - data->phrase_groups = - GRN_MALLOC(sizeof(phrase_group) * data->n_phrase_groups); + data->phrase_groups = static_cast( + GRN_MALLOC(sizeof(phrase_group) * data->n_phrase_groups)); if (!data->phrase_groups) { return false; } @@ -12553,7 +12573,7 @@ grn_ii_similar_search_internal(grn_ctx *ctx, grn_ii_select_data *data) return rc; } -grn_rc +extern "C" grn_rc grn_ii_similar_search(grn_ctx *ctx, grn_ii *ii, const char *string, @@ -12675,7 +12695,7 @@ grn_ii_term_extract_internal(grn_ctx *ctx, grn_ii_select_data *data) return rc; } -grn_rc +extern "C" grn_rc grn_ii_term_extract(grn_ctx *ctx, grn_ii *ii, const char *string, @@ -12739,7 +12759,8 @@ grn_ii_select_cursor_open(grn_ctx *ctx, return NULL; } - grn_ii_select_cursor *cursor = GRN_CALLOC(sizeof(grn_ii_select_cursor)); + auto cursor = static_cast( + GRN_CALLOC(sizeof(grn_ii_select_cursor))); if (!cursor) { char errbuf[GRN_CTX_MSGSIZE]; grn_strcpy(errbuf, GRN_CTX_MSGSIZE, ctx->errbuf); @@ -13522,7 +13543,7 @@ grn_ii_select_cursor_next_find(grn_ctx *ctx, return true; } -grn_ii_select_cursor_posting * +extern "C" grn_ii_select_cursor_posting * grn_ii_select_cursor_next(grn_ctx *ctx, grn_ii_select_cursor *cursor) { const char *tag = "[ii][select][cursor][next]"; @@ -13656,7 +13677,7 @@ grn_ii_select_cursor_unshift(grn_ctx *ctx, cursor->have_unshifted_posting = true; } -grn_ii * +extern "C" grn_ii * grn_ii_select_cursor_get_ii(grn_ctx *ctx, grn_ii_select_cursor *cursor) { return cursor->data.ii; @@ -13885,10 +13906,10 @@ grn_ii_select_regexp(grn_ctx *ctx, grn_ii_select(ctx, ii, parsed_string, parsed_string_len, s, op, optarg); } else { unsigned int i; - grn_ii_select_regexp_chunk *chunks; bool have_error = false; - chunks = GRN_CALLOC(sizeof(grn_ii_select_regexp_chunk) * n_parsed_strings); + auto chunks = static_cast( + GRN_CALLOC(sizeof(grn_ii_select_regexp_chunk) * n_parsed_strings)); for (i = 0; i < n_parsed_strings; i++) { const char *parsed_string; unsigned int parsed_string_len; @@ -14053,7 +14074,7 @@ typedef struct { double score; } grn_ii_quorum_match_record_data; -grn_rc +extern "C" grn_rc grn_ii_quorum_match(grn_ctx *ctx, grn_ii *ii, grn_ii_select_data *data) { size_t record_key_size; @@ -14237,7 +14258,7 @@ grn_ii_select_sequential_search_reference_should_use(grn_ctx *ctx, { int i; - grn_id *source_ids = DB_OBJ(data->ii)->source; + auto source_ids = static_cast(DB_OBJ(data->ii)->source); for (i = 0; i < n_sources; i++) { grn_id source_id = source_ids[i]; @@ -14298,7 +14319,7 @@ grn_ii_select_sequential_search_reference(grn_ctx *ctx, { const grn_id query_id = data->token_infos[0]->cursors[0].bins[0]->id; const grn_id lexicon_id = DB_OBJ(data->ii->lexicon)->id; - grn_id *source_ids = DB_OBJ(data->ii)->source; + auto source_ids = static_cast(DB_OBJ(data->ii)->source); const size_t n_sources = DB_OBJ(data->ii)->source_size / sizeof(grn_id); size_t i; for (i = 0; i < n_sources; i++) { @@ -14396,7 +14417,7 @@ grn_ii_select_sequential_search_text_should_use(grn_ctx *ctx, { size_t i; - grn_id *source_ids = DB_OBJ(data->ii)->source; + auto source_ids = static_cast(DB_OBJ(data->ii)->source); for (i = 0; i < n_sources; i++) { grn_id source_id = source_ids[i]; @@ -14467,7 +14488,7 @@ grn_ii_select_sequential_search_text_body(grn_ctx *ctx, { grn_obj buffer; GRN_TEXT_INIT(&buffer, 0); - grn_id *source_ids = DB_OBJ(data->ii)->source; + auto source_ids = static_cast(DB_OBJ(data->ii)->source); const size_t n_sources = DB_OBJ(data->ii)->source_size / sizeof(grn_id); size_t i; for (i = 0; i < n_sources; i++) { @@ -14501,11 +14522,13 @@ grn_ii_select_sequential_search_text_body(grn_ctx *ctx, &normalized_value, &normalized_value_length, NULL); + const OnigUChar *onig_value = + reinterpret_cast(normalized_value); position = onig_search(regex, - normalized_value, - normalized_value + normalized_value_length, - normalized_value, - normalized_value + normalized_value_length, + onig_value, + onig_value + normalized_value_length, + onig_value, + onig_value + normalized_value_length, NULL, 0); if (position != ONIG_MISMATCH) { @@ -14592,7 +14615,7 @@ grn_ii_select_sequential_search(grn_ctx *ctx, grn_ii_select_data *data) return false; } -grn_rc +extern "C" grn_rc grn_ii_select(grn_ctx *ctx, grn_ii *ii, const char *string, @@ -14854,7 +14877,7 @@ grn_ii_estimate_size_for_query_regexp(grn_ctx *ctx, return size; } -uint32_t +extern "C" uint32_t grn_ii_estimate_size_for_query(grn_ctx *ctx, grn_ii *ii, const char *query, @@ -14917,7 +14940,7 @@ grn_ii_estimate_size_for_query(grn_ctx *ctx, return (uint32_t)estimated_size; } -uint32_t +extern "C" uint32_t grn_ii_estimate_size_for_lexicon_cursor(grn_ctx *ctx, grn_ii *ii, grn_table_cursor *lexicon_cursor) @@ -14934,7 +14957,7 @@ grn_ii_estimate_size_for_lexicon_cursor(grn_ctx *ctx, return estimated_size; } -grn_rc +extern "C" grn_rc grn_ii_sel(grn_ctx *ctx, grn_ii *ii, const char *string, @@ -15100,7 +15123,7 @@ grn_ii_sel(grn_ctx *ctx, return ctx->rc; } -grn_rc +extern "C" grn_rc grn_ii_select_by_id( grn_ctx *ctx, grn_ii *ii, grn_id id, grn_hash *result_set, grn_operator op) { @@ -15109,7 +15132,7 @@ grn_ii_select_by_id( GRN_API_RETURN(rc); } -grn_rc +extern "C" grn_rc grn_ii_at(grn_ctx *ctx, grn_ii *ii, grn_id id, grn_hash *s, grn_operator op) { int rep = 0; @@ -15127,7 +15150,7 @@ grn_ii_at(grn_ctx *ctx, grn_ii *ii, grn_id id, grn_hash *s, grn_operator op) return ctx->rc; } -void +extern "C" void grn_ii_resolve_sel_and(grn_ctx *ctx, grn_hash *s, grn_operator op) { if (op == GRN_OP_AND && @@ -15150,7 +15173,7 @@ grn_ii_resolve_sel_and(grn_ctx *ctx, grn_hash *s, grn_operator op) } } -void +extern "C" void grn_ii_cursor_inspect(grn_ctx *ctx, grn_ii_cursor *c, grn_obj *buf) { grn_obj key_buf; @@ -15197,7 +15220,7 @@ grn_ii_cursor_inspect(grn_ctx *ctx, grn_ii_cursor *c, grn_obj *buf) GRN_TEXT_PUTS(ctx, buf, "\n ]\n >"); } -void +extern "C" void grn_ii_inspect_values(grn_ctx *ctx, grn_ii *ii, grn_obj *buf) { grn_table_cursor *tc; @@ -16012,11 +16035,10 @@ grn_ii_builder_chunk_reserve_enc_buf(grn_ctx *ctx, (chunk->n + 4) * sizeof(uint32_t) + n_cinfos * sizeof(chunk_info); if (chunk->enc_size < rich_size) { size_t size = chunk->enc_size ? chunk->enc_size * 2 : 1; - uint8_t *buf; while (size < rich_size) { size *= 2; } - buf = GRN_REALLOC(chunk->enc_buf, size); + auto buf = static_cast(GRN_REALLOC(chunk->enc_buf, size)); if (!buf) { ERR(GRN_NO_MEMORY_AVAILABLE, "failed to allocate memory for encoding: size = %" GRN_FMT_SIZE, @@ -16128,7 +16150,7 @@ grn_ii_builder_chunk_encode(grn_ctx *ctx, chunk->enc_offset = p - chunk->enc_buf; /* Encode a body. */ - grn_codec_data data = {0}; + grn_codec_data data = {}; data.ii = chunk->ii; data.term_id = chunk->tid; data.values = chunk->rid_buf; @@ -18207,7 +18229,7 @@ grn_ii_builder_commit(grn_ctx *ctx, grn_ii_builder *builder) return GRN_SUCCESS; } -grn_rc +extern "C" grn_rc grn_ii_build(grn_ctx *ctx, grn_ii *ii, const grn_ii_builder_options *options) { grn_rc rc, rc_close; @@ -18229,7 +18251,7 @@ grn_ii_build(grn_ctx *ctx, grn_ii *ii, const grn_ii_builder_options *options) return rc; } -grn_rc +extern "C" grn_rc grn_ii_wal_recover(grn_ctx *ctx, grn_ii *ii) { if (GRN_CTX_GET_WAL_ROLE(ctx) != GRN_WAL_ROLE_PRIMARY) { @@ -18254,7 +18276,7 @@ grn_ii_wal_recover(grn_ctx *ctx, grn_ii *ii) return ctx->rc; } -grn_rc +extern "C" grn_rc grn_ii_warm(grn_ctx *ctx, grn_ii *ii) { grn_rc rc = grn_io_warm(ctx, ii->seg);