[Groonga-commit] groonga/groonga [master] Use the do/while trick and fix indentation.

Back to archive index

null+****@clear***** null+****@clear*****
2012年 3月 27日 (火) 12:18:55 JST


Susumu Yata	2012-03-27 12:18:55 +0900 (Tue, 27 Mar 2012)

  New Revision: 074a10ed0de676741d6467a970cfe07af0846708

  Log:
    Use the do/while trick and fix indentation.

  Modified files:
    lib/com.h
    lib/ctx.h
    lib/db.h
    lib/hash.h
    lib/ii.h
    lib/io.h
    lib/store.h
    lib/str.h
    lib/token.h

  Modified: lib/com.h (+3 -3)
===================================================================
--- lib/com.h    2012-03-27 12:08:36 +0900 (1c8cd7c)
+++ lib/com.h    2012-03-27 12:18:55 +0900 (193ee17)
@@ -1,5 +1,5 @@
 /* -*- c-basic-offset: 2 -*- */
-/* Copyright(C) 2009-2011 Brazil
+/* Copyright(C) 2009-2012 Brazil
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -59,13 +59,13 @@ struct _grn_com_queue {
   grn_critical_section cs;
 };
 
-#define GRN_COM_QUEUE_INIT(q) {\
+#define GRN_COM_QUEUE_INIT(q) do {\
   (q)->next = NULL;\
   (q)->tail = &(q)->next;\
   (q)->first = 0;\
   (q)->last = 0;\
   CRITICAL_SECTION_INIT((q)->cs);\
-}
+} while (0)
 
 #define GRN_COM_QUEUE_EMPTYP(q) (((q)->first == (q)->last) && !(q)->next)
 

  Modified: lib/ctx.h (+35 -36)
===================================================================
--- lib/ctx.h    2012-03-27 12:08:36 +0900 (f01a617)
+++ lib/ctx.h    2012-03-27 12:18:55 +0900 (1cebf75)
@@ -45,8 +45,7 @@ extern "C" {
 
 /**** api in/out ****/
 
-#define GRN_API_ENTER \
-{\
+#define GRN_API_ENTER do {\
   if ((ctx)->seqno & 1) {\
     (ctx)->subno++;\
   } else {\
@@ -55,11 +54,10 @@ extern "C" {
     (ctx)->seqno++;\
   }\
   GRN_TEST_YIELD();\
-}
+} while (0)
 
 /* CAUTION!! : pass only variables or constants as r */
-#define GRN_API_RETURN(r) \
-{\
+#define GRN_API_RETURN(r) do {\
   if (ctx->subno) {\
     ctx->subno--;\
   } else {\
@@ -67,7 +65,7 @@ extern "C" {
   }\
   GRN_TEST_YIELD();\
   return r;\
-}
+} while (0)
 
 /**** error handling ****/
 
@@ -100,7 +98,7 @@ extern "C" {
 GRN_API void grn_ctx_impl_err(grn_ctx *ctx);
 
 #ifdef HAVE_BACKTRACE
-#define LOGTRACE(ctx,lvl) {\
+#define LOGTRACE(ctx,lvl) do {\
   int i;\
   char **p;\
   BACKTRACE(ctx);\
@@ -109,7 +107,7 @@ GRN_API void grn_ctx_impl_err(grn_ctx *ctx);
     GRN_LOG((ctx), lvl, "%s", p[i]);\
   }\
   free(p);\
-}
+} while (0)
 #else  /* HAVE_BACKTRACE */
 #define LOGTRACE(ctx,msg)
 #endif /* HAVE_BACKTRACE */
@@ -128,7 +126,8 @@ GRN_API void grn_ctx_impl_err(grn_ctx *ctx);
   if (lvl <= GRN_LOG_ERROR) { LOGTRACE(ctx, lvl); }\
 } while (0)
 
-#define ERRP(ctx,lvl) (((ctx) && ((grn_ctx *)(ctx))->errlvl <= (lvl)) || (grn_gctx.errlvl <= (lvl)))
+#define ERRP(ctx,lvl) \
+  (((ctx) && ((grn_ctx *)(ctx))->errlvl <= (lvl)) || (grn_gctx.errlvl <= (lvl)))
 
 #define QLERR(...) do {\
   ERRSET(ctx, GRN_WARN, GRN_INVALID_ARGUMENT, __VA_ARGS__);\
@@ -148,7 +147,7 @@ GRN_API void grn_ctx_impl_err(grn_ctx *ctx);
 #define ALERT(...) ERRSET(ctx, GRN_ALERT, GRN_SUCCESS,  __VA_ARGS__)
 
 #ifdef WIN32
-#define SERR(str) {\
+#define SERR(str) do {\
   grn_rc rc;\
   const char *m;\
   int e = WSAGetLastError();\
@@ -227,9 +226,9 @@ GRN_API void grn_ctx_impl_err(grn_ctx *ctx);
     break;\
   }\
   ERR(rc, "syscall error '%s' (%s)", str, m);\
-}
+} while (0)
 #else /* WIN32 */
-#define SERR(str) {\
+#define SERR(str) do {\
   grn_rc rc;\
   switch (errno) {\
   case ELOOP : rc = GRN_TOO_MANY_SYMBOLIC_LINKS; break;\
@@ -280,23 +279,23 @@ GRN_API void grn_ctx_impl_err(grn_ctx *ctx);
   default : rc = GRN_UNKNOWN_ERROR; break;\
   }\
   ERR(rc, "syscall error '%s' (%s)", str, strerror(errno));\
-}
+} while (0)
 #endif /* WIN32 */
 
 #define GERR(rc,...) ERRSET(&grn_gctx, GRN_ERROR, (rc),  __VA_ARGS__)
-#define GMERR(...) ERRSET(&grn_gctx, GRN_ALERT, GRN_NO_MEMORY_AVAILABLE,  __VA_ARGS__)
-
-#define GRN_MALLOC(s) grn_malloc(ctx,s,__FILE__,__LINE__,__FUNCTION__)
-#define GRN_CALLOC(s) grn_calloc(ctx,s,__FILE__,__LINE__,__FUNCTION__)
-#define GRN_REALLOC(p,s) grn_realloc(ctx,p,s,__FILE__,__LINE__,__FUNCTION__)
-#define GRN_STRDUP(s) grn_strdup(ctx,s,__FILE__,__LINE__,__FUNCTION__)
-#define GRN_GMALLOC(s) grn_malloc(&grn_gctx,s,__FILE__,__LINE__,__FUNCTION__)
-#define GRN_GCALLOC(s) grn_calloc(&grn_gctx,s,__FILE__,__LINE__,__FUNCTION__)
+#define GMERR(...)   ERRSET(&grn_gctx, GRN_ALERT, GRN_NO_MEMORY_AVAILABLE,  __VA_ARGS__)
+
+#define GRN_MALLOC(s)     grn_malloc(ctx,s,__FILE__,__LINE__,__FUNCTION__)
+#define GRN_CALLOC(s)     grn_calloc(ctx,s,__FILE__,__LINE__,__FUNCTION__)
+#define GRN_REALLOC(p,s)  grn_realloc(ctx,p,s,__FILE__,__LINE__,__FUNCTION__)
+#define GRN_STRDUP(s)     grn_strdup(ctx,s,__FILE__,__LINE__,__FUNCTION__)
+#define GRN_GMALLOC(s)    grn_malloc(&grn_gctx,s,__FILE__,__LINE__,__FUNCTION__)
+#define GRN_GCALLOC(s)    grn_calloc(&grn_gctx,s,__FILE__,__LINE__,__FUNCTION__)
 #define GRN_GREALLOC(p,s) grn_realloc(&grn_gctx,p,s,__FILE__,__LINE__,__FUNCTION__)
-#define GRN_GSTRDUP(s) grn_strdup(&grn_gctx,s,__FILE__,__LINE__,__FUNCTION__)
-#define GRN_FREE(p) grn_free(ctx,p,__FILE__,__LINE__,__FUNCTION__)
-#define GRN_MALLOCN(t,n) ((t *)(GRN_MALLOC(sizeof(t) * (n))))
-#define GRN_GFREE(p) grn_free(&grn_gctx,p,__FILE__,__LINE__,__FUNCTION__)
+#define GRN_GSTRDUP(s)    grn_strdup(&grn_gctx,s,__FILE__,__LINE__,__FUNCTION__)
+#define GRN_FREE(p)       grn_free(ctx,p,__FILE__,__LINE__,__FUNCTION__)
+#define GRN_MALLOCN(t,n)  ((t *)(GRN_MALLOC(sizeof(t) * (n))))
+#define GRN_GFREE(p)      grn_free(&grn_gctx,p,__FILE__,__LINE__,__FUNCTION__)
 #define GRN_GMALLOCN(t,n) ((t *)(GRN_GMALLOC(sizeof(t) * (n))))
 
 #ifdef DEBUG
@@ -305,10 +304,10 @@ GRN_API void grn_ctx_impl_err(grn_ctx *ctx);
 #define GRN_ASSERT(s)
 #endif
 
-#define GRN_CTX_ALLOC(ctx,s) grn_ctx_calloc(ctx,s,__FILE__,__LINE__,__FUNCTION__)
-#define GRN_CTX_FREE(ctx,p) grn_ctx_free(ctx,p,__FILE__,__LINE__,__FUNCTION__)
+#define GRN_CTX_ALLOC(ctx,s)   grn_ctx_calloc(ctx,s,__FILE__,__LINE__,__FUNCTION__)
+#define GRN_CTX_FREE(ctx,p)    grn_ctx_free(ctx,p,__FILE__,__LINE__,__FUNCTION__)
 #define GRN_CTX_ALLOC_L(ctx,s) grn_ctx_alloc_lifo(ctx,s,f,__FILE__,__LINE__,__FUNCTION__)
-#define GRN_CTX_FREE_L(ctx,p) grn_ctx_free_lifo(ctx,p,__FILE__,__LINE__,__FUNCTION__)
+#define GRN_CTX_FREE_L(ctx,p)  grn_ctx_free_lifo(ctx,p,__FILE__,__LINE__,__FUNCTION__)
 
 void *grn_ctx_alloc(grn_ctx *ctx, size_t size, int flags,
                     const char* file, int line, const char *func);
@@ -350,11 +349,11 @@ void *grn_calloc(grn_ctx *ctx, size_t size, const char* file, int line, const ch
 void *grn_realloc(grn_ctx *ctx, void *ptr, size_t size, const char* file, int line, const char *func);
 char *grn_strdup(grn_ctx *ctx, const char *s, const char* file, int line, const char *func);
 #else
-#  define grn_malloc grn_malloc_default
-#  define grn_calloc grn_calloc_default
+#  define grn_malloc  grn_malloc_default
+#  define grn_calloc  grn_calloc_default
 #  define grn_realloc grn_realloc_default
-#  define grn_strdup grn_strdup_default
-#  define grn_free grn_free_default
+#  define grn_strdup  grn_strdup_default
+#  define grn_free    grn_free_default
 #endif
 
 GRN_API void *grn_malloc_default(grn_ctx *ctx, size_t size, const char* file, int line, const char *func);
@@ -405,14 +404,14 @@ extern grn_timeval grn_starttime;
 #define GRN_TIME_NSEC_TO_USEC(nsec) ((nsec) / GRN_TIME_NSEC_PER_USEC)
 #define GRN_TIME_USEC_TO_NSEC(usec) ((usec) * GRN_TIME_NSEC_PER_USEC)
 
-#define LAP(prefix,format,...) {\
+#define LAP(prefix,format,...) do {\
   uint64_t et;\
   grn_timeval tv;\
   grn_timeval_now(ctx, &tv);\
   et = (uint64_t)(tv.tv_sec - ctx->impl->tv.tv_sec) * GRN_TIME_NSEC_PER_SEC\
     + (tv.tv_nsec - ctx->impl->tv.tv_nsec);\
   GRN_LOG(ctx, GRN_LOG_NONE, "%08x|" prefix "%015llu " format, (intptr_t)ctx, et, __VA_ARGS__);\
-}
+} while (0)
 
 GRN_API grn_rc grn_timeval_now(grn_ctx *ctx, grn_timeval *tv);
 GRN_API grn_rc grn_timeval2str(grn_ctx *ctx, grn_timeval *tv, char *buf);
@@ -459,7 +458,7 @@ typedef struct {
   //  grn_obj_flags flags;
 } grn_db_obj;
 
-#define GRN_DB_OBJ_SET_TYPE(db_obj,obj_type) {\
+#define GRN_DB_OBJ_SET_TYPE(db_obj,obj_type) do {\
   (db_obj)->obj.header.type = (obj_type);\
   (db_obj)->obj.header.impl_flags = 0;\
   (db_obj)->obj.header.flags = 0;\
@@ -473,7 +472,7 @@ typedef struct {
   (db_obj)->obj.hooks[4] = NULL;\
   (db_obj)->obj.source = NULL;\
   (db_obj)->obj.source_size = 0;\
-}
+} while (0)
 
 /**** cache ****/
 

  Modified: lib/db.h (+8 -5)
===================================================================
--- lib/db.h    2012-03-27 12:08:36 +0900 (845c22f)
+++ lib/db.h    2012-03-27 12:18:55 +0900 (7ac0dcd)
@@ -351,7 +351,10 @@ grn_obj *grn_column_open(grn_ctx *ctx, grn_obj *table,
 grn_rc grn_obj_path_rename(grn_ctx *ctx, const char *old_path, const char *new_path);
 
 grn_rc grn_db_check_name(grn_ctx *ctx, const char *name, unsigned int name_size);
-#define GRN_DB_CHECK_NAME_ERR(error_context, name, name_size) ERR(GRN_INVALID_ARGUMENT, "%s name can't start with '%c' and contains only 0-9, A-Z, a-z, #, @, - or _: <%.*s>", error_context, GRN_DB_PSEUDO_COLUMN_PREFIX, name_size, name)
+#define GRN_DB_CHECK_NAME_ERR(error_context, name, name_size) \
+  ERR(GRN_INVALID_ARGUMENT,\
+       "%s name can't start with '%c' and contains only 0-9, A-Z, a-z, #, @, - or _: <%.*s>",\
+      error_context, GRN_DB_PSEUDO_COLUMN_PREFIX, name_size, name)
 
 #define GRN_DB_P(s) ((s) && ((grn_db *)s)->obj.header.type == GRN_DB)
 #define GRN_DB_PERSISTENT_P(s) (((grn_db *)s)->specs)
@@ -364,7 +367,7 @@ grn_rc grn_db_obj_init(grn_ctx *ctx, grn_obj *db, grn_id id, grn_db_obj *obj);
   ((obj) && (((grn_obj *)(obj))->header.type == GRN_ACCESSOR ||\
              ((grn_obj *)(obj))->header.type == GRN_ACCESSOR_VIEW))
 
-#define GRN_TRUEP(ctx, v, result) {\
+#define GRN_TRUEP(ctx, v, result) do {\
   switch (v->header.type) {                             \
   case GRN_BULK :                                       \
     switch (v->header.domain) {                         \
@@ -399,20 +402,20 @@ grn_rc grn_db_obj_init(grn_ctx *ctx, grn_obj *db, grn_id id, grn_db_obj *obj);
     result = GRN_FALSE;                                 \
     break;                                              \
   }                                                     \
-}
+} while (0)
 
 grn_id grn_obj_register(grn_ctx *ctx, grn_obj *db, const char *name, unsigned int name_size);
 int grn_obj_is_persistent(grn_ctx *ctx, grn_obj *obj);
 void grn_obj_spec_save(grn_ctx *ctx, grn_db_obj *obj);
 
-#define GRN_UINT32_POP(obj,value) {\
+#define GRN_UINT32_POP(obj,value) do {\
   if (GRN_BULK_VSIZE(obj) >= sizeof(uint32_t)) {\
     GRN_BULK_INCR_LEN((obj), -(sizeof(uint32_t)));\
     value = *(uint32_t *)(GRN_BULK_CURR(obj));\
   } else {\
     value = 0;\
   }\
-}
+} while (0)
 
 void grn_expr_pack(grn_ctx *ctx, grn_obj *buf, grn_obj *expr);
 GRN_API grn_rc grn_expr_inspect(grn_ctx *ctx, grn_obj *buf, grn_obj *expr);

  Modified: lib/hash.h (+14 -14)
===================================================================
--- lib/hash.h    2012-03-27 12:08:36 +0900 (3ee04b6)
+++ lib/hash.h    2012-03-27 12:18:55 +0900 (9fc8466)
@@ -1,5 +1,5 @@
 /* -*- c-basic-offset: 2 -*- */
-/* Copyright(C) 2009 Brazil
+/* Copyright(C) 2009-2012 Brazil
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -35,10 +35,10 @@ extern "C" {
 #define GRN_TINY_ARRAY_THREADSAFE (1L<<1)
 #define GRN_TINY_ARRAY_USE_MALLOC (1L<<2)
 
-#define GRN_TINY_ARRAY_W 0
+#define GRN_TINY_ARRAY_W    0
 #define GRN_TINY_ARRAY_R(i) (1<<((i)<<GRN_TINY_ARRAY_W))
-#define GRN_TINY_ARRAY_S (GRN_TINY_ARRAY_R(1)-1)
-#define GRN_TINY_ARRAY_N (32>>GRN_TINY_ARRAY_W)
+#define GRN_TINY_ARRAY_S    (GRN_TINY_ARRAY_R(1)-1)
+#define GRN_TINY_ARRAY_N    (32>>GRN_TINY_ARRAY_W)
 
 typedef struct _grn_tiny_array grn_tiny_array;
 
@@ -100,29 +100,29 @@ struct _grn_tiny_array {
 
 #define GRN_TINY_ARRAY_NEXT(a,e) GRN_TINY_ARRAY_AT((a), (a)->max + 1, e)
 
-#define GRN_TINY_ARRAY_BIT_AT(array,offset,res) {\
+#define GRN_TINY_ARRAY_BIT_AT(array,offset,res) do {\
   uint8_t *ptr_;\
   GRN_TINY_ARRAY_AT((array), ((offset) >> 3) + 1, ptr_);\
   res = ptr_ ? ((*ptr_ >> ((offset) & 7)) & 1) : 0;\
-}
+} while (0)
 
-#define GRN_TINY_ARRAY_BIT_ON(array,offset) {\
+#define GRN_TINY_ARRAY_BIT_ON(array,offset) do {\
   uint8_t *ptr_;\
   GRN_TINY_ARRAY_AT((array), ((offset) >> 3) + 1, ptr_);\
   if (ptr_) { *ptr_ |= (1 << ((offset) & 7)); }\
-}
+} while (0)
 
-#define GRN_TINY_ARRAY_BIT_OFF(array,offset) {\
+#define GRN_TINY_ARRAY_BIT_OFF(array,offset) do {\
   uint8_t *ptr_;\
   GRN_TINY_ARRAY_AT((array), ((offset) >> 3) + 1, ptr_);\
   if (ptr_) { *ptr_ &= ~(1 << ((offset) & 7)); }\
-}
+} while (0)
 
-#define GRN_TINY_ARRAY_BIT_FLIP(array,offset) {\
+#define GRN_TINY_ARRAY_BIT_FLIP(array,offset) do {\
   uint8_t *ptr_;\
   GRN_TINY_ARRAY_AT((array), ((offset) >> 3) + 1, ptr_);\
   if (ptr_) { *ptr_ ^= (1 << ((offset) & 7)); }\
-}
+} while (0)
 
 void grn_tiny_array_init(grn_ctx *ctx, grn_tiny_array *a, uint16_t element_size, uint16_t flags);
 void grn_tiny_array_fin(grn_tiny_array *a);
@@ -131,7 +131,7 @@ grn_id grn_tiny_array_id(grn_tiny_array *a, void *p);
 
 /**** grn_array ****/
 
-#define GRN_ARRAY_TINY                 (0x01<<6)
+#define GRN_ARRAY_TINY        (0x01<<6)
 
 struct _grn_array {
   grn_db_obj obj;
@@ -171,7 +171,7 @@ grn_rc grn_array_copy_sort_key(grn_ctx *ctx, grn_array *array,
 
 /**** grn_hash ****/
 
-#define GRN_HASH_TINY                  (0x01<<6)
+#define GRN_HASH_TINY         (0x01<<6)
 #define GRN_HASH_MAX_KEY_SIZE GRN_TABLE_MAX_KEY_SIZE
 
 struct _grn_hash {

  Modified: lib/ii.h (+7 -7)
===================================================================
--- lib/ii.h    2012-03-27 12:08:36 +0900 (bc2165b)
+++ lib/ii.h    2012-03-27 12:18:55 +0900 (877200f)
@@ -1,5 +1,5 @@
 /* -*- c-basic-offset: 2 -*- */
-/* Copyright(C) 2009 Brazil
+/* Copyright(C) 2009-2012 Brazil
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -51,12 +51,12 @@ struct _grn_ii {
 };
 
 #define GRN_II_BGQSIZE 16
-#define GRN_II_MAX_LSEG                 0x10000
-#define GRN_II_W_TOTAL_CHUNK            40
-#define GRN_II_W_CHUNK                  22
-#define GRN_II_W_LEAST_CHUNK            (GRN_II_W_TOTAL_CHUNK - 32)
-#define GRN_II_MAX_CHUNK                (1 << (GRN_II_W_TOTAL_CHUNK - GRN_II_W_CHUNK))
-#define GRN_II_N_CHUNK_VARIATION        (GRN_II_W_CHUNK - GRN_II_W_LEAST_CHUNK)
+#define GRN_II_MAX_LSEG           0x10000
+#define GRN_II_W_TOTAL_CHUNK      40
+#define GRN_II_W_CHUNK            22
+#define GRN_II_W_LEAST_CHUNK      (GRN_II_W_TOTAL_CHUNK - 32)
+#define GRN_II_MAX_CHUNK          (1 << (GRN_II_W_TOTAL_CHUNK - GRN_II_W_CHUNK))
+#define GRN_II_N_CHUNK_VARIATION  (GRN_II_W_CHUNK - GRN_II_W_LEAST_CHUNK)
 
 struct grn_ii_header {
   uint64_t total_chunk_size;

  Modified: lib/io.h (+28 -32)
===================================================================
--- lib/io.h    2012-03-27 12:08:36 +0900 (38bc749)
+++ lib/io.h    2012-03-27 12:18:55 +0900 (348bc9b)
@@ -1,5 +1,5 @@
 /* -*- c-basic-offset: 2 -*- */
-/* Copyright(C) 2009 Brazil
+/* Copyright(C) 2009-2012 Brazil
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -27,16 +27,16 @@ extern "C" {
 
 #ifdef WIN32
 #ifdef WIN32_FMO_EACH
-#define GRN_IO_FILE_SIZE               1073741824UL
+#define GRN_IO_FILE_SIZE  1073741824UL
 #else /* FMO_EACH */
-#define GRN_IO_FILE_SIZE               134217728L
+#define GRN_IO_FILE_SIZE  134217728L
 #endif /* FMO_EACH */
-#define GRN_IO_COPY grn_io_rdonly
-#define GRN_IO_UPDATE grn_io_wronly
+#define GRN_IO_COPY       grn_io_rdonly
+#define GRN_IO_UPDATE     grn_io_wronly
 #else /* WIN32 */
-#define GRN_IO_FILE_SIZE               1073741824UL
-#define GRN_IO_COPY grn_io_rdwr
-#define GRN_IO_UPDATE grn_io_rdwr
+#define GRN_IO_FILE_SIZE  1073741824UL
+#define GRN_IO_COPY       grn_io_rdwr
+#define GRN_IO_UPDATE     grn_io_rdwr
 #endif /* WIN32 */
 
 typedef enum {
@@ -177,7 +177,7 @@ void grn_io_seg_map_(grn_ctx *ctx, grn_io *io, uint32_t segno, grn_io_mapinfo *i
  * segno must be in valid range;
  * addr must be set NULL;
  */
-#define GRN_IO_SEG_REF(io,segno,addr) {\
+#define GRN_IO_SEG_REF(io,segno,addr) do {\
   grn_io_mapinfo *info = &(io)->maps[segno];\
   uint32_t nref, retry, *pnref = &info->nref;\
   if (io->flags & GRN_IO_EXPIRE_SEGMENT) {\
@@ -268,15 +268,15 @@ void grn_io_seg_map_(grn_ctx *ctx, grn_io *io, uint32_t segno, grn_io_mapinfo *i
     info->count = grn_gtick;\
   }\
   addr = info->map;\
-}
+} while (0)
 
-#define GRN_IO_SEG_UNREF(io,segno) {\
+#define GRN_IO_SEG_UNREF(io,segno) do {\
   if (GRN_IO_EXPIRE_SEGMENT ==\
       (io->flags & (GRN_IO_EXPIRE_GTICK|GRN_IO_EXPIRE_SEGMENT))) {\
     uint32_t nref, *pnref = &(io)->maps[segno].nref;\
     GRN_ATOMIC_ADD_EX(pnref, -1, nref);\
   }\
-}
+} while (0)
 
 uint32_t grn_io_base_seg(grn_io *io);
 const char *grn_io_path(grn_io *io);
@@ -323,33 +323,33 @@ uint32_t grn_io_is_locked(grn_io *io);
           (((offset) & ainfo->elm_mask_in_a_segment) * ainfo->element_size));\
 } while (0)
 
-#define GRN_IO_ARRAY_BIT_AT(io,array,offset,res) {\
+#define GRN_IO_ARRAY_BIT_AT(io,array,offset,res) do {\
   uint8_t *ptr_;\
   int flags_ = 0;\
   GRN_IO_ARRAY_AT((io), (array), ((offset) >> 3) + 1, &flags_, ptr_);\
   res = ptr_ ? ((*ptr_ >> ((offset) & 7)) & 1) : 0;\
-}
+} while (0)
 
-#define GRN_IO_ARRAY_BIT_ON(io,array,offset) {\
+#define GRN_IO_ARRAY_BIT_ON(io,array,offset) do {\
   uint8_t *ptr_;\
   int flags_ = GRN_TABLE_ADD;\
   GRN_IO_ARRAY_AT((io), (array), ((offset) >> 3) + 1, &flags_, ptr_);\
   if (ptr_) { *ptr_ |= (1 << ((offset) & 7)); }\
-}
+} while (0)
 
-#define GRN_IO_ARRAY_BIT_OFF(io,array,offset) {\
+#define GRN_IO_ARRAY_BIT_OFF(io,array,offset) do {\
   uint8_t *ptr_;\
   int flags_ = GRN_TABLE_ADD;\
   GRN_IO_ARRAY_AT((io), (array), ((offset) >> 3) + 1, &flags_, ptr_);\
   if (ptr_) { *ptr_ &= ~(1 << ((offset) & 7)); }\
-}
+} while (0)
 
-#define GRN_IO_ARRAY_BIT_FLIP(io,array,offset) {\
+#define GRN_IO_ARRAY_BIT_FLIP(io,array,offset) do {\
   uint8_t *ptr_;\
   int flags_ = GRN_TABLE_ADD;\
   GRN_IO_ARRAY_AT((io), (array), ((offset) >> 3) + 1, &flags_, ptr_);\
   if (ptr_) { *ptr_ ^= (1 << ((offset) & 7)); }\
-}
+} while (0)
 
 void *grn_io_anon_map(grn_ctx *ctx, grn_io_mapinfo *mi, size_t length);
 void grn_io_anon_unmap(grn_ctx *ctx, grn_io_mapinfo *mi, size_t length);
@@ -365,8 +365,7 @@ uint32_t grn_expire(grn_ctx *ctx, int count_thresh, uint32_t limit);
 
 /* encode/decode */
 
-#define GRN_B_ENC(v,p) \
-{ \
+#define GRN_B_ENC(v,p) do {\
   uint8_t *_p = (uint8_t *)p; \
   uint32_t _v = v; \
   if (_v < 0x8f) { \
@@ -392,13 +391,12 @@ uint32_t grn_expire(grn_ctx *ctx, int count_thresh, uint32_t limit);
     _p += sizeof(uint32_t); \
   } \
   p = _p; \
-}
+} while (0)
 
 #define GRN_B_ENC_SIZE(v) \
  ((v) < 0x8f ? 1 : ((v) < 0x408f ? 2 : ((v) < 0x20408f ? 3 : ((v) < 0x1020408f ? 4 : 5))))
 
-#define GRN_B_DEC(v,p) \
-{ \
+#define GRN_B_DEC(v,p) do { \
   uint8_t *_p = (uint8_t *)p; \
   uint32_t _v = *_p++; \
   switch (_v >> 4) { \
@@ -427,10 +425,9 @@ uint32_t grn_expire(grn_ctx *ctx, int count_thresh, uint32_t limit);
   } \
   v = _v; \
   p = _p; \
-}
+} while (0)
 
-#define GRN_B_SKIP(p) \
-{ \
+#define GRN_B_SKIP(p) do { \
   uint8_t *_p = (uint8_t *)p; \
   uint32_t _v = *_p++; \
   switch (_v >> 4) { \
@@ -454,10 +451,9 @@ uint32_t grn_expire(grn_ctx *ctx, int count_thresh, uint32_t limit);
     break; \
   } \
   p = _p; \
-}
+} while (0)
 
-#define GRN_B_COPY(p2,p1) \
-{ \
+#define GRN_B_COPY(p2,p1) do { \
   uint32_t size = 0, _v = *p1++; \
   *p2++ = _v; \
   switch (_v >> 4) { \
@@ -479,7 +475,7 @@ uint32_t grn_expire(grn_ctx *ctx, int count_thresh, uint32_t limit);
     break; \
   } \
   while (size--) { *p2++ = *p1++; } \
-}
+} while (0)
 
 #ifdef __cplusplus
 }

  Modified: lib/store.h (+7 -5)
===================================================================
--- lib/store.h    2012-03-27 12:08:36 +0900 (71da31e)
+++ lib/store.h    2012-03-27 12:18:55 +0900 (1ce0d16)
@@ -1,5 +1,5 @@
 /* -*- c-basic-offset: 2 -*- */
-/* Copyright(C) 2009 Brazil
+/* Copyright(C) 2009-2012 Brazil
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -70,11 +70,13 @@ struct _grn_ra_cache {
   int32_t seg;
 };
 
-#define GRN_RA_CACHE_INIT(ra,c) \
-{ (c)->p = NULL; (c)->seg = -1; }
+#define GRN_RA_CACHE_INIT(ra,c) do {\
+  (c)->p = NULL; (c)->seg = -1;\
+} while (0)
 
-#define GRN_RA_CACHE_FIN(ra,c) \
-{ if ((c)->seg != -1) { GRN_IO_SEG_UNREF((ra)->io, (c)->seg); }}
+#define GRN_RA_CACHE_FIN(ra,c) do {\
+  if ((c)->seg != -1) { GRN_IO_SEG_UNREF((ra)->io, (c)->seg); }\
+} while (0);
 
 void *grn_ra_ref_cache(grn_ctx *ctx, grn_ra *ra, grn_id id, grn_ra_cache *cache);
 

  Modified: lib/str.h (+7 -7)
===================================================================
--- lib/str.h    2012-03-27 12:08:36 +0900 (efbfff5)
+++ lib/str.h    2012-03-27 12:18:55 +0900 (696c4ec)
@@ -1,5 +1,5 @@
 /* -*- c-basic-offset: 2 -*- */
-/* Copyright(C) 2009 Brazil
+/* Copyright(C) 2009-2012 Brazil
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -46,9 +46,9 @@ typedef struct {
 
 GRN_API size_t grn_str_len(grn_ctx *ctx, const char *str, grn_encoding encoding, const char **last);
 
-#define GRN_STR_BLANK 0x80
+#define GRN_STR_BLANK      0x80
 #define GRN_STR_ISBLANK(c) (c & 0x80)
-#define GRN_STR_CTYPE(c) (c & 0x7f)
+#define GRN_STR_CTYPE(c)   (c & 0x7f)
 
 GRN_API int grn_isspace(const char *s, grn_encoding encoding);
 int8_t grn_atoi8(const char *nptr, const char *end, const char **rest);
@@ -82,21 +82,21 @@ void grn_logger_fin(void);
 GRN_API int grn_charlen_(grn_ctx *ctx, const char *str, const char *end, grn_encoding encoding);
 GRN_API grn_str *grn_str_open_(grn_ctx *ctx, const char *str, unsigned int str_len, int flags, grn_encoding encoding);
 
-#define GRN_BULK_INCR_LEN(buf,len) {\
+#define GRN_BULK_INCR_LEN(buf,len) do {\
   if (GRN_BULK_OUTP(buf)) {\
     (buf)->u.b.curr += (len);\
   } else {\
     (buf)->header.flags += (len);\
   }\
-}
+} while (0)
 
-#define GRN_BULK_SET_CURR(buf,p) {\
+#define GRN_BULK_SET_CURR(buf,p) do {\
   if (GRN_BULK_OUTP(buf)) {\
     (buf)->u.b.curr = (char *)(p);\
   } else {\
     (buf)->header.flags = (char *)(p) - GRN_BULK_HEAD(buf);\
   }\
-}
+} while (0)
 
 grn_rc grn_text_ulltoa(grn_ctx *ctx, grn_obj *buf, unsigned long long int i);
 

  Modified: lib/token.h (+1 -1)
===================================================================
--- lib/token.h    2012-03-27 12:08:36 +0900 (95d768b)
+++ lib/token.h    2012-03-27 12:18:55 +0900 (3d0632f)
@@ -69,7 +69,7 @@ enum {
 #define GRN_TOKEN_LAST      (0x01L<<0)
 #define GRN_TOKEN_OVERLAP   (0x01L<<1)
 #define GRN_TOKEN_UNMATURED (0x01L<<2)
-#define GRN_TOKEN_REACH_END  (0x01L<<3)
+#define GRN_TOKEN_REACH_END (0x01L<<3)
 
 extern grn_obj *grn_uvector_tokenizer;
 




Groonga-commit メーリングリストの案内
Back to archive index