From 9b383bd6cf96e1fe21c41528dec1f3ed508f335b Mon Sep 17 00:00:00 2001 From: matz Date: Fri, 9 Jun 2006 21:20:17 +0000 Subject: * sprintf.c (rb_str_format): allow %c to print one character string (e.g. ?x). * lib/tempfile.rb (Tempfile::make_tmpname): put dot between basename and pid. [ruby-talk:196272] * parse.y (do_block): remove -> style block. * parse.y (parser_yylex): remove tLAMBDA_ARG. * eval.c (rb_call0): binding for the return event hook should have consistent scope. [ruby-core:07928] * eval.c (proc_invoke): return behavior should depend whether it is surrounded by a lambda or a mere block. * eval.c (formal_assign): handles post splat arguments. * eval.c (rb_call0): ditto. * st.c (strhash): use FNV-1a hash. * parse.y (parser_yylex): removed experimental ';;' terminator. * eval.c (rb_node_arity): should be aware of post splat arguments. * eval.c (rb_proc_arity): ditto. * parse.y (f_args): syntax rule enhanced to support arguments after the splat. * parse.y (block_param): ditto for block parameters. * parse.y (f_post_arg): mandatory formal arguments after the splat argument. * parse.y (new_args_gen): generate nodes for mandatory formal arguments after the splat argument. * eval.c (rb_eval): dispatch mandatory formal arguments after the splat argument. * parse.y (args): allow more than one splat in the argument list. * parse.y (method_call): allow aref [] to accept all kind of method argument, including assocs, splat, and block argument. * eval.c (SETUP_ARGS0): prepare block argument as well. * lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931] * eval.c (error_line): print receivers true/false/nil specially. * eval.c (rb_proc_yield): handles parameters in yield semantics. * eval.c (nil_yield): gives LocalJumpError to denote no block error. * io.c (rb_io_getc): now takes one-character string. * string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo hashing algorithm. * string.c (rb_str_aref): str[0] now returns 1 character string, instead of a fixnum. [Ruby2] * parse.y (parser_yylex): ?c now returns 1 character string, instead of a fixnum. [Ruby2] * string.c (rb_str_aset): no longer support fixnum insertion. * eval.c (umethod_bind): should not update original class. [ruby-dev:28636] * eval.c (ev_const_get): should support constant access from within instance_eval(). [ruby-dev:28327] * time.c (time_timeval): should round for usec floating number. [ruby-core:07896] * time.c (time_add): ditto. * dir.c (sys_warning): should not call a vararg function rb_sys_warning() indirectly. [ruby-core:07886] * numeric.c (flo_divmod): the first element of Float#divmod should be an integer. [ruby-dev:28589] * test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder. * re.c (rb_reg_initialize): should not allow modifying literal regexps. frozen check moved from rb_reg_initialize_m as well. * re.c (rb_reg_initialize): should not modify untainted objects in safe levels higher than 3. * re.c (rb_memcmp): type change from char* to const void*. * dir.c (dir_close): should not close untainted dir stream. * dir.c (GetDIR): add tainted/frozen check for each dir operation. * lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg): typo fixed. a patch from Florian Gross . * eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from event_hooks. no guarantee for arbitrary hook deletion. [ruby-dev:28632] * util.c (ruby_strtod): differ addition to minimize error. [ruby-dev:28619] * util.c (ruby_strtod): should not raise ERANGE when the input string does not have any digits. [ruby-dev:28629] * eval.c (proc_invoke): should restore old ruby_frame->block. thanks to ts . [ruby-core:07833] also fix [ruby-dev:28614] as well. * signal.c (trap): sig should be less then NSIG. Coverity found this bug. a patch from Kevin Tew . [ruby-core:07823] * math.c (math_log2): add new method inspired by [ruby-talk:191237]. * math.c (math_log): add optional base argument to Math::log(). [ruby-talk:191308] * ext/syck/emitter.c (syck_scan_scalar): avoid accessing uninitialized array element. a patch from Pat Eyler . [ruby-core:07809] * array.c (rb_ary_fill): initialize local variables first. a patch from Pat Eyler . [ruby-core:07810] * ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free type_tag. a patch from Pat Eyler . [ruby-core:07808] * ext/socket/socket.c (make_hostent_internal): accept ai_family check from Sam Roberts . [ruby-core:07691] * util.c (ruby_strtod): should not cut off 18 digits for no reason. [ruby-core:07796] * array.c (rb_ary_fill): internalize local variable "beg" to pacify Coverity. [ruby-core:07770] * pack.c (pack_unpack): now supports CRLF newlines. a patch from . [ruby-dev:28601] * applied code clean-up patch from Stefan Huehner . [ruby-core:07764] * lib/jcode.rb (String::tr_s): should have translated non squeezing character sequence (i.e. a character) as well. thanks to Hiroshi Ichikawa [ruby-list:42090] * ext/socket/socket.c: document update patch from Sam Roberts . [ruby-core:07701] * lib/mathn.rb (Integer): need not to remove gcd2. a patch from NARUSE, Yui . [ruby-dev:28570] * parse.y (arg): too much NEW_LIST() * eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen. * eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1. [ruby-dev:28585] * parse.y (arg): use NODE_ARGSCAT for placeholder. * lib/getoptlong.rb (GetoptLong::get): RDoc update patch from mathew . [ruby-core:07738] * variable.c (rb_const_set): raise error when no target klass is supplied. [ruby-dev:28582] * prec.c (prec_prec_f): documentation patch from . [ruby-core:07689] * bignum.c (rb_big_pow): second operand may be too big even if it's a Fixnum. [ruby-talk:187984] * README.EXT: update symbol description. [ruby-talk:188104] * COPYING: explicitly note GPLv2. [ruby-talk:187922] * parse.y: remove some obsolete syntax rules (unparenthesized method calls in argument list). * eval.c (rb_call0): insecure calling should be checked for non NODE_SCOPE method invocations too. * eval.c (rb_alias): should preserve the current safe level as well as method definition. * process.c (rb_f_sleep): remove RDoc description about SIGALRM which is not valid on the current implementation. [ruby-dev:28464] Thu Mar 23 21:40:47 2006 K.Kosako * eval.c (method_missing): should support argument splat in super. a bug in combination of super, splat and method_missing. [ruby-talk:185438] * configure.in: Solaris SunPro compiler -rapth patch from . [ruby-dev:28443] * configure.in: remove enable_rpath=no for Solaris. [ruby-dev:28440] * ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby String object. * ruby.1: a clarification patch from David Lutterkort . [ruby-core:7508] * lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems directories. a patch from Eric Hodel . [ruby-core:07423] * eval.c (rb_clear_cache_by_class): clearing wrong cache. * ext/extmk.rb: use :remove_destination to install extension libraries to avoid SEGV. [ruby-dev:28417] * eval.c (rb_thread_fd_writable): should not re-schedule output from KILLED thread (must be error printing). * array.c (rb_ary_flatten_bang): allow specifying recursion level. [ruby-talk:182170] * array.c (rb_ary_flatten): ditto. * gc.c (add_heap): a heap_slots may overflow. a patch from Stefan Weil . * eval.c (rb_call): use separate cache for fcall/vcall invocation. * eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local functions. * eval.c (rb_mod_local): a new method to specify newly added visibility "local". * eval.c (search_method): search for local methods which are visible only from the current class. * class.c (rb_class_local_methods): a method to list local methods. * object.c (Init_Object): add BasicObject class as a top level BlankSlate class. * ruby.h (SYM2ID): should not cast to signed long. [ruby-core:07414] * class.c (rb_include_module): allow module duplication. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- COPYING | 2 +- ChangeLog | 408 +++++++++++++++++- README.EXT | 23 +- array.c | 110 ++--- bignum.c | 13 +- class.c | 41 +- configure.in | 10 +- dir.c | 20 +- enumerator.c | 2 +- error.c | 8 +- eval.c | 969 +++++++++++++++++++++++-------------------- ext/.document | 3 +- ext/Setup | 1 - ext/bigdecimal/bigdecimal.c | 12 +- ext/bigdecimal/bigdecimal.h | 10 +- ext/curses/curses.c | 192 +++------ ext/etc/etc.c | 44 +- ext/extmk.rb | 4 +- ext/iconv/iconv.c | 2 +- ext/io/wait/wait.c | 3 +- ext/nkf/nkf-utf8/nkf.c | 114 ++--- ext/nkf/nkf.c | 15 +- ext/openssl/ossl_asn1.c | 2 +- ext/openssl/ossl_pkcs7.c | 2 +- ext/openssl/ossl_ssl.c | 8 +- ext/pty/pty.c | 41 +- ext/readline/readline.c | 123 ++---- ext/ripper/eventids2.c | 3 +- ext/stringio/stringio.c | 17 +- ext/strscan/strscan.c | 12 +- ext/syck/emitter.c | 10 +- ext/syck/handler.c | 2 +- ext/syck/implicit.c | 2 +- ext/syck/node.c | 4 +- ext/syck/syck.c | 2 +- ext/syck/syck.h | 14 +- ext/syck/yaml2byte.c | 1 + ext/tk/tcltklib.c | 4 + ext/zlib/zlib.c | 500 +++++++--------------- gc.c | 8 +- hash.c | 30 +- instruby.rb | 4 +- intern.h | 7 +- io.c | 72 +++- lib/.document | 1 + lib/cgi.rb | 2 + lib/forwardable.rb | 4 +- lib/getoptlong.rb | 196 +++++++-- lib/jcode.rb | 2 +- lib/mathn.rb | 8 - lib/mkmf.rb | 25 +- lib/optparse.rb | 12 +- lib/rdoc/parsers/parse_rb.rb | 2 +- lib/rdoc/ri/ri_paths.rb | 6 + lib/runit/assert.rb | 7 +- lib/runit/testcase.rb | 2 +- lib/tempfile.rb | 2 +- marshal.c | 4 +- math.c | 46 +- missing/vsnprintf.c | 20 +- mkconfig.rb | 6 +- node.h | 9 +- numeric.c | 27 +- object.c | 45 +- pack.c | 6 +- parse.y | 680 ++++++++++++++---------------- prec.c | 4 +- process.c | 28 +- range.c | 3 +- re.c | 38 +- regerror.c | 4 +- regparse.c | 4 +- ruby.1 | 5 +- ruby.c | 4 +- ruby.h | 3 +- sample/test.rb | 274 ++++++------ signal.c | 6 +- sprintf.c | 10 +- st.c | 115 +++-- string.c | 164 +++++--- struct.c | 2 +- test/ruby/test_assignment.rb | 176 ++++---- test/ruby/test_clone.rb | 2 +- test/ruby/test_dir.rb | 6 +- test/ruby/test_file.rb | 2 +- test/ruby/test_float.rb | 28 ++ test/ruby/test_iterator.rb | 30 +- test/ruby/test_stringchar.rb | 8 +- time.c | 6 +- util.c | 90 ++-- variable.c | 12 +- 91 files changed, 2665 insertions(+), 2345 deletions(-) diff --git a/COPYING b/COPYING index 870a5f22d6..9043404a83 100644 --- a/COPYING +++ b/COPYING @@ -1,6 +1,6 @@ Ruby is copyrighted free software by Yukihiro Matsumoto . You can redistribute it and/or modify it under either the terms of the GPL -(see the file GPL), or the conditions below: +version 2 (see the file GPL), or the conditions below: 1. You may make and give away verbatim copies of the source form of the software without restriction, provided that you duplicate all of the diff --git a/ChangeLog b/ChangeLog index cb820064ce..c93ba15fe8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,12 +1,38 @@ +Fri Jun 9 09:56:32 2006 Yukihiro Matsumoto + + * sprintf.c (rb_str_format): allow %c to print one character + string (e.g. ?x). + Thu Jun 8 14:00:02 2006 NAKAMURA Usaku * win32/win32.[ch] (rb_w32_read, rb_w32_write): new functions. use recv() and send() when fd is socket. fixed: [ruby-dev:28694] +Wed Jun 7 16:22:51 2006 Yukihiro Matsumoto + + * lib/tempfile.rb (Tempfile::make_tmpname): put dot between + basename and pid. [ruby-talk:196272] + +Wed Jun 7 16:16:29 2006 Yukihiro Matsumoto + + * parse.y (do_block): remove -> style block. + + * parse.y (parser_yylex): remove tLAMBDA_ARG. + Wed Jun 7 14:51:22 2006 NAKAMURA Usaku * win32/win32.c (errmap): add some winsock errors. +Wed Jun 7 09:14:44 2006 Yukihiro Matsumoto + + * eval.c (rb_call0): binding for the return event hook should have + consistent scope. [ruby-core:07928] + +Tue Jun 6 23:25:49 2006 Yukihiro Matsumoto + + * eval.c (proc_invoke): return behavior should depend whether it + is surrounded by a lambda or a mere block. + Mon Jun 5 18:12:12 2006 Tanaka Akira * ext/socket/socket.c (sock_s_unpack_sockaddr_in): reject @@ -19,6 +45,20 @@ Sun Jun 4 20:40:19 2006 Tanaka Akira * ext/socket/socket.c: fix sockaddr_un handling. [ruby-dev:28677] +Sat Jun 3 23:53:18 2006 Yukihiro Matsumoto + + * eval.c (formal_assign): handles post splat arguments. + + * eval.c (rb_call0): ditto. + +Sat Jun 3 13:10:41 2006 Yukihiro Matsumoto + + * st.c (strhash): use FNV-1a hash. + +Fri Jun 2 20:01:24 2006 Yukihiro Matsumoto + + * parse.y (parser_yylex): removed experimental ';;' terminator. + Fri Jun 2 19:00:40 2006 GOTOU Yuuzou * ext/openssl/extconf.rb: use create_header. @@ -48,17 +88,67 @@ Thu Jun 1 19:12:37 2006 Nobuyoshi Nakada * win32/win32.c (rb_w32_cmdvector): backslashes inside single-quotes no longer has special meanings. fixed: [ruby-list:42311] +Thu Jun 1 17:55:42 2006 Yukihiro Matsumoto + + * eval.c (rb_node_arity): should be aware of post splat arguments. + + * eval.c (rb_proc_arity): ditto. + Thu Jun 1 16:17:26 2006 NAKAMURA Usaku * win32/win32.c (rb_w32_getcwd): runtime's getcwd() will not success if the length of the cwd is longer than MAX_PATH. fixed [ruby-list:42335] +Thu Jun 1 16:07:48 2006 Yukihiro Matsumoto + + * parse.y (f_args): syntax rule enhanced to support arguments + after the splat. + + * parse.y (mlhs_basic): ditto for multiple assignments + + * parse.y (block_param): ditto for block parameters. + + * parse.y (f_post_arg): mandatory formal arguments after the splat + argument. + + * parse.y (new_args_gen): generate nodes for mandatory formal + arguments after the splat argument. + + * eval.c (rb_eval): dispatch mandatory formal arguments after the + splat argument. + Thu Jun 1 11:33:32 2006 NAKAMURA Usaku * win32/win32.c (rb_w32_getcwd): set errno if not set. fixed [ruby-list:42346] +Thu Jun 1 00:45:52 2006 Yukihiro Matsumoto + + * parse.y (args): allow more than one splat in the argument list. + +Wed May 31 18:38:11 2006 Yukihiro Matsumoto + + * parse.y (method_call): allow aref [] to accept all kind of + method argument, including assocs, splat, and block argument. + + * eval.c (SETUP_ARGS0): prepare block argument as well. + +Tue May 30 18:13:53 2006 Yukihiro Matsumoto + + * lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931] + +Mon May 29 22:40:13 2006 Yukihiro Matsumoto + + * eval.c (error_line): print receivers true/false/nil specially. + + * eval.c (rb_proc_yield): handles parameters in yield semantics. + + * eval.c (nil_yield): gives LocalJumpError to denote no block + error. + + * io.c (rb_io_getc): now takes one-character string. + Sat May 27 22:46:38 2006 Yukihiro Matsumoto * eval.c (proc_invoke): save and restore block in the current frame. @@ -69,6 +159,11 @@ Sat May 27 11:29:46 2006 Nobuyoshi Nakada * ext/extmk.rb (extmake): remove extinit files if no statically linked extensions. +Fri May 26 19:56:46 2006 Yukihiro Matsumoto + + * string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo + hashing algorithm. + Fri May 26 09:05:11 2006 Nobuyoshi Nakada * ruby.h, lib/mkmf.rb (create_header): clear command line options for @@ -103,7 +198,17 @@ Wed May 24 23:52:11 2006 Nobuyoshi Nakada * configure.in (ac_install_sh): ignore dummy install-sh. [ruby-talk:193876] -Wed May 24 03:10:44 2006 GOTOU Yuuzou +Wed May 24 17:55:13 2006 Yukihiro Matsumoto + + * string.c (rb_str_aref): str[0] now returns 1 character string, + instead of a fixnum. [Ruby2] + + * parse.y (parser_yylex): ?c now returns 1 character string, + instead of a fixnum. [Ruby2] + + * string.c (rb_str_aset): no longer support fixnum insertion. + +Wed May 24 03:10:44 2006 GOTOU Yuuzou * ext/openssl/lib/openssl/ssl.rb (OpenSSL::SSL::SocketForwarder#setsockopt,getsockopt): typo fixed. @@ -125,6 +230,16 @@ Mon May 22 16:32:03 2006 Tanaka Akira [ruby-core:7917] +Mon May 22 15:57:39 2006 Yukihiro Matsumoto + + * eval.c (umethod_bind): should not update original class. + [ruby-dev:28636] + +Mon May 22 13:38:57 2006 Yukihiro Matsumoto + + * eval.c (ev_const_get): should support constant access from + within instance_eval(). [ruby-dev:28327] + Sun May 21 09:50:31 2006 K.Kosako * regexec.c: add STK_NULL_CHECK_END to IS_TO_VOID_TARGET(). @@ -152,15 +267,55 @@ Thu May 18 22:37:20 2006 GOTOU Yuuzou * test/webrick/test_utils.rb: test for WEBrick::Utils.timeout. +Thu May 18 17:51:32 2006 Yukihiro Matsumoto + + * time.c (time_timeval): should round for usec floating + number. [ruby-core:07896] + + * time.c (time_add): ditto. + Thu May 18 00:42:12 2006 Nobuyoshi Nakada * ext/extmk.rb, lib/mkmf.rb: use BUILD_FILE_SEPARATOR in Makefiles. +Wed May 17 17:55:26 2006 Yukihiro Matsumoto + + * dir.c (sys_warning): should not call a vararg function + rb_sys_warning() indirectly. [ruby-core:07886] + +Tue May 16 17:23:19 2006 + + * numeric.c (flo_divmod): the first element of Float#divmod should + be an integer. [ruby-dev:28589] + + * test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder. + +Tue May 16 15:34:18 2006 Yukihiro Matsumoto + + * re.c (rb_reg_initialize): should not allow modifying literal + regexps. frozen check moved from rb_reg_initialize_m as well. + +Tue May 16 09:20:16 2006 Yukihiro Matsumoto + + * re.c (rb_reg_initialize): should not modify untainted objects in + safe levels higher than 3. + + * re.c (rb_memcmp): type change from char* to const void*. + + * dir.c (dir_close): should not close untainted dir stream. + + * dir.c (GetDIR): add tainted/frozen check for each dir operation. + Mon May 15 21:37:12 2006 K.Kosako * re.c (rb_reg_prepare_re): don't use onig_recompile(). -Sat May 13 16:14:05 2006 Tanaka Akira +Mon May 15 17:42:39 2006 Yukihiro Matsumoto + + * lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg): + typo fixed. a patch from Florian Gross . + +Sat May 13 16:14:05 2006 Tanaka Akira * lib/pp.rb (PP.mcall): new method. (Struct#pretty_print): call Kernel#class and Struct#members even if @@ -168,11 +323,27 @@ Sat May 13 16:14:05 2006 Tanaka Akira (Struct#pretty_print_cycle): ditto. [ruby-core:7865] -Thu May 11 18:30:11 2006 GOTOU Yuuzou +Fri May 12 15:54:48 2006 Yukihiro Matsumoto + + * eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from + event_hooks. no guarantee for arbitrary hook deletion. + [ruby-dev:28632] + +Thu May 11 19:57:00 2006 Yukihiro Matsumoto + + * util.c (ruby_strtod): differ addition to minimize error. + [ruby-dev:28619] + +Thu May 11 18:30:11 2006 GOTOU Yuuzou * ext/openssl/ossl_cipher.c (add_cipher_name_to_ary): should return value. [ruby-dev:28627] +Thu May 11 18:10:43 2006 Yukihiro Matsumoto + + * util.c (ruby_strtod): should not raise ERANGE when the input + string does not have any digits. [ruby-dev:28629] + Wed May 10 23:40:21 2006 K.Kosako * oniguruma.h: Version 4.0.3 @@ -203,7 +374,46 @@ Sun May 7 03:09:51 2006 Stephan Maka * lib/resolv.rb (Resolv::DNS::Requester::ConnectedUDP#initialize): Use AF_INET6 for nameservers containing colons. -Mon May 1 17:58:16 2006 Masaki Suketa +Sat May 6 23:40:03 2006 Yukihiro Matsumoto + + * eval.c (proc_invoke): should restore old ruby_frame->block. + thanks to ts . [ruby-core:07833] + also fix [ruby-dev:28614] as well. + +Sat May 6 00:38:42 2006 Yukihiro Matsumoto + + * signal.c (trap): sig should be less then NSIG. Coverity found + this bug. a patch from Kevin Tew . + [ruby-core:07823] + +Thu May 4 22:13:22 2006 Yukihiro Matsumoto + + * math.c (math_log2): add new method inspired by + [ruby-talk:191237]. + + * math.c (math_log): add optional base argument to Math::log(). + [ruby-talk:191308] + +Thu May 4 02:24:16 2006 Yukihiro Matsumoto + + * ext/syck/emitter.c (syck_scan_scalar): avoid accessing + uninitialized array element. a patch from Pat Eyler + . [ruby-core:07809] + + * array.c (rb_ary_fill): initialize local variables first. a + patch from Pat Eyler . [ruby-core:07810] + + * ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free + type_tag. a patch from Pat Eyler . + [ruby-core:07808] + +Wed May 3 02:12:07 2006 Yukihiro Matsumoto + + * ext/socket/socket.c (make_hostent_internal): accept ai_family + check from Sam Roberts . + [ruby-core:07691] + +Mon May 1 17:58:16 2006 Masaki Suketa * ext/win32ole/win32ole.c (add_event_call_back): should not delete event handler when the event name is not entried. @@ -218,16 +428,75 @@ Sat Apr 29 22:43:37 2006 GOTOU Yuuzou * ext/openssl/ossl_asn1.c (ossl_asn1_decode0): should initialize flag. [ruby-core:07785] +Fri Apr 28 10:53:16 2006 Yukihiro Matsumoto + + * util.c (ruby_strtod): should not cut off 18 digits for no + reason. [ruby-core:07796] + +Thu Apr 27 01:38:10 2006 Yukihiro Matsumoto + + * array.c (rb_ary_fill): internalize local variable "beg" to + pacify Coverity. [ruby-core:07770] + +Wed Apr 26 16:59:24 2006 Yukihiro Matsumoto + + * pack.c (pack_unpack): now supports CRLF newlines. a patch from + . [ruby-dev:28601] + +Wed Apr 26 16:55:19 2006 Yukihiro Matsumoto + + * applied code clean-up patch from Stefan Huehner + . [ruby-core:07764] + Tue Apr 25 18:00:05 2006 Hidetoshi NAGAI * ext/tk/tcltklib.c (delete_slaves): maybe increment the reference count of a NULL Tcl_Obj [ruby-core:07759]. +Tue Apr 25 07:55:31 2006 Yukihiro Matsumoto + + * lib/jcode.rb (String::tr_s): should have translated non + squeezing character sequence (i.e. a character) as well. thanks + to Hiroshi Ichikawa [ruby-list:42090] + Fri Apr 21 15:19:13 2006 Hidetoshi NAGAI * ext/tk/tcltklib.c (lib_eventloop_ensure): refer freed pointer [ruby-core:07744] and memory leak. +Fri Apr 21 12:14:52 2006 Yukihiro Matsumoto + + * ext/socket/socket.c: document update patch from Sam Roberts + . [ruby-core:07701] + +Thu Apr 20 08:43:54 2006 Yukihiro Matsumoto + + * lib/mathn.rb (Integer): need not to remove gcd2. a patch from + NARUSE, Yui . [ruby-dev:28570] + +Wed Apr 19 13:55:27 2006 Yukihiro Matsumoto + + * parse.y (arg): too much NEW_LIST() + + * eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen. + +Wed Apr 19 11:57:04 2006 Yukihiro Matsumoto + + * eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1. + [ruby-dev:28585] + + * parse.y (arg): use NODE_ARGSCAT for placeholder. + +Wed Apr 19 11:13:17 2006 Yukihiro Matsumoto + + * lib/getoptlong.rb (GetoptLong::get): RDoc update patch from + mathew . [ruby-core:07738] + +Wed Apr 19 10:13:27 2006 Yukihiro Matsumoto + + * variable.c (rb_const_set): raise error when no target klass is + supplied. [ruby-dev:28582] + Tue Apr 18 17:40:37 2006 Hidetoshi NAGAI * ext/tk/lib/multi-tk.rb: add a binding to a container for a slave IP. @@ -238,7 +507,21 @@ Tue Apr 18 17:40:37 2006 Hidetoshi NAGAI * ext/tk/stubs.c: fix potential bugs about handling rb_argv0. -Sat Apr 8 18:06:28 2006 Masaki Suketa +Mon Apr 10 01:03:10 2006 Yukihiro Matsumoto + + * prec.c (prec_prec_f): documentation patch from + . [ruby-core:07689] + +Sat Apr 8 02:34:34 2006 Yukihiro Matsumoto + + * bignum.c (rb_big_pow): second operand may be too big even if + it's a Fixnum. [ruby-talk:187984] + +Sat Apr 8 02:12:38 2006 Yukihiro Matsumoto + + * README.EXT: update symbol description. [ruby-talk:188104] + +Sat Apr 8 18:06:28 2006 Masaki Suketa * ext/win32ole/win32ole.c: add WIN32OLE_METHOD#inspect, WIN32OLE_PARAM#inspect. @@ -254,7 +537,11 @@ Fri Apr 7 22:11:30 2006 Masaki Suketa * test/win32ole/test_win32ole_typelib.rb(test_initialize): ditto. -Thu Apr 6 16:43:06 2006 Hidetoshi NAGAI +Thu Apr 6 23:28:47 2006 Yukihiro Matsumoto + + * COPYING: explicitly note GPLv2. [ruby-talk:187922] + +Thu Apr 6 16:43:06 2006 Hidetoshi NAGAI * intern.h (rb_obj_instance_exec, rb_mod_module_exec): add declaration. @@ -287,7 +574,12 @@ Wed Apr 5 00:22:54 2006 Tanaka Akira methods take pathname argument. suggested by Evan Phoenix. [ruby-core:7618] -Sat Apr 1 15:11:27 2006 Masaki Suketa +Tue Apr 4 22:15:41 2006 Yukihiro Matsumoto + + * parse.y: remove some obsolete syntax rules (unparenthesized + method calls in argument list). + +Sat Apr 1 15:11:27 2006 Masaki Suketa * ext/win32ole/win32ole.c :add WIN32OLE_TYPE#inspect, WIN32OLE_VARIABLE#inspect @@ -337,6 +629,14 @@ Mon Mar 27 22:45:37 2006 NARUSE, Yui * ext/nkf/nkf.c, ext/nkf/lib/kconv.rb: Add rdoc. +Mon Mar 27 03:17:21 2006 Yukihiro Matsumoto + + * eval.c (rb_call0): insecure calling should be checked for non + NODE_SCOPE method invocations too. + + * eval.c (rb_alias): should preserve the current safe level as + well as method definition. + Sun Mar 26 22:02:51 2006 K.Kosako * re.c: refactoring for options. @@ -351,6 +651,11 @@ Fri Mar 24 21:11:02 2006 K.Kosako * string.c (rb_str_gsub): ditto. +Fri Mar 24 17:20:03 2006 Yukihiro Matsumoto + + * process.c (rb_f_sleep): remove RDoc description about SIGALRM + which is not valid on the current implementation. [ruby-dev:28464] + Thu Mar 23 21:40:47 2006 K.Kosako * re.c (rb_reg_regsub): prohibit \1, \2 ...\9 in replaced string @@ -366,6 +671,12 @@ Thu Mar 23 21:06:23 2006 K.Kosako * regerror.c: ditto. +Thu Mar 23 10:47:03 2006 Yukihiro Matsumoto + + * eval.c (method_missing): should support argument splat in + super. a bug in combination of super, splat and + method_missing. [ruby-talk:185438] + Thu Mar 23 00:01:32 2006 K.Kosako * re.c (rb_reg_regsub): add back reference by name \k in @@ -387,15 +698,25 @@ Tue Mar 21 22:14:01 2006 K.Kosako * gc.c (gc_mark_children): add gc_mark() to regexp member. +Mon Mar 20 12:05:18 2006 Yukihiro Matsumoto + + * configure.in: Solaris SunPro compiler -rapth patch from + . [ruby-dev:28443] + Mon Mar 20 11:12:38 2006 NAKAMURA Usaku * ext/win32ole/win32ole.c (folevariant_value): could not compile with C90 compiler. -Sun Mar 19 09:46:30 2006 Masaki Suketa +Mon Mar 20 09:40:23 2006 Yukihiro Matsumoto + + * configure.in: remove enable_rpath=no for Solaris. + [ruby-dev:28440] + +Sun Mar 19 09:46:30 2006 Masaki Suketa * ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior - of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby + of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby String object. * ext/win32ole/win32ole.c (folevariant_value): ditto. @@ -421,7 +742,12 @@ Sun Mar 12 17:02:10 2006 Masaki Suketa * ext/win32ole/tests/testOLEPARAM.rb: test method name should not be duplicated. -Sun Mar 5 18:40:58 2006 Minero Aoki +Sat Mar 11 14:24:06 2006 Yukihiro Matsumoto + + * ruby.1: a clarification patch from David Lutterkort + . [ruby-core:7508] + +Sun Mar 5 18:40:58 2006 Minero Aoki * lib/fileutils.rb: do not repeat command options. @@ -434,16 +760,25 @@ Sat Mar 4 15:26:40 2006 Tanaka Akira * gc.c (id2ref): fix symbol test. -Fri Mar 3 21:22:42 2006 Tanaka Akira +Sat Mar 4 01:08:07 2006 Yukihiro Matsumoto + + * lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems + directories. a patch from Eric Hodel . + [ruby-core:07423] + +Fri Mar 3 17:59:00 2006 Yukihiro Matsumoto + + * eval.c (rb_clear_cache_by_class): clearing wrong cache. + +Fri Mar 3 21:22:42 2006 Tanaka Akira * lib/fileutils.rb (FileUtils.cp_r): implement :remove_destination option. * ext/extmk.rb: use :remove_destination to install extension libraries - to avoid SEGV. - [ruby-dev:28417] + to avoid SEGV. [ruby-dev:28417] -Fri Mar 3 14:41:04 2006 Minero Aoki +Fri Mar 3 14:41:04 2006 Minero Aoki * ext/dl/.cvsignore: ignore callback.h. @@ -451,7 +786,40 @@ Fri Mar 3 14:41:04 2006 Minero Aoki * ext/socket/.cvsignore: ignore constants.h. -Thu Mar 2 17:54:45 2006 Hirokazu Yamamoto +Thu Mar 2 18:58:18 2006 Yukihiro Matsumoto + + * eval.c (rb_thread_fd_writable): should not re-schedule output + from KILLED thread (must be error printing). + +Thu Mar 2 09:12:05 2006 Yukihiro Matsumoto + + * array.c (rb_ary_flatten_bang): allow specifying recursion + level. [ruby-talk:182170] + + * array.c (rb_ary_flatten): ditto. + +Thu Mar 2 08:02:42 2006 Yukihiro Matsumoto + + * gc.c (add_heap): a heap_slots may overflow. a patch from Stefan + Weil . + +Wed Mar 1 17:13:37 2006 Yukihiro Matsumoto + + * eval.c (rb_call): use separate cache for fcall/vcall + invocation. + + * eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local + functions. + + * eval.c (rb_mod_local): a new method to specify newly added + visibility "local". + + * eval.c (search_method): search for local methods which are + visible only from the current class. + + * class.c (rb_class_local_methods): a method to list local methods. + +Thu Mar 2 17:54:45 2006 Hirokazu Yamamoto * gc.c: commited magic for reducing RVALUE size on windows. (24->20byte) [ruby-core:7474] @@ -476,6 +844,16 @@ Wed Mar 1 00:15:51 2006 Hirokazu Yamamoto merged Mr. Ishizuka's lib/irb/ruby-lex.rb 's patch rev 1.29. [ruby-talk:181631] [ruby-dev:28404] +Tue Feb 28 19:32:14 2006 Yukihiro Matsumoto + + * object.c (Init_Object): add BasicObject class as a top level + BlankSlate class. + +Mon Feb 27 00:19:16 2006 Yukihiro Matsumoto + + * ruby.h (SYM2ID): should not cast to signed long. + [ruby-core:07414] + Fri Feb 24 20:21:38 2006 Masatoshi SEKI * test/drb/drbtest.rb (add_service_command): quote pathnames in the diff --git a/README.EXT b/README.EXT index 80ac978b99..ca402bf33b 100644 --- a/README.EXT +++ b/README.EXT @@ -330,17 +330,30 @@ of the innermost method (which is defined by Ruby) can be accessed. 2.2.2 ID or Symbol -You can invoke methods directly, without parsing the string. First I -need to explain about symbols (whose data type is ID). ID is the -integer number to represent Ruby's identifiers such as variable names. -It can be accessed from Ruby in the form: +You can invoke methods directly, without parsing the string. First I need +to explain about ID. ID is the integer number to represent Ruby's +identifiers such as variable names. The Ruby data type corresponding to ID +is Symbol. It can be accessed from Ruby in the form: :Identifier -You can get the symbol value from a string within C code by using +You can get the ID value from a string within C code by using rb_intern(const char *name) +You can retrieve ID from Ruby object (Symbol or String) given as an +argument by using + + rb_to_id(VALUE symbol) + +You can convert C ID to Ruby Symbol by using + + VALUE ID2SYM(ID id) + +and to convert Ruby Symbol object to ID, use + + ID SYM2ID(VALUE symbol) + 2.2.3 Invoke Ruby method from C To invoke methods directly, you can use the function below diff --git a/array.c b/array.c index f79a79c784..79db7d4618 100644 --- a/array.c +++ b/array.c @@ -17,7 +17,7 @@ #include "st.h" #include "node.h" -VALUE rb_cArray, rb_cValues; +VALUE rb_cArray; static ID id_cmp; @@ -169,38 +169,6 @@ rb_ary_new4(long n, const VALUE *elts) return ary; } -VALUE -rb_values_new(long n, ...) -{ - va_list ar; - VALUE val; - long i; - - val = ary_new(rb_cValues, n); - va_start(ar, n); - for (i=0; iptr[i] = va_arg(ar, VALUE); - } - va_end(ar); - RARRAY(val)->len = n; - - return val; -} - -VALUE -rb_values_new2(long n, const VALUE *elts) -{ - VALUE val; - - val = ary_new(rb_cValues, n); - if (n > 0 && elts) { - RARRAY(val)->len = n; - MEMCPY(RARRAY(val)->ptr, elts, VALUE, n); - } - - return val; -} - static VALUE ary_make_shared(VALUE ary) { @@ -234,22 +202,10 @@ ary_shared_array(VALUE klass, VALUE ary) return val; } -VALUE -rb_values_from_ary(VALUE ary) -{ - return ary_shared_array(rb_cValues, ary); -} - -VALUE -rb_ary_from_values(VALUE val) -{ - return ary_shared_array(rb_cArray, val); -} - VALUE rb_assoc_new(VALUE car, VALUE cdr) { - return rb_values_new(2, car, cdr); + return rb_ary_new3(2, car, cdr); } static VALUE @@ -2099,7 +2055,7 @@ static VALUE rb_ary_fill(int argc, VALUE *argv, VALUE ary) { VALUE item, arg1, arg2; - long beg, end, len; + long beg = 0, end = 0, len = 0; VALUE *p, *pend; int block_p = Qfalse; @@ -2739,27 +2695,30 @@ rb_ary_nitems(VALUE ary) } static long -flatten(VALUE ary, long idx, VALUE ary2, VALUE memo) +flatten(VALUE ary, long idx, VALUE ary2, VALUE memo, int level) { VALUE id; long i = idx; long n, lim = idx + RARRAY(ary2)->len; + level--; id = rb_obj_id(ary2); if (rb_ary_includes(memo, id)) { rb_raise(rb_eArgError, "tried to flatten recursive array"); } rb_ary_push(memo, id); rb_ary_splice(ary, idx, 1, ary2); - while (i < lim) { - VALUE tmp; - - tmp = rb_check_array_type(rb_ary_elt(ary, i)); - if (!NIL_P(tmp)) { - n = flatten(ary, i, tmp, memo); - i += n; lim += n; + if (level != 0) { + while (i < lim) { + VALUE tmp; + + tmp = rb_check_array_type(rb_ary_elt(ary, i)); + if (!NIL_P(tmp)) { + n = flatten(ary, i, tmp, memo, level); + i += n; lim += n; + } + i++; } - i++; } rb_ary_pop(memo); @@ -2768,25 +2727,34 @@ flatten(VALUE ary, long idx, VALUE ary2, VALUE memo) /* * call-seq: - * array.flatten! -> array or nil + * array.flatten! -> array or nil + * array.flatten!(level) -> array or nil * * Flattens _self_ in place. * Returns nil if no modifications were made (i.e., - * array contains no subarrays.) + * array contains no subarrays.) If the optional level + * argument determins the level of recursion to flatten. * * a = [ 1, 2, [3, [4, 5] ] ] - * a.flatten! #=> [1, 2, 3, 4, 5] - * a.flatten! #=> nil - * a #=> [1, 2, 3, 4, 5] + * a.flatten! #=> [1, 2, 3, 4, 5] + * a.flatten! #=> nil + * a #=> [1, 2, 3, 4, 5] + * a = [ 1, 2, [3, [4, 5] ] ] + * a.flatten!(1) #=> [1, 2, 3, [4, 5]] */ static VALUE -rb_ary_flatten_bang(VALUE ary) +rb_ary_flatten_bang(int argc, VALUE *argv, VALUE ary) { long i = 0; int mod = 0; + int level = -1; VALUE memo = Qnil; + VALUE lv; + rb_scan_args(argc, argv, "01", &lv); + if (!NIL_P(lv)) level = FIX2INT(lv); + if (level == 0) return ary; while (ilen) { VALUE ary2 = RARRAY(ary)->ptr[i]; VALUE tmp; @@ -2796,7 +2764,7 @@ rb_ary_flatten_bang(VALUE ary) if (NIL_P(memo)) { memo = rb_ary_new(); } - i += flatten(ary, i, tmp, memo); + i += flatten(ary, i, tmp, memo, level); mod = 1; } i++; @@ -2808,22 +2776,26 @@ rb_ary_flatten_bang(VALUE ary) /* * call-seq: * array.flatten -> an_array + * array.flatten(level) -> an_array * * Returns a new array that is a one-dimensional flattening of this * array (recursively). That is, for every element that is an array, - * extract its elements into the new array. + * extract its elements into the new array. If the optional + * level argument determins the level of recursion to flatten. * * s = [ 1, 2, 3 ] #=> [1, 2, 3] * t = [ 4, 5, 6, [7, 8] ] #=> [4, 5, 6, [7, 8]] * a = [ s, t, 9, 10 ] #=> [[1, 2, 3], [4, 5, 6, [7, 8]], 9, 10] * a.flatten #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10 + * a = [ 1, 2, [3, [4, 5] ] ] + * a.flatten(1) #=> [1, 2, 3, [4, 5]] */ static VALUE -rb_ary_flatten(VALUE ary) +rb_ary_flatten(int argc, VALUE *argv, VALUE ary) { ary = rb_ary_dup(ary); - rb_ary_flatten_bang(ary); + rb_ary_flatten_bang(argc, argv, ary); return ary; } @@ -2918,11 +2890,9 @@ Init_Array(void) rb_define_method(rb_cArray, "uniq!", rb_ary_uniq_bang, 0); rb_define_method(rb_cArray, "compact", rb_ary_compact, 0); rb_define_method(rb_cArray, "compact!", rb_ary_compact_bang, 0); - rb_define_method(rb_cArray, "flatten", rb_ary_flatten, 0); - rb_define_method(rb_cArray, "flatten!", rb_ary_flatten_bang, 0); + rb_define_method(rb_cArray, "flatten", rb_ary_flatten, -1); + rb_define_method(rb_cArray, "flatten!", rb_ary_flatten_bang, -1); rb_define_method(rb_cArray, "nitems", rb_ary_nitems, 0); id_cmp = rb_intern("<=>"); - - rb_cValues = rb_define_class("Values", rb_cArray); } diff --git a/bignum.c b/bignum.c index 4c070c5c45..2bd44c2bf9 100644 --- a/bignum.c +++ b/bignum.c @@ -406,7 +406,7 @@ rb_cstr_to_inum(const char *str, int base, int badcheck) len *= strlen(str)*sizeof(char); if (len <= (sizeof(VALUE)*CHAR_BIT)) { - unsigned long val = strtoul((char*)str, &end, base); + unsigned long val = strtoul(str, &end, base); if (*end == '_') goto bigparse; if (badcheck) { @@ -516,7 +516,7 @@ rb_str_to_inum(VALUE str, int base, int badcheck) #if HAVE_LONG_LONG -VALUE +static VALUE rb_ull2big(unsigned LONG_LONG n) { BDIGIT_DBL num = n; @@ -537,7 +537,7 @@ rb_ull2big(unsigned LONG_LONG n) return big; } -VALUE +static VALUE rb_ll2big(LONG_LONG n) { long neg = 0; @@ -595,10 +595,10 @@ rb_big2str(VALUE x, int base) if (FIXNUM_P(x)) { return rb_fix2str(x, base); } - i = RBIGNUM(x)->len; if (BIGZEROP(x)) { return rb_str_new2("0"); } + i = RBIGNUM(x)->len; j = SIZEOF_BDIGITS*CHAR_BIT*i; switch (base) { case 2: break; @@ -1546,6 +1546,11 @@ rb_big_pow(VALUE x, VALUE y) if (yy > 0) { VALUE z = x; + if (RBIGNUM(x)->len * SIZEOF_BDIGITS * yy > 1024*1024) { + rb_warn("in a**b, b may be too big"); + d = (double)yy; + break; + } for (;;) { yy -= 1; if (yy == 0) break; diff --git a/class.c b/class.c index 2aac32fc0e..c7aa72344d 100644 --- a/class.c +++ b/class.c @@ -344,7 +344,7 @@ include_class_new(VALUE module, VALUE super) void rb_include_module(VALUE klass, VALUE module) { - VALUE p, c; + VALUE c; int changed = 0; rb_frozen_class_p(klass); @@ -362,30 +362,11 @@ rb_include_module(VALUE klass, VALUE module) OBJ_INFECT(klass, module); c = klass; while (module) { - int superclass_seen = Qfalse; - if (RCLASS(klass)->m_tbl == RCLASS(module)->m_tbl) rb_raise(rb_eArgError, "cyclic include detected"); - /* ignore if the module included already in superclasses */ - for (p = RCLASS(klass)->super; p; p = RCLASS(p)->super) { - switch (BUILTIN_TYPE(p)) { - case T_ICLASS: - if (RCLASS(p)->m_tbl == RCLASS(module)->m_tbl) { - if (!superclass_seen) { - c = p; /* move insertion point */ - } - goto skip; - } - break; - case T_CLASS: - superclass_seen = Qtrue; - break; - } - } RCLASS(c)->super = include_class_new(module, RCLASS(c)->super); c = RCLASS(c)->super; changed = 1; - skip: module = RCLASS(module)->super; } if (changed) rb_clear_cache(); @@ -500,6 +481,7 @@ ins_methods_push(ID name, long type, VALUE ary, long visi) case NOEX_PRIVATE: case NOEX_PROTECTED: case NOEX_PUBLIC: + case NOEX_LOCAL: visi = (type == visi); break; default: @@ -536,6 +518,12 @@ ins_methods_pub_i(ID name, long type, VALUE ary) return ins_methods_push(name, type, ary, NOEX_PUBLIC); } +static int +ins_methods_local_i(ID name, long type, VALUE ary) +{ + return ins_methods_push(name, type, ary, NOEX_LOCAL); +} + static int method_entry(ID key, NODE *body, st_table *list) { @@ -666,6 +654,19 @@ rb_class_public_instance_methods(int argc, VALUE *argv, VALUE mod) return class_instance_method_list(argc, argv, mod, ins_methods_pub_i); } +/* + * call-seq: + * mod.local_methods => array + * + * Returns a list of the local methods defined in mod. + */ + +VALUE +rb_class_local_methods(VALUE mod) +{ + return class_instance_method_list(0, 0, mod, ins_methods_local_i); +} + /* * call-seq: * obj.singleton_methods(all=true) => array diff --git a/configure.in b/configure.in index a37e8e981c..e9fcc2fb24 100644 --- a/configure.in +++ b/configure.in @@ -509,7 +509,7 @@ AC_CHECK_FUNCS(fmod killpg wait4 waitpid fork spawnv syscall chroot fsync getcwd getpgrp setpgrp getpgid setpgid initgroups getgroups setgroups\ getpriority getrlimit setrlimit\ dlopen sigprocmask sigaction _setjmp vsnprintf snprintf\ - setsid telldir seekdir fchmod mktime timegm cosh sinh tanh\ + setsid telldir seekdir fchmod mktime timegm cosh sinh tanh log2\ setuid setgid daemon select_large_fdset setenv unsetenv) AC_ARG_ENABLE(setreuid, [ --enable-setreuid use setreuid()/setregid() according to need even if obsolete.], @@ -1265,8 +1265,6 @@ if test "$enable_shared" = 'yes'; then LIBRUBY_ALIASES='lib$(RUBY_SO_NAME).so.$(MAJOR).$(MINOR).$(TEENY) lib$(RUBY_SO_NAME).so' if test "$GCC" = yes; then LIBRUBY_DLDFLAGS="$DLDFLAGS "'-Wl,-h,$(@F)' - else - enable_rpath=no fi XLDFLAGS="$XLDFLAGS "'-R${libdir}' ;; @@ -1307,7 +1305,11 @@ if test "$enable_shared" = 'yes'; then esac fi if test "$enable_rpath" = yes; then - LIBRUBYARG_SHARED='-Wl,-R -Wl,$(libdir) -L$(libdir) -L. '"$LIBRUBYARG_SHARED" + if test "$GCC" = yes; then + LIBRUBYARG_SHARED='-Wl,-R -Wl,$(libdir) -L$(libdir) -L. '"$LIBRUBYARG_SHARED" + else + LIBRUBYARG_SHARED='-R $(libdir) -L$(libdir) -L. '"$LIBRUBYARG_SHARED" + fi fi XLDFLAGS="$XLDFLAGS -L." diff --git a/dir.c b/dir.c index 42668d338f..2c868c2747 100644 --- a/dir.c +++ b/dir.c @@ -441,7 +441,16 @@ dir_closed(void) rb_raise(rb_eIOError, "closed directory"); } +static void +dir_check(VALUE dir) +{ + if (!OBJ_TAINTED(dir) && rb_safe_level() >= 4) + rb_raise(rb_eSecurityError, "Insecure: operation on untainted Dir"); + rb_check_frozen(dir); +} + #define GetDIR(obj, dirp) do {\ + dir_check(dir);\ Data_Get_Struct(obj, struct dir_data, dirp);\ if (dirp->dir == NULL) dir_closed();\ } while (0) @@ -647,6 +656,9 @@ dir_rewind(VALUE dir) { struct dir_data *dirp; + if (rb_safe_level() >= 4 && !OBJ_TAINTED(dir)) { + rb_raise(rb_eSecurityError, "Insecure: can't close"); + } GetDIR(dir, dirp); rewinddir(dirp->dir); return dir; @@ -903,9 +915,15 @@ dir_s_rmdir(VALUE obj, VALUE dir) return INT2FIX(0); } +static void +sys_warning_1(const char* mesg) +{ + rb_sys_warning("%s", mesg); +} + #define GLOB_VERBOSE (1 << (sizeof(int) * CHAR_BIT - 1)) #define sys_warning(val) \ - ((flags & GLOB_VERBOSE) && rb_protect((VALUE (*)(VALUE))rb_sys_warning, (VALUE)(val), 0)) + ((flags & GLOB_VERBOSE) && rb_protect((VALUE (*)_((VALUE)))sys_warning_1, (VALUE)(val), 0)) /* System call with warning */ static int diff --git a/enumerator.c b/enumerator.c index 4446eb45e8..94e32dfb24 100644 --- a/enumerator.c +++ b/enumerator.c @@ -27,7 +27,7 @@ static VALUE proc_call(VALUE proc, VALUE args) { if (TYPE(args) != T_ARRAY) { - args = rb_values_new(1, args); + args = rb_ary_new3(1, args); } return rb_proc_call(proc, args); } diff --git a/error.c b/error.c index 9c292eaaa1..e03ad2bb3d 100644 --- a/error.c +++ b/error.c @@ -209,7 +209,7 @@ rb_check_type(VALUE x, int t) if (TYPE(x) != t) { while (type->type >= 0) { if (type->type == t) { - char *etype; + const char *etype; if (NIL_P(x)) { etype = "nil"; @@ -434,7 +434,7 @@ static VALUE check_backtrace(VALUE bt) { long i; - static char *err = "backtrace must be Array of String"; + static const char *err = "backtrace must be Array of String"; if (!NIL_P(bt)) { int t = TYPE(bt); @@ -683,7 +683,7 @@ name_err_mesg_to_str(VALUE obj) mesg = ptr[0]; if (NIL_P(mesg)) return Qnil; else { - char *desc = 0; + const char *desc = 0; VALUE d = 0, args[3]; obj = ptr[1]; @@ -828,7 +828,7 @@ syserr_initialize(int argc, VALUE *argv, VALUE self) #if !defined(_WIN32) && !defined(__VMS) char *strerror(); #endif - char *err; + const char *err; VALUE mesg, error; VALUE klass = rb_obj_class(self); diff --git a/eval.c b/eval.c index 7fbf3f2bcb..99c70411a1 100644 --- a/eval.c +++ b/eval.c @@ -236,7 +236,7 @@ typedef jmp_buf rb_jmpbuf_t; VALUE rb_cProc; static VALUE rb_cBinding; -static VALUE proc_invoke(VALUE,VALUE,VALUE,VALUE); +static VALUE proc_invoke(VALUE,VALUE,VALUE,VALUE,int); static VALUE proc_lambda(void); static VALUE rb_f_binding(VALUE); static void rb_f_END(void); @@ -253,7 +253,8 @@ static int vis_mode; #define VIS_PRIVATE 1 #define VIS_PROTECTED 2 #define VIS_MODFUNC 5 -#define VIS_MASK 7 +#define VIS_LOCAL 8 +#define VIS_MASK 16 #define VIS_SET(f) (vis_mode=(f)) #define VIS_TEST(f) (vis_mode&(f)) #define VIS_MODE() (vis_mode) @@ -316,9 +317,9 @@ rb_check_safe_str(VALUE x) } } -NORETURN(static void print_undef(VALUE, ID)); +NORETURN(static void raise_undef(VALUE, ID)); static void -print_undef(VALUE klass, ID id) +raise_undef(VALUE klass, ID id) { rb_name_error(id, "undefined method `%s' for %s `%s'", rb_id2name(id), @@ -332,7 +333,7 @@ static ID removed, singleton_removed, undefined, singleton_undefined; #define CACHE_MASK 0x7ff #define EXPR1(c,m) ((((c)>>3)^(m))&CACHE_MASK) -struct cache_entry { /* method hash table. */ +struct cache_entry { /* method hash table. */ ID mid; /* method's id */ ID mid0; /* method's original id */ VALUE klass; /* receiver's class */ @@ -341,64 +342,65 @@ struct cache_entry { /* method hash table. */ int noex; }; -static struct cache_entry cache[CACHE_SIZE]; +static struct cache_entry cache[2][CACHE_SIZE]; static int ruby_running = 0; void -rb_clear_cache(void) +rb_clear_cache() { - struct cache_entry *ent, *end; + int i; if (!ruby_running) return; - ent = cache; end = ent + CACHE_SIZE; - while (ent < end) { - ent->mid = 0; - ent++; + for (i=0; iorigin == klass && ent->mid == id) { - ent->mid = 0; + for (i=0; iorigin == klass && ent->mid == id) { + ent->mid = 0; + } } - ent++; } } static void rb_clear_cache_by_id(ID id) { - struct cache_entry *ent, *end; + int i, j; if (!ruby_running) return; - ent = cache; end = ent + CACHE_SIZE; - while (ent < end) { - if (ent->mid == id) { - ent->mid = 0; + for (i=0; imid == id) { + ent->mid = 0; + } } - ent++; } } void rb_clear_cache_by_class(VALUE klass) { - struct cache_entry *ent, *end; + int i, j; if (!ruby_running) return; - ent = cache; end = ent + CACHE_SIZE; - while (ent < end) { - if (ent->klass == klass || ent->origin == klass) { - ent->mid = 0; + for (i=0; iklass == klass || ent->origin == klass) { + ent->mid = 0; + } } - ent++; } } @@ -406,8 +408,8 @@ static ID init, eqq, each, aref, aset, match, missing; static ID added, singleton_added; static ID __id__, __send__, respond_to; -#define NOEX_SAFE(n) ((n) >> 4) -#define NOEX_WITH(n, v) ((n) | (v) << 4) +#define NOEX_SAFE(n) ((n) >> 5) +#define NOEX_WITH(n, v) ((n) | (v) << 5) #define NOEX_WITH_SAFE(n) NOEX_WITH(n, ruby_safe_level) void @@ -458,19 +460,30 @@ rb_undef_alloc_func(VALUE klass) rb_add_method(CLASS_OF(klass), ID_ALLOCATOR, 0, NOEX_UNDEF); } +#define LOOKUP_NORMAL 0 +#define LOOKUP_FCALL 1 +#define LOOKUP_NOSKIP 2 + static NODE* -search_method(VALUE klass, ID id, VALUE *origin) +search_method(VALUE klass, ID id, VALUE *origin, int flag) { NODE *body; - if (!klass) return 0; - while (!st_lookup(RCLASS(klass)->m_tbl, id, (st_data_t *)&body)) { - klass = RCLASS(klass)->super; - if (!klass) return 0; + if (flag == LOOKUP_FCALL && ruby_frame->this_class) { + if (st_lookup(RCLASS(ruby_frame->this_class)->m_tbl, id, (st_data_t *)&body) && + body->nd_noex == NOEX_LOCAL) { + if (origin) *origin = ruby_frame->this_class; + return body; + } } - - if (origin) *origin = klass; - return body; + for (;klass; klass = RCLASS(klass)->super) { + if (st_lookup(RCLASS(klass)->m_tbl, id, (st_data_t *)&body) && + (flag == LOOKUP_NOSKIP || body->nd_noex != NOEX_LOCAL)) { + if (origin) *origin = klass; + return body; + } + } + return 0; } static NODE* @@ -481,10 +494,11 @@ rb_get_method_body(VALUE *klassp, ID *idp, int *noexp) VALUE origin; NODE * volatile body; struct cache_entry *ent; + int noex = *noexp; - if ((body = search_method(klass, id, &origin)) == 0 || !body->nd_body) { + if ((body = search_method(klass, id, &origin, noex)) == 0 || !body->nd_body) { /* store empty info in cache */ - ent = cache + EXPR1(klass, id); + ent = cache[noex] + EXPR1(klass, id); ent->klass = klass; ent->origin = klass; ent->mid = ent->mid0 = id; @@ -496,9 +510,9 @@ rb_get_method_body(VALUE *klassp, ID *idp, int *noexp) if (ruby_running) { /* store in cache */ - ent = cache + EXPR1(klass, id); - ent->klass = klass; - ent->noex = body->nd_noex; + ent = cache[noex] + EXPR1(klass, id); + ent->klass = klass; + ent->noex = body->nd_noex; if (noexp) *noexp = body->nd_noex; body = body->nd_body; if (nd_type(body) == NODE_FBODY) { @@ -534,10 +548,10 @@ rb_get_method_body(VALUE *klassp, ID *idp, int *noexp) NODE* rb_method_node(VALUE klass, ID id) { - int noex; + int noex = 0; struct cache_entry *ent; - ent = cache + EXPR1(klass, id); + ent = cache[0] + EXPR1(klass, id); if (ent->mid == id && ent->klass == klass && ent->method){ return ent->method; } @@ -565,7 +579,7 @@ remove_method(VALUE klass, ID mid) rb_name_error(mid, "method `%s' not defined in %s", rb_id2name(mid), rb_class2name(klass)); } - rb_clear_cache_for_undef(klass, mid); + rb_clear_cache_for_remove(klass, mid); if (FL_TEST(klass, FL_SINGLETON)) { rb_funcall(rb_iv_get(klass, "__attached__"), singleton_removed, 1, ID2SYM(mid)); } @@ -623,12 +637,12 @@ rb_export_method(VALUE klass, ID name, ID noex) if (klass == rb_cObject) { rb_secure(4); } - body = search_method(klass, name, &origin); + body = search_method(klass, name, &origin, LOOKUP_NOSKIP); if (!body && TYPE(klass) == T_MODULE) { - body = search_method(rb_cObject, name, &origin); + body = search_method(rb_cObject, name, &origin, LOOKUP_NOSKIP); } if (!body || !body->nd_body) { - print_undef(klass, name); + raise_undef(klass, name); } if (body->nd_noex != noex) { if (klass == origin) { @@ -640,38 +654,52 @@ rb_export_method(VALUE klass, ID name, ID noex) } } -int -rb_method_boundp(VALUE klass, ID id, int ex) +static int +method_exists(VALUE klass, ID id, int noex) { struct cache_entry *ent; - int noex; + int nx = noex; - /* is it in the method cache? */ - ent = cache + EXPR1(klass, id); - if (ent->mid == id && ent->klass == klass) { - if (ex && (ent->noex & NOEX_PRIVATE)) - return Qfalse; - if (!ent->method) return Qfalse; - return Qtrue; - } - if (rb_get_method_body(&klass, &id, &noex)) { - if (ex && (noex & NOEX_PRIVATE)) - return Qfalse; - return Qtrue; + switch (noex) { + case LOOKUP_NORMAL: + case LOOKUP_FCALL: + /* is it in the method cache? */ + ent = cache[noex] + EXPR1(klass, id); + if (ent->mid == id && ent->klass == klass) { + if (nx == LOOKUP_NORMAL) { + if (ent->noex == NOEX_PRIVATE) return Qfalse; + } + else if (ent->noex != NOEX_LOCAL) { + if (!ent->method) return Qfalse; + return Qtrue; + } + } + /* fall through */ + default: + if (rb_get_method_body(&klass, &id, &noex)) { + if (nx == LOOKUP_NORMAL && noex == NOEX_PRIVATE) + return Qfalse; + return Qtrue; + } + return Qfalse; } - return Qfalse; +} + +int +rb_method_boundp(VALUE klass, ID id, int pub) +{ + return method_exists(klass, id, pub ? LOOKUP_NORMAL : LOOKUP_FCALL); } void -rb_attr(VALUE klass, ID id, int read, int write, int ex) +rb_attr(VALUE klass, ID id, int read, int write, int noex) { const char *name; char *buf; ID attriv; - int noex; size_t len; - if (!ex) noex = NOEX_PUBLIC; + if (!noex) noex = NOEX_PUBLIC; else { if (VIS_TEST(VIS_PRIVATE)) { noex = NOEX_PRIVATE; @@ -1017,7 +1045,7 @@ static VALUE rb_eval(VALUE,NODE*); static VALUE eval(VALUE,VALUE,VALUE,const char*,int); static NODE *compile(VALUE, const char*, int); -static VALUE rb_yield_0(VALUE, VALUE, VALUE, int, int); +static VALUE rb_yield_0(VALUE, VALUE, VALUE, int); #define YIELD_LAMBDA_CALL 1 #define YIELD_PROC_CALL 2 @@ -1027,12 +1055,13 @@ static VALUE rb_yield_0(VALUE, VALUE, VALUE, int, int); typedef enum calling_scope { CALLING_NORMAL, + CALLING_FUNCALL, CALLING_FCALL, CALLING_VCALL, CALLING_SUPER, } calling_scope_t; -static VALUE rb_call(VALUE,VALUE,ID,int,const VALUE*,struct BLOCK*,calling_scope_t); +static VALUE rb_call(VALUE,VALUE,ID,int,const VALUE*,struct BLOCK*,calling_scope_t,int); static VALUE module_setup(VALUE,NODE*); static VALUE massign(VALUE,NODE*,VALUE,int); @@ -1049,11 +1078,16 @@ static rb_event_hook_t *event_hooks; #define EXEC_EVENT_HOOK(event, node, self, id, klass) \ do { \ - rb_event_hook_t *hook; \ + rb_event_hook_t *hook = event_hooks; \ + rb_event_hook_func_t hook_func; \ + rb_event_t events; \ \ - for (hook = event_hooks; hook; hook = hook->next) { \ - if (hook->events & event) \ - (*hook->func)(event, node, self, id, klass); \ + while (hook) { \ + hook_func = hook->func; \ + events = hook->events; \ + hook = hook->next; \ + if (events & event) \ + (*hook_func)(event, node, self, id, klass); \ } \ } while (0) @@ -1112,7 +1146,20 @@ error_line(struct FRAME *frame, NODE *node) } else { VALUE oklass = frame->this_class; - + char *rec = 0; + + switch (TYPE(frame->self)) { + case T_NIL: + rec = "nil"; break; + case T_TRUE: + rec = "true"; break; + case T_FALSE: + rec = "false"; break; + } + if (rec) { + return rb_sprintf("%s:%d:in `%s.%s'", file, line, rec, + rb_id2name(frame->this_func)); + } if (TYPE(oklass) == T_ICLASS) { oklass = RBASIC(oklass)->klass; } @@ -1638,9 +1685,9 @@ rb_eval_string_wrap(const char *str, int *state) return val; } -NORETURN(static void localjump_error(const char*, VALUE, int)); +NORETURN(static void localjump_error(const char*, VALUE, int, VALUE)); static void -localjump_error(const char *mesg, VALUE value, int reason) +localjump_error(const char *mesg, VALUE value, int reason, VALUE bt) { VALUE exc = rb_exc_new2(rb_eLocalJumpError, mesg); ID id; @@ -1658,9 +1705,10 @@ localjump_error(const char *mesg, VALUE value, int reason) case TAG_RETURN: id = rb_intern("return"); break; default: - id = rb_intern("noreason"); break; + id = rb_intern("yield"); break; } rb_iv_set(exc, "@reason", ID2SYM(id)); + if (bt) set_backtrace(exc, bt); rb_exc_raise(exc); } @@ -1681,7 +1729,7 @@ localjump_xvalue(VALUE exc) * local_jump_error.reason => symbol * * The reason this block was terminated: - * :break, :redo, :retry, :next, :return, or :noreason. + * :break, :redo, :retry, :next, :return, or :yield. */ static VALUE @@ -1700,19 +1748,19 @@ jump_tag_but_local_jump(int state, VALUE val) case 0: break; case TAG_RETURN: - localjump_error("unexpected return", val, state); + localjump_error("unexpected return", val, state, 0); break; case TAG_BREAK: - localjump_error("unexpected break", val, state); + localjump_error("unexpected break", val, state, 0); break; case TAG_NEXT: - localjump_error("unexpected next", val, state); + localjump_error("unexpected next", val, state, 0); break; case TAG_REDO: - localjump_error("unexpected redo", Qnil, state); + localjump_error("unexpected redo", Qnil, state, 0); break; case TAG_RETRY: - localjump_error("retry outside of rescue clause", Qnil, state); + localjump_error("retry outside of rescue clause", Qnil, state, 0); break; default: break; @@ -1735,7 +1783,8 @@ rb_eval_cmd(VALUE cmd, VALUE arg, int level) PUSH_TAG(PROT_NONE); ruby_safe_level = level; if ((state = EXEC_TAG()) == 0) { - val = rb_funcall2(cmd, rb_intern("call"), RARRAY(arg)->len, RARRAY(arg)->ptr); + val = rb_funcall2(cmd, rb_intern("yield"), + RARRAY(arg)->len, RARRAY(arg)->ptr); } ruby_safe_level = safe; POP_TAG(); @@ -1776,13 +1825,17 @@ ruby_current_class_object() static VALUE ev_const_defined(ID id, VALUE self) { - return rb_const_defined_fallback(ruby_cbase, id, ruby_cref->nd_next); + VALUE cbase = ruby_cbase; + if (NIL_P(cbase)) cbase = rb_obj_class(self); + return rb_const_defined_fallback(cbase, id, ruby_cref->nd_next); } static VALUE ev_const_get(ID id, VALUE self) { - return rb_const_get_fallback(ruby_cbase, id, ruby_cref->nd_next); + VALUE cbase = ruby_cbase; + if (NIL_P(cbase)) cbase = rb_obj_class(self); + return rb_const_get_fallback(cbase, id, ruby_cref->nd_next); } static VALUE @@ -1860,7 +1913,7 @@ rb_mod_s_constants(void) cbase = cbase->nd_next; } - if (!NIL_P(ruby_cbase)) { + if (NIL_P(ruby_cbase)) { data = rb_mod_const_of(ruby_cbase, data); } return rb_const_list(data); @@ -1869,7 +1922,7 @@ rb_mod_s_constants(void) void rb_frozen_class_p(VALUE klass) { - char *desc = "something(?!)"; + const char *desc = "something(?!)"; if (OBJ_FROZEN(klass)) { if (FL_TEST(klass, FL_SINGLETON)) @@ -1903,9 +1956,9 @@ rb_undef(VALUE klass, ID id) if (id == __id__ || id == __send__ || id == init) { rb_warn("undefining `%s' may cause serious problem", rb_id2name(id)); } - body = search_method(klass, id, &origin); + body = search_method(klass, id, &origin, LOOKUP_NOSKIP); if (!body || !body->nd_body) { - char *s0 = " class"; + const char *s0 = " class"; VALUE c = klass; if (FL_TEST(c, FL_SINGLETON)) { @@ -2000,14 +2053,14 @@ rb_alias(VALUE klass, ID name, ID def) if (klass == rb_cObject) { rb_secure(4); } - orig = search_method(klass, def, &origin); + orig = search_method(klass, def, &origin, LOOKUP_NOSKIP); if (!orig || !orig->nd_body) { if (TYPE(klass) == T_MODULE) { - orig = search_method(rb_cObject, def, &origin); + orig = search_method(rb_cObject, def, &origin, LOOKUP_NOSKIP); } } if (!orig || !orig->nd_body) { - print_undef(klass, def); + raise_undef(klass, def); } if (FL_TEST(klass, FL_SINGLETON)) { singleton = rb_iv_get(klass, "__attached__"); @@ -2027,7 +2080,8 @@ rb_alias(VALUE klass, ID name, ID def) } } st_insert(RCLASS(klass)->m_tbl, name, - (st_data_t)NEW_METHOD(NEW_FBODY(body, def, origin), orig->nd_noex)); + (st_data_t)NEW_METHOD(NEW_FBODY(body, def, origin), + NOEX_WITH_SAFE(orig->nd_noex))); if (singleton) { rb_funcall(singleton, singleton_added, 1, ID2SYM(name)); } @@ -2092,17 +2146,21 @@ copy_node_scope(NODE *node, NODE *rval) # define TMP_ALLOC(n) ALLOCA_N(VALUE,n) #endif -#define SETUP_ARGS0(anode,alen,extra) do {\ - NODE *n = anode;\ +#define CALLARGS int argc; VALUE *argv; struct BLOCK *block = 0, _block; +#define SETUP_ARGS0(anode,extra) do {\ + NODE *n = anode, *bpass = 0;\ + if (n && nd_type(n) == NODE_BLOCK_PASS) {\ + bpass = n;\ + n = n->nd_head;\ + }\ if (!n) {\ argc = 0;\ argv = 0;\ }\ else if (nd_type(n) == NODE_ARRAY) {\ - argc=alen;\ + argc=n->nd_alen;\ if (argc > 0) {\ int i;\ - n = anode;\ argv = TMP_ALLOC(argc+extra);\ for (i=0;ind_head);\ @@ -2122,9 +2180,12 @@ copy_node_scope(NODE *node, NODE *rval) argv = TMP_ALLOC(argc+extra);\ MEMCPY(argv, RARRAY(args)->ptr, VALUE, argc);\ }\ + if (bpass) {\ + block = passing_block(rb_eval(self, bpass->nd_body), &_block);\ + }\ } while (0) -#define SETUP_ARGS(anode) SETUP_ARGS0(anode,anode->nd_alen,0) +#define SETUP_ARGS(anode) SETUP_ARGS0(anode,0) #define ZSUPER_ARGS() do {\ argc = ruby_frame->argc;\ @@ -2172,7 +2233,7 @@ static const char* is_defined(VALUE self, NODE *node /* OK */, char *buf, int noeval) { VALUE val; /* OK */ - int state; + int state, noex; static const char *ex = "expression"; if (!node) return ex; @@ -2182,7 +2243,7 @@ is_defined(VALUE self, NODE *node /* OK */, char *buf, int noeval) if (ruby_frame->this_func == 0) return 0; else if (ruby_frame->this_class == 0) return 0; val = ruby_frame->this_class; - if (rb_method_boundp(RCLASS(val)->super, ruby_frame->this_func, 0)) { + if (method_exists(RCLASS(val)->super, ruby_frame->this_func, LOOKUP_FCALL)) { if (nd_type(node) == NODE_SUPER) { return arg_defined(self, node->nd_args, buf, "super"); } @@ -2193,6 +2254,7 @@ is_defined(VALUE self, NODE *node /* OK */, char *buf, int noeval) case NODE_VCALL: case NODE_FCALL: val = self; + noex = LOOKUP_FCALL; goto check_bound; case NODE_ATTRASGN: @@ -2201,26 +2263,21 @@ is_defined(VALUE self, NODE *node /* OK */, char *buf, int noeval) case NODE_CALL: if (!is_defined(self, node->nd_recv, buf, Qtrue)) return 0; if (noeval) return ex; + noex = LOOKUP_NORMAL; val = rb_eval(self, node->nd_recv); check_bound: { - int call = nd_type(node)==NODE_CALL; + ID id = node->nd_mid; val = CLASS_OF(val); - if (call) { - int noex; - ID id = node->nd_mid; - - if (!rb_get_method_body(&val, &id, &noex)) - break; - if ((noex & NOEX_PRIVATE)) - break; + if (!rb_get_method_body(&val, &id, &noex)) + return 0; + if (nd_type(node) == NODE_CALL) { + if ((noex & NOEX_PRIVATE)) return 0; if ((noex & NOEX_PROTECTED) && !rb_obj_is_kind_of(self, rb_class_real(val))) - break; + return 0; } - else if (!rb_method_boundp(val, node->nd_mid, call)) - break; return arg_defined(self, node->nd_args, buf, nd_type(node) == NODE_ATTRASGN ? "assignment" : "method"); @@ -2303,7 +2360,7 @@ is_defined(VALUE self, NODE *node /* OK */, char *buf, int noeval) return "constant"; break; default: - if (rb_method_boundp(CLASS_OF(val), node->nd_mid, 1)) { + if (rb_method_boundp(CLASS_OF(val), node->nd_mid, Qtrue)) { return "method"; } } @@ -2374,6 +2431,7 @@ rb_add_event_hook(rb_event_hook_func_t func, rb_event_t events) int rb_remove_event_hook(rb_event_hook_func_t func) { + rb_event_hook_t *prev, *hook; prev = NULL; @@ -2535,7 +2593,7 @@ call_trace_func(rb_event_t event, NODE *node, VALUE self, ID id, VALUE klass /* id?ID2SYM(id):Qnil, self ? rb_f_binding(self) : Qnil, klass?klass:Qnil), - Qundef, 0); + Qundef, 0, 1); } if (raised) thread_set_raised(); POP_TAG(); @@ -2547,31 +2605,6 @@ call_trace_func(rb_event_t event, NODE *node, VALUE self, ID id, VALUE klass /* if (state) JUMP_TAG(state); } -static VALUE -avalue_to_svalue(VALUE v) -{ - VALUE tmp, top; - - tmp = rb_check_array_type(v); - if (NIL_P(tmp)) { - return v; - } - if (RARRAY(tmp)->len == 0) { - return Qundef; - } - if (RARRAY(tmp)->len == 1) { - top = rb_check_array_type(RARRAY(tmp)->ptr[0]); - if (NIL_P(top)) { - return RARRAY(tmp)->ptr[0]; - } - if (RARRAY(top)->len > 1) { - return v; - } - return top; - } - return tmp; -} - static VALUE svalue_to_avalue(VALUE v) { @@ -2582,51 +2615,9 @@ svalue_to_avalue(VALUE v) if (NIL_P(tmp)) { return rb_ary_new3(1, v); } - if (RARRAY(tmp)->len == 1) { - top = rb_check_array_type(RARRAY(tmp)->ptr[0]); - if (!NIL_P(top) && RARRAY(top)->len > 1) { - return tmp; - } - return rb_ary_new3(1, v); - } - return tmp; -} - -static VALUE -svalue_to_mrhs(VALUE v, NODE *lhs) -{ - VALUE tmp; - - if (v == Qundef) return rb_values_new2(0, 0); - tmp = rb_check_array_type(v); - if (NIL_P(tmp)) { - return rb_values_new(1, v); - } - /* no lhs means splat lhs only */ - if (!lhs) { - return rb_values_new(1, v); - } return tmp; } -static VALUE -avalue_splat(VALUE v) -{ - if (RARRAY(v)->len == 0) { - return Qundef; - } - if (RARRAY(v)->len == 1) { - return RARRAY(v)->ptr[0]; - } - return v; -} - -static VALUE -splat_value(VALUE v) -{ - return rb_values_from_ary(rb_Array(v)); -} - static VALUE class_prefix(VALUE self, NODE *cpath) { @@ -2691,6 +2682,7 @@ rb_eval(VALUE self, NODE *n) NODE * volatile node = n; int state; volatile VALUE result = Qnil; + VALUE pushed_block = 0; #define RETURN(v) do { \ result = (v); \ @@ -2962,8 +2954,6 @@ rb_eval(VALUE self, NODE *n) case NODE_LAMBDA: PUSH_TAG(PROT_LOOP); PUSH_FRAME(Qtrue); - ruby_frame->this_func = 0; - ruby_frame->this_class = 0; PUSH_BLOCK(ruby_frame->block, node->nd_var, node->nd_body); state = EXEC_TAG(); result = proc_lambda(); @@ -2993,18 +2983,13 @@ rb_eval(VALUE self, NODE *n) break; case NODE_SPLAT: - result = splat_value(rb_eval(self, node->nd_head)); + result = svalue_to_avalue(rb_eval(self, node->nd_head)); break; case NODE_TO_ARY: result = rb_ary_to_ary(rb_eval(self, node->nd_head)); break; - case NODE_SVALUE: - result = avalue_splat(rb_eval(self, node->nd_head)); - if (result == Qundef) result = Qnil; - break; - case NODE_YIELD: if (node->nd_head) { result = rb_eval(self, node->nd_head); @@ -3014,7 +2999,7 @@ rb_eval(VALUE self, NODE *n) result = Qundef; /* no arg */ } SET_CURRENT_SOURCE(); - result = rb_yield_0(result, 0, 0, 0, node->nd_state); + result = rb_yield_0(result, 0, 0, 0); break; case NODE_RESCUE: @@ -3160,7 +3145,7 @@ rb_eval(VALUE self, NODE *n) case NODE_ARGSCAT: { VALUE args = rb_eval(self, node->nd_head); - result = rb_ary_concat(args, splat_value(rb_eval(self, node->nd_body))); + result = rb_ary_concat(args, svalue_to_avalue(rb_eval(self, node->nd_body))); } break; @@ -3174,8 +3159,8 @@ rb_eval(VALUE self, NODE *n) case NODE_ATTRASGN: { VALUE recv; - int argc; VALUE *argv; /* used in SETUP_ARGS */ calling_scope_t scope; + CALLARGS; TMP_PROTECT; if (node->nd_recv == (NODE *)1) { @@ -3190,7 +3175,7 @@ rb_eval(VALUE self, NODE *n) ruby_current_node = node; SET_CURRENT_SOURCE(); - rb_call(CLASS_OF(recv),recv,node->nd_mid,argc,argv,0,scope); + rb_call(CLASS_OF(recv),recv,node->nd_mid,argc,argv,block,scope,0); result = argv[argc-1]; } break; @@ -3210,7 +3195,7 @@ rb_eval(VALUE self, NODE *n) recv = rb_eval(self, node->nd_iter); ruby_current_node = node; SET_CURRENT_SOURCE(); - result = rb_call(CLASS_OF(recv),recv,each,0,0,block,CALLING_NORMAL); + result = rb_call(CLASS_OF(recv),recv,each,0,0,block,CALLING_NORMAL,1); } else if (state == TAG_BREAK && TAG_DST()) { result = prot_tag->retval; @@ -3226,69 +3211,14 @@ rb_eval(VALUE self, NODE *n) } break; - case NODE_BLOCK_PASS: - { - VALUE recv = self; - calling_scope_t scope; - NODE *bpass = node; - - PUSH_TAG(PROT_LOOP); - node = node->nd_iter; /* should be NODE_CALL */ - switch (nd_type(node)) { - case NODE_CALL: - scope = CALLING_NORMAL; break; - case NODE_FCALL: - scope = CALLING_FCALL; break; - case NODE_VCALL: - scope = CALLING_VCALL; break; - case NODE_SUPER: - scope = CALLING_SUPER; break; - default: - /* error! */ - unknown_node(node); - } - state = EXEC_TAG(); - if (state == 0) { - struct BLOCK *block, _block; - int argc; VALUE *argv; /* used in SETUP_ARGS */ - TMP_PROTECT; - - block_pass_retry: - if (scope == CALLING_NORMAL) { - recv = rb_eval(self, node->nd_recv); - } - SETUP_ARGS(node->nd_args); - block = passing_block(rb_eval(self, bpass->nd_body), &_block); - ruby_current_node = node; - SET_CURRENT_SOURCE(); - if (scope == CALLING_SUPER) { - result = call_super(argc, argv, block); - } - else { - result = rb_call(CLASS_OF(recv),recv,node->nd_mid,argc,argv,block,scope); - } - } - else if (state == TAG_BREAK && TAG_DST()) { - result = prot_tag->retval; - state = 0; - } - else if (state == TAG_RETRY) { - state = 0; - goto block_pass_retry; - } - POP_TAG(); - if (state) JUMP_TAG(state); - } - break; - case NODE_ITER: { VALUE recv = self; calling_scope_t scope; - struct BLOCK *block; + struct BLOCK *block_given; PUSH_TAG(PROT_LOOP); - PUSH_BLOCK(block, node->nd_var, node->nd_body); + PUSH_BLOCK(block_given, node->nd_var, node->nd_body); node = node->nd_iter; /* should be NODE_CALL */ switch (nd_type(node)) { case NODE_CALL: @@ -3306,7 +3236,7 @@ rb_eval(VALUE self, NODE *n) } state = EXEC_TAG(); if (state == 0) { - int argc; VALUE *argv; /* used in SETUP_ARGS */ + CALLARGS; TMP_PROTECT; iter_retry: @@ -3321,11 +3251,14 @@ rb_eval(VALUE self, NODE *n) ruby_current_node = node; } SET_CURRENT_SOURCE(); - if (scope == CALLING_SUPER) { - result = call_super(argc, argv, block); - } - else { - result = rb_call(CLASS_OF(recv),recv,node->nd_mid,argc,argv,block,scope); + switch (scope) { + case CALLING_SUPER: + result = call_super(argc, argv, block_given); + break; + default: + result = rb_call(CLASS_OF(recv),recv,node->nd_mid, + argc,argv,block_given,scope,1); + break; } } else if (state == TAG_BREAK && TAG_DST()) { @@ -3345,7 +3278,7 @@ rb_eval(VALUE self, NODE *n) case NODE_CALL: { VALUE recv; - int argc; VALUE *argv; /* used in SETUP_ARGS */ + CALLARGS; TMP_PROTECT; recv = rb_eval(self, node->nd_recv); @@ -3353,32 +3286,34 @@ rb_eval(VALUE self, NODE *n) ruby_current_node = node; SET_CURRENT_SOURCE(); - result = rb_call(CLASS_OF(recv),recv,node->nd_mid,argc,argv,0,CALLING_NORMAL); + result = rb_call(CLASS_OF(recv),recv,node->nd_mid,argc,argv, + block,CALLING_NORMAL,0); } break; case NODE_FCALL: { - int argc; VALUE *argv; /* used in SETUP_ARGS */ + CALLARGS; TMP_PROTECT; SETUP_ARGS(node->nd_args); ruby_current_node = node; SET_CURRENT_SOURCE(); - result = rb_call(CLASS_OF(self),self,node->nd_mid,argc,argv,0,CALLING_FCALL); + result = rb_call(CLASS_OF(self),self,node->nd_mid,argc,argv, + block,CALLING_FCALL,0); } break; case NODE_VCALL: SET_CURRENT_SOURCE(); - result = rb_call(CLASS_OF(self),self,node->nd_mid,0,0,0,CALLING_VCALL); + result = rb_call(CLASS_OF(self),self,node->nd_mid,0,0,0,CALLING_VCALL,0); break; case NODE_SUPER: case NODE_ZSUPER: { - int argc; VALUE *argv; /* used in SETUP_ARGS */ + CALLARGS; TMP_PROTECT; if (ruby_frame->this_class == 0) { @@ -3393,14 +3328,15 @@ rb_eval(VALUE self, NODE *n) } if (nd_type(node) == NODE_ZSUPER) { ZSUPER_ARGS(); + SET_CURRENT_SOURCE(); + result = rb_call_super(argc, argv); } else { SETUP_ARGS(node->nd_args); ruby_current_node = node; + SET_CURRENT_SOURCE(); + result = call_super(argc, argv, block); } - - SET_CURRENT_SOURCE(); - result = rb_call_super(argc, argv); } break; @@ -3444,14 +3380,14 @@ rb_eval(VALUE self, NODE *n) case NODE_OP_ASGN1: { - int argc; VALUE *argv; /* used in SETUP_ARGS */ + CALLARGS; VALUE recv, val, tmp; NODE *rval; TMP_PROTECT; recv = rb_eval(self, node->nd_recv); rval = node->nd_args->nd_head; - SETUP_ARGS0(node->nd_args->nd_next,node->nd_args->nd_alen-1,1); + SETUP_ARGS0(node->nd_args->nd_body,1); val = rb_funcall3(recv, aref, argc, argv); switch (node->nd_mid) { case 0: /* OR */ @@ -3549,9 +3485,6 @@ rb_eval(VALUE self, NODE *n) rb_const_set(class_prefix(self, node->nd_else), node->nd_else->nd_mid, result); } else { - if (NIL_P(ruby_cbase)) { - rb_raise(rb_eTypeError, "no class/module to define constant"); - } rb_const_set(ruby_cbase, node->nd_vid, result); } break; @@ -3704,7 +3637,7 @@ rb_eval(VALUE self, NODE *n) long i; i = node->nd_alen; - val = rb_values_new2(i, 0); + val = rb_ary_new4(i, 0); for (i=0;node;node=node->nd_next) { RARRAY(val)->ptr[i++] = rb_eval(self, node->nd_head); RARRAY(val)->len = i; @@ -3799,9 +3732,10 @@ rb_eval(VALUE self, NODE *n) rb_id2name(node->nd_mid)); } rb_frozen_class_p(ruby_cbase); - body = search_method(ruby_cbase, node->nd_mid, &origin); + body = search_method(ruby_cbase, node->nd_mid, &origin, LOOKUP_NOSKIP); if (body){ - if (RTEST(ruby_verbose) && ruby_cbase == origin && body->nd_cnt == 0 && body->nd_body) { + if (RTEST(ruby_verbose) && ruby_cbase == origin && + body->nd_cnt == 0 && body->nd_body) { rb_warning("method redefined; discarding old %s", rb_id2name(node->nd_mid)); } } @@ -3809,6 +3743,9 @@ rb_eval(VALUE self, NODE *n) if (VIS_TEST(VIS_PRIVATE) || node->nd_mid == init) { noex = NOEX_PRIVATE; } + else if (VIS_TEST(VIS_LOCAL)) { + noex = NOEX_LOCAL; + } else if (VIS_TEST(VIS_PROTECTED)) { noex = NOEX_PROTECTED; } @@ -3964,12 +3901,12 @@ rb_eval(VALUE self, NODE *n) module = rb_define_module_id(cname); rb_set_class_path(module, cbase, rb_id2name(cname)); rb_const_set(cbase, cname, module); + rb_obj_call_init(module, 0, 0); } if (ruby_wrapper) { rb_extend_object(module, ruby_wrapper); rb_include_module(module, ruby_wrapper); } - result = module_setup(module, node); } break; @@ -4161,7 +4098,7 @@ rb_mod_method_defined(int argc, VALUE *argv, VALUE mod) if (!RTEST(recur)) { return st_is_member(RCLASS(mod)->m_tbl, id) ? Qtrue : Qfalse; } - return rb_method_boundp(mod, id, 1); + return rb_method_boundp(mod, id, Qtrue); } #define VISI_CHECK(x,f) (((x)&NOEX_MASK) == (f)) @@ -4196,7 +4133,7 @@ static VALUE rb_mod_public_method_defined(VALUE mod, VALUE mid) { ID id = rb_to_id(mid); - int noex; + int noex = 1; if (rb_get_method_body(&mod, &id, &noex)) { if (VISI_CHECK(noex, NOEX_PUBLIC)) @@ -4235,7 +4172,7 @@ static VALUE rb_mod_private_method_defined(VALUE mod, VALUE mid) { ID id = rb_to_id(mid); - int noex; + int noex = 0; if (rb_get_method_body(&mod, &id, &noex)) { if (VISI_CHECK(noex, NOEX_PRIVATE)) @@ -4274,7 +4211,7 @@ static VALUE rb_mod_protected_method_defined(VALUE mod, VALUE mid) { ID id = rb_to_id(mid); - int noex; + int noex = 1; if (rb_get_method_body(&mod, &id, &noex)) { if (VISI_CHECK(noex, NOEX_PROTECTED)) @@ -4653,7 +4590,7 @@ proc_jump_error(int state, VALUE result) statement = "local-jump"; break; /* should not happen */ } snprintf(mesg, sizeof mesg, "%s from proc-closure", statement); - localjump_error(mesg, result, state); + localjump_error(mesg, result, state, 0); } NORETURN(static void return_jump(VALUE)); @@ -4671,7 +4608,7 @@ return_jump(VALUE retval) } if ((tt->tag == PROT_FUNC && tt->frame->uniq == ruby_frame->uniq) || (tt->tag == PROT_LAMBDA && !yield)) - { + { tt->dst = (VALUE)tt->frame->uniq; tt->retval = retval; JUMP_TAG(TAG_RETURN); @@ -4681,7 +4618,7 @@ return_jump(VALUE retval) } tt = tt->prev; } - localjump_error("unexpected return", retval, TAG_RETURN); + localjump_error("unexpected return", retval, TAG_RETURN, 0); } static void @@ -4708,7 +4645,7 @@ break_jump(VALUE retval) } tt = tt->prev; } - localjump_error("unexpected break", retval, TAG_BREAK); + localjump_error("unexpected break", retval, TAG_BREAK, 0); } static VALUE bmcall(VALUE, VALUE); @@ -4718,12 +4655,12 @@ void rb_need_block(void) { if (!rb_block_given_p()) { - localjump_error("no block given", Qnil, 0); + localjump_error("no block given", Qnil, 0, 0); } } static VALUE -rb_yield_0(VALUE val, VALUE self, VALUE klass /* OK */, int flags, int avalue) +rb_yield_0(VALUE val, VALUE self, VALUE klass /* OK */, int flags) { NODE *node, *var; volatile VALUE result = Qnil; @@ -4790,16 +4727,8 @@ rb_yield_0(VALUE val, VALUE self, VALUE klass /* OK */, int flags, int avalue) var = var->nd_args; goto block_var; } - else if (nd_type(var) == NODE_MASGN) { - if (!avalue) { - val = svalue_to_mrhs(val, var->nd_head); - } - massign(self, var, val, lambda); - } else if (nd_type(var) == NODE_ARGS) { - if (!avalue) { - val = svalue_to_mrhs(val, var->nd_head); - } + val = svalue_to_avalue(val); formal_assign(self, var, RARRAY(val)->len, RARRAY(val)->ptr, 0); } else if (nd_type(var) == NODE_BLOCK) { @@ -4809,31 +4738,10 @@ rb_yield_0(VALUE val, VALUE self, VALUE klass /* OK */, int flags, int avalue) var = var->nd_head; goto block_var; } + else if (nd_type(var) == NODE_MASGN) { + massign(self, var, val, lambda); + } else { - int len = 0; - if (avalue) { - len = RARRAY(val)->len; - if (len == 0) { - goto zero_arg; - } - if (len == 1) { - val = RARRAY(val)->ptr[0]; - } - else { - goto multi_values; - } - } - else if (val == Qundef) { - zero_arg: - val = Qnil; - multi_values: - { - ruby_current_node = var; - rb_warn("multiple values for a block parameter (%d for 1)\n\tfrom %s:%d", - len, cnode->nd_file, nd_line(cnode)); - ruby_current_node = cnode; - } - } assign(self, var, val, lambda); } if (bvar) { @@ -4865,14 +4773,9 @@ rb_yield_0(VALUE val, VALUE self, VALUE klass /* OK */, int flags, int avalue) redo: if (nd_type(node) == NODE_CFUNC || nd_type(node) == NODE_IFUNC) { if (node->nd_state == YIELD_FUNC_AVALUE) { - if (!avalue) { - val = svalue_to_avalue(val); - } + val = svalue_to_avalue(val); } else { - if (avalue) { - val = avalue_to_svalue(val); - } if (val == Qundef && node->nd_state != YIELD_FUNC_SVALUE) val = Qnil; } @@ -4967,7 +4870,7 @@ rb_yield_0(VALUE val, VALUE self, VALUE klass /* OK */, int flags, int avalue) VALUE rb_yield(VALUE val) { - return rb_yield_0(val, 0, 0, 0, Qfalse); + return rb_yield_0(val, 0, 0, 0); } VALUE @@ -4978,32 +4881,16 @@ rb_yield_values(int n, ...) VALUE val; if (n == 0) { - return rb_yield_0(Qundef, 0, 0, 0, Qfalse); + return rb_yield_0(Qundef, 0, 0, 0); } - val = rb_values_new2(n, 0); + val = rb_ary_new4(n, 0); va_start(args, n); for (i=0; iptr[i] = va_arg(args, VALUE); } RARRAY(val)->len = n; va_end(args); - return rb_yield_0(val, 0, 0, 0, Qtrue); -} - -VALUE -rb_yield_splat(VALUE values) -{ - int avalue = Qfalse; - - if (TYPE(values) == T_ARRAY) { - if (RARRAY(values)->len == 0) { - values = Qundef; - } - else { - avalue = Qtrue; - } - } - return rb_yield_0(values, 0, 0, 0, avalue); + return rb_yield_0(val, 0, 0, 0); } /* @@ -5024,7 +4911,7 @@ static VALUE rb_f_loop(void) { for (;;) { - rb_yield_0(Qundef, 0, 0, 0, Qfalse); + rb_yield_0(Qundef, 0, 0, 0); CHECK_INTS; } return Qnil; /* dummy */ @@ -5035,11 +4922,27 @@ massign(VALUE self, NODE *node, VALUE val, int pcall) { NODE *list; long i = 0, len; + volatile VALUE tmp; + VALUE *argv; - len = RARRAY(val)->len; + if (val == Qundef) { + argv = 0; + len = 0; + } + else { + tmp = rb_check_array_type(val); + if (NIL_P(tmp)) { + argv = &val; + len = (val == Qundef) ? 0 : 1; + } + else { + argv = RARRAY(tmp)->ptr; + len = RARRAY(tmp)->len; + } + } list = node->nd_head; for (; list && ind_head, RARRAY(val)->ptr[i], pcall); + assign(self, list->nd_head, argv[i], pcall); list = list->nd_next; } if (pcall && list) goto arg_error; @@ -5048,7 +4951,7 @@ massign(VALUE self, NODE *node, VALUE val, int pcall) /* no check for mere `*' */ } else if (!list && ind_args, rb_ary_new4(len-i, RARRAY(val)->ptr+i), pcall); + assign(self, node->nd_args, rb_ary_new4(len-i, argv+i), pcall); } else { assign(self, node->nd_args, rb_ary_new2(0), pcall); @@ -5125,7 +5028,7 @@ assign(VALUE self, NODE *lhs, VALUE val, int pcall) break; case NODE_MASGN: - massign(self, lhs, svalue_to_mrhs(val, lhs->nd_head), pcall); + massign(self, lhs, val, pcall); break; case NODE_CALL: @@ -5135,7 +5038,7 @@ assign(VALUE self, NODE *lhs, VALUE val, int pcall) calling_scope_t scope; if (lhs->nd_recv == (NODE *)1) { recv = self; - scope = CALLING_FCALL; + scope = CALLING_FUNCALL; } else { recv = rb_eval(self, lhs->nd_recv); @@ -5145,7 +5048,7 @@ assign(VALUE self, NODE *lhs, VALUE val, int pcall) /* attr set */ ruby_current_node = lhs; SET_CURRENT_SOURCE(); - rb_call(CLASS_OF(recv), recv, lhs->nd_mid, 1, &val, 0, scope); + rb_call(CLASS_OF(recv), recv, lhs->nd_mid, 1, &val, 0, scope,0); } else { /* array set */ @@ -5156,7 +5059,40 @@ assign(VALUE self, NODE *lhs, VALUE val, int pcall) ruby_current_node = lhs; SET_CURRENT_SOURCE(); rb_call(CLASS_OF(recv), recv, lhs->nd_mid, - RARRAY(args)->len, RARRAY(args)->ptr, 0, scope); + RARRAY(args)->len, RARRAY(args)->ptr, 0, scope,0); + } + } + break; + + case NODE_POSTARG: + { + NODE *v = lhs->nd_head; + int cnt; + VALUE *p; + + if ((long)(lhs->nd_args) != -1) { + assign(self, lhs->nd_args, val, 0); + } + cnt = lhs->nd_head->nd_alen; + if (RARRAY(val)->len < cnt) { + if (pcall) { + rb_raise(rb_eArgError, "wrong number of arguments"); + } + else { + while (RARRAY(val)->len < cnt) { + v = v->nd_next; + cnt--; + } + } + } + p = RARRAY(val)->ptr + RARRAY(val)->len - cnt; + while (cnt--) { + assign(self, v->nd_head, *p++, 0); + v = v->nd_next; + } + cnt = lhs->nd_head->nd_alen; + while (cnt--) { + rb_ary_pop(val); } } break; @@ -5218,7 +5154,7 @@ iterate_method(VALUE obj) arg = (struct iter_method_arg*)obj; return rb_call(CLASS_OF(arg->obj), arg->obj, arg->mid, arg->argc, arg->argv, - ruby_frame->block, CALLING_FCALL); + ruby_frame->block, CALLING_FUNCALL,1); } VALUE @@ -5237,13 +5173,13 @@ VALUE rb_each(VALUE obj) { return rb_call(CLASS_OF(obj), obj, rb_intern("each"), 0, 0, - ruby_frame->block, CALLING_FCALL); + ruby_frame->block, CALLING_FUNCALL,1); } static int handle_rescue(VALUE self, NODE *node) { - int argc; VALUE *argv; /* used in SETUP_ARGS */ + CALLARGS; TMP_PROTECT; if (!node->nd_args) { @@ -5511,12 +5447,23 @@ method_missing(VALUE obj, ID id, int argc, const VALUE *argv, else if (id == ID_ALLOCATOR) { rb_raise(rb_eTypeError, "allocator undefined for %s", rb_class2name(obj)); } + if (argc < 0) { + VALUE tmp; - nargv = ALLOCA_N(VALUE, argc+1); - nargv[0] = ID2SYM(id); - MEMCPY(nargv+1, argv, VALUE, argc); + argc = -argc-1; + tmp = svalue_to_avalue(argv[argc]); + nargv = ALLOCA_N(VALUE, argc + RARRAY(tmp)->len + 1); + MEMCPY(nargv+1, argv, VALUE, argc); + MEMCPY(nargv+1+argc, RARRAY(tmp)->ptr, VALUE, RARRAY(tmp)->len); + argc += RARRAY(tmp)->len; - return rb_call(CLASS_OF(obj), obj, missing, argc+1, nargv, block, CALLING_FCALL); + } + else { + nargv = ALLOCA_N(VALUE, argc+1); + MEMCPY(nargv+1, argv, VALUE, argc); + } + nargv[0] = ID2SYM(id); + return rb_call(CLASS_OF(obj), obj, missing, argc+1, nargv, block, CALLING_FUNCALL, 0); } static inline VALUE @@ -5664,8 +5611,12 @@ formal_assign(VALUE recv, NODE *node, int argc, const VALUE *argv, VALUE *local_ VALUE v; if (argc > 0) { + int n = 1; v = rb_ary_new4(argc,argv); - i = -i - 1; + if (nd_type(node->nd_rest) == NODE_POSTARG) { + n += node->nd_rest->nd_head->nd_alen; + } + i += n*256; } else { v = rb_ary_new2(0); @@ -5698,21 +5649,28 @@ rb_call0(VALUE klass, VALUE recv, ID id, ID oid, volatile int safe = -1; TMP_PROTECT; + if (NOEX_SAFE(flags) > ruby_safe_level && + ruby_safe_level == 0 && NOEX_SAFE(flags) > 2) { + rb_raise(rb_eSecurityError, "calling insecure method: %s", + rb_id2name(id)); + } if ((++tick & 0xff) == 0) { CHECK_INTS; /* better than nothing */ stack_check(); rb_gc_finalize_deferred(); } - if (argc < 0) { + if (argc >= 256) { VALUE tmp; VALUE *nargv; + int n = argc / 256 - 1; - argc = -argc-1; - tmp = splat_value(argv[argc]); - nargv = TMP_ALLOC(argc + RARRAY(tmp)->len); + argc %= 256; + tmp = svalue_to_avalue(argv[argc]); + nargv = TMP_ALLOC(argc + RARRAY(tmp)->len + n); MEMCPY(nargv, argv, VALUE, argc); MEMCPY(nargv+argc, RARRAY(tmp)->ptr, VALUE, RARRAY(tmp)->len); - argc += RARRAY(tmp)->len; + MEMCPY(nargv + argc + RARRAY(tmp)->len, argv + argc + 1, VALUE, n); + argc += RARRAY(tmp)->len + n; argv = nargv; } switch (nd_type(body)) { @@ -5768,7 +5726,7 @@ rb_call0(VALUE klass, VALUE recv, ID id, ID oid, case NODE_BMETHOD: PUSH_METHOD_FRAME(); ruby_frame->flags |= FRAME_DMETH; - result = proc_invoke(body->nd_cval, rb_ary_new4(argc, argv), recv, klass); + result = proc_invoke(body->nd_cval, rb_ary_new4(argc, argv), recv, klass, 1); POP_FRAME(); break; @@ -5798,10 +5756,6 @@ rb_call0(VALUE klass, VALUE recv, ID id, ID oid, b2 = body = body->nd_next; if (NOEX_SAFE(flags) > ruby_safe_level) { - if (ruby_safe_level == 0 && NOEX_SAFE(flags) > 2) { - rb_raise(rb_eSecurityError, "calling insecure method: %s", - rb_id2name(id)); - } safe = ruby_safe_level; ruby_safe_level = NOEX_SAFE(flags); } @@ -5819,7 +5773,8 @@ rb_call0(VALUE klass, VALUE recv, ID id, ID oid, body = body->nd_next; } if (node) { - ruby_frame->argc = formal_assign(recv, node, argc, argv, local_vars); + ruby_frame->argc = + formal_assign(recv, node, argc, argv, local_vars); } if (event_hooks) { @@ -5832,13 +5787,13 @@ rb_call0(VALUE klass, VALUE recv, ID id, ID oid, state = 0; } POP_TAG(); + if (event_hooks) { + EXEC_EVENT_HOOK(RUBY_EVENT_RETURN, body, recv, id, klass); + } POP_VARS(); POP_SCOPE(); ruby_cref = saved_cref; if (safe >= 0) ruby_safe_level = safe; - if (event_hooks) { - EXEC_EVENT_HOOK(RUBY_EVENT_RETURN, body, recv, id, klass); - } POP_FRAME(); switch (state) { case 0: @@ -5869,7 +5824,7 @@ rb_call0(VALUE klass, VALUE recv, ID id, ID oid, static VALUE rb_call(VALUE klass, VALUE recv, ID mid, int argc /* OK */, const VALUE *argv /* OK */, struct BLOCK *block, - calling_scope_t scope) + calling_scope_t scope, int iter) { NODE *body; /* OK */ int noex; @@ -5880,8 +5835,21 @@ rb_call(VALUE klass, VALUE recv, ID mid, rb_raise(rb_eNotImpError, "method `%s' called on terminated object (%p)", rb_id2name(mid), (void*)recv); } + switch (scope) { + case CALLING_FCALL: + case CALLING_VCALL: + if (recv == ruby_frame->self) { + noex = LOOKUP_FCALL; + break; + } + /* fall thtough */ + default: + noex = LOOKUP_NORMAL; + break; + } + /* is it in the method cache? */ - ent = cache + EXPR1(klass, mid); + ent = cache[noex] + EXPR1(klass, mid); if (ent->mid == mid && ent->klass == klass) { if (!ent->method) return method_missing(recv, mid, argc, argv, block, @@ -5917,7 +5885,28 @@ rb_call(VALUE klass, VALUE recv, ID mid, if (scope > CALLING_NORMAL) { /* pass receiver info */ noex |= NOEX_RECV; } - return rb_call0(klass, recv, mid, id, argc, argv, block, body, noex); + if (block && !iter) { + VALUE result; + int state; + + PUSH_TAG(PROT_LOOP); + prot_tag->blkid = block->uniq; + state = EXEC_TAG(); + if (state == 0) { + retry: + result = rb_call0(klass, recv, mid, id, argc, argv, block, body, noex); + } + else if (state == TAG_BREAK && TAG_DST()) { + result = prot_tag->retval; + state = 0; + } + POP_TAG(); + if (state) JUMP_TAG(state); + return result; + } + else { + return rb_call0(klass, recv, mid, id, argc, argv, block, body, noex); + } } VALUE @@ -5929,7 +5918,7 @@ rb_apply(VALUE recv, ID mid, VALUE args) argc = RARRAY(args)->len; /* Assigns LONG, but argc is INT */ argv = ALLOCA_N(VALUE, argc); MEMCPY(argv, RARRAY(args)->ptr, VALUE, argc); - return rb_call(CLASS_OF(recv), recv, mid, argc, argv, 0, CALLING_FCALL); + return rb_call(CLASS_OF(recv), recv, mid, argc, argv, 0, CALLING_FUNCALL, 0); } static VALUE @@ -5941,7 +5930,7 @@ send_funcall(int argc, VALUE *argv, VALUE recv, calling_scope_t scope) vid = *argv++; argc--; vid = rb_call(CLASS_OF(recv), recv, rb_to_id(vid), argc, argv, - ruby_frame->block, scope); + ruby_frame->block, scope, 1); return vid; } @@ -5998,7 +5987,7 @@ rb_f_send(int argc, VALUE *argv, VALUE recv) static VALUE rb_f_funcall(int argc, VALUE *argv, VALUE recv) { - return send_funcall(argc, argv, recv, CALLING_FCALL); + return send_funcall(argc, argv, recv, CALLING_FUNCALL); } VALUE @@ -6022,19 +6011,19 @@ rb_funcall(VALUE recv, ID mid, int n, ...) argv = 0; } - return rb_call(CLASS_OF(recv), recv, mid, n, argv, 0, CALLING_FCALL); + return rb_call(CLASS_OF(recv), recv, mid, n, argv, 0, CALLING_FUNCALL, 0); } VALUE rb_funcall2(VALUE recv, ID mid, int argc, const VALUE *argv) { - return rb_call(CLASS_OF(recv), recv, mid, argc, argv, 0, CALLING_FCALL); + return rb_call(CLASS_OF(recv), recv, mid, argc, argv, 0, CALLING_FUNCALL, 0); } VALUE rb_funcall3(VALUE recv, ID mid, int argc, const VALUE *argv) { - return rb_call(CLASS_OF(recv), recv, mid, argc, argv, 0, CALLING_NORMAL); + return rb_call(CLASS_OF(recv), recv, mid, argc, argv, 0, CALLING_NORMAL, 0); } static VALUE @@ -6045,7 +6034,7 @@ call_super_0(VALUE klass, VALUE self, ID mid, return method_missing(self, mid, argc, argv, block, CSTAT_SUPER); } - return rb_call(RCLASS(klass)->super, self, mid, argc, argv, block, CALLING_SUPER); + return rb_call(RCLASS(klass)->super, self, mid, argc, argv, block, CALLING_SUPER, 1); } static VALUE @@ -6111,7 +6100,7 @@ backtrace(int lev) * * Returns the current execution stack---an array containing strings in * the form ``file:line'' or ``file:line: in - * `method'''. The optional _start_ parameter + * `method'''. The optional start_ parameter * determines the number of initial stack entries to omit from the * result. * @@ -6326,7 +6315,7 @@ static VALUE rb_f_eval(int argc, VALUE *argv, VALUE self) { VALUE src, scope, vfile, vline; - char *file = "(eval)"; + const char *file = "(eval)"; int line = 1; rb_scan_args(argc, argv, "13", &src, &scope, &vfile, &vline); @@ -6430,12 +6419,8 @@ static VALUE yield_under_i(VALUE arg) { VALUE *args = (VALUE *)arg; - int avalue = Qtrue; - if (args[0] == Qundef) { - avalue = Qfalse; - } - return rb_yield_0(args[0], args[1], ruby_cbase, YIELD_PUBLIC_DEF, avalue); + return rb_yield_0(args[0], args[1], ruby_cbase, YIELD_PUBLIC_DEF); } /* block eval under the class/module context */ @@ -6458,7 +6443,7 @@ specific_eval(int argc, VALUE *argv, VALUE klass, VALUE self) return yield_under(klass, self, Qundef); } else { - char *file = "(eval)"; + const char *file = "(eval)"; int line = 1; if (argc == 0) { @@ -6554,7 +6539,7 @@ rb_obj_instance_exec(int argc, VALUE *argv, VALUE self) else { klass = rb_singleton_class(self); } - return yield_under(klass, self, rb_values_new2(argc, argv)); + return yield_under(klass, self, rb_ary_new4(argc, argv)); } /* @@ -6610,7 +6595,7 @@ rb_mod_module_eval(int argc, VALUE *argv, VALUE mod) VALUE rb_mod_module_exec(int argc, VALUE *argv, VALUE mod) { - return yield_under(mod, mod, rb_values_new2(argc, argv)); + return yield_under(mod, mod, rb_ary_new4(argc, argv)); } VALUE rb_load_path; @@ -7086,7 +7071,6 @@ set_method_visibility(VALUE self, int argc, VALUE *argv, ID ex) for (i=0; i self + * local(symbol, ...) => self + * + * With no arguments, sets the default visibility for subsequently + * defined methods to local. With arguments, sets the named methods to + * have local visibility. + */ + +static VALUE +rb_mod_local(int argc, VALUE *argv, VALUE module) +{ + secure_visibility(module); + if (argc == 0) { + VIS_SET(VIS_LOCAL); + } + else { + set_method_visibility(module, argc, argv, NOEX_LOCAL); + rb_clear_cache(); + } + return module; +} + /* * call-seq: * mod.public_class_method(symbol, ...) => mod @@ -7220,6 +7228,16 @@ top_public(int argc, VALUE *argv) return rb_mod_public(argc, argv, rb_cObject); } +/* + * call-seq: + * private => self + * private(symbol, ...) => self + * + * With no arguments, sets the default visibility for subsequently + * defined methods to private. With arguments, sets the named methods + * to have private visibility. + */ + static VALUE top_private(int argc, VALUE *argv) { @@ -7285,9 +7303,9 @@ rb_mod_modfunc(int argc, VALUE *argv, VALUE module) id = rb_to_id(argv[i]); for (;;) { - body = search_method(m, id, &m); + body = search_method(m, id, &m, LOOKUP_NOSKIP); if (body == 0) { - body = search_method(rb_cObject, id, &m); + body = search_method(rb_cObject, id, &m, LOOKUP_NOSKIP); } if (body == 0 || body->nd_body == 0) { rb_bug("undefined method `%s'; can't happen", rb_id2name(id)); @@ -7354,7 +7372,7 @@ rb_mod_include(int argc, VALUE *argv, VALUE module) void rb_obj_call_init(VALUE obj, int argc, VALUE *argv) { - rb_call(CLASS_OF(obj), obj, init, argc, argv, ruby_frame->block, CALLING_FCALL); + rb_call(CLASS_OF(obj), obj, init, argc, argv, ruby_frame->block, CALLING_FUNCALL, 1); } void @@ -7581,7 +7599,7 @@ call_end_proc(VALUE data) PUSH_FRAME(Qfalse); ruby_frame->self = ruby_frame->prev->self; ruby_frame->node = 0; - proc_invoke(data, rb_ary_new2(0), Qundef, 0); + proc_invoke(data, rb_ary_new2(0), Qundef, 0, 1); POP_FRAME(); } @@ -7704,13 +7722,13 @@ Init_eval(void) rb_define_global_function("eval", rb_f_eval, -1); rb_define_global_function("iterator?", rb_f_block_given_p, 0); rb_define_global_function("block_given?", rb_f_block_given_p, 0); - rb_define_global_function("method_missing", rb_method_missing, -1); rb_define_global_function("loop", rb_f_loop, 0); - rb_define_method(rb_mKernel, "respond_to?", obj_respond_to, -1); + rb_define_private_method(rb_cBasicObject, "method_missing", rb_method_missing, -1); + rb_define_method(rb_cBasicObject, "respond_to?", obj_respond_to, -1); respond_to = rb_intern("respond_to?"); rb_global_variable((VALUE*)&basic_respond_to); - basic_respond_to = rb_method_node(rb_cObject, respond_to); + basic_respond_to = rb_method_node(rb_cBasicObject, respond_to); rb_define_global_function("raise", rb_f_raise, -1); rb_define_global_function("fail", rb_f_raise, -1); @@ -7727,9 +7745,9 @@ Init_eval(void) rb_define_global_function("global_variables", rb_f_global_variables, 0); /* in variable.c */ rb_define_global_function("local_variables", rb_f_local_variables, 0); - rb_define_method(rb_mKernel, "send", rb_f_send, -1); - rb_define_method(rb_mKernel, "__send__", rb_f_send, -1); - rb_define_method(rb_mKernel, "funcall", rb_f_funcall, -1); + rb_define_method(rb_cBasicObject, "send", rb_f_send, -1); + rb_define_method(rb_cBasicObject, "__send__", rb_f_send, -1); + rb_define_method(rb_cBasicObject, "funcall", rb_f_funcall, -1); rb_define_method(rb_mKernel, "instance_eval", rb_obj_instance_eval, -1); rb_define_method(rb_mKernel, "instance_exec", rb_obj_instance_exec, -1); @@ -7739,6 +7757,7 @@ Init_eval(void) rb_define_private_method(rb_cModule, "public", rb_mod_public, -1); rb_define_private_method(rb_cModule, "protected", rb_mod_protected, -1); rb_define_private_method(rb_cModule, "private", rb_mod_private, -1); + rb_define_private_method(rb_cModule, "local", rb_mod_local, -1); rb_define_private_method(rb_cModule, "module_function", rb_mod_modfunc, -1); rb_define_method(rb_cModule, "method_defined?", rb_mod_method_defined, -1); rb_define_method(rb_cModule, "public_method_defined?", rb_mod_public_method_defined, 1); @@ -8147,26 +8166,19 @@ proc_alloc(VALUE klass, int lambda) struct FRAME *frame = ruby_frame; struct BLOCK *data; - if (!rb_block_given_p() && (lambda || !rb_f_block_given_p())) { - rb_raise(rb_eArgError, "tried to create Proc object without a block"); - } - if (!lambda) { - if (!rb_block_given_p()) { - frame = ruby_frame->prev; - } - else { - if (frame->block->block_obj) { - VALUE obj = frame->block->block_obj; - if (CLASS_OF(obj) != klass) { - obj = proc_clone(obj); - RBASIC(obj)->klass = klass; - } - return obj; - } + if (!rb_block_given_p()) { + if (lambda || !ruby_frame->prev || !ruby_frame->prev->block) { + rb_raise(rb_eArgError, "tried to create Proc object without a block"); } + frame = ruby_frame->prev; } - else if (!rb_block_given_p()) { - rb_warn("tried to create Proc object without a block"); + else if (!lambda && frame->block->block_obj) { + VALUE obj = frame->block->block_obj; + if (CLASS_OF(obj) != klass) { + obj = proc_clone(obj); + RBASIC(obj)->klass = klass; + } + return obj; } block = Data_Make_Struct(klass, struct BLOCK, blk_mark, blk_free, data); *data = *frame->block; @@ -8179,7 +8191,7 @@ proc_alloc(VALUE klass, int lambda) scope_dup(data->scope); proc_save_safe_level(block); if (lambda) { - data->flags |= BLOCK_LAMBDA; + data->flags |= BLOCK_LAMBDA; } else { frame->block->block_obj = block; @@ -8261,7 +8273,7 @@ block_orphan(struct BLOCK *data) } static VALUE -proc_invoke(VALUE proc, VALUE args /* OK */, VALUE self, VALUE klass) +proc_invoke(VALUE proc, VALUE args /* OK */, VALUE self, VALUE klass, int call) { struct BLOCK _block; struct BLOCK *data, *volatile old_block; @@ -8269,15 +8281,11 @@ proc_invoke(VALUE proc, VALUE args /* OK */, VALUE self, VALUE klass) int state; volatile int safe = ruby_safe_level; volatile VALUE old_wrapper = ruby_wrapper; - volatile int pcall, avalue = Qtrue; - VALUE bvar = Qnil, tmp = args; + volatile int pcall; + VALUE bvar = Qnil; Data_Get_Struct(proc, struct BLOCK, data); - pcall = (data->flags & BLOCK_LAMBDA) ? YIELD_LAMBDA_CALL : 0; - if (!pcall && RARRAY(args)->len == 1) { - avalue = Qfalse; - args = RARRAY(args)->ptr[0]; - } + pcall = call ? YIELD_LAMBDA_CALL : 0; if (rb_block_given_p() && ruby_frame->callee) { if (klass != ruby_frame->this_class) klass = rb_obj_class(proc); @@ -8292,11 +8300,11 @@ proc_invoke(VALUE proc, VALUE args /* OK */, VALUE self, VALUE klass) _block.block_obj = bvar; if (self != Qundef) _block.frame.self = self; if (klass) _block.frame.this_class = klass; - _block.frame.argc = RARRAY(tmp)->len; + _block.frame.argc = RARRAY(args)->len; _block.frame.flags = ruby_frame->flags; if (_block.frame.argc && (ruby_frame->flags & FRAME_DMETH)) { NEWOBJ(scope, struct SCOPE); - OBJSETUP(scope, tmp, T_SCOPE); + OBJSETUP(scope, args, T_SCOPE); scope->local_tbl = _block.scope->local_tbl; scope->local_vars = _block.scope->local_vars; _block.scope = scope; @@ -8304,12 +8312,12 @@ proc_invoke(VALUE proc, VALUE args /* OK */, VALUE self, VALUE klass) /* modify current frame */ old_block = ruby_frame->block; ruby_frame->block = &_block; - PUSH_TAG((pcall&YIELD_LAMBDA_CALL) ? PROT_LAMBDA : PROT_NONE); + PUSH_TAG((data->flags&BLOCK_LAMBDA) ? PROT_LAMBDA : PROT_NONE); state = EXEC_TAG(); if (state == 0) { proc_set_safe_level(proc); result = rb_yield_0(args, self, (self!=Qundef)?CLASS_OF(self):0, - pcall | YIELD_PROC_CALL, avalue); + pcall | YIELD_PROC_CALL); } else if (TAG_DST()) { result = prot_tag->retval; @@ -8380,7 +8388,37 @@ proc_invoke(VALUE proc, VALUE args /* OK */, VALUE self, VALUE klass) VALUE rb_proc_call(VALUE proc, VALUE args /* OK */) { - return proc_invoke(proc, args, Qundef, 0); + return proc_invoke(proc, args, Qundef, 0, 1); +} + +/* + * call-seq: + * prc.yield(params,...) => obj + * + * Invokes the block, setting the block's parameters to the values in + * params in the same manner the yield statement does. + * + * a_proc = Proc.new {|a, *b| b.collect {|i| i*a }} + * a_proc.yield(9, 1, 2, 3) #=> [9, 18, 27] + * a_proc.yield([9, 1, 2, 3]) #=> [9, 18, 27] + * a_proc = Proc.new {|a,b| a} + * a_proc.yield(1,2,3) # => [1] + */ + +VALUE +rb_proc_yield(int argc, VALUE *argv, VALUE proc) +{ + if (argc == 1) + return proc_invoke(proc, svalue_to_avalue(argv[0]), Qundef, 0, 0); + else + return proc_invoke(proc, rb_ary_new4(argc, argv), Qundef, 0, 0); +} + +static VALUE +nil_yield(int argc, VALUE *argv) +{ + localjump_error("no block given", Qnil, 0, backtrace(0)); + return Qnil; /* not reached */ } int @@ -8393,7 +8431,8 @@ rb_proc_arity(VALUE proc) Data_Get_Struct(proc, struct BLOCK, data); var = data->var; if (var == 0) { - if (data->body && nd_type(data->body) == NODE_IFUNC && + if (!data->body) return 0; + if (nd_type(data->body) == NODE_IFUNC && data->body->nd_cfnc == bmcall) { return method_arity(data->body->nd_tval); } @@ -8416,7 +8455,12 @@ rb_proc_arity(VALUE proc) n++; list = list->nd_next; } - if (var->nd_args) return -n-1; + if (var->nd_args) { + if (nd_type(var->nd_args) == NODE_POSTARG) { + return -n-1-var->nd_args->nd_head->nd_alen; + } + return -n-1; + } return n; } } @@ -8699,14 +8743,14 @@ mnew(VALUE klass, VALUE obj, ID id, VALUE mklass) { VALUE method; NODE *body; - int noex; struct METHOD *data; VALUE rklass = klass; ID oid = id; + int noex = LOOKUP_NORMAL; again: if ((body = rb_get_method_body(&klass, &id, &noex)) == 0) { - print_undef(rklass, oid); + raise_undef(rklass, oid); } if (nd_type(body) == NODE_ZSUPER) { @@ -8844,7 +8888,9 @@ method_unbind(VALUE obj) * Method object (or raising NameError). The * Method object acts as a closure in obj's object * instance, so instance variables and the value of self - * remain available. + * remain available. Looks for private methods if optional second + * argument is true. + * * class Demo * def initialize(n) @@ -8874,8 +8920,8 @@ rb_obj_method(VALUE obj, VALUE vid) * call-seq: * mod.instance_method(symbol) => unbound_method * - * Returns an +UnboundMethod+ representing the given - * instance method in _mod_. + * Returns an +UnboundMethod+ representing the given instance method + * in _mod_. * * class Interpreter * def do_a() print "there, "; end @@ -9056,12 +9102,12 @@ static VALUE umethod_bind(VALUE method, VALUE recv) { struct METHOD *data, *bound; - VALUE rklass = CLASS_OF(recv), klass = rklass; + VALUE rklass = CLASS_OF(recv); Data_Get_Struct(method, struct METHOD, data); if (data->rklass != rklass) { if (FL_TEST(data->rklass, FL_SINGLETON)) { - rb_raise(rb_eTypeError, "singleton method called for a different object"); + rb_raise(rb_eTypeError, "singleton method bound for a different object"); } if (TYPE(data->rklass) == T_MODULE) { st_table *m_tbl = RCLASS(data->rklass)->m_tbl; @@ -9080,7 +9126,6 @@ umethod_bind(VALUE method, VALUE recv) method = Data_Make_Struct(rb_cMethod,struct METHOD,bm_mark,free,bound); *bound = *data; bound->recv = recv; - bound->klass = klass; bound->rklass = rklass; return method; @@ -9109,8 +9154,14 @@ rb_node_arity(NODE *body) body = body->nd_head; if (!body) return 0; n = body->nd_frml ? RARRAY(body->nd_frml)->len : 0; - if (body->nd_opt || body->nd_rest) + if (body->nd_opt) + return -n-1; + if (body->nd_rest) { + if (nd_type(body->nd_rest) == NODE_POSTARG) { + return -n-1-body->nd_rest->nd_head->nd_alen; + } n = -n-1; + } return n; default: rb_raise(rb_eArgError, "invalid node 0x%x", nd_type(body)); @@ -9195,7 +9246,7 @@ method_inspect(VALUE method) struct METHOD *data; VALUE str; const char *s; - char *sharp = "#"; + const char *sharp = "#"; Data_Get_Struct(method, struct METHOD, data); str = rb_str_buf_new2("#<"); @@ -9451,6 +9502,7 @@ Init_Proc(void) rb_define_method(rb_cProc, "clone", proc_clone, 0); rb_define_method(rb_cProc, "dup", proc_dup, 0); rb_define_method(rb_cProc, "call", rb_proc_call, -2); + rb_define_method(rb_cProc, "yield", rb_proc_yield, -1); rb_define_method(rb_cProc, "arity", proc_arity, 0); rb_define_method(rb_cProc, "[]", rb_proc_call, -2); rb_define_method(rb_cProc, "==", proc_eq, 1); @@ -9463,6 +9515,8 @@ Init_Proc(void) rb_define_global_function("proc", rb_block_proc, 0); rb_define_global_function("lambda", proc_lambda, 0); + rb_define_method(rb_cNilClass, "yield", nil_yield, -1); + rb_cMethod = rb_define_class("Method", rb_cObject); rb_undef_alloc_func(rb_cMethod); rb_undef_method(CLASS_OF(rb_cMethod), "new"); @@ -10790,6 +10844,7 @@ rb_thread_fd_writable(int fd) if (rb_thread_critical) return Qtrue; if (curr_thread == curr_thread->next) return Qtrue; if (curr_thread->status == THREAD_TO_KILL) return Qtrue; + if (curr_thread->status == THREAD_KILLED) return Qtrue; curr_thread->status = THREAD_STOPPED; FD_ZERO(&curr_thread->readfds); @@ -11838,7 +11893,7 @@ rb_thread_terminated(rb_thread_t th, int state, enum thread_status status) rb_thread_main_jump(ruby_errinfo, RESTORE_RAISE); } } - else if (th->safe < 4 && (ruby_thread_abort || th->abort || RTEST(ruby_debug))) { + else if (th->safe < 4 && (ruby_thread_abort||th->abort||RTEST(ruby_debug))) { /* exit on main_thread */ error_print(); rb_thread_main_jump(ruby_errinfo, RESTORE_EXIT); @@ -11923,7 +11978,7 @@ rb_thread_yield(VALUE arg, rb_thread_t th) rb_dvar_push('~', Qnil); ruby_frame->block->dyna_vars = ruby_dyna_vars; - return rb_yield_0(arg, 0, 0, YIELD_LAMBDA_CALL, Qtrue); + return rb_yield_0(arg, 0, 0, YIELD_LAMBDA_CALL); } /* @@ -12972,7 +13027,7 @@ rb_f_catch(VALUE dmy, VALUE tag) tag = ID2SYM(rb_to_id(tag)); PUSH_TAG(tag); if ((state = EXEC_TAG()) == 0) { - val = rb_yield_0(tag, 0, 0, 0, Qfalse); + val = rb_yield_0(tag, 0, 0, 0); } else if (state == TAG_THROW && tag == prot_tag->dst) { val = prot_tag->retval; diff --git a/ext/.document b/ext/.document index 92370174fa..0985f45328 100644 --- a/ext/.document +++ b/ext/.document @@ -3,7 +3,8 @@ iconv/iconv.c nkf/lib/kconv.rb nkf/nkf.c +socket/socket.c stringio/stringio.c strscan/strscan.c -zlib/zlib.c win32ole +zlib/zlib.c diff --git a/ext/Setup b/ext/Setup index 41817c0f79..b0f29b9f7b 100644 --- a/ext/Setup +++ b/ext/Setup @@ -10,7 +10,6 @@ #digest/sha1 #digest/sha2 #dl -#enumerator #etc #fcntl #gdbm diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 7f3f1520ee..46ed596b7e 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -302,7 +302,7 @@ VpNewRbClass(U_LONG mx, char *str, VALUE klass) } VP_EXPORT Real * -VpCreateRbObject(U_LONG mx, char *str) +VpCreateRbObject(U_LONG mx, const char *str) { Real *pv = VpAlloc(mx,str); pv->obj = (VALUE)Data_Wrap_Struct(rb_cBigDecimal, 0, BigDecimal_delete, pv); @@ -917,7 +917,7 @@ BigDecimal_round(int argc, VALUE *argv, VALUE self) { ENTER(5); Real *c, *a; - int iLoc; + int iLoc = 0; U_LONG mx; VALUE vLoc; VALUE vRound; @@ -1578,7 +1578,7 @@ VpIsNegDoubleZero(double v) } VP_EXPORT int -VpException(unsigned short f,char *str,int always) +VpException(unsigned short f, const char *str,int always) { VALUE exc; int fatal=0; @@ -1720,7 +1720,7 @@ NaN: * returns number of chars needed to represent vp in specified format. */ VP_EXPORT U_LONG -VpNumOfChars(Real *vp,char *pszFmt) +VpNumOfChars(Real *vp,const char *pszFmt) { S_INT ex; U_LONG nc; @@ -1873,7 +1873,7 @@ overflow: * NULL be returned if memory allocation is failed,or any error. */ VP_EXPORT Real * -VpAlloc(U_LONG mx, char *szVal) +VpAlloc(U_LONG mx, const char *szVal) { U_LONG i, ni, ipn, ipf, nf, ipe, ne, nalloc; char v,*psz; @@ -3277,7 +3277,7 @@ VpToFString(Real *a,char *psz,int fFmt,int fPlus) * ne ... number of characters in exp_chr[],not including '+/-'. */ VP_EXPORT int -VpCtoV(Real *a, char *int_chr, U_LONG ni, char *frac, U_LONG nf, char *exp_chr, U_LONG ne) +VpCtoV(Real *a, const char *int_chr, U_LONG ni, const char *frac, U_LONG nf, const char *exp_chr, U_LONG ne) { U_LONG i, j, ind_a, ma, mi, me; U_LONG loc; diff --git a/ext/bigdecimal/bigdecimal.h b/ext/bigdecimal/bigdecimal.h index aabc551a76..80a1ba816c 100644 --- a/ext/bigdecimal/bigdecimal.h +++ b/ext/bigdecimal/bigdecimal.h @@ -105,7 +105,7 @@ typedef struct { VP_EXPORT Real * VpNewRbClass(U_LONG mx,char *str,VALUE klass); -VP_EXPORT Real *VpCreateRbObject(U_LONG mx,char *str); +VP_EXPORT Real *VpCreateRbObject(U_LONG mx,const char *str); VP_EXPORT U_LONG VpBaseFig(void); VP_EXPORT U_LONG VpDblFig(void); @@ -126,13 +126,13 @@ VP_EXPORT int VpIsRoundMode(unsigned long n); VP_EXPORT unsigned long VpGetRoundMode(void); VP_EXPORT unsigned long VpSetRoundMode(unsigned long n); -VP_EXPORT int VpException(unsigned short f,char *str,int always); +VP_EXPORT int VpException(unsigned short f,const char *str,int always); VP_EXPORT int VpIsNegDoubleZero(double v); -VP_EXPORT U_LONG VpNumOfChars(Real *vp,char *pszFmt); +VP_EXPORT U_LONG VpNumOfChars(Real *vp,const char *pszFmt); VP_EXPORT U_LONG VpInit(U_LONG BaseVal); VP_EXPORT void *VpMemAlloc(U_LONG mb); VP_EXPORT void VpFree(Real *pv); -VP_EXPORT Real *VpAlloc(U_LONG mx, char *szVal); +VP_EXPORT Real *VpAlloc(U_LONG mx, const char *szVal); VP_EXPORT int VpAsgn(Real *c,Real *a,int isw); VP_EXPORT int VpAddSub(Real *c,Real *a,Real *b,int operation); VP_EXPORT int VpMult(Real *c,Real *a,Real *b); @@ -143,7 +143,7 @@ VP_EXPORT void VpSzMantissa(Real *a,char *psz); VP_EXPORT int VpToSpecialString(Real *a,char *psz,int fPlus); VP_EXPORT void VpToString(Real *a,char *psz,int fFmt,int fPlus); VP_EXPORT void VpToFString(Real *a,char *psz,int fFmt,int fPlus); -VP_EXPORT int VpCtoV(Real *a,char *int_chr,U_LONG ni,char *frac,U_LONG nf,char *exp_chr,U_LONG ne); +VP_EXPORT int VpCtoV(Real *a,const char *int_chr,U_LONG ni,const char *frac,U_LONG nf,const char *exp_chr,U_LONG ne); VP_EXPORT int VpVtoD(double *d,S_LONG *e,Real *m); VP_EXPORT void VpDtoV(Real *m,double d); VP_EXPORT void VpItoV(Real *m,S_INT ival); diff --git a/ext/curses/curses.c b/ext/curses/curses.c index bdfae8360a..f1d037b19d 100644 --- a/ext/curses/curses.c +++ b/ext/curses/curses.c @@ -90,8 +90,7 @@ no_window() } while (0) static void -free_window(winp) - struct windata *winp; +free_window(struct windata *winp) { if (winp->window && winp->window != stdscr) delwin(winp->window); winp->window = 0; @@ -99,9 +98,7 @@ free_window(winp) } static VALUE -prep_window(class, window) - VALUE class; - WINDOW *window; +prep_window(VALUE class, WINDOW *window) { VALUE obj; struct windata *winp; @@ -178,8 +175,7 @@ curses_closed() /* def clear */ static VALUE -curses_clear(obj) - VALUE obj; +curses_clear(VALUE obj) { curses_stdscr(); wclear(stdscr); @@ -197,8 +193,7 @@ curses_clrtoeol() /* def refresh */ static VALUE -curses_refresh(obj) - VALUE obj; +curses_refresh(VALUE obj) { curses_stdscr(); refresh(); @@ -207,8 +202,7 @@ curses_refresh(obj) /* def doupdate */ static VALUE -curses_doupdate(obj) - VALUE obj; +curses_doupdate(VALUE obj) { curses_stdscr(); #ifdef HAVE_DOUPDATE @@ -221,8 +215,7 @@ curses_doupdate(obj) /* def echo */ static VALUE -curses_echo(obj) - VALUE obj; +curses_echo(VALUE obj) { curses_stdscr(); echo(); @@ -231,8 +224,7 @@ curses_echo(obj) /* def noecho */ static VALUE -curses_noecho(obj) - VALUE obj; +curses_noecho(VALUE obj) { curses_stdscr(); noecho(); @@ -241,8 +233,7 @@ curses_noecho(obj) /* def raw */ static VALUE -curses_raw(obj) - VALUE obj; +curses_raw(VALUE obj) { curses_stdscr(); raw(); @@ -251,8 +242,7 @@ curses_raw(obj) /* def noraw */ static VALUE -curses_noraw(obj) - VALUE obj; +curses_noraw(VALUE obj) { curses_stdscr(); noraw(); @@ -261,8 +251,7 @@ curses_noraw(obj) /* def cbreak */ static VALUE -curses_cbreak(obj) - VALUE obj; +curses_cbreak(VALUE obj) { curses_stdscr(); cbreak(); @@ -271,8 +260,7 @@ curses_cbreak(obj) /* def nocbreak */ static VALUE -curses_nocbreak(obj) - VALUE obj; +curses_nocbreak(VALUE obj) { curses_stdscr(); nocbreak(); @@ -281,8 +269,7 @@ curses_nocbreak(obj) /* def nl */ static VALUE -curses_nl(obj) - VALUE obj; +curses_nl(VALUE obj) { curses_stdscr(); nl(); @@ -291,8 +278,7 @@ curses_nl(obj) /* def nonl */ static VALUE -curses_nonl(obj) - VALUE obj; +curses_nonl(VALUE obj) { curses_stdscr(); nonl(); @@ -301,8 +287,7 @@ curses_nonl(obj) /* def beep */ static VALUE -curses_beep(obj) - VALUE obj; +curses_beep(VALUE obj) { #ifdef HAVE_BEEP curses_stdscr(); @@ -313,8 +298,7 @@ curses_beep(obj) /* def flash */ static VALUE -curses_flash(obj) - VALUE obj; +curses_flash(VALUE obj) { #ifdef HAVE_FLASH curses_stdscr(); @@ -325,9 +309,7 @@ curses_flash(obj) /* def ungetch */ static VALUE -curses_ungetch(obj, ch) - VALUE obj; - VALUE ch; +curses_ungetch(VALUE obj, VALUE ch) { #ifdef HAVE_UNGETCH curses_stdscr(); @@ -340,10 +322,7 @@ curses_ungetch(obj, ch) /* def setpos(y, x) */ static VALUE -curses_setpos(obj, y, x) - VALUE obj; - VALUE y; - VALUE x; +curses_setpos(VALUE obj, VALUE y, VALUE x) { curses_stdscr(); move(NUM2INT(y), NUM2INT(x)); @@ -352,8 +331,7 @@ curses_setpos(obj, y, x) /* def standout */ static VALUE -curses_standout(obj) - VALUE obj; +curses_standout(VALUE obj) { standout(); return Qnil; @@ -361,8 +339,7 @@ curses_standout(obj) /* def standend */ static VALUE -curses_standend(obj) - VALUE obj; +curses_standend(VALUE obj) { standend(); return Qnil; @@ -370,8 +347,7 @@ curses_standend(obj) /* def inch */ static VALUE -curses_inch(obj) - VALUE obj; +curses_inch(VALUE obj) { curses_stdscr(); return CH2FIX(inch()); @@ -379,9 +355,7 @@ curses_inch(obj) /* def addch(ch) */ static VALUE -curses_addch(obj, ch) - VALUE obj; - VALUE ch; +curses_addch(VALUE obj, VALUE ch) { curses_stdscr(); addch(NUM2CH(ch)); @@ -390,9 +364,7 @@ curses_addch(obj, ch) /* def insch(ch) */ static VALUE -curses_insch(obj, ch) - VALUE obj; - VALUE ch; +curses_insch(VALUE obj, VALUE ch) { curses_stdscr(); insch(NUM2CH(ch)); @@ -401,9 +373,7 @@ curses_insch(obj, ch) /* def addstr(str) */ static VALUE -curses_addstr(obj, str) - VALUE obj; - VALUE str; +curses_addstr(VALUE obj, VALUE str) { curses_stdscr(); if (!NIL_P(str)) { @@ -414,8 +384,7 @@ curses_addstr(obj, str) /* def getch */ static VALUE -curses_getch(obj) - VALUE obj; +curses_getch(VALUE obj) { rb_read_check(stdin); curses_stdscr(); @@ -424,8 +393,7 @@ curses_getch(obj) /* def getstr */ static VALUE -curses_getstr(obj) - VALUE obj; +curses_getstr(VALUE obj) { char rtn[1024]; /* This should be big enough.. I hope */ @@ -440,8 +408,7 @@ curses_getstr(obj) /* def delch */ static VALUE -curses_delch(obj) - VALUE obj; +curses_delch(VALUE obj) { delch(); return Qnil; @@ -449,8 +416,7 @@ curses_delch(obj) /* def delelteln */ static VALUE -curses_deleteln(obj) - VALUE obj; +curses_deleteln(VALUE obj) { #if defined(HAVE_DELETELN) || defined(deleteln) deleteln(); @@ -460,8 +426,7 @@ curses_deleteln(obj) /* def insertln */ static VALUE -curses_insertln(obj) - VALUE obj; +curses_insertln(VALUE obj) { #if defined(HAVE_INSERTLN) || defined(insertln) insertln(); @@ -471,9 +436,7 @@ curses_insertln(obj) /* def keyname */ static VALUE -curses_keyname(obj, c) - VALUE obj; - VALUE c; +curses_keyname(VALUE obj, VALUE c) { #ifdef HAVE_KEYNAME const char *name; @@ -768,12 +731,7 @@ window_s_allocate(VALUE class) /* def initialize(h, w, top, left) */ static VALUE -window_initialize(obj, h, w, top, left) - VALUE obj; - VALUE h; - VALUE w; - VALUE top; - VALUE left; +window_initialize(VALUE obj, VALUE h, VALUE w, VALUE top, VALUE left) { struct windata *winp; WINDOW *window; @@ -791,12 +749,7 @@ window_initialize(obj, h, w, top, left) /* def subwin(height, width, top, left) */ static VALUE -window_subwin(obj, height, width, top, left) - VALUE obj; - VALUE height; - VALUE width; - VALUE top; - VALUE left; +window_subwin(VALUE obj, VALUE height, VALUE width, VALUE top, VALUE left) { struct windata *winp; WINDOW *window; @@ -816,8 +769,7 @@ window_subwin(obj, height, width, top, left) /* def close */ static VALUE -window_close(obj) - VALUE obj; +window_close(VALUE obj) { struct windata *winp; @@ -830,8 +782,7 @@ window_close(obj) /* def clear */ static VALUE -window_clear(obj) - VALUE obj; +window_clear(VALUE obj) { struct windata *winp; @@ -843,8 +794,7 @@ window_clear(obj) /* def clrtoeol */ static VALUE -window_clrtoeol(obj) - VALUE obj; +window_clrtoeol(VALUE obj) { struct windata *winp; @@ -856,8 +806,7 @@ window_clrtoeol(obj) /* def refresh */ static VALUE -window_refresh(obj) - VALUE obj; +window_refresh(VALUE obj) { struct windata *winp; @@ -869,8 +818,7 @@ window_refresh(obj) /* def noutrefresh */ static VALUE -window_noutrefresh(obj) - VALUE obj; +window_noutrefresh(VALUE obj) { struct windata *winp; @@ -886,10 +834,7 @@ window_noutrefresh(obj) /* def move(y, x) */ static VALUE -window_move(obj, y, x) - VALUE obj; - VALUE y; - VALUE x; +window_move(VALUE obj, VALUE y, VALUE x) { struct windata *winp; @@ -901,10 +846,7 @@ window_move(obj, y, x) /* def setpos(y, x) */ static VALUE -window_setpos(obj, y, x) - VALUE obj; - VALUE y; - VALUE x; +window_setpos(VALUE obj, VALUE y, VALUE x) { struct windata *winp; @@ -915,8 +857,7 @@ window_setpos(obj, y, x) /* def cury */ static VALUE -window_cury(obj) - VALUE obj; +window_cury(VALUE obj) { struct windata *winp; int x, y; @@ -928,8 +869,7 @@ window_cury(obj) /* def curx */ static VALUE -window_curx(obj) - VALUE obj; +window_curx(VALUE obj) { struct windata *winp; int x, y; @@ -941,8 +881,7 @@ window_curx(obj) /* def maxy */ static VALUE -window_maxy(obj) - VALUE obj; +window_maxy(VALUE obj) { struct windata *winp; @@ -962,8 +901,7 @@ window_maxy(obj) /* def maxx */ static VALUE -window_maxx(obj) - VALUE obj; +window_maxx(VALUE obj) { struct windata *winp; @@ -983,8 +921,7 @@ window_maxx(obj) /* def begy */ static VALUE -window_begy(obj) - VALUE obj; +window_begy(VALUE obj) { struct windata *winp; int x, y; @@ -1000,8 +937,7 @@ window_begy(obj) /* def begx */ static VALUE -window_begx(obj) - VALUE obj; +window_begx(VALUE obj) { struct windata *winp; int x, y; @@ -1053,8 +989,7 @@ window_box(argc, argv, self) /* def standout */ static VALUE -window_standout(obj) - VALUE obj; +window_standout(VALUE obj) { struct windata *winp; @@ -1065,8 +1000,7 @@ window_standout(obj) /* def standend */ static VALUE -window_standend(obj) - VALUE obj; +window_standend(VALUE obj) { struct windata *winp; @@ -1077,8 +1011,7 @@ window_standend(obj) /* def inch */ static VALUE -window_inch(obj) - VALUE obj; +window_inch(VALUE obj) { struct windata *winp; @@ -1088,9 +1021,7 @@ window_inch(obj) /* def addch(ch) */ static VALUE -window_addch(obj, ch) - VALUE obj; - VALUE ch; +window_addch(VALUE obj, VALUE ch) { struct windata *winp; @@ -1102,9 +1033,7 @@ window_addch(obj, ch) /* def insch(ch) */ static VALUE -window_insch(obj, ch) - VALUE obj; - VALUE ch; +window_insch(VALUE obj, VALUE ch) { struct windata *winp; @@ -1116,9 +1045,7 @@ window_insch(obj, ch) /* def addstr(str) */ static VALUE -window_addstr(obj, str) - VALUE obj; - VALUE str; +window_addstr(VALUE obj, VALUE str) { if (!NIL_P(str)) { struct windata *winp; @@ -1131,9 +1058,7 @@ window_addstr(obj, str) /* def <<(str) */ static VALUE -window_addstr2(obj, str) - VALUE obj; - VALUE str; +window_addstr2(VALUE obj, VALUE str) { window_addstr(obj, str); return obj; @@ -1141,8 +1066,7 @@ window_addstr2(obj, str) /* def getch */ static VALUE -window_getch(obj) - VALUE obj; +window_getch(VALUE obj) { struct windata *winp; @@ -1153,8 +1077,7 @@ window_getch(obj) /* def getstr */ static VALUE -window_getstr(obj) - VALUE obj; +window_getstr(VALUE obj) { struct windata *winp; char rtn[1024]; /* This should be big enough.. I hope */ @@ -1171,8 +1094,7 @@ window_getstr(obj) /* def delch */ static VALUE -window_delch(obj) - VALUE obj; +window_delch(VALUE obj) { struct windata *winp; @@ -1183,8 +1105,7 @@ window_delch(obj) /* def delelteln */ static VALUE -window_deleteln(obj) - VALUE obj; +window_deleteln(VALUE obj) { #if defined(HAVE_WDELETELN) || defined(wdeleteln) struct windata *winp; @@ -1197,8 +1118,7 @@ window_deleteln(obj) /* def insertln */ static VALUE -window_insertln(obj) - VALUE obj; +window_insertln(VALUE obj) { #if defined(HAVE_WINSERTLN) || defined(winsertln) struct windata *winp; diff --git a/ext/etc/etc.c b/ext/etc/etc.c index ac95735549..6235d76a73 100644 --- a/ext/etc/etc.c +++ b/ext/etc/etc.c @@ -70,8 +70,7 @@ safe_setup_str(str) #ifdef HAVE_GETPWENT static VALUE -setup_passwd(pwd) - struct passwd *pwd; +setup_passwd(struct passwd *pwd) { if (pwd == 0) rb_sys_fail("/etc/passwd"); return rb_struct_new(sPasswd, @@ -119,10 +118,7 @@ setup_passwd(pwd) * passwd="x", uid=0, gid=0, gecos="root",dir="/root", shell="/bin/bash"> */ static VALUE -etc_getpwuid(argc, argv, obj) - int argc; - VALUE *argv; - VALUE obj; +etc_getpwuid(int argc, VALUE *argv, VALUE obj) { #if defined(HAVE_GETPWENT) VALUE id; @@ -153,8 +149,7 @@ etc_getpwuid(argc, argv, obj) * passwd="x", uid=0, gid=0, gecos="root",dir="/root", shell="/bin/bash"> */ static VALUE -etc_getpwnam(obj, nam) - VALUE obj, nam; +etc_getpwnam(VALUE obj, VALUE nam) { #ifdef HAVE_GETPWENT struct passwd *pwd; @@ -207,8 +202,7 @@ passwd_iterate() * */ static VALUE -etc_passwd(obj) - VALUE obj; +etc_passwd(VALUE obj) { #ifdef HAVE_GETPWENT struct passwd *pw; @@ -232,8 +226,7 @@ etc_passwd(obj) * to getpwent will return the first entry again. */ static VALUE -etc_setpwent(obj) - VALUE obj; +etc_setpwent(VALUE obj) { #ifdef HAVE_GETPWENT setpwent(); @@ -245,8 +238,7 @@ etc_setpwent(obj) * getpwent, and closes the file. */ static VALUE -etc_endpwent(obj) - VALUE obj; +etc_endpwent(VALUE obj) { #ifdef HAVE_GETPWENT endpwent(); @@ -281,8 +273,7 @@ etc_endpwent(obj) * - Passwd#shell contains the path to the login shell of the user as a String. */ static VALUE -etc_getpwent(obj) - VALUE obj; +etc_getpwent(VALUE obj) { #ifdef HAVE_GETPWENT struct passwd *pw; @@ -296,8 +287,7 @@ etc_getpwent(obj) #ifdef HAVE_GETGRENT static VALUE -setup_group(grp) - struct group *grp; +setup_group(struct group *grp) { VALUE mem; char **tbl; @@ -329,8 +319,7 @@ setup_group(grp) * */ static VALUE -etc_getgrgid(obj, id) - VALUE obj, id; +etc_getgrgid(VALUE obj, VALUE id) { #ifdef HAVE_GETGRENT int gid; @@ -357,8 +346,7 @@ etc_getgrgid(obj, id) * */ static VALUE -etc_getgrnam(obj, nam) - VALUE obj, nam; +etc_getgrnam(VALUE obj, VALUE nam) { #ifdef HAVE_GETGRENT struct group *grp; @@ -412,8 +400,7 @@ group_iterate() * */ static VALUE -etc_group(obj) - VALUE obj; +etc_group(VALUE obj) { #ifdef HAVE_GETGRENT struct group *grp; @@ -437,8 +424,7 @@ etc_group(obj) * to getgrent will return the first entry again. */ static VALUE -etc_setgrent(obj) - VALUE obj; +etc_setgrent(VALUE obj) { #ifdef HAVE_GETGRENT setgrent(); @@ -450,8 +436,7 @@ etc_setgrent(obj) * getgrent, and closes the file. */ static VALUE -etc_endgrent(obj) - VALUE obj; +etc_endgrent(VALUE obj) { #ifdef HAVE_GETGRENT endgrent(); @@ -480,8 +465,7 @@ etc_endgrent(obj) * members of the group. */ static VALUE -etc_getgrent(obj) - VALUE obj; +etc_getgrent(VALUE obj) { #ifdef HAVE_GETGRENT struct group *gr; diff --git a/ext/extmk.rb b/ext/extmk.rb index ade62c31d2..1a8f6cf3c3 100644 --- a/ext/extmk.rb +++ b/ext/extmk.rb @@ -233,7 +233,7 @@ def parse_args() opts.on('--make=MAKE') do |v| $make = v || 'make' end - opts.on('--make-flags=FLAGS', '--mflags', Shellwords) do |v| + opts.on('--make-flags=FLAGS', '--mflags', Shellwords) do |*v| v.grep(/\A([-\w]+)=(.*)/) {$configure_args["--#{$1}"] = $2} if arg = v.first arg.insert(0, '-') if /\A[^-][^=]*\Z/ =~ arg @@ -258,7 +258,7 @@ def parse_args() $mflags.unshift(*rest) unless rest.empty? def $mflags.set?(flag) - grep(/\A-(?!-).*#{'%c' % flag}/i) { return true } + grep(/\A-(?!-).*#{'%s' % flag}/i) { return true } false end def $mflags.defined?(var) diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index 37224d884b..767896ed57 100644 --- a/ext/iconv/iconv.c +++ b/ext/iconv/iconv.c @@ -166,7 +166,7 @@ iconv_create(VALUE to, VALUE from, struct rb_iconv_opt_t *opt) } if (cd == (iconv_t)-1) { int inval = errno == EINVAL; - char *s = inval ? "invalid encoding " : "iconv"; + const char *s = inval ? "invalid encoding " : "iconv"; volatile VALUE msg = rb_str_new(0, strlen(s) + RSTRING(to)->len + RSTRING(from)->len + 8); diff --git a/ext/io/wait/wait.c b/ext/io/wait/wait.c index 1226007b63..20aab9dd65 100644 --- a/ext/io/wait/wait.c +++ b/ext/io/wait/wait.c @@ -75,8 +75,7 @@ struct wait_readable_arg { #ifdef HAVE_RB_FD_INIT static VALUE -wait_readable(p) - VALUE p; +wait_readable(VALUE p) { struct wait_readable_arg *arg = (struct wait_readable_arg *)p; rb_fdset_t *fds = &arg->fds; diff --git a/ext/nkf/nkf-utf8/nkf.c b/ext/nkf/nkf-utf8/nkf.c index 1677f4f962..63e1ef5ed8 100644 --- a/ext/nkf/nkf-utf8/nkf.c +++ b/ext/nkf/nkf-utf8/nkf.c @@ -1902,18 +1902,14 @@ const int score_table_F0[] = { SCORE_DEPEND, SCORE_NO_EXIST, SCORE_NO_EXIST, SCORE_ERROR, }; -void set_code_score(ptr, score) - struct input_code *ptr; - int score; +void set_code_score(struct input_code *ptr, int score) { if (ptr){ ptr->score |= score; } } -void clr_code_score(ptr, score) - struct input_code *ptr; - int score; +void clr_code_score(struct input_code *ptr, int score) { if (ptr){ ptr->score &= ~score; @@ -1944,8 +1940,7 @@ void code_score(ptr) } } -void status_disable(ptr) -struct input_code *ptr; +void status_disable(struct input_code *ptr) { ptr->stat = -1; ptr->buf[0] = -1; @@ -1953,46 +1948,37 @@ struct input_code *ptr; if (iconv == ptr->iconv_func) set_iconv(FALSE, 0); } -void status_push_ch(ptr, c) - struct input_code *ptr; - int c; +void status_push_ch(struct input_code *ptr, int c) { ptr->buf[ptr->index++] = c; } -void status_clear(ptr) - struct input_code *ptr; +void status_clear(struct input_code *ptr) { ptr->stat = 0; ptr->index = 0; } -void status_reset(ptr) - struct input_code *ptr; +void status_reset(struct input_code *ptr) { status_clear(ptr); ptr->score = SCORE_INIT; } -void status_reinit(ptr) - struct input_code *ptr; +void status_reinit(struct input_code *ptr) { status_reset(ptr); ptr->_file_stat = 0; } -void status_check(ptr, c) - struct input_code *ptr; - int c; +void status_check(struct input_code *ptr, int c) { if (c <= DEL && estab_f){ status_reset(ptr); } } -void s_status(ptr, c) - struct input_code *ptr; - int c; +void s_status(struct input_code *ptr, int c) { switch(ptr->stat){ case -1: @@ -3062,9 +3048,7 @@ w_iconv(c2, c1, c0) #if defined(UTF8_INPUT_ENABLE) || defined(UTF8_OUTPUT_ENABLE) void -w16w_conv(val, p2, p1, p0) - unsigned short val; - int *p2, *p1, *p0; +w16w_conv(unsigned short val, int *p2, int *p1, int *p0) { if (val < 0x80){ *p2 = val; @@ -3771,9 +3755,7 @@ s_oconv(c2, c1) } void -j_oconv(c2, c1) - int c2, - c1; +j_oconv(int c2, int c1) { #ifdef NUMCHAR_OPTION if (c2 == 0 && (c1 & CLASS_MASK) == CLASS_UTF16){ @@ -3858,9 +3840,7 @@ j_oconv(c2, c1) } void -base64_conv(c2, c1) - int c2, - c1; +base64_conv(int c2, int c1) { mime_prechar(c2, c1); (*o_base64conv)(c2,c1); @@ -3871,8 +3851,7 @@ STATIC int broken_buf[3]; STATIC int broken_counter = 0; STATIC int broken_last = 0; int -broken_getc(f) -FILE *f; +broken_getc(FILE *f) { int c,c1; @@ -3911,9 +3890,7 @@ FILE *f; } int -broken_ungetc(c,f) -int c; -FILE *f; +broken_ungetc(int c, FILE *f) { if (broken_counter<2) broken_buf[broken_counter++]=c; @@ -3923,8 +3900,7 @@ FILE *f; STATIC int prev_cr = 0; void -cr_conv(c2,c1) -int c2,c1; +cr_conv(int c2, int c1) { if (prev_cr) { prev_cr = 0; @@ -3972,8 +3948,7 @@ int c2,c1; #define char_size(c2,c1) (c2?2:1) void -fold_conv(c2,c1) -int c2,c1; +fold_conv(int c2, int c1) { int prev0; int fold_state=0; @@ -4146,8 +4121,7 @@ int c2,c1; int z_prev2=0,z_prev1=0; void -z_conv(c2,c1) -int c2,c1; +z_conv(int c2, int c1) { /* if (c2) c1 &= 0x7f; assertion */ @@ -4237,8 +4211,7 @@ int c2,c1; ) void -rot_conv(c2,c1) -int c2,c1; +rot_conv(int c2, int c1) { if (c2==0 || c2==X0201 || c2==ISO8859_1) { c1 = rot13(c1); @@ -4250,8 +4223,7 @@ int c2,c1; } void -hira_conv(c2,c1) -int c2,c1; +hira_conv(int c2, int c1) { if ((hira_f & 1) && c2==0x25 && 0x20= o_len) { o_len += incsize; @@ -78,8 +77,7 @@ rb_nkf_putchar(c) #include "nkf-utf8/utf8tbl.c" #include "nkf-utf8/nkf.c" -int nkf_split_options(arg) - const char* arg; +int nkf_split_options(const char *arg) { int count = 0; char option[256]; @@ -142,8 +140,7 @@ int nkf_split_options(arg) */ static VALUE -rb_nkf_kconv(obj, opt, src) - VALUE obj, opt, src; +rb_nkf_kconv(VALUE obj, VALUE opt, VALUE src) { char *opt_ptr, *opt_end; volatile VALUE v; @@ -205,8 +202,7 @@ rb_nkf_kconv(obj, opt, src) */ static VALUE -rb_nkf_guess1(obj, src) - VALUE obj, src; +rb_nkf_guess1(VALUE obj, VALUE src) { unsigned char *p; unsigned char *pend; @@ -319,8 +315,7 @@ rb_nkf_guess1(obj, src) */ static VALUE -rb_nkf_guess2(obj, src) - VALUE obj, src; +rb_nkf_guess2(VALUE obj, VALUE src) { int code = _BINARY; diff --git a/ext/openssl/ossl_asn1.c b/ext/openssl/ossl_asn1.c index 1947a42d71..c60cbc12a1 100644 --- a/ext/openssl/ossl_asn1.c +++ b/ext/openssl/ossl_asn1.c @@ -445,7 +445,7 @@ decode_time(unsigned char* der, int length) /********/ typedef struct { - char *name; + const char *name; VALUE *klass; } ossl_asn1_info_t; diff --git a/ext/openssl/ossl_pkcs7.c b/ext/openssl/ossl_pkcs7.c index 0f6ffc0277..07d2a39399 100644 --- a/ext/openssl/ossl_pkcs7.c +++ b/ext/openssl/ossl_pkcs7.c @@ -335,7 +335,7 @@ static int ossl_pkcs7_sym2typeid(VALUE sym) { int i, ret = Qnil; - char *s; + const char *s; static struct { const char *name; diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c index d1340e2b17..963b05c5e2 100644 --- a/ext/openssl/ossl_ssl.c +++ b/ext/openssl/ossl_ssl.c @@ -62,7 +62,7 @@ VALUE cSSLSocket; #define ossl_sslctx_get_tmp_dh_cb(o) rb_iv_get((o),"@tmp_dh_callback") #define ossl_sslctx_get_sess_id_ctx(o) rb_iv_get((o),"@session_id_context") -static char *ossl_sslctx_attrs[] = { +static const char *ossl_sslctx_attrs[] = { "cert", "key", "client_ca", "ca_file", "ca_path", "timeout", "verify_mode", "verify_depth", "verify_callback", "options", "cert_store", "extra_chain_cert", @@ -83,8 +83,8 @@ static char *ossl_sslctx_attrs[] = { #define ossl_ssl_set_key(o,v) rb_iv_set((o),"@key",(v)) #define ossl_ssl_set_tmp_dh(o,v) rb_iv_set((o),"@tmp_dh",(v)) -static char *ossl_ssl_attr_readers[] = { "io", "context", }; -static char *ossl_ssl_attrs[] = { "sync_close", }; +static const char *ossl_ssl_attr_readers[] = { "io", "context", }; +static const char *ossl_ssl_attrs[] = { "sync_close", }; /* * SSLContext class @@ -144,7 +144,7 @@ ossl_sslctx_initialize(int argc, VALUE *argv, VALUE self) SSL_METHOD *method = NULL; SSL_CTX *ctx; int i; - char *s; + const char *s; for(i = 0; i < numberof(ossl_sslctx_attrs); i++){ char buf[32]; diff --git a/ext/pty/pty.c b/ext/pty/pty.c index b946fc8380..ef357ace5c 100644 --- a/ext/pty/pty.c +++ b/ext/pty/pty.c @@ -118,8 +118,7 @@ static char SlaveName[DEVICELEN]; static VALUE eChildExited; static VALUE -echild_status(self) - VALUE self; +echild_status(VALUE self) { return rb_ivar_get(self, rb_intern("status")); } @@ -131,9 +130,7 @@ struct pty_info { }; static void -raise_from_wait(state, info) - struct pty_info *info; - char *state; +raise_from_wait(char *state, struct pty_info *info) { extern VALUE rb_last_status; char buf[1024]; @@ -146,8 +143,7 @@ raise_from_wait(state, info) } static VALUE -pty_syswait(info) - struct pty_info *info; +pty_syswait(struct pty_info *info) { int cpid, status; @@ -184,17 +180,13 @@ struct exec_info { }; static VALUE -pty_exec(arg) - struct exec_info *arg; +pty_exec(struct exec_info *arg) { return rb_f_exec(arg->argc, arg->argv); } static void -establishShell(argc, argv, info) - int argc; - VALUE *argv; - struct pty_info *info; +establishShell(int argc, VALUE *argv, struct pty_info *info) { static int i,master,slave,currentPid; char *p,*getenv(); @@ -295,8 +287,7 @@ establishShell(argc, argv, info) } static VALUE -pty_finalize_syswait(info) - struct pty_info *info; +pty_finalize_syswait(struct pty_info *info) { rb_thread_kill(info->thread); rb_funcall(info->thread, rb_intern("value"), 0); @@ -310,8 +301,7 @@ pty_finalize_syswait(info) * or the same interface function. */ static void -getDevice(master,slave) - int *master,*slave; +getDevice(int *master, int *slave) { if (openpty(master, slave, SlaveName, (struct termios *)0, (struct winsize *)0) == -1) { @@ -321,8 +311,7 @@ getDevice(master,slave) #else /* HAVE_OPENPTY */ #ifdef HAVE__GETPTY static void -getDevice(master,slave) - int *master,*slave; +getDevice(int *master, int *slave) { char *name; @@ -335,8 +324,7 @@ getDevice(master,slave) } #else /* HAVE__GETPTY */ static void -getDevice(master,slave) - int *master,*slave; +getDevice(int *master, int *slave) { int i,j; @@ -407,10 +395,7 @@ freeDevice() /* ruby function: getpty */ static VALUE -pty_getpty(argc, argv, self) - int argc; - VALUE *argv; - VALUE self; +pty_getpty(int argc, VALUE *argv, VALUE self) { VALUE res; struct pty_info info; @@ -450,8 +435,7 @@ pty_getpty(argc, argv, self) /* ruby function: protect_signal - obsolete */ static VALUE -pty_protect(self) - VALUE self; +pty_protect(VALUE self) { rb_warn("PTY::protect_signal is no longer needed"); rb_yield(Qnil); @@ -460,8 +444,7 @@ pty_protect(self) /* ruby function: reset_signal - obsolete */ static VALUE -pty_reset_signal(self) - VALUE self; +pty_reset_signal(VALUE self) { rb_warn("PTY::reset_signal is no longer needed"); return self; diff --git a/ext/readline/readline.c b/ext/readline/readline.c index 9661c3cad9..4a28b6e11c 100644 --- a/ext/readline/readline.c +++ b/ext/readline/readline.c @@ -50,10 +50,7 @@ readline_event() } static VALUE -readline_readline(argc, argv, self) - int argc; - VALUE *argv; - VALUE self; +readline_readline(int argc, VALUE *argv, VALUE self) { VALUE tmp, add_hist, result; char *prompt = NULL; @@ -95,8 +92,7 @@ readline_readline(argc, argv, self) } static VALUE -readline_s_set_input(self, input) - VALUE self, input; +readline_s_set_input(VALUE self, VALUE input) { OpenFile *ifp; @@ -108,8 +104,7 @@ readline_s_set_input(self, input) } static VALUE -readline_s_set_output(self, output) - VALUE self, output; +readline_s_set_output(VALUE self, VALUE output) { OpenFile *ofp; @@ -121,9 +116,7 @@ readline_s_set_output(self, output) } static VALUE -readline_s_set_completion_proc(self, proc) - VALUE self; - VALUE proc; +readline_s_set_completion_proc(VALUE self, VALUE proc) { rb_secure(4); if (!rb_respond_to(proc, rb_intern("call"))) @@ -132,35 +125,28 @@ readline_s_set_completion_proc(self, proc) } static VALUE -readline_s_get_completion_proc(self) - VALUE self; +readline_s_get_completion_proc(VALUE self) { rb_secure(4); return rb_attr_get(mReadline, completion_proc); } static VALUE -readline_s_set_completion_case_fold(self, val) - VALUE self; - VALUE val; +readline_s_set_completion_case_fold(VALUE self, VALUE val) { rb_secure(4); return rb_ivar_set(mReadline, completion_case_fold, val); } static VALUE -readline_s_get_completion_case_fold(self) - VALUE self; +readline_s_get_completion_case_fold(VALUE self) { rb_secure(4); return rb_attr_get(mReadline, completion_case_fold); } static char ** -readline_attempted_completion_function(text, start, end) - const char *text; - int start; - int end; +readline_attempted_completion_function(const char *text, int start, int end) { VALUE proc, ary, temp; char **result; @@ -224,8 +210,7 @@ readline_attempted_completion_function(text, start, end) } static VALUE -readline_s_vi_editing_mode(self) - VALUE self; +readline_s_vi_editing_mode(VALUE self) { #ifdef HAVE_RL_VI_EDITING_MODE rb_secure(4); @@ -238,8 +223,7 @@ readline_s_vi_editing_mode(self) } static VALUE -readline_s_emacs_editing_mode(self) - VALUE self; +readline_s_emacs_editing_mode(VALUE self) { #ifdef HAVE_RL_EMACS_EDITING_MODE rb_secure(4); @@ -252,8 +236,7 @@ readline_s_emacs_editing_mode(self) } static VALUE -readline_s_set_completion_append_character(self, str) - VALUE self, str; +readline_s_set_completion_append_character(VALUE self, VALUE str) { #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER rb_secure(4); @@ -276,8 +259,7 @@ readline_s_set_completion_append_character(self, str) } static VALUE -readline_s_get_completion_append_character(self) - VALUE self; +readline_s_get_completion_append_character(VALUE self) { #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER VALUE str; @@ -296,8 +278,7 @@ readline_s_get_completion_append_character(self) } static VALUE -readline_s_set_basic_word_break_characters(self, str) - VALUE self, str; +readline_s_set_basic_word_break_characters(VALUE self, VALUE str) { #ifdef HAVE_RL_BASIC_WORD_BREAK_CHARACTERS static char *basic_word_break_characters = NULL; @@ -323,8 +304,7 @@ readline_s_set_basic_word_break_characters(self, str) } static VALUE -readline_s_get_basic_word_break_characters(self, str) - VALUE self, str; +readline_s_get_basic_word_break_characters(VALUE self, VALUE str) { #ifdef HAVE_RL_BASIC_WORD_BREAK_CHARACTERS rb_secure(4); @@ -338,8 +318,7 @@ readline_s_get_basic_word_break_characters(self, str) } static VALUE -readline_s_set_completer_word_break_characters(self, str) - VALUE self, str; +readline_s_set_completer_word_break_characters(VALUE self, VALUE str) { #ifdef HAVE_RL_COMPLETER_WORD_BREAK_CHARACTERS static char *completer_word_break_characters = NULL; @@ -365,8 +344,7 @@ readline_s_set_completer_word_break_characters(self, str) } static VALUE -readline_s_get_completer_word_break_characters(self, str) - VALUE self, str; +readline_s_get_completer_word_break_characters(VALUE self, VALUE str) { #ifdef HAVE_RL_COMPLETER_WORD_BREAK_CHARACTERS rb_secure(4); @@ -380,8 +358,7 @@ readline_s_get_completer_word_break_characters(self, str) } static VALUE -readline_s_set_basic_quote_characters(self, str) - VALUE self, str; +readline_s_set_basic_quote_characters(VALUE self, VALUE str) { #ifdef HAVE_RL_BASIC_QUOTE_CHARACTERS static char *basic_quote_characters = NULL; @@ -408,8 +385,7 @@ readline_s_set_basic_quote_characters(self, str) } static VALUE -readline_s_get_basic_quote_characters(self, str) - VALUE self, str; +readline_s_get_basic_quote_characters(VALUE self, VALUE str) { #ifdef HAVE_RL_BASIC_QUOTE_CHARACTERS rb_secure(4); @@ -423,8 +399,7 @@ readline_s_get_basic_quote_characters(self, str) } static VALUE -readline_s_set_completer_quote_characters(self, str) - VALUE self, str; +readline_s_set_completer_quote_characters(VALUE self, VALUE str) { #ifdef HAVE_RL_COMPLETER_QUOTE_CHARACTERS static char *completer_quote_characters = NULL; @@ -451,8 +426,7 @@ readline_s_set_completer_quote_characters(self, str) } static VALUE -readline_s_get_completer_quote_characters(self, str) - VALUE self, str; +readline_s_get_completer_quote_characters(VALUE self, VALUE str) { #ifdef HAVE_RL_COMPLETER_QUOTE_CHARACTERS rb_secure(4); @@ -466,8 +440,7 @@ readline_s_get_completer_quote_characters(self, str) } static VALUE -readline_s_set_filename_quote_characters(self, str) - VALUE self, str; +readline_s_set_filename_quote_characters(VALUE self, VALUE str) { #ifdef HAVE_RL_FILENAME_QUOTE_CHARACTERS static char *filename_quote_characters = NULL; @@ -494,8 +467,7 @@ readline_s_set_filename_quote_characters(self, str) } static VALUE -readline_s_get_filename_quote_characters(self, str) - VALUE self, str; +readline_s_get_filename_quote_characters(VALUE self, VALUE str) { #ifdef HAVE_RL_FILENAME_QUOTE_CHARACTERS rb_secure(4); @@ -509,16 +481,13 @@ readline_s_get_filename_quote_characters(self, str) } static VALUE -hist_to_s(self) - VALUE self; +hist_to_s(VALUE self) { return rb_str_new2("HISTORY"); } static VALUE -hist_get(self, index) - VALUE self; - VALUE index; +hist_get(VALUE self, VALUE index) { HIST_ENTRY *entry; int i; @@ -536,10 +505,7 @@ hist_get(self, index) } static VALUE -hist_set(self, index, str) - VALUE self; - VALUE index; - VALUE str; +hist_set(VALUE self, VALUE index, VALUE str) { #ifdef HAVE_REPLACE_HISTORY_ENTRY HIST_ENTRY *entry; @@ -563,9 +529,7 @@ hist_set(self, index, str) } static VALUE -hist_push(self, str) - VALUE self; - VALUE str; +hist_push(VALUE self, VALUE str) { rb_secure(4); SafeStringValue(str); @@ -574,10 +538,7 @@ hist_push(self, str) } static VALUE -hist_push_method(argc, argv, self) - int argc; - VALUE *argv; - VALUE self; +hist_push_method(int argc, VALUE *argv, VALUE self) { VALUE str; @@ -591,8 +552,7 @@ hist_push_method(argc, argv, self) } static VALUE -rb_remove_history(index) - int index; +rb_remove_history(int index) { #ifdef HAVE_REMOVE_HISTORY HIST_ENTRY *entry; @@ -614,8 +574,7 @@ rb_remove_history(index) } static VALUE -hist_pop(self) - VALUE self; +hist_pop(VALUE self) { rb_secure(4); if (history_length > 0) { @@ -626,8 +585,7 @@ hist_pop(self) } static VALUE -hist_shift(self) - VALUE self; +hist_shift(VALUE self) { rb_secure(4); if (history_length > 0) { @@ -638,8 +596,7 @@ hist_shift(self) } static VALUE -hist_each(self) - VALUE self; +hist_each(VALUE self) { HIST_ENTRY *entry; int i; @@ -655,25 +612,21 @@ hist_each(self) } static VALUE -hist_length(self) - VALUE self; +hist_length(VALUE self) { rb_secure(4); return INT2NUM(history_length); } static VALUE -hist_empty_p(self) - VALUE self; +hist_empty_p(VALUE self) { rb_secure(4); return history_length == 0 ? Qtrue : Qfalse; } static VALUE -hist_delete_at(self, index) - VALUE self; - VALUE index; +hist_delete_at(VALUE self, VALUE index) { int i; @@ -688,9 +641,7 @@ hist_delete_at(self, index) } static VALUE -filename_completion_proc_call(self, str) - VALUE self; - VALUE str; +filename_completion_proc_call(VALUE self, VALUE str) { VALUE result; char **matches; @@ -715,9 +666,7 @@ filename_completion_proc_call(self, str) } static VALUE -username_completion_proc_call(self, str) - VALUE self; - VALUE str; +username_completion_proc_call(VALUE self, VALUE str) { VALUE result; char **matches; diff --git a/ext/ripper/eventids2.c b/ext/ripper/eventids2.c index 88d7856202..18d803873c 100644 --- a/ext/ripper/eventids2.c +++ b/ext/ripper/eventids2.c @@ -265,8 +265,7 @@ static struct token_assoc { }; static ID -ripper_token2eventid(tok) - int tok; +ripper_token2eventid(int tok) { struct token_assoc *a; diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index 60333a1ff9..a1beaae375 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -489,8 +489,7 @@ strio_eof(self) /* :nodoc: */ static VALUE -strio_copy(copy, orig) - VALUE copy, orig; +strio_copy(VALUE copy, VALUE orig) { struct StringIO *ptr; @@ -559,10 +558,7 @@ strio_set_lineno(self, lineno) * and _mode_ (see StringIO#new). */ static VALUE -strio_reopen(argc, argv, self) - int argc; - VALUE *argv; - VALUE self; +strio_reopen(int argc, VALUE *argv, VALUE self) { if (!OBJ_TAINTED(self)) rb_secure(4); if (argc == 1 && TYPE(*argv) != T_STRING) { @@ -717,9 +713,7 @@ strio_getc(self) } static void -strio_extend(ptr, pos, len) - struct StringIO *ptr; - long pos, len; +strio_extend(struct StringIO *ptr, long pos, long len) { long olen; @@ -1149,10 +1143,7 @@ strio_read(argc, argv, self) * returning +nil+, as well as IO#sysread does. */ static VALUE -strio_sysread(argc, argv, self) - int argc; - VALUE *argv; - VALUE self; +strio_sysread(int argc, VALUE *argv, VALUE self) { VALUE val = strio_read(argc, argv, self); if (NIL_P(val) || RSTRING(val)->len == 0) { diff --git a/ext/strscan/strscan.c b/ext/strscan/strscan.c index d9d58fdcfc..913c6b53c1 100644 --- a/ext/strscan/strscan.c +++ b/ext/strscan/strscan.c @@ -263,8 +263,7 @@ strscan_s_mustc(self) * Reset the scan pointer (index 0) and clear matching data. */ static VALUE -strscan_reset(self) - VALUE self; +strscan_reset(VALUE self) { struct strscanner *p; @@ -600,8 +599,7 @@ strscan_scan_until(self, re) * s.exist? /e/ # -> nil */ static VALUE -strscan_exist_p(self, re) - VALUE self, re; +strscan_exist_p(VALUE self, VALUE re) { return strscan_do_scan(self, re, 0, 0, 0); } @@ -962,8 +960,7 @@ strscan_matched_size(self) * This method is obsolete; use #matched_size instead. */ static VALUE -strscan_matchedsize(self) - VALUE self; +strscan_matchedsize(VALUE self) { rb_warning("StringScanner#matchedsize is obsolete; use #matched_size instead"); return strscan_matched_size(self); @@ -1084,8 +1081,7 @@ strscan_rest_size(self) * This method is obsolete; use #rest_size instead. */ static VALUE -strscan_restsize(self) - VALUE self; +strscan_restsize(VALUE self) { rb_warning("StringScanner#restsize is obsolete; use #rest_size instead"); return strscan_rest_size(self); diff --git a/ext/syck/emitter.c b/ext/syck/emitter.c index f8d7b548a9..f5c6c3c4bd 100644 --- a/ext/syck/emitter.c +++ b/ext/syck/emitter.c @@ -282,7 +282,7 @@ syck_emitter_clear( SyckEmitter *e ) * Raw write to the emitter buffer. */ void -syck_emitter_write( SyckEmitter *e, char *str, long len ) +syck_emitter_write( SyckEmitter *e, const char *str, long len ) { long at; ASSERT( str != NULL ) @@ -438,7 +438,7 @@ end_emit: * and the implicit tag which would be assigned to this node. If a tag is * required, write the tag. */ -void syck_emit_tag( SyckEmitter *e, char *tag, char *ignore ) +void syck_emit_tag( SyckEmitter *e, const char *tag, const char *ignore ) { SyckLevel *lvl; if ( tag == NULL ) return; @@ -457,7 +457,7 @@ void syck_emit_tag( SyckEmitter *e, char *tag, char *ignore ) int skip = 4 + strlen( YAML_DOMAIN ) + 1; syck_emitter_write( e, tag + skip, taglen - skip ); } else { - char *subd = tag + 4; + const char *subd = tag + 4; while ( *subd != ':' && *subd != '\0' ) subd++; if ( *subd == ':' ) { if ( subd - tag > ( strlen( YAML_DOMAIN ) + 5 ) && @@ -559,7 +559,7 @@ syck_scan_scalar( int req_width, char *cursor, long len ) } if ( ( cursor[0] == '-' || cursor[0] == ':' || cursor[0] == '?' || cursor[0] == ',' ) && - ( cursor[1] == ' ' || cursor[1] == '\n' || len == 1 ) ) + ( len == 1 || cursor[1] == ' ' || cursor[1] == '\n' ) ) { flags |= SCAN_INDIC_S; } @@ -1221,7 +1221,7 @@ syck_emitter_mark_node( SyckEmitter *e, st_data_t n ) if ( ! st_lookup( e->anchors, (st_data_t)oid, (st_data_t *)&anchor_name ) ) { int idx = 0; - char *anc = ( e->anchor_format == NULL ? DEFAULT_ANCHOR_FORMAT : e->anchor_format ); + const char *anc = ( e->anchor_format == NULL ? DEFAULT_ANCHOR_FORMAT : e->anchor_format ); /* * Second time hitting this object, let's give it an anchor diff --git a/ext/syck/handler.c b/ext/syck/handler.c index 56fe838fbd..b04c4e3c0e 100644 --- a/ext/syck/handler.c +++ b/ext/syck/handler.c @@ -155,7 +155,7 @@ syck_xprivate( char *type_id, int type_len ) } char * -syck_taguri( char *domain, char *type_id, int type_len ) +syck_taguri( const char *domain, const char *type_id, int type_len ) { char *uri = S_ALLOC_N( char, strlen( domain ) + type_len + 14 ); uri[0] = '\0'; diff --git a/ext/syck/implicit.c b/ext/syck/implicit.c index d356faf7d9..cfd5d7b3e6 100644 --- a/ext/syck/implicit.c +++ b/ext/syck/implicit.c @@ -1585,7 +1585,7 @@ yy201: ++YYCURSOR; /* Remove ending fragment and compare types */ int -syck_tagcmp( char *tag1, char *tag2 ) +syck_tagcmp( const char *tag1, const char *tag2 ) { if ( tag1 == tag2 ) return 1; if ( tag1 == NULL || tag2 == NULL ) return 0; diff --git a/ext/syck/node.c b/ext/syck/node.c index 28fc78c077..cbc2adb6c5 100644 --- a/ext/syck/node.c +++ b/ext/syck/node.c @@ -100,13 +100,13 @@ syck_alloc_str() } SyckNode * -syck_new_str( char *str, enum scalar_style style ) +syck_new_str( const char *str, enum scalar_style style ) { return syck_new_str2( str, strlen( str ), style ); } SyckNode * -syck_new_str2( char *str, long len, enum scalar_style style ) +syck_new_str2( const char *str, long len, enum scalar_style style ) { SyckNode *n; diff --git a/ext/syck/syck.c b/ext/syck/syck.c index 24a56a5e48..20b124ab28 100644 --- a/ext/syck/syck.c +++ b/ext/syck/syck.c @@ -32,7 +32,7 @@ syck_assert( char *file_name, unsigned line_num ) * Allocates and copies a string */ char * -syck_strndup( char *buf, long len ) +syck_strndup( const char *buf, long len ) { char *new = S_ALLOC_N( char, len + 1 ); S_MEMZERO( new, char, len + 1 ); diff --git a/ext/syck/syck.h b/ext/syck/syck.h index c49f740173..eb91b242c3 100644 --- a/ext/syck/syck.h +++ b/ext/syck/syck.h @@ -346,8 +346,8 @@ void syck_hdlr_remove_anchor( SyckParser *, char * ); SyckNode *syck_hdlr_get_anchor( SyckParser *, char * ); void syck_add_transfer( char *, SyckNode *, int ); char *syck_xprivate( char *, int ); -char *syck_taguri( char *, char *, int ); -int syck_tagcmp( char *, char * ); +char *syck_taguri( const char *, const char *, int ); +int syck_tagcmp( const char *, const char * ); int syck_add_sym( SyckParser *, char * ); int syck_lookup_sym( SyckParser *, SYMID, char ** ); int syck_try_implicit( SyckNode * ); @@ -358,7 +358,7 @@ char *syck_match_implicit( char *, size_t ); /* * API prototypes */ -char *syck_strndup( char *, long ); +char *syck_strndup( const char *, long ); long syck_io_file_read( char *, SyckIoFile *, long, long ); long syck_io_str_read( char *, SyckIoStr *, long, long ); char *syck_base64enc( char *, long ); @@ -370,7 +370,7 @@ void syck_output_handler( SyckEmitter *, SyckOutputHandler ); void syck_emitter_handler( SyckEmitter *, SyckEmitterHandler ); void syck_free_emitter( SyckEmitter * ); void syck_emitter_clear( SyckEmitter * ); -void syck_emitter_write( SyckEmitter *, char *, long ); +void syck_emitter_write( SyckEmitter *, const char *, long ); void syck_emitter_escape( SyckEmitter *, char *, long ); void syck_emitter_flush( SyckEmitter *, long ); void syck_emit( SyckEmitter *, st_data_t ); @@ -383,7 +383,7 @@ void syck_emit_seq( SyckEmitter *, char *, enum seq_style ); void syck_emit_item( SyckEmitter *, st_data_t ); void syck_emit_map( SyckEmitter *, char *, enum map_style ); void syck_emit_end( SyckEmitter * ); -void syck_emit_tag( SyckEmitter *, char *, char * ); +void syck_emit_tag( SyckEmitter *, const char *, const char * ); void syck_emit_indent( SyckEmitter * ); SyckLevel *syck_emitter_current_level( SyckEmitter * ); SyckLevel *syck_emitter_parent_level( SyckEmitter * ); @@ -421,8 +421,8 @@ SyckNode *syck_alloc_seq(); SyckNode *syck_alloc_str(); void syck_free_node( SyckNode * ); void syck_free_members( SyckNode * ); -SyckNode *syck_new_str( char *, enum scalar_style ); -SyckNode *syck_new_str2( char *, long, enum scalar_style ); +SyckNode *syck_new_str( const char *, enum scalar_style ); +SyckNode *syck_new_str2( const char *, long, enum scalar_style ); void syck_replace_str( SyckNode *, char *, enum scalar_style ); void syck_replace_str2( SyckNode *, char *, long, enum scalar_style ); void syck_str_blow_away_commas( SyckNode * ); diff --git a/ext/syck/yaml2byte.c b/ext/syck/yaml2byte.c index 61cd8c8eac..821a3cd5b5 100644 --- a/ext/syck/yaml2byte.c +++ b/ext/syck/yaml2byte.c @@ -145,6 +145,7 @@ syck_yaml2byte_handler(p, n) strcat( type_tag, "!" ); strcat( type_tag, n->type_id ); bytestring_append( val, YAMLBYTE_TRANSFER, type_tag, NULL); + S_FREE(type_tag); } } switch (n->kind) diff --git a/ext/tk/tcltklib.c b/ext/tk/tcltklib.c index e43b98e2c1..9a64c27870 100644 --- a/ext/tk/tcltklib.c +++ b/ext/tk/tcltklib.c @@ -6217,7 +6217,11 @@ lib_fromUTF8_core(ip_obj, src, encodename) char *s; int len; +<<<<<<< tcltklib.c + StringValue(str); +======= StringValue(str); +>>>>>>> 1.45 s = Tcl_GetByteArrayFromObj(Tcl_NewStringObj(RSTRING(str)->ptr, RSTRING(str)->len), &len); diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index 822b2a5bee..0be5aa9aef 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -197,9 +197,7 @@ static VALUE cZError, cStreamEnd, cNeedDict; static VALUE cStreamError, cDataError, cMemError, cBufError, cVersionError; static void -raise_zlib_error(err, msg) - int err; - const char *msg; +raise_zlib_error(int err, const char *msg) { VALUE exc; @@ -247,8 +245,7 @@ raise_zlib_error(err, msg) /*--- Warning (in finalizer) ---*/ static void -finalizer_warn(msg) - const char *msg; +finalizer_warn(const char *msg) { fprintf(stderr, "zlib(finalizer): %s\n", msg); } @@ -260,8 +257,7 @@ finalizer_warn(msg) * Returns the string which represents the version of zlib library. */ static VALUE -rb_zlib_version(klass) - VALUE klass; +rb_zlib_version(VALUE klass) { VALUE str; @@ -311,10 +307,7 @@ do_checksum(argc, argv, func) * FIXME: expression. */ static VALUE -rb_zlib_adler32(argc, argv, klass) - int argc; - VALUE *argv; - VALUE klass; +rb_zlib_adler32(int argc, VALUE *argv, VALUE klass) { return do_checksum(argc, argv, adler32); } @@ -329,10 +322,7 @@ rb_zlib_adler32(argc, argv, klass) * FIXME: expression. */ static VALUE -rb_zlib_crc32(argc, argv, klass) - int argc; - VALUE *argv; - VALUE klass; +rb_zlib_crc32(int argc, VALUE *argv, VALUE klass) { return do_checksum(argc, argv, crc32); } @@ -341,8 +331,7 @@ rb_zlib_crc32(argc, argv, klass) * Returns the table for calculating CRC checksum as an array. */ static VALUE -rb_zlib_crc_table(obj) - VALUE obj; +rb_zlib_crc_table(VALUE obj) { const unsigned long *crctbl; VALUE dst; @@ -401,24 +390,19 @@ static const struct zstream_funcs inflate_funcs = { static voidpf -zlib_mem_alloc(opaque, items, size) - voidpf opaque; - uInt items, size; +zlib_mem_alloc(voidpf opaque, uInt items, uInt size) { return xmalloc(items * size); } static void -zlib_mem_free(opaque, address) - voidpf opaque, address; +zlib_mem_free(voidpf opaque, voidpf address) { free(address); } static void -zstream_init(z, func) - struct zstream *z; - const struct zstream_funcs *func; +zstream_init(struct zstream *z, const struct zstream_funcs *func) { z->flags = 0; z->buf = Qnil; @@ -439,8 +423,7 @@ zstream_init(z, func) #define zstream_init_inflate(z) zstream_init((z), &inflate_funcs) static void -zstream_expand_buffer(z) - struct zstream *z; +zstream_expand_buffer(struct zstream *z) { long inc; @@ -472,9 +455,7 @@ zstream_expand_buffer(z) } static void -zstream_expand_buffer_into(z, size) - struct zstream *z; - int size; +zstream_expand_buffer_into(struct zstream *z, int size) { if (NIL_P(z->buf)) { /* I uses rb_str_new here not rb_str_buf_new because @@ -493,10 +474,7 @@ zstream_expand_buffer_into(z, size) } static void -zstream_append_buffer(z, src, len) - struct zstream *z; - const Bytef *src; - int len; +zstream_append_buffer(struct zstream *z, const Bytef *src, int len) { if (NIL_P(z->buf)) { z->buf = rb_str_buf_new(len); @@ -529,8 +507,7 @@ zstream_append_buffer(z, src, len) zstream_append_buffer((z),(Bytef*)RSTRING(v)->ptr,RSTRING(v)->len) static VALUE -zstream_detach_buffer(z) - struct zstream *z; +zstream_detach_buffer(struct zstream *z) { VALUE dst; @@ -551,9 +528,7 @@ zstream_detach_buffer(z) } static VALUE -zstream_shift_buffer(z, len) - struct zstream *z; - int len; +zstream_shift_buffer(struct zstream *z, int len) { VALUE dst; @@ -576,9 +551,7 @@ zstream_shift_buffer(z, len) } static void -zstream_buffer_ungetc(z, c) - struct zstream *z; - int c; +zstream_buffer_ungetc(struct zstream *z, int c) { if (NIL_P(z->buf) || RSTRING(z->buf)->len - z->buf_filled == 0) { zstream_expand_buffer(z); @@ -594,10 +567,7 @@ zstream_buffer_ungetc(z, c) } static void -zstream_append_input(z, src, len) - struct zstream *z; - const Bytef *src; - unsigned int len; +zstream_append_input(struct zstream *z, const Bytef *src, unsigned int len) { if (len <= 0) return; @@ -615,9 +585,7 @@ zstream_append_input(z, src, len) zstream_append_input((z), (Bytef*)RSTRING(v)->ptr, RSTRING(v)->len) static void -zstream_discard_input(z, len) - struct zstream *z; - unsigned int len; +zstream_discard_input(struct zstream *z, unsigned int len) { if (NIL_P(z->input) || RSTRING(z->input)->len <= len) { z->input = Qnil; @@ -630,15 +598,13 @@ zstream_discard_input(z, len) } static void -zstream_reset_input(z) - struct zstream *z; +zstream_reset_input(struct zstream *z) { z->input = Qnil; } static void -zstream_passthrough_input(z) - struct zstream *z; +zstream_passthrough_input(struct zstream *z) { if (!NIL_P(z->input)) { zstream_append_buffer2(z, z->input); @@ -647,8 +613,7 @@ zstream_passthrough_input(z) } static VALUE -zstream_detach_input(z) - struct zstream *z; +zstream_detach_input(struct zstream *z) { VALUE dst; @@ -665,8 +630,7 @@ zstream_detach_input(z) } static void -zstream_reset(z) - struct zstream *z; +zstream_reset(struct zstream *z) { int err; @@ -683,8 +647,7 @@ zstream_reset(z) } static VALUE -zstream_end(z) - struct zstream *z; +zstream_end(struct zstream *z) { int err; @@ -707,11 +670,7 @@ zstream_end(z) } static void -zstream_run(z, src, len, flush) - struct zstream *z; - Bytef *src; - uInt len; - int flush; +zstream_run(struct zstream *z, Bytef *src, uInt len, int flush) { uInt n; int err; @@ -773,10 +732,7 @@ zstream_run(z, src, len, flush) } static VALUE -zstream_sync(z, src, len) - struct zstream *z; - Bytef *src; - uInt len; +zstream_sync(struct zstream *z, Bytef *src, uInt len) { VALUE rest; int err; @@ -815,16 +771,14 @@ zstream_sync(z, src, len) } static void -zstream_mark(z) - struct zstream *z; +zstream_mark(struct zstream *z) { rb_gc_mark(z->buf); rb_gc_mark(z->input); } static void -zstream_finalize(z) - struct zstream *z; +zstream_finalize(struct zstream *z) { int err = z->func->end(&z->stream); if (err == Z_STREAM_ERROR) @@ -834,8 +788,7 @@ zstream_finalize(z) } static void -zstream_free(z) - struct zstream *z; +zstream_free(struct zstream *z) { if (ZSTREAM_IS_READY(z)) { zstream_finalize(z); @@ -844,9 +797,7 @@ zstream_free(z) } static VALUE -zstream_new(klass, funcs) - VALUE klass; - const struct zstream_funcs *funcs; +zstream_new(VALUE klass, const struct zstream_funcs *funcs) { VALUE obj; struct zstream *z; @@ -861,8 +812,7 @@ zstream_new(klass, funcs) #define zstream_inflate_new(klass) zstream_new((klass), &inflate_funcs) static struct zstream * -get_zstream(obj) - VALUE obj; +get_zstream(VALUE obj) { struct zstream *z; @@ -942,8 +892,7 @@ get_zstream(obj) * exception. */ static VALUE -rb_zstream_end(obj) - VALUE obj; +rb_zstream_end(VALUE obj) { zstream_end(get_zstream(obj)); return Qnil; @@ -954,8 +903,7 @@ rb_zstream_end(obj) * are discarded. */ static VALUE -rb_zstream_reset(obj) - VALUE obj; +rb_zstream_reset(VALUE obj) { zstream_reset(get_zstream(obj)); return Qnil; @@ -966,8 +914,7 @@ rb_zstream_reset(obj) * Zlib::Inflate#finish for details of this behavior. */ static VALUE -rb_zstream_finish(obj) - VALUE obj; +rb_zstream_finish(VALUE obj) { struct zstream *z = get_zstream(obj); VALUE dst; @@ -983,8 +930,7 @@ rb_zstream_finish(obj) * Flushes input buffer and returns all data in that buffer. */ static VALUE -rb_zstream_flush_next_in(obj) - VALUE obj; +rb_zstream_flush_next_in(VALUE obj) { struct zstream *z; VALUE dst; @@ -999,8 +945,7 @@ rb_zstream_flush_next_in(obj) * Flushes output buffer and returns all data in that buffer. */ static VALUE -rb_zstream_flush_next_out(obj) - VALUE obj; +rb_zstream_flush_next_out(VALUE obj) { struct zstream *z; VALUE dst; @@ -1016,8 +961,7 @@ rb_zstream_flush_next_out(obj) * space is allocated automatically, this method returns 0 normally. */ static VALUE -rb_zstream_avail_out(obj) - VALUE obj; +rb_zstream_avail_out(VALUE obj) { struct zstream *z; Data_Get_Struct(obj, struct zstream, z); @@ -1031,8 +975,7 @@ rb_zstream_avail_out(obj) * method. */ static VALUE -rb_zstream_set_avail_out(obj, size) - VALUE obj, size; +rb_zstream_set_avail_out(VALUE obj, VALUE size) { struct zstream *z = get_zstream(obj); @@ -1045,8 +988,7 @@ rb_zstream_set_avail_out(obj, size) * Returns bytes of data in the input buffer. Normally, returns 0. */ static VALUE -rb_zstream_avail_in(obj) - VALUE obj; +rb_zstream_avail_in(VALUE obj) { struct zstream *z; Data_Get_Struct(obj, struct zstream, z); @@ -1057,8 +999,7 @@ rb_zstream_avail_in(obj) * Returns the total bytes of the input data to the stream. FIXME */ static VALUE -rb_zstream_total_in(obj) - VALUE obj; +rb_zstream_total_in(VALUE obj) { return rb_uint2inum(get_zstream(obj)->stream.total_in); } @@ -1067,8 +1008,7 @@ rb_zstream_total_in(obj) * Returns the total bytes of the output data from the stream. FIXME */ static VALUE -rb_zstream_total_out(obj) - VALUE obj; +rb_zstream_total_out(VALUE obj) { return rb_uint2inum(get_zstream(obj)->stream.total_out); } @@ -1079,8 +1019,7 @@ rb_zstream_total_out(obj) * Zlib::UNKNOWN. */ static VALUE -rb_zstream_data_type(obj) - VALUE obj; +rb_zstream_data_type(VALUE obj) { return INT2FIX(get_zstream(obj)->stream.data_type); } @@ -1089,8 +1028,7 @@ rb_zstream_data_type(obj) * Returns the adler-32 checksum. */ static VALUE -rb_zstream_adler(obj) - VALUE obj; +rb_zstream_adler(VALUE obj) { return rb_uint2inum(get_zstream(obj)->stream.adler); } @@ -1099,8 +1037,7 @@ rb_zstream_adler(obj) * Returns true if the stream is finished. */ static VALUE -rb_zstream_finished_p(obj) - VALUE obj; +rb_zstream_finished_p(VALUE obj) { return ZSTREAM_IS_FINISHED(get_zstream(obj)) ? Qtrue : Qfalse; } @@ -1109,8 +1046,7 @@ rb_zstream_finished_p(obj) * Returns true if the stream is closed. */ static VALUE -rb_zstream_closed_p(obj) - VALUE obj; +rb_zstream_closed_p(VALUE obj) { struct zstream *z; Data_Get_Struct(obj, struct zstream, z); @@ -1139,8 +1075,7 @@ rb_zstream_closed_p(obj) static VALUE -rb_deflate_s_allocate(klass) - VALUE klass; +rb_deflate_s_allocate(VALUE klass) { return zstream_deflate_new(klass); } @@ -1155,10 +1090,7 @@ rb_deflate_s_allocate(klass) * TODO: document better! */ static VALUE -rb_deflate_initialize(argc, argv, obj) - int argc; - VALUE *argv; - VALUE obj; +rb_deflate_initialize(int argc, VALUE *argv, VALUE obj) { struct zstream *z; VALUE level, wbits, memlevel, strategy; @@ -1182,8 +1114,7 @@ rb_deflate_initialize(argc, argv, obj) * Duplicates the deflate stream. */ static VALUE -rb_deflate_init_copy(self, orig) - VALUE self, orig; +rb_deflate_init_copy(VALUE self, VALUE orig) { struct zstream *z1 = get_zstream(self); struct zstream *z2 = get_zstream(orig); @@ -1199,8 +1130,7 @@ rb_deflate_init_copy(self, orig) } static VALUE -deflate_run(args) - VALUE args; +deflate_run(VALUE args) { struct zstream *z = (struct zstream*)((VALUE*)args)[0]; VALUE src = ((VALUE*)args)[1]; @@ -1230,10 +1160,7 @@ deflate_run(args) * */ static VALUE -rb_deflate_s_deflate(argc, argv, klass) - int argc; - VALUE *argv; - VALUE klass; +rb_deflate_s_deflate(int argc, VALUE *argv, VALUE klass) { struct zstream z; VALUE src, level, dst, args[2]; @@ -1259,10 +1186,7 @@ rb_deflate_s_deflate(argc, argv, klass) } static void -do_deflate(z, src, flush) - struct zstream *z; - VALUE src; - int flush; +do_deflate(struct zstream *z, VALUE src, int flush) { if (NIL_P(src)) { zstream_run(z, (Bytef*)"", 0, Z_FINISH); @@ -1289,10 +1213,7 @@ do_deflate(z, src, flush) * TODO: document better! */ static VALUE -rb_deflate_deflate(argc, argv, obj) - int argc; - VALUE *argv; - VALUE obj; +rb_deflate_deflate(int argc, VALUE *argv, VALUE obj) { struct zstream *z = get_zstream(obj); VALUE src, flush, dst; @@ -1314,8 +1235,7 @@ rb_deflate_deflate(argc, argv, obj) * preserved in output buffer. */ static VALUE -rb_deflate_addstr(obj, src) - VALUE obj, src; +rb_deflate_addstr(VALUE obj, VALUE src) { OBJ_INFECT(obj, src); do_deflate(get_zstream(obj), src, Z_NO_FLUSH); @@ -1332,10 +1252,7 @@ rb_deflate_addstr(obj, src) * TODO: document better! */ static VALUE -rb_deflate_flush(argc, argv, obj) - int argc; - VALUE *argv; - VALUE obj; +rb_deflate_flush(int argc, VALUE *argv, VALUE obj) { struct zstream *z = get_zstream(obj); VALUE v_flush, dst; @@ -1362,8 +1279,7 @@ rb_deflate_flush(argc, argv, obj) * TODO: document better! */ static VALUE -rb_deflate_params(obj, v_level, v_strategy) - VALUE obj, v_level, v_strategy; +rb_deflate_params(VALUE obj, VALUE v_level, VALUE v_strategy) { struct zstream *z = get_zstream(obj); int level, strategy; @@ -1395,8 +1311,7 @@ rb_deflate_params(obj, v_level, v_strategy) * TODO: document better! */ static VALUE -rb_deflate_set_dictionary(obj, dic) - VALUE obj, dic; +rb_deflate_set_dictionary(VALUE obj, VALUE dic) { struct zstream *z = get_zstream(obj); VALUE src = dic; @@ -1427,8 +1342,7 @@ rb_deflate_set_dictionary(obj, dic) static VALUE -rb_inflate_s_allocate(klass) - VALUE klass; +rb_inflate_s_allocate(VALUE klass) { return zstream_inflate_new(klass); } @@ -1442,10 +1356,7 @@ rb_inflate_s_allocate(klass) * TODO: document better! */ static VALUE -rb_inflate_initialize(argc, argv, obj) - int argc; - VALUE *argv; - VALUE obj; +rb_inflate_initialize(int argc, VALUE *argv, VALUE obj) { struct zstream *z; VALUE wbits; @@ -1464,8 +1375,7 @@ rb_inflate_initialize(argc, argv, obj) } static VALUE -inflate_run(args) - VALUE args; +inflate_run(VALUE args) { struct zstream *z = (struct zstream*)((VALUE*)args)[0]; VALUE src = ((VALUE*)args)[1]; @@ -1493,8 +1403,7 @@ inflate_run(args) * */ static VALUE -rb_inflate_s_inflate(obj, src) - VALUE obj, src; +rb_inflate_s_inflate(VALUE obj, VALUE src) { struct zstream z; VALUE dst, args[2]; @@ -1517,9 +1426,7 @@ rb_inflate_s_inflate(obj, src) } static void -do_inflate(z, src) - struct zstream *z; - VALUE src; +do_inflate(struct zstream *z, VALUE src) { if (NIL_P(src)) { zstream_run(z, (Bytef*)"", 0, Z_FINISH); @@ -1546,8 +1453,7 @@ do_inflate(z, src) * TODO: document better! */ static VALUE -rb_inflate_inflate(obj, src) - VALUE obj, src; +rb_inflate_inflate(VALUE obj, VALUE src) { struct zstream *z = get_zstream(obj); VALUE dst; @@ -1584,8 +1490,7 @@ rb_inflate_inflate(obj, src) * preserved in output buffer. */ static VALUE -rb_inflate_addstr(obj, src) - VALUE obj, src; +rb_inflate_addstr(VALUE obj, VALUE src) { struct zstream *z = get_zstream(obj); @@ -1616,8 +1521,7 @@ rb_inflate_addstr(obj, src) * following data of full flush point is preserved in the buffer. */ static VALUE -rb_inflate_sync(obj, src) - VALUE obj, src; +rb_inflate_sync(VALUE obj, VALUE src) { struct zstream *z = get_zstream(obj); @@ -1634,8 +1538,7 @@ rb_inflate_sync(obj, src) * :) */ static VALUE -rb_inflate_sync_point_p(obj) - VALUE obj; +rb_inflate_sync_point_p(VALUE obj) { struct zstream *z = get_zstream(obj); int err; @@ -1657,8 +1560,7 @@ rb_inflate_sync_point_p(obj) * TODO: document better! */ static VALUE -rb_inflate_set_dictionary(obj, dic) - VALUE obj, dic; +rb_inflate_set_dictionary(VALUE obj, VALUE dic) { struct zstream *z = get_zstream(obj); VALUE src = dic; @@ -1753,8 +1655,7 @@ struct gzfile { static void -gzfile_mark(gz) - struct gzfile *gz; +gzfile_mark(struct gzfile *gz) { rb_gc_mark(gz->io); rb_gc_mark(gz->orig_name); @@ -1763,8 +1664,7 @@ gzfile_mark(gz) } static void -gzfile_free(gz) - struct gzfile *gz; +gzfile_free(struct gzfile *gz) { struct zstream *z = &gz->z; @@ -1806,8 +1706,7 @@ gzfile_new(klass, funcs, endfunc) #define gzfile_reader_new(gz) gzfile_new((gz),&inflate_funcs,gzfile_reader_end) static void -gzfile_reset(gz) - struct gzfile *gz; +gzfile_reset(struct gzfile *gz) { zstream_reset(&gz->z); gz->crc = crc32(0, Z_NULL, 0); @@ -1816,9 +1715,7 @@ gzfile_reset(gz) } static void -gzfile_close(gz, closeflag) - struct gzfile *gz; - int closeflag; +gzfile_close(struct gzfile *gz, int closeflag) { VALUE io = gz->io; @@ -1832,8 +1729,7 @@ gzfile_close(gz, closeflag) } static void -gzfile_write_raw(gz) - struct gzfile *gz; +gzfile_write_raw(struct gzfile *gz) { VALUE str; @@ -1848,8 +1744,7 @@ gzfile_write_raw(gz) } static VALUE -gzfile_read_raw_partial(arg) - VALUE arg; +gzfile_read_raw_partial(VALUE arg) { struct gzfile *gz = (struct gzfile*)arg; VALUE str; @@ -1860,8 +1755,7 @@ gzfile_read_raw_partial(arg) } static VALUE -gzfile_read_raw_rescue(arg) - VALUE arg; +gzfile_read_raw_rescue(VALUE arg) { struct gzfile *gz = (struct gzfile*)arg; VALUE str = Qnil; @@ -1875,8 +1769,7 @@ gzfile_read_raw_rescue(arg) } static VALUE -gzfile_read_raw(gz) - struct gzfile *gz; +gzfile_read_raw(struct gzfile *gz) { return rb_rescue2(gzfile_read_raw_partial, (VALUE)gz, gzfile_read_raw_rescue, (VALUE)gz, @@ -1884,9 +1777,7 @@ gzfile_read_raw(gz) } static int -gzfile_read_raw_ensure(gz, size) - struct gzfile *gz; - int size; +gzfile_read_raw_ensure(struct gzfile *gz, int size) { VALUE str; @@ -1899,9 +1790,7 @@ gzfile_read_raw_ensure(gz, size) } static char * -gzfile_read_raw_until_zero(gz, offset) - struct gzfile *gz; - long offset; +gzfile_read_raw_until_zero(struct gzfile *gz, long offset) { VALUE str; char *p; @@ -1921,8 +1810,7 @@ gzfile_read_raw_until_zero(gz, offset) } static unsigned int -gzfile_get16(src) - const unsigned char *src; +gzfile_get16(const unsigned char *src) { unsigned int n; n = *(src++) & 0xff; @@ -1931,8 +1819,7 @@ gzfile_get16(src) } static unsigned long -gzfile_get32(src) - const unsigned char *src; +gzfile_get32(const unsigned char *src) { unsigned long n; n = *(src++) & 0xff; @@ -1943,9 +1830,7 @@ gzfile_get32(src) } static void -gzfile_set32(n, dst) - unsigned long n; - unsigned char *dst; +gzfile_set32(unsigned long n, unsigned char *dst) { *(dst++) = n & 0xff; *(dst++) = (n >> 8) & 0xff; @@ -1954,8 +1839,7 @@ gzfile_set32(n, dst) } static void -gzfile_make_header(gz) - struct gzfile *gz; +gzfile_make_header(struct gzfile *gz) { Bytef buf[10]; /* the size of gzip header */ unsigned char flags = 0, extraflags = 0; @@ -1999,8 +1883,7 @@ gzfile_make_header(gz) } static void -gzfile_make_footer(gz) - struct gzfile *gz; +gzfile_make_footer(struct gzfile *gz) { Bytef buf[8]; /* 8 is the size of gzip footer */ @@ -2011,8 +1894,7 @@ gzfile_make_footer(gz) } static void -gzfile_read_header(gz) - struct gzfile *gz; +gzfile_read_header(struct gzfile *gz) { const unsigned char *head; long len; @@ -2087,8 +1969,7 @@ gzfile_read_header(gz) } static void -gzfile_check_footer(gz) - struct gzfile *gz; +gzfile_check_footer(struct gzfile *gz) { unsigned long crc, length; @@ -2113,10 +1994,7 @@ gzfile_check_footer(gz) } static void -gzfile_write(gz, str, len) - struct gzfile *gz; - Bytef *str; - uInt len; +gzfile_write(struct gzfile *gz, Bytef *str, uInt len) { if (!(gz->z.flags & GZFILE_FLAG_HEADER_FINISHED)) { gzfile_make_header(gz); @@ -2131,8 +2009,7 @@ gzfile_write(gz, str, len) } static long -gzfile_read_more(gz) - struct gzfile *gz; +gzfile_read_more(struct gzfile *gz) { volatile VALUE str; @@ -2154,9 +2031,7 @@ gzfile_read_more(gz) } static void -gzfile_calc_crc(gz, str) - struct gzfile *gz; - VALUE str; +gzfile_calc_crc(struct gzfile *gz, VALUE str) { if (RSTRING(str)->len <= gz->ungetc) { gz->ungetc -= RSTRING(str)->len; @@ -2169,9 +2044,7 @@ gzfile_calc_crc(gz, str) } static VALUE -gzfile_read(gz, len) - struct gzfile *gz; - int len; +gzfile_read(struct gzfile *gz, int len) { VALUE dst; @@ -2197,10 +2070,7 @@ gzfile_read(gz, len) } static VALUE -gzfile_readpartial(gz, len, outbuf) - struct gzfile *gz; - int len; - VALUE outbuf; +gzfile_readpartial(struct gzfile *gz, int len, VALUE outbuf) { VALUE dst; @@ -2245,8 +2115,7 @@ gzfile_readpartial(gz, len, outbuf) } static VALUE -gzfile_read_all(gz) - struct gzfile *gz; +gzfile_read_all(struct gzfile *gz) { VALUE dst; @@ -2268,17 +2137,14 @@ gzfile_read_all(gz) } static void -gzfile_ungetc(gz, c) - struct gzfile *gz; - int c; +gzfile_ungetc(struct gzfile *gz, int c) { zstream_buffer_ungetc(&gz->z, c); gz->ungetc++; } static VALUE -gzfile_writer_end_run(arg) - VALUE arg; +gzfile_writer_end_run(VALUE arg) { struct gzfile *gz = (struct gzfile *)arg; @@ -2294,8 +2160,7 @@ gzfile_writer_end_run(arg) } static void -gzfile_writer_end(gz) - struct gzfile *gz; +gzfile_writer_end(struct gzfile *gz) { if (ZSTREAM_IS_CLOSING(&gz->z)) return; gz->z.flags |= ZSTREAM_FLAG_CLOSING; @@ -2304,8 +2169,7 @@ gzfile_writer_end(gz) } static VALUE -gzfile_reader_end_run(arg) - VALUE arg; +gzfile_reader_end_run(VALUE arg) { struct gzfile *gz = (struct gzfile *)arg; @@ -2318,8 +2182,7 @@ gzfile_reader_end_run(arg) } static void -gzfile_reader_end(gz) - struct gzfile *gz; +gzfile_reader_end(struct gzfile *gz) { if (ZSTREAM_IS_CLOSING(&gz->z)) return; gz->z.flags |= ZSTREAM_FLAG_CLOSING; @@ -2328,8 +2191,7 @@ gzfile_reader_end(gz) } static void -gzfile_reader_rewind(gz) - struct gzfile *gz; +gzfile_reader_rewind(struct gzfile *gz) { long n; @@ -2343,8 +2205,7 @@ gzfile_reader_rewind(gz) } static VALUE -gzfile_reader_get_unused(gz) - struct gzfile *gz; +gzfile_reader_get_unused(struct gzfile *gz) { VALUE str; @@ -2361,8 +2222,7 @@ gzfile_reader_get_unused(gz) } static struct gzfile * -get_gzfile(obj) - VALUE obj; +get_gzfile(VALUE obj) { struct gzfile *gz; @@ -2388,8 +2248,7 @@ get_gzfile(obj) static VALUE -gzfile_ensure_close(obj) - VALUE obj; +gzfile_ensure_close(VALUE obj) { struct gzfile *gz; @@ -2404,10 +2263,7 @@ gzfile_ensure_close(obj) * See Zlib::GzipReader#wrap and Zlib::GzipWriter#wrap. */ static VALUE -rb_gzfile_s_wrap(argc, argv, klass) - int argc; - VALUE *argv; - VALUE klass; +rb_gzfile_s_wrap(int argc, VALUE *argv, VALUE klass) { VALUE obj = rb_class_new_instance(argc, argv, klass); @@ -2423,11 +2279,7 @@ rb_gzfile_s_wrap(argc, argv, klass) * See Zlib::GzipReader#open and Zlib::GzipWriter#open. */ static VALUE -gzfile_s_open(argc, argv, klass, mode) - int argc; - VALUE *argv; - VALUE klass; - const char *mode; +gzfile_s_open(int argc, VALUE *argv, VALUE klass, const char *mode) { VALUE io, filename; @@ -2446,8 +2298,7 @@ gzfile_s_open(argc, argv, klass, mode) * Same as IO. */ static VALUE -rb_gzfile_to_io(obj) - VALUE obj; +rb_gzfile_to_io(VALUE obj) { return get_gzfile(obj)->io; } @@ -2456,8 +2307,7 @@ rb_gzfile_to_io(obj) * Returns CRC value of the uncompressed data. */ static VALUE -rb_gzfile_crc(obj) - VALUE obj; +rb_gzfile_crc(VALUE obj) { return rb_uint2inum(get_gzfile(obj)->crc); } @@ -2466,8 +2316,7 @@ rb_gzfile_crc(obj) * Returns last modification time recorded in the gzip file header. */ static VALUE -rb_gzfile_mtime(obj) - VALUE obj; +rb_gzfile_mtime(VALUE obj) { return rb_time_new(get_gzfile(obj)->mtime, (time_t)0); } @@ -2476,8 +2325,7 @@ rb_gzfile_mtime(obj) * Returns compression level. */ static VALUE -rb_gzfile_level(obj) - VALUE obj; +rb_gzfile_level(VALUE obj) { return INT2FIX(get_gzfile(obj)->level); } @@ -2486,8 +2334,7 @@ rb_gzfile_level(obj) * Returns OS code number recorded in the gzip file header. */ static VALUE -rb_gzfile_os_code(obj) - VALUE obj; +rb_gzfile_os_code(VALUE obj) { return INT2FIX(get_gzfile(obj)->os_code); } @@ -2497,8 +2344,7 @@ rb_gzfile_os_code(obj) * original filename is not present. */ static VALUE -rb_gzfile_orig_name(obj) - VALUE obj; +rb_gzfile_orig_name(VALUE obj) { VALUE str = get_gzfile(obj)->orig_name; if (!NIL_P(str)) { @@ -2513,8 +2359,7 @@ rb_gzfile_orig_name(obj) * is not present. */ static VALUE -rb_gzfile_comment(obj) - VALUE obj; +rb_gzfile_comment(VALUE obj) { VALUE str = get_gzfile(obj)->comment; if (!NIL_P(str)) { @@ -2528,8 +2373,7 @@ rb_gzfile_comment(obj) * ??? */ static VALUE -rb_gzfile_lineno(obj) - VALUE obj; +rb_gzfile_lineno(VALUE obj) { return INT2NUM(get_gzfile(obj)->lineno); } @@ -2538,8 +2382,7 @@ rb_gzfile_lineno(obj) * ??? */ static VALUE -rb_gzfile_set_lineno(obj, lineno) - VALUE obj, lineno; +rb_gzfile_set_lineno(VALUE obj, VALUE lineno) { struct gzfile *gz = get_gzfile(obj); gz->lineno = NUM2INT(lineno); @@ -2550,8 +2393,7 @@ rb_gzfile_set_lineno(obj, lineno) * ??? */ static VALUE -rb_gzfile_set_mtime(obj, mtime) - VALUE obj, mtime; +rb_gzfile_set_mtime(VALUE obj, VALUE mtime) { struct gzfile *gz = get_gzfile(obj); VALUE val; @@ -2574,8 +2416,7 @@ rb_gzfile_set_mtime(obj, mtime) * ??? */ static VALUE -rb_gzfile_set_orig_name(obj, str) - VALUE obj, str; +rb_gzfile_set_orig_name(VALUE obj, VALUE str) { struct gzfile *gz = get_gzfile(obj); VALUE s; @@ -2597,8 +2438,7 @@ rb_gzfile_set_orig_name(obj, str) * ??? */ static VALUE -rb_gzfile_set_comment(obj, str) - VALUE obj, str; +rb_gzfile_set_comment(VALUE obj, VALUE str) { struct gzfile *gz = get_gzfile(obj); VALUE s; @@ -2621,8 +2461,7 @@ rb_gzfile_set_comment(obj, str) * associated IO object. Returns the associated IO object. */ static VALUE -rb_gzfile_close(obj) - VALUE obj; +rb_gzfile_close(VALUE obj) { struct gzfile *gz = get_gzfile(obj); VALUE io; @@ -2638,8 +2477,7 @@ rb_gzfile_close(obj) * object. */ static VALUE -rb_gzfile_finish(obj) - VALUE obj; +rb_gzfile_finish(VALUE obj) { struct gzfile *gz = get_gzfile(obj); VALUE io; @@ -2653,8 +2491,7 @@ rb_gzfile_finish(obj) * Same as IO. */ static VALUE -rb_gzfile_closed_p(obj) - VALUE obj; +rb_gzfile_closed_p(VALUE obj) { struct gzfile *gz; Data_Get_Struct(obj, struct gzfile, gz); @@ -2665,8 +2502,7 @@ rb_gzfile_closed_p(obj) * ??? */ static VALUE -rb_gzfile_eof_p(obj) - VALUE obj; +rb_gzfile_eof_p(VALUE obj) { struct gzfile *gz = get_gzfile(obj); return GZFILE_IS_FINISHED(gz) ? Qtrue : Qfalse; @@ -2676,8 +2512,7 @@ rb_gzfile_eof_p(obj) * Same as IO. */ static VALUE -rb_gzfile_sync(obj) - VALUE obj; +rb_gzfile_sync(VALUE obj) { return (get_gzfile(obj)->z.flags & GZFILE_FLAG_SYNC) ? Qtrue : Qfalse; } @@ -2690,8 +2525,7 @@ rb_gzfile_sync(obj) * decreases sharply. */ static VALUE -rb_gzfile_set_sync(obj, mode) - VALUE obj, mode; +rb_gzfile_set_sync(VALUE obj, VALUE mode) { struct gzfile *gz = get_gzfile(obj); @@ -2708,8 +2542,7 @@ rb_gzfile_set_sync(obj, mode) * ??? */ static VALUE -rb_gzfile_total_in(obj) - VALUE obj; +rb_gzfile_total_in(VALUE obj) { return rb_uint2inum(get_gzfile(obj)->z.stream.total_in); } @@ -2718,8 +2551,7 @@ rb_gzfile_total_in(obj) * ??? */ static VALUE -rb_gzfile_total_out(obj) - VALUE obj; +rb_gzfile_total_out(VALUE obj) { struct gzfile *gz = get_gzfile(obj); return rb_uint2inum(gz->z.stream.total_out - gz->z.buf_filled); @@ -2756,8 +2588,7 @@ rb_gzfile_total_out(obj) */ static VALUE -rb_gzwriter_s_allocate(klass) - VALUE klass; +rb_gzwriter_s_allocate(VALUE klass) { return gzfile_writer_new(klass); } @@ -2770,10 +2601,7 @@ rb_gzwriter_s_allocate(klass) * this method are found in Zlib::GzipWriter.new and Zlib::GzipWriter#wrap. */ static VALUE -rb_gzwriter_s_open(argc, argv, klass) - int argc; - VALUE *argv; - VALUE klass; +rb_gzwriter_s_open(int argc, VALUE *argv, VALUE klass) { return gzfile_s_open(argc, argv, klass, "wb"); } @@ -2787,10 +2615,7 @@ rb_gzwriter_s_open(argc, argv, klass) * +write+ method that behaves same as write method in IO class. */ static VALUE -rb_gzwriter_initialize(argc, argv, obj) - int argc; - VALUE *argv; - VALUE obj; +rb_gzwriter_initialize(int argc, VALUE *argv, VALUE obj) { struct gzfile *gz; VALUE io, level, strategy; @@ -2820,10 +2645,7 @@ rb_gzwriter_initialize(argc, argv, obj) * +flush+ is omitted. It is no use giving flush Zlib::NO_FLUSH. */ static VALUE -rb_gzwriter_flush(argc, argv, obj) - int argc; - VALUE *argv; - VALUE obj; +rb_gzwriter_flush(int argc, VALUE *argv, VALUE obj) { struct gzfile *gz = get_gzfile(obj); VALUE v_flush; @@ -2847,8 +2669,7 @@ rb_gzwriter_flush(argc, argv, obj) * Same as IO. */ static VALUE -rb_gzwriter_write(obj, str) - VALUE obj, str; +rb_gzwriter_write(VALUE obj, VALUE str) { struct gzfile *gz = get_gzfile(obj); @@ -2863,8 +2684,7 @@ rb_gzwriter_write(obj, str) * Same as IO. */ static VALUE -rb_gzwriter_putc(obj, ch) - VALUE obj, ch; +rb_gzwriter_putc(VALUE obj, VALUE ch) { struct gzfile *gz = get_gzfile(obj); char c = NUM2CHR(ch); @@ -2955,8 +2775,7 @@ rb_gzwriter_putc(obj, ch) */ static VALUE -rb_gzreader_s_allocate(klass) - VALUE klass; +rb_gzreader_s_allocate(VALUE klass) { return gzfile_reader_new(klass); } @@ -2969,10 +2788,7 @@ rb_gzreader_s_allocate(klass) * are in Zlib::GzipReader.new and ZLib::GzipReader.wrap. */ static VALUE -rb_gzreader_s_open(argc, argv, klass) - int argc; - VALUE *argv; - VALUE klass; +rb_gzreader_s_open(int argc, VALUE *argv, VALUE klass) { return gzfile_s_open(argc, argv, klass, "rb"); } @@ -2988,8 +2804,7 @@ rb_gzreader_s_open(argc, argv, klass) * exception. */ static VALUE -rb_gzreader_initialize(obj, io) - VALUE obj, io; +rb_gzreader_initialize(VALUE obj, VALUE io) { struct gzfile *gz; int err; @@ -3013,8 +2828,7 @@ rb_gzreader_initialize(obj, io) * object. The associated IO object needs to respond to the +seek+ method. */ static VALUE -rb_gzreader_rewind(obj) - VALUE obj; +rb_gzreader_rewind(VALUE obj) { struct gzfile *gz = get_gzfile(obj); gzfile_reader_rewind(gz); @@ -3026,8 +2840,7 @@ rb_gzreader_rewind(obj) * +nil+ if the whole gzip file is not parsed yet. */ static VALUE -rb_gzreader_unused(obj) - VALUE obj; +rb_gzreader_unused(VALUE obj) { struct gzfile *gz; Data_Get_Struct(obj, struct gzfile, gz); @@ -3038,10 +2851,7 @@ rb_gzreader_unused(obj) * See Zlib::GzipReader documentation for a description. */ static VALUE -rb_gzreader_read(argc, argv, obj) - int argc; - VALUE *argv; - VALUE obj; +rb_gzreader_read(int argc, VALUE *argv, VALUE obj) { struct gzfile *gz = get_gzfile(obj); VALUE vlen; @@ -3070,10 +2880,7 @@ rb_gzreader_read(argc, argv, obj) * It raises EOFError on end of file. */ static VALUE -rb_gzreader_readpartial(argc, argv, obj) - int argc; - VALUE *argv; - VALUE obj; +rb_gzreader_readpartial(int argc, VALUE *argv, VALUE obj) { struct gzfile *gz = get_gzfile(obj); VALUE vlen, outbuf; @@ -3094,8 +2901,7 @@ rb_gzreader_readpartial(argc, argv, obj) * See Zlib::GzipReader documentation for a description. */ static VALUE -rb_gzreader_getc(obj) - VALUE obj; +rb_gzreader_getc(VALUE obj) { struct gzfile *gz = get_gzfile(obj); VALUE dst; @@ -3111,8 +2917,7 @@ rb_gzreader_getc(obj) * See Zlib::GzipReader documentation for a description. */ static VALUE -rb_gzreader_readchar(obj) - VALUE obj; +rb_gzreader_readchar(VALUE obj) { VALUE dst; dst = rb_gzreader_getc(obj); @@ -3126,8 +2931,7 @@ rb_gzreader_readchar(obj) * See Zlib::GzipReader documentation for a description. */ static VALUE -rb_gzreader_each_byte(obj) - VALUE obj; +rb_gzreader_each_byte(VALUE obj) { VALUE c; while (!NIL_P(c = rb_gzreader_getc(obj))) { @@ -3140,8 +2944,7 @@ rb_gzreader_each_byte(obj) * See Zlib::GzipReader documentation for a description. */ static VALUE -rb_gzreader_ungetc(obj, ch) - VALUE obj, ch; +rb_gzreader_ungetc(VALUE obj, VALUE ch) { struct gzfile *gz = get_gzfile(obj); gzfile_ungetc(gz, NUM2CHR(ch)); @@ -3149,8 +2952,7 @@ rb_gzreader_ungetc(obj, ch) } static void -gzreader_skip_linebreaks(gz) - struct gzfile *gz; +gzreader_skip_linebreaks(struct gzfile *gz) { VALUE str; char *p; @@ -3181,20 +2983,14 @@ gzreader_skip_linebreaks(gz) } static void -rscheck(rsptr, rslen, rs) - char *rsptr; - long rslen; - VALUE rs; +rscheck(char *rsptr, long rslen, VALUE rs) { if (RSTRING(rs)->ptr != rsptr && RSTRING(rs)->len != rslen) rb_raise(rb_eRuntimeError, "rs modified"); } static VALUE -gzreader_gets(argc, argv, obj) - int argc; - VALUE *argv; - VALUE obj; +gzreader_gets(int argc, VALUE *argv, VALUE obj) { struct gzfile *gz = get_gzfile(obj); volatile VALUE rs; @@ -3274,10 +3070,7 @@ gzreader_gets(argc, argv, obj) * See Zlib::GzipReader documentation for a description. */ static VALUE -rb_gzreader_gets(argc, argv, obj) - int argc; - VALUE *argv; - VALUE obj; +rb_gzreader_gets(int argc, VALUE *argv, VALUE obj) { VALUE dst; dst = gzreader_gets(argc, argv, obj); @@ -3291,10 +3084,7 @@ rb_gzreader_gets(argc, argv, obj) * See Zlib::GzipReader documentation for a description. */ static VALUE -rb_gzreader_readline(argc, argv, obj) - int argc; - VALUE *argv; - VALUE obj; +rb_gzreader_readline(int argc, VALUE *argv, VALUE obj) { VALUE dst; dst = rb_gzreader_gets(argc, argv, obj); @@ -3308,10 +3098,7 @@ rb_gzreader_readline(argc, argv, obj) * See Zlib::GzipReader documentation for a description. */ static VALUE -rb_gzreader_each(argc, argv, obj) - int argc; - VALUE *argv; - VALUE obj; +rb_gzreader_each(int argc, VALUE *argv, VALUE obj) { VALUE str; while (!NIL_P(str = gzreader_gets(argc, argv, obj))) { @@ -3324,10 +3111,7 @@ rb_gzreader_each(argc, argv, obj) * See Zlib::GzipReader documentation for a description. */ static VALUE -rb_gzreader_readlines(argc, argv, obj) - int argc; - VALUE *argv; - VALUE obj; +rb_gzreader_readlines(int argc, VALUE *argv, VALUE obj) { VALUE str, dst; dst = rb_ary_new(); diff --git a/gc.c b/gc.c index 839471b2b5..92d4275e8b 100644 --- a/gc.c +++ b/gc.c @@ -412,6 +412,7 @@ add_heap(void) if (himem < pend) himem = pend; heaps_used++; heap_slots *= 1.8; + if (heap_slots <= 0) heap_slots = HEAP_MIN_SLOTS; while (p < pend) { p->as.free.flags = 0; @@ -832,6 +833,7 @@ gc_mark_children(VALUE ptr, int lev) case NODE_MODULE: case NODE_ALIAS: case NODE_VALIAS: + case NODE_BLOCK_PASS: gc_mark((VALUE)obj->as.node.u1.node, lev); /* fall through */ case NODE_METHOD: /* 2 */ @@ -863,12 +865,10 @@ gc_mark_children(VALUE ptr, int lev) case NODE_COLON2: case NODE_SPLAT: case NODE_TO_ARY: - case NODE_SVALUE: ptr = (VALUE)obj->as.node.u1.node; goto again; case NODE_SCOPE: /* 2,3 */ - case NODE_BLOCK_PASS: case NODE_CDECL: gc_mark((VALUE)obj->as.node.u3.node, lev); ptr = (VALUE)obj->as.node.u2.node; @@ -2066,7 +2066,7 @@ Init_GC(void) rb_global_variable(&nomem_error); nomem_error = rb_exc_new2(rb_eNoMemError, "failed to allocate memory"); + rb_define_method(rb_cBasicObject, "__id__", rb_obj_id, 0); + rb_define_method(rb_cBasicObject, "object_id", rb_obj_id, 0); rb_define_method(rb_mKernel, "hash", rb_obj_id, 0); - rb_define_method(rb_mKernel, "__id__", rb_obj_id, 0); - rb_define_method(rb_mKernel, "object_id", rb_obj_id, 0); } diff --git a/hash.c b/hash.c index 53a0001318..8ffcfdf3ff 100644 --- a/hash.c +++ b/hash.c @@ -33,7 +33,7 @@ rb_hash_freeze(VALUE hash) VALUE rb_cHash; static VALUE envtbl; -static ID id_hash, id_call, id_default; +static ID id_hash, id_yield, id_default; static VALUE eql(VALUE *args) @@ -474,7 +474,7 @@ rb_hash_default(int argc, VALUE *argv, VALUE hash) rb_scan_args(argc, argv, "01", &key); if (FL_TEST(hash, HASH_PROC_DEFAULT)) { - return rb_funcall(RHASH(hash)->ifnone, id_call, 2, hash, key); + return rb_funcall(RHASH(hash)->ifnone, id_yield, 2, hash, key); } return RHASH(hash)->ifnone; } @@ -656,7 +656,7 @@ rb_hash_shift(VALUE hash) return rb_assoc_new(var.key, var.val); } else if (FL_TEST(hash, HASH_PROC_DEFAULT)) { - return rb_funcall(RHASH(hash)->ifnone, id_call, 2, hash, Qnil); + return rb_funcall(RHASH(hash)->ifnone, id_yield, 2, hash, Qnil); } else { return RHASH(hash)->ifnone; @@ -986,7 +986,7 @@ static int each_pair_i(VALUE key, VALUE value) { if (key == Qundef) return ST_CONTINUE; - rb_yield_values(2, key, value); + rb_yield(rb_assoc_new(key, value)); return ST_CONTINUE; } @@ -994,11 +994,11 @@ each_pair_i(VALUE key, VALUE value) * call-seq: * hsh.each_pair {| key_value_array | block } -> hsh * - * Calls block once for each key in hsh, passing the key - * and value as parameters. + * Calls block once for each key in hsh, passing the + * key and value to the block as a two-element array. * * h = { "a" => 100, "b" => 200 } - * h.each_pair {|key, value| puts "#{key} is #{value}" } + * h.each_pair {|(key, value)| puts "#{key} is #{value}" } * * produces: * @@ -1019,7 +1019,7 @@ static int each_i(VALUE key, VALUE value) { if (key == Qundef) return ST_CONTINUE; - rb_yield(rb_assoc_new(key, value)); + rb_yield_values(2, key, value); return ST_CONTINUE; } @@ -1027,11 +1027,9 @@ each_i(VALUE key, VALUE value) * call-seq: * hsh.each {| key, value | block } -> hsh * - * Calls block once for each key in hsh, passing the key - * and value to the block as a two-element array. Because of the assignment - * semantics of block parameters, these elements will be split out if the - * block has two formal parameters. Also see Hash.each_pair, which - * will be marginally more efficient for blocks with two parameters. + * Calls block once for each key in hsh, passing the key-value + * pair as parameters. Also see Hash#each_pair, which + * passes the key and value to the block as a two-element array. * * h = { "a" => 100, "b" => 200 } * h.each {|key, value| puts "#{key} is #{value}" } @@ -1893,14 +1891,14 @@ static VALUE env_each(VALUE ehash) { RETURN_ENUMERATOR(ehash, 0, 0); - return env_each_i(ehash, Qfalse); + return env_each_i(ehash, Qtrue); } static VALUE env_each_pair(VALUE ehash) { RETURN_ENUMERATOR(ehash, 0, 0); - return env_each_i(ehash, Qtrue); + return env_each_i(ehash, Qfalse); } static VALUE @@ -2273,7 +2271,7 @@ void Init_Hash(void) { id_hash = rb_intern("hash"); - id_call = rb_intern("call"); + id_yield = rb_intern("yield"); id_default = rb_intern("default"); rb_cHash = rb_define_class("Hash", rb_cObject); diff --git a/instruby.rb b/instruby.rb index 2b3bf94737..bda4ead3af 100644 --- a/instruby.rb +++ b/instruby.rb @@ -25,7 +25,7 @@ def parse_args() opt.on('--dest-dir=DIR') {|dir| $destdir = dir} opt.on('--make=COMMAND') {|make| $make = make} opt.on('--mantype=MAN') {|man| $mantype = man} - opt.on('--make-flags=FLAGS', '--mflags', Shellwords) do |v| + opt.on('--make-flags=FLAGS', '--mflags', Shellwords) do |*v| if arg = v.first arg.insert(0, '-') if /\A[^-][^=]*\Z/ =~ arg end @@ -38,7 +38,7 @@ def parse_args() $mflags.unshift(*rest) unless rest.empty? def $mflags.set?(flag) - grep(/\A-(?!-).*#{'%c' % flag}/i) { return true } + grep(/\A-(?!-).*#{'%s' % flag}/i) { return true } false end diff --git a/intern.h b/intern.h index 77e0dc867f..1323427e0c 100644 --- a/intern.h +++ b/intern.h @@ -128,6 +128,7 @@ VALUE rb_class_instance_methods(int, VALUE*, VALUE); VALUE rb_class_public_instance_methods(int, VALUE*, VALUE); VALUE rb_class_protected_instance_methods(int, VALUE*, VALUE); VALUE rb_class_private_instance_methods(int, VALUE*, VALUE); +VALUE rb_class_local_methods(VALUE); VALUE rb_obj_singleton_methods(int, VALUE*, VALUE); void rb_define_method_id(VALUE, ID, VALUE (*)(ANYARGS), int); void rb_frozen_class_p(VALUE); @@ -425,9 +426,9 @@ VALUE rb_range_new(VALUE, VALUE, int); VALUE rb_range_beg_len(VALUE, long*, long*, long, int); VALUE rb_length_by_each(VALUE); /* re.c */ -int rb_memcmp(char*,char*,long); -int rb_memcicmp(char*,char*,long); -long rb_memsearch(char*,long,char*,long); +int rb_memcmp(const void*,const void*,long); +int rb_memcicmp(const void*,const void*,long); +long rb_memsearch(const void*,long,const void*,long); VALUE rb_reg_nth_defined(int, VALUE); VALUE rb_reg_nth_match(int, VALUE); VALUE rb_reg_last_match(VALUE); diff --git a/io.c b/io.c index 83c51f4437..9cd5d91d28 100644 --- a/io.c +++ b/io.c @@ -1095,7 +1095,8 @@ static VALUE rb_io_inspect(VALUE obj) { OpenFile *fptr; - char *cname, *st = ""; + char *cname; + const char *st = ""; fptr = RFILE(rb_io_taint_check(obj))->fptr; if (!fptr || !fptr->path) return rb_any_to_s(obj); @@ -1962,21 +1963,40 @@ rb_io_each_byte(VALUE io) return io; } +VALUE +rb_io_getc(VALUE io) +{ + OpenFile *fptr; + int c; + + GetOpenFile(io, fptr); + rb_io_check_readable(fptr); + + READ_CHECK(fptr); + c = io_getc(fptr); + + if (c < 0) { + return Qnil; + } + return INT2FIX(c & 0xff); +} + /* * call-seq: - * ios.getc => fixnum or nil + * ios.getc => string or nil * - * Gets the next 8-bit byte (0..255) from ios. Returns + * Reads a one-character string from ios. Returns * nil if called at end of file. * * f = File.new("testfile") - * f.getc #=> 84 - * f.getc #=> 104 + * f.getc #=> "8" + * f.getc #=> "1" */ VALUE -rb_io_getc(VALUE io) +rb_io_getc_m(VALUE io) { + char ch; OpenFile *fptr; int c; @@ -1989,7 +2009,8 @@ rb_io_getc(VALUE io) if (c < 0) { return Qnil; } - return INT2FIX(c & 0xff); + ch = c & 0xff; + return rb_str_new(&ch, 1); } int @@ -2009,7 +2030,7 @@ rb_getc(FILE *f) /* * call-seq: - * ios.readchar => fixnum + * ios.readchar => string * * Reads a character as with IO#getc, but raises an * EOFError on end of file. @@ -2028,7 +2049,7 @@ rb_io_readchar(VALUE io) /* * call-seq: - * ios.ungetc(integer) => nil + * ios.ungetc(string) => nil * * Pushes back one character (passed as a parameter) onto ios, * such that a subsequent buffered read will return it. Only one character @@ -2037,20 +2058,30 @@ rb_io_readchar(VALUE io) * back). Has no effect with unbuffered reads (such as IO#sysread). * * f = File.new("testfile") #=> # - * c = f.getc #=> 84 + * c = f.getc #=> "8" * f.ungetc(c) #=> nil - * f.getc #=> 84 + * f.getc #=> "8" */ VALUE rb_io_ungetc(VALUE io, VALUE c) { OpenFile *fptr; - int cc = NUM2INT(c); + int cc; GetOpenFile(io, fptr); rb_io_check_readable(fptr); - + if (NIL_P(c)) return Qnil; + if (FIXNUM_P(c)) { + cc = FIX2INT(c); + } + else { + SafeStringValue(c); + if (RSTRING(c)->len > 1) { + rb_warn("IO#ungetc pushes back only one byte"); + } + cc = (unsigned char)RSTRING(c)->ptr[0]; + } if (io_ungetc(cc, fptr) == EOF && cc != EOF) { rb_raise(rb_eIOError, "ungetc failed"); } @@ -2912,8 +2943,9 @@ popen_redirect(struct popen_arg *p) #ifdef HAVE_FORK static int -popen_exec(struct popen_arg *p) +popen_exec(void *pp) { + struct popen_arg *p = (struct popen_arg*)pp; int fd; popen_redirect(p); @@ -5316,23 +5348,23 @@ argf_readpartial(int argc, VALUE *argv) static VALUE argf_getc(void) { - VALUE byte; + VALUE ch; retry: if (!next_argv()) return Qnil; if (TYPE(current_file) != T_FILE) { - byte = rb_funcall3(current_file, rb_intern("getc"), 0, 0); + ch = rb_funcall3(current_file, rb_intern("getc"), 0, 0); } else { - byte = rb_io_getc(current_file); + ch = rb_io_getc(current_file); } - if (NIL_P(byte) && next_p != -1) { + if (NIL_P(ch) && next_p != -1) { argf_close(current_file); next_p = 1; goto retry; } - return byte; + return ch; } static VALUE @@ -5646,7 +5678,7 @@ Init_IO(void) rb_define_method(rb_cIO, "write", io_write, 1); rb_define_method(rb_cIO, "gets", rb_io_gets_m, -1); rb_define_method(rb_cIO, "readline", rb_io_readline, -1); - rb_define_method(rb_cIO, "getc", rb_io_getc, 0); + rb_define_method(rb_cIO, "getc", rb_io_getc_m, 0); rb_define_method(rb_cIO, "readchar", rb_io_readchar, 0); rb_define_method(rb_cIO, "ungetc",rb_io_ungetc, 1); rb_define_method(rb_cIO, "<<", rb_io_addstr, 1); diff --git a/lib/.document b/lib/.document index 3978aa9347..9374ec7fd5 100644 --- a/lib/.document +++ b/lib/.document @@ -20,6 +20,7 @@ fileutils.rb find.rb forwardable.rb generator.rb +getoptlong.rb logger.rb matrix.rb net diff --git a/lib/cgi.rb b/lib/cgi.rb index c1627cb521..825be5a0a8 100644 --- a/lib/cgi.rb +++ b/lib/cgi.rb @@ -726,6 +726,8 @@ class CGI when /shift_jis/ni content = NKF::nkf('-s', content) options["language"] = "ja" unless options.has_key?("language") + when /utf-8/ni + content = NKF::nkf('-w', content) end end diff --git a/lib/forwardable.rb b/lib/forwardable.rb index 3e979a3155..1889f44109 100644 --- a/lib/forwardable.rb +++ b/lib/forwardable.rb @@ -93,7 +93,7 @@ # array, like this: # # class RecordCollection -# extends Forwardable +# extend Forwardable # def_delegator :@records, :[], :record_number # end # @@ -101,7 +101,7 @@ # all of which delegate to @records, this is how you can do it: # # class RecordCollection -# # extends Forwardable, but we did that above +# # extend Forwardable, but we did that above # def_delegators :@records, :size, :<<, :map # end # f = Foo.new diff --git a/lib/getoptlong.rb b/lib/getoptlong.rb index 8fb302d741..922d25371c 100644 --- a/lib/getoptlong.rb +++ b/lib/getoptlong.rb @@ -1,17 +1,94 @@ -# -*- Ruby -*- -# Copyright (C) 1998, 1999, 2000 Motoyuki Kasahara # -# You may redistribute it and/or modify it under the same license +# GetoptLong for Ruby +# +# Copyright (C) 1998, 1999, 2000 Motoyuki Kasahara. +# +# You may redistribute and/or modify this library under the same license # terms as Ruby. # +# See GetoptLong for documentation. +# +# Additional documents and the latest version of `getoptlong.rb' can be +# found at http://www.sra.co.jp/people/m-kasahr/ruby/getoptlong/ +# The GetoptLong class allows you to parse command line options similarly to +# the GNU getopt_long() C library call. Note, however, that GetoptLong is a +# pure Ruby implementation. # -# Documents and latest version of `getoptlong.rb' are found at: -# http://www.sra.co.jp/people/m-kasahr/ruby/getoptlong/ +# GetoptLong allows for POSIX-style options like --file as well +# as single letter options like -f # - +# The empty option -- (two minus symbols) is used to end option +# processing. This can be particularly important if options have optional +# arguments. # -# Parse command line options just like GNU getopt_long(). +# Here is a simple example of usage: +# +# # == Synopsis +# # +# # hello: greets user, demonstrates command line parsing +# # +# # == Usage +# # +# # hello [OPTION] ... DIR +# # +# # -h, --help: +# # show help +# # +# # --repeat x, -n x: +# # repeat x times +# # +# # --name [name]: +# # greet user by name, if name not supplied default is John +# # +# # DIR: The directory in which to issue the greeting. +# +# require 'getoptlong' +# require 'rdoc/usage' +# +# opts = GetoptLong.new( +# [ '--help', '-h', GetoptLong::NO_ARGUMENT ], +# [ '--repeat', '-n', GetoptLong::REQUIRED_ARGUMENT ], +# [ '--name', GetoptLong::OPTIONAL_ARGUMENT ] +# ) +# +# dir = nil +# name = nil +# repetitions = 1 +# opts.each do |opt, arg| +# case opt +# when '--help' +# RDoc::usage +# when '--repeat' +# repetitions = arg.to_i +# when '--name' +# if arg == '' +# name = 'John' +# else +# name = arg +# end +# end +# end +# +# if ARGV.length != 1 +# puts "Missing dir argument (try --help)" +# exit 0 +# end +# +# dir = ARGV.shift +# +# Dir.chdir(dir) +# for i in (1..repetitions) +# print "Hello" +# if name +# print ", #{name}" +# end +# puts +# end +# +# Example command line: +# +# hello -n 6 --name -- /tmp # class GetoptLong # @@ -40,13 +117,20 @@ class GetoptLong class InvalidOption < Error; end # - # The arguments are passed to new() as an array of arrays. Each - # subarray has a number of option names which carry the same - # meaning, and a ARGUMENT_FLAG, being one of - # GetoptLong::NO_ARGUMENT, GetoptLong::REQUIRED_ARGUMENT or - # GetoptLong::OPTIONAL_ARGUMENT. These determine whether the - # option takes an argument or not, or whether it is optional The - # actual processing is done later with #each(). + # Set up option processing. + # + # The options to support are passed to new() as an array of arrays. + # Each sub-array contains any number of String option names which carry + # the same meaning, and one of the following flags: + # + # GetoptLong::NO_ARGUMENT :: Option does not take an argument. + # + # GetoptLong::REQUIRED_ARGUMENT :: Option always takes an argument. + # + # GetoptLong::OPTIONAL_ARGUMENT :: Option may or may not take an argument. + # + # The first option name is considered to be the preferred (canonical) name. + # Other than that, the elements of each sub-array can be in any order. # def initialize(*arguments) # @@ -109,11 +193,53 @@ class GetoptLong end # - # Set the handling of the ordering of options. The supplied - # argument ordering must be a member of ORDERINGS, i.e one of - # GetoptLong::REQUIRE_ORDER, GetoptLong::PERMUTE, - # GetoptLong::RETURN_IN_ORDER. A RuntimeError is raised if - # option processing has already started. + # Set the handling of the ordering of options and arguments. + # A RuntimeError is raised if option processing has already started. + # + # The supplied value must be a member of GetoptLong::ORDERINGS. It alters + # the processing of options as follows: + # + # REQUIRE_ORDER : + # + # Options are required to occur before non-options. + # + # Processing of options ends as soon as a word is encountered that has not + # been preceded by an appropriate option flag. + # + # For example, if -a and -b are options which do not take arguments, + # parsing command line arguments of '-a one -b two' would result in + # 'one', '-b', 'two' being left in ARGV, and only ('-a', '') being + # processed as an option/arg pair. + # + # This is the default ordering, if the environment variable + # POSIXLY_CORRECT is set. (This is for compatibility with GNU getopt_long.) + # + # PERMUTE : + # + # Options can occur anywhere in the command line parsed. This is the + # default behavior. + # + # Every sequence of words which can be interpreted as an option (with or + # without argument) is treated as an option; non-option words are skipped. + # + # For example, if -a does not require an argument and -b optionally takes + # an argument, parsing '-a one -b two three' would result in ('-a','') and + # ('-b', 'two') being processed as option/arg pairs, and 'one','three' + # being left in ARGV. + # + # If the ordering is set to PERMUTE but the environment variable + # POSIXLY_CORRECT is set, REQUIRE_ORDER is used instead. This is for + # compatibility with GNU getopt_long. + # + # RETURN_IN_ORDER : + # + # All words on the command line are processed as options. Words not + # preceded by a short or long option flag are passed as arguments + # with an option of '' (empty string). + # + # For example, if -a requires an argument but -b does not, a command line + # of '-a one -b two three' would result in option/arg pairs of ('-a', 'one') + # ('-b', ''), ('', 'two'), ('', 'three') being processed. # def ordering=(ordering) # @@ -144,7 +270,9 @@ class GetoptLong attr_reader :ordering # - # Set options + # Set options. Takes the same argument as GetoptLong.new. + # + # Raises a RuntimeError if option processing has already started. # def set_options(*arguments) # @@ -233,7 +361,7 @@ class GetoptLong alias quiet? quiet # - # Terminate option processing. + # Explicitly terminate option processing. # def terminate return nil if @status == STATUS_TERMINATED @@ -253,7 +381,7 @@ class GetoptLong end # - # Examine whether option processing is terminated or not. + # Returns true if option processing has terminated, false otherwise. # def terminated? return @status == STATUS_TERMINATED @@ -286,16 +414,22 @@ class GetoptLong # alias error? error - # - # Return an error message. + # Return the appropriate error message in POSIX-defined format. + # If no error has occurred, returns nil. # def error_message return @error_message end # - # Get next option name and its argument as an array. - # Return nil if the processing is complete (as determined by + # Get next option name and its argument, as an Array of two elements. + # + # The option name is always converted to the first (preferred) + # name given in the original options to GetoptLong.new. + # + # Example: ['--option', 'value'] + # + # Returns nil if the processing is complete (as determined by # STATUS_TERMINATED). # def get @@ -462,9 +596,15 @@ class GetoptLong # alias get_option get + # Iterator version of `get'. + # + # The block is called repeatedly with two arguments: + # The first is the option name. + # The second is the argument which followed it (if any). + # Example: ('--opt', 'value') # - # Iterator version of `get', passes the option and the - # corresponding argument to the supplied block for processing. + # The option name is always converted to the first (preferred) + # name given in the original options to GetoptLong.new. # def each loop do diff --git a/lib/jcode.rb b/lib/jcode.rb index ea90871572..fcf4f04730 100644 --- a/lib/jcode.rb +++ b/lib/jcode.rb @@ -174,7 +174,7 @@ class String def tr_s!(from, to) return self.delete!(from) if to.length == 0 - pattern = SqueezePatternCache[from] ||= /([#{_regex_quote(from)}])\1+/ + pattern = SqueezePatternCache[from] ||= /([#{_regex_quote(from)}])\1*/ if from[0] == ?^ last = /.$/.match(to)[0] self.gsub!(pattern, last) diff --git a/lib/mathn.rb b/lib/mathn.rb index 3108dd2eb7..3dea0afec1 100644 --- a/lib/mathn.rb +++ b/lib/mathn.rb @@ -16,14 +16,6 @@ require "matrix.rb" class Integer - remove_method(:gcd2) - def gcd2(other) - min = self.abs - max = other.abs - min, max = max % min, min while min > 0 - max - end - def Integer.from_prime_division(pd) value = 1 for prime, index in pd diff --git a/lib/mkmf.rb b/lib/mkmf.rb index 421e6c9e71..1d495e8205 100644 --- a/lib/mkmf.rb +++ b/lib/mkmf.rb @@ -786,21 +786,26 @@ def find_executable(bin, path = nil) end end -def arg_config(config, *defaults, &block) - $arg_config << [config, *defaults] - defaults << nil if !block and defaults.empty? +def arg_config(config, default=nil, &block) + $arg_config << [config, default] + defaults = [] + if default + defaults << default + elsif !block + defaults << nil + end $configure_args.fetch(config.tr('_', '-'), *defaults, &block) end -def with_config(config, *defaults) +def with_config(config, default=nil) config = config.sub(/^--with[-_]/, '') val = arg_config("--with-"+config) do if arg_config("--without-"+config) false elsif block_given? - yield(config, *defaults) + yield(config, default) else - break *defaults + break default end end case val @@ -813,15 +818,15 @@ def with_config(config, *defaults) end end -def enable_config(config, *defaults) +def enable_config(config, default=nil) if arg_config("--enable-"+config) true elsif arg_config("--disable-"+config) false elsif block_given? - yield(config, *defaults) + yield(config, default) else - return *defaults + return default end end @@ -1105,7 +1110,7 @@ EXTSTATIC = #{$static || ""} STATIC_LIB = #{staticlib unless $static.nil?} } - install_dirs.each {|d| mfile.print("%-14s= %s\n" % d) if /^[[:upper:]]/ =~ d[0]} + install_dirs.each {|*d| mfile.print("%-14s= %s\n" % d) if /^[[:upper:]]/ =~ d[0]} n = ($extout ? '$(RUBYARCHDIR)/' : '') + '$(TARGET).' mfile.print %{ TARGET_SO = #{($extout ? '$(RUBYARCHDIR)/' : '')}$(DLLIB) diff --git a/lib/optparse.rb b/lib/optparse.rb index 6d1daeb6a0..9c7676f4be 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -357,7 +357,7 @@ class OptionParser if conv val = conv.call(*val) else - val = *val + val = val[0] end return arg, block, val else @@ -622,7 +622,7 @@ class OptionParser if list = __send__(id) val = list.fetch(key) {return nil} return val unless block_given? - yield(val) + yield(*val) end end @@ -848,7 +848,7 @@ class OptionParser # :nodoc: def add_officious list = base() - Officious.each_pair do |opt, block| + Officious.each do |opt, block| list.long[opt] ||= block.call(self) end end @@ -1319,7 +1319,7 @@ class OptionParser end begin opt, sw, val = sw.parse(rest, argv) {|*exc| raise(*exc)} - sw.call(val) if sw + sw.call(*val) if sw rescue ParseError raise $!.set_option(arg, rest) end @@ -1458,9 +1458,9 @@ class OptionParser yielded with the found value when succeeded. =end #'#"#`# def search(id, key) - visit(:search, id, key) do |k| + visit(:search, id, key) do |*k| return k unless block_given? - return yield(k) + return yield(*k) end end private :search diff --git a/lib/rdoc/parsers/parse_rb.rb b/lib/rdoc/parsers/parse_rb.rb index fedc67e51f..a297719b80 100644 --- a/lib/rdoc/parsers/parse_rb.rb +++ b/lib/rdoc/parsers/parse_rb.rb @@ -2555,7 +2555,7 @@ module RDoc break when TkCOMMA else - warn("unexpected token: '#{tk2.inspect}'") if $DEBBUG + warn("unexpected token: '#{tk2.inspect}'") if $DEBUG break end end diff --git a/lib/rdoc/ri/ri_paths.rb b/lib/rdoc/ri/ri_paths.rb index c610b6e551..c5526201ea 100644 --- a/lib/rdoc/ri/ri_paths.rb +++ b/lib/rdoc/ri/ri_paths.rb @@ -41,5 +41,11 @@ module RI # This is the search path for 'ri' PATH = [ SYSDIR, SITEDIR, HOMEDIR ].find_all {|p| p && File.directory?(p)} + + begin + require 'rubygems' + Dir["#{Gem.path}/doc/*/ri"].each { |path| RI::Paths::PATH << path } + rescue LoadError + end end end diff --git a/lib/runit/assert.rb b/lib/runit/assert.rb index c752b19a25..f18bb36127 100644 --- a/lib/runit/assert.rb +++ b/lib/runit/assert.rb @@ -6,8 +6,7 @@ require 'test/unit/assertions' require 'runit/error' module RUNIT - module Assert - include Test::Unit::Assertions + module AssertMixin def setup_assert end @@ -70,4 +69,8 @@ module RUNIT /assertions\.rb/.match(caller[1]) end end + module Assert + include Test::Unit::Assertions + include AssertMixin + end end diff --git a/lib/runit/testcase.rb b/lib/runit/testcase.rb index 4576cb8644..9e05a58abe 100644 --- a/lib/runit/testcase.rb +++ b/lib/runit/testcase.rb @@ -10,7 +10,7 @@ require 'test/unit/testcase' module RUNIT class TestCase < Test::Unit::TestCase - include RUNIT::Assert + include RUNIT::AssertMixin def self.suite method_names = instance_methods(true) diff --git a/lib/tempfile.rb b/lib/tempfile.rb index 1b2a889b4a..a033a5b29e 100644 --- a/lib/tempfile.rb +++ b/lib/tempfile.rb @@ -67,7 +67,7 @@ class Tempfile < DelegateClass(File) end def make_tmpname(basename, n) - sprintf('%s%d.%d', basename, $$, n) + sprintf('%s.%d.%d', basename, $$, n) end private :make_tmpname diff --git a/marshal.c b/marshal.c index d4a3c27458..1e6f8926a2 100644 --- a/marshal.c +++ b/marshal.c @@ -304,7 +304,7 @@ w_float(double d, struct dump_arg *arg) static void w_symbol(ID id, struct dump_arg *arg) { - char *sym = rb_id2name(id); + const char *sym = rb_id2name(id); st_data_t num; if (st_lookup(arg->symbols, id, &num)) { @@ -872,7 +872,7 @@ r_symbol(struct load_arg *arg) return r_symreal(arg); } -static char* +static const char* r_unique(struct load_arg *arg) { return rb_id2name(r_symbol(arg)); diff --git a/math.c b/math.c index 47f8dd5710..d7b264cccc 100644 --- a/math.c +++ b/math.c @@ -300,16 +300,55 @@ math_exp(VALUE obj, VALUE x) */ static VALUE -math_log(VALUE obj, VALUE x) +math_log(int argc, VALUE *argv) { - double d; + VALUE x, base; + double d, b; + rb_scan_args(argc, argv, "11", &x, &base); Need_Float(x); errno = 0; d = log(RFLOAT(x)->value); if (errno) { rb_sys_fail("log"); } + if (!NIL_P(base)) { + Need_Float(base); + d /= log(RFLOAT(base)->value); + } + if (errno) { + rb_sys_fail("log"); + } + return rb_float_new(d); +} + +#ifndef HAVE_LOG2 +double +log2(double x) +{ + return log10(x)/log10(2.0); +} +#endif + +/* + * call-seq: + * Math.log2(numeric) => float + * + * Returns the base 2 logarithm of numeric. + */ + +static VALUE +math_log2(VALUE obj, VALUE x) +{ + extern double log2(double); + double d; + + Need_Float(x); + errno = 0; + d = log2(RFLOAT(x)->value); + if (errno) { + rb_sys_fail("log2"); + } return rb_float_new(d); } @@ -485,7 +524,8 @@ Init_Math(void) rb_define_module_function(rb_mMath, "atanh", math_atanh, 1); rb_define_module_function(rb_mMath, "exp", math_exp, 1); - rb_define_module_function(rb_mMath, "log", math_log, 1); + rb_define_module_function(rb_mMath, "log", math_log, -1); + rb_define_module_function(rb_mMath, "log2", math_log2, 1); rb_define_module_function(rb_mMath, "log10", math_log10, 1); rb_define_module_function(rb_mMath, "sqrt", math_sqrt, 1); diff --git a/missing/vsnprintf.c b/missing/vsnprintf.c index 11f4de350b..0cfa5046aa 100644 --- a/missing/vsnprintf.c +++ b/missing/vsnprintf.c @@ -314,9 +314,7 @@ static int BSD__sfvwrite(fp, uio) * then reset it so that it can be reused. */ static int -BSD__sprint(fp, uio) - FILE *fp; - register struct __suio *uio; +BSD__sprint(FILE *fp, register struct __suio *uio) { register int err; @@ -337,10 +335,7 @@ BSD__sprint(fp, uio) * worries about ungetc buffers and so forth. */ static int -BSD__sbprintf(fp, fmt, ap) - register FILE *fp; - const char *fmt; - va_list ap; +BSD__sbprintf(register FILE *fp, const char *fmt, va_list ap) { /* We don't support files. */ return 0; @@ -361,11 +356,7 @@ BSD__sbprintf(fp, fmt, ap) * use the given digits. */ static char * -BSD__ultoa(val, endp, base, octzero, xdigs) - register u_long val; - char *endp; - int base, octzero; - char *xdigs; +BSD__ultoa(register u_long val, char *endp, int base, int octzero, char *xdigs) { register char *cp = endp; register long sval; @@ -464,10 +455,7 @@ static int exponent __P((char *, int, int)); #define ZEROPAD 0x080 /* zero (as opposed to blank) pad */ #define FPT 0x100 /* Floating point number */ static int -BSD_vfprintf(fp, fmt0, ap) - FILE *fp; - const char *fmt0; - va_list ap; +BSD_vfprintf(FILE *fp, const char *fmt0, va_list ap) { register char *fmt; /* format string */ register int ch; /* character from fmt */ diff --git a/mkconfig.rb b/mkconfig.rb index 559078aca6..9af94f7606 100644 --- a/mkconfig.rb +++ b/mkconfig.rb @@ -38,9 +38,11 @@ vars = {} has_version = false File.foreach "config.status" do |line| next if /^#/ =~ line - if /^s[%,]@program_transform_name@[%,]s,(.*)/ =~ line + line.gsub!(/\|#_!!_#\|/, '') + if /^s[%,]@program_transform_name@[%,]s(\\?.)(.*)\1[%,]/ =~ line next if $install_name - ptn = $1.sub(/\$\$/, '$').split(/,/) #' + sep = Regexp.quote($1) + ptn = $2.sub(/\$\$/, '$').split(/#{sep}/,2) v_fast << " CONFIG[\"ruby_install_name\"] = \"" + "ruby".sub(/#{ptn[0]}/,ptn[1]) + "\"\n" elsif /^s[%,]@(\w+)@[%,](.*)[%,]/ =~ line name = $1 diff --git a/node.h b/node.h index 89347ba91c..c51753ad6f 100644 --- a/node.h +++ b/node.h @@ -86,11 +86,11 @@ enum node_type { NODE_DREGX, NODE_DREGX_ONCE, NODE_ARGS, + NODE_POSTARG, NODE_ARGSCAT, NODE_ARGSPUSH, NODE_SPLAT, NODE_TO_ARY, - NODE_SVALUE, NODE_BLOCK_ARG, NODE_BLOCK_PASS, NODE_DEFN, @@ -311,11 +311,11 @@ typedef struct RNode { #define NEW_SUPER(a) NEW_NODE(NODE_SUPER,0,0,a) #define NEW_ZSUPER() NEW_NODE(NODE_ZSUPER,0,0,0) #define NEW_ARGS(f,o,r) NEW_NODE(NODE_ARGS,o,r,f) +#define NEW_POSTARG(r,m) NEW_NODE(NODE_POSTARG,m,0,r) #define NEW_ARGSCAT(a,b) NEW_NODE(NODE_ARGSCAT,a,b,0) #define NEW_ARGSPUSH(a,b) NEW_NODE(NODE_ARGSPUSH,a,b,0) #define NEW_SPLAT(a) NEW_NODE(NODE_SPLAT,a,0,0) #define NEW_TO_ARY(a) NEW_NODE(NODE_TO_ARY,a,0,0) -#define NEW_SVALUE(a) NEW_NODE(NODE_SVALUE,a,0,0) #define NEW_BLOCK_ARG(v) NEW_NODE(NODE_BLOCK_ARG,v,0,local_cnt(v)) #define NEW_BLOCK_PASS(b) NEW_NODE(NODE_BLOCK_PASS,0,b,0) #define NEW_ALIAS(n,o) NEW_NODE(NODE_ALIAS,n,o,0) @@ -345,10 +345,11 @@ typedef struct RNode { #define NOEX_NOSUPER 1 #define NOEX_PRIVATE 2 #define NOEX_PROTECTED 4 -#define NOEX_MASK 6 +#define NOEX_LOCAL 8 +#define NOEX_MASK 14 #define NOEX_UNDEF NOEX_NOSUPER -#define NOEX_RECV 8 +#define NOEX_RECV 16 VALUE rb_parser_new(void); VALUE rb_parser_end_seen_p(VALUE); diff --git a/numeric.c b/numeric.c index f94be7f8ed..2448cce894 100644 --- a/numeric.c +++ b/numeric.c @@ -284,21 +284,21 @@ num_div(VALUE x, VALUE y) * ------+-----+---------------+---------+-------------+--------------- * -13 | -4 | 3, -1 | 3 | -1 | -1 * ------+-----+---------------+---------+-------------+--------------- - * 11.5 | 4 | 2.0, 3.5 | 2.875 | 3.5 | 3.5 + * 11.5 | 4 | 2, 3.5 | 2.875 | 3.5 | 3.5 * ------+-----+---------------+---------+-------------+--------------- - * 11.5 | -4 | -3.0, -0.5 | -2.875 | -0.5 | 3.5 + * 11.5 | -4 | -3, -0.5 | -2.875 | -0.5 | 3.5 * ------+-----+---------------+---------+-------------+--------------- - * -11.5 | 4 | -3.0 0.5 | -2.875 | 0.5 | -3.5 + * -11.5 | 4 | -3, 0.5 | -2.875 | 0.5 | -3.5 * ------+-----+---------------+---------+-------------+--------------- - * -11.5 | -4 | 2.0 -3.5 | 2.875 | -3.5 | -3.5 + * -11.5 | -4 | 2, -3.5 | 2.875 | -3.5 | -3.5 * * * Examples * 11.divmod(3) #=> [3, 2] * 11.divmod(-3) #=> [-4, -1] - * 11.divmod(3.5) #=> [3.0, 0.5] - * (-11).divmod(3.5) #=> [-4.0, 3.0] - * (11.5).divmod(3.5) #=> [3.0, 1.0] + * 11.divmod(3.5) #=> [3, 0.5] + * (-11).divmod(3.5) #=> [-4, 3.0] + * (11.5).divmod(3.5) #=> [3, 1.0] */ static VALUE @@ -696,7 +696,7 @@ flo_mod(VALUE x, VALUE y) static VALUE flo_divmod(VALUE x, VALUE y) { - double fy, div, mod; + double fy, div, mod, val; volatile VALUE a, b; switch (TYPE(y)) { @@ -713,7 +713,13 @@ flo_divmod(VALUE x, VALUE y) return rb_num_coerce_bin(x, y); } flodivmod(RFLOAT(x)->value, fy, &div, &mod); - a = rb_float_new(div); + if (FIXABLE(div)) { + val = div; + a = LONG2FIX(val); + } + else { + a = rb_dbl2big(div); + } b = rb_float_new(mod); return rb_assoc_new(a, b); } @@ -1722,7 +1728,6 @@ int_succ(VALUE num) * receiver's value. * * 65.chr #=> "A" - * ?a.chr #=> "a" * 230.chr #=> "\346" */ @@ -2603,7 +2608,7 @@ fix_abs(VALUE fix) static VALUE fix_id2name(VALUE fix) { - char *name = rb_id2name(FIX2UINT(fix)); + const char *name = rb_id2name(FIX2UINT(fix)); if (name) return rb_str_new2(name); return Qnil; } diff --git a/object.c b/object.c index e3102acc2b..6481ce5880 100644 --- a/object.c +++ b/object.c @@ -20,6 +20,7 @@ #include #include +VALUE rb_cBasicObject; VALUE rb_mKernel; VALUE rb_cObject; VALUE rb_cModule; @@ -266,7 +267,7 @@ static int inspect_i(ID id, VALUE value, VALUE str) { VALUE str2; - char *ivname; + const char *ivname; /* need not to show internal data */ if (CLASS_OF(value) == 0) return ST_CONTINUE; @@ -698,8 +699,7 @@ nil_to_s(VALUE obj) */ static VALUE -nil_to_a(obj) - VALUE obj; +nil_to_a(VALUE obj) { return rb_ary_new2(0); } @@ -1007,7 +1007,7 @@ static VALUE sym_inspect(VALUE sym) { VALUE str; - char *name; + const char *name; ID id = SYM2ID(sym); name = rb_id2name(id); @@ -1374,7 +1374,7 @@ rb_obj_alloc(VALUE klass) { VALUE obj; - if (RCLASS(klass)->super == 0) { + if (RCLASS(klass)->super == 0 && klass != rb_cBasicObject) { rb_raise(rb_eTypeError, "can't instantiate uninitialized class"); } if (FL_TEST(klass, FL_SINGLETON)) { @@ -2258,7 +2258,7 @@ rb_f_array(VALUE obj, VALUE arg) } static VALUE -boot_defclass(char *name, VALUE super) +boot_defclass(const char *name, VALUE super) { extern st_table *rb_class_tbl; VALUE obj = rb_class_boot(super); @@ -2309,9 +2309,12 @@ VALUE ruby_top_self; * that follows, the vertical arrows represent inheritance, and the * parentheses meta-classes. All metaclasses are instances * of the class `Class'. - * - * +------------------+ - * | | + * + * +-----------------+ + * | | + * BasicObject-->(BasicObject) | + * ^ ^ | + * | | | * Object---->(Object) | * ^ ^ ^ ^ | * | | | | | @@ -2331,10 +2334,12 @@ VALUE ruby_top_self; /* - * Object is the parent class of all classes in Ruby. Its + * BasicObject is the parent class of all classes in Ruby. + * It's an explicit blank class. Object, the root of Ruby's + * class hierarchy is a direct subclass of BasicObject. Its * methods are therefore available to all objects unless explicitly * overridden. - * + * * Object mixes in the Kernel module, making * the built-in kernel functions globally accessible. Although the * instance methods of Object are defined by the @@ -2351,18 +2356,23 @@ Init_Object(void) { VALUE metaclass; - rb_cObject = boot_defclass("Object", 0); + rb_cBasicObject = boot_defclass("BasicObject", 0); + rb_cObject = boot_defclass("Object", rb_cBasicObject); rb_cModule = boot_defclass("Module", rb_cObject); rb_cClass = boot_defclass("Class", rb_cModule); - metaclass = rb_make_metaclass(rb_cObject, rb_cClass); + metaclass = rb_make_metaclass(rb_cBasicObject, rb_cClass); + metaclass = rb_make_metaclass(rb_cObject, metaclass); metaclass = rb_make_metaclass(rb_cModule, metaclass); metaclass = rb_make_metaclass(rb_cClass, metaclass); + rb_define_private_method(rb_cBasicObject, "initialize", rb_obj_dummy, 0); + rb_define_alloc_func(rb_cBasicObject, rb_class_allocate_instance); + rb_define_method(rb_cBasicObject, "==", rb_obj_equal, 1); + rb_define_method(rb_cBasicObject, "equal?", rb_obj_equal, 1); + rb_mKernel = rb_define_module("Kernel"); rb_include_module(rb_cObject, rb_mKernel); - rb_define_alloc_func(rb_cObject, rb_class_allocate_instance); - rb_define_private_method(rb_cObject, "initialize", rb_obj_dummy, 0); rb_define_private_method(rb_cClass, "inherited", rb_obj_dummy, 1); rb_define_private_method(rb_cModule, "included", rb_obj_dummy, 1); rb_define_private_method(rb_cModule, "extended", rb_obj_dummy, 1); @@ -2370,10 +2380,7 @@ Init_Object(void) rb_define_private_method(rb_cModule, "method_removed", rb_obj_dummy, 1); rb_define_private_method(rb_cModule, "method_undefined", rb_obj_dummy, 1); - rb_define_method(rb_mKernel, "nil?", rb_false, 0); - rb_define_method(rb_mKernel, "==", rb_obj_equal, 1); - rb_define_method(rb_mKernel, "equal?", rb_obj_equal, 1); rb_define_method(rb_mKernel, "===", rb_equal, 1); rb_define_method(rb_mKernel, "=~", rb_obj_pattern_match, 1); @@ -2477,6 +2484,8 @@ Init_Object(void) rb_class_protected_instance_methods, -1); /* in class.c */ rb_define_method(rb_cModule, "private_instance_methods", rb_class_private_instance_methods, -1); /* in class.c */ + rb_define_method(rb_cModule, "local_methods", + rb_class_local_methods, 0); /* in class.c */ rb_define_method(rb_cModule, "constants", rb_mod_constants, 0); /* in variable.c */ rb_define_method(rb_cModule, "const_get", rb_mod_const_get, -1); diff --git a/pack.c b/pack.c index 220ed970d3..8ff90369fc 100644 --- a/pack.c +++ b/pack.c @@ -1286,7 +1286,7 @@ infected_str_new(const char *ptr, long len, VALUE str) static VALUE pack_unpack(VALUE str, VALUE fmt) { - static char *hexdigits = "0123456789abcdef0123456789ABCDEFx"; + static const char *hexdigits = "0123456789abcdef0123456789ABCDEFx"; char *s, *send; char *p, *pend; VALUE ary; @@ -1320,7 +1320,7 @@ pack_unpack(VALUE str, VALUE fmt) } star = 0; if (*p == '_' || *p == '!') { - char *natstr = "sSiIlL"; + const char *natstr = "sSiIlL"; if (strchr(natstr, type)) { #ifdef NATINT_PACK @@ -1818,6 +1818,8 @@ pack_unpack(VALUE str, VALUE fmt) while (s < send) { if (*s == '=') { if (++s == send) break; + if (s+1 < send && *s == '\r' && *(s+1) == '\n') + s++; if (*s != '\n') { if ((c1 = hex2num(*s)) == -1) break; if (++s == send) break; diff --git a/parse.y b/parse.y index bcb7f115fe..0c984f6f7a 100644 --- a/parse.y +++ b/parse.y @@ -67,7 +67,6 @@ int ruby_sourceline; /* current line no. */ enum lex_state_e { EXPR_BEG, /* ignore newline, +/- is a sign. */ EXPR_END, /* newline significant, +/- is a operator. */ - EXPR_END2, /* newline significant, +/- is a operator. */ EXPR_ARG, /* newline significant, +/- is a operator. */ EXPR_CMDARG, /* newline significant, +/- is a operator. */ EXPR_ENDARG, /* newline significant, +/- is a operator. */ @@ -257,11 +256,12 @@ static NODE *remove_begin(NODE*); static void void_stmts_gen(struct parser_params*,NODE*); #define void_stmts(node) void_stmts_gen(parser, node) static void reduce_nodes(NODE**); -static void block_dup_check(NODE*); +static void block_dup_check(NODE*,NODE*); static NODE *block_append(NODE*,NODE*); static NODE *list_append(NODE*,NODE*); static NODE *list_concat(NODE*,NODE*); +static NODE *arg_append(NODE*,NODE*); static NODE *arg_concat(NODE*,NODE*); static NODE *literal_concat(NODE*,NODE*); static NODE *new_evstr(NODE*); @@ -270,18 +270,14 @@ static NODE *evstr2dstr(NODE*); static NODE *call_op_gen(struct parser_params*,NODE*,ID,int,NODE*); #define call_op(recv,id,narg,arg1) call_op_gen(parser, recv,id,narg,arg1) -static NODE *new_args_gen(struct parser_params*,VALUE,NODE*,NODE*,NODE*); -#define new_args(f,o,r,b) new_args_gen(parser, f,o,r,b) +static NODE *new_args_gen(struct parser_params*,VALUE,NODE*,NODE*,NODE*,NODE*); +#define new_args(f,o,r,p,b) new_args_gen(parser, f,o,r,p,b) static void shadowing_lvar_gen(struct parser_params*,ID); #define shadowing_lvar(name) shadowing_lvar_gen(parser, name) static NODE *negate_lit(NODE*); static NODE *ret_args(NODE*); static NODE *arg_blk_pass(NODE*,NODE*); -static NODE *new_call(NODE*,ID,NODE*); -static NODE *new_fcall_gen(struct parser_params*,ID,NODE*); -#define new_fcall(id,args) new_fcall_gen(parser, id, args) -static NODE *new_super(NODE*); static NODE *new_yield(NODE*); static NODE *gettable_gen(struct parser_params*,ID); @@ -525,7 +521,7 @@ static void ripper_compile_error(struct parser_params*, const char *fmt, ...); k__FILE__ %token tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tLABEL -%token tINTEGER tFLOAT tSTRING_CONTENT +%token tINTEGER tFLOAT tSTRING_CONTENT tCHAR %token tNTH_REF tBACK_REF %token tREGEXP_END @@ -536,15 +532,17 @@ static void ripper_compile_error(struct parser_params*, const char *fmt, ...); %type bodystmt compstmt stmts stmt expr arg primary command command_call method_call %type expr_value arg_value primary_value %type if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure -%type args when_args call_args call_args2 open_args paren_args opt_paren_args +%type args call_args call_args2 opt_call_args +%type open_args paren_args opt_paren_args %type command_args aref_args opt_block_arg block_arg var_ref var_lhs %type mrhs superclass block_call block_command -%type f_arglist f_args f_rest_arg f_optarg f_opt f_block_arg opt_f_block_arg +%type f_arglist f_args f_rest_arg f_post_arg +%type f_optarg f_opt f_block_arg opt_f_block_arg %type assoc_list assocs assoc undef_list backref string_dvar %type for_var block_param opt_block_param block_param_def block_param0 %type opt_bv_decl bv_decls bv_decl lambda f_larglist lambda_body %type brace_block cmd_brace_block do_block lhs none fitem -%type mlhs mlhs_head mlhs_basic mlhs_entry mlhs_item mlhs_node +%type mlhs mlhs_head mlhs_basic mlhs_entry mlhs_item mlhs_node mlhs_post %type fsym variable sym symbol operation operation2 operation3 %type cname fname op f_norm_arg %type f_arg @@ -579,7 +577,6 @@ static void ripper_compile_error(struct parser_params*, const char *fmt, ...); %token tSTAR /* * */ %token tAMPER /* & */ %token tLAMBDA /* -> */ -%token tLAMBDA_ARG /* -> */ %token tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG tWORDS_BEG tQWORDS_BEG %token tSTRING_DBEG tSTRING_DVAR tSTRING_END tLAMBEG @@ -862,16 +859,12 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem } | klEND '{' compstmt '}' { - /*%%%*/ if (in_def || in_single) { - rb_warn("END in method; use at_exit"); + rb_warn0("END in method; use at_exit"); } - + /*%%%*/ $$ = NEW_POSTEXE($3); /*% - if (in_def || in_single) { - rb_warn0("END in method; use at_exit"); - } $$ = dispatch1(END, $3); %*/ } @@ -922,17 +915,13 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem $$ = dispatch3(opassign, $1, $2, $3); %*/ } - | primary_value '[' aref_args ']' tOP_ASGN command_call + | primary_value '[' opt_call_args ']' tOP_ASGN command_call { /*%%%*/ - NODE *args; + NODE *args = $3; value_expr($6); - args = NEW_LIST($6); - if ($3 && nd_type($3) != NODE_ARRAY) - $3 = NEW_LIST($3); - $3 = list_append($3, NEW_NIL()); - list_concat(args, $3); + args = arg_concat($6, $3); if ($5 == tOROP) { $5 = 0; } @@ -1010,7 +999,7 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem | lhs '=' mrhs { /*%%%*/ - $$ = node_assign($1, NEW_SVALUE($3)); + $$ = node_assign($1, $3); /*% $$ = dispatch2(assign, $1, $3); %*/ @@ -1018,7 +1007,7 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem | mlhs '=' arg_value { /*%%%*/ - $1->nd_value = ($1->nd_head) ? NEW_TO_ARY($3) : NEW_ARRAY($3); + $1->nd_value = NEW_SPLAT($3); $$ = $1; /*% dispatch2(massign, $1, $3); @@ -1115,7 +1104,7 @@ block_command : block_call | block_call '.' operation2 command_args { /*%%%*/ - $$ = new_call($1, $3, $4); + $$ = NEW_CALL($1, $3, $4); /*% $$ = dispatch3(call, $1, ripper_id2sym('.'), $3); $$ = method_arg($$, $4); @@ -1124,7 +1113,7 @@ block_command : block_call | block_call tCOLON2 operation2 command_args { /*%%%*/ - $$ = new_call($1, $3, $4); + $$ = NEW_CALL($1, $3, $4); /*% $$ = dispatch3(call, $1, ripper_intern("::"), $3); $$ = method_arg($$, $4); @@ -1159,7 +1148,7 @@ cmd_brace_block : tLBRACE_ARG command : operation command_args %prec tLOWEST { /*%%%*/ - $$ = new_fcall($1, $2); + $$ = NEW_FCALL($1, $2); fixpos($$, $2); /*% $$ = dispatch2(command, $1, $2); @@ -1168,12 +1157,8 @@ command : operation command_args %prec tLOWEST | operation command_args cmd_brace_block { /*%%%*/ - $$ = new_fcall($1, $2); - if ($3) { - block_dup_check($$); - $3->nd_iter = $$; - $$ = $3; - } + $$ = NEW_FCALL($1, $2); + block_dup_check($2,$3); fixpos($$, $2); /*% $$ = dispatch2(command, $1, $2); @@ -1183,7 +1168,7 @@ command : operation command_args %prec tLOWEST | primary_value '.' operation2 command_args %prec tLOWEST { /*%%%*/ - $$ = new_call($1, $3, $4); + $$ = NEW_CALL($1, $3, $4); fixpos($$, $1); /*% $$ = dispatch4(command_call, $1, ripper_id2sym('.'), $3, $4); @@ -1192,12 +1177,8 @@ command : operation command_args %prec tLOWEST | primary_value '.' operation2 command_args cmd_brace_block { /*%%%*/ - $$ = new_call($1, $3, $4); - if ($5) { - block_dup_check($$); - $5->nd_iter = $$; - $$ = $5; - } + $$ = NEW_CALL($1, $3, $4); + block_dup_check($4,$5); fixpos($$, $1); /*% $$ = dispatch4(command_call, $1, ripper_id2sym('.'), $3, $4); @@ -1207,7 +1188,7 @@ command : operation command_args %prec tLOWEST | primary_value tCOLON2 operation2 command_args %prec tLOWEST { /*%%%*/ - $$ = new_call($1, $3, $4); + $$ = NEW_CALL($1, $3, $4); fixpos($$, $1); /*% $$ = dispatch4(command_call, $1, ripper_intern("::"), $3, $4); @@ -1216,12 +1197,8 @@ command : operation command_args %prec tLOWEST | primary_value tCOLON2 operation2 command_args cmd_brace_block { /*%%%*/ - $$ = new_call($1, $3, $4); - if ($5) { - block_dup_check($$); - $5->nd_iter = $$; - $$ = $5; - } + $$ = NEW_CALL($1, $3, $4); + block_dup_check($4,$5); fixpos($$, $1); /*% $$ = dispatch4(command_call, $1, ripper_intern("::"), $3, $4); @@ -1231,7 +1208,7 @@ command : operation command_args %prec tLOWEST | kSUPER command_args { /*%%%*/ - $$ = new_super($2); + $$ = NEW_SUPER($2); fixpos($$, $2); /*% $$ = dispatch1(super, $2); @@ -1294,6 +1271,14 @@ mlhs_basic : mlhs_head $$ = mlhs_add_star($1, $3); %*/ } + | mlhs_head tSTAR mlhs_node ',' mlhs_post + { + /*%%%*/ + $$ = NEW_MASGN($1, NEW_POSTARG($3,$5)); + /*% + $$ = mlhs_add_star($1, $3); + %*/ + } | mlhs_head tSTAR { /*%%%*/ @@ -1302,6 +1287,14 @@ mlhs_basic : mlhs_head $$ = mlhs_add_star($1, Qnil); %*/ } + | mlhs_head tSTAR ',' mlhs_post + { + /*%%%*/ + $$ = NEW_MASGN($1, NEW_POSTARG(-1,$4)); + /*% + $$ = mlhs_add_star($1, Qnil); + %*/ + } | tSTAR mlhs_node { /*%%%*/ @@ -1310,6 +1303,14 @@ mlhs_basic : mlhs_head $$ = mlhs_add_star(mlhs_new(), $2); %*/ } + | tSTAR mlhs_node ',' mlhs_post + { + /*%%%*/ + $$ = NEW_MASGN(0, NEW_POSTARG($2,$4)); + /*% + $$ = mlhs_add_star(mlhs_new(), $2); + %*/ + } | tSTAR { /*%%%*/ @@ -1318,6 +1319,14 @@ mlhs_basic : mlhs_head $$ = mlhs_add_star(mlhs_new(), Qnil); %*/ } + | tSTAR ',' mlhs_head + { + /*%%%*/ + $$ = NEW_MASGN(0, NEW_POSTARG(-1,$3)); + /*% + $$ = mlhs_add_star(mlhs_new(), Qnil); + %*/ + } ; mlhs_item : mlhs_node @@ -1349,6 +1358,24 @@ mlhs_head : mlhs_item ',' } ; +mlhs_post : mlhs_item + { + /*%%%*/ + $$ = NEW_LIST($1); + /*% + $$ = mlhs_add(mlhs_new(), $1); + %*/ + } + | mlhs_post ',' mlhs_item + { + /*%%%*/ + $$ = list_append($1, $3); + /*% + $$ = mlhs_add($1, $3); + %*/ + } + ; + mlhs_node : variable { /*%%%*/ @@ -1357,7 +1384,7 @@ mlhs_node : variable $$ = $1; %*/ } - | primary_value '[' aref_args ']' + | primary_value '[' opt_call_args ']' { /*%%%*/ $$ = aryset($1, $3); @@ -1431,7 +1458,7 @@ lhs : variable $$ = dispatch1(var_field, $1); %*/ } - | primary_value '[' aref_args ']' + | primary_value '[' opt_call_args ']' { /*%%%*/ $$ = aryset($1, $3); @@ -1677,14 +1704,13 @@ arg : lhs '=' arg $$ = dispatch3(opassign, $1, $2, $3); %*/ } - | primary_value '[' aref_args ']' tOP_ASGN arg + | primary_value '[' opt_call_args ']' tOP_ASGN arg { /*%%%*/ NODE *args; value_expr($6); - args = NEW_LIST($6); - list_concat(args, $3); + args = arg_concat($6, $3); if ($5 == tOROP) { $5 = 0; } @@ -2092,27 +2118,16 @@ arg_value : arg ; aref_args : none - | command opt_nl - { - /*%%%*/ - rb_warn("parenthesize argument(s) for future version"); - $$ = NEW_LIST($1); - /*% - rb_warn0("parenthesize argument(s) for future version"); - $$ = arg_add(arg_new(), $1); - %*/ - } | args trailer { $$ = $1; } - | args ',' tSTAR arg opt_nl + | args ',' assocs trailer { /*%%%*/ - value_expr($4); - $$ = arg_concat($1, $4); + $$ = list_append($1, NEW_HASH($3)); /*% - $$ = arg_add_star($1, $4); + $$ = arg_add_assocs($1, $3); %*/ } | assocs trailer @@ -2123,26 +2138,9 @@ aref_args : none $$ = arg_add_assocs(arg_new(), $1); %*/ } - | tSTAR arg opt_nl - { - /*%%%*/ - value_expr($2); - $$ = newline_node(NEW_SPLAT($2)); - /*% - $$ = arg_add_star(arg_new(), $2); - %*/ - } ; -paren_args : '(' none ')' - { - /*%%%*/ - $$ = $2; - /*% - $$ = dispatch1(arg_paren, arg_new()); - %*/ - } - | '(' call_args rparen +paren_args : '(' opt_call_args rparen { /*%%%*/ $$ = $2; @@ -2150,39 +2148,22 @@ paren_args : '(' none ')' $$ = dispatch1(arg_paren, $2); %*/ } - | '(' block_call rparen - { - /*%%%*/ - rb_warn("parenthesize argument for future version"); - $$ = NEW_LIST($2); - /*% - rb_warn0("parenthesize argument for future version"); - $$ = dispatch1(arg_paren, arg_add(arg_new(), $2)); - %*/ - } - | '(' args ',' block_call rparen - { - /*%%%*/ - rb_warn("parenthesize argument for future version"); - $$ = list_append($2, $4); - /*% - rb_warn0("parenthesize argument for future version"); - $$ = dispatch1(arg_paren, arg_add($2, $4)); - %*/ - } ; opt_paren_args : none | paren_args ; +opt_call_args : none + | call_args + ; + call_args : command { + rb_warn("parenthesize argument(s) for future version"); /*%%%*/ - rb_warn("parenthesize argument(s) for future version"); $$ = NEW_LIST($1); /*% - rb_warn0("parenthesize argument(s) for future version"); $$ = arg_add(arg_new(), $1); %*/ } @@ -2194,15 +2175,6 @@ call_args : command $$ = arg_add_optblock($1, $2); %*/ } - | args ',' tSTAR arg_value opt_block_arg - { - /*%%%*/ - $$ = arg_concat($1, $4); - $$ = arg_blk_pass($$, $5); - /*% - arg_add_optblock(arg_add_star($1, $4), $5); - %*/ - } | assocs opt_block_arg { /*%%%*/ @@ -2213,44 +2185,15 @@ call_args : command $$ = arg_add_optblock($$, $2); %*/ } - | assocs ',' tSTAR arg_value opt_block_arg - { - /*%%%*/ - $$ = arg_concat(NEW_LIST(NEW_HASH($1)), $4); - $$ = arg_blk_pass($$, $5); - /*% - $$ = arg_add_star(arg_add_assocs(arg_new(), $1), $4); - $$ = arg_add_optblock($$, $5); - %*/ - } | args ',' assocs opt_block_arg { /*%%%*/ - $$ = list_append($1, NEW_HASH($3)); + $$ = arg_append($1, NEW_HASH($3)); $$ = arg_blk_pass($$, $4); /*% $$ = arg_add_optblock(arg_add_assocs($1, $3), $4); %*/ } - | args ',' assocs ',' tSTAR arg opt_block_arg - { - /*%%%*/ - value_expr($6); - $$ = arg_concat(list_append($1, NEW_HASH($3)), $6); - $$ = arg_blk_pass($$, $7); - /*% - $$ = arg_add_star(arg_add_assocs($1, $3), $6); - $$ = arg_add_optblock($$, $7); - %*/ - } - | tSTAR arg_value opt_block_arg - { - /*%%%*/ - $$ = arg_blk_pass(NEW_SPLAT($2), $3); - /*% - $$ = arg_add_optblock(arg_add_star(arg_new(), $2), $3); - %*/ - } | block_arg /*%c%*/ /*%c @@ -2276,26 +2219,6 @@ call_args2 : arg_value ',' args opt_block_arg $$ = arg_add_block(arg_add(arg_new(), $1), $3); %*/ } - | arg_value ',' tSTAR arg_value opt_block_arg - { - /*%%%*/ - $$ = arg_concat(NEW_LIST($1), $4); - $$ = arg_blk_pass($$, $5); - /*% - $$ = arg_add_star(arg_add(arg_new(), $1), $4); - $$ = arg_add_optblock($$, $5); - %*/ - } - | arg_value ',' args ',' tSTAR arg_value opt_block_arg - { - /*%%%*/ - $$ = arg_concat(list_concat(NEW_LIST($1),$3), $6); - $$ = arg_blk_pass($$, $7); - /*% - $$ = arg_add_star(arg_prepend($3, $1), $6); - $$ = arg_add_optblock($$, $7); - %*/ - } | assocs opt_block_arg { /*%%%*/ @@ -2305,20 +2228,10 @@ call_args2 : arg_value ',' args opt_block_arg $$ = arg_add_optblock(arg_add_assocs(arg_new(), $1), $2); %*/ } - | assocs ',' tSTAR arg_value opt_block_arg - { - /*%%%*/ - $$ = arg_concat(NEW_LIST(NEW_HASH($1)), $4); - $$ = arg_blk_pass($$, $5); - /*% - $$ = arg_add_star(arg_add_assocs(arg_new(), $1), $4); - $$ = arg_add_optblock($$, $4); - %*/ - } | arg_value ',' assocs opt_block_arg { /*%%%*/ - $$ = list_append(NEW_LIST($1), NEW_HASH($3)); + $$ = arg_append(NEW_LIST($1), NEW_HASH($3)); $$ = arg_blk_pass($$, $4); /*% $$ = arg_add_assocs(arg_add(arg_new(), $1), $3); @@ -2328,43 +2241,13 @@ call_args2 : arg_value ',' args opt_block_arg | arg_value ',' args ',' assocs opt_block_arg { /*%%%*/ - $$ = list_append(list_concat(NEW_LIST($1),$3), NEW_HASH($5)); + $$ = arg_append(list_concat(NEW_LIST($1),$3), NEW_HASH($5)); $$ = arg_blk_pass($$, $6); /*% $$ = arg_add_assocs(arg_prepend($3, $1), $5); $$ = arg_add_optblock($$, $6); %*/ } - | arg_value ',' assocs ',' tSTAR arg_value opt_block_arg - { - /*%%%*/ - $$ = arg_concat(list_append(NEW_LIST($1), NEW_HASH($3)), $6); - $$ = arg_blk_pass($$, $7); - /*% - $$ = arg_add_assocs(arg_add(arg_new(), $1), $3); - $$ = arg_add_star($$, $6); - $$ = arg_add_optblock($$, $7); - %*/ - } - | arg_value ',' args ',' assocs ',' tSTAR arg_value opt_block_arg - { - /*%%%*/ - $$ = arg_concat(list_append(list_concat(NEW_LIST($1), $3), NEW_HASH($5)), $8); - $$ = arg_blk_pass($$, $9); - /*% - $$ = arg_add_assocs(arg_prepend($3, $1), $5); - $$ = arg_add_star($$, $8); - $$ = arg_add_optblock($$, $9); - %*/ - } - | tSTAR arg_value opt_block_arg - { - /*%%%*/ - $$ = arg_blk_pass(NEW_SPLAT($2), $3); - /*% - $$ = arg_add_optblock(arg_add_star(arg_new(), $2), $3); - %*/ - } | block_arg ; @@ -2426,14 +2309,30 @@ args : arg_value $$ = arg_add(arg_new(), $1); %*/ } + | tSTAR arg_value + { + /*%%%*/ + $$ = NEW_SPLAT($2); + /*% + $$ = arg_add_star(arg_new(), $1); + %*/ + } | args ',' arg_value { /*%%%*/ - $$ = list_append($1, $3); + $$ = arg_append($1, $3); /*% $$ = arg_add($1, $3); %*/ } + | args ',' tSTAR arg_value + { + /*%%%*/ + $$ = arg_concat($1, $4); + /*% + $$ = arg_add_star($1, $4); + %*/ + } ; mrhs : args ',' arg_value @@ -2615,9 +2514,9 @@ primary : literal | method_call brace_block { /*%%%*/ - block_dup_check($$); + block_dup_check($1->nd_args, $2); $2->nd_iter = $1; - $$ = $2; + $$ = $2; fixpos($$, $1); /*% $$ = dispatch2(iter_block, $1, $2); @@ -3012,13 +2911,7 @@ block_param0 : mlhs_item block_param : block_param0 { /*%%%*/ - if ($1->nd_alen == 1) { - $$ = $1->nd_head; - rb_gc_force_recycle((VALUE)$1); - } - else { - $$ = NEW_MASGN($1, 0); - } + $$ = NEW_MASGN($1, 0); /*% $$ = blockvar_new($1); %*/ @@ -3039,10 +2932,10 @@ block_param : block_param0 $$ = blockvar_add_block(blockvar_new($1), $4); %*/ } - | block_param0 ',' tSTAR lhs ',' tAMPER lhs + | block_param0 ',' tSTAR lhs ',' mlhs_post ',' tAMPER lhs { /*%%%*/ - $$ = NEW_BLOCK_PARAM($7, NEW_MASGN($1, $4)); + $$ = NEW_BLOCK_PARAM($9, NEW_MASGN($1, NEW_POSTARG($4,$6))); /*% $$ = blockvar_add_star(blockvar_new($1), $4); $$ = blockvar_add_block($$, $7); @@ -3057,6 +2950,15 @@ block_param : block_param0 $$ = blockvar_add_block($$, $6); %*/ } + | block_param0 ',' tSTAR ',' mlhs_post ',' tAMPER lhs + { + /*%%%*/ + $$ = NEW_BLOCK_PARAM($8, NEW_MASGN($1, NEW_POSTARG(-1,$5))); + /*% + $$ = blockvar_add_star(blockvar_new($1), Qnil); + $$ = blockvar_add_block($$, $6); + %*/ + } | block_param0 ',' tSTAR lhs { /*%%%*/ @@ -3065,6 +2967,14 @@ block_param : block_param0 $$ = blockvar_add_star(blockvar_new($1), $4); %*/ } + | block_param0 ',' tSTAR lhs ',' mlhs_post + { + /*%%%*/ + $$ = NEW_MASGN($1, NEW_POSTARG($4,$6)); + /*% + $$ = blockvar_add_star(blockvar_new($1), $4); + %*/ + } | block_param0 ',' tSTAR { /*%%%*/ @@ -3073,6 +2983,14 @@ block_param : block_param0 $$ = blockvar_add_star(blockvar_new($1), Qnil); %*/ } + | block_param0 ',' tSTAR ',' mlhs_post + { + /*%%%*/ + $$ = NEW_MASGN($1, NEW_MASGN($1, NEW_POSTARG(-1,$5))); + /*% + $$ = blockvar_add_star(blockvar_new($1), Qnil); + %*/ + } | tSTAR lhs ',' tAMPER lhs { /*%%%*/ @@ -3099,6 +3017,14 @@ block_param : block_param0 $$ = blockvar_add_star(blockvar_new(Qnil), $2); %*/ } + | tSTAR lhs ',' mlhs_post + { + /*%%%*/ + $$ = NEW_MASGN(0, NEW_POSTARG($2,$4)); + /*% + $$ = blockvar_add_star(blockvar_new(Qnil), $2); + %*/ + } | tSTAR { /*%%%*/ @@ -3107,6 +3033,14 @@ block_param : block_param0 $$ = blockvar_add_star(blockvar_new(Qnil), Qnil); %*/ } + | tSTAR ',' mlhs_post + { + /*%%%*/ + $$ = NEW_MASGN(0, NEW_POSTARG(-1,$3)); + /*% + $$ = blockvar_add_star(blockvar_new(Qnil), Qnil); + %*/ + } | tAMPER lhs { /*%%%*/ @@ -3204,18 +3138,15 @@ lambda : { lpar_beg = ++paren_nest; } f_larglist - { - $$ = ruby_dyna_vars; - } lambda_body { /*%%%*/ $$ = $3; - $$->nd_body = block_append($$->nd_body, $5); + $$->nd_body = block_append($$->nd_body, $4); dyna_pop($1); lpar_beg = $2; /*% - $$ = dispatch2(lambda, $3, $5); + $$ = dispatch2(lambda, $3, $4); %*/ } ; @@ -3279,9 +3210,9 @@ do_block : kDO_BLOCK block_call : command do_block { /*%%%*/ - block_dup_check($1); + block_dup_check($1->nd_args, $2); $2->nd_iter = $1; - $$ = $2; + $$ = $2; fixpos($$, $1); /*% $$ = dispatch2(iter_block, $1, $2); @@ -3290,7 +3221,7 @@ block_call : command do_block | block_call '.' operation2 opt_paren_args { /*%%%*/ - $$ = new_call($1, $3, $4); + $$ = NEW_CALL($1, $3, $4); /*% $$ = dispatch3(call, $1, ripper_id2sym('.'), $3); $$ = method_optarg($$, $4); @@ -3299,7 +3230,7 @@ block_call : command do_block | block_call tCOLON2 operation2 opt_paren_args { /*%%%*/ - $$ = new_call($1, $3, $4); + $$ = NEW_CALL($1, $3, $4); /*% $$ = dispatch3(call, $1, ripper_intern("::"), $3); $$ = method_optarg($$, $4); @@ -3310,7 +3241,7 @@ block_call : command do_block method_call : operation paren_args { /*%%%*/ - $$ = new_fcall($1, $2); + $$ = NEW_FCALL($1, $2); fixpos($$, $2); /*% $$ = method_arg(dispatch1(fcall, $1), $2); @@ -3319,7 +3250,7 @@ method_call : operation paren_args | primary_value '.' operation2 opt_paren_args { /*%%%*/ - $$ = new_call($1, $3, $4); + $$ = NEW_CALL($1, $3, $4); fixpos($$, $1); /*% $$ = dispatch3(call, $1, ripper_id2sym('.'), $3); @@ -3329,7 +3260,7 @@ method_call : operation paren_args | primary_value tCOLON2 operation2 paren_args { /*%%%*/ - $$ = new_call($1, $3, $4); + $$ = NEW_CALL($1, $3, $4); fixpos($$, $1); /*% $$ = dispatch3(call, $1, ripper_id2sym('.'), $3); @@ -3339,7 +3270,7 @@ method_call : operation paren_args | primary_value tCOLON2 operation3 { /*%%%*/ - $$ = new_call($1, $3, 0); + $$ = NEW_CALL($1, $3, 0); /*% $$ = dispatch3(call, $1, ripper_intern("::"), $3); %*/ @@ -3347,7 +3278,7 @@ method_call : operation paren_args | kSUPER paren_args { /*%%%*/ - $$ = new_super($2); + $$ = NEW_SUPER($2); /*% $$ = dispatch1(super, $2); %*/ @@ -3364,7 +3295,7 @@ method_call : operation paren_args { /*%%%*/ if (!$2) $2 = NEW_NIL(); - $$ = new_call($2, rb_intern("call"), $4); + $$ = NEW_CALL($2, rb_intern("call"), $4); fixpos($$, $2); /*% $$ = dispatch3(call, dispatch1(paren, $2), @@ -3372,7 +3303,7 @@ method_call : operation paren_args $$ = method_optarg($$, $4); %*/ } - | primary_value '[' aref_args ']' + | primary_value '[' opt_call_args ']' { /*%%%*/ if ($1 && nd_type($1) == NODE_SELF) @@ -3438,19 +3369,9 @@ brace_block : '{' $$ = dispatch2(do_block, escape_Qundef($3), $5); %*/ } - | tLAMBDA_ARG - lambda - { - /*%%%*/ - $$ = $2; - nd_set_type($$, NODE_ITER); - /*% - $$ = dispatch2(do_block, Qnil, $2); - %*/ - } ; -case_body : kWHEN when_args then +case_body : kWHEN args then compstmt cases { @@ -3461,24 +3382,6 @@ case_body : kWHEN when_args then %*/ } ; -when_args : args - | args ',' tSTAR arg_value - { - /*%%%*/ - $$ = list_append($1, NEW_WHEN($4, 0, 0)); - /*% - $$ = arg_add_star($1, $4); - %*/ - } - | tSTAR arg_value - { - /*%%%*/ - $$ = NEW_LIST(NEW_WHEN($2, 0, 0)); - /*% - $$ = arg_add_star(arg_new(), $2); - %*/ - } - ; cases : opt_else | case_body @@ -3565,7 +3468,8 @@ strings : string } ; -string : string1 +string : tCHAR + | string1 | string string1 { /*%%%*/ @@ -3996,7 +3900,15 @@ f_arglist : '(' f_args rparen f_args : f_arg ',' f_optarg ',' f_rest_arg opt_f_block_arg { /*%%%*/ - $$ = new_args($1, $3, $5, $6); + $$ = new_args($1, $3, $5, 0, $6); + /*% + $$ = dispatch4(params, $1, $3, $5, escape_Qundef($6)); + %*/ + } + | f_arg ',' f_optarg ',' f_rest_arg ',' f_post_arg opt_f_block_arg + { + /*%%%*/ + $$ = new_args($1, $3, $5, $7, $8); /*% $$ = dispatch4(params, $1, $3, $5, escape_Qundef($6)); %*/ @@ -4004,7 +3916,7 @@ f_args : f_arg ',' f_optarg ',' f_rest_arg opt_f_block_arg | f_arg ',' f_optarg opt_f_block_arg { /*%%%*/ - $$ = new_args($1, $3, 0, $4); + $$ = new_args($1, $3, 0, 0, $4); /*% $$ = dispatch4(params, $1, $3, Qnil, escape_Qundef($4)); %*/ @@ -4012,7 +3924,15 @@ f_args : f_arg ',' f_optarg ',' f_rest_arg opt_f_block_arg | f_arg ',' f_rest_arg opt_f_block_arg { /*%%%*/ - $$ = new_args($1, 0, $3, $4); + $$ = new_args($1, 0, $3, 0, $4); + /*% + $$ = dispatch4(params, $1, Qnil, $3, escape_Qundef($4)); + %*/ + } + | f_arg ',' f_rest_arg ',' f_post_arg opt_f_block_arg + { + /*%%%*/ + $$ = new_args($1, 0, $3, $5, $6); /*% $$ = dispatch4(params, $1, Qnil, $3, escape_Qundef($4)); %*/ @@ -4020,7 +3940,7 @@ f_args : f_arg ',' f_optarg ',' f_rest_arg opt_f_block_arg | f_arg opt_f_block_arg { /*%%%*/ - $$ = new_args($1, 0, 0, $2); + $$ = new_args($1, 0, 0, 0, $2); /*% $$ = dispatch4(params, $1, Qnil, Qnil, escape_Qundef($2)); %*/ @@ -4028,7 +3948,15 @@ f_args : f_arg ',' f_optarg ',' f_rest_arg opt_f_block_arg | f_optarg ',' f_rest_arg opt_f_block_arg { /*%%%*/ - $$ = new_args(0, $1, $3, $4); + $$ = new_args(0, $1, $3, 0, $4); + /*% + $$ = dispatch4(params, Qnil, $1, $3, escape_Qundef($4)); + %*/ + } + | f_optarg ',' f_rest_arg ',' f_post_arg opt_f_block_arg + { + /*%%%*/ + $$ = new_args(0, $1, $3, $5, $6); /*% $$ = dispatch4(params, Qnil, $1, $3, escape_Qundef($4)); %*/ @@ -4036,7 +3964,7 @@ f_args : f_arg ',' f_optarg ',' f_rest_arg opt_f_block_arg | f_optarg opt_f_block_arg { /*%%%*/ - $$ = new_args(0, $1, 0, $2); + $$ = new_args(0, $1, 0, 0, $2); /*% $$ = dispatch4(params, Qnil, $1, Qnil, escape_Qundef($2)); %*/ @@ -4044,7 +3972,15 @@ f_args : f_arg ',' f_optarg ',' f_rest_arg opt_f_block_arg | f_rest_arg opt_f_block_arg { /*%%%*/ - $$ = new_args(0, 0, $1, $2); + $$ = new_args(0, 0, $1, 0, $2); + /*% + $$ = dispatch4(params, Qnil, Qnil, $1, escape_Qundef($2)); + %*/ + } + | f_rest_arg ',' f_post_arg opt_f_block_arg + { + /*%%%*/ + $$ = new_args(0, 0, $1, $3, $4); /*% $$ = dispatch4(params, Qnil, Qnil, $1, escape_Qundef($2)); %*/ @@ -4052,7 +3988,7 @@ f_args : f_arg ',' f_optarg ',' f_rest_arg opt_f_block_arg | f_block_arg { /*%%%*/ - $$ = new_args(0, 0, 0, $1); + $$ = new_args(0, 0, 0, 0, $1); /*% $$ = dispatch4(params, Qnil, Qnil, Qnil, $1); %*/ @@ -4060,7 +3996,7 @@ f_args : f_arg ',' f_optarg ',' f_rest_arg opt_f_block_arg | /* none */ { /*%%%*/ - $$ = new_args(0, 0, 0, 0); + $$ = new_args(0, 0, 0, 0, 0); /*% $$ = dispatch4(params, Qnil, Qnil, Qnil, Qnil); %*/ @@ -4142,6 +4078,24 @@ f_arg : f_norm_arg } ; +f_post_arg : f_norm_arg + { + /*%%%*/ + $$ = NEW_LIST(assignable($1, 0)); + /*% + $$ = mlhs_add(mlhs_new(), $1); + %*/ + } + | f_post_arg ',' f_norm_arg + { + /*%%%*/ + $$ = list_append($1, assignable($3, 0)); + /*% + $$ = mlhs_add($1, $3); + %*/ + } + ; + f_opt : tIDENTIFIER '=' arg_value { /*%%%*/ @@ -5783,7 +5737,6 @@ parser_yylex(struct parser_params *parser) c = nextc(); if (c == '<' && lex_state != EXPR_END && - lex_state != EXPR_END2 && lex_state != EXPR_DOT && lex_state != EXPR_ENDARG && lex_state != EXPR_CLASS && @@ -5863,7 +5816,6 @@ parser_yylex(struct parser_params *parser) case '?': if (lex_state == EXPR_END || - lex_state == EXPR_END2 || lex_state == EXPR_ENDARG) { lex_state = EXPR_VALUE; return '?'; @@ -5906,20 +5858,30 @@ parser_yylex(struct parser_params *parser) lex_state = EXPR_VALUE; return '?'; } - else if (ismbchar(uc)) { - rb_warnI("multibyte character literal not supported yet; use ?\\%.3o", c); - goto ternary; + newtok(); + if (ismbchar(uc)) { + int i, len = mbclen(uc)-1; + + tokadd(c); + for (i = 0; i < len; i++) { + c = nextc(); + tokadd(c); + } } else if ((ISALNUM(c) || c == '_') && lex_p < lex_pend && is_identchar(*lex_p)) { goto ternary; } else if (c == '\\') { c = read_escape(); + tokadd(c); } - c &= 0xff; + else { + tokadd(c); + } + tokfix(); + set_yylval_str(rb_str_new(tok(), toklen())); lex_state = EXPR_END; - set_yylval_literal(INT2FIX(c)); - return tINTEGER; + return tCHAR; case '&': if ((c = nextc()) == '&') { @@ -6029,15 +5991,7 @@ parser_yylex(struct parser_params *parser) if (c == '>') { enum lex_state_e state = lex_state; lex_state = EXPR_ARG; - switch (state) { - case EXPR_CMDARG: - case EXPR_ENDARG: - case EXPR_ARG: - case EXPR_END: - return tLAMBDA_ARG; - default: - return tLAMBDA; - } + return tLAMBDA; } if (IS_BEG() || (IS_ARG() && space_seen && !ISSPACE(c))) { @@ -6307,7 +6261,7 @@ parser_yylex(struct parser_params *parser) lex_state = EXPR_DOT; return tCOLON2; } - if (lex_state == EXPR_END || lex_state == EXPR_END2 || + if (lex_state == EXPR_END || lex_state == EXPR_ENDARG || ISSPACE(c)) { pushback(c); lex_state = EXPR_BEG; @@ -6369,10 +6323,6 @@ parser_yylex(struct parser_params *parser) return '^'; case ';': - if (lex_state != EXPR_END2 && peek(';')) { - lex_state = EXPR_END2; - return kEND; - } lex_state = EXPR_BEG; command_start = Qtrue; return ';'; @@ -6446,7 +6396,7 @@ parser_yylex(struct parser_params *parser) --paren_nest; return tLAMBEG; } - if (IS_ARG() || lex_state == EXPR_END || lex_state == EXPR_END2) + if (IS_ARG() || lex_state == EXPR_END) c = '{'; /* block (primary) */ else if (lex_state == EXPR_ENDARG) c = tLBRACE_ARG; /* block (expr) */ @@ -6880,13 +6830,13 @@ rb_node_newnode(enum node_type type, VALUE a0, VALUE a1, VALUE a2) return n; } -static enum node_type +enum node_type nodetype(NODE *node) /* for debug */ { return (enum node_type)nd_type(node); } -static int +int nodeline(NODE *node) { return nd_line(node); @@ -7284,10 +7234,10 @@ aryset_gen(struct parser_params *parser, NODE *recv, NODE *idx) } static void -block_dup_check(NODE *node) +block_dup_check(NODE *node1, NODE *node2) { - if (node && nd_type(node) == NODE_BLOCK_PASS) { - compile_error(PARSER_ARG "both block arg and actual block given"); + if (node2 && node1 && nd_type(node1) == NODE_BLOCK_PASS) { + compile_error("both block arg and actual block given"); } } @@ -7326,17 +7276,39 @@ static NODE * arg_concat(NODE *node1, NODE *node2) { if (!node2) return node1; + if (nd_type(node1) == NODE_BLOCK_PASS) { + node1->nd_iter = arg_concat(node1->nd_iter, node2); + return node1; + } return NEW_ARGSCAT(node1, node2); } static NODE * -arg_add(NODE *node1, NODE *node2) +arg_append(NODE *node1, NODE *node2) { if (!node1) return NEW_LIST(node2); - if (nd_type(node1) == NODE_ARRAY) { + switch (nd_type(node1)) { + case NODE_ARRAY: return list_append(node1, node2); + case NODE_BLOCK_PASS: + node1->nd_head = arg_append(node1->nd_head, node2); + return node1; + default: + return NEW_ARGSCAT(node1, node2); } - else { +} + +static NODE * +arg_add(NODE *node1, NODE *node2) +{ + if (!node1) return NEW_LIST(node2); + switch (nd_type(node1)) { + case NODE_ARRAY: + return list_append(node1, node2); + case NODE_BLOCK_PASS: + node1->nd_head = arg_add(node1->nd_head, node2); + return node1; + default: return NEW_ARGSPUSH(node1, node2); } } @@ -7427,7 +7399,7 @@ value_expr_gen(struct parser_params *parser, NODE *node) static void void_expr_gen(struct parser_params *parser, NODE *node) { - char *useless = 0; + const char *useless = 0; if (!RTEST(ruby_verbose)) return; @@ -7814,9 +7786,6 @@ ret_args(NODE *node) nd_set_type(node, NODE_VALUES); } } - else if (nd_type(node) == NODE_SPLAT) { - node = NEW_SVALUE(node); - } } return node; } @@ -7871,26 +7840,6 @@ arg_blk_pass(NODE *node1, NODE *node2) return node1; } -static NODE* -arg_prepend(NODE *node1, NODE *node2) -{ - switch (nd_type(node2)) { - case NODE_ARRAY: - return list_concat(NEW_LIST(node1), node2); - - case NODE_SPLAT: - return arg_concat(node1, node2->nd_head); - - case NODE_BLOCK_PASS: - node2->nd_body = arg_prepend(node1, node2->nd_body); - return node2; - - default: - rb_bug("unknown nodetype(%d) for arg_prepend", nd_type(node2)); - } - return 0; /* not reached */ -} - static int arg_dup_check(ID vid, VALUE m, VALUE list, NODE *node) { @@ -7904,66 +7853,41 @@ arg_dup_check(ID vid, VALUE m, VALUE list, NODE *node) } static NODE* -new_args_gen(struct parser_params *parser, VALUE m, NODE *o, NODE *r, NODE *b) +new_args_gen(struct parser_params *parser, VALUE m, NODE *o, NODE *r, NODE *p, NODE *b) { int saved_line = ruby_sourceline; - NODE *tmp; + NODE *node; VALUE list; list = rb_ary_new(); - tmp = o; - while (tmp) { - if (!tmp->nd_head) break; - if (arg_dup_check(tmp->nd_head->nd_vid, m, list, tmp)) { + node = o; + while (node) { + if (!node->nd_head) break; + if (arg_dup_check(node->nd_head->nd_vid, m, list, node)) { yyerror("duplicated optional argument name"); return 0; } - tmp = tmp->nd_next; + node = node->nd_next; } if (RTEST(r)) { if (arg_dup_check(r->nd_vid, m, list, r)) { yyerror("duplicated rest argument name"); return 0; } + if (p) { + r = NEW_POSTARG(r, p); + } } + node = NEW_ARGS(m, o, r); if (b) { if (arg_dup_check(b->nd_vid, m, list, b)) { yyerror("duplicated block argument name"); return 0; } + node = block_append(node, b); } ruby_sourceline = saved_line; - return block_append(NEW_ARGS(m, o, r), b); -} - -static NODE* -new_call(NODE *r, ID m, NODE *a) -{ - if (a && nd_type(a) == NODE_BLOCK_PASS) { - a->nd_iter = NEW_CALL(r,m,a->nd_head); - return a; - } - return NEW_CALL(r,m,a); -} - -static NODE* -new_fcall_gen(struct parser_params *parser, ID m, NODE *a) -{ - if (a && nd_type(a) == NODE_BLOCK_PASS) { - a->nd_iter = NEW_FCALL(m,a->nd_head); - return a; - } - return NEW_FCALL(m, a); -} - -static NODE* -new_super(NODE *a) -{ - if (a && nd_type(a) == NODE_BLOCK_PASS) { - a->nd_iter = NEW_SUPER(a->nd_head); - return a; - } - return NEW_SUPER(a); + return node; } static void @@ -8236,7 +8160,7 @@ rb_parser_while_loop(NODE *node, int chop, int split) static const struct { ID token; - char *name; + const char *name; } op_tbl[] = { {tDOT2, ".."}, {tDOT3, "..."}, @@ -8430,7 +8354,7 @@ rb_intern(const char *name) if (*op_tbl[i].name == *name && strcmp(op_tbl[i].name, name) == 0) { id = op_tbl[i].token; - goto id_regist; + goto id_register; } } } @@ -8444,7 +8368,7 @@ rb_intern(const char *name) id = rb_intern(buf); if (id > tLAST_TOKEN && !is_attrset_id(id)) { id = rb_id_attrset(id); - goto id_regist; + goto id_register; } id = ID_ATTRSET; } @@ -8464,17 +8388,17 @@ rb_intern(const char *name) if (*m) id = ID_JUNK; new_id: id |= ++global_symbols.last_id << ID_SCOPE_SHIFT; - id_regist: + id_register: name = strdup(name); st_add_direct(global_symbols.tbl, (st_data_t)name, id); st_add_direct(global_symbols.rev, id, (st_data_t)name); return id; } -char * +const char * rb_id2name(ID id) { - char *name; + const char *name; st_data_t data; if (id < tLAST_TOKEN) { diff --git a/prec.c b/prec.c index cd37af960b..80396dfdef 100644 --- a/prec.c +++ b/prec.c @@ -55,9 +55,9 @@ prec_prec_i(VALUE x) /* * call-seq: - * num.prec_f => Integer + * num.prec_f => Float * - * Returns an +Float+ converted from _num_. It is equivalent + * Returns a +Float+ converted from _num_. It is equivalent * to prec(Float). */ diff --git a/process.c b/process.c index d566c18b6b..3112ecfe17 100644 --- a/process.c +++ b/process.c @@ -1296,10 +1296,7 @@ proc_syswait(pid) * +chfunc+ must not raise any exceptions. */ int -rb_fork(status, chfunc, charg) - int *status; - int (*chfunc)(void *); - void *charg; +rb_fork(int *status, int (*chfunc)(void*), void *charg) { int pid, err, state = 0; #ifdef FD_CLOEXEC @@ -1627,12 +1624,11 @@ rb_f_spawn(int argc, VALUE *argv) * call-seq: * sleep([duration]) => fixnum * - * Suspends the current thread for _duration_ seconds (which may be - * any number, including a +Float+ with fractional seconds). Returns the actual - * number of seconds slept (rounded), which may be less than that asked - * for if the thread was interrupted by a +SIGALRM+, or if - * another thread calls Thread#run. Zero arguments - * causes +sleep+ to sleep forever. + * Suspends the current thread for _duration_ seconds (which may be any number, + * including a +Float+ with fractional seconds). Returns the actual number of + * seconds slept (rounded), which may be less than that asked for if another + * thread calls Thread#run. Zero arguments causes +sleep+ to sleep + * forever. * * Time.new #=> Wed Apr 09 08:56:32 CDT 2003 * sleep 1.2 #=> 1 @@ -3314,8 +3310,7 @@ p_uid_have_saved_id(void) #if defined(HAVE_SETRESUID) || defined(HAVE_SETEUID) || defined(_POSIX_SAVED_IDS) static VALUE -p_uid_sw_ensure(id) - int id; +p_uid_sw_ensure(int id) { under_uid_switch = 0; return rb_seteuid_core(id); @@ -3336,8 +3331,7 @@ p_uid_sw_ensure(id) */ static VALUE -p_uid_switch(obj) - VALUE obj; +p_uid_switch(VALUE obj) { int uid, euid; @@ -3423,8 +3417,7 @@ p_gid_have_saved_id(void) #if defined(HAVE_SETRESGID) || defined(HAVE_SETEGID) || defined(_POSIX_SAVED_IDS) static VALUE -p_gid_sw_ensure(id) - int id; +p_gid_sw_ensure(int id) { under_gid_switch = 0; return rb_setegid_core(id); @@ -3445,8 +3438,7 @@ p_gid_sw_ensure(id) */ static VALUE -p_gid_switch(obj) - VALUE obj; +p_gid_switch(VALUE obj) { int gid, egid; diff --git a/range.c b/range.c index ce744e6a7f..96eb2614e8 100644 --- a/range.c +++ b/range.c @@ -654,8 +654,7 @@ range_include(VALUE range, VALUE val) */ static VALUE -range_cover(range, val) - VALUE range, val; +range_cover(VALUE range, VALUE val) { VALUE beg, end; diff --git a/re.c b/re.c index 08df5b38f3..8730723b91 100644 --- a/re.c +++ b/re.c @@ -76,8 +76,9 @@ static const char casetable[] = { #endif int -rb_memcicmp(char *p1, char *p2, long len) +rb_memcicmp(const void *x, const void *y, long len) { + const unsigned char *p1 = x, *p2 = y; int tmp; while (len--) { @@ -88,7 +89,7 @@ rb_memcicmp(char *p1, char *p2, long len) } int -rb_memcmp(char *p1, char *p2, long len) +rb_memcmp(const void *p1, const void *p2, long len) { if (!ruby_ignorecase) { return memcmp(p1, p2, len); @@ -97,10 +98,10 @@ rb_memcmp(char *p1, char *p2, long len) } long -rb_memsearch(char *x0, long m, char *y0, long n) +rb_memsearch(const void *x0, long m, const void *y0, long n) { - unsigned char *x = (unsigned char *)x0, *y = (unsigned char *)y0; - unsigned char *s, *e; + const unsigned char *x = x0, *y = y0; + const unsigned char *s, *e; long i; int d; unsigned long hx, hy; @@ -151,7 +152,9 @@ rb_memsearch(char *x0, long m, char *y0, long n) return s-y; } +#define REG_LITERAL FL_USER5 #define REG_CASESTATE FL_USER0 + #define KCODE_NONE 0 #define KCODE_EUC FL_USER1 #define KCODE_SJIS FL_USER2 @@ -167,10 +170,8 @@ rb_memsearch(char *x0, long m, char *y0, long n) #define ARG_KCODE_UTF8 (ARG_KCODE_UNIT * 4) #define ARG_KCODE_MASK (ARG_KCODE_UNIT * 7) - static int reg_kcode = DEFAULT_KCODE; - static int char_to_option(int c) { int val; @@ -505,13 +506,13 @@ rb_reg_to_s(VALUE re) int options, opt; const int embeddable = ONIG_OPTION_MULTILINE|ONIG_OPTION_IGNORECASE|ONIG_OPTION_EXTEND; long len; - const char* ptr; + const UChar* ptr; VALUE str = rb_str_buf_new2("(?"); rb_reg_check(re); options = RREGEXP(re)->ptr->options; - ptr = RREGEXP(re)->str; + ptr = (UChar*)RREGEXP(re)->str; len = RREGEXP(re)->len; again: if (len >= 4 && ptr[0] == '(' && ptr[1] == '?') { @@ -566,7 +567,7 @@ rb_reg_to_s(VALUE re) } if (err) { options = RREGEXP(re)->ptr->options; - ptr = RREGEXP(re)->str; + ptr = (UChar*)RREGEXP(re)->str; len = RREGEXP(re)->len; } } @@ -583,7 +584,7 @@ rb_reg_to_s(VALUE re) } rb_str_buf_cat2(str, ":"); - rb_reg_expr_str(str, ptr, len); + rb_reg_expr_str(str, (char*)ptr, len); rb_str_buf_cat2(str, ")"); OBJ_INFECT(str, re); @@ -1247,12 +1248,12 @@ match_captures(VALUE match) } static int -name_to_backref_number(struct re_registers *regs, VALUE regexp, char* name, char* name_end) +name_to_backref_number(struct re_registers *regs, VALUE regexp, const char* name, const char* name_end) { int num; num = onig_name_to_backref_number(RREGEXP(regexp)->ptr, - (unsigned char* )name, (unsigned char* )name_end, regs); + (const unsigned char* )name, (const unsigned char* )name_end, regs); if (num >= 1) { return num; } @@ -1301,7 +1302,7 @@ match_aref(int argc, VALUE *argv, VALUE match) } } else { - char *p; + const char *p; int num; switch (TYPE(idx)) { @@ -1336,6 +1337,8 @@ match_entry(VALUE match, long n) /* * call-seq: + if (!OBJ_TAINTED(obj) && rb_safe_level() >= 4) + rb_raise(rb_eSecurityError, "Insecure: can't modify regexp"); * mtch.select([index]*) => array * * Uses each index to access the matching values, returning an array of @@ -1437,6 +1440,11 @@ rb_reg_initialize(VALUE obj, const char *s, long len, { struct RRegexp *re = RREGEXP(obj); + if (!OBJ_TAINTED(obj) && rb_safe_level() >= 4) + rb_raise(rb_eSecurityError, "Insecure: can't modify regexp"); + rb_check_frozen(obj); + if (FL_TEST(obj, REG_LITERAL)) + rb_raise(rb_eSecurityError, "can't modify literal regexp"); if (re->ptr) onig_free(re->ptr); if (re->str) free(re->str); re->ptr = 0; @@ -1459,6 +1467,7 @@ rb_reg_initialize(VALUE obj, const char *s, long len, if (options & ARG_KCODE_MASK) { kcode_reset_option(); } + if (ce) FL_SET(obj, REG_LITERAL); } static VALUE @@ -1760,7 +1769,6 @@ rb_reg_initialize_m(int argc, VALUE *argv, VALUE self) long len; int flags = 0; - rb_check_frozen(self); if (argc == 0 || argc > 3) { rb_raise(rb_eArgError, "wrong number of arguments"); } diff --git a/regerror.c b/regerror.c index f9b35dcb99..811ca2b012 100644 --- a/regerror.c +++ b/regerror.c @@ -276,8 +276,8 @@ onig_snprintf_with_pattern(buf, bufsize, enc, pat, pat_end, fmt, va_alist) UChar bs[6]; va_list args; - va_init_list(args, (char* )fmt); - n = vsnprintf((char* )buf, bufsize, (char* )fmt, args); + va_init_list(args, (const char* )fmt); + n = vsnprintf((char* )buf, bufsize, (const char* )fmt, args); va_end(args); need = (pat_end - pat) * 4 + 4; diff --git a/regparse.c b/regparse.c index e1930a1c1f..21ec65e86d 100644 --- a/regparse.c +++ b/regparse.c @@ -4487,11 +4487,11 @@ parse_effect(Node** np, OnigToken* tok, int term, UChar** src, UChar* end, return 0; } -static char* PopularQStr[] = { +static const char* PopularQStr[] = { "?", "*", "+", "??", "*?", "+?" }; -static char* ReduceQStr[] = { +static const char* ReduceQStr[] = { "", "", "*", "*?", "??", "+ and ??", "+? and ?" }; diff --git a/ruby.1 b/ruby.1 index 5587a6d9a6..f240f2f22b 100644 --- a/ruby.1 +++ b/ruby.1 @@ -309,9 +309,10 @@ this switch, unless you are going to debug the Ruby interpreter. .Sh ENVIRONMENT .Bl -tag -width "RUBYLIB_PREFIX" -compact .It Ev RUBYLIB -A colon-separated list of directories that are appended to Ruby's +A colon-separated list of directories that are added to Ruby's library load path -.Pf ( Li "$:" ) . +.Pf ( Li "$:" ) . Directories from this environment variable are searched +before the standard load path is searched. .Pp e.g.: .Dl RUBYLIB="$HOME/lib/ruby:$HOME/lib/rubyext" diff --git a/ruby.c b/ruby.c index 338631d186..42d9a48bfa 100644 --- a/ruby.c +++ b/ruby.c @@ -73,7 +73,7 @@ usage(const char *name) /* This message really ought to be max 23 lines. * Removed -h because the user already knows that option. Others? */ - static char *usage_msg[] = { + static const char *usage_msg[] = { "-0[octal] specify record separator (\\0, if no argument)", "-a autosplit mode with -n or -p (splits $_ into $F)", "-c check syntax only", @@ -99,7 +99,7 @@ usage(const char *name) "--version print the version", NULL }; - char **p = usage_msg; + const char **p = usage_msg; printf("Usage: %s [switches] [--] [programfile] [arguments]\n", name); while (*p) diff --git a/ruby.h b/ruby.h index 3dd29567a8..d6190c0ee8 100644 --- a/ruby.h +++ b/ruby.h @@ -547,7 +547,7 @@ void rb_gc_register_address(VALUE*); void rb_gc_unregister_address(VALUE*); ID rb_intern(const char*); -char *rb_id2name(ID); +const char *rb_id2name(ID); ID rb_to_id(VALUE); char *rb_class2name(VALUE); @@ -629,6 +629,7 @@ RUBY_EXTERN VALUE rb_mGC; RUBY_EXTERN VALUE rb_mMath; RUBY_EXTERN VALUE rb_mProcess; +RUBY_EXTERN VALUE rb_cBasicObject; RUBY_EXTERN VALUE rb_cObject; RUBY_EXTERN VALUE rb_cArray; RUBY_EXTERN VALUE rb_cValues; diff --git a/sample/test.rb b/sample/test.rb index 8003e8743f..e6a500c4b5 100644 --- a/sample/test.rb +++ b/sample/test.rb @@ -54,13 +54,13 @@ a = [*[]]; test_ok(a == []) a = [*[1]]; test_ok(a == [1]) a = [*[1,2]]; test_ok(a == [1,2]) -a = *[]; test_ok(a == nil) -a = *[1]; test_ok(a == 1) -a = *[nil]; test_ok(a == nil) -a = *[[]]; test_ok(a == []) +a = *[]; test_ok(a == []) +a = *[1]; test_ok(a == [1]) +a = *[nil]; test_ok(a == [nil]) +a = *[[]]; test_ok(a == [[]]) a = *[1,2]; test_ok(a == [1,2]) -a = *[*[]]; test_ok(a == nil) -a = *[*[1]]; test_ok(a == 1) +a = *[*[]]; test_ok(a == []) +a = *[*[1]]; test_ok(a == [1]) a = *[*[1,2]]; test_ok(a == [1,2]) a, = nil; test_ok(a == nil) @@ -87,14 +87,14 @@ a, = *[*[1,2]]; test_ok(a == 1) *a = nil; test_ok(a == [nil]) *a = 1; test_ok(a == [1]) -*a = []; test_ok(a == [[]]) -*a = [1]; test_ok(a == [[1]]) -*a = [nil]; test_ok(a == [[nil]]) -*a = [[]]; test_ok(a == [[[]]]) -*a = [1,2]; test_ok(a == [[1,2]]) -*a = [*[]]; test_ok(a == [[]]) -*a = [*[1]]; test_ok(a == [[1]]) -*a = [*[1,2]]; test_ok(a == [[1,2]]) +*a = []; test_ok(a == []) +*a = [1]; test_ok(a == [1]) +*a = [nil]; test_ok(a == [nil]) +*a = [[]]; test_ok(a == [[]]) +*a = [1,2]; test_ok(a == [1,2]) +*a = [*[]]; test_ok(a == []) +*a = [*[1]]; test_ok(a == [1]) +*a = [*[1,2]]; test_ok(a == [1,2]) *a = *[]; test_ok(a == []) *a = *[1]; test_ok(a == [1]) @@ -127,18 +127,13 @@ a,b,*c = *[*[1,2]]; test_ok([a,b,c] == [1,2,[]]) def f; yield nil; end; f {|a| test_ok(a == nil)} def f; yield 1; end; f {|a| test_ok(a == 1)} -def f; yield []; end; f {|a| test_ok(a == [])} -def f; yield [1]; end; f {|a| test_ok(a == [1])} -def f; yield [nil]; end; f {|a| test_ok(a == [nil])} -def f; yield [[]]; end; f {|a| test_ok(a == [[]])} -def f; yield [*[]]; end; f {|a| test_ok(a == [])} -def f; yield [*[1]]; end; f {|a| test_ok(a == [1])} -def f; yield [*[1,2]]; end; f {|a| test_ok(a == [1,2])} - +def f; yield *[]; end; f {|a| test_ok(a == nil)} def f; yield *[1]; end; f {|a| test_ok(a == 1)} def f; yield *[nil]; end; f {|a| test_ok(a == nil)} def f; yield *[[]]; end; f {|a| test_ok(a == [])} +def f; yield *[*[]]; end; f {|a| test_ok(a == nil)} def f; yield *[*[1]]; end; f {|a| test_ok(a == 1)} +def f; yield *[*[1,2]]; end; f {|a| test_ok(a == 1)} def f; yield; end; f {|a,| test_ok(a == nil)} def f; yield nil; end; f {|a,| test_ok(a == nil)} @@ -162,14 +157,14 @@ def f; yield *[*[1,2]]; end; f {|a,| test_ok(a == 1)} def f; yield; end; f {|*a| test_ok(a == [])} def f; yield nil; end; f {|*a| test_ok(a == [nil])} def f; yield 1; end; f {|*a| test_ok(a == [1])} -def f; yield []; end; f {|*a| test_ok(a == [[]])} -def f; yield [1]; end; f {|*a| test_ok(a == [[1]])} -def f; yield [nil]; end; f {|*a| test_ok(a == [[nil]])} -def f; yield [[]]; end; f {|*a| test_ok(a == [[[]]])} -def f; yield [1,2]; end; f {|*a| test_ok(a == [[1,2]])} -def f; yield [*[]]; end; f {|*a| test_ok(a == [[]])} -def f; yield [*[1]]; end; f {|*a| test_ok(a == [[1]])} -def f; yield [*[1,2]]; end; f {|*a| test_ok(a == [[1,2]])} +def f; yield []; end; f {|*a| test_ok(a == [])} +def f; yield [1]; end; f {|*a| test_ok(a == [1])} +def f; yield [nil]; end; f {|*a| test_ok(a == [nil])} +def f; yield [[]]; end; f {|*a| test_ok(a == [[]])} +def f; yield [1,2]; end; f {|*a| test_ok(a == [1,2])} +def f; yield [*[]]; end; f {|*a| test_ok(a == [])} +def f; yield [*[1]]; end; f {|*a| test_ok(a == [1])} +def f; yield [*[1,2]]; end; f {|*a| test_ok(a == [1,2])} def f; yield *[]; end; f {|*a| test_ok(a == [])} def f; yield *[1]; end; f {|*a| test_ok(a == [1])} @@ -209,39 +204,39 @@ def r; return [*[]]; end; a = r(); test_ok(a == []) def r; return [*[1]]; end; a = r(); test_ok(a == [1]) def r; return [*[1,2]]; end; a = r(); test_ok(a == [1,2]) -def r; return *[]; end; a = r(); test_ok(a == nil) -def r; return *[1]; end; a = r(); test_ok(a == 1) -def r; return *[nil]; end; a = r(); test_ok(a == nil) -def r; return *[[]]; end; a = r(); test_ok(a == []) -def r; return *[*[]]; end; a = r(); test_ok(a == nil) -def r; return *[*[1]]; end; a = r(); test_ok(a == 1) +def r; return *[]; end; a = r(); test_ok(a == []) +def r; return *[1]; end; a = r(); test_ok(a == [1]) +def r; return *[nil]; end; a = r(); test_ok(a == [nil]) +def r; return *[[]]; end; a = r(); test_ok(a == [[]]) +def r; return *[*[]]; end; a = r(); test_ok(a == []) +def r; return *[*[1]]; end; a = r(); test_ok(a == [1]) def r; return *[*[1,2]]; end; a = r(); test_ok(a == [1,2]) -def r; return *[[]]; end; a = *r(); test_ok(a == nil) +def r; return *[[]]; end; a = *r(); test_ok(a == [[]]) def r; return *[*[1,2]]; end; a = *r(); test_ok(a == [1,2]) def r; return; end; *a = r(); test_ok(a == [nil]) def r; return nil; end; *a = r(); test_ok(a == [nil]) def r; return 1; end; *a = r(); test_ok(a == [1]) -def r; return []; end; *a = r(); test_ok(a == [[]]) -def r; return [1]; end; *a = r(); test_ok(a == [[1]]) -def r; return [nil]; end; *a = r(); test_ok(a == [[nil]]) -def r; return [[]]; end; *a = r(); test_ok(a == [[[]]]) -def r; return [1,2]; end; *a = r(); test_ok(a == [[1,2]]) -def r; return [*[]]; end; *a = r(); test_ok(a == [[]]) -def r; return [*[1]]; end; *a = r(); test_ok(a == [[1]]) -def r; return [*[1,2]]; end; *a = r(); test_ok(a == [[1,2]]) - -def r; return *[]; end; *a = r(); test_ok(a == [nil]) +def r; return []; end; *a = r(); test_ok(a == []) +def r; return [1]; end; *a = r(); test_ok(a == [1]) +def r; return [nil]; end; *a = r(); test_ok(a == [nil]) +def r; return [[]]; end; *a = r(); test_ok(a == [[]]) +def r; return [1,2]; end; *a = r(); test_ok(a == [1,2]) +def r; return [*[]]; end; *a = r(); test_ok(a == []) +def r; return [*[1]]; end; *a = r(); test_ok(a == [1]) +def r; return [*[1,2]]; end; *a = r(); test_ok(a == [1,2]) + +def r; return *[]; end; *a = r(); test_ok(a == []) def r; return *[1]; end; *a = r(); test_ok(a == [1]) def r; return *[nil]; end; *a = r(); test_ok(a == [nil]) def r; return *[[]]; end; *a = r(); test_ok(a == [[]]) -def r; return *[1,2]; end; *a = r(); test_ok(a == [[1,2]]) -def r; return *[*[]]; end; *a = r(); test_ok(a == [nil]) +def r; return *[1,2]; end; *a = r(); test_ok(a == [1,2]) +def r; return *[*[]]; end; *a = r(); test_ok(a == []) def r; return *[*[1]]; end; *a = r(); test_ok(a == [1]) -def r; return *[*[1,2]]; end; *a = r(); test_ok(a == [[1,2]]) +def r; return *[*[1,2]]; end; *a = r(); test_ok(a == [1,2]) -def r; return *[[]]; end; *a = *r(); test_ok(a == []) +def r; return *[[]]; end; *a = *r(); test_ok(a == [[]]) def r; return *[1,2]; end; *a = *r(); test_ok(a == [1,2]) def r; return *[*[1,2]]; end; *a = *r(); test_ok(a == [1,2]) @@ -260,7 +255,7 @@ def r; return [*[1,2]]; end; a,b,*c = r(); test_ok([a,b,c] == [1,2,[]]) def r; return *[]; end; a,b,*c = r(); test_ok([a,b,c] == [nil,nil,[]]) def r; return *[1]; end; a,b,*c = r(); test_ok([a,b,c] == [1,nil,[]]) def r; return *[nil]; end; a,b,*c = r(); test_ok([a,b,c] == [nil,nil,[]]) -def r; return *[[]]; end; a,b,*c = r(); test_ok([a,b,c] == [nil,nil,[]]) +def r; return *[[]]; end; a,b,*c = r(); test_ok([a,b,c] == [[],nil,[]]) def r; return *[1,2]; end; a,b,*c = r(); test_ok([a,b,c] == [1,2,[]]) def r; return *[*[]]; end; a,b,*c = r(); test_ok([a,b,c] == [nil,nil,[]]) def r; return *[*[1]]; end; a,b,*c = r(); test_ok([a,b,c] == [1,nil,[]]) @@ -316,36 +311,36 @@ a = loop do break [*[]]; end; test_ok(a == []) a = loop do break [*[1]]; end; test_ok(a == [1]) a = loop do break [*[1,2]]; end; test_ok(a == [1,2]) -a = loop do break *[]; end; test_ok(a == nil) -a = loop do break *[1]; end; test_ok(a == 1) -a = loop do break *[nil]; end; test_ok(a == nil) -a = loop do break *[[]]; end; test_ok(a == []) -a = loop do break *[*[]]; end; test_ok(a == nil) -a = loop do break *[*[1]]; end; test_ok(a == 1) +a = loop do break *[]; end; test_ok(a == []) +a = loop do break *[1]; end; test_ok(a == [1]) +a = loop do break *[nil]; end; test_ok(a == [nil]) +a = loop do break *[[]]; end; test_ok(a == [[]]) +a = loop do break *[*[]]; end; test_ok(a == []) +a = loop do break *[*[1]]; end; test_ok(a == [1]) a = loop do break *[*[1,2]]; end; test_ok(a == [1,2]) *a = loop do break; end; test_ok(a == [nil]) *a = loop do break nil; end; test_ok(a == [nil]) *a = loop do break 1; end; test_ok(a == [1]) -*a = loop do break []; end; test_ok(a == [[]]) -*a = loop do break [1]; end; test_ok(a == [[1]]) -*a = loop do break [nil]; end; test_ok(a == [[nil]]) -*a = loop do break [[]]; end; test_ok(a == [[[]]]) -*a = loop do break [1,2]; end; test_ok(a == [[1,2]]) -*a = loop do break [*[]]; end; test_ok(a == [[]]) -*a = loop do break [*[1]]; end; test_ok(a == [[1]]) -*a = loop do break [*[1,2]]; end; test_ok(a == [[1,2]]) - -*a = loop do break *[]; end; test_ok(a == [nil]) +*a = loop do break []; end; test_ok(a == []) +*a = loop do break [1]; end; test_ok(a == [1]) +*a = loop do break [nil]; end; test_ok(a == [nil]) +*a = loop do break [[]]; end; test_ok(a == [[]]) +*a = loop do break [1,2]; end; test_ok(a == [1,2]) +*a = loop do break [*[]]; end; test_ok(a == []) +*a = loop do break [*[1]]; end; test_ok(a == [1]) +*a = loop do break [*[1,2]]; end; test_ok(a == [1,2]) + +*a = loop do break *[]; end; test_ok(a == []) *a = loop do break *[1]; end; test_ok(a == [1]) *a = loop do break *[nil]; end; test_ok(a == [nil]) *a = loop do break *[[]]; end; test_ok(a == [[]]) -*a = loop do break *[1,2]; end; test_ok(a == [[1,2]]) -*a = loop do break *[*[]]; end; test_ok(a == [nil]) +*a = loop do break *[1,2]; end; test_ok(a == [1,2]) +*a = loop do break *[*[]]; end; test_ok(a == []) *a = loop do break *[*[1]]; end; test_ok(a == [1]) -*a = loop do break *[*[1,2]]; end; test_ok(a == [[1,2]]) +*a = loop do break *[*[1,2]]; end; test_ok(a == [1,2]) -*a = *loop do break *[[]]; end; test_ok(a == []) +*a = *loop do break *[[]]; end; test_ok(a == [[]]) *a = *loop do break *[1,2]; end; test_ok(a == [1,2]) *a = *loop do break *[*[1,2]]; end; test_ok(a == [1,2]) @@ -364,7 +359,7 @@ a,b,*c = loop do break [*[1,2]]; end; test_ok([a,b,c] == [1,2,[]]) a,b,*c = loop do break *[]; end; test_ok([a,b,c] == [nil,nil,[]]) a,b,*c = loop do break *[1]; end; test_ok([a,b,c] == [1,nil,[]]) a,b,*c = loop do break *[nil]; end; test_ok([a,b,c] == [nil,nil,[]]) -a,b,*c = loop do break *[[]]; end; test_ok([a,b,c] == [nil,nil,[]]) +a,b,*c = loop do break *[[]]; end; test_ok([a,b,c] == [[],nil,[]]) a,b,*c = loop do break *[1,2]; end; test_ok([a,b,c] == [1,2,[]]) a,b,*c = loop do break *[*[]]; end; test_ok([a,b,c] == [nil,nil,[]]) a,b,*c = loop do break *[*[1]]; end; test_ok([a,b,c] == [1,nil,[]]) @@ -382,29 +377,29 @@ r([]){next [*[]]} r([1]){next [*[1]]} r([1,2]){next [*[1,2]]} -r(nil){next *[]} -r(1){next *[1]} -r(nil){next *[nil]} -r([]){next *[[]]} -r(nil){next *[*[]]} -r(1){next *[*[1]]} +r([]){next *[]} +r([1]){next *[1]} +r([nil]){next *[nil]} +r([[]]){next *[[]]} +r([]){next *[*[]]} +r([1]){next *[*[1]]} r([1,2]){next *[*[1,2]]} def r(val); *a = yield(); test_ok(a == val, 2); end r([nil]){next} r([nil]){next nil} r([1]){next 1} -r([[]]){next []} -r([[1]]){next [1]} -r([[nil]]){next [nil]} -r([[[]]]){next [[]]} -r([[1,2]]){next [1,2]} -r([[]]){next [*[]]} -r([[1]]){next [*[1]]} -r([[1,2]]){next [*[1,2]]} +r([]){next []} +r([1]){next [1]} +r([nil]){next [nil]} +r([[]]){next [[]]} +r([1,2]){next [1,2]} +r([]){next [*[]]} +r([1]){next [*[1]]} +r([1,2]){next [*[1,2]]} def r(val); *a = *yield(); test_ok(a == val, 2); end -r([]){next *[[]]} +r([[]]){next *[[]]} r([1,2]){next *[1,2]} r([1,2]){next *[*[1,2]]} @@ -422,7 +417,7 @@ r([1,nil,[]]){next [*[1]]} r([1,2,[]]){next [*[1,2]]} def r(val); a,b,*c = *yield(); test_ok([a,b,c] == val, 2); end -r([nil,nil,[]]){next *[[]]} +r([[],nil,[]]){next *[[]]} r([1,2,[]]){next *[1,2]} r([1,2,[]]){next *[*[1,2]]} @@ -963,22 +958,22 @@ IterTest.new([2]).each2 {|x| test_ok(x == [2])} #IterTest.new([3]).each3 {|x| test_ok(x == 3)} IterTest.new([4]).each4 {|x| test_ok(x == 4)} IterTest.new([5]).each5 {|x| test_ok(x == 5)} -IterTest.new([6]).each6 {|x| test_ok(x == [6])} +IterTest.new([6]).each6 {|x| test_ok(x == 6)} #IterTest.new([7]).each7 {|x| test_ok(x == 7)} IterTest.new([8]).each8 {|x| test_ok(x == 8)} -IterTest.new([[0]]).each0 {|x| test_ok(x == [0])} -IterTest.new([[1]]).each1 {|x| test_ok(x == [1])} -IterTest.new([[2]]).each2 {|x| test_ok(x == [[2]])} +IterTest.new([[0]]).each0 {|x| test_ok(x == 0)} +IterTest.new([[1]]).each1 {|x| test_ok(x == 1)} +IterTest.new([[2]]).each2 {|x| test_ok(x == [2])} IterTest.new([[3]]).each3 {|x| test_ok(x == 3)} -IterTest.new([[4]]).each4 {|x| test_ok(x == [4])} -IterTest.new([[5]]).each5 {|x| test_ok(x == [5])} -IterTest.new([[6]]).each6 {|x| test_ok(x == [[6]])} +IterTest.new([[4]]).each4 {|x| test_ok(x == 4)} +IterTest.new([[5]]).each5 {|x| test_ok(x == 5)} +IterTest.new([[6]]).each6 {|x| test_ok(x == 6)} IterTest.new([[7]]).each7 {|x| test_ok(x == 7)} -IterTest.new([[8]]).each8 {|x| test_ok(x == [8])} +IterTest.new([[8]]).each8 {|x| test_ok(x == 8)} -IterTest.new([[0,0]]).each0 {|x| test_ok(x == [0,0])} -IterTest.new([[8,8]]).each8 {|x| test_ok(x == [8,8])} +IterTest.new([[0,0]]).each0 {|*x| test_ok(x == [0,0])} +IterTest.new([[8,8]]).each8 {|*x| test_ok(x == [8])} def m0(v) v @@ -1018,7 +1013,7 @@ end block_test(NilClass) block_test(Proc){} -def argument_test(state, proc, *args) +def call_argument_test(state, proc, *args) x = state begin proc.call(*args) @@ -1028,27 +1023,43 @@ def argument_test(state, proc, *args) test_ok(x,2) end -argument_test(true, lambda{||}) -argument_test(false, lambda{||}, 1) -argument_test(true, lambda{|a,|}, 1) -argument_test(false, lambda{|a,|}) -argument_test(false, lambda{|a,|}, 1,2) +def yield_argument_test(state, proc, *args) + x = state + begin + proc.yield(*args) + rescue ArgumentError + x = !x + end + test_ok(x,2) +end + +call_argument_test(true, lambda{||}) +call_argument_test(false, lambda{||}, 1) +call_argument_test(true, lambda{|a,|}, 1) +call_argument_test(false, lambda{|a,|}) +call_argument_test(false, lambda{|a,|}, 1,2) + +yield_argument_test(true, lambda{||}) +yield_argument_test(true, lambda{||}, 1) +yield_argument_test(true, lambda{|a,|}, 1) +yield_argument_test(true, lambda{|a,|}) +yield_argument_test(true, lambda{|a,|}, 1,2) def get_block(&block) block end test_ok(Proc == get_block{}.class) -argument_test(true, get_block{||}) -argument_test(true, get_block{||}, 1) -argument_test(true, get_block{|a,|}, 1) -argument_test(true, get_block{|a,|}) -argument_test(true, get_block{|a,|}, 1,2) +yield_argument_test(true, get_block{||}) +yield_argument_test(true, get_block{||}, 1) +yield_argument_test(true, get_block{|a,|}, 1) +yield_argument_test(true, get_block{|a,|}) +yield_argument_test(true, get_block{|a,|}, 1,2) -argument_test(true, get_block(&lambda{||})) -argument_test(false, get_block(&lambda{||}),1) -argument_test(true, get_block(&lambda{|a,|}),1) -argument_test(false, get_block(&lambda{|a,|}),1,2) +call_argument_test(true, get_block(&lambda{||})) +call_argument_test(false, get_block(&lambda{||}),1) +call_argument_test(true, get_block(&lambda{|a,|}),1) +call_argument_test(false, get_block(&lambda{|a,|}),1,2) blk = get_block{11} test_ok(blk.class == Proc) @@ -1062,8 +1073,8 @@ test_ok(lmd.to_proc.class == Proc) test_ok(lmd.clone.call == 44) test_ok(get_block(&lmd).class == Proc) -test_ok(Proc.new{|a,| a}.call(1,2,3) == 1) -argument_test(true, Proc.new{|a,|}, 1,2) +test_ok(Proc.new{|a,| a}.yield(1,2,3) == 1) +yield_argument_test(true, Proc.new{|a,|}, 1,2) test_ok(Proc.new{|&b| b.call(10)}.call {|x| x} == 10) test_ok(Proc.new{|a,&b| b.call(a)}.call(12) {|x| x} == 12) @@ -1071,7 +1082,7 @@ test_ok(Proc.new{|a,&b| b.call(a)}.call(12) {|x| x} == 12) def test_return1 Proc.new { return 55 - }.call + 5 + }.yield + 5 end test_ok(test_return1() == 55) def test_return2 @@ -1090,7 +1101,7 @@ end def proc_return1 proc_call{return 42}+1 end -test_ok(proc_return1() == 42) +test_ok(proc_return1() == 43) def proc_return2 proc_yield{return 42}+1 end @@ -1106,7 +1117,7 @@ def ljump_test(state, proc, *args) test_ok(x,2) end -ljump_test(false, get_block{break}) +ljump_test(true, get_block{break}) ljump_test(true, lambda{break}) def exit_value_test(&block) @@ -1149,11 +1160,11 @@ def test_b2 block_get{break 21}.call end end -test_ok(test_b2() == 22) +test_ok(test_b2() == 21) def test_b3 ljump_rescue(33) do - Proc.new{break 31}.call + Proc.new{break 31}.yield end end test_ok(test_b3() == 33) @@ -1169,7 +1180,7 @@ def test_b5 block_call(&b) end end -test_ok(test_b5() == 55) +test_ok(test_b5() == 54) def test_b6 b = lambda{break 67} @@ -1188,7 +1199,7 @@ def test_b7 block_call(&b) end end -test_ok(test_b7() == 77) +test_ok(test_b7() == 78) def util_b8(&block) block_call(&block) @@ -1220,7 +1231,7 @@ test_ok(test_b10() == 100) def test_b11 ljump_rescue(111) do loop do - Proc.new{break 110}.call + Proc.new{break 110}.yield break 112 end end @@ -1238,7 +1249,7 @@ test_ok(test_b12() == 122) def test_b13 ljump_rescue(133) do while true - Proc.new{break 130}.call + Proc.new{break 130}.yield break 131 end end @@ -1260,7 +1271,7 @@ end test_ok(test_b15{|e| break 155 } == 155) def marity_test(m) - method = self.method(m) + method = method(m) test_ok(method.arity == method.to_proc.arity, 2) end marity_test(:test_ok) @@ -1421,7 +1432,6 @@ $good = true; for i in 4000..4096 n1 = 1 << i; if (n1**2-1) / (n1+1) != (n1-1) - p i $good = false end end @@ -1525,9 +1535,9 @@ test_ok($x.sub(/.*\.([^\.]+)$/, '<\&>') == "") # character constants(assumes ASCII) test_ok("a"[0] == ?a) test_ok(?a == ?a) -test_ok(?\C-a == 1) -test_ok(?\M-a == 225) -test_ok(?\M-\C-a == 129) +test_ok(?\C-a == "\1") +test_ok(?\M-a == "\341") +test_ok(?\M-\C-a == "\201") test_ok("a".upcase![0] == ?A) test_ok("A".downcase![0] == ?a) test_ok("abc".tr!("a-z", "A-Z") == "ABC") @@ -1539,7 +1549,7 @@ $x = "abcdef" $y = [ ?a, ?b, ?c, ?d, ?e, ?f ] $bad = false $x.each_byte {|i| - if i != $y.shift + if i.chr != $y.shift $bad = true break end @@ -1927,7 +1937,7 @@ module M003; include M002; end module M002; include M001; end module M003; include M002; end -test_ok(M003.ancestors == [M003, M002, M001]) +test_ok(M003.ancestors == [M003, M002, M001, M002]) test_check "marshal" $x = [1,2,3,[4,5,"foo"],{1=>"bar"},2.5,fact(30)] diff --git a/signal.c b/signal.c index 1f191c6966..6441c0a8cf 100644 --- a/signal.c +++ b/signal.c @@ -226,7 +226,7 @@ rb_f_kill(int argc, VALUE *argv) int negative = 0; int sig; int i; - char *s; + const char *s; rb_secure(2); if (argc < 2) @@ -564,7 +564,7 @@ trap(struct trap_arg *arg) sighandler_t func, oldfunc; VALUE command, oldcmd; int sig = -1; - char *s; + const char *s; func = sighandler; if (NIL_P(arg->cmd)) { @@ -630,7 +630,7 @@ trap(struct trap_arg *arg) rb_raise(rb_eArgError, "unsupported signal SIG%s", s); } - if (sig < 0 || sig > NSIG) { + if (sig < 0 || sig >= NSIG) { rb_raise(rb_eArgError, "invalid signal number (%d)", sig); } #if defined(HAVE_SETITIMER) diff --git a/sprintf.c b/sprintf.c index 580a54ae8f..22c8c12d1c 100644 --- a/sprintf.c +++ b/sprintf.c @@ -394,7 +394,15 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) VALUE val = GETARG(); char c; - c = NUM2INT(val) & 0xff; + if (rb_check_string_type(val)) { + if (RSTRING(val)->len != 1) { + rb_raise(rb_eArgError, "%%c requires a character"); + } + c = RSTRING(val)->ptr[0]; + } + else { + c = NUM2INT(val) & 0xff; + } if (!(flags & FWIDTH)) { PUSH(&c, 1); } diff --git a/st.c b/st.c index 6bcd05879b..c1cb7b6c40 100644 --- a/st.c +++ b/st.c @@ -490,42 +490,97 @@ st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg) return 0; } +/* + * hash_32 - 32 bit Fowler/Noll/Vo FNV-1a hash code + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + *** + * + * Fowler/Noll/Vo hash + * + * The basis of this hash algorithm was taken from an idea sent + * as reviewer comments to the IEEE POSIX P1003.2 committee by: + * + * Phong Vo (http://www.research.att.com/info/kpv/) + * Glenn Fowler (http://www.research.att.com/~gsf/) + * + * In a subsequent ballot round: + * + * Landon Curt Noll (http://www.isthe.com/chongo/) + * + * improved on their algorithm. Some people tried this hash + * and found that it worked rather well. In an EMail message + * to Landon, they named it the ``Fowler/Noll/Vo'' or FNV hash. + * + * FNV hashes are designed to be fast while maintaining a low + * collision rate. The FNV speed allows one to quickly hash lots + * of data while maintaining a reasonable collision rate. See: + * + * http://www.isthe.com/chongo/tech/comp/fnv/index.html + * + * for more details as well as other forms of the FNV hash. + *** + * + * To use the recommended 32 bit FNV-1a hash, pass FNV1_32A_INIT as the + * Fnv32_t hashval argument to fnv_32a_buf() or fnv_32a_str(). + * + *** + * + * Please do not copyright this code. This code is in the public domain. + * + * LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO + * EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF + * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + * + * By: + * chongo /\oo/\ + * http://www.isthe.com/chongo/ + * + * Share and Enjoy! :-) + */ + +/* + * 32 bit FNV-1 and FNV-1a non-zero initial basis + * + * The FNV-1 initial basis is the FNV-0 hash of the following 32 octets: + * + * chongo /\../\ + * + * NOTE: The \'s above are not back-slashing escape characters. + * They are literal ASCII backslash 0x5c characters. + * + * NOTE: The FNV-1a initial basis is the same value as FNV-1 by definition. + */ +#define FNV1_32A_INIT 0x811c9dc5 + +/* + * 32 bit magic FNV-1a prime + */ +#define FNV_32_PRIME 0x01000193 + static int strhash(register const char *string) { - register int c; + register int hval = FNV1_32A_INIT; -#ifdef HASH_ELFHASH - register unsigned int h = 0, g; - - while ((c = *string++) != '\0') { - h = ( h << 4 ) + c; - if ( g = h & 0xF0000000 ) - h ^= g >> 24; - h &= ~g; - } - return h; -#elif HASH_PERL - register int val = 0; - - while ((c = *string++) != '\0') { - val += c; - val += (val << 10); - val ^= (val >> 6); - } - val += (val << 3); - val ^= (val >> 11); - - return val + (val << 15); -#else - register int val = 0; + /* + * FNV-1a hash each octet in the buffer + */ + while (*string) { + /* xor the bottom with the current octet */ + hval ^= (int)*string++; - while ((c = *string++) != '\0') { - val = val*997 + c; + /* multiply by the 32 bit FNV magic prime mod 2^32 */ + hval *= FNV_32_PRIME; } - - return val + (val>>5); -#endif + return hval; } static int diff --git a/string.c b/string.c index 46bc40662b..871fd9a70d 100644 --- a/string.c +++ b/string.c @@ -765,39 +765,103 @@ rb_str_concat(VALUE str1, VALUE str2) return str1; } +/* + * hash_32 - 32 bit Fowler/Noll/Vo FNV-1a hash code + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + *** + * + * Fowler/Noll/Vo hash + * + * The basis of this hash algorithm was taken from an idea sent + * as reviewer comments to the IEEE POSIX P1003.2 committee by: + * + * Phong Vo (http://www.research.att.com/info/kpv/) + * Glenn Fowler (http://www.research.att.com/~gsf/) + * + * In a subsequent ballot round: + * + * Landon Curt Noll (http://www.isthe.com/chongo/) + * + * improved on their algorithm. Some people tried this hash + * and found that it worked rather well. In an EMail message + * to Landon, they named it the ``Fowler/Noll/Vo'' or FNV hash. + * + * FNV hashes are designed to be fast while maintaining a low + * collision rate. The FNV speed allows one to quickly hash lots + * of data while maintaining a reasonable collision rate. See: + * + * http://www.isthe.com/chongo/tech/comp/fnv/index.html + * + * for more details as well as other forms of the FNV hash. + *** + * + * To use the recommended 32 bit FNV-1a hash, pass FNV1_32A_INIT as the + * Fnv32_t hashval argument to fnv_32a_buf() or fnv_32a_str(). + * + *** + * + * Please do not copyright this code. This code is in the public domain. + * + * LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO + * EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF + * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + * + * By: + * chongo /\oo/\ + * http://www.isthe.com/chongo/ + * + * Share and Enjoy! :-) + */ + +/* + * 32 bit FNV-1 and FNV-1a non-zero initial basis + * + * The FNV-1 initial basis is the FNV-0 hash of the following 32 octets: + * + * chongo /\../\ + * + * NOTE: The \'s above are not back-slashing escape characters. + * They are literal ASCII backslash 0x5c characters. + * + * NOTE: The FNV-1a initial basis is the same value as FNV-1 by definition. + */ +#define FNV1_32A_INIT 0x811c9dc5 + +/* + * 32 bit magic FNV-1a prime + */ +#define FNV_32_PRIME 0x01000193 + int rb_str_hash(VALUE str) { register long len = RSTRING(str)->len; register char *p = RSTRING(str)->ptr; - register int key = 0; - -#ifdef HASH_ELFHASH - register unsigned int g; + register int hval = FNV1_32A_INIT; + /* + * FNV-1a hash each octet in the buffer + */ while (len--) { - key = (key << 4) + *p++; - if (g = key & 0xF0000000) - key ^= g >> 24; - key &= ~g; - } -#elif HASH_PERL - while (len--) { - key += *p++; - key += (key << 10); - key ^= (key >> 6); - } - key += (key << 3); - key ^= (key >> 11); - key += (key << 15); + /* xor the bottom with the current octet */ + hval ^= (int)*p++; + + /* multiply by the 32 bit FNV magic prime mod 2^32 */ +#if defined(FNV_GCC_OPTIMIZATION) + hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24); #else - while (len--) { - key = key*65599 + *p; - p++; - } - key = key + (key>>5); + hval *= FNV_32_PRIME; #endif - return key; + } + return hval; } /* @@ -810,8 +874,8 @@ rb_str_hash(VALUE str) static VALUE rb_str_hash_m(VALUE str) { - int key = rb_str_hash(str); - return INT2FIX(key); + int hval = rb_str_hash(str); + return INT2FIX(hval); } #define lesser(a,b) (((a)>(b))?(b):(a)) @@ -1414,13 +1478,7 @@ rb_str_aref(VALUE str, VALUE indx) idx = FIX2LONG(indx); num_index: - if (idx < 0) { - idx = RSTRING(str)->len + idx; - } - if (idx < 0 || RSTRING(str)->len <= idx) { - return Qnil; - } - return INT2FIX(RSTRING(str)->ptr[idx] & 0xff); + return rb_str_substr(str, idx, 1); case T_REGEXP: return rb_str_subpat(str, indx, 0); @@ -1456,21 +1514,21 @@ rb_str_aref(VALUE str, VALUE indx) /* * call-seq: - * str[fixnum] => fixnum or nil + * str[fixnum] => new_str or nil * str[fixnum, fixnum] => new_str or nil * str[range] => new_str or nil * str[regexp] => new_str or nil * str[regexp, fixnum] => new_str or nil * str[other_str] => new_str or nil - * str.slice(fixnum) => fixnum or nil + * str.slice(fixnum) => new_str or nil * str.slice(fixnum, fixnum) => new_str or nil * str.slice(range) => new_str or nil * str.slice(regexp) => new_str or nil * str.slice(regexp, fixnum) => new_str or nil * str.slice(other_str) => new_str or nil * - * Element Reference---If passed a single Fixnum, returns the code - * of the character at that position. If passed two Fixnum + * Element Reference---If passed a single Fixnum, returns a + * substring of one character at that position. If passed two Fixnum * objects, returns a substring starting at the offset given by the first, and * a length given by the second. If given a range, a substring containing * characters at offsets given by the range is returned. In all three cases, if @@ -1486,7 +1544,7 @@ rb_str_aref(VALUE str, VALUE indx) * match. * * a = "hello there" - * a[1] #=> 101 + * a[1] #=> "e" * a[1,3] #=> "ell" * a[1..3] #=> "ell" * a[-3,2] #=> "er" @@ -1615,17 +1673,7 @@ rb_str_aset(VALUE str, VALUE indx, VALUE val) goto out_of_range; idx += RSTRING(str)->len; } - if (FIXNUM_P(val)) { - rb_str_modify(str); - if (RSTRING(str)->len == idx) { - RSTRING(str)->len += 1; - RESIZE_CAPA(str, RSTRING(str)->len); - } - RSTRING(str)->ptr[idx] = FIX2INT(val) & 0xff; - } - else { - rb_str_splice(str, idx, 1, val); - } + rb_str_splice(str, idx, 1, val); return val; case T_REGEXP: @@ -1656,7 +1704,6 @@ rb_str_aset(VALUE str, VALUE indx, VALUE val) /* * call-seq: - * str[fixnum] = fixnum * str[fixnum] = new_str * str[fixnum, fixnum] = new_str * str[range] = aString @@ -2158,6 +2205,22 @@ rb_str_clear(VALUE str) return str; } +/* + * call-seq: + * string.chr -> string + * + * Returns a one-character string at the beginning of the string. + * + * a = "abcde" + * a.chr #=> "a" + */ + +static VALUE +rb_str_chr(VALUE str) +{ + return rb_str_substr(str, 0, 1); +} + /* * call-seq: * str.reverse! => str @@ -4217,6 +4280,7 @@ Init_String(void) rb_define_method(rb_cString, "rindex", rb_str_rindex_m, -1); rb_define_method(rb_cString, "replace", rb_str_replace, 1); rb_define_method(rb_cString, "clear", rb_str_clear, 0); + rb_define_method(rb_cString, "chr", rb_str_chr, 0); rb_define_method(rb_cString, "to_i", rb_str_to_i, -1); rb_define_method(rb_cString, "to_f", rb_str_to_f, 0); diff --git a/struct.c b/struct.c index 49a4de9fac..c7ca180de1 100644 --- a/struct.c +++ b/struct.c @@ -451,7 +451,7 @@ inspect_struct(VALUE s, VALUE dummy, int recur) for (i=0; i 0) { rb_str_cat2(str, ", "); diff --git a/test/ruby/test_assignment.rb b/test/ruby/test_assignment.rb index 5a0e06478f..0e11d6bad6 100644 --- a/test/ruby/test_assignment.rb +++ b/test/ruby/test_assignment.rb @@ -29,25 +29,25 @@ class TestAssignment < Test::Unit::TestCase a = [*[1]]; assert_equal([1], a) a = [*[1,2]]; assert_equal([1,2], a) - a = *[]; assert_nil(a) - a = *[1]; assert_equal(1, a) - a = *[nil]; assert_nil(a) - a = *[[]]; assert_equal([], a) + a = *[]; assert_equal([], a) + a = *[1]; assert_equal([1], a) + a = *[nil]; assert_equal([nil], a) + a = *[[]]; assert_equal([[]], a) a = *[1,2]; assert_equal([1,2], a) - a = *[*[]]; assert_nil(a) - a = *[*[1]]; assert_equal(1, a) + a = *[*[]]; assert_equal([], a) + a = *[*[1]]; assert_equal([1], a) a = *[*[1,2]]; assert_equal([1,2], a) *a = nil; assert_equal([nil], a) *a = 1; assert_equal([1], a) - *a = []; assert_equal([[]], a) - *a = [1]; assert_equal([[1]], a) - *a = [nil]; assert_equal([[nil]], a) - *a = [[]]; assert_equal([[[]]], a) - *a = [1,2]; assert_equal([[1,2]], a) - *a = [*[]]; assert_equal([[]], a) - *a = [*[1]]; assert_equal([[1]], a) - *a = [*[1,2]]; assert_equal([[1,2]], a) + *a = []; assert_equal([], a) + *a = [1]; assert_equal([1], a) + *a = [nil]; assert_equal([nil], a) + *a = [[]]; assert_equal([[]], a) + *a = [1,2]; assert_equal([1,2], a) + *a = [*[]]; assert_equal([], a) + *a = [*[1]]; assert_equal([1], a) + *a = [*[1,2]]; assert_equal([1,2], a) *a = *[]; assert_equal([], a) *a = *[1]; assert_equal([1], a) @@ -82,13 +82,13 @@ class TestAssignment < Test::Unit::TestCase def test_yield def f; yield(nil); end; f {|a| assert_nil(a)}; undef f def f; yield(1); end; f {|a| assert_equal(1, a)}; undef f - def f; yield([]); end; f {|a| assert_equal([], a)}; undef f - def f; yield([1]); end; f {|a| assert_equal([1], a)}; undef f - def f; yield([nil]); end; f {|a| assert_equal([nil], a)}; undef f - def f; yield([[]]); end; f {|a| assert_equal([[]], a)}; undef f - def f; yield([*[]]); end; f {|a| assert_equal([], a)}; undef f - def f; yield([*[1]]); end; f {|a| assert_equal([1], a)}; undef f - def f; yield([*[1,2]]); end; f {|a| assert_equal([1,2], a)}; undef f + def f; yield([]); end; f {|a| assert_equal(nil, a)}; undef f + def f; yield([1]); end; f {|a| assert_equal(1, a)}; undef f + def f; yield([nil]); end; f {|a| assert_equal(nil, a)}; undef f + def f; yield([[]]); end; f {|a| assert_equal([], a)}; undef f + def f; yield([*[]]); end; f {|a| assert_equal(nil, a)}; undef f + def f; yield([*[1]]); end; f {|a| assert_equal(1, a)}; undef f + def f; yield([*[1,2]]); end; f {|a| assert_equal(1, a)}; undef f def f; yield(*[1]); end; f {|a| assert_equal(1, a)}; undef f def f; yield(*[nil]); end; f {|a| assert_nil(a)}; undef f @@ -98,14 +98,14 @@ class TestAssignment < Test::Unit::TestCase def f; yield; end; f {|*a| assert_equal([], a)}; undef f def f; yield(nil); end; f {|*a| assert_equal([nil], a)}; undef f def f; yield(1); end; f {|*a| assert_equal([1], a)}; undef f - def f; yield([]); end; f {|*a| assert_equal([[]], a)}; undef f - def f; yield([1]); end; f {|*a| assert_equal([[1]], a)}; undef f - def f; yield([nil]); end; f {|*a| assert_equal([[nil]], a)}; undef f - def f; yield([[]]); end; f {|*a| assert_equal([[[]]], a)}; undef f - def f; yield([1,2]); end; f {|*a| assert_equal([[1,2]], a)}; undef f - def f; yield([*[]]); end; f {|*a| assert_equal([[]], a)}; undef f - def f; yield([*[1]]); end; f {|*a| assert_equal([[1]], a)}; undef f - def f; yield([*[1,2]]); end; f {|*a| assert_equal([[1,2]], a)}; undef f + def f; yield([]); end; f {|*a| assert_equal([], a)}; undef f + def f; yield([1]); end; f {|*a| assert_equal([1], a)}; undef f + def f; yield([nil]); end; f {|*a| assert_equal([nil], a)}; undef f + def f; yield([[]]); end; f {|*a| assert_equal([[]], a)}; undef f + def f; yield([1,2]); end; f {|*a| assert_equal([1,2], a)}; undef f + def f; yield([*[]]); end; f {|*a| assert_equal([], a)}; undef f + def f; yield([*[1]]); end; f {|*a| assert_equal([1], a)}; undef f + def f; yield([*[1,2]]); end; f {|*a| assert_equal([1,2], a)}; undef f def f; yield(*[]); end; f {|*a| assert_equal([], a)}; undef f def f; yield(*[1]); end; f {|*a| assert_equal([1], a)}; undef f @@ -147,39 +147,39 @@ class TestAssignment < Test::Unit::TestCase def r; return [*[1]]; end; a = r(); assert_equal([1], a); undef r def r; return [*[1,2]]; end; a = r(); assert_equal([1,2], a); undef r - def r; return *[]; end; a = r(); assert_nil(a); undef r - def r; return *[1]; end; a = r(); assert_equal(1, a); undef r - def r; return *[nil]; end; a = r(); assert_nil(a); undef r - def r; return *[[]]; end; a = r(); assert_equal([], a); undef r - def r; return *[*[]]; end; a = r(); assert_nil(a); undef r - def r; return *[*[1]]; end; a = r(); assert_equal(1, a); undef r + def r; return *[]; end; a = r(); assert_equal([], a); undef r + def r; return *[1]; end; a = r(); assert_equal([1], a); undef r + def r; return *[nil]; end; a = r(); assert_equal([nil], a); undef r + def r; return *[[]]; end; a = r(); assert_equal([[]], a); undef r + def r; return *[*[]]; end; a = r(); assert_equal([], a); undef r + def r; return *[*[1]]; end; a = r(); assert_equal([1], a); undef r def r; return *[*[1,2]]; end; a = r(); assert_equal([1,2], a); undef r - def r; return *[[]]; end; a = *r(); assert_nil(a); undef r + def r; return *[[]]; end; a = *r(); assert_equal([[]], a); undef r def r; return *[*[1,2]]; end; a = *r(); assert_equal([1,2], a); undef r def r; return; end; *a = r(); assert_equal([nil], a); undef r def r; return nil; end; *a = r(); assert_equal([nil], a); undef r def r; return 1; end; *a = r(); assert_equal([1], a); undef r - def r; return []; end; *a = r(); assert_equal([[]], a); undef r - def r; return [1]; end; *a = r(); assert_equal([[1]], a); undef r - def r; return [nil]; end; *a = r(); assert_equal([[nil]], a); undef r - def r; return [[]]; end; *a = r(); assert_equal([[[]]], a); undef r - def r; return [1,2]; end; *a = r(); assert_equal([[1,2]], a); undef r - def r; return [*[]]; end; *a = r(); assert_equal([[]], a); undef r - def r; return [*[1]]; end; *a = r(); assert_equal([[1]], a); undef r - def r; return [*[1,2]]; end; *a = r(); assert_equal([[1,2]], a); undef r - - def r; return *[]; end; *a = r(); assert_equal([nil], a); undef r + def r; return []; end; *a = r(); assert_equal([], a); undef r + def r; return [1]; end; *a = r(); assert_equal([1], a); undef r + def r; return [nil]; end; *a = r(); assert_equal([nil], a); undef r + def r; return [[]]; end; *a = r(); assert_equal([[]], a); undef r + def r; return [1,2]; end; *a = r(); assert_equal([1,2], a); undef r + def r; return [*[]]; end; *a = r(); assert_equal([], a); undef r + def r; return [*[1]]; end; *a = r(); assert_equal([1], a); undef r + def r; return [*[1,2]]; end; *a = r(); assert_equal([1,2], a); undef r + + def r; return *[]; end; *a = r(); assert_equal([], a); undef r def r; return *[1]; end; *a = r(); assert_equal([1], a); undef r def r; return *[nil]; end; *a = r(); assert_equal([nil], a); undef r def r; return *[[]]; end; *a = r(); assert_equal([[]], a); undef r - def r; return *[1,2]; end; *a = r(); assert_equal([[1,2]], a); undef r - def r; return *[*[]]; end; *a = r(); assert_equal([nil], a); undef r + def r; return *[1,2]; end; *a = r(); assert_equal([1,2], a); undef r + def r; return *[*[]]; end; *a = r(); assert_equal([], a); undef r def r; return *[*[1]]; end; *a = r(); assert_equal([1], a); undef r - def r; return *[*[1,2]]; end; *a = r(); assert_equal([[1,2]], a); undef r + def r; return *[*[1,2]]; end; *a = r(); assert_equal([1,2], a); undef r - def r; return *[[]]; end; *a = *r(); assert_equal([], a); undef r + def r; return *[[]]; end; *a = *r(); assert_equal([[]], a); undef r def r; return *[1,2]; end; *a = *r(); assert_equal([1,2], a); undef r def r; return *[*[1,2]]; end; *a = *r(); assert_equal([1,2], a); undef r @@ -198,7 +198,7 @@ class TestAssignment < Test::Unit::TestCase def r; return *[]; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c]); undef r def r; return *[1]; end; a,b,*c = r(); assert_equal([1,nil,[]], [a,b,c]); undef r def r; return *[nil]; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c]); undef r - def r; return *[[]]; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c]); undef r + def r; return *[[]]; end; a,b,*c = r(); assert_equal([[],nil,[]], [a,b,c]); undef r def r; return *[1,2]; end; a,b,*c = r(); assert_equal([1,2,[]], [a,b,c]); undef r def r; return *[*[]]; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c]); undef r def r; return *[*[1]]; end; a,b,*c = r(); assert_equal([1,nil,[]], [a,b,c]); undef r @@ -260,36 +260,36 @@ class TestAssignment < Test::Unit::TestCase a = loop do break [*[1]]; end; assert_equal([1], a) a = loop do break [*[1,2]]; end; assert_equal([1,2], a) - a = loop do break *[]; end; assert_nil(a) - a = loop do break *[1]; end; assert_equal(1, a) - a = loop do break *[nil]; end; assert_nil(a) - a = loop do break *[[]]; end; assert_equal([], a) - a = loop do break *[*[]]; end; assert_nil(a) - a = loop do break *[*[1]]; end; assert_equal(1, a) + a = loop do break *[]; end; assert_equal([], a) + a = loop do break *[1]; end; assert_equal([1], a) + a = loop do break *[nil]; end; assert_equal([nil], a) + a = loop do break *[[]]; end; assert_equal([[]], a) + a = loop do break *[*[]]; end; assert_equal([], a) + a = loop do break *[*[1]]; end; assert_equal([1], a) a = loop do break *[*[1,2]]; end; assert_equal([1,2], a) *a = loop do break; end; assert_equal([nil], a) *a = loop do break nil; end; assert_equal([nil], a) *a = loop do break 1; end; assert_equal([1], a) - *a = loop do break []; end; assert_equal([[]], a) - *a = loop do break [1]; end; assert_equal([[1]], a) - *a = loop do break [nil]; end; assert_equal([[nil]], a) - *a = loop do break [[]]; end; assert_equal([[[]]], a) - *a = loop do break [1,2]; end; assert_equal([[1,2]], a) - *a = loop do break [*[]]; end; assert_equal([[]], a) - *a = loop do break [*[1]]; end; assert_equal([[1]], a) - *a = loop do break [*[1,2]]; end; assert_equal([[1,2]], a) - - *a = loop do break *[]; end; assert_equal([nil], a) + *a = loop do break []; end; assert_equal([], a) + *a = loop do break [1]; end; assert_equal([1], a) + *a = loop do break [nil]; end; assert_equal([nil], a) + *a = loop do break [[]]; end; assert_equal([[]], a) + *a = loop do break [1,2]; end; assert_equal([1,2], a) + *a = loop do break [*[]]; end; assert_equal([], a) + *a = loop do break [*[1]]; end; assert_equal([1], a) + *a = loop do break [*[1,2]]; end; assert_equal([1,2], a) + + *a = loop do break *[]; end; assert_equal([], a) *a = loop do break *[1]; end; assert_equal([1], a) *a = loop do break *[nil]; end; assert_equal([nil], a) *a = loop do break *[[]]; end; assert_equal([[]], a) - *a = loop do break *[1,2]; end; assert_equal([[1,2]], a) - *a = loop do break *[*[]]; end; assert_equal([nil], a) + *a = loop do break *[1,2]; end; assert_equal([1,2], a) + *a = loop do break *[*[]]; end; assert_equal([], a) *a = loop do break *[*[1]]; end; assert_equal([1], a) - *a = loop do break *[*[1,2]]; end; assert_equal([[1,2]], a) + *a = loop do break *[*[1,2]]; end; assert_equal([1,2], a) - *a = *loop do break *[[]]; end; assert_equal([], a) + *a = *loop do break *[[]]; end; assert_equal([[]], a) *a = *loop do break *[1,2]; end; assert_equal([1,2], a) *a = *loop do break *[*[1,2]]; end; assert_equal([1,2], a) @@ -308,7 +308,7 @@ class TestAssignment < Test::Unit::TestCase a,b,*c = loop do break *[]; end; assert_equal([nil,nil,[]], [a,b,c]) a,b,*c = loop do break *[1]; end; assert_equal([1,nil,[]], [a,b,c]) a,b,*c = loop do break *[nil]; end; assert_equal([nil,nil,[]], [a,b,c]) - a,b,*c = loop do break *[[]]; end; assert_equal([nil,nil,[]], [a,b,c]) + a,b,*c = loop do break *[[]]; end; assert_equal([[],nil,[]], [a,b,c]) a,b,*c = loop do break *[1,2]; end; assert_equal([1,2,[]], [a,b,c]) a,b,*c = loop do break *[*[]]; end; assert_equal([nil,nil,[]], [a,b,c]) a,b,*c = loop do break *[*[1]]; end; assert_equal([1,nil,[]], [a,b,c]) @@ -328,12 +328,12 @@ class TestAssignment < Test::Unit::TestCase r([1]){next [*[1]]} r([1,2]){next [*[1,2]]} - r(nil){next *[]} - r(1){next *[1]} - r(nil){next *[nil]} - r([]){next *[[]]} - r(nil){next *[*[]]} - r(1){next *[*[1]]} + r([]){next *[]} + r([1]){next *[1]} + r([nil]){next *[nil]} + r([[]]){next *[[]]} + r([]){next *[*[]]} + r([1]){next *[*[1]]} r([1,2]){next *[*[1,2]]} undef r @@ -341,18 +341,18 @@ class TestAssignment < Test::Unit::TestCase r([nil]){next} r([nil]){next nil} r([1]){next 1} - r([[]]){next []} - r([[1]]){next [1]} - r([[nil]]){next [nil]} - r([[[]]]){next [[]]} - r([[1,2]]){next [1,2]} - r([[]]){next [*[]]} - r([[1]]){next [*[1]]} - r([[1,2]]){next [*[1,2]]} + r([]){next []} + r([1]){next [1]} + r([nil]){next [nil]} + r([[]]){next [[]]} + r([1,2]){next [1,2]} + r([]){next [*[]]} + r([1]){next [*[1]]} + r([1,2]){next [*[1,2]]} undef r def r(val); *a = *yield(); assert_equal(val, a); end - r([]){next *[[]]} + r([[]]){next *[[]]} r([1,2]){next *[1,2]} r([1,2]){next *[*[1,2]]} undef r @@ -372,7 +372,7 @@ class TestAssignment < Test::Unit::TestCase undef r def r(val); a,b,*c = *yield(); assert_equal(val, [a,b,c]); end - r([nil,nil,[]]){next *[[]]} + r([[],nil,[]]){next *[[]]} r([1,2,[]]){next *[1,2]} r([1,2,[]]){next *[*[1,2]]} undef r diff --git a/test/ruby/test_clone.rb b/test/ruby/test_clone.rb index 43c0cffa1d..67d79fb8a5 100644 --- a/test/ruby/test_clone.rb +++ b/test/ruby/test_clone.rb @@ -23,6 +23,6 @@ class TestClone < Test::Unit::TestCase assert_raises(NoMethodError) {foo.test2} - assert_equal([M003, M002, M001], M003.ancestors) + assert_equal([M003, M002, M001, M002], M003.ancestors) end end diff --git a/test/ruby/test_dir.rb b/test/ruby/test_dir.rb index 09685bee8f..7887d37670 100644 --- a/test/ruby/test_dir.rb +++ b/test/ruby/test_dir.rb @@ -31,9 +31,9 @@ class TestDir < Test::Unit::TestCase break unless name = dir.read cache << [pos, name] end - for x in cache.sort_by {|x| x[0] % 3 } # shuffle - dir.seek(x[0]) - assert_equal(x[1], dir.read) + for x,y in cache.sort_by {|x| x[0] % 3 } # shuffle + dir.seek(x) + assert_equal(y, dir.read) end ensure dir.close diff --git a/test/ruby/test_file.rb b/test/ruby/test_file.rb index 4947e081c5..e326b97b07 100644 --- a/test/ruby/test_file.rb +++ b/test/ruby/test_file.rb @@ -88,7 +88,7 @@ class TestFile < Test::Unit::TestCase assert_nil(f.getc) open(f.path, "w") {|g| g.print "a" } result = [] - f.each_byte {|b| result << b } + f.each_byte {|b| result << b.chr } assert_equal([?a], result) end diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb index 63979b5be0..c2e5041a21 100644 --- a/test/ruby/test_float.rb +++ b/test/ruby/test_float.rb @@ -87,4 +87,32 @@ class TestFloat < Test::Unit::TestCase assert_raise(ArgumentError){Float("1e")} # add expected behaviour here. end + + def test_divmod + assert_equal([2, 3.5], 11.5.divmod(4)) + assert_equal([-3, -0.5], 11.5.divmod(-4)) + assert_equal([-3, 0.5], (-11.5).divmod(4)) + assert_equal([2, -3.5], (-11.5).divmod(-4)) + end + + def test_div + assert_equal(2, 11.5.div(4)) + assert_equal(-3, 11.5.div(-4)) + assert_equal(-3, (-11.5).div(4)) + assert_equal(2, (-11.5).div(-4)) + end + + def test_modulo + assert_equal(3.5, 11.5.modulo(4)) + assert_equal(-0.5, 11.5.modulo(-4)) + assert_equal(0.5, (-11.5).modulo(4)) + assert_equal(-3.5, (-11.5).modulo(-4)) + end + + def test_remainder + assert_equal(3.5, 11.5.remainder(4)) + assert_equal(3.5, 11.5.remainder(-4)) + assert_equal(-3.5, (-11.5).remainder(4)) + assert_equal(-3.5, (-11.5).remainder(-4)) + end end diff --git a/test/ruby/test_iterator.rb b/test/ruby/test_iterator.rb index 81f02263a8..65e2967e62 100644 --- a/test/ruby/test_iterator.rb +++ b/test/ruby/test_iterator.rb @@ -151,21 +151,21 @@ class TestIterator < Test::Unit::TestCase IterTest.new([2]).each2 {|x| assert_equal([2], x)} IterTest.new([4]).each4 {|x| assert_equal(4, x)} IterTest.new([5]).each5 {|x| assert_equal(5, x)} - IterTest.new([6]).each6 {|x| assert_equal([6], x)} + IterTest.new([6]).each6 {|x| assert_equal(6, x)} IterTest.new([8]).each8 {|x| assert_equal(8, x)} - IterTest.new([[0]]).each0 {|x| assert_equal([0], x)} - IterTest.new([[1]]).each1 {|x| assert_equal([1], x)} - IterTest.new([[2]]).each2 {|x| assert_equal([[2]], x)} + IterTest.new([[0]]).each0 {|x| assert_equal(0, x)} + IterTest.new([[1]]).each1 {|x| assert_equal(1, x)} + IterTest.new([[2]]).each2 {|x| assert_equal([2], x)} IterTest.new([[3]]).each3 {|x| assert_equal(3, x)} - IterTest.new([[4]]).each4 {|x| assert_equal([4], x)} - IterTest.new([[5]]).each5 {|x| assert_equal([5], x)} - IterTest.new([[6]]).each6 {|x| assert_equal([[6]], x)} + IterTest.new([[4]]).each4 {|x| assert_equal(4, x)} + IterTest.new([[5]]).each5 {|x| assert_equal(5, x)} + IterTest.new([[6]]).each6 {|x| assert_equal(6, x)} IterTest.new([[7]]).each7 {|x| assert_equal(7, x)} - IterTest.new([[8]]).each8 {|x| assert_equal([8], x)} + IterTest.new([[8]]).each8 {|x| assert_equal(8, x)} - IterTest.new([[0,0]]).each0 {|x| assert_equal([0,0], x)} - IterTest.new([[8,8]]).each8 {|x| assert_equal([8,8], x)} + IterTest.new([[0,0]]).each0 {|*x| assert_equal([0,0], x)} + IterTest.new([[8,8]]).each8 {|*x| assert_equal([8], x)} end def m(var) @@ -346,10 +346,10 @@ class TestIterator < Test::Unit::TestCase end def foo - yield([:key, :value]) + yield(:key, :value) end def bar(&blk) - blk.call([:key, :value]) + blk.call(:key, :value) end def test_yield_vs_call @@ -359,14 +359,14 @@ class TestIterator < Test::Unit::TestCase class H def each - yield [:key, :value] + yield :key, :value end end def test_assoc_yield [{:key=>:value}, H.new].each {|h| - h.each{|a| assert_equal([:key, :value], a)} - h.each{|*a| assert_equal([[:key, :value]], a)} + h.each{|a| assert_equal(:key, a)} + h.each{|*a| assert_equal([:key, :value], a)} h.each{|k,v| assert_equal([:key, :value], [k,v])} } end diff --git a/test/ruby/test_stringchar.rb b/test/ruby/test_stringchar.rb index 34934e87bd..c128181b2f 100644 --- a/test/ruby/test_stringchar.rb +++ b/test/ruby/test_stringchar.rb @@ -68,9 +68,9 @@ END # character constants(assumes ASCII) assert_equal(?a, "a"[0]) assert_equal(?a, ?a) - assert_equal(1, ?\C-a) - assert_equal(225, ?\M-a) - assert_equal(129, ?\M-\C-a) + assert_equal("\1", ?\C-a) + assert_equal("\341", ?\M-a) + assert_equal("\201", ?\M-\C-a) assert_equal(?A, "a".upcase![0]) assert_equal(?a, "A".downcase![0]) assert_equal("ABC", "abc".tr!("a-z", "A-Z")) @@ -82,7 +82,7 @@ END $y = [ ?a, ?b, ?c, ?d, ?e, ?f ] $bad = false $x.each_byte {|i| - if i != $y.shift + if i.chr != $y.shift $bad = true break end diff --git a/time.c b/time.c index 88a5fedacc..60c0e6b641 100644 --- a/time.c +++ b/time.c @@ -157,7 +157,7 @@ static struct timeval time_timeval(VALUE time, int interval) { struct timeval t; - char *tstr = interval ? "time interval" : "time"; + const char *tstr = interval ? "time interval" : "time"; #ifndef NEGATIVE_TIME_T interval = 1; @@ -182,7 +182,7 @@ time_timeval(VALUE time, int interval) if (f != t.tv_sec) { rb_raise(rb_eRangeError, "%f out of Time range", RFLOAT(time)->value); } - t.tv_usec = (time_t)(d*1e6); + t.tv_usec = (time_t)(d*1e6+0.5); } break; @@ -1229,7 +1229,7 @@ time_add(struct time_object *tobj, VALUE offset, int sign) if (f != (double)sec_off) rb_raise(rb_eRangeError, "time %s %f out of Time range", sign < 0 ? "-" : "+", v); - usec_off = (time_t)(d*1e6); + usec_off = (time_t)(d*1e6+0.5); if (sign < 0) { sec = tobj->tv.tv_sec - sec_off; diff --git a/util.c b/util.c index 953927d145..fbc08de1e7 100644 --- a/util.c +++ b/util.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include #ifdef _WIN32 #include "missing/file.h" @@ -664,11 +666,9 @@ ruby_getcwd(void) * */ -#define TRUE 1 -#define FALSE 0 +#define MDMINEXPT DBL_MIN_EXP +#define MDMAXEXPT DBL_MAX_EXP -static int MDMINEXPT = -323; -static int MDMAXEXPT = 309; static double powersOf10[] = { /* Table giving binary powers of 10. Entry */ 10.0, /* is 10^2^i. Used to convert decimal */ 100.0, /* exponents into floating-point numbers. */ @@ -720,8 +720,8 @@ ruby_strtod( char **endPtr) /* If non-NULL, store terminating character's * address here. */ { - int sign, expSign = FALSE; - double fraction, dblExp, *d; + int sign, expSign = Qfalse; + double fraction = 0.0, dblExp, *d; register const char *p; register int c; int exp = 0; /* Exponent read from "EX" field. */ @@ -735,8 +735,8 @@ ruby_strtod( * case, fracExp is incremented one for each * dropped digit. */ int mantSize = 0; /* Number of digits in mantissa. */ - int hasPoint = FALSE; /* Decimal point exists. */ - int hasDigit = FALSE; /* I or F exists. */ + int hasPoint = Qfalse; /* Decimal point exists. */ + int hasDigit = Qfalse; /* I or F exists. */ const char *pMant; /* Temporarily holds location of mantissa * in string. */ const char *pExp; /* Temporarily holds location of exponent @@ -748,44 +748,43 @@ ruby_strtod( errno = 0; p = string; - while (ISSPACE(*p)) { - p += 1; - } + while (ISSPACE(*p)) p++; if (*p == '-') { - sign = TRUE; - p += 1; + sign = Qtrue; + p++; } else { - if (*p == '+') { - p += 1; - } - sign = FALSE; + if (*p == '+') p++; + sign = Qfalse; } + fraction = 0.; + exp = 0; + /* * Count the number of digits in the mantissa * and also locate the decimal point. */ - for ( ; c = *p; p += 1) { + for ( ; c = *p; p++) { if (!ISDIGIT(c)) { if (c != '.' || hasPoint) { break; } - hasPoint = TRUE; + hasPoint = Qtrue; } else { if (hasPoint) { /* already in fractional part */ - fracExp -= 1; + fracExp--; } if (mantSize) { /* already in mantissa */ - mantSize += 1; + mantSize++; } else if (c != '0') { /* have entered mantissa */ - mantSize += 1; + mantSize++; pMant = p; } - hasDigit = TRUE; + hasDigit = Qtrue; } } @@ -796,7 +795,7 @@ ruby_strtod( * they can't affect the value anyway. */ - pExp = p; + pExp = p; if (mantSize) { p = pMant; } @@ -809,7 +808,7 @@ ruby_strtod( p = string; } else { - int frac1, frac2; + double frac1, frac2; frac1 = 0; for ( ; mantSize > 9; mantSize -= 1) { c = *p; @@ -837,21 +836,20 @@ ruby_strtod( p = pExp; if ((*p == 'E') || (*p == 'e')) { - p += 1; + p++; if (*p == '-') { - expSign = TRUE; - p += 1; + expSign = Qtrue; + p++; } else { if (*p == '+') { - p += 1; + p++; } - expSign = FALSE; + expSign = Qfalse; } if (ISDIGIT(*p)) { do { - exp = exp * 10 + (*p - '0'); - p += 1; + exp = exp * 10 + (*p++ - '0'); } while (ISDIGIT(*p)); } @@ -873,22 +871,22 @@ ruby_strtod( * fraction. */ - if (exp >= MDMAXEXPT - 18) { - exp = MDMAXEXPT; + if (exp >= MDMAXEXPT) { errno = ERANGE; + return HUGE_VAL * (sign ? -1.0 : 1.0); } - else if (exp < MDMINEXPT + 18) { - exp = MDMINEXPT; + else if (exp < MDMINEXPT) { errno = ERANGE; + return 0.0 * (sign ? -1.0 : 1.0); } fracExp = exp; exp += 9; if (exp < 0) { - expSign = TRUE; + expSign = Qtrue; exp = -exp; } else { - expSign = FALSE; + expSign = Qfalse; } dblExp = 1.0; for (d = powersOf10; exp != 0; exp >>= 1, d += 1) { @@ -897,18 +895,18 @@ ruby_strtod( } } if (expSign) { - fraction = frac1 / dblExp; + frac1 /= dblExp; } else { - fraction = frac1 * dblExp; + frac1 *= dblExp; } exp = fracExp; if (exp < 0) { - expSign = TRUE; + expSign = Qtrue; exp = -exp; } else { - expSign = FALSE; + expSign = Qfalse; } dblExp = 1.0; for (d = powersOf10; exp != 0; exp >>= 1, d += 1) { @@ -917,17 +915,17 @@ ruby_strtod( } } if (expSign) { - fraction += frac2 / dblExp; + frac2 /= dblExp; } else { - fraction += frac2 * dblExp; + frac2 *= dblExp; } + fraction = frac1 + frac2; } if (endPtr != NULL) { - *endPtr = (char *) p; + *endPtr = (char *)p; } - if (sign) { return -fraction; } diff --git a/variable.c b/variable.c index 7bd55eb0db..50f3e092fe 100644 --- a/variable.c +++ b/variable.c @@ -186,7 +186,7 @@ rb_class_path(VALUE klass) return path; } else { - char *s = "Class"; + const char *s = "Class"; if (TYPE(klass) == T_MODULE) { if (rb_obj_class(klass) == rb_cModule) { @@ -711,7 +711,7 @@ rb_f_global_variables(void) { VALUE ary = rb_ary_new(); char buf[4]; - char *s = "&`'+123456789"; + const char *s = "&`'+123456789"; st_foreach_safe(rb_global_tbl, gvar_i, ary); if (!NIL_P(rb_backref_get())) { @@ -1282,7 +1282,7 @@ rb_const_get_0(VALUE klass, ID id, int exclude, int recurse, NODE *fallback) tmp = klass; retry: - while (tmp) { + while (tmp && !NIL_P(tmp)) { while (RCLASS(tmp)->iv_tbl && st_lookup(RCLASS(tmp)->iv_tbl,id,&value)) { if (value == Qundef) { if (!RTEST(rb_autoload_load(tmp, id))) break; @@ -1510,7 +1510,7 @@ rb_const_defined_fallback(VALUE klass, ID id, NODE *fallback) static void mod_av_set(VALUE klass, ID id, VALUE val, int isconst) { - char *dest = isconst ? "constant" : "class variable"; + const char *dest = isconst ? "constant" : "class variable"; if (!OBJ_TAINTED(klass) && rb_safe_level() >= 4) rb_raise(rb_eSecurityError, "Insecure: can't set %s", dest); @@ -1542,6 +1542,10 @@ mod_av_set(VALUE klass, ID id, VALUE val, int isconst) void rb_const_set(VALUE klass, ID id, VALUE val) { + if (NIL_P(klass)) { + rb_raise(rb_eTypeError, "no class/module to define constant %s", + rb_id2name(id)); + } mod_av_set(klass, id, val, Qtrue); } -- cgit v1.2.3