null+****@clear*****
null+****@clear*****
2012年 2月 22日 (水) 12:55:31 JST
Daijiro MORI 2012-02-22 12:55:31 +0900 (Wed, 22 Feb 2012)
New Revision: 35711304144147b9888d17ef2822053e19ad4736
Log:
grn_ii_buffer: support WIN32.
Modified files:
lib/db.c
lib/ii.c
Modified: lib/db.c (+2 -35)
===================================================================
--- lib/db.c 2012-02-22 11:14:44 +0900 (64d3fd3)
+++ lib/db.c 2012-02-22 12:55:31 +0900 (775c063)
@@ -5722,42 +5722,9 @@ build_index(grn_ctx *ctx, grn_obj *obj)
grn_id *s = DB_OBJ(obj)->source;
if (!(DB_OBJ(obj)->source_size) || !s) { return; }
if ((src = grn_ctx_at(ctx, *s))) {
- if ((target = GRN_OBJ_TABLEP(src) ? src : grn_ctx_at(ctx, src->header.domain))) {
-#ifdef WIN32
- grn_obj **cp, **col, rv;
- grn_table_cursor *tc;
- grn_id id;
- int i, ncol = DB_OBJ(obj)->source_size / sizeof(grn_id);
- if ((col = GRN_MALLOC(ncol * sizeof(grn_obj *)))) {
- for (cp = col, i = ncol; i; s++, cp++, i--) {
- if (!(*cp = grn_ctx_at(ctx, *s))) {
- ERR(GRN_INVALID_ARGUMENT, "source invalid, n=%d",i);
- GRN_FREE(col);
- return;
- }
- }
- if ((tc = grn_table_cursor_open(ctx, target, NULL, 0, NULL, 0,
- 0, -1, GRN_CURSOR_BY_ID))) {
- GRN_TEXT_INIT(&rv, 0);
- while ((id = grn_table_cursor_next_inline(ctx, tc)) != GRN_ID_NIL) {
- for (cp = col, i = ncol; i; i--, cp++) {
- GRN_BULK_REWIND(&rv);
- if (GRN_OBJ_TABLEP(*cp)) {
- grn_table_get_key2(ctx, *cp, id, &rv);
- } else {
- grn_obj_get_value(ctx, *cp, id, &rv);
- }
- call_hook_for_build(ctx, *cp, id, &rv, 0);
- }
- }
- GRN_OBJ_FIN(ctx, &rv);
- grn_table_cursor_close(ctx, tc);
- }
- GRN_FREE(col);
- }
-#else /* WIN32 */
+ target = GRN_OBJ_TABLEP(src) ? src : grn_ctx_at(ctx, src->header.domain);
+ if (target) {
grn_ii_build(ctx, (grn_ii *)obj);
-#endif /* WIN32 */
} else {
ERR(GRN_INVALID_ARGUMENT, "invalid target");
}
Modified: lib/ii.c (+10 -2)
===================================================================
--- lib/ii.c 2012-02-22 11:14:44 +0900 (ee79f76)
+++ lib/ii.c 2012-02-22 12:55:31 +0900 (424afec)
@@ -6334,7 +6334,6 @@ grn_ii_inspect_elements(grn_ctx *ctx, grn_ii *ii, grn_obj *buf)
GRN_TEXT_PUTS(ctx, buf, "]");
}
-#ifndef WIN32
/********************** buffered index builder ***********************/
const grn_id II_BUFFER_RID_FLAG = 0x80000000;
@@ -7075,8 +7074,14 @@ grn_ii_buffer_open(grn_ctx *ctx, grn_ii *ii)
snprintf(ii_buffer->tmpfpath, PATH_MAX,
"%sXXXXXX", grn_io_path(ii->seg));
ii_buffer->block_buf_size = II_BUFFER_BLOCK_SIZE;
+#ifdef WIN32
+ mktemp(ii_buffer->tmpfpath);
+ ii_buffer->tmpfd = open(ii_buffer->tmpfpath,
+ O_WRONLY|O_CREAT|O_TRUNC|O_BINARY);
+#else /* WIN32 */
ii_buffer->tmpfd = mkostemp(ii_buffer->tmpfpath,
O_WRONLY|O_CREAT|O_TRUNC);
+#endif /* WIN32 */
if (ii_buffer->tmpfd) {
grn_obj_flags flags;
grn_table_get_info(ctx, ii->lexicon, &flags, NULL, NULL);
@@ -7125,7 +7130,11 @@ grn_ii_buffer_commit(grn_ctx *ctx, grn_ii_buffer *ii_buffer)
ii_buffer->packed_len = 0;
ii_buffer->packed_buf_size = 0;
ii_buffer->total_chunk_size = 0;
+#ifdef WIN32
+ ii_buffer->tmpfd = open(ii_buffer->tmpfpath, O_RDONLY|O_BINARY);
+#else /* WIN32 */
ii_buffer->tmpfd = open(ii_buffer->tmpfpath, O_RDONLY);
+#endif /* WIN32 */
datavec_init(ctx, ii_buffer->data_vectors, ii_buffer->ii->n_elements, 0, 0);
{
uint32_t i;
@@ -7252,4 +7261,3 @@ grn_ii_build(grn_ctx *ctx, grn_ii *ii)
}
return ctx->rc;
}
-#endif /* WIN32 */