null+****@clear*****
null+****@clear*****
2012年 3月 27日 (火) 13:29:15 JST
Susumu Yata 2012-03-27 13:29:15 +0900 (Tue, 27 Mar 2012)
New Revision: 32b74260029974bcc810760ed22587ea5c572868
Log:
Fix macros.
Modified files:
lib/ctx.c
lib/db.c
lib/expr.c
lib/geo.c
lib/hash.c
lib/ii.c
lib/io.c
lib/pat.c
lib/plugin.c
lib/proc.c
lib/snip.c
lib/store.c
src/groonga.c
src/suggest/groonga_suggest_learner.c
Modified: lib/ctx.c (+10 -12)
===================================================================
--- lib/ctx.c 2012-03-27 12:18:55 +0900 (3ad232f)
+++ lib/ctx.c 2012-03-27 13:29:15 +0900 (f65b1af)
@@ -32,21 +32,19 @@
#define GRN_CTX_INITIALIZER(enc) \
{ GRN_SUCCESS, 0, enc, 0, GRN_LOG_NOTICE,\
- GRN_CTX_FIN, 0, 0, 0, 0, {0}, NULL, NULL, NULL, NULL, NULL }
+ GRN_CTX_FIN, 0, 0, 0, 0, {0}, NULL, NULL, NULL, NULL, NULL }
#define GRN_CTX_CLOSED(ctx) ((ctx)->stat == GRN_CTX_FIN)
#ifdef USE_EXACT_ALLOC_COUNT
-#define GRN_ADD_ALLOC_COUNT(count) \
-{ \
+#define GRN_ADD_ALLOC_COUNT(count) do { \
uint32_t alloced; \
GRN_ATOMIC_ADD_EX(&alloc_count, count, alloced); \
-}
+} while (0)
#else /* USE_EXACT_ALLOC_COUNT */
-#define GRN_ADD_ALLOC_COUNT(count) \
-{ \
+#define GRN_ADD_ALLOC_COUNT(count) do { \
alloc_count += count; \
-}
+} while (0)
#endif
grn_ctx grn_gctx = GRN_CTX_INITIALIZER(GRN_ENC_DEFAULT);
@@ -1154,11 +1152,11 @@ get_command_version(grn_ctx *ctx, const char *p, const char *pe)
}
}
-#define INDEX_HTML "index.html"
-#define OUTPUT_TYPE "output_type"
-#define COMMAND_VERSION "command_version"
-#define EXPR_MISSING "expr_missing"
-#define OUTPUT_TYPE_LEN (sizeof(OUTPUT_TYPE) - 1)
+#define INDEX_HTML "index.html"
+#define OUTPUT_TYPE "output_type"
+#define COMMAND_VERSION "command_version"
+#define EXPR_MISSING "expr_missing"
+#define OUTPUT_TYPE_LEN (sizeof(OUTPUT_TYPE) - 1)
#define COMMAND_VERSION_LEN (sizeof(COMMAND_VERSION) - 1)
static inline int
Modified: lib/db.c (+24 -25)
===================================================================
--- lib/db.c 2012-03-27 12:18:55 +0900 (3792f9a)
+++ lib/db.c 2012-03-27 13:29:15 +0900 (2d0fccc)
@@ -32,7 +32,7 @@
#define NEXT_ADDR(p) (((byte *)(p)) + sizeof *(p))
-#define WITH_NORMALIZE(table,key,key_size,block) {\
+#define WITH_NORMALIZE(table,key,key_size,block) do {\
if ((table)->obj.header.flags & GRN_OBJ_KEY_NORMALIZE) {\
grn_str *nstr;\
if ((nstr = grn_str_open(ctx, key, key_size, GRN_STR_NORMALIZE))) { \
@@ -44,9 +44,9 @@
} else {\
block\
}\
-}
+} while (0)
-#define REPORT_CAST_ERROR(column, range, element) {\
+#define REPORT_CAST_ERROR(column, range, element) do {\
grn_obj inspected;\
char column_name[GRN_TABLE_MAX_KEY_SIZE];\
int column_name_size;\
@@ -63,7 +63,7 @@
range_name_size, range_name,\
GRN_TEXT_LEN(&inspected), GRN_TEXT_VALUE(&inspected));\
GRN_OBJ_FIN(ctx, &inspected);\
-}
+} while (0)
inline static grn_id
grn_table_add_v_inline(grn_ctx *ctx, grn_obj *table, const void *key, int key_size,
@@ -4322,7 +4322,7 @@ grn_obj_is_persistent(grn_ctx *ctx, grn_obj *obj)
return res;
}
-#define SRC2RECORD() {\
+#define SRC2RECORD() do {\
grn_obj *table = grn_ctx_at(ctx, dest->header.domain);\
if (GRN_OBJ_TABLEP(table)) {\
grn_obj *p_key = src;\
@@ -4352,7 +4352,7 @@ grn_obj_is_persistent(grn_ctx *ctx, grn_obj *obj)
} else {\
rc = GRN_FUNCTION_NOT_IMPLEMENTED;\
}\
-}
+} while (0)
#define NUM2DEST(getvalue,totext,tobool,totime)\
switch (dest->header.domain) {\
@@ -4402,7 +4402,7 @@ grn_obj_is_persistent(grn_ctx *ctx, grn_obj *obj)
SRC2RECORD();\
}
-#define TEXT2DEST(type,tonum,setvalue) {\
+#define TEXT2DEST(type,tonum,setvalue) do {\
const char *cur, *str = GRN_TEXT_VALUE(src);\
const char *str_end = GRN_BULK_CURR(src);\
type i = tonum(str, str_end, &cur);\
@@ -4420,14 +4420,13 @@ grn_obj_is_persistent(grn_ctx *ctx, grn_obj *obj)
} else {\
rc = GRN_INVALID_ARGUMENT;\
}\
-}
+} while (0)
#define NUM2BOOL(ctx, dest, value) GRN_BOOL_SET(ctx, dest, value != 0)
-#define FLOAT2BOOL(ctx, dest, value)\
- {\
- double value_ = value;\
- GRN_BOOL_SET(ctx, dest, value_ < -DBL_EPSILON || DBL_EPSILON < value_);\
- }
+#define FLOAT2BOOL(ctx, dest, value) do {\
+ double value_ = value;\
+ GRN_BOOL_SET(ctx, dest, value_ < -DBL_EPSILON || DBL_EPSILON < value_);\
+} while (0)
#define NUM2TIME(ctx, dest, value)\
GRN_TIME_SET(ctx, dest, (long long int)(value) * GRN_TIME_USEC_PER_SEC);
@@ -6662,7 +6661,7 @@ grn_db_obj_init(grn_ctx *ctx, grn_obj *db, grn_id id, grn_db_obj *obj)
return rc;
}
-#define GET_PATH(spec,buffer,s,id) {\
+#define GET_PATH(spec,buffer,s,id) do {\
if (spec->header.flags & GRN_OBJ_CUSTOM_NAME) {\
const char *path;\
unsigned int size = grn_vector_get_element(ctx, &v, 1, &path, NULL, NULL); \
@@ -6672,9 +6671,9 @@ grn_db_obj_init(grn_ctx *ctx, grn_obj *db, grn_id id, grn_db_obj *obj)
} else {\
gen_pathname(grn_obj_io(s->keys)->path, buffer, id); \
}\
-}
+} while (0)
-#define UNPACK_INFO() {\
+#define UNPACK_INFO() do {\
if (vp->ptr) {\
grn_db_obj *r = DB_OBJ(vp->ptr);\
r->header = spec->header;\
@@ -6691,7 +6690,7 @@ grn_db_obj_init(grn_ctx *ctx, grn_obj *db, grn_id id, grn_db_obj *obj)
size = grn_vector_get_element(ctx, &v, 3, &p, NULL, NULL);\
grn_hook_unpack(ctx, r, p, size);\
}\
-}
+} while (0)
grn_obj *
grn_ctx_at(grn_ctx *ctx, grn_id id)
@@ -7047,7 +7046,7 @@ grn_obj_unlink(grn_ctx *ctx, grn_obj *obj)
}
}
-#define VECTOR_CLEAR(ctx,obj) {\
+#define VECTOR_CLEAR(ctx,obj) do {\
if ((obj)->u.v.body && !((obj)->header.impl_flags & GRN_OBJ_REFER)) {\
grn_obj_close((ctx), (obj)->u.v.body);\
}\
@@ -7056,7 +7055,7 @@ grn_obj_unlink(grn_ctx *ctx, grn_obj *obj)
(obj)->u.b.head = NULL;\
(obj)->u.b.curr = NULL;\
(obj)->u.b.tail = NULL;\
-}
+} while (0)
grn_rc
grn_obj_reinit(grn_ctx *ctx, grn_obj *obj, grn_id domain, unsigned char flags)
@@ -7487,7 +7486,7 @@ enum {
KEY_FLOAT64,
};
-#define CMPNUM(type) {\
+#define CMPNUM(type) do {\
if (as) {\
if (bs) {\
type va = *((type *)(ap));\
@@ -7499,7 +7498,7 @@ enum {
} else {\
if (bs) { return 0; }\
}\
-}
+} while (0)
inline static int
compare_value(grn_ctx *ctx, sort_entry *a, sort_entry *b,
@@ -8808,21 +8807,21 @@ brace_close(grn_ctx *ctx, grn_loader *loader)
}
}
-#define JSON_READ_OPEN_BRACKET() {\
+#define JSON_READ_OPEN_BRACKET() do {\
GRN_UINT32_PUT(ctx, &loader->level, loader->values_size);\
values_add(ctx, loader);\
loader->last->header.domain = OPEN_BRACKET;\
loader->stat = GRN_LOADER_TOKEN;\
str++;\
-}\
+} while (0)
-#define JSON_READ_OPEN_BRACE() {\
+#define JSON_READ_OPEN_BRACE() do {\
GRN_UINT32_PUT(ctx, &loader->level, loader->values_size);\
values_add(ctx, loader);\
loader->last->header.domain = OPEN_BRACE;\
loader->stat = GRN_LOADER_TOKEN;\
str++;\
-}\
+} while (0)
static void
json_read(grn_ctx *ctx, grn_loader *loader, const char *str, unsigned int str_len)
Modified: lib/expr.c (+69 -72)
===================================================================
--- lib/expr.c 2012-03-27 12:18:55 +0900 (3c79202)
+++ lib/expr.c 2012-03-27 13:29:15 +0900 (1056884)
@@ -500,7 +500,7 @@ typedef struct {
unsigned char type;
} grn_expr_dfi;
-#define DFI_POP(e,d) {\
+#define DFI_POP(e,d) do {\
if (GRN_BULK_VSIZE(&(e)->dfi) >= sizeof(grn_expr_dfi)) {\
GRN_BULK_INCR_LEN((&(e)->dfi), -(sizeof(grn_expr_dfi)));\
(d) = (grn_expr_dfi *)(GRN_BULK_CURR(&(e)->dfi));\
@@ -509,9 +509,9 @@ typedef struct {
(d) = NULL;\
(e)->code0 = NULL;\
}\
-}
+} while (0)
-#define DFI_PUT(e,t,d,c) {\
+#define DFI_PUT(e,t,d,c) do {\
grn_expr_dfi dfi;\
dfi.type = (t);\
dfi.domain = (d);\
@@ -519,7 +519,7 @@ typedef struct {
if ((e)->code0) { (e)->code0->modify = (c) ? ((c) - (e)->code0) : 0; }\
grn_bulk_write(ctx, &(e)->dfi, (char *)&dfi, sizeof(grn_expr_dfi));\
(e)->code0 = NULL;\
-}
+} while (0)
grn_expr_dfi *
dfi_value_at(grn_expr *expr, int offset)
@@ -595,14 +595,14 @@ exit :
GRN_API_RETURN((grn_obj *)expr);
}
-#define GRN_PTR_POP(obj,value) {\
+#define GRN_PTR_POP(obj,value) do {\
if (GRN_BULK_VSIZE(obj) >= sizeof(grn_obj *)) {\
GRN_BULK_INCR_LEN((obj), -(sizeof(grn_obj *)));\
value = *(grn_obj **)(GRN_BULK_CURR(obj));\
} else {\
value = NULL;\
}\
-}
+} while (0)
grn_rc
grn_expr_close(grn_ctx *ctx, grn_obj *expr)
@@ -736,16 +736,16 @@ grn_expr_get_var_by_offset(grn_ctx *ctx, grn_obj *expr, unsigned int offset)
#define CONSTP(obj) ((obj) && ((obj)->header.impl_flags & GRN_OBJ_EXPRCONST))
-#define PUSH_CODE(e,o,v,n,c) {\
+#define PUSH_CODE(e,o,v,n,c) do {\
(c) = &(e)->codes[e->codes_curr++];\
(c)->value = (v);\
(c)->nargs = (n);\
(c)->op = (o);\
(c)->flags = 0;\
(c)->modify = 0;\
-}
+} while (0)
-#define APPEND_UNARY_MINUS_OP(e) { \
+#define APPEND_UNARY_MINUS_OP(e) do { \
grn_expr_code *code_; \
grn_id domain; \
unsigned char type; \
@@ -786,9 +786,9 @@ grn_expr_get_var_by_offset(grn_ctx *ctx, grn_obj *expr, unsigned int offset)
PUSH_CODE(e, op, obj, nargs, code); \
} \
DFI_PUT(e, type, domain, code_); \
-}
+} while (0)
-#define PUSH_N_ARGS_ARITHMETIC_OP(e, op, obj, nargs, code) { \
+#define PUSH_N_ARGS_ARITHMETIC_OP(e, op, obj, nargs, code) do { \
PUSH_CODE(e, op, obj, nargs, code); \
{ \
int i = nargs; \
@@ -797,7 +797,7 @@ grn_expr_get_var_by_offset(grn_ctx *ctx, grn_obj *expr, unsigned int offset)
} \
} \
DFI_PUT(e, type, domain, code); \
-}
+} while (0)
grn_obj *
grn_expr_append_obj(grn_ctx *ctx, grn_obj *expr, grn_obj *obj, grn_operator op, int nargs)
@@ -1247,7 +1247,7 @@ grn_expr_compile(grn_ctx *ctx, grn_obj *expr)
return ctx->rc;
}
-#define WITH_SPSAVE(block) {\
+#define WITH_SPSAVE(block) do {\
ctx->impl->stack_curr = sp - ctx->impl->stack;\
e->values_curr = vp - e->values;\
block\
@@ -1255,9 +1255,9 @@ grn_expr_compile(grn_ctx *ctx, grn_obj *expr)
sp = ctx->impl->stack + ctx->impl->stack_curr;\
s0 = sp[-1];\
s1 = sp[-2];\
-}
+} while (0)
-#define DO_COMPARE_SUB_NUMERIC(y,op) {\
+#define DO_COMPARE_SUB_NUMERIC(y,op) do {\
switch ((y)->header.domain) {\
case GRN_DB_INT8 :\
r = (x_ op GRN_INT8_VALUE(y));\
@@ -1293,9 +1293,9 @@ grn_expr_compile(grn_ctx *ctx, grn_obj *expr)
r = 0;\
break;\
}\
-}
+} while (0)
-#define DO_COMPARE_SUB(op) {\
+#define DO_COMPARE_SUB(op) do {\
switch (y->header.domain) {\
case GRN_DB_SHORT_TEXT :\
case GRN_DB_TEXT :\
@@ -1315,9 +1315,9 @@ grn_expr_compile(grn_ctx *ctx, grn_obj *expr)
DO_COMPARE_SUB_NUMERIC(y,op);\
break;\
}\
-}
+} while (0)
-#define DO_COMPARE_BUILTIN(x,y,r,op) {\
+#define DO_COMPARE_BUILTIN(x,y,r,op) do {\
switch (x->header.domain) {\
case GRN_DB_INT8 :\
{\
@@ -1434,9 +1434,9 @@ grn_expr_compile(grn_ctx *ctx, grn_obj *expr)
r = 0;\
break;\
}\
-}
+} while (0)
-#define DO_COMPARE(x, y, r, op) {\
+#define DO_COMPARE(x, y, r, op) do {\
if (x->header.domain >= GRN_N_RESERVED_TYPES) {\
grn_obj *table;\
table = grn_ctx_at(ctx, x->header.domain);\
@@ -1467,9 +1467,9 @@ grn_expr_compile(grn_ctx *ctx, grn_obj *expr)
} else {\
DO_COMPARE_BUILTIN(x, y, r, op);\
}\
-}
+} while (0)
-#define DO_EQ_SUB {\
+#define DO_EQ_SUB do {\
switch (y->header.domain) {\
case GRN_DB_INT8 :\
r = (x_ == GRN_INT8_VALUE(y));\
@@ -1514,9 +1514,9 @@ grn_expr_compile(grn_ctx *ctx, grn_obj *expr)
r = 0;\
break;\
}\
-}\
+} while (0)
-#define DO_EQ(x,y,r) {\
+#define DO_EQ(x,y,r) do {\
switch (x->header.domain) {\
case GRN_DB_VOID :\
r = 0;\
@@ -1674,7 +1674,7 @@ grn_expr_compile(grn_ctx *ctx, grn_obj *expr)
}\
break;\
}\
-}
+} while (0)
#define GEO_RESOLUTION 3600000
#define GEO_RADIOUS 6357303
@@ -1686,7 +1686,7 @@ grn_expr_compile(grn_ctx *ctx, grn_obj *expr)
#define GEO_GRS_C3 0.006694
#define GEO_INT2RAD(x) ((M_PI * x) / (GEO_RESOLUTION * 180))
-#define VAR_SET_VALUE(ctx,var,value) {\
+#define VAR_SET_VALUE(ctx,var,value) do {\
if (GRN_DB_OBJP(value)) {\
(var)->header.type = GRN_PTR;\
(var)->header.domain = DB_OBJ(value)->id;\
@@ -1696,7 +1696,7 @@ grn_expr_compile(grn_ctx *ctx, grn_obj *expr)
(var)->header.domain = (value)->header.domain;\
GRN_TEXT_SET(ctx, (var), GRN_TEXT_VALUE(value), GRN_TEXT_LEN(value));\
}\
-}
+} while (0)
grn_rc
grn_proc_call(grn_ctx *ctx, grn_obj *proc, int nargs, grn_obj *caller)
@@ -1726,28 +1726,28 @@ grn_proc_call(grn_ctx *ctx, grn_obj *proc, int nargs, grn_obj *caller)
GRN_API_RETURN(ctx->rc);
}
-#define PUSH1(v) {\
+#define PUSH1(v) do {\
if (EXPRVP(v)) { vp++; }\
s1 = s0;\
*sp++ = s0 = v;\
-}
+} while (0)
-#define POP1(v) {\
+#define POP1(v) do {\
if (EXPRVP(s0)) { vp--; }\
v = s0;\
s0 = s1;\
sp--;\
if (sp < s_) { ERR(GRN_INVALID_ARGUMENT, "stack underflow"); goto exit; }\
s1 = sp[-2];\
-}
+} while (0)
-#define ALLOC1(value) {\
+#define ALLOC1(value) do {\
s1 = s0;\
*sp++ = s0 = value = vp++;\
if (vp - e->values > e->values_tail) { e->values_tail = vp - e->values; }\
-}
+} while (0)
-#define POP1ALLOC1(arg,value) {\
+#define POP1ALLOC1(arg,value) do {\
arg = s0;\
if (EXPRVP(s0)) {\
value = s0;\
@@ -1756,9 +1756,9 @@ grn_proc_call(grn_ctx *ctx, grn_obj *proc, int nargs, grn_obj *caller)
sp[-1] = s0 = value = vp++;\
s0->header.impl_flags |= GRN_OBJ_EXPRVALUE;\
}\
-}
+} while (0)
-#define POP2ALLOC1(arg1,arg2,value) {\
+#define POP2ALLOC1(arg1,arg2,value) do {\
if (EXPRVP(s0)) { vp--; }\
if (EXPRVP(s1)) { vp--; }\
arg2 = s0;\
@@ -1768,7 +1768,7 @@ grn_proc_call(grn_ctx *ctx, grn_obj *proc, int nargs, grn_obj *caller)
s1 = sp[-2];\
sp[-1] = s0 = value = vp++;\
s0->header.impl_flags |= GRN_OBJ_EXPRVALUE;\
-}
+} while (0)
#define INTEGER_ARITHMETIC_OPERATION_PLUS(x, y) ((x) + (y))
#define FLOAT_ARITHMETIC_OPERATION_PLUS(x, y) ((double)(x) + (double)(y))
@@ -1809,8 +1809,7 @@ grn_proc_call(grn_ctx *ctx, grn_obj *proc, int nargs, grn_obj *caller)
#define FLOAT_UNARY_ARITHMETIC_OPERATION_BITWISE_NOT(x) \
(~((long long int)(x)))
-#define TEXT_ARITHMETIC_OPERATION(operator) \
-{ \
+#define TEXT_ARITHMETIC_OPERATION(operator) do { \
long long int x_; \
long long int y_; \
\
@@ -1825,20 +1824,19 @@ grn_proc_call(grn_ctx *ctx, grn_obj *proc, int nargs, grn_obj *caller)
y_ = GRN_INT64_VALUE(res); \
\
GRN_INT64_SET(ctx, res, x_ operator y_); \
-}
+} while (0)
-#define TEXT_UNARY_ARITHMETIC_OPERATION(unary_operator) \
-{ \
- long long int x_; \
- \
- res->header.domain = GRN_DB_INT64; \
- \
- GRN_INT64_SET(ctx, res, 0); \
- grn_obj_cast(ctx, x, res, GRN_FALSE); \
- x_ = GRN_INT64_VALUE(res); \
- \
- GRN_INT64_SET(ctx, res, unary_operator x_); \
-}
+#define TEXT_UNARY_ARITHMETIC_OPERATION(unary_operator) do { \
+ long long int x_; \
+ \
+ res->header.domain = GRN_DB_INT64; \
+ \
+ GRN_INT64_SET(ctx, res, 0); \
+ grn_obj_cast(ctx, x, res, GRN_FALSE); \
+ x_ = GRN_INT64_VALUE(res); \
+ \
+ GRN_INT64_SET(ctx, res, unary_operator x_); \
+} while (0)
#define ARITHMETIC_OPERATION_NO_CHECK(y) do {} while (0)
#define ARITHMETIC_OPERATION_ZERO_DIVISION_CHECK(y) do { \
@@ -1853,7 +1851,7 @@ grn_proc_call(grn_ctx *ctx, grn_obj *proc, int nargs, grn_obj *caller)
integer_operation, \
float_operation, \
right_expression_check, \
- invalid_type_error) { \
+ invalid_type_error) do { \
switch (y->header.domain) { \
case GRN_DB_INT32 : \
{ \
@@ -1920,7 +1918,7 @@ grn_proc_call(grn_ctx *ctx, grn_obj *proc, int nargs, grn_obj *caller)
invalid_type_error; \
break; \
} \
-}
+} while (0)
#define ARITHMETIC_OPERATION_DISPATCH(x, y, res, \
@@ -1930,7 +1928,7 @@ grn_proc_call(grn_ctx *ctx, grn_obj *proc, int nargs, grn_obj *caller)
left_expression_check, \
right_expression_check, \
text_operation, \
- invalid_type_error) { \
+ invalid_type_error) do { \
switch (x->header.domain) { \
case GRN_DB_INT32 : \
{ \
@@ -2026,7 +2024,7 @@ grn_proc_call(grn_ctx *ctx, grn_obj *proc, int nargs, grn_obj *caller)
break; \
} \
code++; \
-}
+} while (0)
#define ARITHMETIC_BINARY_OPERATION_DISPATCH(integer32_operation, \
integer64_operation, \
@@ -2034,7 +2032,7 @@ grn_proc_call(grn_ctx *ctx, grn_obj *proc, int nargs, grn_obj *caller)
left_expression_check, \
right_expression_check, \
text_operation, \
- invalid_type_error) { \
+ invalid_type_error) do { \
grn_obj *x, *y; \
\
POP2ALLOC1(x, y, res); \
@@ -2047,14 +2045,14 @@ grn_proc_call(grn_ctx *ctx, grn_obj *proc, int nargs, grn_obj *caller)
right_expression_check, \
text_operation, \
invalid_type_error); \
-}
+} while (0)
#define ARITHMETIC_UNARY_OPERATION_DISPATCH(integer_operation, \
float_operation, \
left_expression_check, \
right_expression_check, \
text_operation, \
- invalid_type_error) { \
+ invalid_type_error) do { \
grn_obj *x; \
POP1ALLOC1(x, res); \
res->header.domain = x->header.domain; \
@@ -2117,7 +2115,7 @@ grn_proc_call(grn_ctx *ctx, grn_obj *proc, int nargs, grn_obj *caller)
break; \
} \
code++; \
-}
+} while (0)
#define EXEC_OPERATE(operate_sentence, assign_sentence) \
operate_sentence \
@@ -2128,7 +2126,7 @@ grn_proc_call(grn_ctx *ctx, grn_obj *proc, int nargs, grn_obj *caller)
operate_sentence
#define UNARY_OPERATE_AND_ASSIGN_DISPATCH(exec_operate, delta, \
- set_flags) { \
+ set_flags) do { \
grn_obj *var, *col, value; \
grn_id rid; \
\
@@ -2183,15 +2181,14 @@ grn_proc_call(grn_ctx *ctx, grn_obj *proc, int nargs, grn_obj *caller)
exec_operate(grn_obj_set_value(ctx, col, rid, &value, set_flags);, \
grn_obj_get_value(ctx, col, rid, res);); \
code++; \
-}
+} while (0)
#define ARITHMETIC_OPERATION_AND_ASSIGN_DISPATCH(integer32_operation, \
integer64_operation, \
float_operation, \
left_expression_check, \
right_expression_check,\
- text_operation) \
-{ \
+ text_operation) do { \
grn_obj *value, *var, *res; \
if (code->value) { \
value = code->value; \
@@ -2236,7 +2233,7 @@ grn_proc_call(grn_ctx *ctx, grn_obj *proc, int nargs, grn_obj *caller)
ERR(GRN_INVALID_ARGUMENT, "left hand expression isn't column."); \
POP1(res); \
} \
-}
+} while (0)
void
pseudo_query_scan(grn_ctx *ctx, grn_obj *x, grn_obj *y, grn_obj *res)
@@ -3424,13 +3421,13 @@ typedef enum {
SCAN_CONST
} scan_stat;
-#define SI_FREE(si) {\
+#define SI_FREE(si) do {\
GRN_OBJ_FIN(ctx, &(si)->wv);\
GRN_OBJ_FIN(ctx, &(si)->index);\
GRN_FREE(si);\
-}
+} while (0)
-#define SI_ALLOC(si, i, st) {\
+#define SI_ALLOC(si, i, st) do {\
if (!((si) = GRN_MALLOCN(scan_info, 1))) {\
int j;\
for (j = 0; j < i; j++) { SI_FREE(sis[j]); }\
@@ -3443,7 +3440,7 @@ typedef enum {
(si)->flags = SCAN_PUSH;\
(si)->nargs = 0;\
(si)->start = (st);\
-}
+} while (0)
static scan_info **
put_logical_op(grn_ctx *ctx, scan_info **sis, int *ip, grn_operator op, int start)
@@ -3511,14 +3508,14 @@ put_logical_op(grn_ctx *ctx, scan_info **sis, int *ip, grn_operator op, int star
}
-#define EXPRLOG(name,expr) {\
+#define EXPRLOG(name,expr) do {\
grn_obj strbuf;\
GRN_TEXT_INIT(&strbuf, 0);\
grn_expr_inspect(ctx, &strbuf, (expr));\
GRN_TEXT_PUTC(ctx, &strbuf, '\0');\
GRN_LOG(ctx, GRN_LOG_NOTICE, "%s=(%s)", (name), GRN_TEXT_VALUE(&strbuf));\
GRN_OBJ_FIN(ctx, &strbuf);\
-}
+} while (0)
static void
scan_info_put_index(grn_ctx *ctx, scan_info *si, grn_obj *index, uint32_t sid, int32_t weight)
Modified: lib/geo.c (+9 -7)
===================================================================
--- lib/geo.c 2012-03-27 12:18:55 +0900 (564e16a)
+++ lib/geo.c 2012-03-27 13:29:15 +0900 (46d507b)
@@ -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
@@ -198,7 +198,7 @@ inspect_cursor_entry(grn_ctx *ctx, grn_geo_cursor_entry *entry)
printf(" target bit: %d\n", entry->target_bit);
#define INSPECT_STATUS_FLAG(name) \
- (entry->status_flags & GRN_GEO_CURSOR_ENTRY_STATUS_ ## name) ? "true" : "false"
+ ((entry->status_flags & GRN_GEO_CURSOR_ENTRY_STATUS_ ## name) ? "true" : "false")
printf(" top included: %s\n", INSPECT_STATUS_FLAG(TOP_INCLUDED));
printf("bottom included: %s\n", INSPECT_STATUS_FLAG(BOTTOM_INCLUDED));
@@ -404,11 +404,12 @@ grn_geo_get_meshes_for_circle(grn_ctx *ctx, grn_geo_point *base_point,
n_meshes = 0;
-#define add_mesh(lat_diff_,lng_diff_,key_size_)\
+#define add_mesh(lat_diff_,lng_diff_,key_size_) do {\
meshes[n_meshes].key.latitude = geo_base.latitude + (lat_diff_);\
meshes[n_meshes].key.longitude = geo_base.longitude + (lng_diff_);\
meshes[n_meshes].key_size = key_size_;\
- n_meshes++;
+ n_meshes++;\
+} while (0)
if (include_base_point_mesh || position != MESH_LEFT_TOP) {
add_mesh(0, -lng_diff, diff_bit);
@@ -1076,12 +1077,13 @@ exit :
((((uint8_t *)(a))[(n_bit) / 8] & (1 << (7 - ((n_bit) % 8)))) ==\
(((uint8_t *)(b))[(n_bit) / 8] & (1 << (7 - ((n_bit) % 8)))))
-#define CURSOR_ENTRY_UPDATE_STATUS(entry, name, other_key)\
+#define CURSOR_ENTRY_UPDATE_STATUS(entry, name, other_key) do {\
if (SAME_BIT_P((entry)->key, (other_key), (entry)->target_bit)) {\
(entry)->status_flags |= GRN_GEO_CURSOR_ENTRY_STATUS_ ## name;\
} else {\
(entry)->status_flags &= ~GRN_GEO_CURSOR_ENTRY_STATUS_ ## name;\
- }
+ }\
+} while (0)
#define CURSOR_ENTRY_CHECK_STATUS(entry, name)\
((entry)->status_flags & GRN_GEO_CURSOR_ENTRY_STATUS_ ## name)
@@ -1103,7 +1105,7 @@ exit :
GRN_GEO_CURSOR_ENTRY_STATUS_RIGHT_INCLUDED))
#define SET_N_BIT(a, n_bit)\
- ((uint8_t *)(a))[((n_bit) / 8)] ^= (1 << (7 - ((n_bit) % 8)))
+ (((uint8_t *)(a))[((n_bit) / 8)] ^= (1 << (7 - ((n_bit) % 8))))
#define N_BIT(a, n_bit)\
((((uint8_t *)(a))[((n_bit) / 8)] &\
Modified: lib/hash.c (+31 -33)
===================================================================
--- lib/hash.c 2012-03-27 12:18:55 +0900 (6970094)
+++ lib/hash.c 2012-03-27 13:29:15 +0900 (48cca5d)
@@ -79,7 +79,7 @@ grn_tiny_array_id(grn_tiny_array *a, void *p)
/* grn_array */
-#define GRN_ARRAY_HEADER_SIZE 0x9000
+#define GRN_ARRAY_HEADER_SIZE 0x9000
#define GRN_ARRAY_SEGMENT_SIZE 0x400000
struct grn_array_header {
@@ -100,26 +100,26 @@ enum {
#define IO_ARRAYP(array) ((array)->io)
-#define ARRAY_ENTRY_AT_(array,id,value,addp) {\
+#define ARRAY_ENTRY_AT_(array,id,value,addp) do {\
int flags = addp;\
GRN_IO_ARRAY_AT(array->io, array_seg_value, id, &flags, value);\
-}
+} while (0)
-#define ARRAY_ENTRY_AT(array,id,value,addp) {\
+#define ARRAY_ENTRY_AT(array,id,value,addp) do {\
if (IO_ARRAYP(array)) {\
ARRAY_ENTRY_AT_(array, id, value, addp);\
} else {\
GRN_TINY_ARRAY_AT(&array->a, id, value);\
}\
-}
+} while (0)
-#define ARRAY_BITMAP_AT(array,id,value) {\
+#define ARRAY_BITMAP_AT(array,id,value) do {\
if (IO_ARRAYP(array)) {\
GRN_IO_ARRAY_BIT_AT((array)->io, array_seg_bitmap, (id), (value));\
} else {\
GRN_TINY_ARRAY_BIT_AT(&(array)->bitmap, (id), (value));\
}\
-}
+} while (0)
static grn_rc
tiny_array_init(grn_ctx *ctx, grn_array *array, const char *path,
@@ -615,8 +615,8 @@ grn_array_add(grn_ctx *ctx, grn_array *array, void **value)
/* grn_hash : hash table */
-#define GRN_HASH_MAX_SEGMENT 0x400
-#define GRN_HASH_HEADER_SIZE 0x9000
+#define GRN_HASH_MAX_SEGMENT 0x400
+#define GRN_HASH_HEADER_SIZE 0x9000
#define GRN_HASH_SEGMENT_SIZE 0x400000
#define W_OF_KEY_IN_A_SEGMENT 22
#define IDX_MASK_IN_A_SEGMENT 0xfffff
@@ -653,27 +653,27 @@ enum {
segment_bitmap = 3
};
-#define ENTRY_AT_(hash,id,ee,addp) {\
+#define ENTRY_AT_(hash,id,ee,addp) do {\
int flags = addp;\
GRN_IO_ARRAY_AT(hash->io, segment_entry, id, &flags, ee);\
-}
+} while (0)
// todo : error handling
-#define ENTRY_AT(hash,id,ee,addp) {\
+#define ENTRY_AT(hash,id,ee,addp) do {\
if (IO_HASHP(hash)) {\
ENTRY_AT_(hash, id, ee, addp);\
} else {\
GRN_TINY_ARRAY_AT(&hash->a, id, ee);\
}\
-}
+} while (0)
-#define BITMAP_AT(hash,id,value) {\
+#define BITMAP_AT(hash,id,value) do {\
if (IO_HASHP(hash)) {\
GRN_IO_ARRAY_BIT_AT((hash)->io, segment_bitmap, (id), (value));\
} else {\
GRN_TINY_ARRAY_BIT_AT(&(hash)->bitmap, (id), (value));\
}\
-}
+} while (0)
inline static grn_id *
idx_at_(grn_ctx *ctx, grn_hash *hash, grn_id id)
@@ -684,17 +684,15 @@ idx_at_(grn_ctx *ctx, grn_hash *hash, grn_id id)
return pp;
}
-#define IDX_AT(h,i) (\
- IO_HASHP(h) ?\
- idx_at_(ctx, h, ((i) & *(h)->max_offset) + h->header->idx_offset) :\
- h->index + ((i) & *(h)->max_offset)\
-)
+#define IDX_AT(h,i) \
+ (IO_HASHP(h) ?\
+ idx_at_(ctx, h, ((i) & *(h)->max_offset) + h->header->idx_offset) :\
+ h->index + ((i) & *(h)->max_offset))
-#define KEY_AT(hash,pos,ptr) \
-{\
+#define KEY_AT(hash,pos,ptr) do {\
int flags = GRN_TABLE_ADD;\
GRN_IO_ARRAY_AT(hash->io, segment_key, pos, &flags, ptr);\
-}
+} while (0)
#define HASH_IMMEDIATE 1
@@ -1499,7 +1497,7 @@ grn_hash_set_value(grn_ctx *ctx, grn_hash *hash, grn_id id,
return GRN_INVALID_ARGUMENT;
}
-#define DELETE_IT {\
+#define DELETE_IT do {\
*ep = GARBAGE;\
if (IO_HASHP(hash)) {\
uint32_t size = key_size - 1;\
@@ -1519,7 +1517,7 @@ grn_hash_set_value(grn_ctx *ctx, grn_hash *hash, grn_id id,
(*hash->n_entries)--;\
(*hash->n_garbages)++;\
rc = GRN_SUCCESS;\
-}
+} while (0)
grn_rc
grn_hash_delete_by_id(grn_ctx *ctx, grn_hash *hash, grn_id id,
@@ -1777,7 +1775,7 @@ grn_hash_cursor_delete(grn_ctx *ctx, grn_hash_cursor *c,
/* sort */
-#define PREPARE_VAL(e,ep,es) {\
+#define PREPARE_VAL(e,ep,es) do {\
if ((arg->flags & GRN_TABLE_SORT_BY_VALUE)) {\
ep = ((const uint8_t *)(get_value(hash, (entry_str *)(e))));\
es = hash->value_size;\
@@ -1788,7 +1786,7 @@ grn_hash_cursor_delete(grn_ctx *ctx, grn_hash_cursor *c,
}\
ep += arg->offset;\
es -= arg->offset;\
-}
+} while (0)
#define COMPARE_VAL_(ap,as,bp,bs)\
(arg->compar\
@@ -1853,13 +1851,13 @@ swap(entry **a, entry **b)
*b = c_;
}
-#define SWAP(a,ap,as,b,bp,bs) {\
+#define SWAP(a,ap,as,b,bp,bs) do {\
const uint8_t *cp_ = ap;\
uint32_t cs_ = as;\
ap = bp; bp = cp_;\
as = bs; bs = cs_;\
swap(a,b);\
-}
+} while (0)
inline static entry **
part(grn_ctx *ctx, entry **b, entry **e, grn_table_sort_optarg *arg, grn_hash *hash, int dir)
@@ -1935,14 +1933,14 @@ typedef struct {
int32_t v;
} val32;
-#define PREPARE_VAL32(id,e,ep) {\
+#define PREPARE_VAL32(id,e,ep) do {\
(ep)->id = id;\
(ep)->v = (arg->flags & GRN_TABLE_SORT_BY_ID)\
? (int32_t) id\
: (*((int32_t *)((byte *)((arg->flags & GRN_TABLE_SORT_BY_VALUE)\
? get_value(hash, (e))\
: get_key(ctx, hash, (e))) + arg->offset)));\
-}
+} while (0)
#define COMPARE_VAL32_(ap,bp) \
(arg->compar\
@@ -1995,11 +1993,11 @@ pack_val32(grn_ctx *ctx, grn_hash *hash, val32 *res, grn_table_sort_optarg *arg,
return *hash->n_entries > 2 ? head : NULL;
}
-#define SWAP_VAL32(ap,bp) {\
+#define SWAP_VAL32(ap,bp) do {\
val32 cr_ = *ap;\
*ap = *bp;\
*bp = cr_;\
-}
+} while (0)
inline static val32 *
part_val32(grn_ctx *ctx,
Modified: lib/ii.c (+31 -27)
===================================================================
--- lib/ii.c 2012-03-27 12:18:55 +0900 (11aa443)
+++ lib/ii.c 2012-03-27 13:29:15 +0900 (05ad510)
@@ -175,13 +175,13 @@ buffer_segment_reserve(grn_ctx *ctx, grn_ii *ii,
return GRN_SUCCESS;
}
-#define BGQENQUE(lseg) {\
+#define BGQENQUE(lseg) do {\
if (ii->header->binfo[lseg] != NOT_ASSIGNED) {\
ii->header->bgqbody[ii->header->bgqhead] = ii->header->binfo[lseg];\
ii->header->bgqhead = (ii->header->bgqhead + 1) & (GRN_II_BGQSIZE - 1);\
GRN_ASSERT(ii->header->bgqhead != ii->header->bgqtail);\
}\
-}
+} while (0)
inline static void
buffer_segment_update(grn_ii *ii, uint32_t lseg, uint32_t pseg)
@@ -1570,29 +1570,28 @@ grn_p_encv(grn_ctx *ctx, datavec *dv, uint32_t dvlen, uint8_t *res)
return rp - res;
}
-#define GRN_B_DEC_CHECK(v,p,pe) \
-{ \
+#define GRN_B_DEC_CHECK(v,p,pe) do { \
uint8_t *_p = (uint8_t *)p; \
- uint32_t _v;\
- if (_p >= pe) { return 0; }\
- _v = *_p++;\
+ uint32_t _v; \
+ if (_p >= pe) { return 0; } \
+ _v = *_p++; \
switch (_v >> 4) { \
case 0x08 : \
if (_v == 0x8f) { \
- if (_p + sizeof(uint32_t) > pe) { return 0; }\
- memcpy(&_v, _p, sizeof(uint32_t));\
+ if (_p + sizeof(uint32_t) > pe) { return 0; } \
+ memcpy(&_v, _p, sizeof(uint32_t)); \
_p += sizeof(uint32_t); \
} \
break; \
case 0x09 : \
- if (_p + 3 > pe) { return 0; }\
+ if (_p + 3 > pe) { return 0; } \
_v = (_v - 0x90) * 0x100 + *_p++; \
_v = _v * 0x100 + *_p++; \
_v = _v * 0x100 + *_p++ + 0x20408f; \
break; \
case 0x0a : \
case 0x0b : \
- if (_p + 2 > pe) { return 0; }\
+ if (_p + 2 > pe) { return 0; } \
_v = (_v - 0xa0) * 0x100 + *_p++; \
_v = _v * 0x100 + *_p++ + 0x408f; \
break; \
@@ -1600,13 +1599,13 @@ grn_p_encv(grn_ctx *ctx, datavec *dv, uint32_t dvlen, uint8_t *res)
case 0x0d : \
case 0x0e : \
case 0x0f : \
- if (_p + 1 > pe) { return 0; }\
+ if (_p + 1 > pe) { return 0; } \
_v = (_v - 0xc0) * 0x100 + *_p++ + 0x8f; \
break; \
} \
v = _v; \
p = _p; \
-}
+} while (0)
static uint8_t *
unpack(uint8_t *dp, uint8_t *dpe, int i, uint32_t *rp)
@@ -1915,10 +1914,10 @@ typedef struct {
uint32_t sid;
} docid;
-#define BUFFER_REC_DEL(r) ((r)->jump = 1)
+#define BUFFER_REC_DEL(r) ((r)->jump = 1)
#define BUFFER_REC_DELETED(r) ((r)->jump == 1)
-#define BUFFER_REC_AT(b,pos) ((buffer_rec *)(b) + (pos))
+#define BUFFER_REC_AT(b,pos) ((buffer_rec *)(b) + (pos))
#define BUFFER_REC_POS(b,rec) ((uint16_t)((rec) - (buffer_rec *)(b)))
inline static void
@@ -2004,14 +2003,14 @@ set_jump_r(grn_ctx *ctx, grn_ii *ii, buffer *b, buffer_rec *from, int to)
return GRN_SUCCESS;
}
-#define GET_NUM_BITS(x,n) {\
+#define GET_NUM_BITS(x,n) do {\
n = x;\
n = (n & 0x55555555) + ((n >> 1) & 0x55555555);\
n = (n & 0x33333333) + ((n >> 2) & 0x33333333);\
n = (n & 0x0F0F0F0F) + ((n >> 4) & 0x0F0F0F0F);\
n = (n & 0x00FF00FF) + ((n >> 8) & 0x00FF00FF);\
n = (n & 0x0000FFFF) + ((n >>16) & 0x0000FFFF);\
-}
+} while (0)
inline static grn_rc
buffer_put(grn_ctx *ctx, grn_ii *ii, buffer *b, buffer_term *bt,
@@ -2340,7 +2339,7 @@ typedef struct {
uint32_t flags;
} docinfo;
-#define GETNEXTC() {\
+#define GETNEXTC() do {\
if (sdf) {\
uint32_t dgap = *srp++;\
cid.rid += dgap;\
@@ -2357,8 +2356,9 @@ typedef struct {
} else {\
cid.rid = 0;\
}\
-}
-#define PUTNEXT_(id) {\
+} while (0)
+
+#define PUTNEXT_(id) do {\
uint32_t dgap = id.rid - lid.rid;\
uint32_t sgap = (dgap ? id.sid : id.sid - lid.sid) - 1;\
*ridp++ = dgap;\
@@ -2369,8 +2369,9 @@ typedef struct {
if ((ii->header->flags & GRN_OBJ_WITH_WEIGHT)) { *weightp++ = id.weight; }\
lid.rid = id.rid;\
lid.sid = id.sid;\
-}
-#define PUTNEXTC() {\
+} while (0)
+
+#define PUTNEXTC() do {\
if (cid.rid) {\
if (cid.tf) {\
if (lid.rid > cid.rid || (lid.rid == cid.rid && lid.sid >= cid.sid)) {\
@@ -2393,8 +2394,9 @@ typedef struct {
}\
}\
GETNEXTC();\
-}
-#define GETNEXTB() {\
+} while (0)
+
+#define GETNEXTB() do {\
if (nextb) {\
uint32_t lrid = bid.rid, lsid = bid.sid;\
buffer_rec *br = BUFFER_REC_AT(sb, nextb);\
@@ -2414,8 +2416,9 @@ typedef struct {
} else {\
bid.rid = 0;\
}\
-}
-#define PUTNEXTB() {\
+} while (0)
+
+#define PUTNEXTB() do {\
if (bid.rid && bid.sid) {\
GRN_B_DEC(bid.tf, sbp);\
if (bid.tf > 0) {\
@@ -2432,7 +2435,7 @@ typedef struct {
}\
}\
GETNEXTB();\
-}
+} while (0)
#define MERGE_BC(cond) do {\
if (bid.rid) {\
@@ -5971,6 +5974,7 @@ grn_ii_select(grn_ctx *ctx, grn_ii *ii, const char *string, unsigned int string_
}
}
if (noccur && !rep) { res_add(ctx, s, &pi, (noccur + tscore) * weight, op); }
+#undef SKIP_OR_BREAK
}
}
if (token_info_skip(ctx, *tis, nrid, nsid)) { goto exit; }
Modified: lib/io.c (+5 -7)
===================================================================
--- lib/io.c 2012-03-27 12:18:55 +0900 (5f07600)
+++ lib/io.c 2012-03-27 13:29:15 +0900 (ba61024)
@@ -36,7 +36,7 @@
/* VA hack */
/* max aio request (/proc/sys/fs/aio-max-nr) */
-#define MAX_REQUEST (64*1024)
+#define MAX_REQUEST (64*1024)
#define MEM_ALIGN grn_cache_block
@@ -1247,8 +1247,7 @@ grn_io_win_unmap2(grn_io_win *iw)
}
}
-#define DO_MAP(io,fmo,fi,pos,size,segno,res)\
-{\
+#define DO_MAP(io,fmo,fi,pos,size,segno,res) do {\
if (((res) = GRN_MMAP(&grn_gctx, (fmo), (fi), (pos), (size)))) {\
uint32_t nmaps;\
if (io->max_map_seg < segno) { io->max_map_seg = segno; }\
@@ -1258,10 +1257,9 @@ grn_io_win_unmap2(grn_io_win *iw)
if (tail > io->header->curr_size) { io->header->curr_size = tail; }\
}\
}\
-}
+} while (0)
-#define SEG_MAP(io,segno,info)\
-{\
+#define SEG_MAP(io,segno,info) do {\
uint32_t segment_size = io->header->segment_size;\
if ((io->flags & GRN_IO_TEMPORARY)) {\
DO_MAP(io, &info->fmo, NULL, 0, segment_size, segno, info->map);\
@@ -1282,7 +1280,7 @@ grn_io_win_unmap2(grn_io_win *iw)
DO_MAP(io, &info->fmo, fi, pos, segment_size, segno, info->map);\
}\
}\
-}
+} while (0)
void
grn_io_seg_map_(grn_ctx *ctx, grn_io *io, uint32_t segno, grn_io_mapinfo *info)
Modified: lib/pat.c (+16 -16)
===================================================================
--- lib/pat.c 2012-03-27 12:18:55 +0900 (44c9e9d)
+++ lib/pat.c 2012-03-27 13:29:15 +0900 (42b0913)
@@ -107,10 +107,10 @@ enum {
/* patricia array operation */
-#define PAT_AT(pat,id,n) {\
+#define PAT_AT(pat,id,n) do {\
int flags = 0;\
GRN_IO_ARRAY_AT(pat->io, segment_pat, id, &flags, n);\
-}
+} while (0)
inline static pat_node *
pat_get(grn_ctx *ctx, grn_pat *pat, grn_id id)
@@ -182,11 +182,10 @@ sis_collect(grn_ctx *ctx, grn_pat *pat, grn_hash *h, grn_id id, uint32_t level)
/* key operation */
-#define KEY_AT(pat,pos,ptr,addp)\
-{\
+#define KEY_AT(pat,pos,ptr,addp) do {\
int flags = addp;\
GRN_IO_ARRAY_AT(pat->io, segment_key, pos, &flags, ptr);\
-}
+} while (0)
inline static uint32_t
key_put(grn_ctx *ctx, grn_pat *pat, const uint8_t *key, int len)
@@ -746,7 +745,7 @@ chop(grn_ctx *ctx, grn_pat *pat, const char **key, const char *end, uint32_t *lk
#define KEY_NEEDS_CONVERT(pat,size) \
(!((pat)->obj.header.flags & GRN_OBJ_KEY_VAR_SIZE) && (size) <= MAX_FIXED_KEY_SIZE)
-#define KEY_ENC(pat,keybuf,key,size) {\
+#define KEY_ENC(pat,keybuf,key,size) do {\
switch ((pat)->obj.header.flags & GRN_OBJ_KEY_MASK) {\
case GRN_OBJ_KEY_UINT :\
if (((pat)->obj.header.domain != GRN_DB_TOKYO_GEO_POINT) &&\
@@ -769,9 +768,9 @@ chop(grn_ctx *ctx, grn_pat *pat, const char **key, const char *end, uint32_t *lk
}\
break;\
}\
-}
+} while (0)
-#define KEY_DEC(pat,keybuf,key,size) {\
+#define KEY_DEC(pat,keybuf,key,size) do {\
switch ((pat)->obj.header.flags & GRN_OBJ_KEY_MASK) {\
case GRN_OBJ_KEY_UINT :\
if (((pat)->obj.header.domain != GRN_DB_TOKYO_GEO_POINT) &&\
@@ -793,13 +792,14 @@ chop(grn_ctx *ctx, grn_pat *pat, const char **key, const char *end, uint32_t *lk
}\
break;\
}\
-}
+} while (0)
-#define KEY_ENCODE(pat,keybuf,key,size) \
-if (KEY_NEEDS_CONVERT(pat,size)) {\
- KEY_ENC((pat), (keybuf), (key), (size));\
- (key) = (keybuf);\
-}
+#define KEY_ENCODE(pat,keybuf,key,size) do {\
+ if (KEY_NEEDS_CONVERT(pat,size)) {\
+ KEY_ENC((pat), (keybuf), (key), (size));\
+ (key) = (keybuf);\
+ }\
+} while (0)
grn_id
grn_pat_add(grn_ctx *ctx, grn_pat *pat, const void *key, uint32_t key_size,
@@ -2738,14 +2738,14 @@ rk_emit(rk_tree_node *rn, char **str)
}
}
-#define RK_OUTPUT(e,l) {\
+#define RK_OUTPUT(e,l) do {\
if (oc < oe) {\
uint32_t l_ = (oc + (l) < oe) ? (l) : (oe - oc);\
memcpy(oc, (e), l_);\
oc += l_;\
ic_ = ic;\
}\
-}
+} while (0)
static uint32_t
rk_conv(const char *str, uint32_t str_len, char *buf, uint32_t buf_size, uint8_t *statep)
Modified: lib/plugin.c (+25 -24)
===================================================================
--- lib/plugin.c 2012-03-27 12:18:55 +0900 (22de2fa)
+++ lib/plugin.c 2012-03-27 13:29:15 +0900 (062399e)
@@ -32,22 +32,22 @@ static grn_hash *grn_plugins = NULL;
#define PATHLEN(filename) (strlen(filename) + 1)
#ifdef WIN32
-# define grn_dl_open(filename) LoadLibrary(filename)
-# define grn_dl_open_error_label "LoadLibrary"
-# define grn_dl_close(dl) (FreeLibrary(dl) != 0)
-# define grn_dl_close_error_label "FreeLibrary"
-# define grn_dl_sym(dl, symbol) ((void *)GetProcAddress(dl, symbol))
-# define grn_dl_sym_error_label "GetProcAddress"
-# define grn_dl_clear_error
+# define grn_dl_open(filename) LoadLibrary(filename)
+# define grn_dl_open_error_label() "LoadLibrary"
+# define grn_dl_close(dl) (FreeLibrary(dl) != 0)
+# define grn_dl_close_error_label() "FreeLibrary"
+# define grn_dl_sym(dl, symbol) ((void *)GetProcAddress(dl, symbol))
+# define grn_dl_sym_error_label() "GetProcAddress"
+# define grn_dl_clear_error()
#else
# include <dlfcn.h>
-# define grn_dl_open(filename) dlopen(filename, RTLD_LAZY | RTLD_LOCAL)
-# define grn_dl_open_error_label dlerror()
-# define grn_dl_close(dl) (dlclose(dl) == 0)
-# define grn_dl_close_error_label dlerror()
-# define grn_dl_sym(dl, symbol) dlsym(dl, symbol)
-# define grn_dl_sym_error_label dlerror()
-# define grn_dl_clear_error dlerror()
+# define grn_dl_open(filename) dlopen(filename, RTLD_LAZY | RTLD_LOCAL)
+# define grn_dl_open_error_label() dlerror()
+# define grn_dl_close(dl) (dlclose(dl) == 0)
+# define grn_dl_close_error_label() dlerror()
+# define grn_dl_sym(dl, symbol) dlsym(dl, symbol)
+# define grn_dl_sym_error_label() dlerror()
+# define grn_dl_clear_error() dlerror()
#endif
grn_id
@@ -110,14 +110,15 @@ grn_plugin_initialize(grn_ctx *ctx, grn_plugin *plugin,
{
plugin->dl = dl;
-#define GET_SYMBOL(type) \
- grn_dl_clear_error; \
+#define GET_SYMBOL(type) do { \
+ grn_dl_clear_error(); \
plugin->type ## _func = grn_dl_sym(dl, GRN_PLUGIN_FUNC_PREFIX #type); \
if (!plugin->type ## _func) { \
const char *label; \
- label = grn_dl_sym_error_label; \
+ label = grn_dl_sym_error_label(); \
SERR(label); \
- }
+ } \
+} while (0)
GET_SYMBOL(init);
GET_SYMBOL(register);
@@ -176,7 +177,7 @@ grn_plugin_open(grn_ctx *ctx, const char *filename)
ctx->errfile = NULL;
} else {
const char *label;
- label = grn_dl_close_error_label;
+ label = grn_dl_close_error_label();
SERR(label);
}
id = GRN_ID_NIL;
@@ -186,13 +187,13 @@ grn_plugin_open(grn_ctx *ctx, const char *filename)
} else {
if (!grn_dl_close(dl)) {
const char *label;
- label = grn_dl_close_error_label;
+ label = grn_dl_close_error_label();
SERR(label);
}
}
} else {
const char *label;
- label = grn_dl_open_error_label;
+ label = grn_dl_open_error_label();
SERR(label);
}
return id;
@@ -210,7 +211,7 @@ grn_plugin_close(grn_ctx *ctx, grn_id id)
grn_plugin_call_fin(ctx, id);
if (!grn_dl_close(plugin->dl)) {
const char *label;
- label = grn_dl_close_error_label;
+ label = grn_dl_close_error_label();
SERR(label);
}
GRN_GFREE(plugin);
@@ -226,10 +227,10 @@ grn_plugin_sym(grn_ctx *ctx, grn_id id, const char *symbol)
if (!grn_hash_get_value(ctx, grn_plugins, id, &plugin)) {
return NULL;
}
- grn_dl_clear_error;
+ grn_dl_clear_error();
if (!(func = grn_dl_sym(plugin->dl, symbol))) {
const char *label;
- label = grn_dl_sym_error_label;
+ label = grn_dl_sym_error_label();
SERR(label);
}
return func;
Modified: lib/proc.c (+4 -4)
===================================================================
--- lib/proc.c 2012-03-27 12:18:55 +0900 (2a9553f)
+++ lib/proc.c 2012-03-27 13:29:15 +0900 (4a8c8ee)
@@ -2300,14 +2300,14 @@ dump_table(grn_ctx *ctx, grn_obj *outbuf, grn_obj *table,
}
/* can we move this to groonga.h? */
-#define GRN_PTR_POP(obj,value) {\
+#define GRN_PTR_POP(obj,value) do {\
if (GRN_BULK_VSIZE(obj) >= sizeof(grn_obj *)) {\
GRN_BULK_INCR_LEN((obj), -(sizeof(grn_obj *)));\
value = *(grn_obj **)(GRN_BULK_CURR(obj));\
} else {\
value = NULL;\
}\
-}
+} while (0)
static void
dump_scheme(grn_ctx *ctx, grn_obj *outbuf)
@@ -2796,11 +2796,11 @@ func_edit_distance(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_
return obj;
}
-#define DEF_VAR(v,name_str) {\
+#define DEF_VAR(v,name_str) do {\
(v).name = (name_str);\
(v).name_size = GRN_STRLEN(name_str);\
GRN_TEXT_INIT(&(v).value, 0);\
-}
+} while (0)
#define DEF_COMMAND(name, func, nvars, vars)\
(grn_proc_create(ctx, (name), (sizeof(name) - 1),\
Modified: lib/snip.c (+6 -6)
===================================================================
--- lib/snip.c 2012-03-27 12:18:55 +0900 (8b51933)
+++ lib/snip.c 2012-03-27 13:29:15 +0900 (02a5c10)
@@ -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
@@ -82,7 +82,7 @@ grn_bm_preBmBc(const unsigned char *x, size_t m, size_t *bmBc)
}
}
-#define GRN_BM_COMPARE \
+#define GRN_BM_COMPARE do { \
if (object->checks[found]) { \
size_t offset = cond->last_offset, found_alpha_head = cond->found_alpha_head; \
/* calc real offset */\
@@ -115,10 +115,10 @@ grn_bm_preBmBc(const unsigned char *x, size_t m, size_t *bmBc)
cond->found_alpha_head = found_alpha_head; \
/* printf("bm: cond:%p found:%zd last_found:%zd st_off:%zd ed_off:%zd\n", cond, cond->found,cond->last_found,cond->start_offset,cond->end_offset); */ \
return; \
- }
+ } \
+} while (0)
-#define GRN_BM_BM_COMPARE \
-{ \
+#define GRN_BM_BM_COMPARE do { \
if (p[-2] == ck) { \
for (i = 3; i <= m && p[-(intptr_t)i] == cp[-(intptr_t)i]; ++i) { \
} \
@@ -127,7 +127,7 @@ grn_bm_preBmBc(const unsigned char *x, size_t m, size_t *bmBc)
GRN_BM_COMPARE; \
} \
} \
-}
+} while (0)
void
grn_bm_tunedbm(snip_cond *cond, grn_str *object, int flags)
Modified: lib/store.c (+8 -8)
===================================================================
--- lib/store.c 2012-03-27 12:18:55 +0900 (68ecafb)
+++ lib/store.c 2012-03-27 13:29:15 +0900 (d8eea9b)
@@ -245,28 +245,28 @@ struct _grn_ja_einfo {
#define ETINY_ENC(e,_size) ((e)->u.c[7] = (_size) + ETINY)
#define ETINY_DEC(e,_size) ((_size) = (e)->u.c[7] & ~(ETINY|EHUGE))
#define EHUGE_P(e) ((e)->u.c[7] & EHUGE)
-#define EHUGE_ENC(e,_seg,_size) {\
+#define EHUGE_ENC(e,_seg,_size) do {\
(e)->u.h.c1 = 0;\
(e)->u.h.c2 = EHUGE;\
(e)->u.h.seg = (_seg);\
(e)->u.h.size = (_size);\
-}
-#define EHUGE_DEC(e,_seg,_size) {\
+} while (0)
+#define EHUGE_DEC(e,_seg,_size) do {\
(_seg) = (e)->u.h.seg;\
(_size) = (e)->u.h.size;\
-}
-#define EINFO_ENC(e,_seg,_pos,_size) {\
+} while (0)
+#define EINFO_ENC(e,_seg,_pos,_size) do {\
(e)->u.n.c1 = (_pos) >> 16;\
(e)->u.n.c2 = ((_size) >> 16);\
(e)->u.n.seg = (_seg);\
(e)->u.n.pos = (_pos);\
(e)->u.n.size = (_size);\
-}
-#define EINFO_DEC(e,_seg,_pos,_size) {\
+} while (0)
+#define EINFO_DEC(e,_seg,_pos,_size) do {\
(_seg) = (e)->u.n.seg;\
(_pos) = ((e)->u.n.c1 << 16) + (e)->u.n.pos;\
(_size) = ((e)->u.n.c2 << 16) + (e)->u.n.size;\
-}
+} while (0)
typedef struct {
uint32_t seg;
Modified: src/groonga.c (+3 -4)
===================================================================
--- src/groonga.c 2012-03-27 12:18:55 +0900 (e83b56f)
+++ src/groonga.c 2012-03-27 13:29:15 +0900 (ca1bbf7)
@@ -1042,13 +1042,12 @@ cache_init(grn_ctx *ctx)
#define RELATIVE_TIME_THRESH 1000000000
-#define MBRES(ctx,re,status,key_len,extra_len,flags) {\
+#define MBRES(ctx,re,status,key_len,extra_len,flags) do {\
grn_msg_set_property((ctx), (re), (status), (key_len), (extra_len));\
grn_msg_send((ctx), (re), (flags));\
-}
+} while (0)
-#define GRN_MSG_MBRES(block) \
-do {\
+#define GRN_MSG_MBRES(block) do {\
if (!quiet) {\
grn_obj *re = grn_msg_open_for_reply(ctx, (grn_obj *)msg, &edge->send_old);\
((grn_msg *)re)->header.qtype = header->qtype;\
Modified: src/suggest/groonga_suggest_learner.c (+4 -6)
===================================================================
--- src/suggest/groonga_suggest_learner.c 2012-03-27 12:18:55 +0900 (042d710)
+++ src/suggest/groonga_suggest_learner.c 2012-03-27 13:29:15 +0900 (7d5224c)
@@ -125,17 +125,15 @@ load_to_multi_targets(grn_ctx *ctx,
}
}
-#define PACK_KEY_FROM_ID(id) \
-{ \
+#define PACK_KEY_FROM_ID(id) do { \
int _k_len; \
char _k_buf[GRN_TABLE_MAX_KEY_SIZE]; \
_k_len = grn_table_get_key(ctx, ref_table, (id), _k_buf, GRN_TABLE_MAX_KEY_SIZE); \
msgpack_pack_raw(&pk, _k_len); \
msgpack_pack_raw_body(&pk, _k_buf, _k_len); \
-}
+} while (0)
-#define PACK_MAP_ITEM(col_name) \
-{ \
+#define PACK_MAP_ITEM(col_name) do { \
grn_obj _v; \
msgpack_pack_raw(&pk, sizeof(#col_name) - 1); \
msgpack_pack_raw_body(&pk, CONST_STR_LEN(#col_name)); \
@@ -188,7 +186,7 @@ load_to_multi_targets(grn_ctx *ctx,
break; \
} \
grn_obj_close(ctx, &_v); \
-}
+} while (0)
static int
zmq_send_to_httpd(void *zmq_send_sock, void *data, size_t size)