1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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 <florg at florg.net>.

* 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 <decoux at moulon.inra.fr>.  [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 <tewk at tewk.com>.
  [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
  <rubypate at gmail.com>.  [ruby-core:07809]

* array.c (rb_ary_fill): initialize local variables first.  a
  patch from Pat Eyler <rubypate at gmail.com>.	 [ruby-core:07810]

* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
  type_tag.  a patch from Pat Eyler <rubypate at gmail.com>.
  [ruby-core:07808]

* ext/socket/socket.c (make_hostent_internal): accept ai_family
  check from Sam Roberts <sroberts at uniserve.com>.
  [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
  <tommy at tmtm.org>.	[ruby-dev:28601]

* applied code clean-up patch from Stefan Huehner
  <stefan at huehner.org>.  [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 <gimite at gimite.ddo.jp> [ruby-list:42090]

* ext/socket/socket.c: document update patch from Sam Roberts
  <sroberts at uniserve.com>.  [ruby-core:07701]

* lib/mathn.rb (Integer): need not to remove gcd2.  a patch from
  NARUSE, Yui <naruse at airemix.com>.	[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 <meta at pobox.com>.  [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
  <gerardo.santana at gmail.com>.  [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  <sndgk393 AT ybb.ne.jp>

* 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
  <kuwa at labs.fujitsu.com>.  [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
  <dlutter at redhat.com>.  [ruby-core:7508]

* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
  directories.	a patch from Eric Hodel <drbrain at segment7.net>.
  [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 <weil at mail.berlios.de>.

* 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
This commit is contained in:
matz 2006-06-09 21:20:17 +00:00
parent f83f236f25
commit 9b383bd6cf
91 changed files with 2666 additions and 2346 deletions

View file

@ -1,6 +1,6 @@
Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>. Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
You can redistribute it and/or modify it under either the terms of the GPL 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 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 software without restriction, provided that you duplicate all of the

382
ChangeLog
View file

@ -1,12 +1,38 @@
Fri Jun 9 09:56:32 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
Thu Jun 8 14:00:02 2006 NAKAMURA Usaku <usa@ruby-lang.org> Thu Jun 8 14:00:02 2006 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.[ch] (rb_w32_read, rb_w32_write): new functions. * win32/win32.[ch] (rb_w32_read, rb_w32_write): new functions.
use recv() and send() when fd is socket. fixed: [ruby-dev:28694] use recv() and send() when fd is socket. fixed: [ruby-dev:28694]
Wed Jun 7 16:22:51 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
Wed Jun 7 16:16:29 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
Wed Jun 7 14:51:22 2006 NAKAMURA Usaku <usa@ruby-lang.org> Wed Jun 7 14:51:22 2006 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (errmap): add some winsock errors. * win32/win32.c (errmap): add some winsock errors.
Wed Jun 7 09:14:44 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <matz@ruby-lang.org>
* 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 <akr@m17n.org> Mon Jun 5 18:12:12 2006 Tanaka Akira <akr@m17n.org>
* ext/socket/socket.c (sock_s_unpack_sockaddr_in): reject * ext/socket/socket.c (sock_s_unpack_sockaddr_in): reject
@ -19,6 +45,20 @@ Sun Jun 4 20:40:19 2006 Tanaka Akira <akr@m17n.org>
* ext/socket/socket.c: fix sockaddr_un handling. * ext/socket/socket.c: fix sockaddr_un handling.
[ruby-dev:28677] [ruby-dev:28677]
Sat Jun 3 23:53:18 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
Sat Jun 3 13:10:41 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* st.c (strhash): use FNV-1a hash.
Fri Jun 2 20:01:24 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* parse.y (parser_yylex): removed experimental ';;' terminator.
Fri Jun 2 19:00:40 2006 GOTOU Yuuzou <gotoyuzo@notwork.org> Fri Jun 2 19:00:40 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/extconf.rb: use create_header. * ext/openssl/extconf.rb: use create_header.
@ -48,17 +88,67 @@ Thu Jun 1 19:12:37 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
* win32/win32.c (rb_w32_cmdvector): backslashes inside single-quotes * win32/win32.c (rb_w32_cmdvector): backslashes inside single-quotes
no longer has special meanings. fixed: [ruby-list:42311] no longer has special meanings. fixed: [ruby-list:42311]
Thu Jun 1 17:55:42 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <usa@ruby-lang.org> Thu Jun 1 16:17:26 2006 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (rb_w32_getcwd): runtime's getcwd() will not success * win32/win32.c (rb_w32_getcwd): runtime's getcwd() will not success
if the length of the cwd is longer than MAX_PATH. if the length of the cwd is longer than MAX_PATH.
fixed [ruby-list:42335] fixed [ruby-list:42335]
Thu Jun 1 16:07:48 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <usa@ruby-lang.org> Thu Jun 1 11:33:32 2006 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (rb_w32_getcwd): set errno if not set. * win32/win32.c (rb_w32_getcwd): set errno if not set.
fixed [ruby-list:42346] fixed [ruby-list:42346]
Thu Jun 1 00:45:52 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* parse.y (args): allow more than one splat in the argument list.
Wed May 31 18:38:11 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <matz@ruby-lang.org>
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
Mon May 29 22:40:13 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <matz@ruby-lang.org> Sat May 27 22:46:38 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (proc_invoke): save and restore block in the current frame. * 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 <nobu@ruby-lang.org>
* ext/extmk.rb (extmake): remove extinit files if no statically linked * ext/extmk.rb (extmake): remove extinit files if no statically linked
extensions. extensions.
Fri May 26 19:56:46 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
Fri May 26 09:05:11 2006 Nobuyoshi Nakada <nobu@ruby-lang.org> Fri May 26 09:05:11 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ruby.h, lib/mkmf.rb (create_header): clear command line options for * ruby.h, lib/mkmf.rb (create_header): clear command line options for
@ -103,6 +198,16 @@ Wed May 24 23:52:11 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (ac_install_sh): ignore dummy install-sh. * configure.in (ac_install_sh): ignore dummy install-sh.
[ruby-talk:193876] [ruby-talk:193876]
Wed May 24 17:55:13 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <gotoyuzo@notwork.org> Wed May 24 03:10:44 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/lib/openssl/ssl.rb * ext/openssl/lib/openssl/ssl.rb
@ -125,6 +230,16 @@ Mon May 22 16:32:03 2006 Tanaka Akira <akr@m17n.org>
[ruby-core:7917] [ruby-core:7917]
Mon May 22 15:57:39 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
Mon May 22 13:38:57 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <sndgk393 AT ybb.ne.jp> Sun May 21 09:50:31 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* regexec.c: add STK_NULL_CHECK_END to IS_TO_VOID_TARGET(). * regexec.c: add STK_NULL_CHECK_END to IS_TO_VOID_TARGET().
@ -152,14 +267,54 @@ Thu May 18 22:37:20 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
* test/webrick/test_utils.rb: test for WEBrick::Utils.timeout. * test/webrick/test_utils.rb: test for WEBrick::Utils.timeout.
Thu May 18 17:51:32 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <nobu@ruby-lang.org> Thu May 18 00:42:12 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/extmk.rb, lib/mkmf.rb: use BUILD_FILE_SEPARATOR in Makefiles. * ext/extmk.rb, lib/mkmf.rb: use BUILD_FILE_SEPARATOR in Makefiles.
Wed May 17 17:55:26 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
Tue May 16 17:23:19 2006 <sinara@blade.nagaokaut.ac.jp>
* 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 <matz@ruby-lang.org>
* 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 <matz@ruby-lang.org>
* 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 <sndgk393 AT ybb.ne.jp> Mon May 15 21:37:12 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* re.c (rb_reg_prepare_re): don't use onig_recompile(). * re.c (rb_reg_prepare_re): don't use onig_recompile().
Mon May 15 17:42:39 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
Sat May 13 16:14:05 2006 Tanaka Akira <akr@m17n.org> Sat May 13 16:14:05 2006 Tanaka Akira <akr@m17n.org>
* lib/pp.rb (PP.mcall): new method. * lib/pp.rb (PP.mcall): new method.
@ -168,11 +323,27 @@ Sat May 13 16:14:05 2006 Tanaka Akira <akr@m17n.org>
(Struct#pretty_print_cycle): ditto. (Struct#pretty_print_cycle): ditto.
[ruby-core:7865] [ruby-core:7865]
Fri May 12 15:54:48 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <matz@ruby-lang.org>
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
Thu May 11 18:30:11 2006 GOTOU Yuuzou <gotoyuzo@notwork.org> Thu May 11 18:30:11 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_cipher.c (add_cipher_name_to_ary): should return * ext/openssl/ossl_cipher.c (add_cipher_name_to_ary): should return
value. [ruby-dev:28627] value. [ruby-dev:28627]
Thu May 11 18:10:43 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <sndgk393 AT ybb.ne.jp> Wed May 10 23:40:21 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* oniguruma.h: Version 4.0.3 * oniguruma.h: Version 4.0.3
@ -203,6 +374,45 @@ Sun May 7 03:09:51 2006 Stephan Maka <stephan@spaceboyz.net>
* lib/resolv.rb (Resolv::DNS::Requester::ConnectedUDP#initialize): * lib/resolv.rb (Resolv::DNS::Requester::ConnectedUDP#initialize):
Use AF_INET6 for nameservers containing colons. Use AF_INET6 for nameservers containing colons.
Sat May 6 23:40:03 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
Sat May 6 00:38:42 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
Thu May 4 22:13:22 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <matz@ruby-lang.org>
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
Wed May 3 02:12:07 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
Mon May 1 17:58:16 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp> Mon May 1 17:58:16 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c (add_event_call_back): should not * ext/win32ole/win32ole.c (add_event_call_back): should not
@ -218,16 +428,75 @@ Sat Apr 29 22:43:37 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_asn1.c (ossl_asn1_decode0): should initialize * ext/openssl/ossl_asn1.c (ossl_asn1_decode0): should initialize
flag. [ruby-core:07785] flag. [ruby-core:07785]
Fri Apr 28 10:53:16 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <matz@ruby-lang.org>
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
Wed Apr 26 16:59:24 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
Wed Apr 26 16:55:19 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
Tue Apr 25 18:00:05 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> Tue Apr 25 18:00:05 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/tcltklib.c (delete_slaves): maybe increment the reference * ext/tk/tcltklib.c (delete_slaves): maybe increment the reference
count of a NULL Tcl_Obj [ruby-core:07759]. count of a NULL Tcl_Obj [ruby-core:07759].
Tue Apr 25 07:55:31 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
Fri Apr 21 15:19:13 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> Fri Apr 21 15:19:13 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/tcltklib.c (lib_eventloop_ensure): refer freed pointer * ext/tk/tcltklib.c (lib_eventloop_ensure): refer freed pointer
[ruby-core:07744] and memory leak. [ruby-core:07744] and memory leak.
Fri Apr 21 12:14:52 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
Thu Apr 20 08:43:54 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
Wed Apr 19 13:55:27 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <matz@ruby-lang.org>
* 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 <matz@ruby-lang.org>
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
Wed Apr 19 10:13:27 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <nagai@ai.kyutech.ac.jp> Tue Apr 18 17:40:37 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/multi-tk.rb: add a binding to a container for a slave IP. * ext/tk/lib/multi-tk.rb: add a binding to a container for a slave IP.
@ -238,6 +507,20 @@ Tue Apr 18 17:40:37 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/stubs.c: fix potential bugs about handling rb_argv0. * ext/tk/stubs.c: fix potential bugs about handling rb_argv0.
Mon Apr 10 01:03:10 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
Sat Apr 8 02:34:34 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <matz@ruby-lang.org>
* README.EXT: update symbol description. [ruby-talk:188104]
Sat Apr 8 18:06:28 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp> Sat Apr 8 18:06:28 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c: add WIN32OLE_METHOD#inspect, * ext/win32ole/win32ole.c: add WIN32OLE_METHOD#inspect,
@ -254,6 +537,10 @@ Fri Apr 7 22:11:30 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* test/win32ole/test_win32ole_typelib.rb(test_initialize): ditto. * test/win32ole/test_win32ole_typelib.rb(test_initialize): ditto.
Thu Apr 6 23:28:47 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
Thu Apr 6 16:43:06 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> Thu Apr 6 16:43:06 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* intern.h (rb_obj_instance_exec, rb_mod_module_exec): add declaration. * intern.h (rb_obj_instance_exec, rb_mod_module_exec): add declaration.
@ -287,6 +574,11 @@ Wed Apr 5 00:22:54 2006 Tanaka Akira <akr@m17n.org>
methods take pathname argument. suggested by Evan Phoenix. methods take pathname argument. suggested by Evan Phoenix.
[ruby-core:7618] [ruby-core:7618]
Tue Apr 4 22:15:41 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
Sat Apr 1 15:11:27 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp> Sat Apr 1 15:11:27 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c :add WIN32OLE_TYPE#inspect, * ext/win32ole/win32ole.c :add WIN32OLE_TYPE#inspect,
@ -337,6 +629,14 @@ Mon Mar 27 22:45:37 2006 NARUSE, Yui <naruse@ruby-lang.org>
* ext/nkf/nkf.c, ext/nkf/lib/kconv.rb: Add rdoc. * ext/nkf/nkf.c, ext/nkf/lib/kconv.rb: Add rdoc.
Mon Mar 27 03:17:21 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <sndgk393 AT ybb.ne.jp> Sun Mar 26 22:02:51 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* re.c: refactoring for options. * re.c: refactoring for options.
@ -351,6 +651,11 @@ Fri Mar 24 21:11:02 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* string.c (rb_str_gsub): ditto. * string.c (rb_str_gsub): ditto.
Fri Mar 24 17:20:03 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <sndgk393 AT ybb.ne.jp> Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* re.c (rb_reg_regsub): prohibit \1, \2 ...\9 in replaced string * 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 <sndgk393 AT ybb.ne.jp>
* regerror.c: ditto. * regerror.c: ditto.
Thu Mar 23 10:47:03 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <sndgk393 AT ybb.ne.jp> Thu Mar 23 00:01:32 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* re.c (rb_reg_regsub): add back reference by name \k<name> in * re.c (rb_reg_regsub): add back reference by name \k<name> in
@ -387,11 +698,21 @@ Tue Mar 21 22:14:01 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* gc.c (gc_mark_children): add gc_mark() to regexp member. * gc.c (gc_mark_children): add gc_mark() to regexp member.
Mon Mar 20 12:05:18 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
Mon Mar 20 11:12:38 2006 NAKAMURA Usaku <usa@ruby-lang.org> Mon Mar 20 11:12:38 2006 NAKAMURA Usaku <usa@ruby-lang.org>
* ext/win32ole/win32ole.c (folevariant_value): could not compile * ext/win32ole/win32ole.c (folevariant_value): could not compile
with C90 compiler. with C90 compiler.
Mon Mar 20 09:40:23 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
Sun Mar 19 09:46:30 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp> Sun Mar 19 09:46:30 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior * ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
@ -421,6 +742,11 @@ Sun Mar 12 17:02:10 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/tests/testOLEPARAM.rb: test method name should not be * ext/win32ole/tests/testOLEPARAM.rb: test method name should not be
duplicated. duplicated.
Sat Mar 11 14:24:06 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
Sun Mar 5 18:40:58 2006 Minero Aoki <aamine@loveruby.net> Sun Mar 5 18:40:58 2006 Minero Aoki <aamine@loveruby.net>
* lib/fileutils.rb: do not repeat command options. * lib/fileutils.rb: do not repeat command options.
@ -434,14 +760,23 @@ Sat Mar 4 15:26:40 2006 Tanaka Akira <akr@m17n.org>
* gc.c (id2ref): fix symbol test. * gc.c (id2ref): fix symbol test.
Sat Mar 4 01:08:07 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
Fri Mar 3 17:59:00 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
Fri Mar 3 21:22:42 2006 Tanaka Akira <akr@m17n.org> Fri Mar 3 21:22:42 2006 Tanaka Akira <akr@m17n.org>
* lib/fileutils.rb (FileUtils.cp_r): implement :remove_destination * lib/fileutils.rb (FileUtils.cp_r): implement :remove_destination
option. option.
* ext/extmk.rb: use :remove_destination to install extension libraries * ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. to avoid SEGV. [ruby-dev:28417]
[ruby-dev:28417]
Fri Mar 3 14:41:04 2006 Minero Aoki <aamine@loveruby.net> Fri Mar 3 14:41:04 2006 Minero Aoki <aamine@loveruby.net>
@ -451,6 +786,39 @@ Fri Mar 3 14:41:04 2006 Minero Aoki <aamine@loveruby.net>
* ext/socket/.cvsignore: ignore constants.h. * ext/socket/.cvsignore: ignore constants.h.
Thu Mar 2 18:58:18 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <matz@ruby-lang.org>
* 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 <matz@ruby-lang.org>
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
Wed Mar 1 17:13:37 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <ocean@m2.ccsnet.ne.jp> Thu Mar 2 17:54:45 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* gc.c: commited magic for reducing RVALUE size on windows. (24->20byte) * gc.c: commited magic for reducing RVALUE size on windows. (24->20byte)
@ -476,6 +844,16 @@ Wed Mar 1 00:15:51 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
merged Mr. Ishizuka's lib/irb/ruby-lex.rb 's patch rev 1.29. merged Mr. Ishizuka's lib/irb/ruby-lex.rb 's patch rev 1.29.
[ruby-talk:181631] [ruby-dev:28404] [ruby-talk:181631] [ruby-dev:28404]
Tue Feb 28 19:32:14 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
Mon Feb 27 00:19:16 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
Fri Feb 24 20:21:38 2006 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp> Fri Feb 24 20:21:38 2006 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* test/drb/drbtest.rb (add_service_command): quote pathnames in the * test/drb/drbtest.rb (add_service_command): quote pathnames in the

View file

@ -330,17 +330,30 @@ of the innermost method (which is defined by Ruby) can be accessed.
2.2.2 ID or Symbol 2.2.2 ID or Symbol
You can invoke methods directly, without parsing the string. First I You can invoke methods directly, without parsing the string. First I need
need to explain about symbols (whose data type is ID). ID is the to explain about ID. ID is the integer number to represent Ruby's
integer number to represent Ruby's identifiers such as variable names. identifiers such as variable names. The Ruby data type corresponding to ID
It can be accessed from Ruby in the form: is Symbol. It can be accessed from Ruby in the form:
:Identifier :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) 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 2.2.3 Invoke Ruby method from C
To invoke methods directly, you can use the function below To invoke methods directly, you can use the function below

88
array.c
View file

@ -17,7 +17,7 @@
#include "st.h" #include "st.h"
#include "node.h" #include "node.h"
VALUE rb_cArray, rb_cValues; VALUE rb_cArray;
static ID id_cmp; static ID id_cmp;
@ -169,38 +169,6 @@ rb_ary_new4(long n, const VALUE *elts)
return ary; 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; i<n; i++) {
RARRAY(val)->ptr[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 static VALUE
ary_make_shared(VALUE ary) ary_make_shared(VALUE ary)
{ {
@ -234,22 +202,10 @@ ary_shared_array(VALUE klass, VALUE ary)
return val; 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 VALUE
rb_assoc_new(VALUE car, VALUE cdr) rb_assoc_new(VALUE car, VALUE cdr)
{ {
return rb_values_new(2, car, cdr); return rb_ary_new3(2, car, cdr);
} }
static VALUE static VALUE
@ -2099,7 +2055,7 @@ static VALUE
rb_ary_fill(int argc, VALUE *argv, VALUE ary) rb_ary_fill(int argc, VALUE *argv, VALUE ary)
{ {
VALUE item, arg1, arg2; VALUE item, arg1, arg2;
long beg, end, len; long beg = 0, end = 0, len = 0;
VALUE *p, *pend; VALUE *p, *pend;
int block_p = Qfalse; int block_p = Qfalse;
@ -2739,28 +2695,31 @@ rb_ary_nitems(VALUE ary)
} }
static long static long
flatten(VALUE ary, long idx, VALUE ary2, VALUE memo) flatten(VALUE ary, long idx, VALUE ary2, VALUE memo, int level)
{ {
VALUE id; VALUE id;
long i = idx; long i = idx;
long n, lim = idx + RARRAY(ary2)->len; long n, lim = idx + RARRAY(ary2)->len;
level--;
id = rb_obj_id(ary2); id = rb_obj_id(ary2);
if (rb_ary_includes(memo, id)) { if (rb_ary_includes(memo, id)) {
rb_raise(rb_eArgError, "tried to flatten recursive array"); rb_raise(rb_eArgError, "tried to flatten recursive array");
} }
rb_ary_push(memo, id); rb_ary_push(memo, id);
rb_ary_splice(ary, idx, 1, ary2); rb_ary_splice(ary, idx, 1, ary2);
if (level != 0) {
while (i < lim) { while (i < lim) {
VALUE tmp; VALUE tmp;
tmp = rb_check_array_type(rb_ary_elt(ary, i)); tmp = rb_check_array_type(rb_ary_elt(ary, i));
if (!NIL_P(tmp)) { if (!NIL_P(tmp)) {
n = flatten(ary, i, tmp, memo); n = flatten(ary, i, tmp, memo, level);
i += n; lim += n; i += n; lim += n;
} }
i++; i++;
} }
}
rb_ary_pop(memo); rb_ary_pop(memo);
return lim - idx - 1; /* returns number of increased items */ return lim - idx - 1; /* returns number of increased items */
@ -2769,24 +2728,33 @@ flatten(VALUE ary, long idx, VALUE ary2, VALUE memo)
/* /*
* call-seq: * call-seq:
* array.flatten! -> array or nil * array.flatten! -> array or nil
* array.flatten!(level) -> array or nil
* *
* Flattens _self_ in place. * Flattens _self_ in place.
* Returns <code>nil</code> if no modifications were made (i.e., * Returns <code>nil</code> if no modifications were made (i.e.,
* <i>array</i> contains no subarrays.) * <i>array</i> contains no subarrays.) If the optional <i>level</i>
* argument determins the level of recursion to flatten.
* *
* a = [ 1, 2, [3, [4, 5] ] ] * a = [ 1, 2, [3, [4, 5] ] ]
* a.flatten! #=> [1, 2, 3, 4, 5] * a.flatten! #=> [1, 2, 3, 4, 5]
* a.flatten! #=> nil * a.flatten! #=> nil
* a #=> [1, 2, 3, 4, 5] * a #=> [1, 2, 3, 4, 5]
* a = [ 1, 2, [3, [4, 5] ] ]
* a.flatten!(1) #=> [1, 2, 3, [4, 5]]
*/ */
static VALUE static VALUE
rb_ary_flatten_bang(VALUE ary) rb_ary_flatten_bang(int argc, VALUE *argv, VALUE ary)
{ {
long i = 0; long i = 0;
int mod = 0; int mod = 0;
int level = -1;
VALUE memo = Qnil; 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 (i<RARRAY(ary)->len) { while (i<RARRAY(ary)->len) {
VALUE ary2 = RARRAY(ary)->ptr[i]; VALUE ary2 = RARRAY(ary)->ptr[i];
VALUE tmp; VALUE tmp;
@ -2796,7 +2764,7 @@ rb_ary_flatten_bang(VALUE ary)
if (NIL_P(memo)) { if (NIL_P(memo)) {
memo = rb_ary_new(); memo = rb_ary_new();
} }
i += flatten(ary, i, tmp, memo); i += flatten(ary, i, tmp, memo, level);
mod = 1; mod = 1;
} }
i++; i++;
@ -2808,22 +2776,26 @@ rb_ary_flatten_bang(VALUE ary)
/* /*
* call-seq: * call-seq:
* array.flatten -> an_array * array.flatten -> an_array
* array.flatten(level) -> an_array
* *
* Returns a new array that is a one-dimensional flattening of this * Returns a new array that is a one-dimensional flattening of this
* array (recursively). That is, for every element that is an array, * 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
* <i>level</i> argument determins the level of recursion to flatten.
* *
* s = [ 1, 2, 3 ] #=> [1, 2, 3] * s = [ 1, 2, 3 ] #=> [1, 2, 3]
* t = [ 4, 5, 6, [7, 8] ] #=> [4, 5, 6, [7, 8]] * 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 = [ 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.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 static VALUE
rb_ary_flatten(VALUE ary) rb_ary_flatten(int argc, VALUE *argv, VALUE ary)
{ {
ary = rb_ary_dup(ary); ary = rb_ary_dup(ary);
rb_ary_flatten_bang(ary); rb_ary_flatten_bang(argc, argv, ary);
return 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, "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, 0);
rb_define_method(rb_cArray, "compact!", rb_ary_compact_bang, 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, -1);
rb_define_method(rb_cArray, "flatten!", rb_ary_flatten_bang, 0); rb_define_method(rb_cArray, "flatten!", rb_ary_flatten_bang, -1);
rb_define_method(rb_cArray, "nitems", rb_ary_nitems, 0); rb_define_method(rb_cArray, "nitems", rb_ary_nitems, 0);
id_cmp = rb_intern("<=>"); id_cmp = rb_intern("<=>");
rb_cValues = rb_define_class("Values", rb_cArray);
} }

View file

@ -406,7 +406,7 @@ rb_cstr_to_inum(const char *str, int base, int badcheck)
len *= strlen(str)*sizeof(char); len *= strlen(str)*sizeof(char);
if (len <= (sizeof(VALUE)*CHAR_BIT)) { 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 (*end == '_') goto bigparse;
if (badcheck) { if (badcheck) {
@ -516,7 +516,7 @@ rb_str_to_inum(VALUE str, int base, int badcheck)
#if HAVE_LONG_LONG #if HAVE_LONG_LONG
VALUE static VALUE
rb_ull2big(unsigned LONG_LONG n) rb_ull2big(unsigned LONG_LONG n)
{ {
BDIGIT_DBL num = n; BDIGIT_DBL num = n;
@ -537,7 +537,7 @@ rb_ull2big(unsigned LONG_LONG n)
return big; return big;
} }
VALUE static VALUE
rb_ll2big(LONG_LONG n) rb_ll2big(LONG_LONG n)
{ {
long neg = 0; long neg = 0;
@ -595,10 +595,10 @@ rb_big2str(VALUE x, int base)
if (FIXNUM_P(x)) { if (FIXNUM_P(x)) {
return rb_fix2str(x, base); return rb_fix2str(x, base);
} }
i = RBIGNUM(x)->len;
if (BIGZEROP(x)) { if (BIGZEROP(x)) {
return rb_str_new2("0"); return rb_str_new2("0");
} }
i = RBIGNUM(x)->len;
j = SIZEOF_BDIGITS*CHAR_BIT*i; j = SIZEOF_BDIGITS*CHAR_BIT*i;
switch (base) { switch (base) {
case 2: break; case 2: break;
@ -1546,6 +1546,11 @@ rb_big_pow(VALUE x, VALUE y)
if (yy > 0) { if (yy > 0) {
VALUE z = x; 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 (;;) { for (;;) {
yy -= 1; yy -= 1;
if (yy == 0) break; if (yy == 0) break;

41
class.c
View file

@ -344,7 +344,7 @@ include_class_new(VALUE module, VALUE super)
void void
rb_include_module(VALUE klass, VALUE module) rb_include_module(VALUE klass, VALUE module)
{ {
VALUE p, c; VALUE c;
int changed = 0; int changed = 0;
rb_frozen_class_p(klass); rb_frozen_class_p(klass);
@ -362,30 +362,11 @@ rb_include_module(VALUE klass, VALUE module)
OBJ_INFECT(klass, module); OBJ_INFECT(klass, module);
c = klass; c = klass;
while (module) { while (module) {
int superclass_seen = Qfalse;
if (RCLASS(klass)->m_tbl == RCLASS(module)->m_tbl) if (RCLASS(klass)->m_tbl == RCLASS(module)->m_tbl)
rb_raise(rb_eArgError, "cyclic include detected"); 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); RCLASS(c)->super = include_class_new(module, RCLASS(c)->super);
c = RCLASS(c)->super; c = RCLASS(c)->super;
changed = 1; changed = 1;
skip:
module = RCLASS(module)->super; module = RCLASS(module)->super;
} }
if (changed) rb_clear_cache(); 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_PRIVATE:
case NOEX_PROTECTED: case NOEX_PROTECTED:
case NOEX_PUBLIC: case NOEX_PUBLIC:
case NOEX_LOCAL:
visi = (type == visi); visi = (type == visi);
break; break;
default: default:
@ -536,6 +518,12 @@ ins_methods_pub_i(ID name, long type, VALUE ary)
return ins_methods_push(name, type, ary, NOEX_PUBLIC); 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 static int
method_entry(ID key, NODE *body, st_table *list) 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); 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 <i>mod</i>.
*/
VALUE
rb_class_local_methods(VALUE mod)
{
return class_instance_method_list(0, 0, mod, ins_methods_local_i);
}
/* /*
* call-seq: * call-seq:
* obj.singleton_methods(all=true) => array * obj.singleton_methods(all=true) => array

View file

@ -509,7 +509,7 @@ AC_CHECK_FUNCS(fmod killpg wait4 waitpid fork spawnv syscall chroot fsync getcwd
getpgrp setpgrp getpgid setpgid initgroups getgroups setgroups\ getpgrp setpgrp getpgid setpgid initgroups getgroups setgroups\
getpriority getrlimit setrlimit\ getpriority getrlimit setrlimit\
dlopen sigprocmask sigaction _setjmp vsnprintf snprintf\ 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) setuid setgid daemon select_large_fdset setenv unsetenv)
AC_ARG_ENABLE(setreuid, AC_ARG_ENABLE(setreuid,
[ --enable-setreuid use setreuid()/setregid() according to need even if obsolete.], [ --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' LIBRUBY_ALIASES='lib$(RUBY_SO_NAME).so.$(MAJOR).$(MINOR).$(TEENY) lib$(RUBY_SO_NAME).so'
if test "$GCC" = yes; then if test "$GCC" = yes; then
LIBRUBY_DLDFLAGS="$DLDFLAGS "'-Wl,-h,$(@F)' LIBRUBY_DLDFLAGS="$DLDFLAGS "'-Wl,-h,$(@F)'
else
enable_rpath=no
fi fi
XLDFLAGS="$XLDFLAGS "'-R${libdir}' XLDFLAGS="$XLDFLAGS "'-R${libdir}'
;; ;;
@ -1307,7 +1305,11 @@ if test "$enable_shared" = 'yes'; then
esac esac
fi fi
if test "$enable_rpath" = yes; then if test "$enable_rpath" = yes; then
if test "$GCC" = yes; then
LIBRUBYARG_SHARED='-Wl,-R -Wl,$(libdir) -L$(libdir) -L. '"$LIBRUBYARG_SHARED" LIBRUBYARG_SHARED='-Wl,-R -Wl,$(libdir) -L$(libdir) -L. '"$LIBRUBYARG_SHARED"
else
LIBRUBYARG_SHARED='-R $(libdir) -L$(libdir) -L. '"$LIBRUBYARG_SHARED"
fi
fi fi
XLDFLAGS="$XLDFLAGS -L." XLDFLAGS="$XLDFLAGS -L."

20
dir.c
View file

@ -441,7 +441,16 @@ dir_closed(void)
rb_raise(rb_eIOError, "closed directory"); 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 {\ #define GetDIR(obj, dirp) do {\
dir_check(dir);\
Data_Get_Struct(obj, struct dir_data, dirp);\ Data_Get_Struct(obj, struct dir_data, dirp);\
if (dirp->dir == NULL) dir_closed();\ if (dirp->dir == NULL) dir_closed();\
} while (0) } while (0)
@ -647,6 +656,9 @@ dir_rewind(VALUE dir)
{ {
struct dir_data *dirp; struct dir_data *dirp;
if (rb_safe_level() >= 4 && !OBJ_TAINTED(dir)) {
rb_raise(rb_eSecurityError, "Insecure: can't close");
}
GetDIR(dir, dirp); GetDIR(dir, dirp);
rewinddir(dirp->dir); rewinddir(dirp->dir);
return dir; return dir;
@ -903,9 +915,15 @@ dir_s_rmdir(VALUE obj, VALUE dir)
return INT2FIX(0); 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 GLOB_VERBOSE (1 << (sizeof(int) * CHAR_BIT - 1))
#define sys_warning(val) \ #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 */ /* System call with warning */
static int static int

View file

@ -27,7 +27,7 @@ static VALUE
proc_call(VALUE proc, VALUE args) proc_call(VALUE proc, VALUE args)
{ {
if (TYPE(args) != T_ARRAY) { if (TYPE(args) != T_ARRAY) {
args = rb_values_new(1, args); args = rb_ary_new3(1, args);
} }
return rb_proc_call(proc, args); return rb_proc_call(proc, args);
} }

View file

@ -209,7 +209,7 @@ rb_check_type(VALUE x, int t)
if (TYPE(x) != t) { if (TYPE(x) != t) {
while (type->type >= 0) { while (type->type >= 0) {
if (type->type == t) { if (type->type == t) {
char *etype; const char *etype;
if (NIL_P(x)) { if (NIL_P(x)) {
etype = "nil"; etype = "nil";
@ -434,7 +434,7 @@ static VALUE
check_backtrace(VALUE bt) check_backtrace(VALUE bt)
{ {
long i; 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)) { if (!NIL_P(bt)) {
int t = TYPE(bt); int t = TYPE(bt);
@ -683,7 +683,7 @@ name_err_mesg_to_str(VALUE obj)
mesg = ptr[0]; mesg = ptr[0];
if (NIL_P(mesg)) return Qnil; if (NIL_P(mesg)) return Qnil;
else { else {
char *desc = 0; const char *desc = 0;
VALUE d = 0, args[3]; VALUE d = 0, args[3];
obj = ptr[1]; obj = ptr[1];
@ -828,7 +828,7 @@ syserr_initialize(int argc, VALUE *argv, VALUE self)
#if !defined(_WIN32) && !defined(__VMS) #if !defined(_WIN32) && !defined(__VMS)
char *strerror(); char *strerror();
#endif #endif
char *err; const char *err;
VALUE mesg, error; VALUE mesg, error;
VALUE klass = rb_obj_class(self); VALUE klass = rb_obj_class(self);

895
eval.c

File diff suppressed because it is too large Load diff

View file

@ -3,7 +3,8 @@
iconv/iconv.c iconv/iconv.c
nkf/lib/kconv.rb nkf/lib/kconv.rb
nkf/nkf.c nkf/nkf.c
socket/socket.c
stringio/stringio.c stringio/stringio.c
strscan/strscan.c strscan/strscan.c
zlib/zlib.c
win32ole win32ole
zlib/zlib.c

View file

@ -10,7 +10,6 @@
#digest/sha1 #digest/sha1
#digest/sha2 #digest/sha2
#dl #dl
#enumerator
#etc #etc
#fcntl #fcntl
#gdbm #gdbm

View file

@ -302,7 +302,7 @@ VpNewRbClass(U_LONG mx, char *str, VALUE klass)
} }
VP_EXPORT Real * VP_EXPORT Real *
VpCreateRbObject(U_LONG mx, char *str) VpCreateRbObject(U_LONG mx, const char *str)
{ {
Real *pv = VpAlloc(mx,str); Real *pv = VpAlloc(mx,str);
pv->obj = (VALUE)Data_Wrap_Struct(rb_cBigDecimal, 0, BigDecimal_delete, pv); 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); ENTER(5);
Real *c, *a; Real *c, *a;
int iLoc; int iLoc = 0;
U_LONG mx; U_LONG mx;
VALUE vLoc; VALUE vLoc;
VALUE vRound; VALUE vRound;
@ -1578,7 +1578,7 @@ VpIsNegDoubleZero(double v)
} }
VP_EXPORT int VP_EXPORT int
VpException(unsigned short f,char *str,int always) VpException(unsigned short f, const char *str,int always)
{ {
VALUE exc; VALUE exc;
int fatal=0; int fatal=0;
@ -1720,7 +1720,7 @@ NaN:
* returns number of chars needed to represent vp in specified format. * returns number of chars needed to represent vp in specified format.
*/ */
VP_EXPORT U_LONG VP_EXPORT U_LONG
VpNumOfChars(Real *vp,char *pszFmt) VpNumOfChars(Real *vp,const char *pszFmt)
{ {
S_INT ex; S_INT ex;
U_LONG nc; U_LONG nc;
@ -1873,7 +1873,7 @@ overflow:
* NULL be returned if memory allocation is failed,or any error. * NULL be returned if memory allocation is failed,or any error.
*/ */
VP_EXPORT Real * 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; U_LONG i, ni, ipn, ipf, nf, ipe, ne, nalloc;
char v,*psz; 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 '+/-'. * ne ... number of characters in exp_chr[],not including '+/-'.
*/ */
VP_EXPORT int 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 i, j, ind_a, ma, mi, me;
U_LONG loc; U_LONG loc;

View file

@ -105,7 +105,7 @@ typedef struct {
VP_EXPORT Real * VP_EXPORT Real *
VpNewRbClass(U_LONG mx,char *str,VALUE klass); 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 VpBaseFig(void);
VP_EXPORT U_LONG VpDblFig(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 VpGetRoundMode(void);
VP_EXPORT unsigned long VpSetRoundMode(unsigned long n); 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 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 U_LONG VpInit(U_LONG BaseVal);
VP_EXPORT void *VpMemAlloc(U_LONG mb); VP_EXPORT void *VpMemAlloc(U_LONG mb);
VP_EXPORT void VpFree(Real *pv); 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 VpAsgn(Real *c,Real *a,int isw);
VP_EXPORT int VpAddSub(Real *c,Real *a,Real *b,int operation); VP_EXPORT int VpAddSub(Real *c,Real *a,Real *b,int operation);
VP_EXPORT int VpMult(Real *c,Real *a,Real *b); 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 int VpToSpecialString(Real *a,char *psz,int fPlus);
VP_EXPORT void VpToString(Real *a,char *psz,int fFmt,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 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 int VpVtoD(double *d,S_LONG *e,Real *m);
VP_EXPORT void VpDtoV(Real *m,double d); VP_EXPORT void VpDtoV(Real *m,double d);
VP_EXPORT void VpItoV(Real *m,S_INT ival); VP_EXPORT void VpItoV(Real *m,S_INT ival);

View file

@ -90,8 +90,7 @@ no_window()
} while (0) } while (0)
static void static void
free_window(winp) free_window(struct windata *winp)
struct windata *winp;
{ {
if (winp->window && winp->window != stdscr) delwin(winp->window); if (winp->window && winp->window != stdscr) delwin(winp->window);
winp->window = 0; winp->window = 0;
@ -99,9 +98,7 @@ free_window(winp)
} }
static VALUE static VALUE
prep_window(class, window) prep_window(VALUE class, WINDOW *window)
VALUE class;
WINDOW *window;
{ {
VALUE obj; VALUE obj;
struct windata *winp; struct windata *winp;
@ -178,8 +175,7 @@ curses_closed()
/* def clear */ /* def clear */
static VALUE static VALUE
curses_clear(obj) curses_clear(VALUE obj)
VALUE obj;
{ {
curses_stdscr(); curses_stdscr();
wclear(stdscr); wclear(stdscr);
@ -197,8 +193,7 @@ curses_clrtoeol()
/* def refresh */ /* def refresh */
static VALUE static VALUE
curses_refresh(obj) curses_refresh(VALUE obj)
VALUE obj;
{ {
curses_stdscr(); curses_stdscr();
refresh(); refresh();
@ -207,8 +202,7 @@ curses_refresh(obj)
/* def doupdate */ /* def doupdate */
static VALUE static VALUE
curses_doupdate(obj) curses_doupdate(VALUE obj)
VALUE obj;
{ {
curses_stdscr(); curses_stdscr();
#ifdef HAVE_DOUPDATE #ifdef HAVE_DOUPDATE
@ -221,8 +215,7 @@ curses_doupdate(obj)
/* def echo */ /* def echo */
static VALUE static VALUE
curses_echo(obj) curses_echo(VALUE obj)
VALUE obj;
{ {
curses_stdscr(); curses_stdscr();
echo(); echo();
@ -231,8 +224,7 @@ curses_echo(obj)
/* def noecho */ /* def noecho */
static VALUE static VALUE
curses_noecho(obj) curses_noecho(VALUE obj)
VALUE obj;
{ {
curses_stdscr(); curses_stdscr();
noecho(); noecho();
@ -241,8 +233,7 @@ curses_noecho(obj)
/* def raw */ /* def raw */
static VALUE static VALUE
curses_raw(obj) curses_raw(VALUE obj)
VALUE obj;
{ {
curses_stdscr(); curses_stdscr();
raw(); raw();
@ -251,8 +242,7 @@ curses_raw(obj)
/* def noraw */ /* def noraw */
static VALUE static VALUE
curses_noraw(obj) curses_noraw(VALUE obj)
VALUE obj;
{ {
curses_stdscr(); curses_stdscr();
noraw(); noraw();
@ -261,8 +251,7 @@ curses_noraw(obj)
/* def cbreak */ /* def cbreak */
static VALUE static VALUE
curses_cbreak(obj) curses_cbreak(VALUE obj)
VALUE obj;
{ {
curses_stdscr(); curses_stdscr();
cbreak(); cbreak();
@ -271,8 +260,7 @@ curses_cbreak(obj)
/* def nocbreak */ /* def nocbreak */
static VALUE static VALUE
curses_nocbreak(obj) curses_nocbreak(VALUE obj)
VALUE obj;
{ {
curses_stdscr(); curses_stdscr();
nocbreak(); nocbreak();
@ -281,8 +269,7 @@ curses_nocbreak(obj)
/* def nl */ /* def nl */
static VALUE static VALUE
curses_nl(obj) curses_nl(VALUE obj)
VALUE obj;
{ {
curses_stdscr(); curses_stdscr();
nl(); nl();
@ -291,8 +278,7 @@ curses_nl(obj)
/* def nonl */ /* def nonl */
static VALUE static VALUE
curses_nonl(obj) curses_nonl(VALUE obj)
VALUE obj;
{ {
curses_stdscr(); curses_stdscr();
nonl(); nonl();
@ -301,8 +287,7 @@ curses_nonl(obj)
/* def beep */ /* def beep */
static VALUE static VALUE
curses_beep(obj) curses_beep(VALUE obj)
VALUE obj;
{ {
#ifdef HAVE_BEEP #ifdef HAVE_BEEP
curses_stdscr(); curses_stdscr();
@ -313,8 +298,7 @@ curses_beep(obj)
/* def flash */ /* def flash */
static VALUE static VALUE
curses_flash(obj) curses_flash(VALUE obj)
VALUE obj;
{ {
#ifdef HAVE_FLASH #ifdef HAVE_FLASH
curses_stdscr(); curses_stdscr();
@ -325,9 +309,7 @@ curses_flash(obj)
/* def ungetch */ /* def ungetch */
static VALUE static VALUE
curses_ungetch(obj, ch) curses_ungetch(VALUE obj, VALUE ch)
VALUE obj;
VALUE ch;
{ {
#ifdef HAVE_UNGETCH #ifdef HAVE_UNGETCH
curses_stdscr(); curses_stdscr();
@ -340,10 +322,7 @@ curses_ungetch(obj, ch)
/* def setpos(y, x) */ /* def setpos(y, x) */
static VALUE static VALUE
curses_setpos(obj, y, x) curses_setpos(VALUE obj, VALUE y, VALUE x)
VALUE obj;
VALUE y;
VALUE x;
{ {
curses_stdscr(); curses_stdscr();
move(NUM2INT(y), NUM2INT(x)); move(NUM2INT(y), NUM2INT(x));
@ -352,8 +331,7 @@ curses_setpos(obj, y, x)
/* def standout */ /* def standout */
static VALUE static VALUE
curses_standout(obj) curses_standout(VALUE obj)
VALUE obj;
{ {
standout(); standout();
return Qnil; return Qnil;
@ -361,8 +339,7 @@ curses_standout(obj)
/* def standend */ /* def standend */
static VALUE static VALUE
curses_standend(obj) curses_standend(VALUE obj)
VALUE obj;
{ {
standend(); standend();
return Qnil; return Qnil;
@ -370,8 +347,7 @@ curses_standend(obj)
/* def inch */ /* def inch */
static VALUE static VALUE
curses_inch(obj) curses_inch(VALUE obj)
VALUE obj;
{ {
curses_stdscr(); curses_stdscr();
return CH2FIX(inch()); return CH2FIX(inch());
@ -379,9 +355,7 @@ curses_inch(obj)
/* def addch(ch) */ /* def addch(ch) */
static VALUE static VALUE
curses_addch(obj, ch) curses_addch(VALUE obj, VALUE ch)
VALUE obj;
VALUE ch;
{ {
curses_stdscr(); curses_stdscr();
addch(NUM2CH(ch)); addch(NUM2CH(ch));
@ -390,9 +364,7 @@ curses_addch(obj, ch)
/* def insch(ch) */ /* def insch(ch) */
static VALUE static VALUE
curses_insch(obj, ch) curses_insch(VALUE obj, VALUE ch)
VALUE obj;
VALUE ch;
{ {
curses_stdscr(); curses_stdscr();
insch(NUM2CH(ch)); insch(NUM2CH(ch));
@ -401,9 +373,7 @@ curses_insch(obj, ch)
/* def addstr(str) */ /* def addstr(str) */
static VALUE static VALUE
curses_addstr(obj, str) curses_addstr(VALUE obj, VALUE str)
VALUE obj;
VALUE str;
{ {
curses_stdscr(); curses_stdscr();
if (!NIL_P(str)) { if (!NIL_P(str)) {
@ -414,8 +384,7 @@ curses_addstr(obj, str)
/* def getch */ /* def getch */
static VALUE static VALUE
curses_getch(obj) curses_getch(VALUE obj)
VALUE obj;
{ {
rb_read_check(stdin); rb_read_check(stdin);
curses_stdscr(); curses_stdscr();
@ -424,8 +393,7 @@ curses_getch(obj)
/* def getstr */ /* def getstr */
static VALUE static VALUE
curses_getstr(obj) curses_getstr(VALUE obj)
VALUE obj;
{ {
char rtn[1024]; /* This should be big enough.. I hope */ char rtn[1024]; /* This should be big enough.. I hope */
@ -440,8 +408,7 @@ curses_getstr(obj)
/* def delch */ /* def delch */
static VALUE static VALUE
curses_delch(obj) curses_delch(VALUE obj)
VALUE obj;
{ {
delch(); delch();
return Qnil; return Qnil;
@ -449,8 +416,7 @@ curses_delch(obj)
/* def delelteln */ /* def delelteln */
static VALUE static VALUE
curses_deleteln(obj) curses_deleteln(VALUE obj)
VALUE obj;
{ {
#if defined(HAVE_DELETELN) || defined(deleteln) #if defined(HAVE_DELETELN) || defined(deleteln)
deleteln(); deleteln();
@ -460,8 +426,7 @@ curses_deleteln(obj)
/* def insertln */ /* def insertln */
static VALUE static VALUE
curses_insertln(obj) curses_insertln(VALUE obj)
VALUE obj;
{ {
#if defined(HAVE_INSERTLN) || defined(insertln) #if defined(HAVE_INSERTLN) || defined(insertln)
insertln(); insertln();
@ -471,9 +436,7 @@ curses_insertln(obj)
/* def keyname */ /* def keyname */
static VALUE static VALUE
curses_keyname(obj, c) curses_keyname(VALUE obj, VALUE c)
VALUE obj;
VALUE c;
{ {
#ifdef HAVE_KEYNAME #ifdef HAVE_KEYNAME
const char *name; const char *name;
@ -768,12 +731,7 @@ window_s_allocate(VALUE class)
/* def initialize(h, w, top, left) */ /* def initialize(h, w, top, left) */
static VALUE static VALUE
window_initialize(obj, h, w, top, left) window_initialize(VALUE obj, VALUE h, VALUE w, VALUE top, VALUE left)
VALUE obj;
VALUE h;
VALUE w;
VALUE top;
VALUE left;
{ {
struct windata *winp; struct windata *winp;
WINDOW *window; WINDOW *window;
@ -791,12 +749,7 @@ window_initialize(obj, h, w, top, left)
/* def subwin(height, width, top, left) */ /* def subwin(height, width, top, left) */
static VALUE static VALUE
window_subwin(obj, height, width, top, left) window_subwin(VALUE obj, VALUE height, VALUE width, VALUE top, VALUE left)
VALUE obj;
VALUE height;
VALUE width;
VALUE top;
VALUE left;
{ {
struct windata *winp; struct windata *winp;
WINDOW *window; WINDOW *window;
@ -816,8 +769,7 @@ window_subwin(obj, height, width, top, left)
/* def close */ /* def close */
static VALUE static VALUE
window_close(obj) window_close(VALUE obj)
VALUE obj;
{ {
struct windata *winp; struct windata *winp;
@ -830,8 +782,7 @@ window_close(obj)
/* def clear */ /* def clear */
static VALUE static VALUE
window_clear(obj) window_clear(VALUE obj)
VALUE obj;
{ {
struct windata *winp; struct windata *winp;
@ -843,8 +794,7 @@ window_clear(obj)
/* def clrtoeol */ /* def clrtoeol */
static VALUE static VALUE
window_clrtoeol(obj) window_clrtoeol(VALUE obj)
VALUE obj;
{ {
struct windata *winp; struct windata *winp;
@ -856,8 +806,7 @@ window_clrtoeol(obj)
/* def refresh */ /* def refresh */
static VALUE static VALUE
window_refresh(obj) window_refresh(VALUE obj)
VALUE obj;
{ {
struct windata *winp; struct windata *winp;
@ -869,8 +818,7 @@ window_refresh(obj)
/* def noutrefresh */ /* def noutrefresh */
static VALUE static VALUE
window_noutrefresh(obj) window_noutrefresh(VALUE obj)
VALUE obj;
{ {
struct windata *winp; struct windata *winp;
@ -886,10 +834,7 @@ window_noutrefresh(obj)
/* def move(y, x) */ /* def move(y, x) */
static VALUE static VALUE
window_move(obj, y, x) window_move(VALUE obj, VALUE y, VALUE x)
VALUE obj;
VALUE y;
VALUE x;
{ {
struct windata *winp; struct windata *winp;
@ -901,10 +846,7 @@ window_move(obj, y, x)
/* def setpos(y, x) */ /* def setpos(y, x) */
static VALUE static VALUE
window_setpos(obj, y, x) window_setpos(VALUE obj, VALUE y, VALUE x)
VALUE obj;
VALUE y;
VALUE x;
{ {
struct windata *winp; struct windata *winp;
@ -915,8 +857,7 @@ window_setpos(obj, y, x)
/* def cury */ /* def cury */
static VALUE static VALUE
window_cury(obj) window_cury(VALUE obj)
VALUE obj;
{ {
struct windata *winp; struct windata *winp;
int x, y; int x, y;
@ -928,8 +869,7 @@ window_cury(obj)
/* def curx */ /* def curx */
static VALUE static VALUE
window_curx(obj) window_curx(VALUE obj)
VALUE obj;
{ {
struct windata *winp; struct windata *winp;
int x, y; int x, y;
@ -941,8 +881,7 @@ window_curx(obj)
/* def maxy */ /* def maxy */
static VALUE static VALUE
window_maxy(obj) window_maxy(VALUE obj)
VALUE obj;
{ {
struct windata *winp; struct windata *winp;
@ -962,8 +901,7 @@ window_maxy(obj)
/* def maxx */ /* def maxx */
static VALUE static VALUE
window_maxx(obj) window_maxx(VALUE obj)
VALUE obj;
{ {
struct windata *winp; struct windata *winp;
@ -983,8 +921,7 @@ window_maxx(obj)
/* def begy */ /* def begy */
static VALUE static VALUE
window_begy(obj) window_begy(VALUE obj)
VALUE obj;
{ {
struct windata *winp; struct windata *winp;
int x, y; int x, y;
@ -1000,8 +937,7 @@ window_begy(obj)
/* def begx */ /* def begx */
static VALUE static VALUE
window_begx(obj) window_begx(VALUE obj)
VALUE obj;
{ {
struct windata *winp; struct windata *winp;
int x, y; int x, y;
@ -1053,8 +989,7 @@ window_box(argc, argv, self)
/* def standout */ /* def standout */
static VALUE static VALUE
window_standout(obj) window_standout(VALUE obj)
VALUE obj;
{ {
struct windata *winp; struct windata *winp;
@ -1065,8 +1000,7 @@ window_standout(obj)
/* def standend */ /* def standend */
static VALUE static VALUE
window_standend(obj) window_standend(VALUE obj)
VALUE obj;
{ {
struct windata *winp; struct windata *winp;
@ -1077,8 +1011,7 @@ window_standend(obj)
/* def inch */ /* def inch */
static VALUE static VALUE
window_inch(obj) window_inch(VALUE obj)
VALUE obj;
{ {
struct windata *winp; struct windata *winp;
@ -1088,9 +1021,7 @@ window_inch(obj)
/* def addch(ch) */ /* def addch(ch) */
static VALUE static VALUE
window_addch(obj, ch) window_addch(VALUE obj, VALUE ch)
VALUE obj;
VALUE ch;
{ {
struct windata *winp; struct windata *winp;
@ -1102,9 +1033,7 @@ window_addch(obj, ch)
/* def insch(ch) */ /* def insch(ch) */
static VALUE static VALUE
window_insch(obj, ch) window_insch(VALUE obj, VALUE ch)
VALUE obj;
VALUE ch;
{ {
struct windata *winp; struct windata *winp;
@ -1116,9 +1045,7 @@ window_insch(obj, ch)
/* def addstr(str) */ /* def addstr(str) */
static VALUE static VALUE
window_addstr(obj, str) window_addstr(VALUE obj, VALUE str)
VALUE obj;
VALUE str;
{ {
if (!NIL_P(str)) { if (!NIL_P(str)) {
struct windata *winp; struct windata *winp;
@ -1131,9 +1058,7 @@ window_addstr(obj, str)
/* def <<(str) */ /* def <<(str) */
static VALUE static VALUE
window_addstr2(obj, str) window_addstr2(VALUE obj, VALUE str)
VALUE obj;
VALUE str;
{ {
window_addstr(obj, str); window_addstr(obj, str);
return obj; return obj;
@ -1141,8 +1066,7 @@ window_addstr2(obj, str)
/* def getch */ /* def getch */
static VALUE static VALUE
window_getch(obj) window_getch(VALUE obj)
VALUE obj;
{ {
struct windata *winp; struct windata *winp;
@ -1153,8 +1077,7 @@ window_getch(obj)
/* def getstr */ /* def getstr */
static VALUE static VALUE
window_getstr(obj) window_getstr(VALUE obj)
VALUE obj;
{ {
struct windata *winp; struct windata *winp;
char rtn[1024]; /* This should be big enough.. I hope */ char rtn[1024]; /* This should be big enough.. I hope */
@ -1171,8 +1094,7 @@ window_getstr(obj)
/* def delch */ /* def delch */
static VALUE static VALUE
window_delch(obj) window_delch(VALUE obj)
VALUE obj;
{ {
struct windata *winp; struct windata *winp;
@ -1183,8 +1105,7 @@ window_delch(obj)
/* def delelteln */ /* def delelteln */
static VALUE static VALUE
window_deleteln(obj) window_deleteln(VALUE obj)
VALUE obj;
{ {
#if defined(HAVE_WDELETELN) || defined(wdeleteln) #if defined(HAVE_WDELETELN) || defined(wdeleteln)
struct windata *winp; struct windata *winp;
@ -1197,8 +1118,7 @@ window_deleteln(obj)
/* def insertln */ /* def insertln */
static VALUE static VALUE
window_insertln(obj) window_insertln(VALUE obj)
VALUE obj;
{ {
#if defined(HAVE_WINSERTLN) || defined(winsertln) #if defined(HAVE_WINSERTLN) || defined(winsertln)
struct windata *winp; struct windata *winp;

View file

@ -70,8 +70,7 @@ safe_setup_str(str)
#ifdef HAVE_GETPWENT #ifdef HAVE_GETPWENT
static VALUE static VALUE
setup_passwd(pwd) setup_passwd(struct passwd *pwd)
struct passwd *pwd;
{ {
if (pwd == 0) rb_sys_fail("/etc/passwd"); if (pwd == 0) rb_sys_fail("/etc/passwd");
return rb_struct_new(sPasswd, 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"> * passwd="x", uid=0, gid=0, gecos="root",dir="/root", shell="/bin/bash">
*/ */
static VALUE static VALUE
etc_getpwuid(argc, argv, obj) etc_getpwuid(int argc, VALUE *argv, VALUE obj)
int argc;
VALUE *argv;
VALUE obj;
{ {
#if defined(HAVE_GETPWENT) #if defined(HAVE_GETPWENT)
VALUE id; VALUE id;
@ -153,8 +149,7 @@ etc_getpwuid(argc, argv, obj)
* passwd="x", uid=0, gid=0, gecos="root",dir="/root", shell="/bin/bash"> * passwd="x", uid=0, gid=0, gecos="root",dir="/root", shell="/bin/bash">
*/ */
static VALUE static VALUE
etc_getpwnam(obj, nam) etc_getpwnam(VALUE obj, VALUE nam)
VALUE obj, nam;
{ {
#ifdef HAVE_GETPWENT #ifdef HAVE_GETPWENT
struct passwd *pwd; struct passwd *pwd;
@ -207,8 +202,7 @@ passwd_iterate()
* *
*/ */
static VALUE static VALUE
etc_passwd(obj) etc_passwd(VALUE obj)
VALUE obj;
{ {
#ifdef HAVE_GETPWENT #ifdef HAVE_GETPWENT
struct passwd *pw; struct passwd *pw;
@ -232,8 +226,7 @@ etc_passwd(obj)
* to getpwent will return the first entry again. * to getpwent will return the first entry again.
*/ */
static VALUE static VALUE
etc_setpwent(obj) etc_setpwent(VALUE obj)
VALUE obj;
{ {
#ifdef HAVE_GETPWENT #ifdef HAVE_GETPWENT
setpwent(); setpwent();
@ -245,8 +238,7 @@ etc_setpwent(obj)
* getpwent, and closes the file. * getpwent, and closes the file.
*/ */
static VALUE static VALUE
etc_endpwent(obj) etc_endpwent(VALUE obj)
VALUE obj;
{ {
#ifdef HAVE_GETPWENT #ifdef HAVE_GETPWENT
endpwent(); endpwent();
@ -281,8 +273,7 @@ etc_endpwent(obj)
* - Passwd#shell contains the path to the login shell of the user as a String. * - Passwd#shell contains the path to the login shell of the user as a String.
*/ */
static VALUE static VALUE
etc_getpwent(obj) etc_getpwent(VALUE obj)
VALUE obj;
{ {
#ifdef HAVE_GETPWENT #ifdef HAVE_GETPWENT
struct passwd *pw; struct passwd *pw;
@ -296,8 +287,7 @@ etc_getpwent(obj)
#ifdef HAVE_GETGRENT #ifdef HAVE_GETGRENT
static VALUE static VALUE
setup_group(grp) setup_group(struct group *grp)
struct group *grp;
{ {
VALUE mem; VALUE mem;
char **tbl; char **tbl;
@ -329,8 +319,7 @@ setup_group(grp)
* *
*/ */
static VALUE static VALUE
etc_getgrgid(obj, id) etc_getgrgid(VALUE obj, VALUE id)
VALUE obj, id;
{ {
#ifdef HAVE_GETGRENT #ifdef HAVE_GETGRENT
int gid; int gid;
@ -357,8 +346,7 @@ etc_getgrgid(obj, id)
* *
*/ */
static VALUE static VALUE
etc_getgrnam(obj, nam) etc_getgrnam(VALUE obj, VALUE nam)
VALUE obj, nam;
{ {
#ifdef HAVE_GETGRENT #ifdef HAVE_GETGRENT
struct group *grp; struct group *grp;
@ -412,8 +400,7 @@ group_iterate()
* *
*/ */
static VALUE static VALUE
etc_group(obj) etc_group(VALUE obj)
VALUE obj;
{ {
#ifdef HAVE_GETGRENT #ifdef HAVE_GETGRENT
struct group *grp; struct group *grp;
@ -437,8 +424,7 @@ etc_group(obj)
* to getgrent will return the first entry again. * to getgrent will return the first entry again.
*/ */
static VALUE static VALUE
etc_setgrent(obj) etc_setgrent(VALUE obj)
VALUE obj;
{ {
#ifdef HAVE_GETGRENT #ifdef HAVE_GETGRENT
setgrent(); setgrent();
@ -450,8 +436,7 @@ etc_setgrent(obj)
* getgrent, and closes the file. * getgrent, and closes the file.
*/ */
static VALUE static VALUE
etc_endgrent(obj) etc_endgrent(VALUE obj)
VALUE obj;
{ {
#ifdef HAVE_GETGRENT #ifdef HAVE_GETGRENT
endgrent(); endgrent();
@ -480,8 +465,7 @@ etc_endgrent(obj)
* members of the group. * members of the group.
*/ */
static VALUE static VALUE
etc_getgrent(obj) etc_getgrent(VALUE obj)
VALUE obj;
{ {
#ifdef HAVE_GETGRENT #ifdef HAVE_GETGRENT
struct group *gr; struct group *gr;

View file

@ -233,7 +233,7 @@ def parse_args()
opts.on('--make=MAKE') do |v| opts.on('--make=MAKE') do |v|
$make = v || 'make' $make = v || 'make'
end 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} v.grep(/\A([-\w]+)=(.*)/) {$configure_args["--#{$1}"] = $2}
if arg = v.first if arg = v.first
arg.insert(0, '-') if /\A[^-][^=]*\Z/ =~ arg arg.insert(0, '-') if /\A[^-][^=]*\Z/ =~ arg
@ -258,7 +258,7 @@ def parse_args()
$mflags.unshift(*rest) unless rest.empty? $mflags.unshift(*rest) unless rest.empty?
def $mflags.set?(flag) def $mflags.set?(flag)
grep(/\A-(?!-).*#{'%c' % flag}/i) { return true } grep(/\A-(?!-).*#{'%s' % flag}/i) { return true }
false false
end end
def $mflags.defined?(var) def $mflags.defined?(var)

View file

@ -166,7 +166,7 @@ iconv_create(VALUE to, VALUE from, struct rb_iconv_opt_t *opt)
} }
if (cd == (iconv_t)-1) { if (cd == (iconv_t)-1) {
int inval = errno == EINVAL; 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 + volatile VALUE msg = rb_str_new(0, strlen(s) + RSTRING(to)->len +
RSTRING(from)->len + 8); RSTRING(from)->len + 8);

View file

@ -75,8 +75,7 @@ struct wait_readable_arg {
#ifdef HAVE_RB_FD_INIT #ifdef HAVE_RB_FD_INIT
static VALUE static VALUE
wait_readable(p) wait_readable(VALUE p)
VALUE p;
{ {
struct wait_readable_arg *arg = (struct wait_readable_arg *)p; struct wait_readable_arg *arg = (struct wait_readable_arg *)p;
rb_fdset_t *fds = &arg->fds; rb_fdset_t *fds = &arg->fds;

View file

@ -1902,18 +1902,14 @@ const int score_table_F0[] = {
SCORE_DEPEND, SCORE_NO_EXIST, SCORE_NO_EXIST, SCORE_ERROR, SCORE_DEPEND, SCORE_NO_EXIST, SCORE_NO_EXIST, SCORE_ERROR,
}; };
void set_code_score(ptr, score) void set_code_score(struct input_code *ptr, int score)
struct input_code *ptr;
int score;
{ {
if (ptr){ if (ptr){
ptr->score |= score; ptr->score |= score;
} }
} }
void clr_code_score(ptr, score) void clr_code_score(struct input_code *ptr, int score)
struct input_code *ptr;
int score;
{ {
if (ptr){ if (ptr){
ptr->score &= ~score; ptr->score &= ~score;
@ -1944,8 +1940,7 @@ void code_score(ptr)
} }
} }
void status_disable(ptr) void status_disable(struct input_code *ptr)
struct input_code *ptr;
{ {
ptr->stat = -1; ptr->stat = -1;
ptr->buf[0] = -1; ptr->buf[0] = -1;
@ -1953,46 +1948,37 @@ struct input_code *ptr;
if (iconv == ptr->iconv_func) set_iconv(FALSE, 0); if (iconv == ptr->iconv_func) set_iconv(FALSE, 0);
} }
void status_push_ch(ptr, c) void status_push_ch(struct input_code *ptr, int c)
struct input_code *ptr;
int c;
{ {
ptr->buf[ptr->index++] = c; ptr->buf[ptr->index++] = c;
} }
void status_clear(ptr) void status_clear(struct input_code *ptr)
struct input_code *ptr;
{ {
ptr->stat = 0; ptr->stat = 0;
ptr->index = 0; ptr->index = 0;
} }
void status_reset(ptr) void status_reset(struct input_code *ptr)
struct input_code *ptr;
{ {
status_clear(ptr); status_clear(ptr);
ptr->score = SCORE_INIT; ptr->score = SCORE_INIT;
} }
void status_reinit(ptr) void status_reinit(struct input_code *ptr)
struct input_code *ptr;
{ {
status_reset(ptr); status_reset(ptr);
ptr->_file_stat = 0; ptr->_file_stat = 0;
} }
void status_check(ptr, c) void status_check(struct input_code *ptr, int c)
struct input_code *ptr;
int c;
{ {
if (c <= DEL && estab_f){ if (c <= DEL && estab_f){
status_reset(ptr); status_reset(ptr);
} }
} }
void s_status(ptr, c) void s_status(struct input_code *ptr, int c)
struct input_code *ptr;
int c;
{ {
switch(ptr->stat){ switch(ptr->stat){
case -1: case -1:
@ -3062,9 +3048,7 @@ w_iconv(c2, c1, c0)
#if defined(UTF8_INPUT_ENABLE) || defined(UTF8_OUTPUT_ENABLE) #if defined(UTF8_INPUT_ENABLE) || defined(UTF8_OUTPUT_ENABLE)
void void
w16w_conv(val, p2, p1, p0) w16w_conv(unsigned short val, int *p2, int *p1, int *p0)
unsigned short val;
int *p2, *p1, *p0;
{ {
if (val < 0x80){ if (val < 0x80){
*p2 = val; *p2 = val;
@ -3771,9 +3755,7 @@ s_oconv(c2, c1)
} }
void void
j_oconv(c2, c1) j_oconv(int c2, int c1)
int c2,
c1;
{ {
#ifdef NUMCHAR_OPTION #ifdef NUMCHAR_OPTION
if (c2 == 0 && (c1 & CLASS_MASK) == CLASS_UTF16){ if (c2 == 0 && (c1 & CLASS_MASK) == CLASS_UTF16){
@ -3858,9 +3840,7 @@ j_oconv(c2, c1)
} }
void void
base64_conv(c2, c1) base64_conv(int c2, int c1)
int c2,
c1;
{ {
mime_prechar(c2, c1); mime_prechar(c2, c1);
(*o_base64conv)(c2,c1); (*o_base64conv)(c2,c1);
@ -3871,8 +3851,7 @@ STATIC int broken_buf[3];
STATIC int broken_counter = 0; STATIC int broken_counter = 0;
STATIC int broken_last = 0; STATIC int broken_last = 0;
int int
broken_getc(f) broken_getc(FILE *f)
FILE *f;
{ {
int c,c1; int c,c1;
@ -3911,9 +3890,7 @@ FILE *f;
} }
int int
broken_ungetc(c,f) broken_ungetc(int c, FILE *f)
int c;
FILE *f;
{ {
if (broken_counter<2) if (broken_counter<2)
broken_buf[broken_counter++]=c; broken_buf[broken_counter++]=c;
@ -3923,8 +3900,7 @@ FILE *f;
STATIC int prev_cr = 0; STATIC int prev_cr = 0;
void void
cr_conv(c2,c1) cr_conv(int c2, int c1)
int c2,c1;
{ {
if (prev_cr) { if (prev_cr) {
prev_cr = 0; prev_cr = 0;
@ -3972,8 +3948,7 @@ int c2,c1;
#define char_size(c2,c1) (c2?2:1) #define char_size(c2,c1) (c2?2:1)
void void
fold_conv(c2,c1) fold_conv(int c2, int c1)
int c2,c1;
{ {
int prev0; int prev0;
int fold_state=0; int fold_state=0;
@ -4146,8 +4121,7 @@ int c2,c1;
int z_prev2=0,z_prev1=0; int z_prev2=0,z_prev1=0;
void void
z_conv(c2,c1) z_conv(int c2, int c1)
int c2,c1;
{ {
/* if (c2) c1 &= 0x7f; assertion */ /* if (c2) c1 &= 0x7f; assertion */
@ -4237,8 +4211,7 @@ int c2,c1;
) )
void void
rot_conv(c2,c1) rot_conv(int c2, int c1)
int c2,c1;
{ {
if (c2==0 || c2==X0201 || c2==ISO8859_1) { if (c2==0 || c2==X0201 || c2==ISO8859_1) {
c1 = rot13(c1); c1 = rot13(c1);
@ -4250,8 +4223,7 @@ int c2,c1;
} }
void void
hira_conv(c2,c1) hira_conv(int c2, int c1)
int c2,c1;
{ {
if ((hira_f & 1) && c2==0x25 && 0x20<c1 && c1<0x74) { if ((hira_f & 1) && c2==0x25 && 0x20<c1 && c1<0x74) {
c2 = 0x24; c2 = 0x24;
@ -4263,8 +4235,7 @@ int c2,c1;
void void
iso2022jp_check_conv(c2,c1) iso2022jp_check_conv(int c2, int c1)
int c2, c1;
{ {
STATIC const int range[RANGE_NUM_MAX][2] = { STATIC const int range[RANGE_NUM_MAX][2] = {
{0x222f, 0x2239,}, {0x222f, 0x2239,},
@ -4386,8 +4357,7 @@ unswitch_mime_getc()
} }
int int
mime_begin_strict(f) mime_begin_strict(FILE *f)
FILE *f;
{ {
int c1 = 0; int c1 = 0;
int i,j,k; int i,j,k;
@ -4437,8 +4407,7 @@ FILE *f;
} }
int int
mime_getc_buf(f) mime_getc_buf(FILE *f)
FILE *f;
{ {
/* we don't keep eof of Fifo, becase it contains ?= as /* we don't keep eof of Fifo, becase it contains ?= as
a terminator. It was checked in mime_integrity. */ a terminator. It was checked in mime_integrity. */
@ -4447,9 +4416,7 @@ FILE *f;
} }
int int
mime_ungetc_buf(c,f) mime_ungetc_buf(int c, FILE *f)
FILE *f;
int c;
{ {
if (mimebuf_f) if (mimebuf_f)
(*i_mungetc_buf)(c,f); (*i_mungetc_buf)(c,f);
@ -4459,8 +4426,7 @@ int c;
} }
int int
mime_begin(f) mime_begin(FILE *f)
FILE *f;
{ {
int c1; int c1;
int i,k; int i,k;
@ -4518,8 +4484,7 @@ FILE *f;
#ifdef CHECK_OPTION #ifdef CHECK_OPTION
void void
no_putc(c) no_putc(int c)
int c;
{ {
; ;
} }
@ -4534,8 +4499,7 @@ void debug(str)
#endif #endif
void void
set_input_codename (codename) set_input_codename (char *codename)
char *codename;
{ {
if (guess_f && if (guess_f &&
is_inputcode_set && is_inputcode_set &&
@ -4550,8 +4514,7 @@ set_input_codename (codename)
#if !defined(PERL_XS) && !defined(WIN32DLL) #if !defined(PERL_XS) && !defined(WIN32DLL)
void void
print_guessed_code (filename) print_guessed_code (char *filename)
char *filename;
{ {
char *codename = "BINARY"; char *codename = "BINARY";
if (!is_inputcode_mixed) { if (!is_inputcode_mixed) {
@ -4599,31 +4562,25 @@ hex_getc(ch, f, g, u)
} }
int int
cap_getc(f) cap_getc(FILE *f)
FILE *f;
{ {
return hex_getc(':', f, i_cgetc, i_cungetc); return hex_getc(':', f, i_cgetc, i_cungetc);
} }
int int
cap_ungetc(c, f) cap_ungetc(int c, FILE *f)
int c;
FILE *f;
{ {
return (*i_cungetc)(c, f); return (*i_cungetc)(c, f);
} }
int int
url_getc(f) url_getc(FILE *f)
FILE *f;
{ {
return hex_getc('%', f, i_ugetc, i_uungetc); return hex_getc('%', f, i_ugetc, i_uungetc);
} }
int int
url_ungetc(c, f) url_ungetc(int c, FILE *f)
int c;
FILE *f;
{ {
return (*i_uungetc)(c, f); return (*i_uungetc)(c, f);
} }
@ -4631,8 +4588,7 @@ url_ungetc(c, f)
#ifdef NUMCHAR_OPTION #ifdef NUMCHAR_OPTION
int int
numchar_getc(f) numchar_getc(FILE *f)
FILE *f;
{ {
int (*g)() = i_ngetc; int (*g)() = i_ngetc;
int (*u)() = i_nungetc; int (*u)() = i_nungetc;
@ -4698,8 +4654,7 @@ numchar_ungetc(c, f)
/* Normalization Form C */ /* Normalization Form C */
int int
nfc_getc(f) nfc_getc(FILE *f)
FILE *f;
{ {
int (*g)() = i_nfc_getc; int (*g)() = i_nfc_getc;
int (*u)() = i_nfc_ungetc; int (*u)() = i_nfc_ungetc;
@ -5185,8 +5140,7 @@ eof_mime()
} }
void void
mimeout_addchar(c) mimeout_addchar(int c)
int c;
{ {
switch(mimeout_mode) { switch(mimeout_mode) {
case 'Q': case 'Q':

View file

@ -56,8 +56,7 @@ static int incsize;
static VALUE result; static VALUE result;
static int static int
rb_nkf_putchar(c) rb_nkf_putchar(unsigned int c)
unsigned int c;
{ {
if (output_ctr >= o_len) { if (output_ctr >= o_len) {
o_len += incsize; o_len += incsize;
@ -78,8 +77,7 @@ rb_nkf_putchar(c)
#include "nkf-utf8/utf8tbl.c" #include "nkf-utf8/utf8tbl.c"
#include "nkf-utf8/nkf.c" #include "nkf-utf8/nkf.c"
int nkf_split_options(arg) int nkf_split_options(const char *arg)
const char* arg;
{ {
int count = 0; int count = 0;
char option[256]; char option[256];
@ -142,8 +140,7 @@ int nkf_split_options(arg)
*/ */
static VALUE static VALUE
rb_nkf_kconv(obj, opt, src) rb_nkf_kconv(VALUE obj, VALUE opt, VALUE src)
VALUE obj, opt, src;
{ {
char *opt_ptr, *opt_end; char *opt_ptr, *opt_end;
volatile VALUE v; volatile VALUE v;
@ -205,8 +202,7 @@ rb_nkf_kconv(obj, opt, src)
*/ */
static VALUE static VALUE
rb_nkf_guess1(obj, src) rb_nkf_guess1(VALUE obj, VALUE src)
VALUE obj, src;
{ {
unsigned char *p; unsigned char *p;
unsigned char *pend; unsigned char *pend;
@ -319,8 +315,7 @@ rb_nkf_guess1(obj, src)
*/ */
static VALUE static VALUE
rb_nkf_guess2(obj, src) rb_nkf_guess2(VALUE obj, VALUE src)
VALUE obj, src;
{ {
int code = _BINARY; int code = _BINARY;

View file

@ -445,7 +445,7 @@ decode_time(unsigned char* der, int length)
/********/ /********/
typedef struct { typedef struct {
char *name; const char *name;
VALUE *klass; VALUE *klass;
} ossl_asn1_info_t; } ossl_asn1_info_t;

View file

@ -335,7 +335,7 @@ static int
ossl_pkcs7_sym2typeid(VALUE sym) ossl_pkcs7_sym2typeid(VALUE sym)
{ {
int i, ret = Qnil; int i, ret = Qnil;
char *s; const char *s;
static struct { static struct {
const char *name; const char *name;

View file

@ -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_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") #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", "cert", "key", "client_ca", "ca_file", "ca_path",
"timeout", "verify_mode", "verify_depth", "timeout", "verify_mode", "verify_depth",
"verify_callback", "options", "cert_store", "extra_chain_cert", "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_key(o,v) rb_iv_set((o),"@key",(v))
#define ossl_ssl_set_tmp_dh(o,v) rb_iv_set((o),"@tmp_dh",(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 const char *ossl_ssl_attr_readers[] = { "io", "context", };
static char *ossl_ssl_attrs[] = { "sync_close", }; static const char *ossl_ssl_attrs[] = { "sync_close", };
/* /*
* SSLContext class * SSLContext class
@ -144,7 +144,7 @@ ossl_sslctx_initialize(int argc, VALUE *argv, VALUE self)
SSL_METHOD *method = NULL; SSL_METHOD *method = NULL;
SSL_CTX *ctx; SSL_CTX *ctx;
int i; int i;
char *s; const char *s;
for(i = 0; i < numberof(ossl_sslctx_attrs); i++){ for(i = 0; i < numberof(ossl_sslctx_attrs); i++){
char buf[32]; char buf[32];

View file

@ -118,8 +118,7 @@ static char SlaveName[DEVICELEN];
static VALUE eChildExited; static VALUE eChildExited;
static VALUE static VALUE
echild_status(self) echild_status(VALUE self)
VALUE self;
{ {
return rb_ivar_get(self, rb_intern("status")); return rb_ivar_get(self, rb_intern("status"));
} }
@ -131,9 +130,7 @@ struct pty_info {
}; };
static void static void
raise_from_wait(state, info) raise_from_wait(char *state, struct pty_info *info)
struct pty_info *info;
char *state;
{ {
extern VALUE rb_last_status; extern VALUE rb_last_status;
char buf[1024]; char buf[1024];
@ -146,8 +143,7 @@ raise_from_wait(state, info)
} }
static VALUE static VALUE
pty_syswait(info) pty_syswait(struct pty_info *info)
struct pty_info *info;
{ {
int cpid, status; int cpid, status;
@ -184,17 +180,13 @@ struct exec_info {
}; };
static VALUE static VALUE
pty_exec(arg) pty_exec(struct exec_info *arg)
struct exec_info *arg;
{ {
return rb_f_exec(arg->argc, arg->argv); return rb_f_exec(arg->argc, arg->argv);
} }
static void static void
establishShell(argc, argv, info) establishShell(int argc, VALUE *argv, struct pty_info *info)
int argc;
VALUE *argv;
struct pty_info *info;
{ {
static int i,master,slave,currentPid; static int i,master,slave,currentPid;
char *p,*getenv(); char *p,*getenv();
@ -295,8 +287,7 @@ establishShell(argc, argv, info)
} }
static VALUE static VALUE
pty_finalize_syswait(info) pty_finalize_syswait(struct pty_info *info)
struct pty_info *info;
{ {
rb_thread_kill(info->thread); rb_thread_kill(info->thread);
rb_funcall(info->thread, rb_intern("value"), 0); rb_funcall(info->thread, rb_intern("value"), 0);
@ -310,8 +301,7 @@ pty_finalize_syswait(info)
* or the same interface function. * or the same interface function.
*/ */
static void static void
getDevice(master,slave) getDevice(int *master, int *slave)
int *master,*slave;
{ {
if (openpty(master, slave, SlaveName, if (openpty(master, slave, SlaveName,
(struct termios *)0, (struct winsize *)0) == -1) { (struct termios *)0, (struct winsize *)0) == -1) {
@ -321,8 +311,7 @@ getDevice(master,slave)
#else /* HAVE_OPENPTY */ #else /* HAVE_OPENPTY */
#ifdef HAVE__GETPTY #ifdef HAVE__GETPTY
static void static void
getDevice(master,slave) getDevice(int *master, int *slave)
int *master,*slave;
{ {
char *name; char *name;
@ -335,8 +324,7 @@ getDevice(master,slave)
} }
#else /* HAVE__GETPTY */ #else /* HAVE__GETPTY */
static void static void
getDevice(master,slave) getDevice(int *master, int *slave)
int *master,*slave;
{ {
int i,j; int i,j;
@ -407,10 +395,7 @@ freeDevice()
/* ruby function: getpty */ /* ruby function: getpty */
static VALUE static VALUE
pty_getpty(argc, argv, self) pty_getpty(int argc, VALUE *argv, VALUE self)
int argc;
VALUE *argv;
VALUE self;
{ {
VALUE res; VALUE res;
struct pty_info info; struct pty_info info;
@ -450,8 +435,7 @@ pty_getpty(argc, argv, self)
/* ruby function: protect_signal - obsolete */ /* ruby function: protect_signal - obsolete */
static VALUE static VALUE
pty_protect(self) pty_protect(VALUE self)
VALUE self;
{ {
rb_warn("PTY::protect_signal is no longer needed"); rb_warn("PTY::protect_signal is no longer needed");
rb_yield(Qnil); rb_yield(Qnil);
@ -460,8 +444,7 @@ pty_protect(self)
/* ruby function: reset_signal - obsolete */ /* ruby function: reset_signal - obsolete */
static VALUE static VALUE
pty_reset_signal(self) pty_reset_signal(VALUE self)
VALUE self;
{ {
rb_warn("PTY::reset_signal is no longer needed"); rb_warn("PTY::reset_signal is no longer needed");
return self; return self;

View file

@ -50,10 +50,7 @@ readline_event()
} }
static VALUE static VALUE
readline_readline(argc, argv, self) readline_readline(int argc, VALUE *argv, VALUE self)
int argc;
VALUE *argv;
VALUE self;
{ {
VALUE tmp, add_hist, result; VALUE tmp, add_hist, result;
char *prompt = NULL; char *prompt = NULL;
@ -95,8 +92,7 @@ readline_readline(argc, argv, self)
} }
static VALUE static VALUE
readline_s_set_input(self, input) readline_s_set_input(VALUE self, VALUE input)
VALUE self, input;
{ {
OpenFile *ifp; OpenFile *ifp;
@ -108,8 +104,7 @@ readline_s_set_input(self, input)
} }
static VALUE static VALUE
readline_s_set_output(self, output) readline_s_set_output(VALUE self, VALUE output)
VALUE self, output;
{ {
OpenFile *ofp; OpenFile *ofp;
@ -121,9 +116,7 @@ readline_s_set_output(self, output)
} }
static VALUE static VALUE
readline_s_set_completion_proc(self, proc) readline_s_set_completion_proc(VALUE self, VALUE proc)
VALUE self;
VALUE proc;
{ {
rb_secure(4); rb_secure(4);
if (!rb_respond_to(proc, rb_intern("call"))) if (!rb_respond_to(proc, rb_intern("call")))
@ -132,35 +125,28 @@ readline_s_set_completion_proc(self, proc)
} }
static VALUE static VALUE
readline_s_get_completion_proc(self) readline_s_get_completion_proc(VALUE self)
VALUE self;
{ {
rb_secure(4); rb_secure(4);
return rb_attr_get(mReadline, completion_proc); return rb_attr_get(mReadline, completion_proc);
} }
static VALUE static VALUE
readline_s_set_completion_case_fold(self, val) readline_s_set_completion_case_fold(VALUE self, VALUE val)
VALUE self;
VALUE val;
{ {
rb_secure(4); rb_secure(4);
return rb_ivar_set(mReadline, completion_case_fold, val); return rb_ivar_set(mReadline, completion_case_fold, val);
} }
static VALUE static VALUE
readline_s_get_completion_case_fold(self) readline_s_get_completion_case_fold(VALUE self)
VALUE self;
{ {
rb_secure(4); rb_secure(4);
return rb_attr_get(mReadline, completion_case_fold); return rb_attr_get(mReadline, completion_case_fold);
} }
static char ** static char **
readline_attempted_completion_function(text, start, end) readline_attempted_completion_function(const char *text, int start, int end)
const char *text;
int start;
int end;
{ {
VALUE proc, ary, temp; VALUE proc, ary, temp;
char **result; char **result;
@ -224,8 +210,7 @@ readline_attempted_completion_function(text, start, end)
} }
static VALUE static VALUE
readline_s_vi_editing_mode(self) readline_s_vi_editing_mode(VALUE self)
VALUE self;
{ {
#ifdef HAVE_RL_VI_EDITING_MODE #ifdef HAVE_RL_VI_EDITING_MODE
rb_secure(4); rb_secure(4);
@ -238,8 +223,7 @@ readline_s_vi_editing_mode(self)
} }
static VALUE static VALUE
readline_s_emacs_editing_mode(self) readline_s_emacs_editing_mode(VALUE self)
VALUE self;
{ {
#ifdef HAVE_RL_EMACS_EDITING_MODE #ifdef HAVE_RL_EMACS_EDITING_MODE
rb_secure(4); rb_secure(4);
@ -252,8 +236,7 @@ readline_s_emacs_editing_mode(self)
} }
static VALUE static VALUE
readline_s_set_completion_append_character(self, str) readline_s_set_completion_append_character(VALUE self, VALUE str)
VALUE self, str;
{ {
#ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
rb_secure(4); rb_secure(4);
@ -276,8 +259,7 @@ readline_s_set_completion_append_character(self, str)
} }
static VALUE static VALUE
readline_s_get_completion_append_character(self) readline_s_get_completion_append_character(VALUE self)
VALUE self;
{ {
#ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
VALUE str; VALUE str;
@ -296,8 +278,7 @@ readline_s_get_completion_append_character(self)
} }
static VALUE static VALUE
readline_s_set_basic_word_break_characters(self, str) readline_s_set_basic_word_break_characters(VALUE self, VALUE str)
VALUE self, str;
{ {
#ifdef HAVE_RL_BASIC_WORD_BREAK_CHARACTERS #ifdef HAVE_RL_BASIC_WORD_BREAK_CHARACTERS
static char *basic_word_break_characters = NULL; static char *basic_word_break_characters = NULL;
@ -323,8 +304,7 @@ readline_s_set_basic_word_break_characters(self, str)
} }
static VALUE static VALUE
readline_s_get_basic_word_break_characters(self, str) readline_s_get_basic_word_break_characters(VALUE self, VALUE str)
VALUE self, str;
{ {
#ifdef HAVE_RL_BASIC_WORD_BREAK_CHARACTERS #ifdef HAVE_RL_BASIC_WORD_BREAK_CHARACTERS
rb_secure(4); rb_secure(4);
@ -338,8 +318,7 @@ readline_s_get_basic_word_break_characters(self, str)
} }
static VALUE static VALUE
readline_s_set_completer_word_break_characters(self, str) readline_s_set_completer_word_break_characters(VALUE self, VALUE str)
VALUE self, str;
{ {
#ifdef HAVE_RL_COMPLETER_WORD_BREAK_CHARACTERS #ifdef HAVE_RL_COMPLETER_WORD_BREAK_CHARACTERS
static char *completer_word_break_characters = NULL; static char *completer_word_break_characters = NULL;
@ -365,8 +344,7 @@ readline_s_set_completer_word_break_characters(self, str)
} }
static VALUE static VALUE
readline_s_get_completer_word_break_characters(self, str) readline_s_get_completer_word_break_characters(VALUE self, VALUE str)
VALUE self, str;
{ {
#ifdef HAVE_RL_COMPLETER_WORD_BREAK_CHARACTERS #ifdef HAVE_RL_COMPLETER_WORD_BREAK_CHARACTERS
rb_secure(4); rb_secure(4);
@ -380,8 +358,7 @@ readline_s_get_completer_word_break_characters(self, str)
} }
static VALUE static VALUE
readline_s_set_basic_quote_characters(self, str) readline_s_set_basic_quote_characters(VALUE self, VALUE str)
VALUE self, str;
{ {
#ifdef HAVE_RL_BASIC_QUOTE_CHARACTERS #ifdef HAVE_RL_BASIC_QUOTE_CHARACTERS
static char *basic_quote_characters = NULL; static char *basic_quote_characters = NULL;
@ -408,8 +385,7 @@ readline_s_set_basic_quote_characters(self, str)
} }
static VALUE static VALUE
readline_s_get_basic_quote_characters(self, str) readline_s_get_basic_quote_characters(VALUE self, VALUE str)
VALUE self, str;
{ {
#ifdef HAVE_RL_BASIC_QUOTE_CHARACTERS #ifdef HAVE_RL_BASIC_QUOTE_CHARACTERS
rb_secure(4); rb_secure(4);
@ -423,8 +399,7 @@ readline_s_get_basic_quote_characters(self, str)
} }
static VALUE static VALUE
readline_s_set_completer_quote_characters(self, str) readline_s_set_completer_quote_characters(VALUE self, VALUE str)
VALUE self, str;
{ {
#ifdef HAVE_RL_COMPLETER_QUOTE_CHARACTERS #ifdef HAVE_RL_COMPLETER_QUOTE_CHARACTERS
static char *completer_quote_characters = NULL; static char *completer_quote_characters = NULL;
@ -451,8 +426,7 @@ readline_s_set_completer_quote_characters(self, str)
} }
static VALUE static VALUE
readline_s_get_completer_quote_characters(self, str) readline_s_get_completer_quote_characters(VALUE self, VALUE str)
VALUE self, str;
{ {
#ifdef HAVE_RL_COMPLETER_QUOTE_CHARACTERS #ifdef HAVE_RL_COMPLETER_QUOTE_CHARACTERS
rb_secure(4); rb_secure(4);
@ -466,8 +440,7 @@ readline_s_get_completer_quote_characters(self, str)
} }
static VALUE static VALUE
readline_s_set_filename_quote_characters(self, str) readline_s_set_filename_quote_characters(VALUE self, VALUE str)
VALUE self, str;
{ {
#ifdef HAVE_RL_FILENAME_QUOTE_CHARACTERS #ifdef HAVE_RL_FILENAME_QUOTE_CHARACTERS
static char *filename_quote_characters = NULL; static char *filename_quote_characters = NULL;
@ -494,8 +467,7 @@ readline_s_set_filename_quote_characters(self, str)
} }
static VALUE static VALUE
readline_s_get_filename_quote_characters(self, str) readline_s_get_filename_quote_characters(VALUE self, VALUE str)
VALUE self, str;
{ {
#ifdef HAVE_RL_FILENAME_QUOTE_CHARACTERS #ifdef HAVE_RL_FILENAME_QUOTE_CHARACTERS
rb_secure(4); rb_secure(4);
@ -509,16 +481,13 @@ readline_s_get_filename_quote_characters(self, str)
} }
static VALUE static VALUE
hist_to_s(self) hist_to_s(VALUE self)
VALUE self;
{ {
return rb_str_new2("HISTORY"); return rb_str_new2("HISTORY");
} }
static VALUE static VALUE
hist_get(self, index) hist_get(VALUE self, VALUE index)
VALUE self;
VALUE index;
{ {
HIST_ENTRY *entry; HIST_ENTRY *entry;
int i; int i;
@ -536,10 +505,7 @@ hist_get(self, index)
} }
static VALUE static VALUE
hist_set(self, index, str) hist_set(VALUE self, VALUE index, VALUE str)
VALUE self;
VALUE index;
VALUE str;
{ {
#ifdef HAVE_REPLACE_HISTORY_ENTRY #ifdef HAVE_REPLACE_HISTORY_ENTRY
HIST_ENTRY *entry; HIST_ENTRY *entry;
@ -563,9 +529,7 @@ hist_set(self, index, str)
} }
static VALUE static VALUE
hist_push(self, str) hist_push(VALUE self, VALUE str)
VALUE self;
VALUE str;
{ {
rb_secure(4); rb_secure(4);
SafeStringValue(str); SafeStringValue(str);
@ -574,10 +538,7 @@ hist_push(self, str)
} }
static VALUE static VALUE
hist_push_method(argc, argv, self) hist_push_method(int argc, VALUE *argv, VALUE self)
int argc;
VALUE *argv;
VALUE self;
{ {
VALUE str; VALUE str;
@ -591,8 +552,7 @@ hist_push_method(argc, argv, self)
} }
static VALUE static VALUE
rb_remove_history(index) rb_remove_history(int index)
int index;
{ {
#ifdef HAVE_REMOVE_HISTORY #ifdef HAVE_REMOVE_HISTORY
HIST_ENTRY *entry; HIST_ENTRY *entry;
@ -614,8 +574,7 @@ rb_remove_history(index)
} }
static VALUE static VALUE
hist_pop(self) hist_pop(VALUE self)
VALUE self;
{ {
rb_secure(4); rb_secure(4);
if (history_length > 0) { if (history_length > 0) {
@ -626,8 +585,7 @@ hist_pop(self)
} }
static VALUE static VALUE
hist_shift(self) hist_shift(VALUE self)
VALUE self;
{ {
rb_secure(4); rb_secure(4);
if (history_length > 0) { if (history_length > 0) {
@ -638,8 +596,7 @@ hist_shift(self)
} }
static VALUE static VALUE
hist_each(self) hist_each(VALUE self)
VALUE self;
{ {
HIST_ENTRY *entry; HIST_ENTRY *entry;
int i; int i;
@ -655,25 +612,21 @@ hist_each(self)
} }
static VALUE static VALUE
hist_length(self) hist_length(VALUE self)
VALUE self;
{ {
rb_secure(4); rb_secure(4);
return INT2NUM(history_length); return INT2NUM(history_length);
} }
static VALUE static VALUE
hist_empty_p(self) hist_empty_p(VALUE self)
VALUE self;
{ {
rb_secure(4); rb_secure(4);
return history_length == 0 ? Qtrue : Qfalse; return history_length == 0 ? Qtrue : Qfalse;
} }
static VALUE static VALUE
hist_delete_at(self, index) hist_delete_at(VALUE self, VALUE index)
VALUE self;
VALUE index;
{ {
int i; int i;
@ -688,9 +641,7 @@ hist_delete_at(self, index)
} }
static VALUE static VALUE
filename_completion_proc_call(self, str) filename_completion_proc_call(VALUE self, VALUE str)
VALUE self;
VALUE str;
{ {
VALUE result; VALUE result;
char **matches; char **matches;
@ -715,9 +666,7 @@ filename_completion_proc_call(self, str)
} }
static VALUE static VALUE
username_completion_proc_call(self, str) username_completion_proc_call(VALUE self, VALUE str)
VALUE self;
VALUE str;
{ {
VALUE result; VALUE result;
char **matches; char **matches;

View file

@ -265,8 +265,7 @@ static struct token_assoc {
}; };
static ID static ID
ripper_token2eventid(tok) ripper_token2eventid(int tok)
int tok;
{ {
struct token_assoc *a; struct token_assoc *a;

View file

@ -489,8 +489,7 @@ strio_eof(self)
/* :nodoc: */ /* :nodoc: */
static VALUE static VALUE
strio_copy(copy, orig) strio_copy(VALUE copy, VALUE orig)
VALUE copy, orig;
{ {
struct StringIO *ptr; struct StringIO *ptr;
@ -559,10 +558,7 @@ strio_set_lineno(self, lineno)
* and _mode_ (see StringIO#new). * and _mode_ (see StringIO#new).
*/ */
static VALUE static VALUE
strio_reopen(argc, argv, self) strio_reopen(int argc, VALUE *argv, VALUE self)
int argc;
VALUE *argv;
VALUE self;
{ {
if (!OBJ_TAINTED(self)) rb_secure(4); if (!OBJ_TAINTED(self)) rb_secure(4);
if (argc == 1 && TYPE(*argv) != T_STRING) { if (argc == 1 && TYPE(*argv) != T_STRING) {
@ -717,9 +713,7 @@ strio_getc(self)
} }
static void static void
strio_extend(ptr, pos, len) strio_extend(struct StringIO *ptr, long pos, long len)
struct StringIO *ptr;
long pos, len;
{ {
long olen; long olen;
@ -1149,10 +1143,7 @@ strio_read(argc, argv, self)
* returning +nil+, as well as IO#sysread does. * returning +nil+, as well as IO#sysread does.
*/ */
static VALUE static VALUE
strio_sysread(argc, argv, self) strio_sysread(int argc, VALUE *argv, VALUE self)
int argc;
VALUE *argv;
VALUE self;
{ {
VALUE val = strio_read(argc, argv, self); VALUE val = strio_read(argc, argv, self);
if (NIL_P(val) || RSTRING(val)->len == 0) { if (NIL_P(val) || RSTRING(val)->len == 0) {

View file

@ -263,8 +263,7 @@ strscan_s_mustc(self)
* Reset the scan pointer (index 0) and clear matching data. * Reset the scan pointer (index 0) and clear matching data.
*/ */
static VALUE static VALUE
strscan_reset(self) strscan_reset(VALUE self)
VALUE self;
{ {
struct strscanner *p; struct strscanner *p;
@ -600,8 +599,7 @@ strscan_scan_until(self, re)
* s.exist? /e/ # -> nil * s.exist? /e/ # -> nil
*/ */
static VALUE static VALUE
strscan_exist_p(self, re) strscan_exist_p(VALUE self, VALUE re)
VALUE self, re;
{ {
return strscan_do_scan(self, re, 0, 0, 0); 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. * This method is obsolete; use #matched_size instead.
*/ */
static VALUE static VALUE
strscan_matchedsize(self) strscan_matchedsize(VALUE self)
VALUE self;
{ {
rb_warning("StringScanner#matchedsize is obsolete; use #matched_size instead"); rb_warning("StringScanner#matchedsize is obsolete; use #matched_size instead");
return strscan_matched_size(self); return strscan_matched_size(self);
@ -1084,8 +1081,7 @@ strscan_rest_size(self)
* This method is obsolete; use #rest_size instead. * This method is obsolete; use #rest_size instead.
*/ */
static VALUE static VALUE
strscan_restsize(self) strscan_restsize(VALUE self)
VALUE self;
{ {
rb_warning("StringScanner#restsize is obsolete; use #rest_size instead"); rb_warning("StringScanner#restsize is obsolete; use #rest_size instead");
return strscan_rest_size(self); return strscan_rest_size(self);

View file

@ -282,7 +282,7 @@ syck_emitter_clear( SyckEmitter *e )
* Raw write to the emitter buffer. * Raw write to the emitter buffer.
*/ */
void void
syck_emitter_write( SyckEmitter *e, char *str, long len ) syck_emitter_write( SyckEmitter *e, const char *str, long len )
{ {
long at; long at;
ASSERT( str != NULL ) ASSERT( str != NULL )
@ -438,7 +438,7 @@ end_emit:
* and the implicit tag which would be assigned to this node. If a tag is * and the implicit tag which would be assigned to this node. If a tag is
* required, write the tag. * 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; SyckLevel *lvl;
if ( tag == NULL ) return; 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; int skip = 4 + strlen( YAML_DOMAIN ) + 1;
syck_emitter_write( e, tag + skip, taglen - skip ); syck_emitter_write( e, tag + skip, taglen - skip );
} else { } else {
char *subd = tag + 4; const char *subd = tag + 4;
while ( *subd != ':' && *subd != '\0' ) subd++; while ( *subd != ':' && *subd != '\0' ) subd++;
if ( *subd == ':' ) { if ( *subd == ':' ) {
if ( subd - tag > ( strlen( YAML_DOMAIN ) + 5 ) && 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] == ':' || if ( ( cursor[0] == '-' || cursor[0] == ':' ||
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; 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 ) ) if ( ! st_lookup( e->anchors, (st_data_t)oid, (st_data_t *)&anchor_name ) )
{ {
int idx = 0; 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 * Second time hitting this object, let's give it an anchor

View file

@ -155,7 +155,7 @@ syck_xprivate( char *type_id, int type_len )
} }
char * 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 ); char *uri = S_ALLOC_N( char, strlen( domain ) + type_len + 14 );
uri[0] = '\0'; uri[0] = '\0';

View file

@ -1585,7 +1585,7 @@ yy201: ++YYCURSOR;
/* Remove ending fragment and compare types */ /* Remove ending fragment and compare types */
int int
syck_tagcmp( char *tag1, char *tag2 ) syck_tagcmp( const char *tag1, const char *tag2 )
{ {
if ( tag1 == tag2 ) return 1; if ( tag1 == tag2 ) return 1;
if ( tag1 == NULL || tag2 == NULL ) return 0; if ( tag1 == NULL || tag2 == NULL ) return 0;

View file

@ -100,13 +100,13 @@ syck_alloc_str()
} }
SyckNode * 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 ); return syck_new_str2( str, strlen( str ), style );
} }
SyckNode * 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; SyckNode *n;

View file

@ -32,7 +32,7 @@ syck_assert( char *file_name, unsigned line_num )
* Allocates and copies a string * Allocates and copies a string
*/ */
char * char *
syck_strndup( char *buf, long len ) syck_strndup( const char *buf, long len )
{ {
char *new = S_ALLOC_N( char, len + 1 ); char *new = S_ALLOC_N( char, len + 1 );
S_MEMZERO( new, char, len + 1 ); S_MEMZERO( new, char, len + 1 );

View file

@ -346,8 +346,8 @@ void syck_hdlr_remove_anchor( SyckParser *, char * );
SyckNode *syck_hdlr_get_anchor( SyckParser *, char * ); SyckNode *syck_hdlr_get_anchor( SyckParser *, char * );
void syck_add_transfer( char *, SyckNode *, int ); void syck_add_transfer( char *, SyckNode *, int );
char *syck_xprivate( char *, int ); char *syck_xprivate( char *, int );
char *syck_taguri( char *, char *, int ); char *syck_taguri( const char *, const char *, int );
int syck_tagcmp( char *, char * ); int syck_tagcmp( const char *, const char * );
int syck_add_sym( SyckParser *, char * ); int syck_add_sym( SyckParser *, char * );
int syck_lookup_sym( SyckParser *, SYMID, char ** ); int syck_lookup_sym( SyckParser *, SYMID, char ** );
int syck_try_implicit( SyckNode * ); int syck_try_implicit( SyckNode * );
@ -358,7 +358,7 @@ char *syck_match_implicit( char *, size_t );
/* /*
* API prototypes * 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_file_read( char *, SyckIoFile *, long, long );
long syck_io_str_read( char *, SyckIoStr *, long, long ); long syck_io_str_read( char *, SyckIoStr *, long, long );
char *syck_base64enc( char *, long ); char *syck_base64enc( char *, long );
@ -370,7 +370,7 @@ void syck_output_handler( SyckEmitter *, SyckOutputHandler );
void syck_emitter_handler( SyckEmitter *, SyckEmitterHandler ); void syck_emitter_handler( SyckEmitter *, SyckEmitterHandler );
void syck_free_emitter( SyckEmitter * ); void syck_free_emitter( SyckEmitter * );
void syck_emitter_clear( 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_escape( SyckEmitter *, char *, long );
void syck_emitter_flush( SyckEmitter *, long ); void syck_emitter_flush( SyckEmitter *, long );
void syck_emit( SyckEmitter *, st_data_t ); 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_item( SyckEmitter *, st_data_t );
void syck_emit_map( SyckEmitter *, char *, enum map_style ); void syck_emit_map( SyckEmitter *, char *, enum map_style );
void syck_emit_end( SyckEmitter * ); 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 * ); void syck_emit_indent( SyckEmitter * );
SyckLevel *syck_emitter_current_level( SyckEmitter * ); SyckLevel *syck_emitter_current_level( SyckEmitter * );
SyckLevel *syck_emitter_parent_level( SyckEmitter * ); SyckLevel *syck_emitter_parent_level( SyckEmitter * );
@ -421,8 +421,8 @@ SyckNode *syck_alloc_seq();
SyckNode *syck_alloc_str(); SyckNode *syck_alloc_str();
void syck_free_node( SyckNode * ); void syck_free_node( SyckNode * );
void syck_free_members( SyckNode * ); void syck_free_members( SyckNode * );
SyckNode *syck_new_str( char *, enum scalar_style ); SyckNode *syck_new_str( const char *, enum scalar_style );
SyckNode *syck_new_str2( char *, long, 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_str( SyckNode *, char *, enum scalar_style );
void syck_replace_str2( SyckNode *, char *, long, enum scalar_style ); void syck_replace_str2( SyckNode *, char *, long, enum scalar_style );
void syck_str_blow_away_commas( SyckNode * ); void syck_str_blow_away_commas( SyckNode * );

View file

@ -145,6 +145,7 @@ syck_yaml2byte_handler(p, n)
strcat( type_tag, "!" ); strcat( type_tag, "!" );
strcat( type_tag, n->type_id ); strcat( type_tag, n->type_id );
bytestring_append( val, YAMLBYTE_TRANSFER, type_tag, NULL); bytestring_append( val, YAMLBYTE_TRANSFER, type_tag, NULL);
S_FREE(type_tag);
} }
} }
switch (n->kind) switch (n->kind)

View file

@ -6217,7 +6217,11 @@ lib_fromUTF8_core(ip_obj, src, encodename)
char *s; char *s;
int len; int len;
<<<<<<< tcltklib.c
StringValue(str); StringValue(str);
=======
StringValue(str);
>>>>>>> 1.45
s = Tcl_GetByteArrayFromObj(Tcl_NewStringObj(RSTRING(str)->ptr, s = Tcl_GetByteArrayFromObj(Tcl_NewStringObj(RSTRING(str)->ptr,
RSTRING(str)->len), RSTRING(str)->len),
&len); &len);

File diff suppressed because it is too large Load diff

8
gc.c
View file

@ -412,6 +412,7 @@ add_heap(void)
if (himem < pend) himem = pend; if (himem < pend) himem = pend;
heaps_used++; heaps_used++;
heap_slots *= 1.8; heap_slots *= 1.8;
if (heap_slots <= 0) heap_slots = HEAP_MIN_SLOTS;
while (p < pend) { while (p < pend) {
p->as.free.flags = 0; p->as.free.flags = 0;
@ -832,6 +833,7 @@ gc_mark_children(VALUE ptr, int lev)
case NODE_MODULE: case NODE_MODULE:
case NODE_ALIAS: case NODE_ALIAS:
case NODE_VALIAS: case NODE_VALIAS:
case NODE_BLOCK_PASS:
gc_mark((VALUE)obj->as.node.u1.node, lev); gc_mark((VALUE)obj->as.node.u1.node, lev);
/* fall through */ /* fall through */
case NODE_METHOD: /* 2 */ case NODE_METHOD: /* 2 */
@ -863,12 +865,10 @@ gc_mark_children(VALUE ptr, int lev)
case NODE_COLON2: case NODE_COLON2:
case NODE_SPLAT: case NODE_SPLAT:
case NODE_TO_ARY: case NODE_TO_ARY:
case NODE_SVALUE:
ptr = (VALUE)obj->as.node.u1.node; ptr = (VALUE)obj->as.node.u1.node;
goto again; goto again;
case NODE_SCOPE: /* 2,3 */ case NODE_SCOPE: /* 2,3 */
case NODE_BLOCK_PASS:
case NODE_CDECL: case NODE_CDECL:
gc_mark((VALUE)obj->as.node.u3.node, lev); gc_mark((VALUE)obj->as.node.u3.node, lev);
ptr = (VALUE)obj->as.node.u2.node; ptr = (VALUE)obj->as.node.u2.node;
@ -2066,7 +2066,7 @@ Init_GC(void)
rb_global_variable(&nomem_error); rb_global_variable(&nomem_error);
nomem_error = rb_exc_new2(rb_eNoMemError, "failed to allocate memory"); 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, "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);
} }

30
hash.c
View file

@ -33,7 +33,7 @@ rb_hash_freeze(VALUE hash)
VALUE rb_cHash; VALUE rb_cHash;
static VALUE envtbl; static VALUE envtbl;
static ID id_hash, id_call, id_default; static ID id_hash, id_yield, id_default;
static VALUE static VALUE
eql(VALUE *args) eql(VALUE *args)
@ -474,7 +474,7 @@ rb_hash_default(int argc, VALUE *argv, VALUE hash)
rb_scan_args(argc, argv, "01", &key); rb_scan_args(argc, argv, "01", &key);
if (FL_TEST(hash, HASH_PROC_DEFAULT)) { 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; return RHASH(hash)->ifnone;
} }
@ -656,7 +656,7 @@ rb_hash_shift(VALUE hash)
return rb_assoc_new(var.key, var.val); return rb_assoc_new(var.key, var.val);
} }
else if (FL_TEST(hash, HASH_PROC_DEFAULT)) { 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 { else {
return RHASH(hash)->ifnone; return RHASH(hash)->ifnone;
@ -986,7 +986,7 @@ static int
each_pair_i(VALUE key, VALUE value) each_pair_i(VALUE key, VALUE value)
{ {
if (key == Qundef) return ST_CONTINUE; if (key == Qundef) return ST_CONTINUE;
rb_yield_values(2, key, value); rb_yield(rb_assoc_new(key, value));
return ST_CONTINUE; return ST_CONTINUE;
} }
@ -994,11 +994,11 @@ each_pair_i(VALUE key, VALUE value)
* call-seq: * call-seq:
* hsh.each_pair {| key_value_array | block } -> hsh * hsh.each_pair {| key_value_array | block } -> hsh
* *
* Calls <i>block</i> once for each key in <i>hsh</i>, passing the key * Calls <i>block</i> once for each key in <i>hsh</i>, passing the
* and value as parameters. * key and value to the block as a two-element array.
* *
* h = { "a" => 100, "b" => 200 } * h = { "a" => 100, "b" => 200 }
* h.each_pair {|key, value| puts "#{key} is #{value}" } * h.each_pair {|(key, value)| puts "#{key} is #{value}" }
* *
* <em>produces:</em> * <em>produces:</em>
* *
@ -1019,7 +1019,7 @@ static int
each_i(VALUE key, VALUE value) each_i(VALUE key, VALUE value)
{ {
if (key == Qundef) return ST_CONTINUE; if (key == Qundef) return ST_CONTINUE;
rb_yield(rb_assoc_new(key, value)); rb_yield_values(2, key, value);
return ST_CONTINUE; return ST_CONTINUE;
} }
@ -1027,11 +1027,9 @@ each_i(VALUE key, VALUE value)
* call-seq: * call-seq:
* hsh.each {| key, value | block } -> hsh * hsh.each {| key, value | block } -> hsh
* *
* Calls <i>block</i> once for each key in <i>hsh</i>, passing the key * Calls <i>block</i> once for each key in <i>hsh</i>, passing the key-value
* and value to the block as a two-element array. Because of the assignment * pair as parameters. Also see <code>Hash#each_pair</code>, which
* semantics of block parameters, these elements will be split out if the * passes the key and value to the block as a two-element array.
* block has two formal parameters. Also see <code>Hash.each_pair</code>, which
* will be marginally more efficient for blocks with two parameters.
* *
* h = { "a" => 100, "b" => 200 } * h = { "a" => 100, "b" => 200 }
* h.each {|key, value| puts "#{key} is #{value}" } * h.each {|key, value| puts "#{key} is #{value}" }
@ -1893,14 +1891,14 @@ static VALUE
env_each(VALUE ehash) env_each(VALUE ehash)
{ {
RETURN_ENUMERATOR(ehash, 0, 0); RETURN_ENUMERATOR(ehash, 0, 0);
return env_each_i(ehash, Qfalse); return env_each_i(ehash, Qtrue);
} }
static VALUE static VALUE
env_each_pair(VALUE ehash) env_each_pair(VALUE ehash)
{ {
RETURN_ENUMERATOR(ehash, 0, 0); RETURN_ENUMERATOR(ehash, 0, 0);
return env_each_i(ehash, Qtrue); return env_each_i(ehash, Qfalse);
} }
static VALUE static VALUE
@ -2273,7 +2271,7 @@ void
Init_Hash(void) Init_Hash(void)
{ {
id_hash = rb_intern("hash"); id_hash = rb_intern("hash");
id_call = rb_intern("call"); id_yield = rb_intern("yield");
id_default = rb_intern("default"); id_default = rb_intern("default");
rb_cHash = rb_define_class("Hash", rb_cObject); rb_cHash = rb_define_class("Hash", rb_cObject);

View file

@ -25,7 +25,7 @@ def parse_args()
opt.on('--dest-dir=DIR') {|dir| $destdir = dir} opt.on('--dest-dir=DIR') {|dir| $destdir = dir}
opt.on('--make=COMMAND') {|make| $make = make} opt.on('--make=COMMAND') {|make| $make = make}
opt.on('--mantype=MAN') {|man| $mantype = man} 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 if arg = v.first
arg.insert(0, '-') if /\A[^-][^=]*\Z/ =~ arg arg.insert(0, '-') if /\A[^-][^=]*\Z/ =~ arg
end end
@ -38,7 +38,7 @@ def parse_args()
$mflags.unshift(*rest) unless rest.empty? $mflags.unshift(*rest) unless rest.empty?
def $mflags.set?(flag) def $mflags.set?(flag)
grep(/\A-(?!-).*#{'%c' % flag}/i) { return true } grep(/\A-(?!-).*#{'%s' % flag}/i) { return true }
false false
end end

View file

@ -128,6 +128,7 @@ VALUE rb_class_instance_methods(int, VALUE*, VALUE);
VALUE rb_class_public_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_protected_instance_methods(int, VALUE*, VALUE);
VALUE rb_class_private_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); VALUE rb_obj_singleton_methods(int, VALUE*, VALUE);
void rb_define_method_id(VALUE, ID, VALUE (*)(ANYARGS), int); void rb_define_method_id(VALUE, ID, VALUE (*)(ANYARGS), int);
void rb_frozen_class_p(VALUE); 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_range_beg_len(VALUE, long*, long*, long, int);
VALUE rb_length_by_each(VALUE); VALUE rb_length_by_each(VALUE);
/* re.c */ /* re.c */
int rb_memcmp(char*,char*,long); int rb_memcmp(const void*,const void*,long);
int rb_memcicmp(char*,char*,long); int rb_memcicmp(const void*,const void*,long);
long rb_memsearch(char*,long,char*,long); long rb_memsearch(const void*,long,const void*,long);
VALUE rb_reg_nth_defined(int, VALUE); VALUE rb_reg_nth_defined(int, VALUE);
VALUE rb_reg_nth_match(int, VALUE); VALUE rb_reg_nth_match(int, VALUE);
VALUE rb_reg_last_match(VALUE); VALUE rb_reg_last_match(VALUE);

84
io.c
View file

@ -1095,7 +1095,8 @@ static VALUE
rb_io_inspect(VALUE obj) rb_io_inspect(VALUE obj)
{ {
OpenFile *fptr; OpenFile *fptr;
char *cname, *st = ""; char *cname;
const char *st = "";
fptr = RFILE(rb_io_taint_check(obj))->fptr; fptr = RFILE(rb_io_taint_check(obj))->fptr;
if (!fptr || !fptr->path) return rb_any_to_s(obj); if (!fptr || !fptr->path) return rb_any_to_s(obj);
@ -1962,18 +1963,6 @@ rb_io_each_byte(VALUE io)
return io; return io;
} }
/*
* call-seq:
* ios.getc => fixnum or nil
*
* Gets the next 8-bit byte (0..255) from <em>ios</em>. Returns
* <code>nil</code> if called at end of file.
*
* f = File.new("testfile")
* f.getc #=> 84
* f.getc #=> 104
*/
VALUE VALUE
rb_io_getc(VALUE io) rb_io_getc(VALUE io)
{ {
@ -1992,6 +1981,38 @@ rb_io_getc(VALUE io)
return INT2FIX(c & 0xff); return INT2FIX(c & 0xff);
} }
/*
* call-seq:
* ios.getc => string or nil
*
* Reads a one-character string from <em>ios</em>. Returns
* <code>nil</code> if called at end of file.
*
* f = File.new("testfile")
* f.getc #=> "8"
* f.getc #=> "1"
*/
VALUE
rb_io_getc_m(VALUE io)
{
char ch;
OpenFile *fptr;
int c;
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
READ_CHECK(fptr);
c = io_getc(fptr);
if (c < 0) {
return Qnil;
}
ch = c & 0xff;
return rb_str_new(&ch, 1);
}
int int
rb_getc(FILE *f) rb_getc(FILE *f)
{ {
@ -2009,7 +2030,7 @@ rb_getc(FILE *f)
/* /*
* call-seq: * call-seq:
* ios.readchar => fixnum * ios.readchar => string
* *
* Reads a character as with <code>IO#getc</code>, but raises an * Reads a character as with <code>IO#getc</code>, but raises an
* <code>EOFError</code> on end of file. * <code>EOFError</code> on end of file.
@ -2028,7 +2049,7 @@ rb_io_readchar(VALUE io)
/* /*
* call-seq: * call-seq:
* ios.ungetc(integer) => nil * ios.ungetc(string) => nil
* *
* Pushes back one character (passed as a parameter) onto <em>ios</em>, * Pushes back one character (passed as a parameter) onto <em>ios</em>,
* such that a subsequent buffered read will return it. Only one character * 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 <code>IO#sysread</code>). * back). Has no effect with unbuffered reads (such as <code>IO#sysread</code>).
* *
* f = File.new("testfile") #=> #<File:testfile> * f = File.new("testfile") #=> #<File:testfile>
* c = f.getc #=> 84 * c = f.getc #=> "8"
* f.ungetc(c) #=> nil * f.ungetc(c) #=> nil
* f.getc #=> 84 * f.getc #=> "8"
*/ */
VALUE VALUE
rb_io_ungetc(VALUE io, VALUE c) rb_io_ungetc(VALUE io, VALUE c)
{ {
OpenFile *fptr; OpenFile *fptr;
int cc = NUM2INT(c); int cc;
GetOpenFile(io, fptr); GetOpenFile(io, fptr);
rb_io_check_readable(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) { if (io_ungetc(cc, fptr) == EOF && cc != EOF) {
rb_raise(rb_eIOError, "ungetc failed"); rb_raise(rb_eIOError, "ungetc failed");
} }
@ -2912,8 +2943,9 @@ popen_redirect(struct popen_arg *p)
#ifdef HAVE_FORK #ifdef HAVE_FORK
static int static int
popen_exec(struct popen_arg *p) popen_exec(void *pp)
{ {
struct popen_arg *p = (struct popen_arg*)pp;
int fd; int fd;
popen_redirect(p); popen_redirect(p);
@ -5316,23 +5348,23 @@ argf_readpartial(int argc, VALUE *argv)
static VALUE static VALUE
argf_getc(void) argf_getc(void)
{ {
VALUE byte; VALUE ch;
retry: retry:
if (!next_argv()) return Qnil; if (!next_argv()) return Qnil;
if (TYPE(current_file) != T_FILE) { 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 { 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); argf_close(current_file);
next_p = 1; next_p = 1;
goto retry; goto retry;
} }
return byte; return ch;
} }
static VALUE static VALUE
@ -5646,7 +5678,7 @@ Init_IO(void)
rb_define_method(rb_cIO, "write", io_write, 1); 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, "gets", rb_io_gets_m, -1);
rb_define_method(rb_cIO, "readline", rb_io_readline, -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, "readchar", rb_io_readchar, 0);
rb_define_method(rb_cIO, "ungetc",rb_io_ungetc, 1); rb_define_method(rb_cIO, "ungetc",rb_io_ungetc, 1);
rb_define_method(rb_cIO, "<<", rb_io_addstr, 1); rb_define_method(rb_cIO, "<<", rb_io_addstr, 1);

View file

@ -20,6 +20,7 @@ fileutils.rb
find.rb find.rb
forwardable.rb forwardable.rb
generator.rb generator.rb
getoptlong.rb
logger.rb logger.rb
matrix.rb matrix.rb
net net

View file

@ -726,6 +726,8 @@ class CGI
when /shift_jis/ni when /shift_jis/ni
content = NKF::nkf('-s', content) content = NKF::nkf('-s', content)
options["language"] = "ja" unless options.has_key?("language") options["language"] = "ja" unless options.has_key?("language")
when /utf-8/ni
content = NKF::nkf('-w', content)
end end
end end

View file

@ -93,7 +93,7 @@
# array, like this: # array, like this:
# #
# class RecordCollection # class RecordCollection
# extends Forwardable # extend Forwardable
# def_delegator :@records, :[], :record_number # def_delegator :@records, :[], :record_number
# end # end
# #
@ -101,7 +101,7 @@
# all of which delegate to @records, this is how you can do it: # all of which delegate to @records, this is how you can do it:
# #
# class RecordCollection # class RecordCollection
# # extends Forwardable, but we did that above # # extend Forwardable, but we did that above
# def_delegators :@records, :size, :<<, :map # def_delegators :@records, :size, :<<, :map
# end # end
# f = Foo.new # f = Foo.new

View file

@ -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. # 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: # GetoptLong allows for POSIX-style options like <tt>--file</tt> as well
# http://www.sra.co.jp/people/m-kasahr/ruby/getoptlong/ # as single letter options like <tt>-f</tt>
# #
# The empty option <tt>--</tt> (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 class GetoptLong
# #
@ -40,13 +117,20 @@ class GetoptLong
class InvalidOption < Error; end class InvalidOption < Error; end
# #
# The arguments are passed to new() as an array of arrays. Each # Set up option processing.
# subarray has a number of option names which carry the same #
# meaning, and a ARGUMENT_FLAG, being one of # The options to support are passed to new() as an array of arrays.
# GetoptLong::NO_ARGUMENT, GetoptLong::REQUIRED_ARGUMENT or # Each sub-array contains any number of String option names which carry
# GetoptLong::OPTIONAL_ARGUMENT. These determine whether the # the same meaning, and one of the following flags:
# option takes an argument or not, or whether it is optional The #
# actual processing is done later with #each(). # 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) def initialize(*arguments)
# #
@ -109,11 +193,53 @@ class GetoptLong
end end
# #
# Set the handling of the ordering of options. The supplied # Set the handling of the ordering of options and arguments.
# argument ordering must be a member of ORDERINGS, i.e one of # A RuntimeError is raised if option processing has already started.
# GetoptLong::REQUIRE_ORDER, GetoptLong::PERMUTE, #
# GetoptLong::RETURN_IN_ORDER. A RuntimeError is raised if # The supplied value must be a member of GetoptLong::ORDERINGS. It alters
# option processing has already started. # the processing of options as follows:
#
# <b>REQUIRE_ORDER</b> :
#
# 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.)
#
# <b>PERMUTE</b> :
#
# 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.
#
# <b>RETURN_IN_ORDER</b> :
#
# 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) def ordering=(ordering)
# #
@ -144,7 +270,9 @@ class GetoptLong
attr_reader :ordering 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) def set_options(*arguments)
# #
@ -233,7 +361,7 @@ class GetoptLong
alias quiet? quiet alias quiet? quiet
# #
# Terminate option processing. # Explicitly terminate option processing.
# #
def terminate def terminate
return nil if @status == STATUS_TERMINATED return nil if @status == STATUS_TERMINATED
@ -253,7 +381,7 @@ class GetoptLong
end end
# #
# Examine whether option processing is terminated or not. # Returns true if option processing has terminated, false otherwise.
# #
def terminated? def terminated?
return @status == STATUS_TERMINATED return @status == STATUS_TERMINATED
@ -286,16 +414,22 @@ class GetoptLong
# #
alias error? error alias error? error
# # Return the appropriate error message in POSIX-defined format.
# Return an error message. # If no error has occurred, returns nil.
# #
def error_message def error_message
return @error_message return @error_message
end end
# #
# Get next option name and its argument as an array. # Get next option name and its argument, as an Array of two elements.
# Return nil if the processing is complete (as determined by #
# 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). # STATUS_TERMINATED).
# #
def get def get
@ -462,9 +596,15 @@ class GetoptLong
# #
alias get_option get alias get_option get
# Iterator version of `get'.
# #
# Iterator version of `get', passes the option and the # The block is called repeatedly with two arguments:
# corresponding argument to the supplied block for processing. # The first is the option name.
# The second is the argument which followed it (if any).
# Example: ('--opt', 'value')
#
# The option name is always converted to the first (preferred)
# name given in the original options to GetoptLong.new.
# #
def each def each
loop do loop do

View file

@ -174,7 +174,7 @@ class String
def tr_s!(from, to) def tr_s!(from, to)
return self.delete!(from) if to.length == 0 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] == ?^ if from[0] == ?^
last = /.$/.match(to)[0] last = /.$/.match(to)[0]
self.gsub!(pattern, last) self.gsub!(pattern, last)

View file

@ -16,14 +16,6 @@ require "matrix.rb"
class Integer 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) def Integer.from_prime_division(pd)
value = 1 value = 1
for prime, index in pd for prime, index in pd

View file

@ -786,21 +786,26 @@ def find_executable(bin, path = nil)
end end
end end
def arg_config(config, *defaults, &block) def arg_config(config, default=nil, &block)
$arg_config << [config, *defaults] $arg_config << [config, default]
defaults << nil if !block and defaults.empty? defaults = []
if default
defaults << default
elsif !block
defaults << nil
end
$configure_args.fetch(config.tr('_', '-'), *defaults, &block) $configure_args.fetch(config.tr('_', '-'), *defaults, &block)
end end
def with_config(config, *defaults) def with_config(config, default=nil)
config = config.sub(/^--with[-_]/, '') config = config.sub(/^--with[-_]/, '')
val = arg_config("--with-"+config) do val = arg_config("--with-"+config) do
if arg_config("--without-"+config) if arg_config("--without-"+config)
false false
elsif block_given? elsif block_given?
yield(config, *defaults) yield(config, default)
else else
break *defaults break default
end end
end end
case val case val
@ -813,15 +818,15 @@ def with_config(config, *defaults)
end end
end end
def enable_config(config, *defaults) def enable_config(config, default=nil)
if arg_config("--enable-"+config) if arg_config("--enable-"+config)
true true
elsif arg_config("--disable-"+config) elsif arg_config("--disable-"+config)
false false
elsif block_given? elsif block_given?
yield(config, *defaults) yield(config, default)
else else
return *defaults return default
end end
end end
@ -1105,7 +1110,7 @@ EXTSTATIC = #{$static || ""}
STATIC_LIB = #{staticlib unless $static.nil?} 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).' n = ($extout ? '$(RUBYARCHDIR)/' : '') + '$(TARGET).'
mfile.print %{ mfile.print %{
TARGET_SO = #{($extout ? '$(RUBYARCHDIR)/' : '')}$(DLLIB) TARGET_SO = #{($extout ? '$(RUBYARCHDIR)/' : '')}$(DLLIB)

View file

@ -357,7 +357,7 @@ class OptionParser
if conv if conv
val = conv.call(*val) val = conv.call(*val)
else else
val = *val val = val[0]
end end
return arg, block, val return arg, block, val
else else
@ -622,7 +622,7 @@ class OptionParser
if list = __send__(id) if list = __send__(id)
val = list.fetch(key) {return nil} val = list.fetch(key) {return nil}
return val unless block_given? return val unless block_given?
yield(val) yield(*val)
end end
end end
@ -848,7 +848,7 @@ class OptionParser
# :nodoc: # :nodoc:
def add_officious def add_officious
list = base() list = base()
Officious.each_pair do |opt, block| Officious.each do |opt, block|
list.long[opt] ||= block.call(self) list.long[opt] ||= block.call(self)
end end
end end
@ -1319,7 +1319,7 @@ class OptionParser
end end
begin begin
opt, sw, val = sw.parse(rest, argv) {|*exc| raise(*exc)} opt, sw, val = sw.parse(rest, argv) {|*exc| raise(*exc)}
sw.call(val) if sw sw.call(*val) if sw
rescue ParseError rescue ParseError
raise $!.set_option(arg, rest) raise $!.set_option(arg, rest)
end end
@ -1458,9 +1458,9 @@ class OptionParser
yielded with the found value when succeeded. yielded with the found value when succeeded.
=end #'#"#`# =end #'#"#`#
def search(id, key) def search(id, key)
visit(:search, id, key) do |k| visit(:search, id, key) do |*k|
return k unless block_given? return k unless block_given?
return yield(k) return yield(*k)
end end
end end
private :search private :search

View file

@ -2555,7 +2555,7 @@ module RDoc
break break
when TkCOMMA when TkCOMMA
else else
warn("unexpected token: '#{tk2.inspect}'") if $DEBBUG warn("unexpected token: '#{tk2.inspect}'") if $DEBUG
break break
end end
end end

View file

@ -41,5 +41,11 @@ module RI
# This is the search path for 'ri' # This is the search path for 'ri'
PATH = [ SYSDIR, SITEDIR, HOMEDIR ].find_all {|p| p && File.directory?(p)} 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
end end

View file

@ -6,8 +6,7 @@ require 'test/unit/assertions'
require 'runit/error' require 'runit/error'
module RUNIT module RUNIT
module Assert module AssertMixin
include Test::Unit::Assertions
def setup_assert def setup_assert
end end
@ -70,4 +69,8 @@ module RUNIT
/assertions\.rb/.match(caller[1]) /assertions\.rb/.match(caller[1])
end end
end end
module Assert
include Test::Unit::Assertions
include AssertMixin
end
end end

View file

@ -10,7 +10,7 @@ require 'test/unit/testcase'
module RUNIT module RUNIT
class TestCase < Test::Unit::TestCase class TestCase < Test::Unit::TestCase
include RUNIT::Assert include RUNIT::AssertMixin
def self.suite def self.suite
method_names = instance_methods(true) method_names = instance_methods(true)

View file

@ -67,7 +67,7 @@ class Tempfile < DelegateClass(File)
end end
def make_tmpname(basename, n) def make_tmpname(basename, n)
sprintf('%s%d.%d', basename, $$, n) sprintf('%s.%d.%d', basename, $$, n)
end end
private :make_tmpname private :make_tmpname

View file

@ -304,7 +304,7 @@ w_float(double d, struct dump_arg *arg)
static void static void
w_symbol(ID id, struct dump_arg *arg) w_symbol(ID id, struct dump_arg *arg)
{ {
char *sym = rb_id2name(id); const char *sym = rb_id2name(id);
st_data_t num; st_data_t num;
if (st_lookup(arg->symbols, id, &num)) { if (st_lookup(arg->symbols, id, &num)) {
@ -872,7 +872,7 @@ r_symbol(struct load_arg *arg)
return r_symreal(arg); return r_symreal(arg);
} }
static char* static const char*
r_unique(struct load_arg *arg) r_unique(struct load_arg *arg)
{ {
return rb_id2name(r_symbol(arg)); return rb_id2name(r_symbol(arg));

46
math.c
View file

@ -300,16 +300,55 @@ math_exp(VALUE obj, VALUE x)
*/ */
static VALUE 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); Need_Float(x);
errno = 0; errno = 0;
d = log(RFLOAT(x)->value); d = log(RFLOAT(x)->value);
if (errno) { if (errno) {
rb_sys_fail("log"); 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 <i>numeric</i>.
*/
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); 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, "atanh", math_atanh, 1);
rb_define_module_function(rb_mMath, "exp", math_exp, 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, "log10", math_log10, 1);
rb_define_module_function(rb_mMath, "sqrt", math_sqrt, 1); rb_define_module_function(rb_mMath, "sqrt", math_sqrt, 1);

View file

@ -314,9 +314,7 @@ static int BSD__sfvwrite(fp, uio)
* then reset it so that it can be reused. * then reset it so that it can be reused.
*/ */
static int static int
BSD__sprint(fp, uio) BSD__sprint(FILE *fp, register struct __suio *uio)
FILE *fp;
register struct __suio *uio;
{ {
register int err; register int err;
@ -337,10 +335,7 @@ BSD__sprint(fp, uio)
* worries about ungetc buffers and so forth. * worries about ungetc buffers and so forth.
*/ */
static int static int
BSD__sbprintf(fp, fmt, ap) BSD__sbprintf(register FILE *fp, const char *fmt, va_list ap)
register FILE *fp;
const char *fmt;
va_list ap;
{ {
/* We don't support files. */ /* We don't support files. */
return 0; return 0;
@ -361,11 +356,7 @@ BSD__sbprintf(fp, fmt, ap)
* use the given digits. * use the given digits.
*/ */
static char * static char *
BSD__ultoa(val, endp, base, octzero, xdigs) BSD__ultoa(register u_long val, char *endp, int base, int octzero, char *xdigs)
register u_long val;
char *endp;
int base, octzero;
char *xdigs;
{ {
register char *cp = endp; register char *cp = endp;
register long sval; register long sval;
@ -464,10 +455,7 @@ static int exponent __P((char *, int, int));
#define ZEROPAD 0x080 /* zero (as opposed to blank) pad */ #define ZEROPAD 0x080 /* zero (as opposed to blank) pad */
#define FPT 0x100 /* Floating point number */ #define FPT 0x100 /* Floating point number */
static int static int
BSD_vfprintf(fp, fmt0, ap) BSD_vfprintf(FILE *fp, const char *fmt0, va_list ap)
FILE *fp;
const char *fmt0;
va_list ap;
{ {
register char *fmt; /* format string */ register char *fmt; /* format string */
register int ch; /* character from fmt */ register int ch; /* character from fmt */

View file

@ -38,9 +38,11 @@ vars = {}
has_version = false has_version = false
File.foreach "config.status" do |line| File.foreach "config.status" do |line|
next if /^#/ =~ 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 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" v_fast << " CONFIG[\"ruby_install_name\"] = \"" + "ruby".sub(/#{ptn[0]}/,ptn[1]) + "\"\n"
elsif /^s[%,]@(\w+)@[%,](.*)[%,]/ =~ line elsif /^s[%,]@(\w+)@[%,](.*)[%,]/ =~ line
name = $1 name = $1

9
node.h
View file

@ -86,11 +86,11 @@ enum node_type {
NODE_DREGX, NODE_DREGX,
NODE_DREGX_ONCE, NODE_DREGX_ONCE,
NODE_ARGS, NODE_ARGS,
NODE_POSTARG,
NODE_ARGSCAT, NODE_ARGSCAT,
NODE_ARGSPUSH, NODE_ARGSPUSH,
NODE_SPLAT, NODE_SPLAT,
NODE_TO_ARY, NODE_TO_ARY,
NODE_SVALUE,
NODE_BLOCK_ARG, NODE_BLOCK_ARG,
NODE_BLOCK_PASS, NODE_BLOCK_PASS,
NODE_DEFN, NODE_DEFN,
@ -311,11 +311,11 @@ typedef struct RNode {
#define NEW_SUPER(a) NEW_NODE(NODE_SUPER,0,0,a) #define NEW_SUPER(a) NEW_NODE(NODE_SUPER,0,0,a)
#define NEW_ZSUPER() NEW_NODE(NODE_ZSUPER,0,0,0) #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_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_ARGSCAT(a,b) NEW_NODE(NODE_ARGSCAT,a,b,0)
#define NEW_ARGSPUSH(a,b) NEW_NODE(NODE_ARGSPUSH,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_SPLAT(a) NEW_NODE(NODE_SPLAT,a,0,0)
#define NEW_TO_ARY(a) NEW_NODE(NODE_TO_ARY,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_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_BLOCK_PASS(b) NEW_NODE(NODE_BLOCK_PASS,0,b,0)
#define NEW_ALIAS(n,o) NEW_NODE(NODE_ALIAS,n,o,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_NOSUPER 1
#define NOEX_PRIVATE 2 #define NOEX_PRIVATE 2
#define NOEX_PROTECTED 4 #define NOEX_PROTECTED 4
#define NOEX_MASK 6 #define NOEX_LOCAL 8
#define NOEX_MASK 14
#define NOEX_UNDEF NOEX_NOSUPER #define NOEX_UNDEF NOEX_NOSUPER
#define NOEX_RECV 8 #define NOEX_RECV 16
VALUE rb_parser_new(void); VALUE rb_parser_new(void);
VALUE rb_parser_end_seen_p(VALUE); VALUE rb_parser_end_seen_p(VALUE);

View file

@ -284,21 +284,21 @@ num_div(VALUE x, VALUE y)
* ------+-----+---------------+---------+-------------+--------------- * ------+-----+---------------+---------+-------------+---------------
* -13 | -4 | 3, -1 | 3 | -1 | -1 * -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 * Examples
* 11.divmod(3) #=> [3, 2] * 11.divmod(3) #=> [3, 2]
* 11.divmod(-3) #=> [-4, -1] * 11.divmod(-3) #=> [-4, -1]
* 11.divmod(3.5) #=> [3.0, 0.5] * 11.divmod(3.5) #=> [3, 0.5]
* (-11).divmod(3.5) #=> [-4.0, 3.0] * (-11).divmod(3.5) #=> [-4, 3.0]
* (11.5).divmod(3.5) #=> [3.0, 1.0] * (11.5).divmod(3.5) #=> [3, 1.0]
*/ */
static VALUE static VALUE
@ -696,7 +696,7 @@ flo_mod(VALUE x, VALUE y)
static VALUE static VALUE
flo_divmod(VALUE x, VALUE y) flo_divmod(VALUE x, VALUE y)
{ {
double fy, div, mod; double fy, div, mod, val;
volatile VALUE a, b; volatile VALUE a, b;
switch (TYPE(y)) { switch (TYPE(y)) {
@ -713,7 +713,13 @@ flo_divmod(VALUE x, VALUE y)
return rb_num_coerce_bin(x, y); return rb_num_coerce_bin(x, y);
} }
flodivmod(RFLOAT(x)->value, fy, &div, &mod); 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); b = rb_float_new(mod);
return rb_assoc_new(a, b); return rb_assoc_new(a, b);
} }
@ -1722,7 +1728,6 @@ int_succ(VALUE num)
* receiver's value. * receiver's value.
* *
* 65.chr #=> "A" * 65.chr #=> "A"
* ?a.chr #=> "a"
* 230.chr #=> "\346" * 230.chr #=> "\346"
*/ */
@ -2603,7 +2608,7 @@ fix_abs(VALUE fix)
static VALUE static VALUE
fix_id2name(VALUE fix) fix_id2name(VALUE fix)
{ {
char *name = rb_id2name(FIX2UINT(fix)); const char *name = rb_id2name(FIX2UINT(fix));
if (name) return rb_str_new2(name); if (name) return rb_str_new2(name);
return Qnil; return Qnil;
} }

View file

@ -20,6 +20,7 @@
#include <ctype.h> #include <ctype.h>
#include <math.h> #include <math.h>
VALUE rb_cBasicObject;
VALUE rb_mKernel; VALUE rb_mKernel;
VALUE rb_cObject; VALUE rb_cObject;
VALUE rb_cModule; VALUE rb_cModule;
@ -266,7 +267,7 @@ static int
inspect_i(ID id, VALUE value, VALUE str) inspect_i(ID id, VALUE value, VALUE str)
{ {
VALUE str2; VALUE str2;
char *ivname; const char *ivname;
/* need not to show internal data */ /* need not to show internal data */
if (CLASS_OF(value) == 0) return ST_CONTINUE; if (CLASS_OF(value) == 0) return ST_CONTINUE;
@ -698,8 +699,7 @@ nil_to_s(VALUE obj)
*/ */
static VALUE static VALUE
nil_to_a(obj) nil_to_a(VALUE obj)
VALUE obj;
{ {
return rb_ary_new2(0); return rb_ary_new2(0);
} }
@ -1007,7 +1007,7 @@ static VALUE
sym_inspect(VALUE sym) sym_inspect(VALUE sym)
{ {
VALUE str; VALUE str;
char *name; const char *name;
ID id = SYM2ID(sym); ID id = SYM2ID(sym);
name = rb_id2name(id); name = rb_id2name(id);
@ -1374,7 +1374,7 @@ rb_obj_alloc(VALUE klass)
{ {
VALUE obj; VALUE obj;
if (RCLASS(klass)->super == 0) { if (RCLASS(klass)->super == 0 && klass != rb_cBasicObject) {
rb_raise(rb_eTypeError, "can't instantiate uninitialized class"); rb_raise(rb_eTypeError, "can't instantiate uninitialized class");
} }
if (FL_TEST(klass, FL_SINGLETON)) { if (FL_TEST(klass, FL_SINGLETON)) {
@ -2258,7 +2258,7 @@ rb_f_array(VALUE obj, VALUE arg)
} }
static VALUE static VALUE
boot_defclass(char *name, VALUE super) boot_defclass(const char *name, VALUE super)
{ {
extern st_table *rb_class_tbl; extern st_table *rb_class_tbl;
VALUE obj = rb_class_boot(super); VALUE obj = rb_class_boot(super);
@ -2310,8 +2310,11 @@ VALUE ruby_top_self;
* parentheses meta-classes. All metaclasses are instances * parentheses meta-classes. All metaclasses are instances
* of the class `Class'. * of the class `Class'.
* *
* +------------------+ * +-----------------+
* | | * | |
* BasicObject-->(BasicObject) |
* ^ ^ |
* | | |
* Object---->(Object) | * Object---->(Object) |
* ^ ^ ^ ^ | * ^ ^ ^ ^ |
* | | | | | * | | | | |
@ -2331,7 +2334,9 @@ VALUE ruby_top_self;
/* /*
* <code>Object</code> is the parent class of all classes in Ruby. Its * <code>BasicObject</code> is the parent class of all classes in Ruby.
* It's an explicit blank class. <code>Object</code>, the root of Ruby's
* class hierarchy is a direct subclass of <code>BasicObject</code>. Its
* methods are therefore available to all objects unless explicitly * methods are therefore available to all objects unless explicitly
* overridden. * overridden.
* *
@ -2351,18 +2356,23 @@ Init_Object(void)
{ {
VALUE metaclass; 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_cModule = boot_defclass("Module", rb_cObject);
rb_cClass = boot_defclass("Class", rb_cModule); 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_cModule, metaclass);
metaclass = rb_make_metaclass(rb_cClass, 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_mKernel = rb_define_module("Kernel");
rb_include_module(rb_cObject, rb_mKernel); 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_cClass, "inherited", rb_obj_dummy, 1);
rb_define_private_method(rb_cModule, "included", 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); 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_removed", rb_obj_dummy, 1);
rb_define_private_method(rb_cModule, "method_undefined", 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, "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_equal, 1);
rb_define_method(rb_mKernel, "=~", rb_obj_pattern_match, 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_class_protected_instance_methods, -1); /* in class.c */
rb_define_method(rb_cModule, "private_instance_methods", rb_define_method(rb_cModule, "private_instance_methods",
rb_class_private_instance_methods, -1); /* in class.c */ 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, "constants", rb_mod_constants, 0); /* in variable.c */
rb_define_method(rb_cModule, "const_get", rb_mod_const_get, -1); rb_define_method(rb_cModule, "const_get", rb_mod_const_get, -1);

6
pack.c
View file

@ -1286,7 +1286,7 @@ infected_str_new(const char *ptr, long len, VALUE str)
static VALUE static VALUE
pack_unpack(VALUE str, VALUE fmt) pack_unpack(VALUE str, VALUE fmt)
{ {
static char *hexdigits = "0123456789abcdef0123456789ABCDEFx"; static const char *hexdigits = "0123456789abcdef0123456789ABCDEFx";
char *s, *send; char *s, *send;
char *p, *pend; char *p, *pend;
VALUE ary; VALUE ary;
@ -1320,7 +1320,7 @@ pack_unpack(VALUE str, VALUE fmt)
} }
star = 0; star = 0;
if (*p == '_' || *p == '!') { if (*p == '_' || *p == '!') {
char *natstr = "sSiIlL"; const char *natstr = "sSiIlL";
if (strchr(natstr, type)) { if (strchr(natstr, type)) {
#ifdef NATINT_PACK #ifdef NATINT_PACK
@ -1818,6 +1818,8 @@ pack_unpack(VALUE str, VALUE fmt)
while (s < send) { while (s < send) {
if (*s == '=') { if (*s == '=') {
if (++s == send) break; if (++s == send) break;
if (s+1 < send && *s == '\r' && *(s+1) == '\n')
s++;
if (*s != '\n') { if (*s != '\n') {
if ((c1 = hex2num(*s)) == -1) break; if ((c1 = hex2num(*s)) == -1) break;
if (++s == send) break; if (++s == send) break;

674
parse.y

File diff suppressed because it is too large Load diff

4
prec.c
View file

@ -55,9 +55,9 @@ prec_prec_i(VALUE x)
/* /*
* call-seq: * 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 <code>prec(Float)</code>. * to <code>prec(Float)</code>.
*/ */

View file

@ -1296,10 +1296,7 @@ proc_syswait(pid)
* +chfunc+ must not raise any exceptions. * +chfunc+ must not raise any exceptions.
*/ */
int int
rb_fork(status, chfunc, charg) rb_fork(int *status, int (*chfunc)(void*), void *charg)
int *status;
int (*chfunc)(void *);
void *charg;
{ {
int pid, err, state = 0; int pid, err, state = 0;
#ifdef FD_CLOEXEC #ifdef FD_CLOEXEC
@ -1627,12 +1624,11 @@ rb_f_spawn(int argc, VALUE *argv)
* call-seq: * call-seq:
* sleep([duration]) => fixnum * sleep([duration]) => fixnum
* *
* Suspends the current thread for _duration_ seconds (which may be * Suspends the current thread for _duration_ seconds (which may be any number,
* any number, including a +Float+ with fractional seconds). Returns the actual * including a +Float+ with fractional seconds). Returns the actual number of
* number of seconds slept (rounded), which may be less than that asked * seconds slept (rounded), which may be less than that asked for if another
* for if the thread was interrupted by a +SIGALRM+, or if * thread calls <code>Thread#run</code>. Zero arguments causes +sleep+ to sleep
* another thread calls <code>Thread#run</code>. Zero arguments * forever.
* causes +sleep+ to sleep forever.
* *
* Time.new #=> Wed Apr 09 08:56:32 CDT 2003 * Time.new #=> Wed Apr 09 08:56:32 CDT 2003
* sleep 1.2 #=> 1 * 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) #if defined(HAVE_SETRESUID) || defined(HAVE_SETEUID) || defined(_POSIX_SAVED_IDS)
static VALUE static VALUE
p_uid_sw_ensure(id) p_uid_sw_ensure(int id)
int id;
{ {
under_uid_switch = 0; under_uid_switch = 0;
return rb_seteuid_core(id); return rb_seteuid_core(id);
@ -3336,8 +3331,7 @@ p_uid_sw_ensure(id)
*/ */
static VALUE static VALUE
p_uid_switch(obj) p_uid_switch(VALUE obj)
VALUE obj;
{ {
int uid, euid; int uid, euid;
@ -3423,8 +3417,7 @@ p_gid_have_saved_id(void)
#if defined(HAVE_SETRESGID) || defined(HAVE_SETEGID) || defined(_POSIX_SAVED_IDS) #if defined(HAVE_SETRESGID) || defined(HAVE_SETEGID) || defined(_POSIX_SAVED_IDS)
static VALUE static VALUE
p_gid_sw_ensure(id) p_gid_sw_ensure(int id)
int id;
{ {
under_gid_switch = 0; under_gid_switch = 0;
return rb_setegid_core(id); return rb_setegid_core(id);
@ -3445,8 +3438,7 @@ p_gid_sw_ensure(id)
*/ */
static VALUE static VALUE
p_gid_switch(obj) p_gid_switch(VALUE obj)
VALUE obj;
{ {
int gid, egid; int gid, egid;

View file

@ -654,8 +654,7 @@ range_include(VALUE range, VALUE val)
*/ */
static VALUE static VALUE
range_cover(range, val) range_cover(VALUE range, VALUE val)
VALUE range, val;
{ {
VALUE beg, end; VALUE beg, end;

38
re.c
View file

@ -76,8 +76,9 @@ static const char casetable[] = {
#endif #endif
int 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; int tmp;
while (len--) { while (len--) {
@ -88,7 +89,7 @@ rb_memcicmp(char *p1, char *p2, long len)
} }
int int
rb_memcmp(char *p1, char *p2, long len) rb_memcmp(const void *p1, const void *p2, long len)
{ {
if (!ruby_ignorecase) { if (!ruby_ignorecase) {
return memcmp(p1, p2, len); return memcmp(p1, p2, len);
@ -97,10 +98,10 @@ rb_memcmp(char *p1, char *p2, long len)
} }
long 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; const unsigned char *x = x0, *y = y0;
unsigned char *s, *e; const unsigned char *s, *e;
long i; long i;
int d; int d;
unsigned long hx, hy; unsigned long hx, hy;
@ -151,7 +152,9 @@ rb_memsearch(char *x0, long m, char *y0, long n)
return s-y; return s-y;
} }
#define REG_LITERAL FL_USER5
#define REG_CASESTATE FL_USER0 #define REG_CASESTATE FL_USER0
#define KCODE_NONE 0 #define KCODE_NONE 0
#define KCODE_EUC FL_USER1 #define KCODE_EUC FL_USER1
#define KCODE_SJIS FL_USER2 #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_UTF8 (ARG_KCODE_UNIT * 4)
#define ARG_KCODE_MASK (ARG_KCODE_UNIT * 7) #define ARG_KCODE_MASK (ARG_KCODE_UNIT * 7)
static int reg_kcode = DEFAULT_KCODE; static int reg_kcode = DEFAULT_KCODE;
static int char_to_option(int c) static int char_to_option(int c)
{ {
int val; int val;
@ -505,13 +506,13 @@ rb_reg_to_s(VALUE re)
int options, opt; int options, opt;
const int embeddable = ONIG_OPTION_MULTILINE|ONIG_OPTION_IGNORECASE|ONIG_OPTION_EXTEND; const int embeddable = ONIG_OPTION_MULTILINE|ONIG_OPTION_IGNORECASE|ONIG_OPTION_EXTEND;
long len; long len;
const char* ptr; const UChar* ptr;
VALUE str = rb_str_buf_new2("(?"); VALUE str = rb_str_buf_new2("(?");
rb_reg_check(re); rb_reg_check(re);
options = RREGEXP(re)->ptr->options; options = RREGEXP(re)->ptr->options;
ptr = RREGEXP(re)->str; ptr = (UChar*)RREGEXP(re)->str;
len = RREGEXP(re)->len; len = RREGEXP(re)->len;
again: again:
if (len >= 4 && ptr[0] == '(' && ptr[1] == '?') { if (len >= 4 && ptr[0] == '(' && ptr[1] == '?') {
@ -566,7 +567,7 @@ rb_reg_to_s(VALUE re)
} }
if (err) { if (err) {
options = RREGEXP(re)->ptr->options; options = RREGEXP(re)->ptr->options;
ptr = RREGEXP(re)->str; ptr = (UChar*)RREGEXP(re)->str;
len = RREGEXP(re)->len; len = RREGEXP(re)->len;
} }
} }
@ -583,7 +584,7 @@ rb_reg_to_s(VALUE re)
} }
rb_str_buf_cat2(str, ":"); 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, ")"); rb_str_buf_cat2(str, ")");
OBJ_INFECT(str, re); OBJ_INFECT(str, re);
@ -1247,12 +1248,12 @@ match_captures(VALUE match)
} }
static int 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; int num;
num = onig_name_to_backref_number(RREGEXP(regexp)->ptr, 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) { if (num >= 1) {
return num; return num;
} }
@ -1301,7 +1302,7 @@ match_aref(int argc, VALUE *argv, VALUE match)
} }
} }
else { else {
char *p; const char *p;
int num; int num;
switch (TYPE(idx)) { switch (TYPE(idx)) {
@ -1336,6 +1337,8 @@ match_entry(VALUE match, long n)
/* /*
* call-seq: * call-seq:
if (!OBJ_TAINTED(obj) && rb_safe_level() >= 4)
rb_raise(rb_eSecurityError, "Insecure: can't modify regexp");
* mtch.select([index]*) => array * mtch.select([index]*) => array
* *
* Uses each <i>index</i> to access the matching values, returning an array of * Uses each <i>index</i> 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); 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->ptr) onig_free(re->ptr);
if (re->str) free(re->str); if (re->str) free(re->str);
re->ptr = 0; re->ptr = 0;
@ -1459,6 +1467,7 @@ rb_reg_initialize(VALUE obj, const char *s, long len,
if (options & ARG_KCODE_MASK) { if (options & ARG_KCODE_MASK) {
kcode_reset_option(); kcode_reset_option();
} }
if (ce) FL_SET(obj, REG_LITERAL);
} }
static VALUE static VALUE
@ -1760,7 +1769,6 @@ rb_reg_initialize_m(int argc, VALUE *argv, VALUE self)
long len; long len;
int flags = 0; int flags = 0;
rb_check_frozen(self);
if (argc == 0 || argc > 3) { if (argc == 0 || argc > 3) {
rb_raise(rb_eArgError, "wrong number of arguments"); rb_raise(rb_eArgError, "wrong number of arguments");
} }

View file

@ -276,8 +276,8 @@ onig_snprintf_with_pattern(buf, bufsize, enc, pat, pat_end, fmt, va_alist)
UChar bs[6]; UChar bs[6];
va_list args; va_list args;
va_init_list(args, (char* )fmt); va_init_list(args, (const char* )fmt);
n = vsnprintf((char* )buf, bufsize, (char* )fmt, args); n = vsnprintf((char* )buf, bufsize, (const char* )fmt, args);
va_end(args); va_end(args);
need = (pat_end - pat) * 4 + 4; need = (pat_end - pat) * 4 + 4;

View file

@ -4487,11 +4487,11 @@ parse_effect(Node** np, OnigToken* tok, int term, UChar** src, UChar* end,
return 0; return 0;
} }
static char* PopularQStr[] = { static const char* PopularQStr[] = {
"?", "*", "+", "??", "*?", "+?" "?", "*", "+", "??", "*?", "+?"
}; };
static char* ReduceQStr[] = { static const char* ReduceQStr[] = {
"", "", "*", "*?", "??", "+ and ??", "+? and ?" "", "", "*", "*?", "??", "+ and ??", "+? and ?"
}; };

5
ruby.1
View file

@ -309,9 +309,10 @@ this switch, unless you are going to debug the Ruby interpreter.
.Sh ENVIRONMENT .Sh ENVIRONMENT
.Bl -tag -width "RUBYLIB_PREFIX" -compact .Bl -tag -width "RUBYLIB_PREFIX" -compact
.It Ev RUBYLIB .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 library load path
.Pf ( Li "$:" ) . .Pf ( Li "$:" ) . Directories from this environment variable are searched
before the standard load path is searched.
.Pp .Pp
e.g.: e.g.:
.Dl RUBYLIB="$HOME/lib/ruby:$HOME/lib/rubyext" .Dl RUBYLIB="$HOME/lib/ruby:$HOME/lib/rubyext"

4
ruby.c
View file

@ -73,7 +73,7 @@ usage(const char *name)
/* This message really ought to be max 23 lines. /* This message really ought to be max 23 lines.
* Removed -h because the user already knows that option. Others? */ * 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)", "-0[octal] specify record separator (\\0, if no argument)",
"-a autosplit mode with -n or -p (splits $_ into $F)", "-a autosplit mode with -n or -p (splits $_ into $F)",
"-c check syntax only", "-c check syntax only",
@ -99,7 +99,7 @@ usage(const char *name)
"--version print the version", "--version print the version",
NULL NULL
}; };
char **p = usage_msg; const char **p = usage_msg;
printf("Usage: %s [switches] [--] [programfile] [arguments]\n", name); printf("Usage: %s [switches] [--] [programfile] [arguments]\n", name);
while (*p) while (*p)

3
ruby.h
View file

@ -547,7 +547,7 @@ void rb_gc_register_address(VALUE*);
void rb_gc_unregister_address(VALUE*); void rb_gc_unregister_address(VALUE*);
ID rb_intern(const char*); ID rb_intern(const char*);
char *rb_id2name(ID); const char *rb_id2name(ID);
ID rb_to_id(VALUE); ID rb_to_id(VALUE);
char *rb_class2name(VALUE); char *rb_class2name(VALUE);
@ -629,6 +629,7 @@ RUBY_EXTERN VALUE rb_mGC;
RUBY_EXTERN VALUE rb_mMath; RUBY_EXTERN VALUE rb_mMath;
RUBY_EXTERN VALUE rb_mProcess; RUBY_EXTERN VALUE rb_mProcess;
RUBY_EXTERN VALUE rb_cBasicObject;
RUBY_EXTERN VALUE rb_cObject; RUBY_EXTERN VALUE rb_cObject;
RUBY_EXTERN VALUE rb_cArray; RUBY_EXTERN VALUE rb_cArray;
RUBY_EXTERN VALUE rb_cValues; RUBY_EXTERN VALUE rb_cValues;

View file

@ -54,13 +54,13 @@ a = [*[]]; test_ok(a == [])
a = [*[1]]; test_ok(a == [1]) a = [*[1]]; test_ok(a == [1])
a = [*[1,2]]; test_ok(a == [1,2]) a = [*[1,2]]; test_ok(a == [1,2])
a = *[]; test_ok(a == nil) a = *[]; test_ok(a == [])
a = *[1]; test_ok(a == 1) a = *[1]; test_ok(a == [1])
a = *[nil]; test_ok(a == nil) a = *[nil]; test_ok(a == [nil])
a = *[[]]; test_ok(a == []) a = *[[]]; test_ok(a == [[]])
a = *[1,2]; test_ok(a == [1,2]) a = *[1,2]; test_ok(a == [1,2])
a = *[*[]]; test_ok(a == nil) a = *[*[]]; test_ok(a == [])
a = *[*[1]]; test_ok(a == 1) a = *[*[1]]; test_ok(a == [1])
a = *[*[1,2]]; test_ok(a == [1,2]) a = *[*[1,2]]; test_ok(a == [1,2])
a, = nil; test_ok(a == nil) a, = nil; test_ok(a == nil)
@ -87,14 +87,14 @@ a, = *[*[1,2]]; test_ok(a == 1)
*a = nil; test_ok(a == [nil]) *a = nil; test_ok(a == [nil])
*a = 1; test_ok(a == [1]) *a = 1; test_ok(a == [1])
*a = []; test_ok(a == [[]]) *a = []; test_ok(a == [])
*a = [1]; test_ok(a == [[1]]) *a = [1]; test_ok(a == [1])
*a = [nil]; test_ok(a == [[nil]]) *a = [nil]; test_ok(a == [nil])
*a = [[]]; test_ok(a == [[[]]]) *a = [[]]; test_ok(a == [[]])
*a = [1,2]; test_ok(a == [[1,2]]) *a = [1,2]; test_ok(a == [1,2])
*a = [*[]]; test_ok(a == [[]]) *a = [*[]]; test_ok(a == [])
*a = [*[1]]; test_ok(a == [[1]]) *a = [*[1]]; test_ok(a == [1])
*a = [*[1,2]]; test_ok(a == [[1,2]]) *a = [*[1,2]]; test_ok(a == [1,2])
*a = *[]; test_ok(a == []) *a = *[]; test_ok(a == [])
*a = *[1]; test_ok(a == [1]) *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 nil; end; f {|a| test_ok(a == nil)}
def f; yield 1; end; f {|a| test_ok(a == 1)} def f; yield 1; end; f {|a| test_ok(a == 1)}
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 [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 *[1]; end; f {|a| test_ok(a == 1)} 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 *[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 *[*[]]; end; f {|a| test_ok(a == nil)}
def f; yield *[*[1]]; end; f {|a| test_ok(a == 1)} 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; end; f {|a,| test_ok(a == nil)}
def f; yield nil; 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; end; f {|*a| test_ok(a == [])}
def f; yield nil; end; f {|*a| test_ok(a == [nil])} 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 1; end; f {|*a| test_ok(a == [1])}
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]; end; f {|*a| test_ok(a == [1])}
def f; yield [nil]; end; f {|*a| test_ok(a == [[nil]])} 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,2]; end; f {|*a| test_ok(a == [[1,2]])} 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 [*[]]; end; f {|*a| test_ok(a == [])}
def f; yield [*[1]]; end; f {|*a| test_ok(a == [[1]])} 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 [*[1,2]]; end; f {|*a| test_ok(a == [1,2])}
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]; 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]]; 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 == nil) def r; return *[]; end; a = r(); test_ok(a == [])
def r; return *[1]; end; a = r(); test_ok(a == 1) 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 *[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 *[*[]]; 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 *[*[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 == 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 *[*[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 == [nil])
def r; return nil; 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 1; end; *a = r(); test_ok(a == [1])
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]; end; *a = r(); test_ok(a == [1])
def r; return [nil]; end; *a = r(); test_ok(a == [[nil]]) 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,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]]; end; *a = r(); test_ok(a == [[1]]) 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 == [nil]) def r; return *[]; end; *a = r(); test_ok(a == [])
def r; return *[1]; end; *a = r(); test_ok(a == [1]) 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 *[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,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 == [nil]) def r; return *[*[]]; end; *a = r(); test_ok(a == [])
def r; return *[*[1]]; end; *a = r(); test_ok(a == [1]) 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])
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 *[]; 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 *[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 *[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 *[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 *[*[]]; 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 *[*[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]]; 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 == nil) a = loop do break *[]; end; test_ok(a == [])
a = loop do break *[1]; end; test_ok(a == 1) a = loop do break *[1]; end; test_ok(a == [1])
a = loop do break *[nil]; end; test_ok(a == nil) 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 *[*[]]; 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 *[*[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 == [nil]) *a = loop do break; end; test_ok(a == [nil])
*a = loop do break nil; 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 1; end; test_ok(a == [1])
*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]; end; test_ok(a == [1])
*a = loop do break [nil]; end; test_ok(a == [[nil]]) *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,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]]; end; test_ok(a == [[1]]) *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 == [nil]) *a = loop do break *[]; end; test_ok(a == [])
*a = loop do break *[1]; end; test_ok(a == [1]) *a = loop do break *[1]; end; test_ok(a == [1])
*a = loop do break *[nil]; end; test_ok(a == [nil]) *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,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 == [nil]) *a = loop do break *[*[]]; end; test_ok(a == [])
*a = loop do break *[*[1]]; end; test_ok(a == [1]) *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])
*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 *[]; 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 *[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 *[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 *[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 *[*[]]; 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 *[*[1]]; end; test_ok([a,b,c] == [1,nil,[]])
@ -382,29 +377,29 @@ r([]){next [*[]]}
r([1]){next [*[1]]} r([1]){next [*[1]]}
r([1,2]){next [*[1,2]]} r([1,2]){next [*[1,2]]}
r(nil){next *[]} r([]){next *[]}
r(1){next *[1]} r([1]){next *[1]}
r(nil){next *[nil]} r([nil]){next *[nil]}
r([]){next *[[]]} r([[]]){next *[[]]}
r(nil){next *[*[]]} r([]){next *[*[]]}
r(1){next *[*[1]]} r([1]){next *[*[1]]}
r([1,2]){next *[*[1,2]]} r([1,2]){next *[*[1,2]]}
def r(val); *a = yield(); test_ok(a == val, 2); end def r(val); *a = yield(); test_ok(a == val, 2); end
r([nil]){next} r([nil]){next}
r([nil]){next nil} r([nil]){next nil}
r([1]){next 1} r([1]){next 1}
r([[]]){next []} r([]){next []}
r([[1]]){next [1]} r([1]){next [1]}
r([[nil]]){next [nil]} r([nil]){next [nil]}
r([[[]]]){next [[]]} r([[]]){next [[]]}
r([[1,2]]){next [1,2]} r([1,2]){next [1,2]}
r([[]]){next [*[]]} r([]){next [*[]]}
r([[1]]){next [*[1]]} r([1]){next [*[1]]}
r([[1,2]]){next [*[1,2]]} r([1,2]){next [*[1,2]]}
def r(val); *a = *yield(); test_ok(a == val, 2); end 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]}
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]]} r([1,2,[]]){next [*[1,2]]}
def r(val); a,b,*c = *yield(); test_ok([a,b,c] == val, 2); end 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]}
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([3]).each3 {|x| test_ok(x == 3)}
IterTest.new([4]).each4 {|x| test_ok(x == 4)} IterTest.new([4]).each4 {|x| test_ok(x == 4)}
IterTest.new([5]).each5 {|x| test_ok(x == 5)} 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([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]]).each0 {|x| test_ok(x == [0])} IterTest.new([[0]]).each0 {|x| test_ok(x == 0)}
IterTest.new([[1]]).each1 {|x| test_ok(x == [1])} IterTest.new([[1]]).each1 {|x| test_ok(x == 1)}
IterTest.new([[2]]).each2 {|x| test_ok(x == [[2]])} IterTest.new([[2]]).each2 {|x| test_ok(x == [2])}
IterTest.new([[3]]).each3 {|x| test_ok(x == 3)} IterTest.new([[3]]).each3 {|x| test_ok(x == 3)}
IterTest.new([[4]]).each4 {|x| test_ok(x == [4])} IterTest.new([[4]]).each4 {|x| test_ok(x == 4)}
IterTest.new([[5]]).each5 {|x| test_ok(x == [5])} 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([[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([[0,0]]).each0 {|*x| test_ok(x == [0,0])}
IterTest.new([[8,8]]).each8 {|x| test_ok(x == [8,8])} IterTest.new([[8,8]]).each8 {|*x| test_ok(x == [8])}
def m0(v) def m0(v)
v v
@ -1018,7 +1013,7 @@ end
block_test(NilClass) block_test(NilClass)
block_test(Proc){} block_test(Proc){}
def argument_test(state, proc, *args) def call_argument_test(state, proc, *args)
x = state x = state
begin begin
proc.call(*args) proc.call(*args)
@ -1028,27 +1023,43 @@ def argument_test(state, proc, *args)
test_ok(x,2) test_ok(x,2)
end end
argument_test(true, lambda{||}) def yield_argument_test(state, proc, *args)
argument_test(false, lambda{||}, 1) x = state
argument_test(true, lambda{|a,|}, 1) begin
argument_test(false, lambda{|a,|}) proc.yield(*args)
argument_test(false, lambda{|a,|}, 1,2) 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) def get_block(&block)
block block
end end
test_ok(Proc == get_block{}.class) test_ok(Proc == get_block{}.class)
argument_test(true, get_block{||}) yield_argument_test(true, get_block{||})
argument_test(true, get_block{||}, 1) yield_argument_test(true, get_block{||}, 1)
argument_test(true, get_block{|a,|}, 1) yield_argument_test(true, get_block{|a,|}, 1)
argument_test(true, get_block{|a,|}) yield_argument_test(true, get_block{|a,|})
argument_test(true, get_block{|a,|}, 1,2) yield_argument_test(true, get_block{|a,|}, 1,2)
argument_test(true, get_block(&lambda{||})) call_argument_test(true, get_block(&lambda{||}))
argument_test(false, get_block(&lambda{||}),1) call_argument_test(false, get_block(&lambda{||}),1)
argument_test(true, get_block(&lambda{|a,|}),1) call_argument_test(true, get_block(&lambda{|a,|}),1)
argument_test(false, get_block(&lambda{|a,|}),1,2) call_argument_test(false, get_block(&lambda{|a,|}),1,2)
blk = get_block{11} blk = get_block{11}
test_ok(blk.class == Proc) test_ok(blk.class == Proc)
@ -1062,8 +1073,8 @@ test_ok(lmd.to_proc.class == Proc)
test_ok(lmd.clone.call == 44) test_ok(lmd.clone.call == 44)
test_ok(get_block(&lmd).class == Proc) test_ok(get_block(&lmd).class == Proc)
test_ok(Proc.new{|a,| a}.call(1,2,3) == 1) test_ok(Proc.new{|a,| a}.yield(1,2,3) == 1)
argument_test(true, Proc.new{|a,|}, 1,2) 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{|&b| b.call(10)}.call {|x| x} == 10)
test_ok(Proc.new{|a,&b| b.call(a)}.call(12) {|x| x} == 12) 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 def test_return1
Proc.new { Proc.new {
return 55 return 55
}.call + 5 }.yield + 5
end end
test_ok(test_return1() == 55) test_ok(test_return1() == 55)
def test_return2 def test_return2
@ -1090,7 +1101,7 @@ end
def proc_return1 def proc_return1
proc_call{return 42}+1 proc_call{return 42}+1
end end
test_ok(proc_return1() == 42) test_ok(proc_return1() == 43)
def proc_return2 def proc_return2
proc_yield{return 42}+1 proc_yield{return 42}+1
end end
@ -1106,7 +1117,7 @@ def ljump_test(state, proc, *args)
test_ok(x,2) test_ok(x,2)
end end
ljump_test(false, get_block{break}) ljump_test(true, get_block{break})
ljump_test(true, lambda{break}) ljump_test(true, lambda{break})
def exit_value_test(&block) def exit_value_test(&block)
@ -1149,11 +1160,11 @@ def test_b2
block_get{break 21}.call block_get{break 21}.call
end end
end end
test_ok(test_b2() == 22) test_ok(test_b2() == 21)
def test_b3 def test_b3
ljump_rescue(33) do ljump_rescue(33) do
Proc.new{break 31}.call Proc.new{break 31}.yield
end end
end end
test_ok(test_b3() == 33) test_ok(test_b3() == 33)
@ -1169,7 +1180,7 @@ def test_b5
block_call(&b) block_call(&b)
end end
end end
test_ok(test_b5() == 55) test_ok(test_b5() == 54)
def test_b6 def test_b6
b = lambda{break 67} b = lambda{break 67}
@ -1188,7 +1199,7 @@ def test_b7
block_call(&b) block_call(&b)
end end
end end
test_ok(test_b7() == 77) test_ok(test_b7() == 78)
def util_b8(&block) def util_b8(&block)
block_call(&block) block_call(&block)
@ -1220,7 +1231,7 @@ test_ok(test_b10() == 100)
def test_b11 def test_b11
ljump_rescue(111) do ljump_rescue(111) do
loop do loop do
Proc.new{break 110}.call Proc.new{break 110}.yield
break 112 break 112
end end
end end
@ -1238,7 +1249,7 @@ test_ok(test_b12() == 122)
def test_b13 def test_b13
ljump_rescue(133) do ljump_rescue(133) do
while true while true
Proc.new{break 130}.call Proc.new{break 130}.yield
break 131 break 131
end end
end end
@ -1260,7 +1271,7 @@ end
test_ok(test_b15{|e| break 155 } == 155) test_ok(test_b15{|e| break 155 } == 155)
def marity_test(m) def marity_test(m)
method = self.method(m) method = method(m)
test_ok(method.arity == method.to_proc.arity, 2) test_ok(method.arity == method.to_proc.arity, 2)
end end
marity_test(:test_ok) marity_test(:test_ok)
@ -1421,7 +1432,6 @@ $good = true;
for i in 4000..4096 for i in 4000..4096
n1 = 1 << i; n1 = 1 << i;
if (n1**2-1) / (n1+1) != (n1-1) if (n1**2-1) / (n1+1) != (n1-1)
p i
$good = false $good = false
end end
end end
@ -1525,9 +1535,9 @@ test_ok($x.sub(/.*\.([^\.]+)$/, '<\&>') == "<a.gif>")
# character constants(assumes ASCII) # character constants(assumes ASCII)
test_ok("a"[0] == ?a) test_ok("a"[0] == ?a)
test_ok(?a == ?a) test_ok(?a == ?a)
test_ok(?\C-a == 1) test_ok(?\C-a == "\1")
test_ok(?\M-a == 225) test_ok(?\M-a == "\341")
test_ok(?\M-\C-a == 129) test_ok(?\M-\C-a == "\201")
test_ok("a".upcase![0] == ?A) test_ok("a".upcase![0] == ?A)
test_ok("A".downcase![0] == ?a) test_ok("A".downcase![0] == ?a)
test_ok("abc".tr!("a-z", "A-Z") == "ABC") test_ok("abc".tr!("a-z", "A-Z") == "ABC")
@ -1539,7 +1549,7 @@ $x = "abcdef"
$y = [ ?a, ?b, ?c, ?d, ?e, ?f ] $y = [ ?a, ?b, ?c, ?d, ?e, ?f ]
$bad = false $bad = false
$x.each_byte {|i| $x.each_byte {|i|
if i != $y.shift if i.chr != $y.shift
$bad = true $bad = true
break break
end end
@ -1927,7 +1937,7 @@ module M003; include M002; end
module M002; include M001; end module M002; include M001; end
module M003; include M002; end module M003; include M002; end
test_ok(M003.ancestors == [M003, M002, M001]) test_ok(M003.ancestors == [M003, M002, M001, M002])
test_check "marshal" test_check "marshal"
$x = [1,2,3,[4,5,"foo"],{1=>"bar"},2.5,fact(30)] $x = [1,2,3,[4,5,"foo"],{1=>"bar"},2.5,fact(30)]

View file

@ -226,7 +226,7 @@ rb_f_kill(int argc, VALUE *argv)
int negative = 0; int negative = 0;
int sig; int sig;
int i; int i;
char *s; const char *s;
rb_secure(2); rb_secure(2);
if (argc < 2) if (argc < 2)
@ -564,7 +564,7 @@ trap(struct trap_arg *arg)
sighandler_t func, oldfunc; sighandler_t func, oldfunc;
VALUE command, oldcmd; VALUE command, oldcmd;
int sig = -1; int sig = -1;
char *s; const char *s;
func = sighandler; func = sighandler;
if (NIL_P(arg->cmd)) { if (NIL_P(arg->cmd)) {
@ -630,7 +630,7 @@ trap(struct trap_arg *arg)
rb_raise(rb_eArgError, "unsupported signal SIG%s", s); 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); rb_raise(rb_eArgError, "invalid signal number (%d)", sig);
} }
#if defined(HAVE_SETITIMER) #if defined(HAVE_SETITIMER)

View file

@ -394,7 +394,15 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
VALUE val = GETARG(); VALUE val = GETARG();
char c; char c;
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; c = NUM2INT(val) & 0xff;
}
if (!(flags & FWIDTH)) { if (!(flags & FWIDTH)) {
PUSH(&c, 1); PUSH(&c, 1);
} }

115
st.c
View file

@ -490,42 +490,97 @@ st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)
return 0; 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 <Landon Curt Noll> /\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 <Landon Curt Noll> /\../\
*
* 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 static int
strhash(register const char *string) strhash(register const char *string)
{ {
register int c; register int hval = FNV1_32A_INIT;
#ifdef HASH_ELFHASH /*
register unsigned int h = 0, g; * FNV-1a hash each octet in the buffer
*/
while (*string) {
/* xor the bottom with the current octet */
hval ^= (int)*string++;
while ((c = *string++) != '\0') { /* multiply by the 32 bit FNV magic prime mod 2^32 */
h = ( h << 4 ) + c; hval *= FNV_32_PRIME;
if ( g = h & 0xF0000000 )
h ^= g >> 24;
h &= ~g;
} }
return h; return hval;
#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;
while ((c = *string++) != '\0') {
val = val*997 + c;
}
return val + (val>>5);
#endif
} }
static int static int

162
string.c
View file

@ -765,39 +765,103 @@ rb_str_concat(VALUE str1, VALUE str2)
return str1; 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 <Landon Curt Noll> /\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 <Landon Curt Noll> /\../\
*
* 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 int
rb_str_hash(VALUE str) rb_str_hash(VALUE str)
{ {
register long len = RSTRING(str)->len; register long len = RSTRING(str)->len;
register char *p = RSTRING(str)->ptr; register char *p = RSTRING(str)->ptr;
register int key = 0; register int hval = FNV1_32A_INIT;
#ifdef HASH_ELFHASH /*
register unsigned int g; * FNV-1a hash each octet in the buffer
*/
while (len--) {
/* xor the bottom with the current octet */
hval ^= (int)*p++;
while (len--) { /* multiply by the 32 bit FNV magic prime mod 2^32 */
key = (key << 4) + *p++; #if defined(FNV_GCC_OPTIMIZATION)
if (g = key & 0xF0000000) hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
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);
#else #else
while (len--) { hval *= FNV_32_PRIME;
key = key*65599 + *p;
p++;
}
key = key + (key>>5);
#endif #endif
return key; }
return hval;
} }
/* /*
@ -810,8 +874,8 @@ rb_str_hash(VALUE str)
static VALUE static VALUE
rb_str_hash_m(VALUE str) rb_str_hash_m(VALUE str)
{ {
int key = rb_str_hash(str); int hval = rb_str_hash(str);
return INT2FIX(key); return INT2FIX(hval);
} }
#define lesser(a,b) (((a)>(b))?(b):(a)) #define lesser(a,b) (((a)>(b))?(b):(a))
@ -1414,13 +1478,7 @@ rb_str_aref(VALUE str, VALUE indx)
idx = FIX2LONG(indx); idx = FIX2LONG(indx);
num_index: num_index:
if (idx < 0) { return rb_str_substr(str, idx, 1);
idx = RSTRING(str)->len + idx;
}
if (idx < 0 || RSTRING(str)->len <= idx) {
return Qnil;
}
return INT2FIX(RSTRING(str)->ptr[idx] & 0xff);
case T_REGEXP: case T_REGEXP:
return rb_str_subpat(str, indx, 0); return rb_str_subpat(str, indx, 0);
@ -1456,21 +1514,21 @@ rb_str_aref(VALUE str, VALUE indx)
/* /*
* call-seq: * call-seq:
* str[fixnum] => fixnum or nil * str[fixnum] => new_str or nil
* str[fixnum, fixnum] => new_str or nil * str[fixnum, fixnum] => new_str or nil
* str[range] => new_str or nil * str[range] => new_str or nil
* str[regexp] => new_str or nil * str[regexp] => new_str or nil
* str[regexp, fixnum] => new_str or nil * str[regexp, fixnum] => new_str or nil
* str[other_str] => 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(fixnum, fixnum) => new_str or nil
* str.slice(range) => new_str or nil * str.slice(range) => new_str or nil
* str.slice(regexp) => new_str or nil * str.slice(regexp) => new_str or nil
* str.slice(regexp, fixnum) => new_str or nil * str.slice(regexp, fixnum) => new_str or nil
* str.slice(other_str) => new_str or nil * str.slice(other_str) => new_str or nil
* *
* Element Reference---If passed a single <code>Fixnum</code>, returns the code * Element Reference---If passed a single <code>Fixnum</code>, returns a
* of the character at that position. If passed two <code>Fixnum</code> * substring of one character at that position. If passed two <code>Fixnum</code>
* objects, returns a substring starting at the offset given by the first, and * 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 * 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 * 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. * match.
* *
* a = "hello there" * a = "hello there"
* a[1] #=> 101 * a[1] #=> "e"
* a[1,3] #=> "ell" * a[1,3] #=> "ell"
* a[1..3] #=> "ell" * a[1..3] #=> "ell"
* a[-3,2] #=> "er" * a[-3,2] #=> "er"
@ -1615,17 +1673,7 @@ rb_str_aset(VALUE str, VALUE indx, VALUE val)
goto out_of_range; goto out_of_range;
idx += RSTRING(str)->len; 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; return val;
case T_REGEXP: case T_REGEXP:
@ -1656,7 +1704,6 @@ rb_str_aset(VALUE str, VALUE indx, VALUE val)
/* /*
* call-seq: * call-seq:
* str[fixnum] = fixnum
* str[fixnum] = new_str * str[fixnum] = new_str
* str[fixnum, fixnum] = new_str * str[fixnum, fixnum] = new_str
* str[range] = aString * str[range] = aString
@ -2158,6 +2205,22 @@ rb_str_clear(VALUE str)
return 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: * call-seq:
* str.reverse! => str * 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, "rindex", rb_str_rindex_m, -1);
rb_define_method(rb_cString, "replace", rb_str_replace, 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, "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_i", rb_str_to_i, -1);
rb_define_method(rb_cString, "to_f", rb_str_to_f, 0); rb_define_method(rb_cString, "to_f", rb_str_to_f, 0);

View file

@ -451,7 +451,7 @@ inspect_struct(VALUE s, VALUE dummy, int recur)
for (i=0; i<RSTRUCT_LEN(s); i++) { for (i=0; i<RSTRUCT_LEN(s); i++) {
VALUE slot; VALUE slot;
ID id; ID id;
char *p; const char *p;
if (i > 0) { if (i > 0) {
rb_str_cat2(str, ", "); rb_str_cat2(str, ", ");

View file

@ -29,25 +29,25 @@ class TestAssignment < Test::Unit::TestCase
a = [*[1]]; assert_equal([1], a) a = [*[1]]; assert_equal([1], a)
a = [*[1,2]]; assert_equal([1,2], a) a = [*[1,2]]; assert_equal([1,2], a)
a = *[]; assert_nil(a) a = *[]; assert_equal([], a)
a = *[1]; assert_equal(1, a) a = *[1]; assert_equal([1], a)
a = *[nil]; assert_nil(a) a = *[nil]; assert_equal([nil], a)
a = *[[]]; assert_equal([], a) a = *[[]]; assert_equal([[]], a)
a = *[1,2]; assert_equal([1,2], a) a = *[1,2]; assert_equal([1,2], a)
a = *[*[]]; assert_nil(a) a = *[*[]]; assert_equal([], a)
a = *[*[1]]; assert_equal(1, a) a = *[*[1]]; assert_equal([1], a)
a = *[*[1,2]]; assert_equal([1,2], a) a = *[*[1,2]]; assert_equal([1,2], a)
*a = nil; assert_equal([nil], a) *a = nil; assert_equal([nil], a)
*a = 1; assert_equal([1], a) *a = 1; assert_equal([1], a)
*a = []; assert_equal([[]], a) *a = []; assert_equal([], a)
*a = [1]; assert_equal([[1]], a) *a = [1]; assert_equal([1], a)
*a = [nil]; assert_equal([[nil]], a) *a = [nil]; assert_equal([nil], a)
*a = [[]]; assert_equal([[[]]], a) *a = [[]]; assert_equal([[]], a)
*a = [1,2]; assert_equal([[1,2]], a) *a = [1,2]; assert_equal([1,2], a)
*a = [*[]]; assert_equal([[]], a) *a = [*[]]; assert_equal([], a)
*a = [*[1]]; assert_equal([[1]], a) *a = [*[1]]; assert_equal([1], a)
*a = [*[1,2]]; assert_equal([[1,2]], a) *a = [*[1,2]]; assert_equal([1,2], a)
*a = *[]; assert_equal([], a) *a = *[]; assert_equal([], a)
*a = *[1]; assert_equal([1], a) *a = *[1]; assert_equal([1], a)
@ -82,13 +82,13 @@ class TestAssignment < Test::Unit::TestCase
def test_yield def test_yield
def f; yield(nil); end; f {|a| assert_nil(a)}; undef f 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(1); end; f {|a| assert_equal(1, 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]); 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([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([*[]]); 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]]); 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([*[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(*[1]); end; f {|a| assert_equal(1, a)}; undef f
def f; yield(*[nil]); end; f {|a| assert_nil(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; end; f {|*a| assert_equal([], a)}; undef f
def f; yield(nil); end; f {|*a| assert_equal([nil], 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(1); end; f {|*a| assert_equal([1], 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]); 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([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,2]); end; f {|*a| assert_equal([[1,2]], 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([*[]]); 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]]); 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([*[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(*[]); 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]); 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]]; 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_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 *[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 *[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 *[*[]]; end; a = r(); assert_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 *[*[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_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 *[*[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([nil], a); undef r
def r; return nil; 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 1; end; *a = r(); assert_equal([1], 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]; 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 [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,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]]; end; *a = r(); assert_equal([[1]], 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([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 *[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 *[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,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([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 *[*[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
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 *[]; 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 *[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 *[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 *[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 *[*[]]; 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 *[*[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]]; 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_nil(a) a = loop do break *[]; end; assert_equal([], a)
a = loop do break *[1]; end; assert_equal(1, a) a = loop do break *[1]; end; assert_equal([1], a)
a = loop do break *[nil]; end; assert_nil(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 *[*[]]; end; assert_nil(a) a = loop do break *[*[]]; end; assert_equal([], a)
a = loop do break *[*[1]]; end; assert_equal(1, 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([nil], a) *a = loop do break; end; assert_equal([nil], a)
*a = loop do break nil; 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 1; end; assert_equal([1], 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]; end; assert_equal([1], a)
*a = loop do break [nil]; end; assert_equal([[nil]], 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,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]]; end; assert_equal([[1]], 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([nil], a) *a = loop do break *[]; end; assert_equal([], a)
*a = loop do break *[1]; end; assert_equal([1], 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 *[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,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([nil], a) *a = loop do break *[*[]]; end; assert_equal([], a)
*a = loop do break *[*[1]]; end; assert_equal([1], 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)
*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 *[]; 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 *[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 *[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 *[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 *[*[]]; 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 *[*[1]]; end; assert_equal([1,nil,[]], [a,b,c])
@ -328,12 +328,12 @@ class TestAssignment < Test::Unit::TestCase
r([1]){next [*[1]]} r([1]){next [*[1]]}
r([1,2]){next [*[1,2]]} r([1,2]){next [*[1,2]]}
r(nil){next *[]} r([]){next *[]}
r(1){next *[1]} r([1]){next *[1]}
r(nil){next *[nil]} r([nil]){next *[nil]}
r([]){next *[[]]} r([[]]){next *[[]]}
r(nil){next *[*[]]} r([]){next *[*[]]}
r(1){next *[*[1]]} r([1]){next *[*[1]]}
r([1,2]){next *[*[1,2]]} r([1,2]){next *[*[1,2]]}
undef r undef r
@ -341,18 +341,18 @@ class TestAssignment < Test::Unit::TestCase
r([nil]){next} r([nil]){next}
r([nil]){next nil} r([nil]){next nil}
r([1]){next 1} r([1]){next 1}
r([[]]){next []} r([]){next []}
r([[1]]){next [1]} r([1]){next [1]}
r([[nil]]){next [nil]} r([nil]){next [nil]}
r([[[]]]){next [[]]} r([[]]){next [[]]}
r([[1,2]]){next [1,2]} r([1,2]){next [1,2]}
r([[]]){next [*[]]} r([]){next [*[]]}
r([[1]]){next [*[1]]} r([1]){next [*[1]]}
r([[1,2]]){next [*[1,2]]} r([1,2]){next [*[1,2]]}
undef r undef r
def r(val); *a = *yield(); assert_equal(val, a); end 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]}
r([1,2]){next *[*[1,2]]} r([1,2]){next *[*[1,2]]}
undef r undef r
@ -372,7 +372,7 @@ class TestAssignment < Test::Unit::TestCase
undef r undef r
def r(val); a,b,*c = *yield(); assert_equal(val, [a,b,c]); end 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]}
r([1,2,[]]){next *[*[1,2]]} r([1,2,[]]){next *[*[1,2]]}
undef r undef r

View file

@ -23,6 +23,6 @@ class TestClone < Test::Unit::TestCase
assert_raises(NoMethodError) {foo.test2} assert_raises(NoMethodError) {foo.test2}
assert_equal([M003, M002, M001], M003.ancestors) assert_equal([M003, M002, M001, M002], M003.ancestors)
end end
end end

View file

@ -31,9 +31,9 @@ class TestDir < Test::Unit::TestCase
break unless name = dir.read break unless name = dir.read
cache << [pos, name] cache << [pos, name]
end end
for x in cache.sort_by {|x| x[0] % 3 } # shuffle for x,y in cache.sort_by {|x| x[0] % 3 } # shuffle
dir.seek(x[0]) dir.seek(x)
assert_equal(x[1], dir.read) assert_equal(y, dir.read)
end end
ensure ensure
dir.close dir.close

View file

@ -88,7 +88,7 @@ class TestFile < Test::Unit::TestCase
assert_nil(f.getc) assert_nil(f.getc)
open(f.path, "w") {|g| g.print "a" } open(f.path, "w") {|g| g.print "a" }
result = [] result = []
f.each_byte {|b| result << b } f.each_byte {|b| result << b.chr }
assert_equal([?a], result) assert_equal([?a], result)
end end

View file

@ -87,4 +87,32 @@ class TestFloat < Test::Unit::TestCase
assert_raise(ArgumentError){Float("1e")} assert_raise(ArgumentError){Float("1e")}
# add expected behaviour here. # add expected behaviour here.
end 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 end

View file

@ -151,21 +151,21 @@ class TestIterator < Test::Unit::TestCase
IterTest.new([2]).each2 {|x| assert_equal([2], x)} IterTest.new([2]).each2 {|x| assert_equal([2], x)}
IterTest.new([4]).each4 {|x| assert_equal(4, x)} IterTest.new([4]).each4 {|x| assert_equal(4, x)}
IterTest.new([5]).each5 {|x| assert_equal(5, 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([8]).each8 {|x| assert_equal(8, x)}
IterTest.new([[0]]).each0 {|x| assert_equal([0], x)} IterTest.new([[0]]).each0 {|x| assert_equal(0, x)}
IterTest.new([[1]]).each1 {|x| assert_equal([1], x)} IterTest.new([[1]]).each1 {|x| assert_equal(1, x)}
IterTest.new([[2]]).each2 {|x| assert_equal([[2]], x)} IterTest.new([[2]]).each2 {|x| assert_equal([2], x)}
IterTest.new([[3]]).each3 {|x| assert_equal(3, x)} IterTest.new([[3]]).each3 {|x| assert_equal(3, x)}
IterTest.new([[4]]).each4 {|x| assert_equal([4], x)} IterTest.new([[4]]).each4 {|x| assert_equal(4, x)}
IterTest.new([[5]]).each5 {|x| assert_equal([5], 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([[7]]).each7 {|x| assert_equal(7, 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([[0,0]]).each0 {|*x| assert_equal([0,0], x)}
IterTest.new([[8,8]]).each8 {|x| assert_equal([8,8], x)} IterTest.new([[8,8]]).each8 {|*x| assert_equal([8], x)}
end end
def m(var) def m(var)
@ -346,10 +346,10 @@ class TestIterator < Test::Unit::TestCase
end end
def foo def foo
yield([:key, :value]) yield(:key, :value)
end end
def bar(&blk) def bar(&blk)
blk.call([:key, :value]) blk.call(:key, :value)
end end
def test_yield_vs_call def test_yield_vs_call
@ -359,14 +359,14 @@ class TestIterator < Test::Unit::TestCase
class H class H
def each def each
yield [:key, :value] yield :key, :value
end end
end end
def test_assoc_yield def test_assoc_yield
[{:key=>:value}, H.new].each {|h| [{:key=>:value}, H.new].each {|h|
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{|*a| assert_equal([:key, :value], a)}
h.each{|k,v| assert_equal([:key, :value], [k,v])} h.each{|k,v| assert_equal([:key, :value], [k,v])}
} }
end end

View file

@ -68,9 +68,9 @@ END
# character constants(assumes ASCII) # character constants(assumes ASCII)
assert_equal(?a, "a"[0]) assert_equal(?a, "a"[0])
assert_equal(?a, ?a) assert_equal(?a, ?a)
assert_equal(1, ?\C-a) assert_equal("\1", ?\C-a)
assert_equal(225, ?\M-a) assert_equal("\341", ?\M-a)
assert_equal(129, ?\M-\C-a) assert_equal("\201", ?\M-\C-a)
assert_equal(?A, "a".upcase![0]) assert_equal(?A, "a".upcase![0])
assert_equal(?a, "A".downcase![0]) assert_equal(?a, "A".downcase![0])
assert_equal("ABC", "abc".tr!("a-z", "A-Z")) assert_equal("ABC", "abc".tr!("a-z", "A-Z"))
@ -82,7 +82,7 @@ END
$y = [ ?a, ?b, ?c, ?d, ?e, ?f ] $y = [ ?a, ?b, ?c, ?d, ?e, ?f ]
$bad = false $bad = false
$x.each_byte {|i| $x.each_byte {|i|
if i != $y.shift if i.chr != $y.shift
$bad = true $bad = true
break break
end end

6
time.c
View file

@ -157,7 +157,7 @@ static struct timeval
time_timeval(VALUE time, int interval) time_timeval(VALUE time, int interval)
{ {
struct timeval t; struct timeval t;
char *tstr = interval ? "time interval" : "time"; const char *tstr = interval ? "time interval" : "time";
#ifndef NEGATIVE_TIME_T #ifndef NEGATIVE_TIME_T
interval = 1; interval = 1;
@ -182,7 +182,7 @@ time_timeval(VALUE time, int interval)
if (f != t.tv_sec) { if (f != t.tv_sec) {
rb_raise(rb_eRangeError, "%f out of Time range", RFLOAT(time)->value); 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; break;
@ -1229,7 +1229,7 @@ time_add(struct time_object *tobj, VALUE offset, int sign)
if (f != (double)sec_off) if (f != (double)sec_off)
rb_raise(rb_eRangeError, "time %s %f out of Time range", rb_raise(rb_eRangeError, "time %s %f out of Time range",
sign < 0 ? "-" : "+", v); sign < 0 ? "-" : "+", v);
usec_off = (time_t)(d*1e6); usec_off = (time_t)(d*1e6+0.5);
if (sign < 0) { if (sign < 0) {
sec = tobj->tv.tv_sec - sec_off; sec = tobj->tv.tv_sec - sec_off;

86
util.c
View file

@ -15,6 +15,8 @@
#include <ctype.h> #include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <math.h>
#include <float.h>
#ifdef _WIN32 #ifdef _WIN32
#include "missing/file.h" #include "missing/file.h"
@ -664,11 +666,9 @@ ruby_getcwd(void)
* *
*/ */
#define TRUE 1 #define MDMINEXPT DBL_MIN_EXP
#define FALSE 0 #define MDMAXEXPT DBL_MAX_EXP
static int MDMINEXPT = -323;
static int MDMAXEXPT = 309;
static double powersOf10[] = { /* Table giving binary powers of 10. Entry */ static double powersOf10[] = { /* Table giving binary powers of 10. Entry */
10.0, /* is 10^2^i. Used to convert decimal */ 10.0, /* is 10^2^i. Used to convert decimal */
100.0, /* exponents into floating-point numbers. */ 100.0, /* exponents into floating-point numbers. */
@ -720,8 +720,8 @@ ruby_strtod(
char **endPtr) /* If non-NULL, store terminating character's char **endPtr) /* If non-NULL, store terminating character's
* address here. */ * address here. */
{ {
int sign, expSign = FALSE; int sign, expSign = Qfalse;
double fraction, dblExp, *d; double fraction = 0.0, dblExp, *d;
register const char *p; register const char *p;
register int c; register int c;
int exp = 0; /* Exponent read from "EX" field. */ int exp = 0; /* Exponent read from "EX" field. */
@ -735,8 +735,8 @@ ruby_strtod(
* case, fracExp is incremented one for each * case, fracExp is incremented one for each
* dropped digit. */ * dropped digit. */
int mantSize = 0; /* Number of digits in mantissa. */ int mantSize = 0; /* Number of digits in mantissa. */
int hasPoint = FALSE; /* Decimal point exists. */ int hasPoint = Qfalse; /* Decimal point exists. */
int hasDigit = FALSE; /* I or F exists. */ int hasDigit = Qfalse; /* I or F exists. */
const char *pMant; /* Temporarily holds location of mantissa const char *pMant; /* Temporarily holds location of mantissa
* in string. */ * in string. */
const char *pExp; /* Temporarily holds location of exponent const char *pExp; /* Temporarily holds location of exponent
@ -748,44 +748,43 @@ ruby_strtod(
errno = 0; errno = 0;
p = string; p = string;
while (ISSPACE(*p)) { while (ISSPACE(*p)) p++;
p += 1;
}
if (*p == '-') { if (*p == '-') {
sign = TRUE; sign = Qtrue;
p += 1; p++;
} }
else { else {
if (*p == '+') { if (*p == '+') p++;
p += 1; sign = Qfalse;
}
sign = FALSE;
} }
fraction = 0.;
exp = 0;
/* /*
* Count the number of digits in the mantissa * Count the number of digits in the mantissa
* and also locate the decimal point. * and also locate the decimal point.
*/ */
for ( ; c = *p; p += 1) { for ( ; c = *p; p++) {
if (!ISDIGIT(c)) { if (!ISDIGIT(c)) {
if (c != '.' || hasPoint) { if (c != '.' || hasPoint) {
break; break;
} }
hasPoint = TRUE; hasPoint = Qtrue;
} }
else { else {
if (hasPoint) { /* already in fractional part */ if (hasPoint) { /* already in fractional part */
fracExp -= 1; fracExp--;
} }
if (mantSize) { /* already in mantissa */ if (mantSize) { /* already in mantissa */
mantSize += 1; mantSize++;
} }
else if (c != '0') { /* have entered mantissa */ else if (c != '0') { /* have entered mantissa */
mantSize += 1; mantSize++;
pMant = p; pMant = p;
} }
hasDigit = TRUE; hasDigit = Qtrue;
} }
} }
@ -809,7 +808,7 @@ ruby_strtod(
p = string; p = string;
} }
else { else {
int frac1, frac2; double frac1, frac2;
frac1 = 0; frac1 = 0;
for ( ; mantSize > 9; mantSize -= 1) { for ( ; mantSize > 9; mantSize -= 1) {
c = *p; c = *p;
@ -837,21 +836,20 @@ ruby_strtod(
p = pExp; p = pExp;
if ((*p == 'E') || (*p == 'e')) { if ((*p == 'E') || (*p == 'e')) {
p += 1; p++;
if (*p == '-') { if (*p == '-') {
expSign = TRUE; expSign = Qtrue;
p += 1; p++;
} }
else { else {
if (*p == '+') { if (*p == '+') {
p += 1; p++;
} }
expSign = FALSE; expSign = Qfalse;
} }
if (ISDIGIT(*p)) { if (ISDIGIT(*p)) {
do { do {
exp = exp * 10 + (*p - '0'); exp = exp * 10 + (*p++ - '0');
p += 1;
} }
while (ISDIGIT(*p)); while (ISDIGIT(*p));
} }
@ -873,22 +871,22 @@ ruby_strtod(
* fraction. * fraction.
*/ */
if (exp >= MDMAXEXPT - 18) { if (exp >= MDMAXEXPT) {
exp = MDMAXEXPT;
errno = ERANGE; errno = ERANGE;
return HUGE_VAL * (sign ? -1.0 : 1.0);
} }
else if (exp < MDMINEXPT + 18) { else if (exp < MDMINEXPT) {
exp = MDMINEXPT;
errno = ERANGE; errno = ERANGE;
return 0.0 * (sign ? -1.0 : 1.0);
} }
fracExp = exp; fracExp = exp;
exp += 9; exp += 9;
if (exp < 0) { if (exp < 0) {
expSign = TRUE; expSign = Qtrue;
exp = -exp; exp = -exp;
} }
else { else {
expSign = FALSE; expSign = Qfalse;
} }
dblExp = 1.0; dblExp = 1.0;
for (d = powersOf10; exp != 0; exp >>= 1, d += 1) { for (d = powersOf10; exp != 0; exp >>= 1, d += 1) {
@ -897,18 +895,18 @@ ruby_strtod(
} }
} }
if (expSign) { if (expSign) {
fraction = frac1 / dblExp; frac1 /= dblExp;
} }
else { else {
fraction = frac1 * dblExp; frac1 *= dblExp;
} }
exp = fracExp; exp = fracExp;
if (exp < 0) { if (exp < 0) {
expSign = TRUE; expSign = Qtrue;
exp = -exp; exp = -exp;
} }
else { else {
expSign = FALSE; expSign = Qfalse;
} }
dblExp = 1.0; dblExp = 1.0;
for (d = powersOf10; exp != 0; exp >>= 1, d += 1) { for (d = powersOf10; exp != 0; exp >>= 1, d += 1) {
@ -917,17 +915,17 @@ ruby_strtod(
} }
} }
if (expSign) { if (expSign) {
fraction += frac2 / dblExp; frac2 /= dblExp;
} }
else { else {
fraction += frac2 * dblExp; frac2 *= dblExp;
} }
fraction = frac1 + frac2;
} }
if (endPtr != NULL) { if (endPtr != NULL) {
*endPtr = (char *)p; *endPtr = (char *)p;
} }
if (sign) { if (sign) {
return -fraction; return -fraction;
} }

View file

@ -186,7 +186,7 @@ rb_class_path(VALUE klass)
return path; return path;
} }
else { else {
char *s = "Class"; const char *s = "Class";
if (TYPE(klass) == T_MODULE) { if (TYPE(klass) == T_MODULE) {
if (rb_obj_class(klass) == rb_cModule) { if (rb_obj_class(klass) == rb_cModule) {
@ -711,7 +711,7 @@ rb_f_global_variables(void)
{ {
VALUE ary = rb_ary_new(); VALUE ary = rb_ary_new();
char buf[4]; char buf[4];
char *s = "&`'+123456789"; const char *s = "&`'+123456789";
st_foreach_safe(rb_global_tbl, gvar_i, ary); st_foreach_safe(rb_global_tbl, gvar_i, ary);
if (!NIL_P(rb_backref_get())) { 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; tmp = klass;
retry: retry:
while (tmp) { while (tmp && !NIL_P(tmp)) {
while (RCLASS(tmp)->iv_tbl && st_lookup(RCLASS(tmp)->iv_tbl,id,&value)) { while (RCLASS(tmp)->iv_tbl && st_lookup(RCLASS(tmp)->iv_tbl,id,&value)) {
if (value == Qundef) { if (value == Qundef) {
if (!RTEST(rb_autoload_load(tmp, id))) break; if (!RTEST(rb_autoload_load(tmp, id))) break;
@ -1510,7 +1510,7 @@ rb_const_defined_fallback(VALUE klass, ID id, NODE *fallback)
static void static void
mod_av_set(VALUE klass, ID id, VALUE val, int isconst) 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) if (!OBJ_TAINTED(klass) && rb_safe_level() >= 4)
rb_raise(rb_eSecurityError, "Insecure: can't set %s", dest); 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 void
rb_const_set(VALUE klass, ID id, VALUE val) 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); mod_av_set(klass, id, val, Qtrue);
} }