ruby-changes:43099
From: nobu <ko1@a...>
Date: Thu, 26 May 2016 14:13:58 +0900 (JST)
Subject: [ruby-changes:43099] nobu:r55173 (trunk): ruby.h: count and verify
nobu 2016-05-26 14:13:54 +0900 (Thu, 26 May 2016) New Revision: 55173 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55173 Log: ruby.h: count and verify * include/ruby/ruby.h (rb_scan_args_count): verify length with counting variables together. Modified files: trunk/ChangeLog trunk/include/ruby/ruby.h Index: include/ruby/ruby.h =================================================================== --- include/ruby/ruby.h (revision 55172) +++ include/ruby/ruby.h (revision 55173) @@ -2164,90 +2164,71 @@ ERRORFUNC(("variable argument length doe https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L2164 # endif # define rb_scan_args_isdigit(c) ((unsigned char)((c)-'0')<10) - -# define rb_scan_args_count_block(fmt, ofs) \ - ((fmt)[ofs]=='&') - -# define rb_scan_args_count_hash(fmt, ofs) \ - ((fmt)[ofs]!=':' ? \ - rb_scan_args_count_block(fmt, ofs) : \ - rb_scan_args_count_block(fmt, (ofs)+1)+1) - -# define rb_scan_args_count_trail(fmt, ofs) \ - (!rb_scan_args_isdigit((fmt)[ofs]) ? \ - rb_scan_args_count_hash(fmt, ofs) : \ - ((fmt)[ofs]-'0') + rb_scan_args_count_hash(fmt, (ofs)+1)) - -# define rb_scan_args_count_var(fmt, ofs) \ - ((fmt)[ofs]!='*' ? \ - rb_scan_args_count_trail(fmt, ofs) : \ - rb_scan_args_count_trail(fmt, (ofs)+1)+1) - -# define rb_scan_args_count(fmt) \ - (!rb_scan_args_isdigit((fmt)[0]) ? rb_scan_args_count_var(fmt, 0) : \ - !rb_scan_args_isdigit((fmt)[1]) ? rb_scan_args_count_var(fmt, 1)+(fmt)[0]-'0' : \ - rb_scan_args_count_var(fmt, 2)+(fmt)[0]-'0'+(fmt)[1]-'0') - -# define rb_scan_args_lead_p(fmt) rb_scan_args_isdigit((fmt)[0]) -# define rb_scan_args_n_lead(fmt) (rb_scan_args_lead_p(fmt) ? (fmt)[0]-'0' : 0) -# define rb_scan_args_opt_p(fmt) (rb_scan_args_lead_p(fmt) && rb_scan_args_isdigit((fmt)[1])) -# define rb_scan_args_n_opt(fmt) (rb_scan_args_opt_p(fmt) ? (fmt)[1]-'0' : 0) +# define rb_scan_args_count_end(fmt, ofs, varc, vari) \ + (((varc) \ + /(!fmt[ofs] || rb_scan_args_bad_format(fmt))) \ + /((varc)==(vari) || rb_scan_args_length_mismatch(vari, varc))) + +# define rb_scan_args_count_block(fmt, ofs, varc, vari) \ + (fmt[ofs]!='&' ? \ + rb_scan_args_count_end(fmt, ofs, varc, vari) : \ + rb_scan_args_count_end(fmt, ofs+1, varc, vari+1)) + +# define rb_scan_args_count_hash(fmt, ofs, varc, vari) \ + (fmt[ofs]!=':' ? \ + rb_scan_args_count_block(fmt, ofs, varc, vari) : \ + rb_scan_args_count_block(fmt, ofs+1, varc, vari+1)) + +# define rb_scan_args_count_trail(fmt, ofs, varc, vari) \ + (!rb_scan_args_isdigit(fmt[ofs]) ? \ + rb_scan_args_count_hash(fmt, ofs, varc, vari) : \ + rb_scan_args_count_hash(fmt, ofs+1, varc, vari+(fmt[ofs]-'0'))) + +# define rb_scan_args_count_var(fmt, ofs, varc, vari) \ + (fmt[ofs]!='*' ? \ + rb_scan_args_count_trail(fmt, ofs, varc, vari) : \ + rb_scan_args_count_trail(fmt, ofs+1, varc, vari+1)) + +# define rb_scan_args_count_opt(fmt, ofs, varc, vari) \ + (!rb_scan_args_isdigit(fmt[1]) ? \ + rb_scan_args_count_var(fmt, ofs, varc, vari) : \ + rb_scan_args_count_var(fmt, ofs+1, varc, vari+fmt[ofs]-'0')) + +# define rb_scan_args_count(fmt, varc) \ + (!rb_scan_args_isdigit(fmt[0]) ? \ + rb_scan_args_count_var(fmt, 0, varc, 0) : \ + rb_scan_args_count_opt(fmt, 1, varc, fmt[0]-'0')) + +# define rb_scan_args_lead_p(fmt) rb_scan_args_isdigit(fmt[0]) +# define rb_scan_args_n_lead(fmt) (rb_scan_args_lead_p(fmt) ? fmt[0]-'0' : 0) +# define rb_scan_args_opt_p(fmt) (rb_scan_args_lead_p(fmt) && rb_scan_args_isdigit(fmt[1])) +# define rb_scan_args_n_opt(fmt) (rb_scan_args_opt_p(fmt) ? fmt[1]-'0' : 0) # define rb_scan_args_var_idx(fmt) \ - (!rb_scan_args_lead_p(fmt) ? 0 : !rb_scan_args_isdigit((fmt)[1]) ? 1 : 2) -# define rb_scan_args_f_var(fmt) ((fmt)[rb_scan_args_var_idx(fmt)]=='*') + (!rb_scan_args_lead_p(fmt) ? 0 : !rb_scan_args_isdigit(fmt[1]) ? 1 : 2) +# define rb_scan_args_f_var(fmt) (fmt[rb_scan_args_var_idx(fmt)]=='*') # define rb_scan_args_trail_idx(fmt) \ (rb_scan_args_lead_p(fmt) ? \ - (rb_scan_args_isdigit((fmt)[1]) || (fmt)[1]=='*')+1 : \ - ((fmt)[0]=='*')) + (rb_scan_args_isdigit(fmt[1]) || fmt[1]=='*')+1 : \ + (fmt[0]=='*')) # define rb_scan_args_trail_p(fmt) \ (rb_scan_args_lead_p(fmt) ? \ - (rb_scan_args_isdigit((fmt)[1]) || (fmt)[1]=='*') && \ - rb_scan_args_isdigit((fmt)[2]) : \ - (fmt)[0]=='*' && rb_scan_args_isdigit((fmt)[1])) + (rb_scan_args_isdigit(fmt[1]) || fmt[1]=='*') && \ + rb_scan_args_isdigit(fmt[2]) : \ + fmt[0]=='*' && rb_scan_args_isdigit(fmt[1])) # define rb_scan_args_n_trail(fmt) \ (rb_scan_args_lead_p(fmt) ? \ - ((rb_scan_args_isdigit((fmt)[1]) || (fmt)[1]=='*') && \ - rb_scan_args_isdigit((fmt)[2]) ? (fmt)[2]-'0' : 0) : \ - ((fmt)[0]=='*' && rb_scan_args_isdigit((fmt)[1]) ? (fmt)[1]-'0' : 0)) + ((rb_scan_args_isdigit(fmt[1]) || fmt[1]=='*') && \ + rb_scan_args_isdigit(fmt[2]) ? fmt[2]-'0' : 0) : \ + (fmt[0]=='*' && rb_scan_args_isdigit(fmt[1]) ? fmt[1]-'0' : 0)) # define rb_scan_args_hash_idx(fmt) \ (rb_scan_args_trail_idx(fmt)+rb_scan_args_trail_p(fmt)) -# define rb_scan_args_f_hash(fmt) ((fmt)[rb_scan_args_hash_idx(fmt)]==':') +# define rb_scan_args_f_hash(fmt) (fmt[rb_scan_args_hash_idx(fmt)]==':') # define rb_scan_args_block_idx(fmt) \ (rb_scan_args_hash_idx(fmt)+rb_scan_args_f_hash(fmt)) -# define rb_scan_args_f_block(fmt) ((fmt)[rb_scan_args_block_idx(fmt)]=='&') +# define rb_scan_args_f_block(fmt) (fmt[rb_scan_args_block_idx(fmt)]=='&') # define rb_scan_args_end_idx(fmt) \ (rb_scan_args_block_idx(fmt)+rb_scan_args_f_block(fmt)) -# define rb_scan_args_validate(fmt, varc) \ - (!rb_scan_args_isdigit((fmt)[0]) ? \ - rb_scan_args_validate_var(fmt, 0, varc) : \ - !rb_scan_args_isdigit((fmt)[1]) ? \ - rb_scan_args_validate_var(fmt, 1, (varc-(fmt)[0]+'0')) : \ - rb_scan_args_validate_var(fmt, 2, (varc-(fmt)[0]+'0'-(fmt)[1]+'0'))) -# define rb_scan_args_validate_var(fmt, ofs, varc) \ - ((fmt)[ofs]=='*' ? \ - rb_scan_args_validate_trail(fmt, ofs+1, (varc-1)) : \ - rb_scan_args_validate_trail(fmt, ofs, varc)) -# define rb_scan_args_validate_trail(fmt, ofs, varc) \ - (rb_scan_args_isdigit((fmt)[ofs]) ? \ - rb_scan_args_validate_hash(fmt, ofs+1, (varc-1)) : \ - rb_scan_args_validate_hash(fmt, ofs, varc)) -# define rb_scan_args_validate_hash(fmt, ofs, varc) \ - ((fmt)[ofs]==':' ? \ - rb_scan_args_validate_block(fmt, ofs+1, (varc-1)) : \ - rb_scan_args_validate_block(fmt, ofs, varc)) -# define rb_scan_args_validate_block(fmt, ofs, varc) \ - ((fmt)[ofs]=='&' ? \ - rb_scan_args_validate_end(fmt, ofs+1, (varc-1)) : \ - rb_scan_args_validate_end(fmt, ofs, varc)) -# define rb_scan_args_validate_end(fmt, ofs, varc) \ - ((fmt)[ofs]?rb_scan_args_bad_format(fmt):!(varc)) - -# define rb_scan_args_verify(fmt, varc) \ - ((varc)\ - /(rb_scan_args_validate(fmt, varc)|| \ - rb_scan_args_length_mismatch((varc), rb_scan_args_count(fmt)))) - # define rb_scan_args0(argc, argv, fmt, varc, vars) \ rb_scan_args_set(argc, argv, \ rb_scan_args_n_lead(fmt), \ @@ -2256,7 +2237,7 @@ ERRORFUNC(("variable argument length doe https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L2237 rb_scan_args_f_var(fmt), \ rb_scan_args_f_hash(fmt), \ rb_scan_args_f_block(fmt), \ - rb_scan_args_verify(fmt, varc), vars) + rb_scan_args_count(fmt, varc), vars) ALWAYS_INLINE(static int rb_scan_args_set(int argc, const VALUE *argv, int n_lead, int n_opt, int n_trail, Index: ChangeLog =================================================================== --- ChangeLog (revision 55172) +++ ChangeLog (revision 55173) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu May 26 14:13:52 2016 Nobuyoshi Nakada <nobu@r...> + + * include/ruby/ruby.h (rb_scan_args_count): verify length with + counting variables together. + Thu May 26 09:45:41 2016 Martin Duerst <duerst@i...> * test/ruby/enc/test_case_comprehensive.rb: Add set of comprehensive -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/