[前][次][番号順一覧][スレッド一覧]

ruby-changes:52395

From: nobu <ko1@a...>
Date: Sat, 1 Sep 2018 13:09:07 +0900 (JST)
Subject: [ruby-changes:52395] nobu:r64604 (trunk): surround macro block with do/while

nobu	2018-09-01 13:09:02 +0900 (Sat, 01 Sep 2018)

  New Revision: 64604

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64604

  Log:
    surround macro block with do/while

  Modified files:
    trunk/ext/date/date_core.c
    trunk/ext/date/date_parse.c
    trunk/ext/date/date_strptime.c
Index: ext/date/date_strptime.c
===================================================================
--- ext/date/date_strptime.c	(revision 64603)
+++ ext/date/date_strptime.c	(revision 64604)
@@ -118,21 +118,21 @@ read_digits(const char *s, VALUE *n, siz https://github.com/ruby/ruby/blob/trunk/ext/date/date_strptime.c#L118
 #define del_hash(k) rb_hash_delete(hash, ID2SYM(rb_intern(k"")))
 
 #define fail() \
-{ \
+do { \
     set_hash("_fail", Qtrue); \
     return 0; \
-}
+} while (0)
 
 #define fail_p() (!NIL_P(ref_hash("_fail")))
 
 #define READ_DIGITS(n,w) \
-{ \
+do { \
     size_t l; \
     l = read_digits(&str[si], &n, w); \
     if (l == 0) \
 	fail();	\
     si += l; \
-}
+} while (0)
 
 #define READ_DIGITS_MAX(n) READ_DIGITS(n, LONG_MAX)
 
@@ -147,14 +147,14 @@ valid_range_p(VALUE v, int a, int b) https://github.com/ruby/ruby/blob/trunk/ext/date/date_strptime.c#L147
 }
 
 #define recur(fmt) \
-{ \
+do { \
     size_t l; \
     l = date__strptime_internal(&str[si], slen - si, \
 				fmt, sizeof fmt - 1, hash); \
     if (fail_p()) \
 	return 0; \
     si += l; \
-}
+} while (0)
 
 VALUE date_zone_to_diff(VALUE);
 
@@ -237,9 +237,9 @@ date__strptime_internal(const char *str, https://github.com/ruby/ruby/blob/trunk/ext/date/date_strptime.c#L237
 		    VALUE n;
 
 		    if (NUM_PATTERN_P())
-			READ_DIGITS(n, 2)
+			READ_DIGITS(n, 2);
 		    else
-			READ_DIGITS_MAX(n)
+			READ_DIGITS_MAX(n);
 		    set_hash("_cent", n);
 		    goto matched;
 		}
@@ -278,9 +278,9 @@ date__strptime_internal(const char *str, https://github.com/ruby/ruby/blob/trunk/ext/date/date_strptime.c#L278
 		    VALUE n;
 
 		    if (NUM_PATTERN_P())
-			READ_DIGITS(n, 4)
+			READ_DIGITS(n, 4);
 		    else
-			READ_DIGITS_MAX(n)
+			READ_DIGITS_MAX(n);
 		    set_hash("cwyear", n);
 		    goto matched;
 		}
@@ -358,9 +358,9 @@ date__strptime_internal(const char *str, https://github.com/ruby/ruby/blob/trunk/ext/date/date_strptime.c#L358
 		    }
 		    osi = si;
 		    if (NUM_PATTERN_P())
-			READ_DIGITS(n, c == 'L' ? 3 : 9)
+			READ_DIGITS(n, c == 'L' ? 3 : 9);
 		    else
-			READ_DIGITS_MAX(n)
+			READ_DIGITS_MAX(n);
 		    if (sign == -1)
 			n = f_negate(n);
 		    set_hash("sec_fraction",
@@ -539,11 +539,11 @@ date__strptime_internal(const char *str, https://github.com/ruby/ruby/blob/trunk/ext/date/date_strptime.c#L539
 			  si++;
 		      }
 		      if (NUM_PATTERN_P())
-			  READ_DIGITS(n, 4)
+			  READ_DIGITS(n, 4);
 		      else
-			  READ_DIGITS_MAX(n)
-		    if (sign == -1)
-			n = f_negate(n);
+			  READ_DIGITS_MAX(n);
+		      if (sign == -1)
+			  n = f_negate(n);
 		      set_hash("year", n);
 		      goto matched;
 		  }
Index: ext/date/date_core.c
===================================================================
--- ext/date/date_core.c	(revision 64603)
+++ ext/date/date_core.c	(revision 64604)
@@ -315,7 +315,7 @@ canon(VALUE x) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L315
 
 #ifndef USE_PACK
 #define set_to_simple(obj, x, _nth, _jd ,_sg, _year, _mon, _mday, _flags) \
-{\
+do {\
     RB_OBJ_WRITE((obj), &(x)->nth, canon(_nth)); \
     (x)->jd = _jd;\
     (x)->sg = (date_sg_t)(_sg);\
@@ -323,23 +323,23 @@ canon(VALUE x) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L323
     (x)->mon = _mon;\
     (x)->mday = _mday;\
     (x)->flags = _flags;\
-}
+} while (0)
 #else
 #define set_to_simple(obj, x, _nth, _jd ,_sg, _year, _mon, _mday, _flags) \
-{\
+do {\
     RB_OBJ_WRITE((obj), &(x)->nth, canon(_nth)); \
     (x)->jd = _jd;\
     (x)->sg = (date_sg_t)(_sg);\
     (x)->year = _year;\
     (x)->pc = PACK2(_mon, _mday);\
     (x)->flags = _flags;\
-}
+} while (0)
 #endif
 
 #ifndef USE_PACK
 #define set_to_complex(obj, x, _nth, _jd ,_df, _sf, _of, _sg,\
 _year, _mon, _mday, _hour, _min, _sec, _flags) \
-{\
+do {\
     RB_OBJ_WRITE((obj), &(x)->nth, canon(_nth));\
     (x)->jd = _jd;\
     (x)->df = _df;\
@@ -353,11 +353,11 @@ _year, _mon, _mday, _hour, _min, _sec, _ https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L353
     (x)->min = _min;\
     (x)->sec = _sec;\
     (x)->flags = _flags;\
-}
+} while (0)
 #else
 #define set_to_complex(obj, x, _nth, _jd ,_df, _sf, _of, _sg,\
 _year, _mon, _mday, _hour, _min, _sec, _flags) \
-{\
+do {\
     RB_OBJ_WRITE((obj), &(x)->nth, canon(_nth));\
     (x)->jd = _jd;\
     (x)->df = _df;\
@@ -367,12 +367,12 @@ _year, _mon, _mday, _hour, _min, _sec, _ https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L367
     (x)->year = _year;\
     (x)->pc = PACK5(_mon, _mday, _hour, _min, _sec);\
     (x)->flags = _flags;\
-}
+} while (0)
 #endif
 
 #ifndef USE_PACK
 #define copy_simple_to_complex(obj, x, y) \
-{\
+do {\
     RB_OBJ_WRITE((obj), &(x)->nth, (y)->nth);\
     (x)->jd = (y)->jd;\
     (x)->df = 0;\
@@ -386,10 +386,10 @@ _year, _mon, _mday, _hour, _min, _sec, _ https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L386
     (x)->min = 0;\
     (x)->sec = 0;\
     (x)->flags = (y)->flags;\
-}
+} while (0)
 #else
 #define copy_simple_to_complex(obj, x, y) \
-{\
+do {\
     RB_OBJ_WRITE((obj), &(x)->nth, (y)->nth);\
     (x)->jd = (y)->jd;\
     (x)->df = 0;\
@@ -399,12 +399,12 @@ _year, _mon, _mday, _hour, _min, _sec, _ https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L399
     (x)->year = (y)->year;\
     (x)->pc = PACK5(EX_MON((y)->pc), EX_MDAY((y)->pc), 0, 0, 0);\
     (x)->flags = (y)->flags;\
-}
+} while (0)
 #endif
 
 #ifndef USE_PACK
 #define copy_complex_to_simple(obj, x, y) \
-{\
+do {\
     RB_OBJ_WRITE((obj), &(x)->nth, (y)->nth);\
     (x)->jd = (y)->jd;\
     (x)->sg = (date_sg_t)((y)->sg);\
@@ -412,17 +412,17 @@ _year, _mon, _mday, _hour, _min, _sec, _ https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L412
     (x)->mon = (y)->mon;\
     (x)->mday = (y)->mday;\
     (x)->flags = (y)->flags;\
-}
+} while (0)
 #else
 #define copy_complex_to_simple(obj, x, y) \
-{\
+do {\
     RB_OBJ_WRITE((obj), &(x)->nth, (y)->nth);\
     (x)->jd = (y)->jd;\
     (x)->sg = (date_sg_t)((y)->sg);\
     (x)->year = (y)->year;\
     (x)->pc = PACK2(EX_MON((y)->pc), EX_MDAY((y)->pc));\
     (x)->flags = (y)->flags;\
-}
+} while (0)
 #endif
 
 /* base */
@@ -1109,7 +1109,7 @@ m_virtual_sg(union DateData *x) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L1109
 }
 
 #define canonicalize_jd(_nth, _jd) \
-{\
+do {\
     if (_jd < 0) {\
 	_nth = f_sub(_nth, INT2FIX(1));\
 	_jd += CM_PERIOD;\
@@ -1118,7 +1118,7 @@ m_virtual_sg(union DateData *x) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L1118
 	_nth = f_add(_nth, INT2FIX(1));\
 	_jd -= CM_PERIOD;\
     }\
-}
+} while (0)
 
 inline static void
 canonicalize_s_jd(VALUE obj, union DateData *x)
@@ -1928,13 +1928,13 @@ m_sec(union DateData *x) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L1928
 }
 
 #define decode_offset(of,s,h,m)\
-{\
+do {\
     int a;\
     s = (of < 0) ? '-' : '+';\
     a = (of < 0) ? -of : of;\
     h = a / HOUR_IN_SECONDS;\
     m = a % HOUR_IN_SECONDS / MINUTE_IN_SECONDS;\
-}
+} while (0)
 
 static VALUE
 of2str(int of)
@@ -2418,12 +2418,12 @@ offset_to_sec(VALUE vof, int *rof) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L2418
 /* date */
 
 #define valid_sg(sg) \
-{\
+do {\
     if (!c_valid_start_p(sg)) {\
 	sg = 0;\
 	rb_warning("invalid start is ignored");\
     }\
-}
+} while (0)
 
 static VALUE
 valid_jd_sub(int argc, VALUE *argv, VALUE klass, int need_jd)
@@ -3205,47 +3205,47 @@ s_trunc(VALUE s, VALUE *fr) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L3205
 }
 
 #define num2num_with_frac(s,n) \
-{\
+do {\
     s = s##_trunc(v##s, &fr);\
     if (f_nonzero_p(fr)) {\
 	if (argc > n)\
 	    rb_raise(rb_eArgError, "invalid fraction");\
 	fr2 = fr;\
     }\
-}
+} while (0)
 
 #define num2int_with_frac(s,n) \
-{\
+do {\
     s = NUM2INT(s##_trunc(v##s, &fr));\
     if (f_nonzero_p(fr)) {\
 	if (argc > n)\
 	    rb_raise(rb_eArgError, "invalid fraction");\
 	fr2 = fr;\
     }\
-}
+} while (0)
 
 #define canon24oc() \
-{\
+do {\
     if (rh == 24) {\
 	rh = 0;\
 	fr2 = f_add(fr2, INT2FIX(1));\
     }\
-}
+} while (0)
 
 #define add_frac() \
-{\
+do {\
     if (f_nonzero_p(fr2))\
 	ret = d_lite_plus(ret, fr2);\
-}
+} while (0)
 
 #define val2sg(vsg,dsg) \
-{\
+do {\
     dsg = NUM2DBL(vsg);\
     if (!c_valid_start_p(dsg)) {\
 	dsg = DEFAULT_SG;\
 	rb_warning("invalid start is ignored");\
     }\
-}
+} while (0)
 
 static VALUE d_lite_plus(VALUE, VALUE);
 
@@ -4689,12 +4689,12 @@ dup_obj_as_complex(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L4689
 }
 
 #define val2off(vof,iof) \
-{\
+do {\
     if (!offset_to_sec(vof, &iof)) {\
 	iof = 0;\
 	rb_warning("invalid offset is ignored");\
     }\
-}
+} while (0)
 
 #ifndef NDEBUG
 static VALUE
@@ -8646,7 +8646,7 @@ datetime_to_date(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L8646
 	VALUE new = d_lite_s_alloc_simple(cDate);
 	{
 	    get_d1b(new);
-	    copy_complex_to_simple(new, &bdat->s, &adat->c)
+	    copy_complex_to_simple(new, &bdat->s, &adat->c);
 	    bdat->s.jd = m_local_jd(adat);
 	    bdat->s.flags &= ~(HAVE_DF | HAVE_TIME | COMPLEX_DAT);
 	    return new;
Index: ext/date/date_parse.c
===================================================================
--- ext/date/date_parse.c	(revision 64603)
+++ ext/date/date_parse.c	(revision 64604)
@@ -263,18 +263,18 @@ regcomp(const char *source, long len, in https://github.com/ruby/ruby/blob/trunk/ext/date/date_parse.c#L263
 }
 
 #define REGCOMP(pat,opt) \
-{ \
+do { \
     if (NIL_P(pat)) \
 	pat = regcomp(pat##_source, sizeof pat##_source - 1, opt); \
-}
+} while (0)
 
 #define REGCOMP_0(pat) REGCOMP(pat, 0)
 #define REGCOMP_I(pat) REGCOMP(pat, ONIG_OPTION_IGNORECASE)
 
 #define MATCH(s,p,c) \
-{ \
+do { \
     return match(s, p, hash, c); \
-}
+} while (0)
 
 static int
 match(VALUE str, VALUE pat, VALUE hash, int (*cb)(VALUE, VALUE))
@@ -314,30 +314,30 @@ subx(VALUE str, VALUE rep, VALUE pat, VA https://github.com/ruby/ruby/blob/trunk/ext/date/date_parse.c#L314
 }
 
 #define SUBS(s,p,c) \
-{ \
+do { \
     return subx(s, asp_string(), p, hash, c); \
-}
+} while (0)
 
 #ifdef TIGHT_PARSER
 #define SUBA(s,p,c) \
-{ \
+do { \
     return subx(s, asuba_string(), p, hash, c); \
-}
+} while (0)
 
 #define SUBB(s,p,c) \
-{ \
+do { \
     return subx(s, asubb_string(), p, hash, c); \
-}
+} while (0)
 
 #define SUBW(s,p,c) \
-{ \
+do { \
     return subx(s, asubw_string(), p, hash, c); \
-}
+} while (0)
 
 #define SUBT(s,p,c) \
-{ \
+do { \
     return subx(s, asubt_string(), p, hash, c); \
-}
+} while (0)
 #endif
 
 #include "zonetab.h"

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]