[Groonga-commit] groonga/groonga at e277e1e [master] windows: use memcpy_s() on Windows

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Apr 15 20:40:28 JST 2015


Kouhei Sutou	2015-04-15 20:40:28 +0900 (Wed, 15 Apr 2015)

  New Revision: e277e1e8f756f8d00115bf7180aa653956fe24cb
  https://github.com/groonga/groonga/commit/e277e1e8f756f8d00115bf7180aa653956fe24cb

  Message:
    windows: use memcpy_s() on Windows

  Copied files:
    include/groonga/compat.h
      (from include/groonga.h)
  Modified files:
    include/groonga.h
    include/groonga/Makefile.am
    lib/com.c
    lib/ctx.c
    lib/dat.cpp
    lib/dat/dat.hpp
    lib/dat/key-cursor.cpp
    lib/db.c
    lib/expr.c
    lib/geo.c
    lib/grn.h
    lib/grn_io.h
    lib/grn_rset.h
    lib/hash.c
    lib/ii.c
    lib/io.c
    lib/logger.c
    lib/normalizer.c
    lib/pat.c
    lib/plugin.c
    lib/proc.c
    lib/snip.c
    lib/store.c
    lib/str.c
    lib/string.c
    lib/tokenizer.c
    plugins/query_expanders/tsv.c

  Modified: include/groonga.h (+1 -0)
===================================================================
--- include/groonga.h    2015-04-15 18:11:18 +0900 (9638428)
+++ include/groonga.h    2015-04-15 20:40:28 +0900 (1d97f87)
@@ -18,6 +18,7 @@
 #ifndef GROONGA_H
 #define GROONGA_H
 
+#include "groonga/compat.h"
 #include "groonga/groonga.h"
 #include "groonga/obj.h"
 #include "groonga/ii.h"

  Modified: include/groonga/Makefile.am (+1 -0)
===================================================================
--- include/groonga/Makefile.am    2015-04-15 18:11:18 +0900 (af3a79b)
+++ include/groonga/Makefile.am    2015-04-15 20:40:28 +0900 (b623549)
@@ -1,6 +1,7 @@
 groonga_includedir = $(pkgincludedir)/groonga
 groonga_include_HEADERS =			\
 	command.h				\
+	compat.h				\
 	expr.h					\
 	groonga.h				\
 	ii.h					\

  Copied: include/groonga/compat.h (+17 -11) 56%
===================================================================
--- include/groonga.h    2015-04-15 18:11:18 +0900 (9638428)
+++ include/groonga/compat.h    2015-04-15 20:40:28 +0900 (9dab744)
@@ -1,5 +1,5 @@
 /*
-  Copyright(C) 2014-2015 Brazil
+  Copyright(C) 2015 Brazil
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -15,15 +15,21 @@
   License along with this library; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
-#ifndef GROONGA_H
-#define GROONGA_H
+#ifndef GROONGA_COMPAT_H
+#define GROONGA_COMPAT_H
 
-#include "groonga/groonga.h"
-#include "groonga/obj.h"
-#include "groonga/ii.h"
-#include "groonga/expr.h"
-#include "groonga/output.h"
-#include "groonga/util.h"
-#include "groonga/request_canceler.h"
+#ifdef WIN32
+# ifdef __cplusplus
+#  define grn_memcpy(dest, src, n) ::memcpy_s((dest), (n), (src), (n))
+# else /* __cplusplus */
+#  define grn_memcpy(dest, src, n) memcpy_s((dest), (n), (src), (n))
+# endif /* __cplusplus */
+#else /* WIN32 */
+# ifdef __cplusplus
+#  define grn_memcpy(dest, src, n) std::memcpy((dest), (src), (n))
+# else /* __cplusplus */
+#  define grn_memcpy(dest, src, n) memcpy((dest), (src), (n))
+# endif /* __cplusplus */
+#endif /* WIN32 */
 
-#endif /* GROONGA_H */
+#endif /* GROONGA_COMPAT_H */

  Modified: lib/com.c (+2 -2)
===================================================================
--- lib/com.c    2015-04-15 18:11:18 +0900 (a17d3a9)
+++ lib/com.c    2015-04-15 20:40:28 +0900 (9b31cdf)
@@ -528,7 +528,7 @@ grn_com_receiver(grn_ctx *ctx, grn_com *com)
     grn_msg *msg = (grn_msg *)grn_msg_open(ctx, com, &ev->recv_old);
     grn_com_recv(ctx, msg->u.peer, &msg->header, (grn_obj *)msg);
     if (msg->u.peer /* is_edge_request(msg)*/) {
-      memcpy(&msg->edge_id, &ev->curr_edge_id, sizeof(grn_com_addr));
+      grn_memcpy(&msg->edge_id, &ev->curr_edge_id, sizeof(grn_com_addr));
       if (!com->has_sid) {
         com->has_sid = 1;
         com->sid = ev->curr_edge_id.sid++;
@@ -1069,7 +1069,7 @@ grn_com_sopen(grn_ctx *ctx, grn_com_event *ev,
     SOERR("socket");
     goto exit;
   }
-  memcpy(&ev->curr_edge_id.addr, he->h_addr, he->h_length);
+  grn_memcpy(&ev->curr_edge_id.addr, he->h_addr, he->h_length);
   ev->curr_edge_id.port = htons(port);
   ev->curr_edge_id.sid = 0;
   {

  Modified: lib/ctx.c (+3 -3)
===================================================================
--- lib/ctx.c    2015-04-15 18:11:18 +0900 (077272e)
+++ lib/ctx.c    2015-04-15 20:40:28 +0900 (4ec2aab)
@@ -253,7 +253,7 @@ grn_alloc_info_set_backtrace(char *buffer, size_t size)
       if (symbol_length + 2 > rest) {
         break;
       }
-      memcpy(buffer, symbols[i], symbol_length);
+      grn_memcpy(buffer, symbols[i], symbol_length);
       buffer += symbol_length;
       rest -= symbol_length;
       buffer[0] = '\n';
@@ -1997,7 +1997,7 @@ grn_ctx_realloc(grn_ctx *ctx, void *ptr, size_t size,
     if (res && ptr) {
       int32_t *header = &((int32_t *)ptr)[-2];
       size_t size_ = header[1];
-      memcpy(res, ptr, size_ > size ? size : size_);
+      grn_memcpy(res, ptr, size_ > size ? size : size_);
       grn_ctx_free(ctx, ptr, file, line, func);
     }
   } else {
@@ -2013,7 +2013,7 @@ grn_ctx_strdup(grn_ctx *ctx, const char *s, const char* file, int line, const ch
   if (s) {
     size_t size = strlen(s) + 1;
     if ((res = grn_ctx_alloc(ctx, size, 0, file, line, func))) {
-      memcpy(res, s, size);
+      grn_memcpy(res, s, size);
     }
   }
   return res;

  Modified: lib/dat.cpp (+2 -2)
===================================================================
--- lib/dat.cpp    2015-04-15 18:11:18 +0900 (4a3db12)
+++ lib/dat.cpp    2015-04-15 20:40:28 +0900 (faae04e)
@@ -144,7 +144,7 @@ grn_dat_generate_trie_path(const char *base_path, char *trie_path, uint32_t file
     return;
   }
   const size_t len = std::strlen(base_path);
-  std::memcpy(trie_path, base_path, len);
+  grn_memcpy(trie_path, base_path, len);
   trie_path[len] = '.';
   grn_itoh(file_id % (1U << (4 * FILE_ID_LENGTH)),
            trie_path + len + 1, FILE_ID_LENGTH);
@@ -502,7 +502,7 @@ grn_dat_get_key(grn_ctx *ctx, grn_dat *dat, grn_id id, void *keybuf, int bufsize
     return 0;
   }
   if (keybuf && (bufsize >= (int)key.length())) {
-    std::memcpy(keybuf, key.ptr(), key.length());
+    grn_memcpy(keybuf, key.ptr(), key.length());
   }
   return (int)key.length();
 }

  Modified: lib/dat/dat.hpp (+6 -0)
===================================================================
--- lib/dat/dat.hpp    2015-04-15 18:11:18 +0900 (d2b2264)
+++ lib/dat/dat.hpp    2015-04-15 20:40:28 +0900 (c941bf2)
@@ -42,6 +42,12 @@
 # endif  // WIN32
 #endif  // GRN_DAT_API
 
+#ifdef WIN32
+# define grn_memcpy(dest, src, n) ::memcpy_s((dest), (n), (src), (n))
+#else  // WIN32
+# define grn_memcpy(dest, src, n) std::memcpy((dest), (src), (n))
+#endif  // WIN32
+
 namespace grn {
 namespace dat {
 

  Modified: lib/dat/key-cursor.cpp (+2 -2)
===================================================================
--- lib/dat/key-cursor.cpp    2015-04-15 18:11:18 +0900 (90ba25e)
+++ lib/dat/key-cursor.cpp    2015-04-15 20:40:28 +0900 (6bf864d)
@@ -133,7 +133,7 @@ void KeyCursor::ascending_init(const String &min_str, const String &max_str) {
   if (max_str.ptr() != NULL) {
     if (max_str.length() != 0) {
       end_buf_ = new UInt8[max_str.length()];
-      std::memcpy(end_buf_, max_str.ptr(), max_str.length());
+      grn_memcpy(end_buf_, max_str.ptr(), max_str.length());
       end_str_.assign(end_buf_, max_str.length());
     }
   }
@@ -206,7 +206,7 @@ void KeyCursor::descending_init(const String &min_str, const String &max_str) {
   if (min_str.ptr() != NULL) {
     if (min_str.length() != 0) {
       end_buf_ = new UInt8[min_str.length()];
-      std::memcpy(end_buf_, min_str.ptr(), min_str.length());
+      grn_memcpy(end_buf_, min_str.ptr(), min_str.length());
       end_str_.assign(end_buf_, min_str.length());
     }
   }

  Modified: lib/db.c (+23 -23)
===================================================================
--- lib/db.c    2015-04-15 18:11:18 +0900 (6fc2c2c)
+++ lib/db.c    2015-04-15 20:40:28 +0900 (85a730a)
@@ -89,7 +89,7 @@ inline static void
 gen_pathname(const char *path, char *buffer, int fno)
 {
   size_t len = strlen(path);
-  memcpy(buffer, path, len);
+  grn_memcpy(buffer, path, len);
   if (fno >= 0) {
     buffer[len] = '.';
     grn_itoh(fno, buffer + len + 1, 7);
@@ -2063,7 +2063,7 @@ subrecs_push(byte *subrecs, int size, int n_subrecs, double score, void *body, i
   }
   v = subrecs + n * (GRN_RSET_SCORE_SIZE + size);
   *((double *)v) = score;
-  memcpy(v + GRN_RSET_SCORE_SIZE, body, size);
+  grn_memcpy(v + GRN_RSET_SCORE_SIZE, body, size);
 }
 
 inline static void
@@ -2097,8 +2097,8 @@ subrecs_replace_min(byte *subrecs, int size, int n_subrecs, double score, void *
     }
   }
   v = subrecs + n * (GRN_RSET_SCORE_SIZE + size);
-  memcpy(v, &score, GRN_RSET_SCORE_SIZE);
-  memcpy(v + GRN_RSET_SCORE_SIZE, body, size);
+  grn_memcpy(v, &score, GRN_RSET_SCORE_SIZE);
+  grn_memcpy(v + GRN_RSET_SCORE_SIZE, body, size);
 }
 
 inline static void
@@ -3788,7 +3788,7 @@ grn_table_setoperation(grn_ctx *ctx, grn_obj *table1, grn_obj *table2, grn_obj *
       GRN_TABLE_EACH(ctx, table2, 0, 0, id, &key, &key_size, &value2, {
         if (grn_table_add_v_inline(ctx, table1, key, key_size, &value1, &added)) {
           if (added) {
-            memcpy(value1, value2, value_size);
+            grn_memcpy(value1, value2, value_size);
           } else {
             grn_rset_recinfo *ri1 = value1;
             grn_rset_recinfo *ri2 = value2;
@@ -3799,7 +3799,7 @@ grn_table_setoperation(grn_ctx *ctx, grn_obj *table1, grn_obj *table2, grn_obj *
     } else {
       GRN_TABLE_EACH(ctx, table2, 0, 0, id, &key, &key_size, &value2, {
         if (grn_table_add_v_inline(ctx, table1, key, key_size, &value1, NULL)) {
-          memcpy(value1, value2, value_size);
+          grn_memcpy(value1, value2, value_size);
         }
       });
     }
@@ -3831,7 +3831,7 @@ grn_table_setoperation(grn_ctx *ctx, grn_obj *table1, grn_obj *table2, grn_obj *
   case GRN_OP_ADJUST :
     GRN_TABLE_EACH(ctx, table2, 0, 0, id, &key, &key_size, &value2, {
       if (grn_table_get_v(ctx, table1, key, key_size, &value1)) {
-        memcpy(value1, value2, value_size);
+        grn_memcpy(value1, value2, value_size);
       }
     });
     break;
@@ -3880,7 +3880,7 @@ grn_obj_column_(grn_ctx *ctx, grn_obj *table, const char *name, unsigned int nam
   if (len) {
     buf[len++] = GRN_DB_DELIMITER;
     if (len + name_size <= GRN_TABLE_MAX_KEY_SIZE) {
-      memcpy(buf + len, name, name_size);
+      grn_memcpy(buf + len, name, name_size);
       column = grn_ctx_get(ctx, buf, len + name_size);
     } else {
       ERR(GRN_INVALID_ARGUMENT, "name is too long");
@@ -4026,7 +4026,7 @@ grn_column_create(grn_ctx *ctx, grn_obj *table,
       goto exit;
     }
     fullname[len] = GRN_DB_DELIMITER;
-    memcpy(fullname + len + 1, name, name_size);
+    grn_memcpy(fullname + len + 1, name, name_size);
     name_size += len + 1;
   } else {
     ERR(GRN_FUNCTION_NOT_IMPLEMENTED,
@@ -4154,7 +4154,7 @@ grn_column_open(grn_ctx *ctx, grn_obj *table,
       goto exit;
     }
     fullname[len] = GRN_DB_DELIMITER;
-    memcpy(fullname + len + 1, name, name_size);
+    grn_memcpy(fullname + len + 1, name, name_size);
     name_size += len + 1;
   } else {
     ERR(GRN_INVALID_ARGUMENT, "todo : not supported yet");
@@ -4218,7 +4218,7 @@ default_column_set_value(grn_ctx *ctx, grn_proc_ctx *pctx, grn_obj *in, grn_obj
           ERR(GRN_NO_MEMORY_AVAILABLE, "ra get failed");
           return GRN_NO_MEMORY_AVAILABLE;
         }
-        memcpy(v, in->u.p.ptr, value_size);
+        grn_memcpy(v, in->u.p.ptr, value_size);
         grn_ra_unref(ctx, (grn_ra *)pctx->obj, arg->id);
       }
       break;
@@ -6604,13 +6604,13 @@ grn_obj_set_value_column_fix_size(grn_ctx *ctx, grn_obj *obj, grn_id id,
         } else {
           void *b;
           if ((b = GRN_CALLOC(element_size))) {
-            memcpy(b, v, s);
-            memcpy(p, b, element_size);
+            grn_memcpy(b, v, s);
+            grn_memcpy(p, b, element_size);
             GRN_FREE(b);
           }
         }
       } else {
-        memcpy(p, v, s);
+        grn_memcpy(p, v, s);
       }
       rc = GRN_SUCCESS;
       break;
@@ -7384,7 +7384,7 @@ grn_hook_unpack(grn_ctx *ctx, grn_db_obj *obj, const char *buf, uint32_t buf_siz
         new->proc = NULL;
       }
       if ((new->hld_size = hld_size)) {
-        memcpy(NEXT_ADDR(new), p, hld_size);
+        grn_memcpy(NEXT_ADDR(new), p, hld_size);
         p += hld_size;
       }
       *last = new;
@@ -7618,7 +7618,7 @@ grn_obj_set_info_source_update(grn_ctx *ctx, grn_obj *obj, grn_obj *value)
     if (!v2) {
       return ctx->rc;
     }
-    memcpy(v2, v, s);
+    grn_memcpy(v2, v, s);
     if (DB_OBJ(obj)->source) { GRN_FREE(DB_OBJ(obj)->source); }
     DB_OBJ(obj)->source = v2;
     DB_OBJ(obj)->source_size = s;
@@ -7838,7 +7838,7 @@ grn_obj_add_hook(grn_ctx *ctx, grn_obj *obj, grn_hook_entry entry,
     new->proc = (grn_proc *)proc;
     new->hld_size = hld_size;
     if (hld_size) {
-      memcpy(NEXT_ADDR(new), hld_value, hld_size);
+      grn_memcpy(NEXT_ADDR(new), hld_value, hld_size);
     }
     for (i = 0; i != offset && *last; i++) { last = &(*last)->next; }
     new->next = *last;
@@ -8495,7 +8495,7 @@ grn_table_rename(grn_ctx *ctx, grn_obj *table, const char *name, unsigned int na
     if (!(rc = grn_obj_rename(ctx, table, name, name_size))) {
       grn_id *key;
       char fullname[GRN_TABLE_MAX_KEY_SIZE];
-      memcpy(fullname, name, name_size);
+      grn_memcpy(fullname, name, name_size);
       fullname[name_size] = GRN_DB_DELIMITER;
       GRN_HASH_EACH(ctx, cols, id, &key, NULL, NULL, {
         grn_obj *col = grn_ctx_at(ctx, *key);
@@ -8536,7 +8536,7 @@ grn_column_rename(grn_ctx *ctx, grn_obj *column, const char *name, unsigned int
       goto exit;
     }
     fullname[len] = GRN_DB_DELIMITER;
-    memcpy(fullname + len + 1, name, name_size);
+    grn_memcpy(fullname + len + 1, name, name_size);
     name_size += len + 1;
     rc = grn_obj_rename(ctx, column, fullname, name_size);
   }
@@ -8678,7 +8678,7 @@ grn_db_obj_init(grn_ctx *ctx, grn_obj *db, grn_id id, grn_db_obj *obj)
                                                NULL,\
                                                NULL);\
     if (size > PATH_MAX) { ERR(GRN_FILENAME_TOO_LONG, "too long path"); }\
-    memcpy(buffer, path, size);\
+    grn_memcpy(buffer, path, size);\
     buffer[size] = '\0';\
   } else {\
     gen_pathname(grn_obj_io(s->keys)->path, buffer, id);  \
@@ -8700,7 +8700,7 @@ grn_db_obj_init(grn_ctx *ctx, grn_obj *db, grn_id id, grn_db_obj *obj)
                                   NULL);\
     if (size) {\
       if ((r->source = GRN_MALLOC(size))) {\
-        memcpy(r->source, p, size);\
+        grn_memcpy(r->source, p, size);\
         r->source_size = size;\
       }\
     }\
@@ -9308,7 +9308,7 @@ grn_column_name(grn_ctx *ctx, grn_obj *obj, char *namebuf, int buf_size)
         }
         len = pe - p0;
         if (len && len <= buf_size) {
-          memcpy(namebuf, p0, len);
+          grn_memcpy(namebuf, p0, len);
         }
       }
     }
@@ -9354,7 +9354,7 @@ grn_column_name(grn_ctx *ctx, grn_obj *obj, char *namebuf, int buf_size)
     if (name) {
       len = strlen(name);
       if (len <= buf_size) {
-        memcpy(namebuf, name, len);
+        grn_memcpy(namebuf, name, len);
       }
     }
   }

  Modified: lib/expr.c (+2 -2)
===================================================================
--- lib/expr.c    2015-04-15 18:11:18 +0900 (389dc3a)
+++ lib/expr.c    2015-04-15 20:40:28 +0900 (4af0849)
@@ -3611,9 +3611,9 @@ put_logical_op(grn_ctx *ctx, scan_info **sis, int *ip, grn_operator op, int star
             } else {
               s_->flags &= ~SCAN_PUSH;
               s_->logical_op = op;
-              memcpy(&sis[i], &sis[j], sizeof(scan_info *) * (r - j));
+              grn_memcpy(&sis[i], &sis[j], sizeof(scan_info *) * (r - j));
               memmove(&sis[j], &sis[r], sizeof(scan_info *) * (i - r));
-              memcpy(&sis[i + j - r], &sis[i], sizeof(scan_info *) * (r - j));
+              grn_memcpy(&sis[i + j - r], &sis[i], sizeof(scan_info *) * (r - j));
             }
             break;
           }

  Modified: lib/geo.c (+20 -20)
===================================================================
--- lib/geo.c    2015-04-15 18:11:18 +0900 (21b50c4)
+++ lib/geo.c    2015-04-15 20:40:28 +0900 (cea9634)
@@ -91,18 +91,18 @@ compute_min_and_max_key(uint8_t *key_base, int diff_bit,
   diff_bit_mask = 0xff >> (diff_bit % 8);
 
   if (diff_byte == sizeof(grn_geo_point)) {
-    if (key_min) { memcpy(key_min, key_base, diff_byte); }
-    if (key_max) { memcpy(key_max, key_base, diff_byte); }
+    if (key_min) { grn_memcpy(key_min, key_base, diff_byte); }
+    if (key_max) { grn_memcpy(key_max, key_base, diff_byte); }
   } else {
     if (key_min) {
-      memcpy(key_min, key_base, diff_byte + 1);
+      grn_memcpy(key_min, key_base, diff_byte + 1);
       key_min[diff_byte] &= ~diff_bit_mask;
       memset(key_min + diff_byte + 1, 0,
              sizeof(grn_geo_point) - diff_byte - 1);
     }
 
     if (key_max) {
-      memcpy(key_max, key_base, diff_byte + 1);
+      grn_memcpy(key_max, key_base, diff_byte + 1);
       key_max[diff_byte] |= diff_bit_mask;
       memset(key_max + diff_byte + 1, 0xff,
              sizeof(grn_geo_point) - diff_byte - 1);
@@ -274,7 +274,7 @@ grn_geo_table_sort_detect_far_point(grn_ctx *ctx, grn_obj *table, grn_obj *index
   grn_gton(geo_key_curr, base_point, sizeof(grn_geo_point));
   *diff_bit = sizeof(grn_geo_point) * 8;
   diff_bit_current = sizeof(grn_geo_point) * 8;
-  memcpy(&point, base_point, sizeof(grn_geo_point));
+  grn_memcpy(&point, base_point, sizeof(grn_geo_point));
   ep = entries;
   inspect_mesh(ctx, &point, *diff_bit, -1);
   while ((tid = grn_pat_cursor_next(ctx, pc))) {
@@ -1419,8 +1419,8 @@ grn_geo_cursor_area_init(grn_ctx *ctx,
   }
 
   area->current_entry = 0;
-  memcpy(&(area->top_left), &area_top_left, sizeof(grn_geo_point));
-  memcpy(&(area->bottom_right), &area_bottom_right, sizeof(grn_geo_point));
+  grn_memcpy(&(area->top_left), &area_top_left, sizeof(grn_geo_point));
+  grn_memcpy(&(area->bottom_right), &area_bottom_right, sizeof(grn_geo_point));
   grn_gton(area->top_left_key, &area_top_left, sizeof(grn_geo_point));
   grn_gton(area->bottom_right_key, &area_bottom_right, sizeof(grn_geo_point));
 
@@ -1430,7 +1430,7 @@ grn_geo_cursor_area_init(grn_ctx *ctx,
                                  &area_bottom_right,
                                  &data);
   entry->target_bit = data.rectangle_common_bit;
-  memcpy(entry->key, data.rectangle_common_key, sizeof(grn_geo_point));
+  grn_memcpy(entry->key, data.rectangle_common_key, sizeof(grn_geo_point));
   entry->status_flags =
     GRN_GEO_CURSOR_ENTRY_STATUS_TOP_INCLUDED |
     GRN_GEO_CURSOR_ENTRY_STATUS_BOTTOM_INCLUDED |
@@ -1474,8 +1474,8 @@ grn_geo_cursor_open_in_rectangle(grn_ctx *ctx,
 
   cursor->pat = data.pat;
   cursor->index = index;
-  memcpy(&(cursor->top_left), data.top_left, sizeof(grn_geo_point));
-  memcpy(&(cursor->bottom_right), data.bottom_right, sizeof(grn_geo_point));
+  grn_memcpy(&(cursor->top_left), data.top_left, sizeof(grn_geo_point));
+  grn_memcpy(&(cursor->bottom_right), data.bottom_right, sizeof(grn_geo_point));
   cursor->pat_cursor = NULL;
   cursor->ii_cursor = NULL;
   cursor->offset = offset;
@@ -1544,7 +1544,7 @@ grn_geo_cursor_entry_next_push(grn_ctx *ctx,
       grn_geo_cursor_area *area;
       area = &(cursor->areas[cursor->current_area]);
       next_entry = &(area->entries[++area->current_entry]);
-      memcpy(next_entry, entry, sizeof(grn_geo_cursor_entry));
+      grn_memcpy(next_entry, entry, sizeof(grn_geo_cursor_entry));
       pushed = GRN_TRUE;
     }
     grn_table_cursor_close(ctx, pat_cursor);
@@ -1578,9 +1578,9 @@ grn_geo_cursor_entry_next(grn_ctx *ctx,
 
   top_left_key = area->top_left_key;
   bottom_right_key = area->bottom_right_key;
-  memcpy(entry,
-         &(area->entries[area->current_entry--]),
-         sizeof(grn_geo_cursor_entry));
+  grn_memcpy(entry,
+             &(area->entries[area->current_entry--]),
+             sizeof(grn_geo_cursor_entry));
   while (GRN_TRUE) {
     grn_geo_cursor_entry next_entry0, next_entry1;
     grn_bool pushed = GRN_FALSE;
@@ -1663,9 +1663,9 @@ grn_geo_cursor_entry_next(grn_ctx *ctx,
       break;
     }
 
-    memcpy(&next_entry0, entry, sizeof(grn_geo_cursor_entry));
+    grn_memcpy(&next_entry0, entry, sizeof(grn_geo_cursor_entry));
     next_entry0.target_bit++;
-    memcpy(&next_entry1, entry, sizeof(grn_geo_cursor_entry));
+    grn_memcpy(&next_entry1, entry, sizeof(grn_geo_cursor_entry));
     next_entry1.target_bit++;
     SET_N_BIT(next_entry1.key, next_entry1.target_bit);
 
@@ -1767,9 +1767,9 @@ grn_geo_cursor_entry_next(grn_ctx *ctx,
         print_key_mark(ctx, stack_entry->target_bit);
       }
 #endif
-      memcpy(entry,
-             &(area->entries[area->current_entry--]),
-             sizeof(grn_geo_cursor_entry));
+      grn_memcpy(entry,
+                 &(area->entries[area->current_entry--]),
+                 sizeof(grn_geo_cursor_entry));
 #ifdef GEO_DEBUG
       printf("%d: pop entry\n", entry->target_bit);
 #endif
@@ -1979,7 +1979,7 @@ geo_point_get(grn_ctx *ctx, grn_obj *pat, int flags, grn_geo_point *geo_point)
     void *key;
     int key_size;
     key_size = grn_table_cursor_get_key(ctx, cursor, &key);
-    memcpy(geo_point, key, key_size);
+    grn_memcpy(geo_point, key, key_size);
   }
 
 exit:

  Modified: lib/grn.h (+1 -1)
===================================================================
--- lib/grn.h    2015-04-15 18:11:18 +0900 (c33ad7f)
+++ lib/grn.h    2015-04-15 20:40:28 +0900 (2af41e6)
@@ -712,7 +712,7 @@ grn_str_greater(const uint8_t *ap, uint32_t as, const uint8_t *bp, uint32_t bs)
   lo_ = (lo_ | (lo_ <<  1)) & 0x5555555555555555ULL;\
   result_ = (la_ << 1) | lo_;\
   grn_hton_uint64(result_, result_);\
-  memcpy(keybuf, &result_, sizeof(result_));\
+  grn_memcpy(keybuf, &result_, sizeof(result_));\
 } while (0)
 
 #define grn_ntog(keybuf,key,size) do {\

  Modified: lib/grn_io.h (+2 -2)
===================================================================
--- lib/grn_io.h    2015-04-15 18:11:18 +0900 (00a1c3a)
+++ lib/grn_io.h    2015-04-15 20:40:28 +0900 (14f5e49)
@@ -380,7 +380,7 @@ uint32_t grn_expire(grn_ctx *ctx, int count_thresh, uint32_t limit);
     *_p++ = _v & 0xff; \
   } else { \
     *_p++ = 0x8f; \
-    memcpy(_p, &_v, sizeof(uint32_t));\
+    grn_memcpy(_p, &_v, sizeof(uint32_t));\
     _p += sizeof(uint32_t); \
   } \
   p = _p; \
@@ -395,7 +395,7 @@ uint32_t grn_expire(grn_ctx *ctx, int count_thresh, uint32_t limit);
   switch (_v >> 4) { \
   case 0x08 : \
     if (_v == 0x8f) { \
-      memcpy(&_v, _p, sizeof(uint32_t));\
+      grn_memcpy(&_v, _p, sizeof(uint32_t));\
       _p += sizeof(uint32_t); \
     } \
     break; \

  Modified: lib/grn_rset.h (+1 -1)
===================================================================
--- lib/grn_rset.h    2015-04-15 18:11:18 +0900 (4fa0d08)
+++ lib/grn_rset.h    2015-04-15 20:40:28 +0900 (b92e211)
@@ -53,7 +53,7 @@ typedef struct {
 #define GRN_RSET_SUBRECS_NTH(subrecs,size,n) \
   ((double *)((byte *)subrecs + n * GRN_RSET_SUBREC_SIZE(size)))
 #define GRN_RSET_SUBRECS_COPY(subrecs,size,n,src) \
-  (memcpy(GRN_RSET_SUBRECS_NTH(subrecs, size, n), src, GRN_RSET_SUBREC_SIZE(size)))
+  (grn_memcpy(GRN_RSET_SUBRECS_NTH(subrecs, size, n), src, GRN_RSET_SUBREC_SIZE(size)))
 #define GRN_RSET_SUBRECS_SIZE(subrec_size,n) \
   (GRN_RSET_SUBREC_SIZE(subrec_size) * n)
 

  Modified: lib/hash.c (+17 -17)
===================================================================
--- lib/hash.c    2015-04-15 18:11:18 +0900 (bfdc695)
+++ lib/hash.c    2015-04-15 20:40:28 +0900 (2c44f25)
@@ -700,7 +700,7 @@ grn_array_get_value(grn_ctx *ctx, grn_array *array, grn_id id, void *valuebuf)
   void * const value = grn_array_get_value_inline(ctx, array, id);
   if (value) {
     if (valuebuf) {
-      memcpy(valuebuf, value, array->value_size);
+      grn_memcpy(valuebuf, value, array->value_size);
     }
     return array->value_size;
   }
@@ -724,7 +724,7 @@ grn_array_set_value_inline(grn_ctx *ctx, grn_array *array, grn_id id,
 
   switch ((flags & GRN_OBJ_SET_MASK)) {
   case GRN_OBJ_SET :
-    memcpy(entry, value, array->value_size);
+    grn_memcpy(entry, value, array->value_size);
     return GRN_SUCCESS;
   case GRN_OBJ_INCR :
     switch (array->value_size) {
@@ -863,7 +863,7 @@ grn_array_copy_sort_key(grn_ctx *ctx, grn_array *array,
   if (!array->keys) {
     return ctx->rc;
   }
-  memcpy(array->keys, keys, sizeof(grn_table_sort_key) * n_keys);
+  grn_memcpy(array->keys, keys, sizeof(grn_table_sort_key) * n_keys);
   array->n_keys = n_keys;
   return GRN_SUCCESS;
 }
@@ -1404,7 +1404,7 @@ grn_io_hash_entry_put_key(grn_ctx *ctx, grn_hash *hash,
     if (!key_ptr) {
       return GRN_NO_MEMORY_AVAILABLE;
     }
-    memcpy(key_ptr, key, key_size);
+    grn_memcpy(key_ptr, key, key_size);
   }
   return GRN_SUCCESS;
 }
@@ -1417,7 +1417,7 @@ grn_hash_entry_put_key(grn_ctx *ctx, grn_hash *hash,
   if (hash->obj.header.flags & GRN_OBJ_KEY_VAR_SIZE) {
     if (grn_hash_is_io_hash(hash)) {
       if (key_size <= sizeof(entry->io_entry.key.buf)) {
-        memcpy(entry->io_entry.key.buf, key, key_size);
+        grn_memcpy(entry->io_entry.key.buf, key, key_size);
         entry->io_entry.flag = HASH_IMMEDIATE;
       } else {
         const grn_rc rc =
@@ -1432,7 +1432,7 @@ grn_hash_entry_put_key(grn_ctx *ctx, grn_hash *hash,
       entry->io_entry.key_size = key_size;
     } else {
       if (key_size <= sizeof(entry->tiny_entry.key.buf)) {
-        memcpy(entry->tiny_entry.key.buf, key, key_size);
+        grn_memcpy(entry->tiny_entry.key.buf, key, key_size);
         entry->tiny_entry.flag = HASH_IMMEDIATE;
       } else {
         grn_ctx * const ctx = hash->ctx;
@@ -1440,7 +1440,7 @@ grn_hash_entry_put_key(grn_ctx *ctx, grn_hash *hash,
         if (!entry->tiny_entry.key.ptr) {
           return GRN_NO_MEMORY_AVAILABLE;
         }
-        memcpy(entry->tiny_entry.key.ptr, key, key_size);
+        grn_memcpy(entry->tiny_entry.key.ptr, key, key_size);
         entry->tiny_entry.flag = 0;
       }
       entry->tiny_entry.hash_value = hash_value;
@@ -1451,7 +1451,7 @@ grn_hash_entry_put_key(grn_ctx *ctx, grn_hash *hash,
       *(uint32_t *)entry->plain_entry.key = hash_value;
     } else {
       entry->rich_entry.hash_value = hash_value;
-      memcpy(entry->rich_entry.key_and_value, key, key_size);
+      grn_memcpy(entry->rich_entry.key_and_value, key, key_size);
     }
   }
   return GRN_SUCCESS;
@@ -2311,7 +2311,7 @@ grn_hash_get_key(grn_ctx *ctx, grn_hash *hash, grn_id id, void *keybuf, int bufs
   }
   key_size = grn_hash_entry_get_key_size(hash, entry);
   if (bufsize >= key_size) {
-    memcpy(keybuf, grn_hash_entry_get_key(ctx, hash, entry), key_size);
+    grn_memcpy(keybuf, grn_hash_entry_get_key(ctx, hash, entry), key_size);
   }
   return key_size;
 }
@@ -2349,7 +2349,7 @@ grn_hash_get_value(grn_ctx *ctx, grn_hash *hash, grn_id id, void *valuebuf)
     return 0;
   }
   if (valuebuf) {
-    memcpy(valuebuf, value, hash->value_size);
+    grn_memcpy(valuebuf, value, hash->value_size);
   }
   return hash->value_size;
 }
@@ -2382,14 +2382,14 @@ grn_hash_get_key_value(grn_ctx *ctx, grn_hash *hash, grn_id id,
   }
   key_size = grn_hash_entry_get_key_size(hash, entry);
   if (bufsize >= key_size) {
-    memcpy(keybuf, grn_hash_entry_get_key(ctx, hash, entry), key_size);
+    grn_memcpy(keybuf, grn_hash_entry_get_key(ctx, hash, entry), key_size);
   }
   value = grn_hash_entry_get_value(hash, entry);
   if (!value) {
     return 0;
   }
   if (valuebuf) {
-    memcpy(valuebuf, value, hash->value_size);
+    grn_memcpy(valuebuf, value, hash->value_size);
   }
   return key_size;
 }
@@ -2429,7 +2429,7 @@ grn_hash_set_value(grn_ctx *ctx, grn_hash *hash, grn_id id,
 
   switch (flags & GRN_OBJ_SET_MASK) {
   case GRN_OBJ_SET :
-    memcpy(entry_value, value, hash->value_size);
+    grn_memcpy(entry_value, value, hash->value_size);
     return GRN_SUCCESS;
   case GRN_OBJ_INCR :
     switch (hash->value_size) {
@@ -3192,7 +3192,7 @@ subrecs_push(byte *subrecs, int size, int n_subrecs, int score, void *body, int
   }
   v = subrecs + n * (size + GRN_RSET_SCORE_SIZE);
   *((int *)v) = score;
-  memcpy(v + GRN_RSET_SCORE_SIZE, body, size);
+  grn_memcpy(v + GRN_RSET_SCORE_SIZE, body, size);
 }
 
 inline static void
@@ -3225,8 +3225,8 @@ subrecs_replace_min(byte *subrecs, int size, int n_subrecs, int score, void *bod
     }
   }
   v = subrecs + n * (size + GRN_RSET_SCORE_SIZE);
-  memcpy(v, &score, GRN_RSET_SCORE_SIZE);
-  memcpy(v + GRN_RSET_SCORE_SIZE, body, size);
+  grn_memcpy(v, &score, GRN_RSET_SCORE_SIZE);
+  grn_memcpy(v + GRN_RSET_SCORE_SIZE, body, size);
 }
 
 void
@@ -3286,7 +3286,7 @@ grn_rhash_group(grn_hash *s, int limit, grn_group_optarg *optarg)
     if (gkey) { GRN_FREE(gkey); }
     return NULL;
   }
-  memcpy(&h, s, sizeof(grn_hash));
+  grn_memcpy(&h, s, sizeof(grn_hash));
   g = s;
   s = &h;
   if (grn_rhash_init(ctx, g, unit, rsize, s->record_unit, s->key_size, limit)) {

  Modified: lib/ii.c (+12 -12)
===================================================================
--- lib/ii.c    2015-04-15 18:11:18 +0900 (a6e66f5)
+++ lib/ii.c    2015-04-15 20:40:28 +0900 (7c8247f)
@@ -1409,7 +1409,7 @@ pack(uint32_t *p, uint32_t i, uint8_t *freq, uint8_t *rp)
     }
   }
   rp = pack_(p - i, i, w, rp);
-  memcpy(rp, ebuf, ep - ebuf);
+  grn_memcpy(rp, ebuf, ep - ebuf);
   return rp + (ep - ebuf);
 }
 
@@ -1561,7 +1561,7 @@ grn_p_encv(grn_ctx *ctx, datavec *dv, uint32_t dvlen, uint8_t *res)
   case 0x08 : \
     if (_v == 0x8f) { \
       if (_p + sizeof(uint32_t) > pe) { return 0; } \
-      memcpy(&_v, _p, sizeof(uint32_t)); \
+      grn_memcpy(&_v, _p, sizeof(uint32_t)); \
       _p += sizeof(uint32_t); \
     } \
     break; \
@@ -2005,7 +2005,7 @@ buffer_put(grn_ctx *ctx, grn_ii *ii, buffer *b, buffer_term *bt,
   buffer_rec *r_curr, *r_start = NULL;
   uint16_t last = 0, *lastp = &bt->pos_in_buffer, pos = BUFFER_REC_POS(b, rnew);
   int vdelta = 0, delta, delta0 = 0, vhops = 0, nhops = 0, reset = 1;
-  memcpy(NEXT_ADDR(rnew), bs, size - sizeof(buffer_rec));
+  grn_memcpy(NEXT_ADDR(rnew), bs, size - sizeof(buffer_rec));
   for (;;) {
     if (!*lastp) {
       rnew->step = 0;
@@ -2469,7 +2469,7 @@ chunk_flush(grn_ctx *ctx, grn_ii *ii, chunk_info *cinfo, uint8_t *enc, uint32_t
   if (encsize) {
     if (!(rc = chunk_new(ctx, ii, &dcn, encsize))) {
       if ((dc = WIN_MAP(ii->chunk, ctx, &dw, dcn, 0, encsize, grn_io_wronly))) {
-        memcpy(dc, enc, encsize);
+        grn_memcpy(dc, enc, encsize);
         grn_io_win_unmap(&dw);
         cinfo->segno = dcn;
         cinfo->size = encsize;
@@ -2613,7 +2613,7 @@ buffer_merge(grn_ctx *ctx, grn_ii *ii, uint32_t seg, grn_hash *h,
     if (!bt->pos_in_buffer) {
       GRN_ASSERT(!bt->size_in_buffer);
       if (bt->size_in_chunk) {
-        memcpy(dcp, sc + bt->pos_in_chunk, bt->size_in_chunk);
+        grn_memcpy(dcp, sc + bt->pos_in_chunk, bt->size_in_chunk);
         bt->pos_in_chunk = (uint32_t)(dcp - dc);
         dcp += bt->size_in_chunk;
       }
@@ -2891,7 +2891,7 @@ buffer_flush(grn_ctx *ctx, grn_ii *ii, uint32_t seg, grn_hash *h)
                           sb->header.chunk_size, grn_io_rdonly))) {
           uint16_t n = sb->header.nterms;
           memset(db, 0, S_SEGMENT);
-          memcpy(db->terms, sb->terms, n * sizeof(buffer_term));
+          grn_memcpy(db->terms, sb->terms, n * sizeof(buffer_term));
           db->header.nterms = n;
           if (!(rc = buffer_merge(ctx, ii, seg, h, sb, sc, db, dc))) {
             actual_chunk_size = db->header.chunk_size;
@@ -3169,7 +3169,7 @@ term_split(grn_ctx *ctx, grn_obj *lexicon, buffer *sb, buffer *db0, buffer *db1)
   bt = db0->terms;
   nt = &db0->header.nterms;
   for (s = 0; n + 1 < i && s <= th; n++, bt++) {
-    memcpy(bt, ts[n].bt, sizeof(buffer_term));
+    grn_memcpy(bt, ts[n].bt, sizeof(buffer_term));
     (*nt)++;
     s += ts[n].bt->size_in_chunk + 1;
   }
@@ -3177,7 +3177,7 @@ term_split(grn_ctx *ctx, grn_obj *lexicon, buffer *sb, buffer *db0, buffer *db1)
   bt = db1->terms;
   nt = &db1->header.nterms;
   for (; n < i; n++, bt++) {
-    memcpy(bt, ts[n].bt, sizeof(buffer_term));
+    grn_memcpy(bt, ts[n].bt, sizeof(buffer_term));
     (*nt)++;
   }
   GRN_FREE(ts);
@@ -7087,7 +7087,7 @@ encode_terms(grn_ctx *ctx, grn_ii_buffer *ii_buffer,
     }
     if (outbufp_ + II_BUFFER_BLOCK_READ_UNIT_SIZE < outbufp) {
       uint32_t size = outbufp - outbufp_ + sizeof(uint32_t);
-      memcpy(pnext, &size, sizeof(uint32_t));
+      grn_memcpy(pnext, &size, sizeof(uint32_t));
       pnext = outbufp;
       outbufp += sizeof(uint32_t);
       outbufp_ = outbufp;
@@ -7096,7 +7096,7 @@ encode_terms(grn_ctx *ctx, grn_ii_buffer *ii_buffer,
   grn_table_cursor_close(ctx, tc);
   if (outbufp_ < outbufp) {
     uint32_t size = outbufp - outbufp_;
-    memcpy(pnext, &size, sizeof(uint32_t));
+    grn_memcpy(pnext, &size, sizeof(uint32_t));
   }
   return outbufp - outbuf;
 }
@@ -7405,8 +7405,8 @@ grn_ii_buffer_fetch(grn_ctx *ctx, grn_ii_buffer *ii_buffer,
         block->nextsize = 0;
       } else {
         block->rest = block->nextsize - sizeof(uint32_t);
-        memcpy(&block->nextsize,
-               &block->buffer[block->rest], sizeof(uint32_t));
+        grn_memcpy(&block->nextsize,
+                   &block->buffer[block->rest], sizeof(uint32_t));
       }
     }
   }

  Modified: lib/io.c (+8 -8)
===================================================================
--- lib/io.c    2015-04-15 18:11:18 +0900 (f8d13ff)
+++ lib/io.c    2015-04-15 20:40:28 +0900 (d93e836)
@@ -194,7 +194,7 @@ grn_io_create_tmp(uint32_t header_size, uint32_t segment_size,
     header->n_arrays = 0;
     header->flags = flags;
     header->lock = 0;
-    memcpy(header->idstr, GRN_IO_IDSTR, 16);
+    grn_memcpy(header->idstr, GRN_IO_IDSTR, 16);
     if ((io = GRN_GMALLOCN(grn_io, 1))) {
       grn_io_mapinfo *maps = NULL;
       if ((maps = GRN_GCALLOC(sizeof(grn_io_mapinfo) * max_segment))) {
@@ -294,7 +294,7 @@ grn_io_create(grn_ctx *ctx, const char *path, uint32_t header_size, uint32_t seg
         header->n_arrays = 0;
         header->flags = flags;
         header->lock = 0;
-        memcpy(header->idstr, GRN_IO_IDSTR, 16);
+        grn_memcpy(header->idstr, GRN_IO_IDSTR, 16);
         grn_msync(ctx, header, b);
         if ((io = GRN_GMALLOCN(grn_io, 1))) {
           grn_io_mapinfo *maps = NULL;
@@ -395,7 +395,7 @@ grn_io_create_with_array(grn_ctx *ctx, const char *path,
     if ((io = grn_io_create(ctx, path, header_size + hsize,
                             segment_size, nsegs, mode, GRN_IO_EXPIRE_GTICK))) {
       hp = io->user_header;
-      memcpy(hp, array_specs, sizeof(grn_io_array_spec) * n_arrays);
+      grn_memcpy(hp, array_specs, sizeof(grn_io_array_spec) * n_arrays);
       io->header->n_arrays = n_arrays;
       io->header->segment_tail = 1;
       if (!array_init_(io, n_arrays, hsize, msize)) {
@@ -547,7 +547,7 @@ grn_io_open(grn_ctx *ctx, const char *path, grn_io_mode mode)
         return NULL;
       }
       grn_fileinfo_init(fis, max_nfiles);
-      memcpy(fis, &fi, sizeof(fileinfo));
+      grn_memcpy(fis, &fi, sizeof(fileinfo));
       if ((io = GRN_GMALLOC(sizeof(grn_io)))) {
         grn_io_mapinfo *maps = NULL;
         if ((maps = GRN_GCALLOC(sizeof(grn_io_mapinfo) * max_segment))) {
@@ -671,7 +671,7 @@ inline static void
 gen_pathname(const char *path, char *buffer, int fno)
 {
   size_t len = strlen(path);
-  memcpy(buffer, path, len);
+  grn_memcpy(buffer, path, len);
   if (fno) {
     buffer[len] = '.';
     grn_itoh(fno, buffer + len + 1, 3);
@@ -890,7 +890,7 @@ grn_io_write_ja(grn_io *io, grn_ctx *ctx, uint32_t key,
     ja_element je;
     je.head.size = value_len;
     je.head.key = key;
-    memcpy(je.body, value, value_len);
+    grn_memcpy(je.body, value, value_len);
     rc = grn_pwrite(ctx, fi, &je, size, pos);
   } else {
     grn_io_ja_ehead eh;
@@ -987,7 +987,7 @@ grn_io_win_map(grn_io *io, grn_ctx *ctx, grn_io_win *iw, uint32_t segment,
             return NULL;
           }
           s = (offset + r > segment_size) ? segment_size - offset : r;
-          memcpy(p, q + offset, s);
+          grn_memcpy(p, q + offset, s);
           GRN_IO_SEG_UNREF(io, segment);
         }
       }
@@ -1027,7 +1027,7 @@ grn_io_win_unmap(grn_io_win *iw)
           GRN_IO_SEG_REF(io, segment, q);
           if (!q) { return GRN_NO_MEMORY_AVAILABLE; }
           s = (offset + r > segment_size) ? segment_size - offset : r;
-          memcpy(q + offset, p, s);
+          grn_memcpy(q + offset, p, s);
           GRN_IO_SEG_UNREF(io, segment);
         }
       }

  Modified: lib/logger.c (+3 -2)
===================================================================
--- lib/logger.c    2015-04-15 18:11:18 +0900 (f7a3cd3)
+++ lib/logger.c    2015-04-15 20:40:28 +0900 (b42733a)
@@ -300,7 +300,7 @@ grn_logger_init(void)
   if (!default_logger_path) {
     default_logger_path = strdup(GRN_LOG_PATH);
   }
-  memcpy(&current_logger, &default_logger, sizeof(grn_logger));
+  grn_memcpy(&current_logger, &default_logger, sizeof(grn_logger));
   CRITICAL_SECTION_INIT(default_logger_lock);
 }
 
@@ -531,7 +531,8 @@ grn_query_logger_put(grn_ctx *ctx, unsigned int flag, const char *mark,
 void
 grn_query_logger_init(void)
 {
-  memcpy(&current_query_logger, &default_query_logger, sizeof(grn_query_logger));
+  grn_memcpy(&current_query_logger,
+             &default_query_logger, sizeof(grn_query_logger));
   CRITICAL_SECTION_INIT(default_query_logger_lock);
 }
 

  Modified: lib/normalizer.c (+1 -1)
===================================================================
--- lib/normalizer.c    2015-04-15 18:11:18 +0900 (27d34a4)
+++ lib/normalizer.c    2015-04-15 20:40:28 +0900 (5999bf6)
@@ -728,7 +728,7 @@ utf8_normalize(grn_ctx *ctx, grn_string *nstr)
             nstr->ctypes = ctypes;
           }
         }
-        memcpy(d, p, lp);
+        grn_memcpy(d, p, lp);
         d_ = d;
         d += lp;
         length++;

  Modified: lib/pat.c (+9 -9)
===================================================================
--- lib/pat.c    2015-04-15 18:11:18 +0900 (add8469)
+++ lib/pat.c    2015-04-15 20:40:28 +0900 (c5dacc0)
@@ -202,7 +202,7 @@ key_put(grn_ctx *ctx, grn_pat *pat, const uint8_t *key, int len)
     uint8_t *dest;
     KEY_AT(pat, res, dest, GRN_TABLE_ADD);
     if (!dest) { return 0; }
-    memcpy(dest, key, len);
+    grn_memcpy(dest, key, len);
   }
   pat->header->curr_key += len;
   return res;
@@ -227,7 +227,7 @@ pat_node_set_key(grn_ctx *ctx, grn_pat *pat, pat_node *n, const uint8_t *key, un
   PAT_LEN_SET(n, len);
   if (len <= sizeof(uint32_t)) {
     PAT_IMD_ON(n);
-    memcpy(&n->key, key, len);
+    grn_memcpy(&n->key, key, len);
   } else {
     PAT_IMD_OFF(n);
     n->key = key_put(ctx, pat, key, len);
@@ -725,7 +725,7 @@ _grn_pat_add(grn_ctx *ctx, grn_pat *pat, const uint8_t *key, uint32_t size, uint
         pat->header->garbages[size2] = rn->lr[0];
         if (!(keybuf = pat_node_get_key(ctx, pat, rn))) { return 0; }
         PAT_LEN_SET(rn, size);
-        memcpy(keybuf, key, size);
+        grn_memcpy(keybuf, key, size);
       } else {
         if (!(rn = pat_node_new(ctx, pat, &r))) { return 0; }
         pat_node_set_key(ctx, pat, rn, key, size);
@@ -1295,7 +1295,7 @@ grn_pat_get_key(grn_ctx *ctx, grn_pat *pat, grn_id id, void *keybuf, int bufsize
     if (KEY_NEEDS_CONVERT(pat, len)) {
       KEY_DEC(pat, keybuf, key, len);
     } else {
-      memcpy(keybuf, key, len);
+      grn_memcpy(keybuf, key, len);
     }
   }
   return len;
@@ -1341,9 +1341,9 @@ grn_pat_get_value(grn_ctx *ctx, grn_pat *pat, grn_id id, void *valuebuf)
     if (v) {
       if (valuebuf) {
         if (pat->obj.header.flags & GRN_OBJ_KEY_WITH_SIS) {
-          memcpy(valuebuf, v + sizeof(sis_node), value_size);
+          grn_memcpy(valuebuf, v + sizeof(sis_node), value_size);
         } else {
-          memcpy(valuebuf, v, value_size);
+          grn_memcpy(valuebuf, v, value_size);
         }
       }
       return value_size;
@@ -1377,7 +1377,7 @@ grn_pat_set_value(grn_ctx *ctx, grn_pat *pat, grn_id id,
         if (pat->obj.header.flags & GRN_OBJ_KEY_WITH_SIS) { v += sizeof(sis_node); }
         switch ((flags & GRN_OBJ_SET_MASK)) {
         case GRN_OBJ_SET :
-          memcpy(v, value, value_size);
+          grn_memcpy(v, value, value_size);
           return GRN_SUCCESS;
         case GRN_OBJ_INCR :
           switch (value_size) {
@@ -2773,7 +2773,7 @@ rk_emit(rk_tree_node *rn, char **str)
 #define RK_OUTPUT(e,l) do {\
   if (oc < oe) {\
     uint32_t l_ = (oc + (l) < oe) ? (l) : (oe - oc);\
-    memcpy(oc, (e), l_);\
+    grn_memcpy(oc, (e), l_);\
     oc += l_;\
     ic_ = ic;\
   }\
@@ -2863,7 +2863,7 @@ search_push(grn_ctx *ctx, grn_pat *pat, grn_pat_cursor *c,
           if (l + key_len <= GRN_TABLE_MAX_KEY_SIZE) {
             int ch = c0;
             grn_id i;
-            memcpy(key + key_len, e, l);
+            grn_memcpy(key + key_len, e, l);
             if ((i = sub_search(ctx, pat, id, &ch, key, key_len + l))) {
               search_push(ctx, pat, c, key, key_len + l, rn->next, i, ch, flags);
             }

  Modified: lib/plugin.c (+2 -2)
===================================================================
--- lib/plugin.c    2015-04-15 18:11:18 +0900 (71a835f)
+++ lib/plugin.c    2015-04-15 20:40:28 +0900 (a0d119c)
@@ -272,7 +272,7 @@ grn_plugin_open_mrb(grn_ctx *ctx, const char *filename, size_t filename_size)
     return GRN_ID_NIL;
   }
 
-  memcpy((*plugin)->path, filename, filename_size);
+  grn_memcpy((*plugin)->path, filename, filename_size);
   (*plugin)->dl = NULL;
   (*plugin)->init_func = NULL;
   (*plugin)->register_func = NULL;
@@ -318,7 +318,7 @@ grn_plugin_open(grn_ctx *ctx, const char *filename)
                            (void **)&plugin, NULL))) {
       *plugin = GRN_GMALLOCN(grn_plugin, 1);
       if (*plugin) {
-        memcpy((*plugin)->path, filename, filename_size);
+        grn_memcpy((*plugin)->path, filename, filename_size);
         if (grn_plugin_initialize(ctx, *plugin, dl, id, filename)) {
           GRN_GFREE(*plugin);
           *plugin = NULL;

  Modified: lib/proc.c (+26 -21)
===================================================================
--- lib/proc.c    2015-04-15 18:11:18 +0900 (acf01b9)
+++ lib/proc.c    2015-04-15 20:40:28 +0900 (dfcf010)
@@ -889,49 +889,54 @@ grn_select(grn_ctx *ctx, const char *table, unsigned int table_len,
   if (cache_key_size <= GRN_CACHE_MAX_KEY_SIZE) {
     grn_obj *cache_value;
     char *cp = cache_key;
-    memcpy(cp, table, table_len);
+    grn_memcpy(cp, table, table_len);
     cp += table_len; *cp++ = '\0';
-    memcpy(cp, match_columns, match_columns_len);
+    grn_memcpy(cp, match_columns, match_columns_len);
     cp += match_columns_len; *cp++ = '\0';
-    memcpy(cp, query, query_len);
+    grn_memcpy(cp, query, query_len);
     cp += query_len; *cp++ = '\0';
-    memcpy(cp, filter, filter_len);
+    grn_memcpy(cp, filter, filter_len);
     cp += filter_len; *cp++ = '\0';
-    memcpy(cp, scorer, scorer_len);
+    grn_memcpy(cp, scorer, scorer_len);
     cp += scorer_len; *cp++ = '\0';
-    memcpy(cp, sortby, sortby_len);
+    grn_memcpy(cp, sortby, sortby_len);
     cp += sortby_len; *cp++ = '\0';
-    memcpy(cp, output_columns, output_columns_len);
+    grn_memcpy(cp, output_columns, output_columns_len);
     cp += output_columns_len; *cp++ = '\0';
     {
       unsigned int i;
       for (i = 0; i < n_drilldowns; i++) {
         drilldown_info *drilldown = &(drilldowns[i]);
-        memcpy(cp, drilldown->keys, drilldown->keys_len);
+        grn_memcpy(cp, drilldown->keys, drilldown->keys_len);
         cp += drilldown->keys_len; *cp++ = '\0';
-        memcpy(cp, drilldown->sortby, drilldown->sortby_len);
+        grn_memcpy(cp, drilldown->sortby, drilldown->sortby_len);
         cp += drilldown->sortby_len; *cp++ = '\0';
-        memcpy(cp, drilldown->output_columns, drilldown->output_columns_len);
+        grn_memcpy(cp, drilldown->output_columns, drilldown->output_columns_len);
         cp += drilldown->output_columns_len; *cp++ = '\0';
       }
     }
-    memcpy(cp, match_escalation_threshold, match_escalation_threshold_len);
+    grn_memcpy(cp, match_escalation_threshold, match_escalation_threshold_len);
     cp += match_escalation_threshold_len; *cp++ = '\0';
-    memcpy(cp, query_expander, query_expander_len);
+    grn_memcpy(cp, query_expander, query_expander_len);
     cp += query_expander_len; *cp++ = '\0';
-    memcpy(cp, query_flags, query_flags_len);
+    grn_memcpy(cp, query_flags, query_flags_len);
     cp += query_flags_len; *cp++ = '\0';
-    memcpy(cp, adjuster, adjuster_len);
+    grn_memcpy(cp, adjuster, adjuster_len);
     cp += adjuster_len; *cp++ = '\0';
-    memcpy(cp, &output_type, sizeof(grn_content_type)); cp += sizeof(grn_content_type);
-    memcpy(cp, &offset, sizeof(int)); cp += sizeof(int);
-    memcpy(cp, &limit, sizeof(int)); cp += sizeof(int);
+    grn_memcpy(cp, &output_type, sizeof(grn_content_type));
+    cp += sizeof(grn_content_type);
+    grn_memcpy(cp, &offset, sizeof(int));
+    cp += sizeof(int);
+    grn_memcpy(cp, &limit, sizeof(int));
+    cp += sizeof(int);
     {
       unsigned int i;
       for (i = 0; i < n_drilldowns; i++) {
         drilldown_info *drilldown = &(drilldowns[i]);
-        memcpy(cp, &(drilldown->offset), sizeof(int)); cp += sizeof(int);
-        memcpy(cp, &(drilldown->limit), sizeof(int)); cp += sizeof(int);
+        grn_memcpy(cp, &(drilldown->offset), sizeof(int));
+        cp += sizeof(int);
+        grn_memcpy(cp, &(drilldown->limit), sizeof(int));
+        cp += sizeof(int);
       }
     }
     cache_value = grn_cache_fetch(ctx, cache_obj, cache_key, cache_key_size);
@@ -1942,7 +1947,7 @@ proc_column_remove(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_
 
   if ((fullname_len = grn_obj_name(ctx, table, fullname, GRN_TABLE_MAX_KEY_SIZE))) {
     fullname[fullname_len] = GRN_DB_DELIMITER;
-    memcpy((fullname + fullname_len + 1), colname, colname_len);
+    grn_memcpy((fullname + fullname_len + 1), colname, colname_len);
     fullname_len += colname_len + 1;
     //TODO:check fullname_len < GRN_TABLE_MAX_KEY_SIZE
     col = grn_ctx_get(ctx, fullname, fullname_len);
@@ -2335,7 +2340,7 @@ proc_missing(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
   }
   if ((plen = GRN_TEXT_LEN(VAR(0))) + grn_document_root_len < PATH_MAX) {
     char path[PATH_MAX];
-    memcpy(path, grn_document_root, grn_document_root_len);
+    grn_memcpy(path, grn_document_root, grn_document_root_len);
     path[grn_document_root_len] = '/';
     grn_str_url_path_normalize(ctx,
                                GRN_TEXT_VALUE(VAR(0)),

  Modified: lib/snip.c (+7 -4)
===================================================================
--- lib/snip.c    2015-04-15 18:11:18 +0900 (739ee34)
+++ lib/snip.c    2015-04-15 20:40:28 +0900 (da5ba70)
@@ -306,7 +306,7 @@ grn_snip_strndup(grn_ctx *ctx, const char *string, unsigned int string_len)
    if (!copied_string) {
      return NULL;
    }
-   memcpy(copied_string, string, string_len);
+   grn_memcpy(copied_string, string, string_len);
    copied_string[string_len]= '\0'; /* not required, but for ql use */
    return copied_string;
 }
@@ -775,7 +775,9 @@ grn_snip_get_result(grn_ctx *ctx, grn_obj *snip, const unsigned int index, char
       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);
+      grn_memcpy(p,
+                 snip_->tag_result[j].cond->opentag,
+                 snip_->tag_result[j].cond->opentag_len);
       p += snip_->tag_result[j].cond->opentag_len;
     }
 
@@ -820,8 +822,9 @@ grn_snip_get_result(grn_ctx *ctx, grn_obj *snip, const unsigned int index, char
          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);
+        grn_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) {

  Modified: lib/store.c (+23 -19)
===================================================================
--- lib/store.c    2015-04-15 18:11:18 +0900 (6b3b01c)
+++ lib/store.c    2015-04-15 20:40:28 +0900 (527d7ce)
@@ -881,12 +881,12 @@ set_value(grn_ctx *ctx, grn_ja *ja, grn_id id, void *value, uint32_t value_len,
     if ((rc = grn_ja_alloc(ctx, ja, id, value_len + sizeof(uint32_t), einfo, &iw))) {
       return rc;
     }
-    memcpy(iw.addr, value, value_len);
+    grn_memcpy(iw.addr, value, value_len);
     memset((byte *)iw.addr + value_len, 0, sizeof(uint32_t));
     grn_io_win_unmap(&iw);
   } else {
     if ((rc = grn_ja_alloc(ctx, ja, id, value_len, einfo, &iw))) { return rc; }
-    memcpy(iw.addr, value, value_len);
+    grn_memcpy(iw.addr, value, value_len);
     grn_io_win_unmap(&iw);
   }
   return rc;
@@ -935,11 +935,11 @@ grn_ja_put_raw(grn_ctx *ctx, grn_ja *ja, grn_id id,
             GRN_ASSERT(pos < el);
             if (el <= pos + value_len) {
               uint32_t rest = el - pos;
-              memcpy(b + pos, value, rest);
-              memcpy(b, (byte *)value + rest, value_len - rest);
+              grn_memcpy(b + pos, value, rest);
+              grn_memcpy(b, (byte *)value + rest, value_len - rest);
               *((uint32_t *)(b + el)) = value_len - rest;
             } else {
-              memcpy(b + pos, value, value_len);
+              grn_memcpy(b + pos, value, value_len);
               *((uint32_t *)(b + el)) = pos + value_len;
             }
             return GRN_SUCCESS;
@@ -950,8 +950,8 @@ grn_ja_put_raw(grn_ctx *ctx, grn_ja *ja, grn_id id,
               grn_ja_unref(ctx, &jw);
               return rc;
             }
-            memcpy(iw.addr, oldvalue, old_len);
-            memcpy((byte *)iw.addr + old_len, value, value_len);
+            grn_memcpy(iw.addr, oldvalue, old_len);
+            grn_memcpy((byte *)iw.addr + old_len, value, value_len);
             memset((byte *)iw.addr + old_len + value_len, 0, sizeof(uint32_t));
             grn_io_win_unmap(&iw);
           }
@@ -960,8 +960,8 @@ grn_ja_put_raw(grn_ctx *ctx, grn_ja *ja, grn_id id,
             grn_ja_unref(ctx, &jw);
             return rc;
           }
-          memcpy(iw.addr, oldvalue, old_len);
-          memcpy((byte *)iw.addr + old_len, value, value_len);
+          grn_memcpy(iw.addr, oldvalue, old_len);
+          grn_memcpy((byte *)iw.addr + old_len, value, value_len);
           grn_io_win_unmap(&iw);
         }
         grn_ja_unref(ctx, &jw);
@@ -985,11 +985,11 @@ grn_ja_put_raw(grn_ctx *ctx, grn_ja *ja, grn_id id,
             GRN_ASSERT(pos < el);
             if (pos < value_len) {
               uint32_t rest = value_len - pos;
-              memcpy(b, (byte *)value + rest, pos);
-              memcpy(b + el - rest, value, rest);
+              grn_memcpy(b, (byte *)value + rest, pos);
+              grn_memcpy(b + el - rest, value, rest);
               *((uint32_t *)(b + el)) = el - rest;
             } else {
-              memcpy(b + pos - value_len, value, value_len);
+              grn_memcpy(b + pos - value_len, value, value_len);
               *((uint32_t *)(b + el)) = pos - value_len;
             }
             return GRN_SUCCESS;
@@ -1000,8 +1000,8 @@ grn_ja_put_raw(grn_ctx *ctx, grn_ja *ja, grn_id id,
               grn_ja_unref(ctx, &jw);
               return rc;
             }
-            memcpy(iw.addr, value, value_len);
-            memcpy((byte *)iw.addr + value_len, oldvalue, old_len);
+            grn_memcpy(iw.addr, value, value_len);
+            grn_memcpy((byte *)iw.addr + value_len, oldvalue, old_len);
             memset((byte *)iw.addr + value_len + old_len, 0, sizeof(uint32_t));
             grn_io_win_unmap(&iw);
           }
@@ -1010,8 +1010,8 @@ grn_ja_put_raw(grn_ctx *ctx, grn_ja *ja, grn_id id,
             grn_ja_unref(ctx, &jw);
             return rc;
           }
-          memcpy(iw.addr, value, value_len);
-          memcpy((byte *)iw.addr + value_len, oldvalue, old_len);
+          grn_memcpy(iw.addr, value, value_len);
+          grn_memcpy((byte *)iw.addr + value_len, oldvalue, old_len);
           grn_io_win_unmap(&iw);
         }
         grn_ja_unref(ctx, &jw);
@@ -1100,9 +1100,13 @@ grn_ja_putv(grn_ctx *ctx, grn_ja *ja, grn_id id, grn_obj *vector, int flags)
     size_t sizev = body ? GRN_BULK_VSIZE(body) : 0;
     size_t sizef = GRN_BULK_VSIZE(&footer);
     if ((rc = grn_ja_alloc(ctx, ja, id, sizeh + sizev + sizef, &einfo, &iw))) { goto exit; }
-    memcpy(iw.addr, GRN_BULK_HEAD(&header), sizeh);
-    if (body) { memcpy((char *)iw.addr + sizeh, GRN_BULK_HEAD(body), sizev); }
-    if (f) { memcpy((char *)iw.addr + sizeh + sizev, GRN_BULK_HEAD(&footer), sizef); }
+    grn_memcpy(iw.addr, GRN_BULK_HEAD(&header), sizeh);
+    if (body) {
+      grn_memcpy((char *)iw.addr + sizeh, GRN_BULK_HEAD(body), sizev);
+    }
+    if (f) {
+      grn_memcpy((char *)iw.addr + sizeh + sizev, GRN_BULK_HEAD(&footer), sizef);
+    }
     grn_io_win_unmap(&iw);
     rc = grn_ja_replace(ctx, ja, id, &einfo, NULL);
   }

  Modified: lib/str.c (+5 -5)
===================================================================
--- lib/str.c    2015-04-15 18:11:18 +0900 (5945400)
+++ lib/str.c    2015-04-15 20:40:28 +0900 (b33596c)
@@ -538,7 +538,7 @@ normalize_utf8(grn_ctx *ctx, grn_str *nstr)
             nstr->ctypes = ctypes;
           }
         }
-        memcpy(d, p, lp);
+        grn_memcpy(d, p, lp);
         d_ = d;
         d += lp;
         length++;
@@ -1154,7 +1154,7 @@ grn_fakenstr_open(grn_ctx *ctx, const char *str, size_t str_len, grn_encoding en
   }
   nstr->orig = str;
   nstr->orig_blen = str_len;
-  memcpy(nstr->norm, str, str_len);
+  grn_memcpy(nstr->norm, str, str_len);
   nstr->norm[str_len] = '\0';
   nstr->norm_blen = str_len;
   nstr->ctypes = NULL;
@@ -1924,7 +1924,7 @@ grn_bulk_resize(grn_ctx *ctx, grn_obj *buf, unsigned int newsize)
       if (rounded_newsize < newsize) { return GRN_NOT_ENOUGH_SPACE; }
       newsize = rounded_newsize;
       if (!(head = GRN_MALLOC(newsize))) { return GRN_NO_MEMORY_AVAILABLE; }
-      memcpy(head, GRN_BULK_HEAD(buf), GRN_BULK_VSIZE(buf));
+      grn_memcpy(head, GRN_BULK_HEAD(buf), GRN_BULK_VSIZE(buf));
       buf->u.b.curr = head + grn_bulk_margin_size + GRN_BULK_VSIZE(buf);
       buf->u.b.head = head + grn_bulk_margin_size;
       buf->u.b.tail = head + newsize;
@@ -1950,7 +1950,7 @@ grn_bulk_write(grn_ctx *ctx, grn_obj *buf, const char *str, unsigned int len)
     if ((rc = grn_bulk_resize(ctx, buf, GRN_BULK_VSIZE(buf) + len))) { return rc; }
   }
   curr = GRN_BULK_CURR(buf);
-  memcpy(curr, str, len);
+  grn_memcpy(curr, str, len);
   GRN_BULK_INCR_LEN(buf, len);
   return rc;
 }
@@ -3156,7 +3156,7 @@ grn_str_url_path_normalize(grn_ctx *ctx, const char *path, size_t path_len,
       }
     }
     if (be - b >= pc - p) {
-      memcpy(b, p, (pc - p));
+      grn_memcpy(b, p, (pc - p));
       b += pc - p;
       p = pc;
       if (p < pe && *pc == '/' && be > b) {

  Modified: lib/string.c (+2 -2)
===================================================================
--- lib/string.c    2015-04-15 18:11:18 +0900 (b080f3f)
+++ lib/string.c    2015-04-15 20:40:28 +0900 (3249865)
@@ -54,7 +54,7 @@ grn_fake_string_open(grn_ctx *ctx, grn_string *string)
       if (!grn_tokenizer_is_tokenized_delimiter(ctx,
                                                 source_current, char_length,
                                                 ctx->encoding)) {
-        memcpy(destination, source_current, char_length);
+        grn_memcpy(destination, source_current, char_length);
         destination += char_length;
         destination_length += char_length;
       }
@@ -63,7 +63,7 @@ grn_fake_string_open(grn_ctx *ctx, grn_string *string)
     nstr->normalized[destination_length] = '\0';
     nstr->normalized_length_in_bytes = destination_length;
   } else {
-    memcpy(nstr->normalized, str, str_len);
+    grn_memcpy(nstr->normalized, str, str_len);
     nstr->normalized[str_len] = '\0';
     nstr->normalized_length_in_bytes = str_len;
   }

  Modified: lib/tokenizer.c (+1 -1)
===================================================================
--- lib/tokenizer.c    2015-04-15 18:11:18 +0900 (ef9eb5b)
+++ lib/tokenizer.c    2015-04-15 20:40:28 +0900 (e72d3b4)
@@ -167,7 +167,7 @@ grn_tokenizer_query_open(grn_ctx *ctx, int num_args, grn_obj **args,
           return NULL;
         }
         query->normalized_query = normalized_query;
-        memcpy(query_buf, GRN_TEXT_VALUE(query_str), query_length);
+        grn_memcpy(query_buf, GRN_TEXT_VALUE(query_str), query_length);
         query_buf[query_length] = '\0';
         query->query_buf = query_buf;
         query->ptr = query_buf;

  Modified: plugins/query_expanders/tsv.c (+1 -1)
===================================================================
--- plugins/query_expanders/tsv.c    2015-04-15 18:11:18 +0900 (79bd53f)
+++ plugins/query_expanders/tsv.c    2015-04-15 20:40:28 +0900 (ddba662)
@@ -188,7 +188,7 @@ parse_synonyms_file_line(grn_ctx *ctx, const char *line, int line_length,
       grn_bulk_truncate(ctx, value, MAX_SYNONYM_BYTES - 1);
       GRN_TEXT_PUTC(ctx, value, '\0');
     }
-    memcpy(value_location, GRN_TEXT_VALUE(value), GRN_TEXT_LEN(value));
+    grn_memcpy(value_location, GRN_TEXT_VALUE(value), GRN_TEXT_LEN(value));
   }
 }
 
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index