summaryrefslogtreecommitdiff
path: root/spec/ruby/library/tempfile/initialize_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/tempfile/initialize_spec.rb')
-rw-r--r--spec/ruby/library/tempfile/initialize_spec.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/ruby/library/tempfile/initialize_spec.rb b/spec/ruby/library/tempfile/initialize_spec.rb
new file mode 100644
index 0000000000..0e882a3f0c
--- /dev/null
+++ b/spec/ruby/library/tempfile/initialize_spec.rb
@@ -0,0 +1,46 @@
+require_relative '../../spec_helper'
+require 'tempfile'
+
+describe "Tempfile#initialize" do
+ before :each do
+ @tempfile = Tempfile.allocate
+ end
+
+ after :each do
+ @tempfile.close!
+ end
+
+ it "opens a new tempfile with the passed name in the passed directory" do
+ @tempfile.send(:initialize, "basename", tmp(""))
+ File.should.exist?(@tempfile.path)
+
+ tmpdir = tmp("")
+ path = @tempfile.path
+
+ platform_is :windows do
+ # on Windows, both types of slashes are OK,
+ # but the tmp helper always uses '/'
+ path.gsub!('\\', '/')
+ end
+
+ path[0, tmpdir.length].should == tmpdir
+ path.should.include?("basename")
+ end
+
+ platform_is_not :windows do
+ it "sets the permissions on the tempfile to 0600" do
+ @tempfile.send(:initialize, "basename", tmp(""))
+ File.stat(@tempfile.path).mode.should == 0100600
+ end
+ end
+
+ it "accepts encoding options" do
+ @tempfile.send(:initialize, ['shiftjis', 'yml'], encoding: 'SHIFT_JIS')
+ @tempfile.external_encoding.should == Encoding::Shift_JIS
+ end
+
+ it "does not try to modify the arguments" do
+ @tempfile.send(:initialize, ['frozen'.freeze, 'txt'.freeze], encoding: Encoding::IBM437)
+ @tempfile.external_encoding.should == Encoding::IBM437
+ end
+end
distruby.rb32
-rw-r--r--dln.c70
-rw-r--r--error.c16
-rw-r--r--eval.c625
-rw-r--r--ext/Win32API/Win32API.c2
-rw-r--r--ext/Win32API/lib/win32/registry.rb2
-rw-r--r--ext/Win32API/lib/win32/resolv.rb2
-rw-r--r--ext/bigdecimal/bigdecimal.c64
-rw-r--r--ext/bigdecimal/extconf.rb10
-rw-r--r--ext/curses/extconf.rb2
-rw-r--r--ext/digest/digest.c9
-rw-r--r--ext/digest/lib/digest.rb6
-rw-r--r--ext/dl/dl.c14
-rw-r--r--ext/dl/lib/dl/win32.rb2
-rw-r--r--ext/dl/ptr.c41
-rw-r--r--ext/dl/sym.c3
-rw-r--r--ext/extmk.rb83
-rw-r--r--ext/gdbm/gdbm.c26
-rw-r--r--ext/iconv/iconv.c43
-rw-r--r--ext/nkf/nkf-utf8/nkf.c8
-rw-r--r--ext/openssl/lib/net/ftptls.rb10
-rw-r--r--ext/openssl/lib/net/telnets.rb3
-rw-r--r--ext/openssl/lib/openssl/ssl.rb2
-rw-r--r--ext/openssl/openssl_missing.h4
-rw-r--r--ext/openssl/ossl.h6
-rw-r--r--ext/openssl/ossl_config.c5
-rw-r--r--ext/openssl/ossl_pkcs5.h6
-rw-r--r--ext/openssl/ossl_x509name.c4
-rw-r--r--ext/pty/lib/expect.rb2
-rw-r--r--ext/pty/pty.c5
-rw-r--r--ext/purelib.rb3
-rw-r--r--ext/readline/extconf.rb7
-rw-r--r--ext/readline/readline.c19
-rw-r--r--ext/sdbm/_sdbm.c2
-rw-r--r--ext/socket/extconf.rb13
-rw-r--r--ext/socket/getaddrinfo.c9
-rw-r--r--ext/socket/getnameinfo.c5
-rw-r--r--ext/socket/socket.c29
-rw-r--r--ext/stringio/stringio.c47
-rw-r--r--ext/syck/rubyext.c1
-rw-r--r--ext/syck/syck.h2
-rw-r--r--ext/syslog/syslog.c3
-rw-r--r--ext/thread/thread.c138
-rw-r--r--ext/tk/ChangeLog.tkextlib9
-rw-r--r--ext/tk/lib/tkextlib/blt.rb4
-rw-r--r--ext/tk/lib/tkextlib/blt/vector.rb12
-rw-r--r--ext/tk/lib/tkextlib/tcllib/tablelist.rb2
-rw-r--r--ext/tk/lib/tkextlib/tile/dialog.rb2
-rw-r--r--ext/tk/lib/tkextlib/version.rb2
-rw-r--r--ext/tk/tcltklib.c11
-rw-r--r--ext/win32ole/tests/testOLEEVENT.rb91
-rw-r--r--ext/win32ole/tests/testWIN32OLE.rb3
-rw-r--r--ext/win32ole/tests/test_win32ole_event.rb133
-rw-r--r--ext/win32ole/tests/testall.rb1
-rw-r--r--ext/win32ole/win32ole.c177
-rw-r--r--ext/zlib/extconf.rb4
-rw-r--r--ext/zlib/zlib.c15
-rw-r--r--file.c276
-rw-r--r--gc.c254
-rw-r--r--hash.c61
-rw-r--r--intern.h8
-rw-r--r--io.c87
-rw-r--r--lib/README2
-rw-r--r--lib/base64.rb2
-rw-r--r--lib/benchmark.rb7
-rw-r--r--lib/cgi.rb9
-rw-r--r--lib/cgi/session.rb22
-rw-r--r--lib/date.rb23
-rw-r--r--lib/date/format.rb4
-rw-r--r--lib/delegate.rb30
-rw-r--r--lib/drb/drb.rb1
-rw-r--r--lib/erb.rb57
-rw-r--r--lib/ipaddr.rb2
-rw-r--r--lib/irb.rb18
-rw-r--r--lib/logger.rb4
-rw-r--r--lib/matrix.rb2
-rw-r--r--lib/mkmf.rb36
-rw-r--r--lib/monitor.rb21
-rw-r--r--lib/net/ftp.rb19
-rw-r--r--lib/net/http.rb3
-rw-r--r--lib/net/imap.rb13
-rw-r--r--lib/net/pop.rb4
-rw-r--r--lib/net/smtp.rb11
-rw-r--r--lib/net/telnet.rb15
-rw-r--r--lib/open-uri.rb10
-rw-r--r--lib/optparse.rb18
-rw-r--r--lib/rdoc/options.rb4
-rw-r--r--lib/rdoc/parsers/parse_c.rb2
-rw-r--r--lib/rdoc/parsers/parse_rb.rb8
-rw-r--r--lib/resolv-replace.rb3
-rw-r--r--lib/resolv.rb276
-rw-r--r--lib/rexml/attribute.rb38
-rw-r--r--lib/rexml/cdata.rb21
-rw-r--r--lib/rexml/comment.rb4
-rw-r--r--lib/rexml/doctype.rb27
-rw-r--r--lib/rexml/document.rb113
-rw-r--r--lib/rexml/dtd/dtd.rb2
-rw-r--r--lib/rexml/element.rb2270
-rw-r--r--lib/rexml/encoding.rb13
-rw-r--r--lib/rexml/encodings/CP-1252.rb123
-rw-r--r--lib/rexml/encodings/ISO-8859-15.rb59
-rw-r--r--lib/rexml/encodings/SHIFT-JIS.rb4
-rw-r--r--lib/rexml/encodings/UTF-16.rb2
-rw-r--r--lib/rexml/entity.rb7
-rw-r--r--lib/rexml/formatters/default.rb109
-rw-r--r--lib/rexml/formatters/pretty.rb138
-rw-r--r--lib/rexml/formatters/transitive.rb56
-rw-r--r--lib/rexml/functions.rb1
-rw-r--r--lib/rexml/instruction.rb4
-rw-r--r--lib/rexml/node.rb19
-rw-r--r--lib/rexml/parsers/baseparser.rb66
-rw-r--r--lib/rexml/parsers/sax2parser.rb4
-rw-r--r--lib/rexml/parsers/treeparser.rb6
-rw-r--r--lib/rexml/parsers/xpathparser.rb2
-rw-r--r--lib/rexml/rexml.rb13
-rw-r--r--lib/rexml/source.rb363
-rw-r--r--lib/rexml/text.rb17
-rw-r--r--lib/rexml/undefinednamespaceexception.rb8
-rw-r--r--lib/rexml/xmldecl.rb11
-rw-r--r--lib/rexml/xpath_parser.rb21
-rw-r--r--lib/rinda/tuplespace.rb13
-rw-r--r--lib/scanf.rb2
-rw-r--r--lib/set.rb29
-rw-r--r--lib/shell/command-processor.rb7
-rw-r--r--lib/singleton.rb3
-rw-r--r--lib/sync.rb5
-rw-r--r--lib/timeout.rb23
-rw-r--r--lib/tmpdir.rb21
-rw-r--r--lib/uri/common.rb2
-rw-r--r--lib/uri/generic.rb3
-rw-r--r--lib/webrick/httprequest.rb2
-rw-r--r--lib/webrick/httpservlet/abstract.rb2
-rw-r--r--lib/webrick/httpservlet/cgi_runner.rb4
-rw-r--r--lib/webrick/httpservlet/filehandler.rb71
-rw-r--r--lib/webrick/httputils.rb16
-rw-r--r--lib/xmlrpc/client.rb7
-rw-r--r--lib/xmlrpc/parser.rb4
-rw-r--r--lib/xmlrpc/server.rb10
-rw-r--r--lib/xmlrpc/utils.rb2
-rw-r--r--lib/yaml.rb4
-rw-r--r--lib/yaml/basenode.rb2
-rw-r--r--lib/yaml/rubytypes.rb18
-rw-r--r--lib/yaml/types.rb8
-rw-r--r--marshal.c117
-rw-r--r--math.c2
-rw-r--r--misc/ruby-mode.el2
-rw-r--r--missing/isinf.c7
-rw-r--r--missing/strftime.c58
-rwxr-xr-xmkconfig.rb2
-rw-r--r--node.h48
-rw-r--r--numeric.c186
-rw-r--r--object.c23
-rw-r--r--pack.c9
-rw-r--r--parse.y156
-rw-r--r--process.c126
-rw-r--r--random.c11
-rw-r--r--range.c5
-rw-r--r--re.c49
-rw-r--r--regex.c87
-rw-r--r--ruby.c278
-rw-r--r--ruby.h2
-rw-r--r--rubysig.h8
-rwxr-xr-xrunruby.rb12
-rw-r--r--sample/test.rb5
-rw-r--r--signal.c33
-rw-r--r--sprintf.c86
-rw-r--r--string.c125
-rw-r--r--struct.c20
-rw-r--r--test/erb/hello.erb4
-rw-r--r--test/erb/test_erb.rb388
-rw-r--r--test/logger/test_logger.rb4
-rw-r--r--test/matrix/test_matrix.rb43
-rw-r--r--test/matrix/test_vector.rb43
-rw-r--r--test/net/pop/test_pop.rb132
-rw-r--r--test/optparse/test_summary.rb23
-rw-r--r--test/rexml/test_document.rb66
-rw-r--r--test/rinda/test_rinda.rb36
-rw-r--r--test/rss/rss-testcase.rb9
-rw-r--r--test/rss/test_image.rb27
-rw-r--r--test/rss/test_parser_1.0.rb9
-rw-r--r--test/rss/test_taxonomy.rb16
-rw-r--r--test/ruby/marshaltestlib.rb6
-rw-r--r--test/ruby/suicide.rb2
-rw-r--r--test/ruby/test_beginendblock.rb41
-rw-r--r--test/ruby/test_bignum.rb8
-rw-r--r--test/ruby/test_float.rb34
-rw-r--r--test/ruby/test_hash.rb564
-rw-r--r--test/ruby/test_marshal.rb20
-rw-r--r--test/ruby/test_method.rb11
-rw-r--r--test/ruby/test_pack.rb40
-rw-r--r--test/ruby/test_system.rb5
-rw-r--r--test/ruby/test_time.rb21
-rwxr-xr-xtest/thread/lbtest.rb51
-rw-r--r--test/thread/test_thread.rb52
-rw-r--r--test/webrick/.htaccess1
-rw-r--r--test/webrick/test_cgi.rb9
-rw-r--r--test/webrick/test_filehandler.rb135
-rw-r--r--test/webrick/utils.rb12
-rwxr-xr-xtest/webrick/webrick_long_filename.cgi36
-rw-r--r--test/yaml/test_yaml.rb8
-rw-r--r--time.c24
-rw-r--r--util.c3413
-rw-r--r--variable.c24
-rw-r--r--version.h15
-rw-r--r--win32/Makefile.sub8
-rwxr-xr-xwin32/mkexports.rb15
-rw-r--r--win32/setup.mak2
-rw-r--r--win32/win32.c444
-rw-r--r--win32/win32.h2
-rw-r--r--wince/setup.mak2
221 files changed, 3945 insertions, 13106 deletions
diff --git a/ChangeLog b/ChangeLog
index cfc83c3138..4334805ffc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,2133 +1,3 @@
-Mon Mar 9 10:01:26 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * re.c (match_check): check if MatchData is initialized.
- [ruby-core:18749]
-
-Mon Mar 9 09:55:57 2009 Shugo Maeda <shugo@ruby-lang.org>
-
- * lib/rexml/rexml.rb: incremented Ruby::VERSION. Thanks, Jeremy
- Kemper. [ruby-core:20113]
-
-Mon Mar 9 09:51:19 2009 Tanaka Akira <akr@fsij.org>
-
- * io.c (io_getpartial): fflush after read for updating pos in FILE.
- not portable, I guess. [ruby-core:21561]
-
-Mon Mar 9 09:03:01 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * gc.c (define_final): cannot define finalizer for immediate
- values. [ruby-core:21500]
-
- * gc.c (define_final): freezes or hides internal values.
-
-Mon Mar 9 08:52:37 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (IS_BEG): EXPR_CLASS should be treated like EXPR_BEG.
- [ruby-core:21453]
-
-Wed Feb 25 15:14:32 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * node.h (rb_thread_raised_clear): should not clear flags other than
- raised flags. a patch by Tomoyuki Chikanaga <chikanag AT
- nippon-control-system.co.jp> at [ruby-dev:37794]. [ruby-dev:37776]
-
-Wed Feb 25 15:04:31 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/socket/extconf.rb (gai_strerror): checks if available and if
- returns const pointer.
-
- * ext/socket/getaddrinfo.c (gai_strerror): defines only if non
- available. [ruby-core:21328]
-
-Wed Feb 25 14:56:30 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * win32/win32.c (open_dir_handle): extracted from rb_w32_opendir.
-
- * win32/win32.c (winnt_stat): gets rid of strange behavior of
- GetFileAttributes(). [ruby-core:21269]
-
-Tue Feb 24 02:41:47 2009 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * lib/erb.rb (PercentScanner): remove PercentScanner. fixed % after
- %> bug. [ruby-dev:37751] [Bug #997]
-
- * test/erb/test_erb.rb: ditto
-
-Sun Feb 22 22:05:44 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (stack_extend): streamlined rb_thread_restore_context()
- to ensure O(1) time. based on a patch by Brent Roman <brent AT
- mbari.org>.
-
-Sun Feb 22 21:50:29 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (cc_mark): frees the continuation's stack if its thread
- is dead to avoid recursive gc that segfaults. [ruby-core:13889]
- a patch by Brent Roman <brent AT mbari.org>.
-
- * eval.c (rb_cont_check): checks for valid continuation instance.
-
- * eval.c (rb_callcc): assigns th->thread before scope_dup() to
- avoid segfaults if this scope_dup() triggers a gc pass.
- a patch by Brent Roman <brent AT mbari.org>.
-
-Sun Feb 22 00:29:05 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/extmk.rb (extmake): does not use both of makefile.rb and
- extconf.rb at the same time.
-
- * lib/mkmf.rb (DLLIB): depends on Makefile. [ruby-core:21096]
-
-Sun Feb 22 00:13:58 2009 Tanaka Akira <akr@fsij.org>
-
- * eval.c (rb_thread_schedule): Don't change status of threads which
- don't run next even if select notify readability/writability.
- [ruby-core:20446]
-
-Fri Feb 20 20:36:18 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/optparse.rb (OptionParser::List#summarize): gives priority
- to latter switches. [ruby-dev:36692]
-
- * lib/optparse.rb (OptionParser#summarize): do not append
- unnecessary line terminator.
-
-Fri Feb 20 19:34:36 2009 Takeyuki FUJIOKA <xibbar@ruby-lang.org>
-
- * lib/cgi/session.rb: ignore session_id options fixed.[Bug #605]
-
-Fri Feb 20 18:05:27 2009 James Edward Gray II <jeg2@ruby-lang.org>
-
- Merged 20854 from trunk.
-
- * lib/xmlrpc/server.rb: Restricting method inspection to show only
- non-inherited public methods. [ruby-core:20603]
-
- * lib/xmlrpc/server.rb: Fixing method inspection so it doesn't
- trigger XMLRPC::FaultException when used. [ruby-core:20604]
-
-Fri Feb 20 01:40:18 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/sync.rb (Sync_m#sync_try_lock): wrong variable name fixed.
- a patch from [ruby-core:20561]
-
- * lib/sync.rb (Sync_m::Err.Fail): turn off Thread.critical before
- exit.
-
-Thu Feb 19 17:52:42 2009 Yuki Sonoda (Yugui) <yugui@yugui.jp>
-
- * pack.c (pack_pack): fixed odd act of 'm*', 'M*', and 'P*'.
- just ignores '*' in these cases.
- [ruby-dev:37289]
-
-Thu Feb 19 17:24:30 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * pack.c (pack_pack): fixed length for odd length string.
- [ruby-dev:37283]
-
-Wed Feb 18 22:27:11 2009 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (rb_w32_isatty): check whether fd is valid.
-
-Wed Feb 18 22:23:44 2009 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (waitpid): fix bug of checking child slot.
-
- * win32/win32.c (FindChildSlotByHandle): new.
-
-Wed Feb 18 22:12:24 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * pack.c (pack_pack): propagate taint status from format string to
- result string.
-
-Wed Feb 18 22:05:44 2009 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
-
- * ext/gdbm/gdbm.c: do not set members of RSTRING(str) directly.
- [ruby-dev:37182]
-
- * ext/gdbm/gdbm.c (rb_gdbm_nextkey): fix memory leak.
-
-Tue Feb 17 11:57:39 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * string.c (str_independent): no independent string points null_str.
- [ruby-core:20082]
-
-Mon Feb 16 23:25:43 2009 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/lib/tkextlib/blt.rb, ext/tk/lib/tkextlib/blt/vector.rb:
- fix NameError bug.
-
-Mon Feb 16 22:59:48 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * string.c (rb_str_s_alloc, rb_str_replace): use null_str as well as
- rb_string_value so that extension libraries do not segfault.
- [ruby-core:19971]
-
- * string.c (rb_str_replace): reduced unnecessary malloc and copy.
-
-Mon Feb 16 22:42:50 2009 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * test/rinda/test_rinda.rb: fixed fails occasionally [ruby-dev:37119].
- thanks, shinichiro.h.
-
-Mon Feb 16 22:21:20 2009 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * lib/drb/drb.rb (DRbConn::alive?): fixed NoMethodError problem
- from NaHi [ruby-dev:37110].
-
-Sun Feb 15 04:18:49 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/net/ftp.rb (Net::FTP#open_socket): SOCKSsocket is obsolete.
- a patch from Alan Johnson <alan.wayne.johnson at gmail.com> in
- [ruby-core:19982].
-
-Fri Feb 13 19:17:29 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/logger.rb (ProgName): fixed for svn, based on a patch from
- Nobuhiro IMAI at [ruby-dev:37108].
-
-Sun Feb 15 04:15:39 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/webrick/httprequest.rb (WEBrick::HTTPRequest#read_request_line):
- use non-greedy match for path retrieval to avoid huge recursion
- for insanely long path.
-
-Fri Feb 13 19:04:06 2009 Keiju Ishitsuka <keiju@ruby-lang.org>
-
- * shell/command-processor.rb: undefined method `top_level_test' in
- Shell#test. [ruby-list:45634]
-
-Tue Feb 10 19:57:43 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (load_lock): makes circular require deadlock.
- [ruby-core:19821]
-
-Tue Feb 10 19:13:08 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_feature_p): returns found feature name if loading.
- [ruby-core:19798]
-
- * eval.c (search_required): ditto.
-
-Wed Feb 11 23:36:20 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * ext/bigdecimal/bigdecimal.c (VpMidRound): Round method bug
- pointed by Ryan Platte fixed(Patch to the patch from "NATORI
- Shin"). [ruby-talk:273360]
- back ported from 1.9. fix [ruby-core:19791]
-
-Mon Feb 9 17:34:55 2009 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (rb_w32_accept): secure fd before accept because if
- error causes in securing, cannot restore the state of accepted
- socket.
- fixed [ruby-core:19728]
-
-Mon Feb 9 13:41:50 2009 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (ifs_open_socket): should retry without proto_buffer
- if cannot find the suitable protocol. a patch from Heesob Park.
- fixed [ruby-core:19713]
-
-Mon Feb 9 13:39:14 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * ext/stringio/stringio.c (strio_ungetc): should allow ungetc at
- the top of the buffer. ref #701
-
-Thu Feb 5 09:37:39 2009 NARUSE, Yui <naruse@ruby-lang.org>
-
- * ext/nkf/nkf-utf8/nkf.c (h_conv): can't guess UTF-8 input in
- conversion. [ruby-list:45609]
-
-Thu Feb 5 09:02:18 2009 Shugo Maeda <shugo@ruby-lang.org>
-
- * lib/rexml/entity.rb (unnormalized): do not call
- document.record_entity_expansion if document is nil.
- see <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=502535>.
- Thanks, Naohisa Goto. backported from trunk.
-
- * test/rexml/test_document.rb: ditto.
-
-Thu Feb 5 08:54:25 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * array.c (rb_ary_join): do not repeat self in a recursive array.
- [ruby-dev:37019]
-
-Wed Feb 4 14:25:44 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * dir.c (dir_globs): need taint check. reported by steve
- <oksteev at gmail.com>
-
-Tue Feb 3 14:33:08 2009 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
-
- * lib/net/pop.rb: check for invalid APOP timestamp. (CVE-2007-1558)
- [ruby-dev:36631]
-
- * test/net/pop/test_pop.rb: ditto.
-
-Mon Feb 2 20:03:00 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * time.c (time_mdump, time_mload): preserves GMT status.
- [ruby-core:19252]
-
-Mon Feb 2 11:33:26 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * variable.c (autoload_delete, autoload_file): should not delete
- autoload table, since it may be shared with duplicated modules.
- [ruby-core:19181]
-
-Thu Jan 29 11:53:14 2009 Tadayoshi Funaba <tadf@dotrb.org>
-
- * lib/date.rb (today,now): should produce own instances.
- [ruby-talk:317020]
-
-Wed Jan 28 22:48:00 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_mod_modfunc): method undefined in included module
- may not have nd_body. [ruby-core:18738]
-
-Wed Jan 28 20:53:27 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * marshal.c (marshal_dump): fixed for check_dump_arg.
-
-Tue Jan 27 17:29:05 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * marshal.c (marshal_dump): initializes dump_arg before any funcall.
- [ruby-dev:36648]
-
-Tue Jan 27 15:16:05 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/socket/socket.c (host_str): numeric address should be unsigned.
- [ruby-core:18971]
-
-Mon Jan 26 11:11:22 2009 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * lib/tmpdir.rb: setup buffer with nul characters instead of spaces.
- fixed [ruby-dev:36493]
-
-Sun Jan 25 00:06:48 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/rexml/formatters/pretty.rb (REXML::Formatters::Pretty#wrap):
- abandon wrapping if the line contains no space. [ruby-dev:36045]
- fix: #342
-
-Sun Jan 25 00:00:50 2009 Yuki Sonoda (Yugui) <yugui@yugui.jp>
-
- * lib/matrix.rb (Vector#eql?): typo of the method name as "eqn?".
- (Vector#eqn?): removed. Defined by mistake.
- Fixes [ruby-dev:36294]. Reported by weda <weda AT
- issp.u-tokyo.ac.jp> and an anonymous user.
-
- * test/matrix/test_matrix.rb: added.
-
- * test/matrix/test_vector.rb: added.
-
-Fri Jan 23 11:42:21 2009 Shugo Maeda <shugo@ruby-lang.org>
-
- * NEWS: added an entry for REXML.
-
- * lib/rexml/document.rb: fixed typo.
-
-Fri Jan 23 11:42:21 2009 Shugo Maeda <shugo@ruby-lang.org>
-
- * lib/rexml/document.rb: limit entity expansion. Thanks, Luka
- Treiber, Mitja Kolsek, and Michael Koziarski. backported from
- trunk r19033, r19317, r19318.
-
- * lib/rexml/entity.rb: ditto.
-
- * test/rexml/test_document.rb: ditto.
-
-Thu Jan 22 15:11:09 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * marshal.c (marshal_load): arg.data is no longer a VALUE but a
- st_table, and freed in load_ensure. pointed out by pegacorn.
- [ruby-dev:37008]
-
-Thu Jan 22 15:11:09 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * gc.c (rb_mark_set): new function to mark keys.
-
- * marshal.c (struct dump_arg, struct load_arg): added wrappers to mark
- data entries. backport from trunk r13527,r13528,r13961,r16533.
- [ruby-dev:36082]
-
-Wed Jan 21 10:56:20 2009 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (filetime_to_timeval): new function, split from
- gettimeofday().
-
- * win32/win32.c (gettimeofday): use above function.
-
- * win32/win32.c (filetime_to_unixtime): ditto. [ruby-dev:36135]
-
-Wed Jan 21 10:56:20 2009 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (gettimeofday): tv_usec is usec, not msec.
- [ruby-dev:36094]
-
-Wed Jan 21 10:56:20 2009 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (gettimeofday): calc tv_sec and tv_usec from system
- time by myself. [ruby-dev:36084]
-
-Wed Jan 21 10:56:20 2009 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (gettimeofday): shouldn't use mktime(2) because it's
- buggy about handling summer time.
- reported by Yoshikawa <yoshixool AT gmail.com> at [ruby-dev:36071]
-
-Tue Jan 20 12:22:12 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/scanf.rb (Scanf::FormatSpecifier#initialize): %i should accept
- single digit decimal. [ruby-core:18355]
-
-Mon Jan 19 18:24:13 2009 Tanaka Akira <akr@fsij.org>
-
- * configure.in (rb_cv_broken_glibc_ia64_erfc): renamed from
- rb_broken_glibc_ia64_erfc.
- [ruby-core:18228]
-
-Sat Jan 17 12:13:10 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * random.c (Init_Random): always initialize seed.
-
-Sat Jan 17 12:11:06 2009 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * marshal.c (dump_ensure, load_ensure): should return values.
-
-Fri Jan 16 10:55:51 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * class.c (clone_method): should copy cbase in cref as well.
- [ruby-dev:35116]
-
- * node.h (NEW_CREF): new NEW_ macro.
-
- * eval.c (PUSH_CREF): use NEW_CREF().
-
-Thu Jan 15 14:34:32 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * gc.c (STACK_LEVEL_MAX, ruby_stack_length): returns size_t.
- [ruby-core:18207]
-Wed Jan 14 10:32:13 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * stable/ext/socket/socket.c (NI_MAXHOST, NI_MAXSERV): fixed invalid
- preprocessor directives. a patch from Peter Bowen at
- [ruby-core:18211].
-
-Tue Jan 13 04:39:30 2009 Shugo Maeda <shugo@ruby-lang.org>
-
- * lib/net/ftp.rb (login): raise FTPReplyError if passwd or acct
- is not supplied. backported from trunk. fixed [ruby-core:18058].
-
-Mon Jan 12 00:21:49 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * gc.c (gc_sweep, obj_free, run_final): defer finalizers of IO and
- Data. [ruby-dev:35578]
-
- * gc.c (rb_gc_call_finalizer_at_exit): self-referencing finalizers
- cannot be invoked. [ruby-dev:35681]
-
-Sun Jan 11 11:31:52 2009 Shugo Maeda <shugo@ruby-lang.org>
-
- * lib/net/ftp.rb (chdir): handle 5xx errors correctly.
- backported from trunk. fixed [ruby-core:18057].
-
-Fri Jan 9 19:22:24 2009 Shugo Maeda <shugo@ruby-lang.org>
-
- * lib/net/imap.rb (disconnect): do not refer SSL::SSLSocket for
- environments without OpenSSL. backported from trunk.
- fixed [ruby-dev:35755].
-
-Thu Jan 8 13:20:15 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y (deferred_nodes, compstmt, arg, fixup_nodes, range_op): fix
- up fixnum range literal in conditional as automagical line number
- comparison. [ruby-core:12124], [ruby-dev:35731]
-
-Wed Jan 7 10:06:12 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (timeofday): use monotonic clock. based on a patch
- from zimbatm <zimbatm@oree.ch> in [ruby-core:16627].
-
-Tue Jan 6 09:02:14 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y (yylex): 8 and 9 in octal integer should cause compile
- error. [ruby-dev:35729]
-
-Mon Jan 5 11:12:39 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_thread_schedule): runs deferred finalizers.
-
- * gc.c (gc_sweep): sets rb_thread_pending to run deferred finalizers.
-
- * rubysig.h (CHECK_INTS): now checks rb_thread_pending even on
- platforms where setitimer is not available. [ruby-core:18045]
-
-Mon Jan 5 11:12:39 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * rubysig.h (CHECK_INTS): gives the chance to perform to deferred
- finalizers before explicit GC.start or the process termination.
- [ruby-core:18045]
-
-Sun Jan 4 04:47:57 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * win32/win32.c (rb_w32_telldir): just returns loc.
-
- * win32/win32.c (rb_w32_rewinddir): needs to intialize loc.
- [ruby-core:18041]
-
-Thu Jan 1 08:39:36 2009 Tadayoshi Funaba <tadf@dotrb.org>
-
- * lib/date.rb (Date::Infinity#<=>): didn't work. A patch from
- Dirkjan Bussink <d.bussink AT gmail.com> [ruby-core:15098].
- This is a bug obviously. However it didn't affect the library's
- functions.
-
- * lib/date.rb, lib/date/format.rb: some trivial changes.
-
-Mon Aug 11 09:34:52 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * ext/dl/dl.c (rb_str_to_ptr): should propagate taint to dlptr.
-
- * ext/dl/dl.c (rb_ary_to_ptr): ditto.
-
- * ext/dl/sym.c (rb_dlsym_call): should check taint of DLPtrData as
- well.
-
-Fri Aug 8 10:53:52 2008 Tanaka Akira <akr@fsij.org>
-
- * lib/resolv.rb: randomize source port and transaction id.
- CVE-2008-1447.
-
- * lib/resolv-replace.rb (UDPSocket#bind): don't resolv host if host is
- "".
-
-Mon Aug 4 14:15:58 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/webrick/httputils.rb (WEBrick::HTTPUtils#split_header_value):
- reduce backtrack. based on a fix by Christian Neukirchen
- <chneukirchen AT gmail.com>.
-
-Mon Aug 4 14:10:01 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * regex.c (xmalloc, xrealloc, xfree): not to use ruby managed memory.
-
- * regex.c (DOUBLE_STACK, re_compile_fastmap0, re_adjust_startpos),
- (re_search, re_match_exec): check if failed to allocate memory.
-
-Mon Aug 4 13:49:36 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * bignum.c (rb_big2str0, bigsqr): made interruptible. [ruby-Bugs-20622]
-
-Mon Aug 4 13:39:53 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/openssl/openssl_missing.h (d2i_of_void): define for older
- versions. [ruby-dev:35637]
-
-Mon Aug 4 12:25:08 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * numeric.c (check_uint, rb_num2uint, rb_fix2uint): fixed wrong check
- about 64bit positive value.
-Mon Aug 4 12:25:08 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * numeric.c (check_uint, rb_num2uint, rb_fix2uint): strict check.
- fixed [ruby-dev:33683]
-
-Mon Aug 4 12:11:29 2008 Tanaka Akira <akr@fsij.org>
-
- * gc.c (Init_GC): fix syntax error.
-
-Mon Aug 4 12:11:29 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * error.c (rb_exc_new3): keeps the given string itself.
-
- * eval.c (Init_Proc), gc.c (Init_GC): freeze messages of preallocated
- special exceptions also.
-
-Thu Jul 17 21:37:39 2008 URABE Shyouhei <shyouhei@ruby-lang.org>
-
- * lib/net/smtp.rb (Net::SMTP::start): revert to avoid RFC2821
- violation. [ruby-dev:35487]
-
-Thu Jul 17 21:31:46 2008 Tanaka Akira <akr@fsij.org>
-
- * string.c (rb_str_format_m): make tmp volatile to avoid possible GC
- problem.
-
-Thu Jul 17 21:29:34 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/optparse.rb (OptionParser#environment): requires shellwords.
- [ruby-dev:35466]
-
-Thu Jul 17 01:36:02 2008 Yusuke Endoh <mame@tsg.ne.jp>
-
- * ext/zlib/zlib.c (rb_gzfile_set_mtime): fix typo. [ruby-core:17713]
-
-Sun Jul 13 00:07:07 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/ipaddr.rb (IPAddr#initialize): get rid of ArgumentError in
- IPAddr#to_range. a patch from okkez <okkez000 AT gmail.com> in
- [ruby-dev:35091].
-
-Sun Jul 13 00:02:26 2008 Tanaka Akira <akr@fsij.org>
-
- * configure.in (erfc): erfc of glibc comes with Debian GNU/Linux Etch
- on IA64 is broken. erfc(10000.0) aborts.
- use missing/erf.c instead.
- http://sources.redhat.com/ml/libc-hacker/2005-08/msg00008.html
-
-Thu Jul 10 18:44:01 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * file.c (rb_file_s_extname): fix for file name with spaces.
- [ruby-talk:307404]
-
-Thu Jul 10 18:39:17 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/net/ftp.rb (Net::FTP#sendport): use divmod. [ruby-core:17557]
-
-Thu Jul 10 18:35:07 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
-
- * ruby.c: Mac OS X needs origargc times of '\0' in
- origargv. [ruby-dev:35308]
-
-Thu Jul 10 13:51:03 2008 Tanaka Akira <akr@fsij.org>
-
- * include/ruby/ruby.h (POSFIXABLE): use FIXNUM_MAX+1 instead of
- FIXNUM_MAX to make it possible to convert to double accurately.
- It assumes FLT_RADIX is 2.
- fix RubyForge bug #14102.
- backported from 1.9.
-
-Mon Jul 7 16:14:05 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/net/smtp.rb (Net::SMTP::start): use 'localhost' instead of
- 'localhost.localdomain'. [ruby-dev:35333]
-
- * lib/net/smtp.rb (Net::SMTP::SMTP.start): ditto.
-
-Mon Jul 7 12:07:28 2008 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-
- * ext/win32ole/win32ole.c: avoid creating Ruby object during
- GC. thanks to arton <artonx AT yahoo.co.jp>. [ruby-dev:35313]
-
- * ext/win32ole/tests: add test_win32ole_event.rb, remove
- testOLEEVENT.rb
-
- * ext/win32ole/tests/testWIN32OLE.rb(test_convert_bignum):
- fix test.
-
-Mon Jul 7 12:07:28 2008 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-
- * gc.c: add rb_during_gc(). based on a patch from arton <artonx AT
- yahoo.co.jp> at [ruby-dev:35313].
-
- * intern.h: ditto.
-
-Thu Jul 3 17:15:04 2008 URABE Shyouhei <shyouhei@ruby-lang.org>
-
- * win32/win32.c: revert r17290, requested by NAKAMURA Usaku
- <usa at ruby-lang.org>
-
-Wed Jul 2 19:05:35 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/cgi.rb (CGI::QueryExtension.read_multipart): blanks inside
- double quotes are allowed. [ruby-list:45140]
-
-Wed Jul 2 19:01:13 2008 Tanaka Akira <akr@fsij.org>
-
- * numeric.c (num_coerce): call rb_Float(x) first. don't depend on
- evaluation order of function arguments.
-
-Wed Jul 2 18:55:50 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * ext/syslog/syslog.c (syslog_write): syslog operations should be
- protected from $SAFE level 4. a patch from Keita Yamaguchi
- <keita.yamaguchi at gmail.com>.
-
- * ext/syslog/syslog.c (mSyslog_close): ditto.
-
- * ext/syslog/syslog.c (mSyslog_set_mask): ditto.
-
-Wed Jul 2 18:25:17 2008 Tanaka Akira <akr@fsij.org>
-
- * math.c (domain_check): fix preprocess condition.
-
-Wed Jul 2 18:19:45 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/tmpdir.rb (@@systmpdir): prior LOCAL_APPDATA if possible, and
- should be clean. based on a patch from arton <artonx AT
- yahoo.co.jp> at [ruby-dev:35269]
-
-Wed Jul 2 18:13:30 2008 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-
- * ext/win32ole/win32ole.c (date2time_str): fix the overflow in
- some situation. [ruby-bugs-20793]
-
-Wed Jul 2 17:38:01 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/iconv/iconv.c (iconv_iconv): fixed backport miss.
- [ruby-core:17115]
-
-Tue Jul 1 15:09:37 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * array.c (rb_ary_fill): check if beg is too big.
-
-Mon Jun 30 20:34:05 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * string.c (str_buf_cat): check for self concatenation.
-
-Sun Jun 29 21:38:52 2008 Tanaka Akira <akr@fsij.org>
-
- * eval.c (rb_obj_respond_to): use RTEST to test the result of
- respond_to? method.
-
-Sun Jun 29 20:40:57 2008 URABE Shyouhei <shyouhei@ruby-lang.org>
-
- * array.c (rb_ary_fill): (compatibility) do not raise
- ArgumentError on negative length. This behaviour shall change
- in a future release.
-
-Sun Jun 29 20:06:45 2008 Tanaka Akira <akr@fsij.org>
-
- * time.c (time_timeval): fix rounding negative float.
-
-Sun Jun 29 18:35:23 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * test/inlinetest.rb (InlineTest.in_progname): workaround for frozen
- $0. [ruby-dev:35261]
-
- * lib/test/unit/ui/console/testrunner.rb (TestRunner#finished): ditto.
-
-Sun Jun 29 18:35:23 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ruby.c (set_arg0, ruby_prog_init): freeze $0. a patch from Keita
- Yamaguchi <keita.yamaguchi at gmail.com>.
-
-Sun Jun 29 18:32:19 2008 Tanaka Akira <akr@fsij.org>
-
- * process.c: include sys/resource.h if HAVE_SYS_RESOURCE_H is defined.
- pointed by TOYOFUKU Chikanobu. [ruby-dev:35258]
-
-Sun Jun 29 18:25:03 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * variable.c (rb_f_trace_var): should not be allowed at safe level 4.
- a patch from Keita Yamaguchi <keita.yamaguchi at gmail.com>.
-
- * eval.c (rb_call0): wrong condition to check insecure method.
- a patch from Keita Yamaguchi <keita.yamaguchi at gmail.com>.
-
-Sun Jun 29 18:24:13 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * array.c (rb_ary_fill): not depend on unspecified behavior at integer
- overflow. reported by Vincenzo Iozzo <snagg AT openssl.it>.
-
-Sun Jun 29 18:21:23 2008 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-
- * ext/win32ole/win32ole.c(ole_invoke): fix memory leak.
- [ruby-bugs-20792]
-
-Sun Jun 29 17:34:11 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * eval.c (PUSH_FRAME, PUSH_CLASS): Add volatile to avoid a
- possible optimization bug on OS X/PPC. This at least makes
- build with gcc -O1 and `make test' pass.
-
-Sun Jun 29 17:23:51 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/rdoc/parsers/parse_rb.rb (RDoc#collect_first_comment): skip
- magic comment.
-
-Sun Jun 29 17:21:08 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/stringio/stringio.c (strio_each, strio_readlines): IO#each and
- IO#readlines do not affect $_. [ruby-core:17277]
-
-Sun Jun 29 17:18:45 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/stringio/stringio.c (strio_readline, strio_each)
- (strio_readlines): set lastline. [ruby-core:17257]
-
-Sun Jun 29 17:10:30 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * ext/openssl/ossl.h: include winsock.h if USE_WINSOCK2 is not defined.
- a patch from arton <artonx at yahoo.co.jp> in [ruby-dev:35078]
-
-Sun Jun 29 17:07:30 2008 wanabe <s.wanabe@gmail.com>
-
- * util.c (ruby_strtod): ruby_strtod don't allow a trailing
- decimal point like "7.". [ruby-dev:34835] [ruby-dev:35009]
-
-Sun Jun 29 16:56:57 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * lib/set.rb (Set#delete_if): Call to_a.
- (SortedSet#delete_if, TC_SortedSet#test_sortedset): Use super to
- yield elements in sorted order; [ruby-core:17144] by Arthur
- Schreiber.
- (SortedSet#each, SortedSet#each, TC_Set#test_each)
- (TC_SortedSet#test_sortedset): Return self; [ruby-dev:35002] by
- Arthur Schreiber.
-
-Sun Jun 29 16:49:11 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (search_method, remove_method, error_print, rb_alias)
- (rb_eval, rb_rescue2, search_required, Init_eval, rb_thread_create),
- gc.c (rb_source_filename, Init_stack), io.c (rb_io_getline),
- parse.y (rb_id2name, rb_parser_free): suppress warnings.
-
-Sat Jun 28 19:26:43 2008 URABE Shyouhei <shyouhei@ruby-lang.org>
-
- * class.c (clone_method): use rb_copy_node_scope.
- fixed [ruby-list:45102]
- fixed [ruby-core:17393]
-
-Sat Jun 28 19:25:56 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * eval.c (rb_copy_node_scope), node.h: Rename from copy_node_scope
- and export.
-
-Fri Jun 27 17:38:21 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * ext/zlib/zlib.c (rb_deflate_initialize, Init_zlib): Fix up
- initialize_copy; [ruby-list:45016], [ruby-list:45018].
-
-Fri Jun 27 17:28:39 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * io.c (rb_open_file, rb_io_s_sysopen): fmode should be unsigned int.
- fixed [ruby-dev:34979]
-
-Fri Jun 27 17:20:40 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.h: include ws2tcpip.h. fixed [ruby-Bugs-20528]
-
-Fri Jun 27 15:57:05 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/iconv/iconv.c (iconv_iconv): fixed backport miss.
- [ruby-core:17115]
-
-Fri Jun 27 15:57:05 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/iconv/iconv.c (iconv_iconv): fix for length argument and now
- allows range. [ruby-core:17092]
-
-Tue Jun 24 15:38:52 2008 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * lib/erb.rb (ERB::Compiler::TrimScanner#explicit_trim_line): Fix
- without strscan problems. [ruby_core:17028].
-
- * test/erb/test_erb.rb (TestERBCoreWOStrScan): Add test class for
- without strscan.
-
-Sun Jun 22 00:09:20 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * lib/delegate.rb (DelegateClass, Delegator#respond_to?):
- respond_to? should now take optional second argument; submitted
- by Jeremy Kemper <jeremy at bitsweat.net> in [ruby-core:17045].
-
-Fri Jun 20 18:24:18 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * string.c (rb_str_buf_append): should infect.
-
-Fri Jun 20 15:52:30 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * array.c (rb_ary_store, rb_ary_splice): not depend on unspecified
- behavior at integer overflow.
-
- * string.c (str_buf_cat): ditto.
-
-Wed Jun 18 22:25:10 2008 URABE Shyouhei <shyouhei@ruby-lang.org>
-
- * array.c (ary_new, rb_ary_initialize, rb_ary_store,
- rb_ary_aplice, rb_ary_times): integer overflows should be
- checked. based on patches from Drew Yao <ayao at apple.com>
- fixed CVE-2008-2726
-
- * string.c (rb_str_buf_append): fixed unsafe use of alloca,
- which led memory corruption. based on a patch from Drew Yao
- <ayao at apple.com> fixed CVE-2008-2726
-
- * sprintf.c (rb_str_format): backported from trunk.
-
- * intern.h: ditto.
-
-Fri Jun 20 01:40:21 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * array.c (rb_ary_equal, rb_ary_eql, rb_ary_hash, rb_ary_cmp):
- Make Array#eql?, #hash, #== and #<=> use rb_protect_inspect() and
- handle recursive data properly. [ruby-dev:35181]
-
-Wed Jun 18 15:20:21 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * marshal.c (w_object, marshal_dump, r_object0, marshal_load): search
- public methods only. [ruby-core:17283]
-
- * object.c (convert_type): ditto.
-
- * lib/singleton.rb (Singleton#_dump): conversion method should be
- public.
-
-Wed Jun 18 13:19:55 2008 URABE Shyouhei <shyouhei@ruby-lang.org>
-
- * file.c: fixes to compile on mswin32. Patch from U. Nakamura
- <usa at garbagecollect.jp>. [ruby-dev:35127]
-
-Tue Jun 17 22:16:44 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (LIBPATHFLAG, RPATHFLAG): no needs to be quoted,
- it is done by libpathflag in mkmf.rb.
-
-Mon Jun 16 15:43:07 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * proc.c (proc_dup): should copy safe_level from src proc
- properly. a patch from Keita Yamaguchi
- <keita.yamaguchi at gmail.com>
-
-Sun Jun 15 23:31:10 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/zlib/extconf.rb: search zlib1, and regard mswin32 later than VC6
- as WIN32. [ruby-core:16984]
-
-Sun Jun 15 23:28:15 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * marshal.c (w_object, marshal_dump, r_object0, marshal_load): search
- private methods too. [ruby-dev:34671]
-
- * object.c (convert_type): ditto.
-
-Sun Jun 15 23:26:50 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * numeric.c (flo_divmod): Revert the behavior change; do not
- suppress an exception when div is NaN or Inf. [ruby-dev:34857]
-
-Sun Jun 15 23:24:32 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * file.c (BUFCHECK): wrong condition. [ruby-core:16921]
-
- * file.c (file_expand_buf): shouldn't use buflen for length of string.
-
-Sun Jun 15 23:21:22 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * marshal.c (r_object0, Init_marshal): Fix the garbled s_call
- definition; fixes [ruby-dev:34843].
-
-Sun Jun 15 23:19:53 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * object.c (rb_cstr_to_dbl): should clear errno before calling
- strtod(3). [ruby-dev:34834]
-
-Sun Jun 15 23:18:15 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * marshal.c (marshal_load): should initialize arg.data used for
- reentrant check. [ruby-dev:34837]
-
-Sun Jun 15 23:13:23 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (top_local_setup): fixed memory leak bug based on a
- patch from Roger Pack <rogerpack2005 at gmail.com> in
- [ruby-core:16610].
-Sun Jun 15 23:16:26 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * marshal.c (reentrant_check): check reentrance via callcc.
- [ruby-dev:34802]
-
-
-Sun Jun 15 23:09:00 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * sprintf.c (rb_f_sprintf): fixed SEGV on win32 with "% 0e" % 1.0/0.0.
-
-Sun Jun 15 23:07:46 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * process.c (rb_f_system): set last_status when status == -1 because
- there is no path to set it on win32. this patch is derived from
- [ruby-core:16787], submitted by Luis Lavena <luislavena at gmail.com>
-
-Sun Jun 15 23:02:12 2008 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * lib/webrick/httpservlet/filehandler.rb: should normalize path
- name in path_info to prevent script disclosure vulnerability on
- DOSISH filesystems. (fix: CVE-2008-1891)
- Note: NTFS/FAT filesystem should not be published by the platforms
- other than Windows. Pathname interpretation (including short
- filename) is less than perfect.
-
- * lib/webrick/httpservlet/abstract.rb
- (WEBrick::HTTPServlet::AbstracServlet#redirect_to_directory_uri):
- should escape the value of Location: header.
-
- * lib/webrick/httpservlet/cgi_runner.rb: accept interpreter
- command line arguments.
-
-Sun Jun 15 23:02:12 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * file.c (file_expand_path): support for alternative data stream
- and ignored trailing garbages of NTFS.
-
- * file.c (rb_file_s_basename): ditto.
-
- * file.c (rb_file_s_extname): ditto.
-
-Sun Jun 15 22:53:20 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * string.c (rb_str_cat): fixed buffer overrun reported by
- Christopher Thompson <cthompson at nexopia.com> in [ruby-core:16746]
-
-Sun Jun 15 22:51:24 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (is_defined): add NODE_OP_ASGN_{OR,AND}. "defined?(a||=1)"
- should not operate assignment. [ruby-dev:34645]
-
-Sun Jun 15 22:49:45 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (rb_w32_select): backport from trunk.
- [ruby-talk:300743]
-
-Sun Jun 15 22:48:26 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/delegate.rb (SimpleDelegator::dup): removed needless argument.
- [ruby-list:44910]
-
- * lib/delegate.rb (clone, dup): keep relationship with the target
- object.
-
-Sun Jun 15 22:46:34 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * util.c (ruby_strtod): backported from 1.9. a patch from Satoshi
- Nakagawa <psychs at limechat.net> in [ruby-dev:34625].
- fixed: [ruby-dev:34623]
-
-Sun Jun 15 22:44:25 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * struct.c (rb_struct_s_def): to_str should be called only once.
- [ruby-core:16647]
-
-Sun Jun 15 22:42:54 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * ext/zlib/zlib.c (gzreader_gets): may cause infinite loop.
- a patch from Kouya <kouyataifu4 at gmail.com> in
- [ruby-reference-manual:762].
-
-Sun Jun 15 22:34:09 2008 James Edward Gray II <jeg2@ruby-lang.org>
-
- Merged 16241 from trunk.
-
- * lib/net/telnet.rb: Fixing a bug where line endings would not be properly
- escaped when the two character ending was broken up into separate TCP
- packets. Issue reported and patched by Brian Candler.
-
-Sun Jun 15 22:31:47 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * re.c (rb_reg_search): use local variable. a patch from wanabe
- <s.wanabe AT gmail.com> in [ruby-dev:34537]. [ruby-dev:34492]
-
-Sun Jun 15 22:20:45 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * sprintf.c (rb_f_sprintf): should protect temporary string from
- GC. [ruby-dev:34480]
-
-Sun Jun 15 22:18:30 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * regex.c (re_search): string might be NULL. [ruby-core:16478]
-
-Sun Jun 15 22:16:21 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * time.c (rb_strftime): check errno to detect strftime(3)'s error.
- this is workaround for recent version of MSVCRT.
- [ruby-dev:34456]
-
-Sun Jun 15 22:12:07 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * lib/yaml/types.rb: Likewise, pass self to YAML::quick_emit;
- merged from 1.9.
-
- * lib/yaml.rb (quick_emit): use combination of object_id and hash to
- identify repeated object references, since GC will reuse memory of
- objects during output of YAML. [ruby-Bugs-8548] [ruby-Bugs-3698];
- merged from 1.9.
-
-Sun Jun 15 22:09:02 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * ext/syck/rubyext.c: Node#value defined twice.
-
- * lib/yaml/: several method redefinitions causing warnings.
-
-Sun Jun 15 22:04:44 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * marshal.c (w_object): add volatile to avoid potential GC bug. a
- patch from Tomoyuki Chikanaga <chikanag at nippon-control-system.co.jp>
- in [ruby-dev:34311].
-
-Sun Jun 15 21:59:22 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * re.c (rb_reg_quote): should always copy the quoting string.
- [ruby-core:16235]
-
-Sun Jun 15 21:27:46 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/net/pop.rb (Net::POP3::do_finish): clear @n_mails and
- @n_bytes as well. [ruby-core:16144]
-
-Sun Jun 15 21:08:10 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/resolv.rb (Resolv::Config.default_config_hash): requires
- win32/resolv to use Win32::Resolv. [ruby-dev:34138]
-
-Sun Jun 15 20:54:07 2008 Akinori MUSHA <knu@iDaemons.org>
-
- * parse.y (yycompile): Always prepare a new array for each file's
- SCRIPT_LINES__ storage, instead of appending source lines every
- time a file is re-loaded; submitted by Rocky Bernstein in
- #18517.
-
-Sun Jun 15 20:30:01 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/resolv.rb (Resolv::Hosts): should not use win32/resolv on cygwin.
- [ruby-dev:29945], [ruby-dev:34095]
-
- * lib/win32/registry.rb (Win32::Registry.expand_environ): try upcased
- name too for cygwin. [ruby-dev:29945]
-
- * lib/win32/resolv.rb (Win32::Resolv.get_hosts_path): use expand_path.
-
-Sun Jun 15 20:27:59 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * misc/ruby-mode.el (ruby-mode): should use `run-mode-hooks' instead
- of calling `run-hooks' directly to run the mode hook. patch from
- Chiyuan Zhang <pluskid AT gmail.com> in [ruby-core:15915]
-
-Sun Jun 15 20:20:59 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * numeric.c (fix_coerce): try conversion before type check.
- [ruby-core:15838]
-
-Sun Jun 15 19:56:53 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * bignum.c (BIGZEROP): fix for longer Bignum zeros. [ruby-Bugs-17454]
-
-Sun Jun 15 19:54:21 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * bignum.c (big2str_find_n1): check integer overflow.
-
-Sun Jun 15 19:52:20 2008 Tanaka Akira <akr@fsij.org>
-
- * gc.c (STACK_LENGTH) [SPARC] : 0x80 offset removed. [ruby-dev:33857]
-
-Sun Jun 15 19:50:20 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/readline/readline.c (readline_event): prevent polling. based on
- a patch from error errorsson in [ruby-Bugs-17675].
-
-Sun Jun 15 19:44:52 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y (yycompile): clear ruby_eval_tree_begin if parse failed.
-
-Sun Jun 15 19:44:52 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y (yycompile): clear ruby_eval_tree_begin too before parse.
-
-Sun Jun 15 19:22:21 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/pty/lib/expect.rb (IO#expect): check if peer is closed.
- [ruby-Bugs-17940]
-
-Sun Jun 15 19:20:13 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/iconv/iconv.c (iconv_convert): check upper bound. a patch from
- Daniel Luz at [ruby-Bugs-17910].
-
-Sun Jun 15 19:13:46 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (ftruncate): check if available.
-
- * file.c (rb_file_truncate): check if ftruncate instead of truncate.
-
-Sun Jun 15 19:02:46 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (sigsetmask): check when signal semantics is not POSIX.
-
- * signal.c (USE_TRAP_MASK): set true if sigprocmask or sigsetmask is
- available.
-
-Sat Jun 14 16:49:41 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/timeout.rb (Timeout::timeout): made sensitive to location on the
- stack. [ruby-core:15458]
-
-Fri Jun 13 13:14:31 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * ext/dl/ptr.c (dlmem_each_i): typo fixed. a patch from IKOMA
-Sun Jun 15 21:06:12 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * class.c (clone_method): should copy cref as well.
- [ruby-core:15833]
-
- Yoshiki <ikoma@mb.i-chubu.ne.jp> in [ruby-dev:33776].
-
-Fri Jun 13 13:13:23 2008 URABE Shyouhei <shyouhei@ice.uec.ac.jp>
-
- * gc.c (rb_newobj): prohibit call of rb_newobj() during gc.
- Submitted by Sylvain Joyeux [ruby-core:12099].
-
- * ext/dl/ptr.c: do not use LONG2NUM() inside dlptr_free().
- Slightly modified fix bassed on a patch by Sylvain Joyeux
- [ruby-core:12099] [ ruby-bugs-11859 ] [ ruby-bugs-11882 ]
- [ ruby-patches-13151 ].
-
-Fri Jun 13 12:10:13 2008 NARUSE, Yui <naruse@ruby-lang.org>
-
- * lib/benchmark.rb (Job::Benchmark#item): fix typo.
-
-Fri Jun 13 12:06:17 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/bigdecimal/bigdecimal.c (BigDecimal_to_f): use strtod() for more
- precision. [ruby-talk:290296]
-
- * ext/bigdecimal/bigdecimal.c (BASE_FIG): made constant.
-
- * ext/bigdecimal/extconf.rb: ditto. [ruby-dev:33658]
-
-Fri Jun 13 12:01:57 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/irb.rb (IRB::Irb::eval_input): rescues Interrupt and other than
- SystemExit and SignalException. [ruby-core:15359]
-
-Fri Jun 13 11:57:46 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/benchmark.rb (Benchmark::realtime): make Benchmark#realtime
- a bit faster. a patch from Alexander Dymo <dymo@ukrpost.ua> in
- [ruby-core:15337].
-
-Fri Jun 13 11:50:59 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * io.c (rb_open_file): should check NUL in path.
- <http://www.rubyist.net/~matz/20080125.html#c01>.
-
- * io.c (rb_io_s_popen): ditto.
-
- * io.c (rb_io_reopen): ditto.
-
- * io.c (next_argv): ditto.
-
- * io.c (rb_io_s_foreach): ditto.
-
- * io.c (rb_io_s_readlines): ditto.
-
- * io.c (rb_io_s_read): ditto.
-
-Wed Jun 11 15:23:13 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/uri/generic.rb (URI::Generic::inspect): use Kernel#to_s instead
- object_id with printf. [ruby-dev:33347]
-
-Wed Jun 11 15:00:55 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in: Remove wrong assumptions about Cygwin. a patch from
- Corinna Vinschen in [ruby-Bugs-17018].
-
-Mon Jun 9 18:09:20 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (eval): check if backtrace is empty. [ruby-core:15040]
-
-Sun Jun 8 06:08:26 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_define_alloc_func, rb_undef_alloc_func): should
- define/undef on a signleton class. [ruby-core:09959]
-
-Sun Jun 8 06:04:41 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * time.c (time_arg): use converted object. [ruby-core:14759]
-
-Sun Jun 8 06:02:11 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * io.c (fptr_finalize): clear errno first. [ruby-talk:284492]
-
-Sun Jun 8 05:59:36 2008 Tadayoshi Funaba <tadf@dotrb.org>
-
- * lib/date.rb: don't freeze nil even if 1.8 will not be aware of
- the issue. [ruby-dev:32677]
-
-Sun Jun 8 05:54:44 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (TIMEZONE_VOID): check whether timezone requires zero
- arguments. [ruby-dev:32631]
-
-Sun Jun 8 05:37:10 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y (f_rest_arg): check if duplicated. [ruby-core:14140]
-
-Sun Jun 8 05:32:45 2008 Tanaka Akira <akr@fsij.org>
-
- * gc.c (stack_end_address): use local variable address instead of
- __builtin_frame_address(0) to avoid SEGV on SunOS 5.11 on x86 with
- gcc (GCC) 3.4.3 (csl-sol210-3_4-20050802).
-
-Sun Jun 8 05:24:19 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (RUBY_CHECK_VARTYPE): check if a variable is defined
- and its type.
-
- * configure.in (timezone, altzone): check for recent cygwin.
-
- * missing/strftime.c (strftime): fix for timezone. [ruby-dev:32536]
-
- * lib/mkmf.rb (try_var): should fail for functions.
-
- * ext/readline/extconf.rb: should use have_func for functions instead
- of have_var.
-
-Sun Jun 8 05:08:35 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/cgi.rb (read_multipart): exclude blanks from header values.
- [ruby-list:44327]
-
-Sun Jun 8 05:02:25 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * bignum.c (rb_cstr_to_inum): trailing spaces may exist at sqeezing
- preceeding 0s. [ruby-core:13873]
-
-Sun Jun 8 04:58:05 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (error_print): put newline unless multiple line message ends
- with a newline. [ruby-dev:32429]
-
-Sun Jun 8 04:55:26 2008 James Edward Gray II <jeg2@ruby-lang.org>
-
- Merged 14070 from trunk.
-
- * lib/xmlrpc/server.rb (XMLRPC::Server#server): Improve signal handling so
- pressing control-c in the controlling terminal or sending SIGTERM stops
- the XML-RPC server.
-
-Sun Jun 8 04:49:43 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y (newline_node): set line from outermost node before removing
- NODE_BEGIN. [ruby-dev:32406]
-
-Sun Jun 8 04:37:34 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y (stmt): remove unnecessary NODE_BEGIN. [ruby-core:13814]
-
-Sun Jun 8 04:16:35 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_alias): do not call hook functions until initialization
- finishes. [ruby-talk:279538]
-
-Sun Jun 8 04:14:16 2008 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-
- * ext/win32ole/win32ole.c (ole_invoke): bug fix. [ruby-talk:279100]
-
-Sun Jun 8 03:59:31 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * ext/curses/extconf.rb: check macro if cannot find func.
- [ruby-list:44224]
-
-Sun Jun 8 03:52:53 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/cgi/session.rb (CGI::Session::FileStore::restore): use
- lockfile for exclusive locks. a patch from <tommy AT tmtm.org>.
- [ruby-dev:32296]
-
-Sun Jun 8 03:49:15 2008 Tanaka Akira <akr@fsij.org>
-
- * missing/isinf.c (isinf): don't define if the macro is defined.
-
-Sun Jun 8 03:42:10 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * numeric.c (round): fallback definition.
-
- * numeric.c (flo_divmod, flo_round): use round() always.
- [ruby-dev:32269]
-
-Sun Jun 8 03:42:10 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * numeric.c (flodivmod): work around for infinity.
-
- * numeric.c (flo_divmod): work around for platforms have no round().
- [ruby-dev:32247]
-
-Sun Jun 8 03:42:10 2008 URABE Shyouhei <shyouhei@ice.uec.ac.jp>
-
- * numeric.c (flo_divmod): round to the nearest integer.
- [ ruby-Bugs-14540 ]
-
-Sun Jun 8 03:28:53 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/rexml/encodings/SHIFT-JIS.rb (REXML::Encoding): place -x for
- nkf conversion. a patch from <moonwolf AT moonwolf.com>.
- [ruby-dev:32183]
-
-Sun Jun 8 03:07:19 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/optparse.rb (OptionParser::Switch::summarize): fix for long form
- option with very long argument. a patch from Kobayashi Noritada
- <nori1 AT dolphin.c.u-tokyo.ac.jp> in [ruby-list:44179].
-
-Sun Jun 8 03:04:38 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * numeric.c (fix_pow): returns infinity for 0**-1. [ruby-dev:32084]
-
-Sun Jun 8 02:58:19 2008 James Edward Gray II <jeg2@ruby-lang.org>
-
- Merged 13781 from trunk.
-
- * lib/net/telnet.rb (Net::Telnet#login): Allowing "passphrase" in
- addition to "password" for Telnet login prompts. [ruby-Bugs-10746]
-
-Wed Oct 25 06:46:21 2007 James Edward Gray II <jeg2@ruby-lang.org>
-
- Merged 13779 from trunk.
-
- * lib/net/telnet.rb (Net::Telnet#login): Making the password prompt
- pattern case insensitive. [ruby-Bugs-10746]
-
-Sun Jun 8 02:55:19 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * io.c (rb_io_tell, rb_io_seek): check errno too. [ruby-dev:32093]
-
-Sun Jun 8 01:53:50 2008 James Edward Gray II <jeg2@ruby-lang.org>
-
- Merged 13767, 13768, 13769, and 13770 from trunk.
-
- * lib/xmlrpc/parser.rb (XMLRPC::Convert::dateTime): Fixing a bug that
- caused time zone conversion to fail for some ISO 8601 date formats.
- [ruby-Bugs-12677]
-
- * lib/xmlrpc/client.rb (XMLRPC::Client#do_rpc): Explicitly start
- the HTTP connection to support keepalive requests. [ruby-Bugs-9353]
-
- * lib/xmlrpc/client.rb (XMLRPC::Client#do_rpc): Improving the error
- message for Content-Type check failures. [ruby-core:12163]
-
- * lib/xmlrpc/utils.rb (XMLRPC::ParseContentType#parse_content_type):
- Making Content-Type checks case insensitive. [ruby-Bugs-3367]
-
-Sun Jun 8 01:50:07 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * marshal.c (r_bytes0): refined length check. [ruby-dev:32059]
-
-Sun Jun 8 01:50:07 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * marshal.c (r_bytes0): check if source has enough data.
- [ruby-dev:32054]
-
-Sun Jun 8 01:41:19 2008 Tanaka Akira <akr@fsij.org>
-
- * ext/socket/socket.c (s_accept_nonblock): make accepted fd
- nonblocking. [ruby-talk:274079]
-
-Sun Jun 8 01:36:26 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (AC_SYS_LARGEFILE): keep results also in command
- options, to vail out of mismatch. [ruby-list:44114]
-
- * mkconfig.rb, lib/mkmf.rb (configuration): add DEFS.
-
-Sun Jun 8 01:31:17 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * win32/mkexports.rb: deal with __fastcall name decorations.
- [ruby-list:44111]
-
-Sun Jun 8 01:27:06 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * {bcc,win}32/mkexports.rb: explicit data. [ruby-list:44108]
-
-Sun Jun 8 01:15:50 2008 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * lib/net/http.rb, lib/open-uri.rb: remove
- Net::HTTP#enable_post_connection_check. [ruby-dev:31960]
-
- * lib/net/imap.rb: hostname should be verified against server's
- indentity as persented in the server's certificate. [ruby-dev:31960]
-
- * ext/openssl/lib/net/telnets.rb, ext/openssl/lib/net/ftptls.rb: ditto.
-
-Thu Jun 5 16:21:16 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (make_cmdvector): adjust escaped successive
- double-quote handling. (merge from trunk)
-
-Thu Jun 5 12:26:45 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (init_env): initialize HOME and USER environment
- variables unless set. [ruby-core:12328] (merge from trunk)
-
- * win32/win32.c (NtInitialize, getlogin): ditto.
-
- * configure.in, win32/Makefile.sub (LIBS): need to link shell32
- library for SH* functions on mswin32 and mingw32.
-
-Thu Jun 5 12:22:28 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * gc.c (id2ref): valid id should not refer T_VALUE nor T_ICLASS.
- [ruby-dev:31911]
-
-Wed Jun 4 16:41:19 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * Makefile.in (ext/extinit.o): use $(OUTFLAG) as well as other
- objects. [ruby-Bugs-14228]
-
-Tue Jun 3 16:15:27 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y (yyerror): limit error message length. [ruby-dev:31848]
-
- * regex.c (re_mbc_startpos): separated from re_adjust_startpos.
-
-Tue Jun 3 15:45:00 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * gc.c (os_obj_of, os_each_obj): hide objects to be finalized.
- [ruby-dev:31810]
-
-Wed Jun 4 19:16:40 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (remove_method): should not remove undef place holder.
- [ruby-dev:31817]
-
-Tue Jun 3 15:22:47 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * process.c (struct rb_exec_arg): proc should be a VALUE.
-
- * process.c (rb_f_exec): suppress a warning.
-
- * process.c (rb_detach_process): cast for the platforms where size of
- pointer differs from size of int.
-
- * process.c (rb_f_exec, rb_f_system): should not exceptions after
- fork. [ruby-core:08262]
-
-Wed May 21 01:32:56 2008 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * lib/webrick/httpservlet/filehandler.rb: should normalize path
- name in path_info to prevent script disclosure vulnerability on
- DOSISH filesystems. (fix: CVE-2008-1891)
- Note: NTFS/FAT filesystem should not be published by the platforms
- other than Windows. Pathname interpretation (including short
- filename) is less than perfect.
-
- * lib/webrick/httpservlet/abstract.rb
- (WEBrick::HTTPServlet::AbstracServlet#redirect_to_directory_uri):
- should escape the value of Location: header.
-
- * lib/webrick/httpservlet/cgi_runner.rb: accept interpreter
- command line arguments.
-
-Sun May 18 01:57:44 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * file.c (isdirsep): backslash is valid path separator on cygwin too.
- backported from 1.8 HEAD.
-
-Sat May 17 23:53:57 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * file.c (file_expand_path): fix for short file name on Cygwin.
-
-Sat May 17 23:50:29 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * file.c (OpenFile): prevent conflict on Windows.
-
- * file.c (USE_NTFS): fixed merge miss.
-
-Sat May 17 12:36:46 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * file.c (file_expand_path): rb_str_set_len is not backported.
-
-Sat May 17 12:15:48 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * file.c (file_expand_path): support for alternative data stream
- and ignored trailing garbages of NTFS.
-
- * file.c (rb_file_s_basename): ditto.
-
- * file.c (rb_file_s_extname): ditto.
-
-Sat May 17 10:18:44 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * re.c (rb_reg_search): need to free allocated buffer in re_register.
-
-Mon Mar 3 23:34:13 2008 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * lib/webrick/httpservlet/filehandler.rb: should normalize path
- separators in path_info to prevent directory traversal attacks
- on DOSISH platforms.
- reported by Digital Security Research Group [DSECRG-08-026].
-
- * lib/webrick/httpservlet/filehandler.rb: pathnames which have
- not to be published should be checked case-insensitively.
-
-Mon Dec 3 08:13:52 2007 Kouhei Sutou <kou@cozmixng.org>
-
- * test/rss/test_taxonomy.rb, test/rss/test_parser_1.0.rb,
- test/rss/test_image.rb, test/rss/rss-testcase.rb: ensured
- declaring XML namespaces.
-
-Sun Sep 23 21:57:25 2007 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * lib/net/http.rb: an SSL verification (the server hostname should
- be matched with its certificate's commonName) is added.
- this verification can be skipped by
- "Net::HTTP#enable_post_connection_check=(false)".
- suggested by Chris Clark <cclark at isecpartners.com>
-
- * lib/net/open-uri.rb: use Net::HTTP#enable_post_connection_check to
- perform SSL post connection check.
-
- * ext/openssl/lib/openssl/ssl.c
- (OpenSSL::SSL::SSLSocket#post_connection_check): refine error message.
-
-Sun Sep 23 07:49:49 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c, intern.h, ext/thread/thread.c: should not free queue while
- any live threads are waiting. [ruby-dev:30653]
-
-Sun Sep 23 06:05:35 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/stringio/stringio.c (strio_init): separate from strio_initialize
- to share with strio_reopen properly. [ruby-Bugs-13919]
-
-Sun Sep 23 05:42:35 2007 URABE Shyouhei <shyouhei@ruby-lang.org>
-
- * lib/rdoc/options.rb (Options::check_diagram): dot -V output
- changed. [ ruby-Bugs-11978 ], Thanks Florian Frank.
-
-Wed Sep 19 11:13:07 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * bignum.c (bigtrunc): RBIGNUM(x)->len may be zero. out of bound
- access. [ruby-dev:31404]
-
-Mon Sep 17 05:24:13 2007 Sylvain Joyeux <sylvain.joyeux@m4x.org>
-
- * ext/thread/thread.c (lock_mutex): should take care of threads
- not waiting any longer; there cases of a thread raising
- exceptions. [ ruby-Bugs-11901 ]
-
- * test/thread/test_thread.rb (test_mutex_exception_handling):
- test for above.
-
-Mon Sep 17 05:01:55 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * runruby.rb: fix incomplete backport r12339.
-
-Mon Sep 17 04:56:28 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * test/thread/test_thread.rb (test_local_barrier),
- test/thread/lbtest.rb: test for [ruby-dev:30653].
-
-Mon Sep 17 04:52:21 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * ruby.c (proc_options): -W should be allowed in RUBYOPT
- environment variable. [ruby-core:12118]
-
-Mon Sep 17 04:37:10 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * range.c (range_step): fixed integer overflow. [ruby-dev:31763]
-
-Fri Sep 7 17:06:16 2007 Vincent Isambart <vincent.isambart@gmail.com>
-
- * eval.c (rb_thread_start_0): should unset time_thread_alive_p.
- [ruby-talk:257219], [ruby-core:11542], [ruby-dev:31253]
-
-Fri Sep 7 16:39:23 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * array.c (rb_ary_subseq): need integer overflow check.
- [ruby-dev:31736]
-
- * array.c (rb_ary_splice): ditto. [ruby-dev:31737]
-
- * array.c (rb_ary_fill): ditto. [ruby-dev:31738]
-
- * string.c (rb_str_splice): integer overflow for length.
- [ruby-dev:31739]
-
-Fri Sep 7 16:33:23 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * include/ruby/defines.h (flush_register_windows): call "ta 0x03"
- even on Linux/Sparc. [ruby-dev:31674]
-
-Fri Sep 7 16:09:39 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-
- * ext/win32ole/win32ole.c (ole_type_progid, reg_enum_key,
- reg_get_val, ole_wc2mb): fix the bug. Thanks, arton.
- [ruby-dev:31576]
-
-Fri Sep 7 15:50:50 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (mnew): should preserve noex as safe_level.
-
- * eval.c (rb_call0): tighten security check condition..
-
-Fri Sep 7 15:43:43 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/tk/tcltklib.c (Init_tcltklib): use rb_set_end_proc().
-
-Fri Sep 7 15:42:07 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * process.c (detach_process_watcher): should not pass the pointer
- to an auto variable to the thread to be created. pointed and
- fix by KUBO Takehiro <kubo at jiubao.org> [ruby-dev:30618]
-
-Fri Sep 7 15:40:47 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * sample/test.rb, test/ruby/test_system.rb(valid_syntax?): keep
- comment lines first.
-
-Wed Aug 22 12:40:15 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * hash.c (rb_hash_delete_key): delete the entry without calling block.
-
- * hash.c (rb_hash_shift): should consider iter_lev too.
-
- * hash.c (delete_if_i): use rb_hash_delete_key() so that the block
- isn't called twice. [ruby-core:11556]
-
-Sun Arg 12 03:56:30 2007 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * lib/rinda/tuplespace.rb: fix Rinda::TupleSpace keeper thread bug.
- the thread is started too early. [ruby-talk:264062]
-
- * test/rinda/test_rinda.rb: ditto.
-
-Wed Aug 22 12:31:15 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (ac_cv_func_isinf): set yes also on OpenSolaris.
- [ruby-Bugs-12859]
-
-Wed Aug 22 12:30:42 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/rexml/encodings/{ISO-8859-15,CP-1252}.rb: fixed invalid syntax.
-
-Wed Aug 22 12:29:36 2007 Tadayoshi Funaba <tadf@dotrb.org>
-
- * lib/README: fixed a typo.
-
-Wed Aug 22 12:13:54 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/extmk.rb (extmake): save all CONFIG values.
-
- * ext/extmk.rb (extmake): remove mkmf.log at clean, and extconf.h at
- distclean, respectively.
-
- * ext/extmk.rb: remove rdoc at clean, and installed list file at
- distclean, respectively.
-
-Wed Aug 22 11:49:00 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * sprintf.c (rb_f_sprintf): should not check positional number as
- width. [ruby-core:11838]
-
-Wed Aug 22 11:47:11 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * bignum.c (rb_big_aref): check for Bignum index range.
- [ruby-dev:31271]
-
-Wed Aug 22 11:41:44 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * dln.c (conv_to_posix_path): removed.
-
- * ruby.c (rubylib_mangled_path, rubylib_mangled_path2): return
- VALUE instead of a pointer to static buffer.
-
- * ruby.c (push_include_cygwin): fixed buffer overflow.
- [ruby-dev:31297]
-
- * ruby.c (ruby_init_loadpath): not convert built-in paths.
-
-Wed Aug 22 11:39:31 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * intern.h (is_ruby_native_thread): removed since declared as an int
- function in ruby.h already.
-
-Wed Aug 22 11:00:20 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/mkmf.rb (init_mkmf): should remove mkmf.log too.
-
-Wed Aug 22 10:57:50 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/openssl/ossl_config.c (ossl_config_set_section): do not
- initialize aggregations with dynamic values. [ruby-talk:259306]
-
-Wed Aug 22 10:55:00 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (get_backtrace): check the result more.
- [ruby-dev:31261] [ruby-bugs-12398]
-
-Wed Aug 22 10:36:15 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * bignum.c (rb_big_lshift, rb_big_rshift): separated functions
- to get rid of infinite recursion. fixed calculation in edge
- cases. [ruby-dev:31244]
-
- * numeric.c (rb_fix_lshift, rb_fix_rshift): ditto.
-
-Wed Aug 22 10:29:45 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * bignum.c (rb_big_pow): refine overflow check. [ruby-dev:31242]
-
-Wed Aug 22 10:26:59 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * time.c (time_succ): Time#succ should return a time object in the
- same timezone mode to the original. [ruby-talk:260256]
-
-Wed Aug 22 10:24:00 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * numeric.c (fix_pow): integer power calculation: 0**n => 0,
- 1**n => 1, -1**n => 1 (n: even) / -1 (n: odd).
-
- * test/ruby/test_fixnum.rb (TestFixnum::test_pow): update test
- suite. pow(-3, 2^64) gives NaN when pow(3, 2^64) gives Inf.
-
-Wed Aug 22 10:23:01 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/base64.rb (Base64::b64encode): should not specify /o option
- for regular expression. [ruby-dev:31221]
-
-Wed Aug 22 10:20:32 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * sprintf.c (rb_f_sprintf): more checks for format argument.
- [ruby-core:11569], [ruby-core:11570], [ruby-core:11571],
- [ruby-core:11573]
-
-Wed Aug 22 10:13:45 2007 pegacorn <subscriber.jp AT gmail.com>
-
- * ext/digest/digest.c (rb_digest_instance_update,
- rb_digest_instance_finish, rb_digest_instance_reset,
- rb_digest_instance_block_length): %s in rb_raise() expects char*.
- [ruby-dev:31222]
-
- * ext/openssl/ossl.h: include ossl_pkcs5.h. [ruby-dev:31231]
-
- * ext/openssl/ossl_pkcs5.h: new file for PKCS5. [ruby-dev:31231]
-
- * ext/openssl/ossl_x509name.c (ossl_x509name_to_s): use ossl_raise()
- instead of rb_raise(). [ruby-dev:31222]
-
- * ext/sdbm/_sdbm.c: DOSISH platforms need io.h. [ruby-dev:31232]
-
- * ext/syck/syck.h: include stdlib.h for malloc() and free().
- [ruby-dev:31232]
-
- * ext/syck/syck.h (syck_parser_set_input_type): prototype added.
- [ruby-dev:31231]
-
- * win32/win32.c: include mbstring.h for _mbspbrk(). [ruby-dev:31232]
-
- * win32.h (rb_w32_getcwd): prototype added. [ruby-dev:31232]
-
-Wed Aug 22 10:11:59 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * bignum.c (rb_cstr_to_inum): check leading non-digits.
- [ruby-core:11691]
-
-Wed Aug 22 10:07:48 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * bignum.c (rb_big_neg): SIGNED_VALUE isn't in 1.8.
-
- * bignum.c (bigtrunc): do not empty Bignum. [ruby-dev:31229]
-
-Wed Aug 22 10:02:42 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * numeric.c (fix_pow): 0**2 should not raise floating point
- exception. [ruby-dev:31216]
-
-Wed Aug 22 10:01:08 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * win32/win32.c (CreateChild): enclose command line except for
- command.com which can not handle quotes. [ruby-talk:258939]
-
-Wed Aug 22 09:58:30 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/mkmf.rb (link_command, cc_command, cpp_command): do not expand
- ::CONFIG which is an alias of MAKEFILE_CONFIG.
-
-Wed Aug 22 09:55:08 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * struct.c (rb_struct_init_copy): disallow changing the size.
- [ruby-dev:31168]
-
-Wed Aug 22 09:54:28 2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
-
- * random.c: documentation fix. srand(0) initializes PRNG with '0',
- not with random_seed.
-
-Wed Aug 22 09:53:14 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * bcc32/{Makefile.sub,setup.mak}: remove surplus slash from srcdir.
-
-Wed Aug 22 09:46:25 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * sprintf.c (rb_f_sprintf): sign bit extension should not be done
- if FPLUS flag is specified. [ruby-list:39224]
-
-Wed Aug 22 09:41:56 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * array.c (rb_ary_initialize): should call rb_ary_modify() first.
- [ruby-core:11562]
-
-Wed Aug 22 09:40:25 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y (yylex): return non-valid token for an invalid
- instance/class variable name. a patch from from Yusuke ENDOH
- <mame AT tsg.ne.jp>. [ruby-dev:31095]
-
-Wed Aug 22 09:39:26 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y (dsym): return non-null NODE even if yyerror(). based on a
- patch from from Yusuke ENDOH <mame AT tsg.ne.jp>. [ruby-dev:31085]
-
-Wed Aug 22 09:38:43 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * process.c (proc_exec_v, rb_proc_exec): preserve errno.
-
-Wed Aug 22 09:00:23 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (ruby_cleanup): return EXIT_FAILURE if any exceptions occured
- in at_exit blocks. [ruby-core:11263]
-
-Wed Aug 22 08:52:02 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * variable.c (rb_path2class): get rid of dangling pointer caused by
- optimized out value.
-
-Wed Aug 22 08:51:20 2007 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * ext/dl/lib/dl/win32.rb: seems that dl doesn't accept void argument.
- fixed [ruby-bugs:PR#5489].
-
-Wed Aug 22 08:49:47 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (darwin): prohibit loading extension libraries to
- miniruby.
-
-Wed Aug 22 08:34:20 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_kill_thread): renamed in order to get rid of conflict
- with a BeOS system function. [ruby-core:10830]
-
-Wed Aug 22 08:32:32 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * process.c (ruby_setreuid, ruby_setregid): rename to get rid of name
- clash.
-Wed Aug 22 08:27:53 2007 Shugo Maeda <shugo@ruby-lang.org>
-
- * lib/net/imap.rb (ResponseParser#next_token): fixed
- error message. (backported from HEAD)
-
- * lib/net/imap.rb (ResponseParser#parse_error): fixed
- the condition not to refer @token.symbol unexpectedly.
- Thanks, Dick Monahan. (backported from HEAD)
-
-Wed Aug 22 08:26:33 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * marshal.c (w_extended): erroneous check condition when dump
- method is defined. [ruby-core:10646]
-
-Mon Jun 18 11:29:49 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * intern.h, ext/thread/thread.c: moved prototype of rb_thread_status()
- to get rid of error in C++. [ruby-list:43615]
-
-Sun Jun 10 13:47:36 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * test/ruby/test_beginendblock.rb (test_should_propagate_signaled):
- get rid of invoking shell. [ruby-dev:30942]
-
-Sat Jun 9 10:40:00 2007 URABE Shyouhei <shyouhei@ruby-lang.org>
-
- * stable version 1.8.6-p36 released.
-
-Fri Jun 8 17:50:17 2007 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * eval.c (rb_thread_cancel_timer): fix undefined function
-
-Wed May 30 05:17:55 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_eval): get rid of SEGV at ZSUPER in a block
- [ruby-dev:30836]
-
-Wed May 30 04:29:43 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (thread_timer): timer thread should not receive any
- signals. submitted by Sylvain Joyeux. [ruby-core:08546]
-
-Wed May 30 04:18:37 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_eval_cmd): just return if no exceptions.
- [ruby-dev:30820]
-
-Tue May 29 11:01:06 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * win32/win32.c (rb_w32_opendir): store attributes of the second
- entries or later too.
-
- * win32/win32.c (rb_w32_opendir, rb_w32_readdir): eliminate magic
- numbers.
-
-Thu Jun 7 20:10:51 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c, intern.h, ext/thread/thread.c: should not free queue
- while any live threads are waiting.
- [ruby-dev:30653]
-
-Thu Jun 7 14:53:46 2007 URABE Shyouhei <shyouhei@ruby-lang.org>
-
- * eval.c (method_inspect): show proper class name.
- [ruby-talk:248647], Thanks Calamitas.
-
-Sun May 27 05:24:56 2007 URABE Shyouhei <shyouhei@ruby-lang.org>
-
- * runruby.rb: eliminate uninitialized variable.
- [ruby-core:11255]
-
-Sun May 27 05:19:03 2007 URABE Shyouhei <shyouhei@ruby-lang.org>
-
- * eval.c (mnew): call of super via a method object should work again.
- [ruby-talk:248647], Thanks Calamitas.
-
- * test/ruby/test_method.rb (TestMethod::test_method_super): test for
- above fix.
-
-Wed May 23 07:29:53 2007 URABE Shyouhei <shyouhei@ruby-lang.org>
-
- * process.c (proc_exec_v): terminate timer thread in advance.
- [ruby-dev:30581], Thanks H. Holon.
-
-Wed May 23 06:51:46 2007 URABE Shyouhei <shyouhei@ruby-lang.org>
-
- * lib/cgi.rb (CGI#[]): get rid of exceptions being raised.
- [ruby-dev:30740], Thanks Kentaro KAWAMOTO.
-
-Wed May 23 05:49:49 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/extmk.rb, ext/purelib.rb, lib/mkmf.rb, runruby.rb: clear default
- load path to get rid of load pre-installed extensions/libraries.
- [ruby-core:11017]
-
-Wed May 23 06:14:15 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * win32/win32.c (move_to_next_entry): loc also must move forward.
- [ruby-talk:251987]
-
-Wed May 23 05:55:04 2007 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (init_stdhandle): stderr should be without buffering,
- but mswin32 use buffering when stderr is not connected to tty.
-
-Wed May 23 05:35:42 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * bignum.c (rb_big_pow): truncate all zero BDIGITs. [ruby-dev:30733]
-
-Wed May 23 05:17:33 2007 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * ext/iconv/iconv.c (iconv_s_conv): rdoc fix.
-
-Wed May 23 05:10:02 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_thread_priority): rdoc fix; the initial value is
- inherited from the creating thread. [ruby-core:10607]
-
-Wed May 23 04:22:57 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * dir.c (do_stat, do_lstat, do_opendir): should not warn ENOTDIR.
- [ruby-talk:248288]
-
-Wed May 23 03:50:35 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/mkmf.rb (libpathflag): not to append RPATHFLAG to current
- directory.
-
- * lib/mkmf.rb (init_mkmf): add current directory to default
- library path with highest priority. [ruby-core:10960]
-
- * lib/mkmf.rb (LINK_SO): LIBPATH to be placed before DLDFLAGS.
-
-Wed May 23 03:33:55 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/monitor.rb (ConditionVariable#wait, mon_enter, mon_exit_for_cond):
- ensures Thread.critical to be false. [ruby-talk:248300]
-
-Wed May 23 03:25:13 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * util.c (ruby_strtod): exponent is radix 10. [ruby-talk:248272]
-
-Wed May 23 03:12:17 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (LDFLAGS): prepend -L. instead appending it to
- XLDFLAGS. [ruby-core:10933]
-
- * configure.in (Makefile): remove $U for automake from MISSING.
- [ruby-talk:248171]
-
-Wed May 23 02:09:32 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (rb_yield_0): should not clear state on TAG_NEXT when
- it's invoked from within lambda body. [ruby-talk:248136]
-
- * eval.c (proc_invoke): handle TAG_NEXT which would be caused by
- next in the lambda body as well.
-
-Wed May 23 01:55:49 2007 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (rb_w32_fclose, rb_w32_close): need to save errno
- before calling original fclose()/close().
-
-Wed May 23 01:42:29 2007 Shugo Maeda <shugo@ruby-lang.org>
-
- * lib/net/imap.rb (disconnect): call shutdown for
- SSLSocket. Thanks, Technorama Ltd.
-
-Wed May 23 01:28:14 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * error.c (rb_notimplement), io.c (pipe_open): removed definite
- articles and UNIX manual section from messages. [ruby-dev:30690]
-
- * io.c (pipe_open): raise NotImplementedError for command "-" on
- platforms where fork(2) is not available. [ruby-dev:30681]
-
-Wed May 23 00:03:42 2007 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * ext/socket/socket.c (s_recv, s_recvfrom): some systems (such as
- windows) doesn't set fromlen if the socket is connection-oriented.
- reported by Bram Whillock in [ruby-core:10512] [ruby-Bugs#9061]
-
-Sat Mar 24 23:40:29 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * node.h (struct rb_thread.locals): explicit as struct.
- [ruby-core:10585]
-
- * eval.c, node.h (enum rb_thread_status, struct rb_thread,
- rb_curr_thread, rb_main_thread): prefixed. [ruby-core:10586]
-
- * file.c (chompdirsep): made an unprefixed name static.
-
- * io.c (io_fread): ditto.
-
-Tue May 22 23:27:16 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (ruby_cleanup): exit by SystemExit and SignalException in END
- block. [ruby-core:10609]
-
- * test/ruby/test_beginendblock.rb (test_should_propagate_exit_code):
- test for exit in END block. [ruby-core:10760]
-
- * test/ruby/test_beginendblock.rb (test_should_propagate_signaled):
- test for signal in END block.
-
-Tue May 22 23:14:19 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_provided): check for extension library if SOEXT is
- explicitly given. [ruby-dev:30657]
-
-Tue May 22 21:29:08 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * bignum.c (rb_big2str0): round up for the most significant digit.
- [ruby-core:10686]
-
-Tue May 22 20:53:02 2007 Akinori MUSHA <knu@iDaemons.org>
-
- * ext/thread/thread.c (remove_one): Preserve List invariants;
- submitted by: MenTaLguY <mental AT rydia.net>
- in [ruby-core:10598] and [ruby-bugs:PR#9388].
-
-Tue Mar 20 15:37:24 2007 URABE Shyouhei <shyouhei@ruby-lang.org>
-
- * distruby.rb: Add zip generation.
-
Fri Mar 16 21:48:11 2007 Akinori MUSHA <knu@iDaemons.org>
* ext/dl/dl.c (rb_ary2cary): Fix a bug in type validation;
@@ -2276,7 +146,7 @@ Tue Mar 6 19:03:42 2007 Akinori MUSHA <knu@iDaemons.org>
moriq.com> in [ruby-dev:30500].
* ext/digest/lib/sha1.rb (SHA1::new, SHA1::sha1): Ditto.
-
+
* time.c (time_to_s): Back out the format changes; discussed
in [ruby-dev:30495].
@@ -2516,13 +386,13 @@ Mon Feb 19 18:27:42 2007 Akinori MUSHA <knu@iDaemons.org>
[ruby-dev:30023] / [ruby-dev:30239]
Thu Feb 15 20:31:07 2007 Akinori MUSHA <knu@iDaemons.org>
-
+
* lib/uri/ftp.rb: Revert the previous change pending discussion.
-
+
Fri Feb 16 11:18:21 2007 Eric Hodel <drbrain@segment7.net>
* lib/.document: Apply patch for irb, e2mmap and README by Hugh Sasse
- <hgs at dmu.ac.uk> from [ruby-core:10135]
+ <hgs at dmu.ac.uk> from [ruby-core:10135]
* lib/prettyprint.rb: Suppress RDoc for PrettyPrint test suite.
@@ -2640,7 +510,7 @@ Sat Feb 10 07:41:52 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp>
Sat Feb 10 00:13:11 2007 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * ext/tk/lib/tk.rb: fix typo (TkConfigMethod::__confinfo_cmd,
+ * ext/tk/lib/tk.rb: fix typo (TkConfigMethod::__confinfo_cmd,
__conv_keyonly_opts).
Fri Feb 9 20:44:53 2007 Akinori MUSHA <knu@iDaemons.org>
@@ -2720,7 +590,7 @@ Wed Jan 24 18:05:39 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
regexp font-lock bug. [ruby-talk:235758]
Tue Jan 23 11:02:33 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-
+
* lib/webrick/httprequest.rb (WEBrick::HTTPRequest::read_line):
Tue Jan 23 18:26:12 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -2740,8 +610,8 @@ Mon Jan 22 14:57:25 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
Sat Jan 13 23:54:48 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp>
- * ext/win32ole/win32ole.c (ole_free, ole_type_free,
- olemethod_free, olevariable_free, oleparam_free,
+ * ext/win32ole/win32ole.c (ole_free, ole_type_free,
+ olemethod_free, olevariable_free, oleparam_free,
ole_event_free): fix memory leak. [ruby-core:09846]
Fri Jan 12 11:13:55 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
@@ -2771,7 +641,7 @@ Tue Jan 9 03:54:38 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (rb_str_upto): String#upto from empty string makes
inifinite loop. [ruby-core:09864]
-Sun Jan 7 12:13:26 2007 Eric Hodel <drbrain@segment7.net>
+Sun Jan 7 12:13:26 2007 Eric Hodel <drbrain@segment7.net>
* lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser#find_class_comment):
Look for class and module comments above rb_define_class and
@@ -2795,20 +665,20 @@ Wed Jan 3 11:36:51 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
Mon Jan 1 06:13:11 2007 Eric Hodel <drbrain@segment7.net>
* lib/rdoc/parsers/c_parser.rb: Make Rdoc accessible. Update constant
- value information.
+ value information.
Mon Jan 1 06:13:11 2007 Eric Hodel <drbrain@segment7.net>
* ext/bigdecimal/bigdecimal.c: Update constant comments to provide
- values for RDoc.
+ values for RDoc.
Mon Jan 1 06:05:55 2007 Eric Hodel <drbrain@segment7.net>
* lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser#handle_constansts):
- Allow RDoc comment to give friendly value for rb_define_const. Patch
- by Daniel Berger <djberg96 at gmail.com>, [ruby-patches-7499].
+ Allow RDoc comment to give friendly value for rb_define_const. Patch
+ by Daniel Berger <djberg96 at gmail.com>, [ruby-patches-7499].
* lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser#handle_constansts): Fix
- whitespace handling in constant comments.
+ whitespace handling in constant comments.
Sun Dec 31 00:31:16 2006 Tadayoshi Funaba <tadf@dotrb.org>
@@ -4257,7 +2127,7 @@ Thu Jul 13 22:23:56 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
Thu Jul 13 20:32:19 2006 Kouhei Sutou <kou@cozmixng.org>
* lib/rss/parser.rb: updated documents by a patch from
- Hugh Sasse <hgs at dmu.ac.uk>. [ruby-core:8194]
+ Hugh Sasse <hgs at dmu.ac.uk>. [ruby-core:8194]
Wed Jul 12 13:54:09 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -7330,8 +5200,8 @@ Sat Sep 17 09:45:26 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
Sat Sep 17 08:35:39 2005 Kouhei Sutou <kou@cozmixng.org>
* lib/rss/maker/base.rb (RSS::Maker::ItemsBase#normalize): fixed
- strange RSS::Maker::Item#max_size behavior.
- Thanks to Kazuhiko <kazuhiko@fdiary.net>.
+ strange RSS::Maker::Item#max_size behavior.
+ Thanks to Kazuhiko <kazuhiko@fdiary.net>.
* test/rss/test_maker_1.0.rb (RSS::TestMaker10#test_items): ditto.
@@ -10606,7 +8476,7 @@ Wed Feb 2 21:56:01 2005 Kouhei Sutou <kou@cozmixng.org>
Tue Feb 1 22:48:48 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/drb/drb.rb (DRb::DRbObject#respond_to?): check marshal_dump and
- _dump.
+ _dump.
Tue Feb 1 00:20:23 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
@@ -11513,7 +9383,7 @@ Wed Dec 15 18:57:01 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
Wed Dec 15 18:48:42 2004 Shugo Maeda <shugo@ruby-lang.org>
* ext/curses/curses.c (window_subwin): call NUM2INT() before
- GetWINDOW(). (backported from CVS HEAD)
+ GetWINDOW(). (backported from CVS HEAD)
Wed Dec 15 17:03:50 2004 NAKAMURA Usaku <usa@ruby-lang.org>
@@ -12136,7 +10006,7 @@ Thu Nov 18 18:41:08 2004 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
* test/ruby/test_stringchar.rb (test_bang): added.
* string.c (rb_str_upcase_bang, rb_str_capitalize_bang)
- (rb_str_swapcase_bang): missing rb_str_modify(). [ruby-dev:24915]
+ (rb_str_swapcase_bang): missing rb_str_modify(). [ruby-dev:24915]
Thu Nov 18 00:21:15 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -12752,7 +10622,7 @@ Mon Oct 18 15:58:01 2004 NAKAMURA Usaku <usa@ruby-lang.org>
Fri Oct 29 16:34:19 2004 Daiki Ueno <ueno@unixuser.org>
* misc/ruby-mode.el (ruby-parse-partial): Parse the rest of the
- line after opening heredoc identifier. [ruby-dev:24635]
+ line after opening heredoc identifier. [ruby-dev:24635]
Mon Oct 18 07:26:21 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
@@ -12948,7 +10818,7 @@ Mon Oct 4 12:53:45 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
Sun Oct 3 21:20:03 2004 Shugo Maeda <shugo@ruby-lang.org>
* lib/net/imap.rb (TEXT_REGEXP): allow 8-bit characters for the german
- version of Microsoft Exchange Server. (backported from HEAD)
+ version of Microsoft Exchange Server. (backported from HEAD)
* lib/net/imap.rb (RTEXT_REGEXP): ditto.
@@ -13754,9 +11624,9 @@ Sun Jul 18 03:21:42 2004 Akinori MUSHA <knu@iDaemons.org>
Sun Jul 18 03:12:11 2004 Shugo Maeda <shugo@ruby-lang.org>
* lib/net/imap.rb (receive_responses): return if a LOGOUT response
- received. (backported from HEAD)
+ received. (backported from HEAD)
* lib/net/imap.rb (send_string_data): wait command continuation
- requests before sending octet data of literals. (backported from HEAD)
+ requests before sending octet data of literals. (backported from HEAD)
Sat Jul 17 23:54:59 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
@@ -13827,7 +11697,7 @@ Thu Jul 15 23:53:38 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
Thu Jul 15 22:59:48 2004 Shugo Maeda <shugo@ruby-lang.org>
* ext/readline/extconf.rb: added dir_config for curses, ncurses,
- termcap. (backported from HEAD)
+ termcap. (backported from HEAD)
Thu Jul 15 20:29:15 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
@@ -14348,7 +12218,7 @@ Tue Jun 22 21:11:36 2004 Masaki Suketa <masaki.suketa@nifty.ne.jp>
Tue Jun 22 16:47:42 2004 Shugo Maeda <shugo@ruby-lang.org>
* lib/net/ftp.rb (MDTM_REGEXP): fix for demon's ftp server.
- Thanks, Rutger Nijlunsing.
+ Thanks, Rutger Nijlunsing.
Mon Jun 21 10:19:23 2004 NAKAMURA Usaku <usa@ruby-lang.org>
@@ -15620,7 +13490,7 @@ Wed Feb 18 17:18:01 2004 WATANABE Hirofumi <eban@ruby-lang.org>
Wed Feb 18 10:40:38 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* sprintf.c (rb_f_sprintf): do not prepend dots for negative
- numbers if FZERO is specified. [ruby-list:39218]
+ numbers if FZERO is specified. [ruby-dev:39218]
Tue Feb 17 23:40:34 2004 Guy Decoux <ts@moulon.inra.fr>
diff --git a/Makefile.in b/Makefile.in
index 314e1ed256..1e372885b7 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -177,4 +177,4 @@ distclean-local::
@$(RM) ext/config.cache $(RBCONFIG)
ext/extinit.$(OBJEXT): ext/extinit.c $(SETUP)
- $(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(OUTFLAG)$@ -c ext/extinit.c
+ $(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -o$@ -c ext/extinit.c
diff --git a/array.c b/array.c
index 6441d871ed..acc59d20b4 100644
--- a/array.c
+++ b/array.c
@@ -20,7 +20,6 @@ VALUE rb_cArray;
static ID id_cmp;
#define ARY_DEFAULT_SIZE 16
-#define ARY_MAX_SIZE (LONG_MAX / sizeof(VALUE))
void
rb_mem_clear(mem, size)
@@ -121,7 +120,7 @@ ary_new(klass, len)
if (len < 0) {
rb_raise(rb_eArgError, "negative array size (or size too big)");
}
- if (len > ARY_MAX_SIZE) {
+ if (len > 0 && len * sizeof(VALUE) <= len) {
rb_raise(rb_eArgError, "array size too big");
}
if (len == 0) len++;
@@ -273,7 +272,6 @@ rb_ary_initialize(argc, argv, ary)
long len;
VALUE size, val;
- rb_ary_modify(ary);
if (rb_scan_args(argc, argv, "02", &size, &val) == 0) {
RARRAY(ary)->len = 0;
if (rb_block_given_p()) {
@@ -294,9 +292,10 @@ rb_ary_initialize(argc, argv, ary)
if (len < 0) {
rb_raise(rb_eArgError, "negative array size");
}
- if (len > ARY_MAX_SIZE) {
+ if (len > 0 && len * (long)sizeof(VALUE) <= len) {
rb_raise(rb_eArgError, "array size too big");
}
+ rb_ary_modify(ary);
if (len > RARRAY(ary)->aux.capa) {
REALLOC_N(RARRAY(ary)->ptr, VALUE, len);
RARRAY(ary)->aux.capa = len;
@@ -359,9 +358,6 @@ rb_ary_store(ary, idx, val)
idx - RARRAY(ary)->len);
}
}
- else if (idx >= ARY_MAX_SIZE) {
- rb_raise(rb_eIndexError, "index %ld too big", idx);
- }
rb_ary_modify(ary);
if (idx >= RARRAY(ary)->aux.capa) {
@@ -370,10 +366,10 @@ rb_ary_store(ary, idx, val)
if (new_capa < ARY_DEFAULT_SIZE) {
new_capa = ARY_DEFAULT_SIZE;
}
- if (new_capa >= ARY_MAX_SIZE - idx) {
- new_capa = (ARY_MAX_SIZE - idx) / 2;
- }
new_capa += idx;
+ if (new_capa * (long)sizeof(VALUE) <= new_capa) {
+ rb_raise(rb_eArgError, "index too big");
+ }
REALLOC_N(RARRAY(ary)->ptr, VALUE, new_capa);
RARRAY(ary)->aux.capa = new_capa;
}
@@ -610,7 +606,7 @@ rb_ary_subseq(ary, beg, len)
if (beg > RARRAY(ary)->len) return Qnil;
if (beg < 0 || len < 0) return Qnil;
- if (RARRAY(ary)->len < len || RARRAY(ary)->len < beg + len) {
+ if (beg + len > RARRAY(ary)->len) {
len = RARRAY(ary)->len - beg;
if (len < 0)
len = 0;
@@ -965,7 +961,7 @@ rb_ary_splice(ary, beg, len, rpl)
rb_raise(rb_eIndexError, "index %ld out of array", beg);
}
}
- if (RARRAY(ary)->len < len || RARRAY(ary)->len < beg + len) {
+ if (beg + len > RARRAY(ary)->len) {
len = RARRAY(ary)->len - beg;
}
@@ -979,9 +975,6 @@ rb_ary_splice(ary, beg, len, rpl)
rb_ary_modify(ary);
if (beg >= RARRAY(ary)->len) {
- if (beg > ARY_MAX_SIZE - rlen) {
- rb_raise(rb_eIndexError, "index %ld too big", beg);
- }
len = beg + rlen;
if (len >= RARRAY(ary)->aux.capa) {
REALLOC_N(RARRAY(ary)->ptr, VALUE, len);
@@ -1286,7 +1279,7 @@ rb_ary_join(ary, sep)
case T_STRING:
break;
case T_ARRAY:
- if (tmp == ary || rb_inspecting_p(tmp)) {
+ if (rb_inspecting_p(tmp)) {
tmp = rb_str_new2("[...]");
}
else {
@@ -2272,12 +2265,6 @@ rb_ary_fill(argc, argv, ary)
break;
}
rb_ary_modify(ary);
- if (len < 0) {
- return ary;
- }
- if (beg >= ARY_MAX_SIZE || len > ARY_MAX_SIZE - beg) {
- rb_raise(rb_eArgError, "argument too big");
- }
end = beg + len;
if (end > RARRAY(ary)->len) {
if (end >= RARRAY(ary)->aux.capa) {
@@ -2388,7 +2375,7 @@ rb_ary_times(ary, times)
if (len < 0) {
rb_raise(rb_eArgError, "negative argument");
}
- if (ARY_MAX_SIZE/len < RARRAY(ary)->len) {
+ if (LONG_MAX/len < RARRAY(ary)->len) {
rb_raise(rb_eArgError, "argument too big");
}
len *= RARRAY(ary)->len;
@@ -2472,19 +2459,6 @@ rb_ary_rassoc(ary, value)
return Qnil;
}
-static VALUE
-recursive_equal(ary1, ary2)
- VALUE ary1, ary2;
-{
- long i;
-
- for (i=0; i<RARRAY(ary1)->len; i++) {
- if (!rb_equal(rb_ary_elt(ary1, i), rb_ary_elt(ary2, i)))
- return Qfalse;
- }
- return Qtrue;
-}
-
/*
* call-seq:
* array == other_array -> bool
@@ -2503,6 +2477,8 @@ static VALUE
rb_ary_equal(ary1, ary2)
VALUE ary1, ary2;
{
+ long i;
+
if (ary1 == ary2) return Qtrue;
if (TYPE(ary2) != T_ARRAY) {
if (!rb_respond_to(ary2, rb_intern("to_ary"))) {
@@ -2511,18 +2487,8 @@ rb_ary_equal(ary1, ary2)
return rb_equal(ary2, ary1);
}
if (RARRAY(ary1)->len != RARRAY(ary2)->len) return Qfalse;
- if (rb_inspecting_p(ary1)) return Qfalse;
- return rb_protect_inspect(recursive_equal, ary1, ary2);
-}
-
-static VALUE
-recursive_eql(ary1, ary2)
- VALUE ary1, ary2;
-{
- long i;
-
for (i=0; i<RARRAY(ary1)->len; i++) {
- if (!rb_eql(rb_ary_elt(ary1, i), rb_ary_elt(ary2, i)))
+ if (!rb_equal(rb_ary_elt(ary1, i), rb_ary_elt(ary2, i)))
return Qfalse;
}
return Qtrue;
@@ -2540,29 +2506,16 @@ static VALUE
rb_ary_eql(ary1, ary2)
VALUE ary1, ary2;
{
+ long i;
+
if (ary1 == ary2) return Qtrue;
if (TYPE(ary2) != T_ARRAY) return Qfalse;
if (RARRAY(ary1)->len != RARRAY(ary2)->len) return Qfalse;
- if (rb_inspecting_p(ary1)) return Qfalse;
- return rb_protect_inspect(recursive_eql, ary1, ary2);
-}
-
-static VALUE recursive_hash _((VALUE ary));
-
-static VALUE
-recursive_hash(ary)
- VALUE ary;
-{
- long i, h;
- VALUE n;
-
- h = RARRAY(ary)->len;
- for (i=0; i<RARRAY(ary)->len; i++) {
- h = (h << 1) | (h<0 ? 1 : 0);
- n = rb_hash(RARRAY(ary)->ptr[i]);
- h ^= NUM2LONG(n);
+ for (i=0; i<RARRAY(ary1)->len; i++) {
+ if (!rb_eql(rb_ary_elt(ary1, i), rb_ary_elt(ary2, i)))
+ return Qfalse;
}
- return LONG2FIX(h);
+ return Qtrue;
}
/*
@@ -2577,10 +2530,16 @@ static VALUE
rb_ary_hash(ary)
VALUE ary;
{
- if (rb_inspecting_p(ary)) {
- return LONG2FIX(0);
+ long i, h;
+ VALUE n;
+
+ h = RARRAY(ary)->len;
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ h = (h << 1) | (h<0 ? 1 : 0);
+ n = rb_hash(RARRAY(ary)->ptr[i]);
+ h ^= NUM2LONG(n);
}
- return rb_protect_inspect(recursive_hash, ary, 0);
+ return LONG2FIX(h);
}
/*
@@ -2611,24 +2570,6 @@ rb_ary_includes(ary, item)
return Qfalse;
}
-VALUE
-recursive_cmp(ary1, ary2)
- VALUE ary1, ary2;
-{
- long i, len;
-
- len = RARRAY(ary1)->len;
- if (len > RARRAY(ary2)->len) {
- len = RARRAY(ary2)->len;
- }
- for (i=0; i<len; i++) {
- VALUE v = rb_funcall(rb_ary_elt(ary1, i), id_cmp, 1, rb_ary_elt(ary2, i));
- if (v != INT2FIX(0)) {
- return v;
- }
- }
- return Qundef;
-}
/*
* call-seq:
@@ -2654,14 +2595,19 @@ VALUE
rb_ary_cmp(ary1, ary2)
VALUE ary1, ary2;
{
- long len;
- VALUE v;
+ long i, len;
ary2 = to_ary(ary2);
- if (ary1 == ary2) return INT2FIX(0);
- if (rb_inspecting_p(ary1)) return INT2FIX(0);
- v = rb_protect_inspect(recursive_cmp, ary1, ary2);
- if (v != Qundef) return v;
+ len = RARRAY(ary1)->len;
+ if (len > RARRAY(ary2)->len) {
+ len = RARRAY(ary2)->len;
+ }
+ for (i=0; i<len; i++) {
+ VALUE v = rb_funcall(rb_ary_elt(ary1, i), id_cmp, 1, rb_ary_elt(ary2, i));
+ if (v != INT2FIX(0)) {
+ return v;
+ }
+ }
len = RARRAY(ary1)->len - RARRAY(ary2)->len;
if (len == 0) return INT2FIX(0);
if (len > 0) return INT2FIX(1);
diff --git a/bcc32/Makefile.sub b/bcc32/Makefile.sub
index b5546104d0..0c2fe7cdf6 100644
--- a/bcc32/Makefile.sub
+++ b/bcc32/Makefile.sub
@@ -135,7 +135,7 @@ MISSING = acosh.obj crypt.obj erf.obj win32.obj
STACK = 0x2000000
!endif
-XCFLAGS = -DRUBY_EXPORT -I. -I$(srcdir) -I$(srcdir)/missing
+XCFLAGS = -DRUBY_EXPORT -I. -I$(srcdir) -I$(srcdir)missing
ARFLAGS = /a
LD = ilink32 -q -Gn
@@ -154,7 +154,7 @@ PROGRAM=$(RUBY_INSTALL_NAME)$(EXEEXT)
WPROGRAM=$(RUBYW_INSTALL_NAME)$(EXEEXT)
RUBYDEF = $(RUBY_SO_NAME).def
MINIRUBY = .\miniruby$(EXEEXT) $(MINIRUBYOPT)
-RUNRUBY = .\ruby$(EXEEXT) "$(srcdir)/runruby.rb" --extout="$(EXTOUT)" --
+RUNRUBY = .\ruby$(EXEEXT) "$(srcdir)runruby.rb" --extout="$(EXTOUT)" --
ORGLIBPATH = $(LIB)
@@ -174,8 +174,8 @@ INSTALLED_LIST= .installed.list
WINMAINOBJ = winmain.$(OBJEXT)
MINIOBJS = dmydln.$(OBJEXT)
-.path.c = .;$(srcdir);$(srcdir)/win32;$(srcdir)/missing
-.path.h = .;$(srcdir);$(srcdir)/win32;$(srcdir)/missing
+.path.c = .;$(srcdir);$(srcdir)win32;$(srcdir)missing
+.path.h = .;$(srcdir);$(srcdir)win32;$(srcdir)missing
.path.y = $(srcdir)
.path. = $(srcdir)
@@ -183,14 +183,14 @@ MINIOBJS = dmydln.$(OBJEXT)
$(CC) $(CFLAGS) $(XCFLAGS) -I. $(CPPFLAGS) -c $(<:/=\)
.rc.res:
- $(RC) $(RFLAGS) -I. -I$(<D). $(iconinc) -I$(srcdir)/win32 $(RFLAGS) -fo$@ $(<:/=\)
+ $(RC) $(RFLAGS) -I. -I$(<D). $(iconinc) -I$(srcdir)win32 $(RFLAGS) -fo$@ $(<:/=\)
.y.c:
$(YACC) $(YFLAGS) $(<:\=/)
sed -e "s!^ *extern char \*getenv();!/* & */!;s/^\(#.*\)y\.tab/\1parse/" y.tab.c > $(@F)
@del y.tab.c
-all: $(srcdir)/bcc32/Makefile.sub $(srcdir)/common.mk
+all: $(srcdir)bcc32/Makefile.sub $(srcdir)common.mk
ruby: $(PROGRAM)
rubyw: $(WPROGRAM)
@@ -205,8 +205,8 @@ config: config.status
config.status: $(CONFIG_H)
-$(CONFIG_H): $(MKFILES) $(srcdir)/bcc32/Makefile.sub
- @$(srcdir:/=\)\win32\ifchange.bat config.h &&|
+$(CONFIG_H): $(MKFILES) $(srcdir)bcc32/Makefile.sub
+ @$(srcdir:/=\)win32\ifchange.bat config.h &&|
\#define HAVE_SYS_TYPES_H 1
\#define HAVE_SYS_STAT_H 1
\#define HAVE_STDLIB_H 1
@@ -286,7 +286,7 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/bcc32/Makefile.sub
|
@exit > $@
-config.status: $(MKFILES) $(srcdir)/bcc32/Makefile.sub $(srcdir)/common.mk
+config.status: $(MKFILES) $(srcdir)bcc32/Makefile.sub $(srcdir)common.mk
@echo Creating $@
@type > $@ &&|
# Generated automatically by Makefile.sub.
@@ -388,7 +388,7 @@ s,@COMPILE_CXX@,$$(CXX) $$(INCFLAGS) $$(CXXFLAGS) $$(CPPFLAGS) -P -c $$(<:/=\),;
s,@COMPILE_RULES@,{$$(srcdir)}.%s{}.%s: {$$(topdir)}.%s{}.%s: {$$(hdrdir)}.%s{}.%s: .%s.%s:,;t t
s,@RULE_SUBST@,{.;$$(VPATH)}%s,;t t
s,@COMMON_LIBS@,m advapi32 avicap32 avifil32 cap comctl32 comdlg32 dlcapi gdi32 glu32 imagehlp imm32 inetmib1 kernel32 loadperf lsapi32 lz32 mapi32 mgmtapi mpr msacm32 msvfw32 nddeapi netapi32 ole32 oleaut32 oledlg olepro32 opengl32 pdh pkpd32 rasapi32 rasdlg rassapi rpcrt4 setupapi shell32 shfolder snmpapi sporder tapi32 url user32 vdmdbg version win32spl winmm wintrust wsock32,;t t
-s,@COMMON_MACROS@,WIN32_LEAN_AND_MEAN WIN32,;t t
+s,@COMMON_MACROS@,WIN32_LEAN_AND_MEAN,;t t
s,@COMMON_HEADERS@,winsock2.h windows.h,;t t
s,@TRY_LINK@,$$(CC) -oconftest $$(INCFLAGS) -I$$(hdrdir) $$(CPPFLAGS) $$(CFLAGS) $$(LIBPATH) $$(LDFLAGS) $$(src) $$(LOCAL_LIBS) $$(LIBS),;t t
s,@EXPORT_PREFIX@,_,;t t
@@ -426,14 +426,14 @@ $(LIBRUBY_SO): $(LIBRUBY_A) $(DLDOBJS) $(RUBYDEF) $(RUBY_SO_NAME).res
$(LIBRUBY): $(LIBRUBY_SO)
$(RUBYDEF): $(LIBRUBY_A) $(PREP)
- $(MINIRUBY) $(srcdir)/bcc32/mkexports.rb -output=$@ -base=$(RUBY_SO_NAME) $(LIBRUBY_A)
+ $(MINIRUBY) $(srcdir)bcc32/mkexports.rb -output=$@ -base=$(RUBY_SO_NAME) $(LIBRUBY_A)
$(RUBY_INSTALL_NAME).rc $(RUBYW_INSTALL_NAME).rc $(RUBY_SO_NAME).rc: rbconfig.rb
- @$(MINIRUBY) $(srcdir)/win32/resource.rb \
+ @$(MINIRUBY) $(srcdir)win32/resource.rb \
-ruby_name=$(RUBY_INSTALL_NAME) \
-rubyw_name=$(RUBYW_INSTALL_NAME) \
-so_name=$(RUBY_SO_NAME) \
- . $(icondirs) $(srcdir)/win32
+ . $(icondirs) $(srcdir)win32
post-install-bin::
@$(NULLCMD)
diff --git a/bcc32/setup.mak b/bcc32/setup.mak
index b7a2539d0a..1c922c208f 100644
--- a/bcc32/setup.mak
+++ b/bcc32/setup.mak
@@ -1,13 +1,13 @@
# -*- makefile -*-
!if "$(srcdir)" != ""
-bcc32dir = $(srcdir)/bcc32
+bcc32dir = $(srcdir)bcc32/
!elseif "$(bcc32dir)" == "bcc32/"
-srcdir = .
+srcdir = ./
!elseif "$(bcc32dir:/bcc32/=)/bcc32/" == "$(bcc32dir)"
-srcdir = $(bcc32dir:/bcc32/=)
+srcdir = $(bcc32dir:/bcc32/=/)
!else
-srcdir = $(bcc32dir)/..
+srcdir = $(bcc32dir)../
!endif
!ifndef prefix
prefix = /usr
@@ -62,7 +62,7 @@ if exist usebormm.tds echo MEMLIB = usebormm.lib
@usebormm.bat >> $(MAKEFILE)
@del usebormm.*
- @cpp32 -I$(srcdir) -P- -o$(MAKEFILE) > nul &&|
+ @cpp32 -I$(srcdir) -DRUBY_EXTERN="//" -P- -o$(MAKEFILE) > nul &&|
\#include "version.h"
MAJOR = RUBY_VERSION_MAJOR
MINOR = RUBY_VERSION_MINOR
@@ -122,12 +122,12 @@ $(BANG)endif
\# RUBY_INSTALL_NAME = ruby
\# RUBY_SO_NAME = $$(RT)-$$(RUBY_INSTALL_NAME)$$(MAJOR)$$(MINOR)
\# CFLAGS = -q $$(DEBUGFLAGS) $$(OPTFLAGS) $$(PROCESSOR_FLAG) -w- -wsus -wcpt -wdup -wext -wrng -wrpt -wzdi
-\# CPPFLAGS = -I. -I$$(srcdir) -I$$(srcdir)/missing -DLIBRUBY_SO=\"$$(LIBRUBY_SO)\"
+\# CPPFLAGS = -I. -I$$(srcdir) -I$$(srcdir)missing -DLIBRUBY_SO=\"$$(LIBRUBY_SO)\"
\# STACK = 0x2000000
\# LDFLAGS = -S:$$(STACK)
\# RFLAGS = $$(iconinc)
\# EXTLIBS = cw32.lib import32.lib user32.lib kernel32.lib
-$(BANG)include $$(srcdir)/bcc32/Makefile.sub
+$(BANG)include $$(srcdir)bcc32/Makefile.sub
|
@$(srcdir:/=\)\win32\rm.bat config.h config.status
@echo type "`$(MAKE)'" to make ruby for $(OS).
diff --git a/bignum.c b/bignum.c
index c23b76b1fe..cc3dd1e5c3 100644
--- a/bignum.c
+++ b/bignum.c
@@ -11,7 +11,6 @@
**********************************************************************/
#include "ruby.h"
-#include "rubysig.h"
#include <math.h>
#include <ctype.h>
@@ -37,21 +36,7 @@ VALUE rb_cBignum;
#define BIGLO(x) ((BDIGIT)((x) & (BIGRAD-1)))
#define BDIGMAX ((BDIGIT)-1)
-#define BIGZEROP(x) (RBIGNUM(x)->len == 0 || \
- (BDIGITS(x)[0] == 0 && \
- (RBIGNUM(x)->len == 1 || bigzero_p(x))))
-
-static int bigzero_p(VALUE);
-static int
-bigzero_p(x)
- VALUE x;
-{
- long i;
- for (i = 0; i < RBIGNUM(x)->len; ++i) {
- if (BDIGITS(x)[i]) return 0;
- }
- return 1;
-}
+#define BIGZEROP(x) (RBIGNUM(x)->len == 0 || (RBIGNUM(x)->len == 1 && BDIGITS(x)[0] == 0))
static VALUE
bignew_1(klass, len, sign)
@@ -89,7 +74,6 @@ get2comp(x)
BDIGIT *ds = BDIGITS(x);
BDIGIT_DBL num;
- if (!i) return;
while (i--) ds[i] = ~ds[i];
i = 0; num = 1;
do {
@@ -112,50 +96,35 @@ rb_big_2comp(x) /* get 2's complement */
}
static VALUE
-bigtrunc(x)
+bignorm(x)
VALUE x;
{
- long len = RBIGNUM(x)->len;
- BDIGIT *ds = BDIGITS(x);
-
- if (len == 0) return x;
- while (--len && !ds[len]);
- RBIGNUM(x)->len = ++len;
- return x;
-}
+ if (FIXNUM_P(x)) {
+ return x;
+ }
+ else if (TYPE(x) == T_BIGNUM) {
+ long len = RBIGNUM(x)->len;
+ BDIGIT *ds = BDIGITS(x);
-static VALUE
-bigfixize(VALUE x)
-{
- long len = RBIGNUM(x)->len;
- BDIGIT *ds = BDIGITS(x);
+ while (len-- && !ds[len]) ;
+ RBIGNUM(x)->len = ++len;
- if (len*SIZEOF_BDIGITS <= sizeof(VALUE)) {
- long num = 0;
- while (len--) {
- num = BIGUP(num) + ds[len];
- }
- if (num >= 0) {
- if (RBIGNUM(x)->sign) {
- if (POSFIXABLE(num)) return LONG2FIX(num);
+ if (len*SIZEOF_BDIGITS <= sizeof(VALUE)) {
+ long num = 0;
+ while (len--) {
+ num = BIGUP(num) + ds[len];
}
- else {
- if (NEGFIXABLE(-(long)num)) return LONG2FIX(-(long)num);
+ if (num >= 0) {
+ if (RBIGNUM(x)->sign) {
+ if (POSFIXABLE(num)) return LONG2FIX(num);
+ }
+ else if (NEGFIXABLE(-(long)num)) return LONG2FIX(-(long)num);
}
}
}
return x;
}
-static VALUE
-bignorm(VALUE x)
-{
- if (!FIXNUM_P(x) && TYPE(x) == T_BIGNUM) {
- x = bigfixize(bigtrunc(x));
- }
- return x;
-}
-
VALUE
rb_big_norm(x)
VALUE x;
@@ -362,13 +331,6 @@ rb_cstr_to_inum(str, base, badcheck)
VALUE z;
BDIGIT *zds;
-#define conv_digit(c) \
- (!ISASCII(c) ? -1 : \
- isdigit(c) ? ((c) - '0') : \
- islower(c) ? ((c) - 'a' + 10) : \
- isupper(c) ? ((c) - 'A' + 10) : \
- -1)
-
if (!str) {
if (badcheck) goto bad;
return INT2FIX(0);
@@ -461,13 +423,7 @@ rb_cstr_to_inum(str, base, badcheck)
}
if (*str == '0') { /* squeeze preceeding 0s */
while (*++str == '0');
- if (!(c = *str) || ISSPACE(c)) --str;
- }
- c = *str;
- c = conv_digit(c);
- if (c < 0 || c >= base) {
- if (badcheck) goto bad;
- return INT2FIX(0);
+ --str;
}
len *= strlen(str)*sizeof(char);
@@ -501,7 +457,7 @@ rb_cstr_to_inum(str, base, badcheck)
z = bignew(len, sign);
zds = BDIGITS(z);
for (i=len;i--;) zds[i]=0;
- while ((c = *str++) != 0) {
+ while (c = *str++) {
if (c == '_') {
if (badcheck) {
if (nondigit) goto bad;
@@ -509,7 +465,19 @@ rb_cstr_to_inum(str, base, badcheck)
}
continue;
}
- else if ((c = conv_digit(c)) < 0) {
+ else if (!ISASCII(c)) {
+ break;
+ }
+ else if (isdigit(c)) {
+ c -= '0';
+ }
+ else if (islower(c)) {
+ c -= 'a' - 10;
+ }
+ else if (isupper(c)) {
+ c -= 'A' - 10;
+ }
+ else {
break;
}
if (c >= base) break;
@@ -667,9 +635,6 @@ rb_big2str0(x, base, trim)
if (BIGZEROP(x)) {
return rb_str_new2("0");
}
- if (i >= LONG_MAX/SIZEOF_BDIGITS/CHAR_BIT) {
- rb_raise(rb_eRangeError, "bignum too big to convert into `string'");
- }
j = SIZEOF_BDIGITS*CHAR_BIT*i;
switch (base) {
case 2: break;
@@ -677,10 +642,10 @@ rb_big2str0(x, base, trim)
j = j * 53L / 84 + 1;
break;
case 4: case 5: case 6: case 7:
- j = (j + 1) / 2;
+ j /= 2;
break;
case 8: case 9:
- j = (j + 2) / 3;
+ j /= 3;
break;
case 10: case 11: case 12: case 13: case 14: case 15:
j = j * 28L / 93 + 1;
@@ -688,10 +653,10 @@ rb_big2str0(x, base, trim)
case 16: case 17: case 18: case 19: case 20: case 21:
case 22: case 23: case 24: case 25: case 26: case 27:
case 28: case 29: case 30: case 31:
- j = (j + 3) / 4;
+ j /= 4;
break;
case 32: case 33: case 34: case 35: case 36:
- j = (j + 4) / 5;
+ j /= 5;
break;
default:
rb_raise(rb_eArgError, "illegal radix %d", base);
@@ -710,7 +675,6 @@ rb_big2str0(x, base, trim)
s = RSTRING(ss)->ptr;
s[0] = RBIGNUM(x)->sign ? '+' : '-';
- TRAP_BEG;
while (i && j > 1) {
long k = i;
BDIGIT_DBL num = 0;
@@ -725,7 +689,7 @@ rb_big2str0(x, base, trim)
while (k--) {
s[--j] = ruby_digitmap[num % base];
num /= base;
- if (!trim && j <= 1) break;
+ if (!trim && j < 1) break;
if (trim && i == 0 && num == 0) break;
}
}
@@ -740,7 +704,6 @@ rb_big2str0(x, base, trim)
RSTRING(ss)->len = i;
}
s[RSTRING(ss)->len] = '\0';
- TRAP_END;
return ss;
}
@@ -1109,7 +1072,6 @@ rb_big_neg(x)
if (!RBIGNUM(x)->sign) get2comp(z);
ds = BDIGITS(z);
i = RBIGNUM(x)->len;
- if (!i) return INT2FIX(~0);
while (i--) ds[i] = ~ds[i];
RBIGNUM(z)->sign = !RBIGNUM(z)->sign;
if (RBIGNUM(x)->sign) get2comp(z);
@@ -1565,20 +1527,6 @@ rb_big_remainder(x, y)
return bignorm(z);
}
-static VALUE big_lshift _((VALUE, unsigned long));
-static VALUE big_rshift _((VALUE, unsigned long));
-
-static VALUE big_shift(x, n)
- VALUE x;
- int n;
-{
- if (n < 0)
- return big_lshift(x, (unsigned int)n);
- else if (n > 0)
- return big_rshift(x, (unsigned int)n);
- return x;
-}
-
/*
* call-seq:
* big.divmod(numeric) => array
@@ -1681,10 +1629,8 @@ rb_big_pow(x, y)
yy = FIX2LONG(y);
if (yy > 0) {
VALUE z = x;
- const long BIGLEN_LIMIT = 1024*1024 / SIZEOF_BDIGITS;
- if ((RBIGNUM(x)->len > BIGLEN_LIMIT) ||
- (RBIGNUM(x)->len > BIGLEN_LIMIT / yy)) {
+ if (RBIGNUM(x)->len * SIZEOF_BDIGITS * yy > 1024*1024) {
rb_warn("in a**b, b may be too big");
d = (double)yy;
break;
@@ -1695,10 +1641,10 @@ rb_big_pow(x, y)
while (yy % 2 == 0) {
yy /= 2;
x = rb_big_mul0(x, x);
- bigtrunc(x);
+ if (!BDIGITS(x)[RBIGNUM(x)->len-1]) RBIGNUM(x)->len--;
}
z = rb_big_mul0(z, x);
- bigtrunc(z);
+ if (!BDIGITS(z)[RBIGNUM(z)->len-1]) RBIGNUM(z)->len--;
}
return bignorm(z);
}
@@ -1884,15 +1830,7 @@ rb_big_xor(xx, yy)
return bignorm(z);
}
-static VALUE
-check_shiftdown(VALUE y, VALUE x)
-{
- if (!RBIGNUM(x)->len) return INT2FIX(0);
- if (RBIGNUM(y)->len > SIZEOF_LONG / SIZEOF_BDIGITS) {
- return RBIGNUM(x)->sign ? INT2FIX(0) : INT2FIX(-1);
- }
- return Qnil;
-}
+static VALUE rb_big_rshift _((VALUE,VALUE));
/*
* call-seq:
@@ -1905,46 +1843,15 @@ VALUE
rb_big_lshift(x, y)
VALUE x, y;
{
- long shift;
- int neg = 0;
-
- for (;;) {
- if (FIXNUM_P(y)) {
- shift = FIX2LONG(y);
- if (shift < 0) {
- neg = 1;
- shift = -shift;
- }
- break;
- }
- else if (TYPE(y) == T_BIGNUM) {
- if (!RBIGNUM(y)->sign) {
- VALUE t = check_shiftdown(y, x);
- if (!NIL_P(t)) return t;
- neg = 1;
- }
- shift = big2ulong(y, "long", Qtrue);
- break;
- }
- y = rb_to_int(y);
- }
-
- if (neg) return big_rshift(x, shift);
- return big_lshift(x, shift);
-}
-
-static VALUE
-big_lshift(x, shift)
- VALUE x;
- unsigned long shift;
-{
BDIGIT *xds, *zds;
- long s1 = shift/BITSPERDIG;
+ int shift = NUM2INT(y);
+ int s1 = shift/BITSPERDIG;
int s2 = shift%BITSPERDIG;
VALUE z;
BDIGIT_DBL num = 0;
long len, i;
+ if (shift < 0) return rb_big_rshift(x, INT2FIX(-shift));
len = RBIGNUM(x)->len;
z = bignew(len+s1+1, RBIGNUM(x)->sign);
zds = BDIGITS(z);
@@ -1968,53 +1875,21 @@ big_lshift(x, shift)
* Shifts big right _numeric_ positions (left if _numeric_ is negative).
*/
-VALUE
+static VALUE
rb_big_rshift(x, y)
VALUE x, y;
{
- long shift;
- int neg = 0;
-
- for (;;) {
- if (FIXNUM_P(y)) {
- shift = FIX2LONG(y);
- if (shift < 0) {
- neg = 1;
- shift = -shift;
- }
- break;
- }
- else if (TYPE(y) == T_BIGNUM) {
- if (RBIGNUM(y)->sign) {
- VALUE t = check_shiftdown(y, x);
- if (!NIL_P(t)) return t;
- }
- else {
- neg = 1;
- }
- shift = big2ulong(y, "long", Qtrue);
- break;
- }
- y = rb_to_int(y);
- }
-
- if (neg) return big_lshift(x, shift);
- return big_rshift(x, shift);
-}
-
-static VALUE
-big_rshift(x, shift)
- VALUE x;
- unsigned long shift;
-{
BDIGIT *xds, *zds;
+ int shift = NUM2INT(y);
long s1 = shift/BITSPERDIG;
- int s2 = shift%BITSPERDIG;
+ long s2 = shift%BITSPERDIG;
VALUE z;
BDIGIT_DBL num = 0;
long i, j;
volatile VALUE save_x;
+ if (shift < 0) return rb_big_lshift(x, INT2FIX(-shift));
+
if (s1 > RBIGNUM(x)->len) {
if (RBIGNUM(x)->sign)
return INT2FIX(0);
@@ -2071,39 +1946,29 @@ rb_big_aref(x, y)
VALUE x, y;
{
BDIGIT *xds;
- BDIGIT_DBL num;
- unsigned long shift;
- long i, s1, s2;
+ int shift;
+ long s1, s2;
if (TYPE(y) == T_BIGNUM) {
- if (!RBIGNUM(y)->sign)
+ if (!RBIGNUM(y)->sign || RBIGNUM(x)->sign)
return INT2FIX(0);
- if (RBIGNUM(bigtrunc(y))->len > SIZEOF_LONG/SIZEOF_BDIGITS) {
- out_of_range:
- return RBIGNUM(x)->sign ? INT2FIX(0) : INT2FIX(1);
- }
- shift = big2ulong(y, "long", Qfalse);
- }
- else {
- i = NUM2LONG(y);
- if (i < 0) return INT2FIX(0);
- shift = (VALUE)i;
+ return INT2FIX(1);
}
+ shift = NUM2INT(y);
+ if (shift < 0) return INT2FIX(0);
s1 = shift/BITSPERDIG;
s2 = shift%BITSPERDIG;
- if (s1 >= RBIGNUM(x)->len) goto out_of_range;
if (!RBIGNUM(x)->sign) {
- xds = BDIGITS(x);
- i = 0; num = 1;
- while (num += ~xds[i], ++i <= s1) {
- num = BIGDN(num);
- }
+ if (s1 >= RBIGNUM(x)->len) return INT2FIX(1);
+ x = rb_big_clone(x);
+ get2comp(x);
}
else {
- num = BDIGITS(x)[s1];
+ if (s1 >= RBIGNUM(x)->len) return INT2FIX(0);
}
- if (num & ((BDIGIT_DBL)1<<s2))
+ xds = BDIGITS(x);
+ if (xds[s1] & (1<<s2))
return INT2FIX(1);
return INT2FIX(0);
}
diff --git a/class.c b/class.c
index 80f57a1622..80dc9e4b2d 100644
--- a/class.c
+++ b/class.c
@@ -48,26 +48,13 @@ rb_class_new(super)
return rb_class_boot(super);
}
-struct clone_method_data {
- st_table *tbl;
- VALUE klass;
-};
-
static int
-clone_method(mid, body, data)
+clone_method(mid, body, tbl)
ID mid;
NODE *body;
- struct clone_method_data *data;
+ st_table *tbl;
{
- NODE *fbody = body->nd_body;
-
- if (fbody && nd_type(fbody) == NODE_SCOPE) {
- NODE *cref = (NODE*)fbody->nd_rval;
-
- if (cref) cref = cref->nd_next;
- fbody = rb_copy_node_scope(fbody, NEW_CREF(data->klass, cref));
- }
- st_insert(data->tbl, mid, (st_data_t)NEW_METHOD(fbody, body->nd_noex));
+ st_insert(tbl, mid, (st_data_t)NEW_METHOD(body->nd_body, body->nd_noex));
return ST_CONTINUE;
}
@@ -78,8 +65,7 @@ rb_mod_init_copy(clone, orig)
{
rb_obj_init_copy(clone, orig);
if (!FL_TEST(CLASS_OF(clone), FL_SINGLETON)) {
- RBASIC(clone)->klass = RBASIC(orig)->klass;
- RBASIC(clone)->klass = rb_singleton_class_clone(clone);
+ RBASIC(clone)->klass = rb_singleton_class_clone(orig);
}
RCLASS(clone)->super = RCLASS(orig)->super;
if (RCLASS(orig)->iv_tbl) {
@@ -92,12 +78,9 @@ rb_mod_init_copy(clone, orig)
st_delete(RCLASS(clone)->iv_tbl, (st_data_t*)&id, 0);
}
if (RCLASS(orig)->m_tbl) {
- struct clone_method_data data;
-
- data.tbl = RCLASS(clone)->m_tbl = st_init_numtable();
- data.klass = (VALUE)clone;
-
- st_foreach(RCLASS(orig)->m_tbl, clone_method, (st_data_t)&data);
+ RCLASS(clone)->m_tbl = st_init_numtable();
+ st_foreach(RCLASS(orig)->m_tbl, clone_method,
+ (st_data_t)RCLASS(clone)->m_tbl);
}
return clone;
@@ -143,22 +126,9 @@ rb_singleton_class_clone(obj)
if (RCLASS(klass)->iv_tbl) {
clone->iv_tbl = st_copy(RCLASS(klass)->iv_tbl);
}
- {
- struct clone_method_data data;
-
- data.tbl = clone->m_tbl = st_init_numtable();
- switch (TYPE(obj)) {
- case T_CLASS:
- case T_MODULE:
- data.klass = obj;
- break;
- default:
- data.klass = 0;
- break;
- }
-
- st_foreach(RCLASS(klass)->m_tbl, clone_method, (st_data_t)&data);
- }
+ clone->m_tbl = st_init_numtable();
+ st_foreach(RCLASS(klass)->m_tbl, clone_method,
+ (st_data_t)clone->m_tbl);
rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone);
FL_SET(clone, FL_SINGLETON);
return (VALUE)clone;
diff --git a/common.mk b/common.mk
index 6d5b35dee6..f751fecfb5 100644
--- a/common.mk
+++ b/common.mk
@@ -341,8 +341,7 @@ array.$(OBJEXT): {$(VPATH)}array.c {$(VPATH)}ruby.h config.h \
{$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
{$(VPATH)}util.h {$(VPATH)}st.h
bignum.$(OBJEXT): {$(VPATH)}bignum.c {$(VPATH)}ruby.h config.h \
- {$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
- {$(VPATH)}rubysig.h
+ {$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h
class.$(OBJEXT): {$(VPATH)}class.c {$(VPATH)}ruby.h config.h \
{$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
{$(VPATH)}rubysig.h {$(VPATH)}node.h {$(VPATH)}st.h
diff --git a/configure.in b/configure.in
index ae4b67c280..950ee8ac4f 100644
--- a/configure.in
+++ b/configure.in
@@ -149,11 +149,6 @@ if test x"${build}" != x"${host}"; then
fi
AC_PROG_CC
AC_PROG_GCC_TRADITIONAL
-if test "$GCC" = yes; then
- linker_flag=-Wl,
-else
- linker_flag=
-fi
RUBY_PROG_GNU_LD
RUBY_CPPOUTFILE
@@ -234,12 +229,7 @@ else
fi
dnl check for large file stuff
-mv confdefs.h confdefs1.h
-: > confdefs.h
AC_SYS_LARGEFILE
-mv confdefs.h largefile.h
-mv confdefs1.h confdefs.h
-cat largefile.h >> confdefs.h
AC_CHECK_TYPES([long long, off_t])
@@ -377,13 +367,16 @@ human*) ac_cv_func_getpgrp_void=yes
ac_cv_func_setitimer=no
;;
beos*) ac_cv_func_link=no;;
-cygwin*) ;;
+cygwin*) rb_cv_have_daylight=no
+ ac_cv_var_tzname=no
+ ac_cv_func__setjmp=no
+ ac_cv_func_setitimer=no
+ ;;
mingw*) if test "$with_winsock2" = yes; then
LIBS="-lws2_32 $LIBS"
else
LIBS="-lwsock32 $LIBS"
fi
- LIBS="-lshell32 $LIBS"
ac_cv_header_a_out_h=no
ac_cv_header_pwd_h=no
ac_cv_header_utime_h=no
@@ -462,17 +455,16 @@ bow) ac_cv_func_setitimer=no
;;
superux*) ac_cv_func_setitimer=no
;;
-solaris*2.1*) if test -z "$GCC"; then
- ac_cv_func_isinf=yes
+solaris*2.10) if test -z "$GCC"; then
+ ac_cv_func_isinf=yes
fi
- LIBS="-lm $LIBS"
+ LIBS="-lm $LIBS"
;;
*) LIBS="-lm $LIBS";;
esac
AC_CHECK_LIB(crypt, crypt)
AC_CHECK_LIB(dl, dlopen) # Dynamic linking for SunOS/Solaris and SYSV
AC_CHECK_LIB(dld, shl_load) # Dynamic linking for HP-UX
-AC_CHECK_LIB(rt, clock_gettime) # GNU/Linux
case "$target_cpu" in
alpha*) case "$target_os"::"$GCC" in
@@ -531,40 +523,18 @@ esac
AC_FUNC_MEMCMP
AC_FUNC_FSEEKO
AC_CHECK_FUNCS(ftello)
-
-# http://sources.redhat.com/ml/libc-hacker/2005-08/msg00008.html
-# Debian GNU/Linux Etch's libc6.1 2.3.6.ds1-13etch5 has this problem.
-# Debian GNU/Linux Lenny's libc6.1 2.7-10 has no problem.
-AC_CACHE_CHECK(for broken erfc of glibc-2.3.6 on IA64, rb_cv_broken_glibc_ia64_erfc,
- [AC_TRY_RUN([
-#include <math.h>
-int
-main()
-{
- erfc(10000.0);
- return 0;
-}
-],
- rb_cv_broken_glibc_ia64_erfc=no,
- rb_cv_broken_glibc_ia64_erfc=yes,
- rb_cv_broken_glibc_ia64_erfc=no)])
-case $rb_cv_broken_glibc_ia64_erfc in
- yes) ac_cv_func_erf=no;;
-esac
-
AC_REPLACE_FUNCS(dup2 memmove strcasecmp strncasecmp strerror strftime\
strchr strstr strtoul crypt flock vsnprintf\
isnan finite isinf hypot acosh erf)
AC_CHECK_FUNCS(fmod killpg wait4 waitpid syscall chroot fsync getcwd eaccess\
- truncate ftruncate chsize times utimes fcntl lockf lstat symlink link\
+ truncate chsize times utimes fcntl lockf lstat symlink link\
readlink setitimer setruid seteuid setreuid setresuid\
setproctitle setrgid setegid setregid setresgid issetugid pause\
lchown lchmod getpgrp setpgrp getpgid setpgid initgroups\
getgroups setgroups getpriority getrlimit setrlimit sysconf\
- group_member dlopen sigprocmask\
- sigaction _setjmp setsid telldir seekdir fchmod\
- mktime timegm gettimeofday\
- cosh sinh tanh round setuid setgid setenv unsetenv)
+ dlopen sigprocmask\
+ sigaction _setjmp setsid telldir seekdir fchmod mktime timegm\
+ cosh sinh tanh setuid setgid setenv unsetenv)
AC_ARG_ENABLE(setreuid,
[ --enable-setreuid use setreuid()/setregid() according to need even if obsolete.],
[use_setreuid=$enableval])
@@ -590,42 +560,6 @@ AC_CACHE_CHECK(for external int daylight, rb_cv_have_daylight,
if test "$rb_cv_have_daylight" = yes; then
AC_DEFINE(HAVE_DAYLIGHT)
fi
-AC_DEFUN([RUBY_CHECK_VARTYPE], [dnl
-AC_CACHE_CHECK([for external $1], rb_cv_var_$1,
- [rb_cv_var_$1=no
- AC_TRY_COMPILE([#define _XOPEN_SOURCE 1
- $2
- const volatile void *volatile t;],
- [t = &(&$1)[0];],
- [for t in $3; do
- AC_TRY_COMPILE([#define _XOPEN_SOURCE 1
- $2
- extern $t $1;
- const volatile void *volatile t;],
- [t = &(&$1)[0];],
- [rb_cv_var_$1=$t; break])
- done])])
-if test "[$rb_cv_var_]$1" != no; then
- AC_DEFINE([HAVE_VAR_]m4_toupper($1))
- AC_DEFINE_UNQUOTED([TYPEOF_VAR_]m4_toupper($1), $rb_cv_var_$1)
-fi])
-RUBY_CHECK_VARTYPE(timezone, [#include <time.h>], [long int])
-RUBY_CHECK_VARTYPE(altzone, [#include <time.h>], [long int])
-if test "$rb_cv_var_timezone" = no; then
- AC_CHECK_FUNCS(timezone)
- if test "$ ac_cv_func_timezone" = yes; then
- AC_CACHE_CHECK([whether timezone requires zero arguments], rb_cv_func_timezone_void,
- [AC_TRY_COMPILE([#include <time.h>],
- [(void)timezone(0, 0);],
- [rb_cv_func_timezone_void=no],
- [rb_cv_func_timezone_void=yes])]
- )
- if test $rb_cv_func_timezone_void = yes; then
- AC_DEFINE(TIMEZONE_VOID)
- fi
- fi
-fi
-
AC_CACHE_CHECK(for negative time_t for gmtime(3), rb_cv_negative_time_t,
[AC_TRY_RUN([
#include <time.h>
@@ -667,7 +601,6 @@ fi
if test "$ac_cv_func_sigprocmask" = yes && test "$ac_cv_func_sigaction" = yes; then
AC_DEFINE(POSIX_SIGNAL)
else
- AC_CHECK_FUNCS(sigsetmask)
AC_CACHE_CHECK(for BSD signal semantics, rb_cv_bsd_signal,
[AC_TRY_RUN([
#include <stdio.h>
@@ -690,7 +623,7 @@ main()
],
rb_cv_bsd_signal=yes,
rb_cv_bsd_signal=no,
- rb_cv_bsd_signal=$ac_cv_func_sigsetmask)])
+ rb_cv_bsd_signal=no)])
if test "$rb_cv_bsd_signal" = yes; then
AC_DEFINE(BSD_SIGNAL)
fi
@@ -1026,7 +959,7 @@ AC_SUBST(DLEXT2)dnl
AC_SUBST(LIBEXT)dnl
STATIC=
-: ${LIBPATHFLAG=' -L%s'}
+: ${LIBPATHFLAG=' -L"%s"'}
: ${PATHFLAG=''}
if test "$with_dln_a_out" != yes; then
@@ -1090,7 +1023,7 @@ if test "$with_dln_a_out" != yes; then
rb_cv_dlopen=yes ;;
interix*) : ${LDSHARED="$CC -shared"}
XLDFLAGS="$XLDFLAGS -Wl,-E"
- LIBPATHFLAG=" -L%1\$-s"
+ LIBPATHFLAG=" -L'%1\$-s'"
rb_cv_dlopen=yes ;;
freebsd*|dragonfly*) : ${LDSHARED="$CC -shared"}
if test "$rb_cv_binary_elf" = yes; then
@@ -1120,12 +1053,15 @@ if test "$with_dln_a_out" != yes; then
rb_cv_dlopen=yes ;;
aix*) if test "$GCC" = yes; then
: ${LDSHARED='$(CC) -shared'}
+ DLDFLAGS='-Wl,-G -eInit_$(TARGET)'
+ LDFLAGS='-Wl,-brtl'
+ XLDFLAGS='-Wl,-bE:ruby.imp'
else
: ${LDSHARED='/usr/ccs/bin/ld'}
- fi
- DLDFLAGS="${linker_flag}-G"' -eInit_$(TARGET)'
- LDFLAGS="${LDFLAGS} ${linker_flag}-brtl"
- XLDFLAGS="${linker_flag}-bE:ruby.imp"
+ DLDFLAGS='-G -eInit_$(TARGET)'
+ LDFLAGS='-brtl'
+ XLDFLAGS='-bE:ruby.imp'
+ fi
: ${ARCHFILE="ruby.imp"}
TRY_LINK='$(CC) $(LDFLAGS) -oconftest $(INCFLAGS) -I$(hdrdir) $(CPPFLAGS)'
TRY_LINK="$TRY_LINK"' $(CFLAGS) $(src) $(LIBPATH) $(LOCAL_LIBS) $(LIBS)'
@@ -1170,8 +1106,12 @@ if test "$with_dln_a_out" != yes; then
[ --disable-rpath embed run path into extension libraries.],
[enable_rpath=$enableval], [enable_rpath="$rb_cv_binary_elf"])
if test "$enable_rpath" = yes; then
- LIBPATHFLAG=" -L%1\$-s"
- RPATHFLAG=" ${linker_flag}-R%1\$-s"
+ LIBPATHFLAG=" -L'%1\$-s'"
+ if test "$GCC" = yes; then
+ RPATHFLAG=" -Wl,-R'%1\$-s'"
+ else
+ RPATHFLAG=" -R'%1\$-s'"
+ fi
fi
fi
AC_SUBST(LINK_SO)
@@ -1259,7 +1199,7 @@ case "$target_os" in
human*)
AC_CHECK_LIB(signal, _harderr)
AC_CHECK_LIB(hmem, hmemset)
- AC_CHECK_FUNCS(select)
+ AC_CHECK_FUNCS(select gettimeofday)
AC_CACHE_CHECK(whether PD libc _dtos18 fail to convert big number,
rb_cv_missing__dtos18,
[AC_TRY_RUN(
@@ -1421,7 +1361,12 @@ if test "$enable_shared" = 'yes'; then
LIBRUBY_ALIASES='lib$(RUBY_SO_NAME).sl.$(MAJOR).$(MINOR) lib$(RUBY_SO_NAME).sl'
;;
aix*)
- LIBRUBY_DLDFLAGS="${linker_flag}-G ${linker_flag}-bnoentry $XLDFLAGS"
+ if test "$GCC" = yes; then
+ LIBRUBY_DLDFLAGS='-Wl,-G -Wl,-bnoentry'
+ else
+ LIBRUBY_DLDFLAGS='-G -bnoentry'
+ fi
+ LIBRUBY_DLDFLAGS="$LIBRUBY_DLDFLAGS $XLDFLAGS"
LIBRUBYARG_SHARED='-L${libdir} -l${RUBY_SO_NAME}'
SOLIBS='-lm -lc'
;;
@@ -1439,17 +1384,21 @@ if test "$enable_shared" = 'yes'; then
LIBRUBY_ALIASES='lib$(RUBY_SO_NAME).$(MAJOR).$(MINOR).dylib lib$(RUBY_SO_NAME).dylib'
;;
interix*)
- LIBRUBYARG_SHARED='-L. -L${libdir} -l$(RUBY_SO_NAME)'
+ LIBRUBYARG_SHARED='-L${libdir} -L. -l$(RUBY_SO_NAME)'
;;
*)
;;
esac
fi
if test "$enable_rpath" = yes; then
- LIBRUBYARG_SHARED="${linker_flag}-R ${linker_flag}\$(libdir) -L\$(libdir) $LIBRUBYARG_SHARED"
+ if test "$GCC" = yes; then
+ LIBRUBYARG_SHARED='-Wl,-R -Wl,$(libdir) -L$(libdir) -L. '"$LIBRUBYARG_SHARED"
+ else
+ LIBRUBYARG_SHARED='-R $(libdir) -L$(libdir) -L. '"$LIBRUBYARG_SHARED"
+ fi
fi
-LDFLAGS="-L. $LDFLAGS"
+XLDFLAGS="$XLDFLAGS -L."
AC_SUBST(ARCHFILE)
dnl build rdoc index if requested
@@ -1463,9 +1412,6 @@ fi
AC_SUBST(RDOCTARGET)
case "$target_os" in
- linux*)
- XCFLAGS="$XCFLAGS -D_GNU_SOURCE=1"
- ;;
netbsd*)
CFLAGS="$CFLAGS -pipe"
;;
@@ -1485,7 +1431,6 @@ case "$target_os" in
;;
darwin*)
CFLAGS="$CFLAGS -pipe -fno-common"
- MINIOBJS=dmydln.o
;;
os2-emx)
CFLAGS="$CFLAGS -DOS2 -Zmts"
@@ -1508,7 +1453,7 @@ case "$target_os" in
rm -f /tmp/main.o
CFLAGS="$CFLAGS -std"
fi
- ;;
+ ;;
beos*)
case "$target_cpu" in
powerpc*)
@@ -1523,6 +1468,7 @@ case "$target_os" in
LIBRUBY_SO='cyg$(RUBY_SO_NAME)'${MAJOR}${MINOR}.dll
LIBRUBY='lib$(RUBY_SO_NAME).dll.a'
fi
+ AC_LIBOBJ([strftime])
;;
mingw*)
RUBY_SO_NAME=${rb_cv_msvcrt}-'$(RUBY_INSTALL_NAME)'${MAJOR}${MINOR}
@@ -1564,7 +1510,6 @@ case "$build_os" in
*msdosdjgpp*) FIRSTMAKEFILE=GNUmakefile:djgpp/GNUmakefile.in;;
esac
-CPPFLAGS="$CPPFLAGS "'$(DEFS)'
AC_SUBST(XCFLAGS)dnl
AC_SUBST(XLDFLAGS)dnl
AC_SUBST(LIBRUBY_LDSHARED)
@@ -1701,14 +1646,12 @@ else
echo "creating config.h"
tr -d '\015' < confdefs.h > config.h
fi
-tr -d '\015' < largefile.h > confdefs.h
+: > confdefs.h
AC_CONFIG_FILES($FIRSTMAKEFILE)
AC_CONFIG_FILES(Makefile, [{
- sed '/^MISSING/s/\$U\././g' Makefile
echo; test x"$EXEEXT" = x || echo 'miniruby: miniruby$(EXEEXT)'
test "$RUBY_INSTALL_NAME$EXEEXT" = ruby || echo 'ruby: $(PROGRAM);'
sed ['s/{\$([^(){}]*)[^{}]*}//g'] ${srcdir}/common.mk
- } >> confmk$$.tmp && mv -f confmk$$.tmp Makefile],
-[RUBY_INSTALL_NAME=$RUBY_INSTALL_NAME EXEEXT=$EXEEXT])
+} >> Makefile], [RUBY_INSTALL_NAME=$RUBY_INSTALL_NAME EXEEXT=$EXEEXT])
AC_OUTPUT
diff --git a/defines.h b/defines.h
index 7b62c5cd02..f1a565acf3 100644
--- a/defines.h
+++ b/defines.h
@@ -218,7 +218,9 @@ flush_register_windows(void)
#endif
# if defined(__sparc_v9__) || defined(__sparcv9) || defined(__arch64__)
("flushw")
-# else
+# elif defined(linux) || defined(__linux__)
+ ("ta 0x83")
+# else /* Solaris, OpenBSD, NetBSD, etc. */
("ta 0x03")
# endif /* trap always to flush register windows if we are on a Sparc system */
;
@@ -251,14 +253,6 @@ void rb_ia64_flushrs(void);
#define ENV_IGNORECASE
#endif
-#ifndef CASEFOLD_FILESYSTEM
-# if defined DOSISH || defined __VMS
-# define CASEFOLD_FILESYSTEM 1
-# else
-# define CASEFOLD_FILESYSTEM 0
-# endif
-#endif
-
#ifndef DLEXT_MAXLEN
#define DLEXT_MAXLEN 4
#endif
diff --git a/dir.c b/dir.c
index 74de8c5430..4c63a0936f 100644
--- a/dir.c
+++ b/dir.c
@@ -958,19 +958,13 @@ sys_warning_1(mesg)
#define GLOB_ALLOC_N(type, n) (type *)malloc(sizeof(type) * (n))
#define GLOB_JUMP_TAG(status) ((status == -1) ? rb_memerror() : rb_jump_tag(status))
-/*
- * ENOTDIR can be returned by stat(2) if a non-leaf element of the path
- * is not a directory.
- */
-#define to_be_ignored(e) ((e) == ENOENT || (e) == ENOTDIR)
-
/* System call with warning */
static int
do_stat(const char *path, struct stat *pst, int flags)
{
int ret = stat(path, pst);
- if (ret < 0 && !to_be_ignored(errno))
+ if (ret < 0 && errno != ENOENT)
sys_warning(path);
return ret;
@@ -980,7 +974,7 @@ static int
do_lstat(const char *path, struct stat *pst, int flags)
{
int ret = lstat(path, pst);
- if (ret < 0 && !to_be_ignored(errno))
+ if (ret < 0 && errno != ENOENT)
sys_warning(path);
return ret;
@@ -990,7 +984,7 @@ static DIR *
do_opendir(const char *path, int flags)
{
DIR *dirp = opendir(path);
- if (dirp == NULL && !to_be_ignored(errno))
+ if (dirp == NULL && errno != ENOENT && errno != ENOTDIR)
sys_warning(path);
return dirp;
@@ -1659,7 +1653,7 @@ dir_globs(argc, argv, flags)
for (i = 0; i < argc; ++i) {
int status;
VALUE str = argv[i];
- SafeStringValue(str);
+ StringValue(str);
status = push_glob(ary, RSTRING(str)->ptr, flags);
if (status) GLOB_JUMP_TAG(status);
}
diff --git a/distruby.rb b/distruby.rb
index 613da0eb9c..dcc3e76ce8 100644
--- a/distruby.rb
+++ b/distruby.rb
@@ -7,9 +7,7 @@ else
dirname = sprintf 'ruby-%s-p%u', RUBY_VERSION, RUBY_PATCHLEVEL
tagname = dirname.gsub /ruby-(\d)\.(\d)\.(\d)-p/, 'v\1_\2_\3_'
end
-tgzname = dirname + '.tar.gz'
-tbzname = dirname + '.tar.bz2'
-zipname = dirname + '.zip'
+tarname = dirname + '.tar.gz'
repos = 'http://svn.ruby-lang.org/repos/ruby/tags/' + tagname
STDERR.puts 'exporting sources...'
@@ -23,24 +21,16 @@ Dir.chdir dirname do
system 'bison', '-y', '-o', 'parse.c', 'parse.y'
end
-STDERR.puts 'generating tarballs...'
-ENV['GZIP'] = '-9'
-system 'tar', 'chofzp', tgzname, dirname
-system 'tar', 'chojfp', tbzname, dirname
-system 'zip', '-q9r', zipname, dirname
-
-require 'digest/md5'
-require 'digest/sha2'
-for name in [tgzname, tbzname, zipname] do
- open name, 'rb' do |fp|
- str = fp.read
- md5 = Digest::MD5.hexdigest str
- sha = Digest::SHA256.hexdigest str
- printf "MD5(%s)= %s\nSHA256(%s)= %s\nSIZE(%s)= %s\n\n",
- name, md5,
- name, sha,
- name, str.size
- end
+STDERR.puts 'generating tarball...'
+system 'tar', 'chofzp', tarname, dirname
+
+open tarname, 'rb' do |fp|
+ require 'digest/md5'
+ require 'digest/sha1'
+ str = fp.read
+ md5 = Digest::MD5.hexdigest str
+ sha = Digest::SHA1.hexdigest str
+ printf "MD5(%s)= %s\nSHA1(%s)= %s\n", tarname, md5, tarname, sha
end
diff --git a/dln.c b/dln.c
index ae12758d19..b405da6bff 100644
--- a/dln.c
+++ b/dln.c
@@ -1676,6 +1676,35 @@ dln_find_file(fname, path)
#endif
}
+#if defined(__CYGWIN32__)
+const char *
+conv_to_posix_path(win32, posix, len)
+ char *win32;
+ char *posix;
+ int len;
+{
+ char *first = win32;
+ char *p = win32;
+ char *dst = posix;
+
+ posix[0] = '\0';
+ for (p = win32; *p; p++)
+ if (*p == ';') {
+ *p = 0;
+ cygwin32_conv_to_posix_path(first, posix);
+ posix += strlen(posix);
+ *posix++ = ':';
+ first = p + 1;
+ *p = ';';
+ }
+ if (len < strlen(first))
+ fprintf(stderr, "PATH length too long: %s\n", first);
+ else
+ cygwin32_conv_to_posix_path(first, posix);
+ return dst;
+}
+#endif
+
static char fbuf[MAXPATHLEN];
static char *
@@ -1772,9 +1801,26 @@ dln_find_1(fname, path, exe_flag)
}
memcpy(bp, fname, i + 1);
+#ifndef __MACOS__
+ if (stat(fbuf, &st) == 0) {
+ if (exe_flag == 0) return fbuf;
+ /* looking for executable */
+ if (!S_ISDIR(st.st_mode) && eaccess(fbuf, X_OK) == 0)
+ return fbuf;
+ }
+#else
+ if (mac_fullpath = _macruby_exist_file_in_libdir_as_posix_name(fbuf)) {
+ if (exe_flag == 0) return mac_fullpath;
+ /* looking for executable */
+ if (stat(mac_fullpath, &st) == 0) {
+ if (!S_ISDIR(st.st_mode) && eaccess(mac_fullpath, X_OK) == 0)
+ return mac_fullpath;
+ }
+ }
+#endif
#if defined(DOSISH)
if (exe_flag) {
- static const char extension[][5] = {
+ static const char *extension[] = {
#if defined(MSDOS)
".com", ".exe", ".bat",
#if defined(DJGPP)
@@ -1787,10 +1833,11 @@ dln_find_1(fname, path, exe_flag)
".r", ".R", ".x", ".X", ".bat", ".BAT",
/* __human68k__ */
#endif
+ (char *) NULL
};
int j;
- for (j = 0; j < sizeof(extension) / sizeof(extension[0]); j++) {
+ for (j = 0; extension[j]; j++) {
if (fspace < strlen(extension[j])) {
fprintf(stderr, "openpath: pathname too long (ignored)\n");
fprintf(stderr, "\tDirectory \"%.*s\"\n", (int) (bp - fbuf), fbuf);
@@ -1807,28 +1854,9 @@ dln_find_1(fname, path, exe_flag)
#endif
}
- goto next;
}
#endif /* MSDOS or _WIN32 or __human68k__ or __EMX__ */
-#ifndef __MACOS__
- if (stat(fbuf, &st) == 0) {
- if (exe_flag == 0) return fbuf;
- /* looking for executable */
- if (!S_ISDIR(st.st_mode) && eaccess(fbuf, X_OK) == 0)
- return fbuf;
- }
-#else
- if (mac_fullpath = _macruby_exist_file_in_libdir_as_posix_name(fbuf)) {
- if (exe_flag == 0) return mac_fullpath;
- /* looking for executable */
- if (stat(mac_fullpath, &st) == 0) {
- if (!S_ISDIR(st.st_mode) && eaccess(mac_fullpath, X_OK) == 0)
- return mac_fullpath;
- }
- }
-#endif
-
next:
/* if not, and no other alternatives, life is bleak */
if (*ep == '\0') {
diff --git a/error.c b/error.c
index 73d7934815..1b23d433c8 100644
--- a/error.c
+++ b/error.c
@@ -334,7 +334,7 @@ rb_exc_new3(etype, str)
VALUE etype, str;
{
StringValue(str);
- return rb_funcall(etype, rb_intern("new"), 1, str);
+ return rb_exc_new(etype, RSTRING(str)->ptr, RSTRING(str)->len);
}
/*
@@ -488,14 +488,14 @@ static VALUE
exc_backtrace(exc)
VALUE exc;
{
- static ID bt;
+ ID bt = rb_intern("bt");
- if (!bt) bt = rb_intern("bt");
- return rb_attr_get(exc, bt);
+ if (!rb_ivar_defined(exc, bt)) return Qnil;
+ return rb_ivar_get(exc, bt);
}
-VALUE
-rb_check_backtrace(bt)
+static VALUE
+check_backtrace(bt)
VALUE bt;
{
long i;
@@ -532,7 +532,7 @@ exc_set_backtrace(exc, bt)
VALUE exc;
VALUE bt;
{
- return rb_iv_set(exc, "bt", rb_check_backtrace(bt));
+ return rb_iv_set(exc, "bt", check_backtrace(bt));
}
/*
@@ -1083,7 +1083,7 @@ void
rb_notimplement()
{
rb_raise(rb_eNotImpError,
- "%s() function is unimplemented on this machine",
+ "the %s() function is unimplemented on this machine",
rb_id2name(ruby_frame->last_func));
}
diff --git a/eval.c b/eval.c
index 049f78c998..014f3f73a6 100644
--- a/eval.c
+++ b/eval.c
@@ -72,8 +72,6 @@ char *strrchr _((const char*,const char));
#include <unistd.h>
#endif
-#include <time.h>
-
#ifdef __BEOS__
#include <net/socket.h>
#endif
@@ -245,8 +243,8 @@ static int scope_vmode;
#define SCOPE_SET(f) (scope_vmode=(f))
#define SCOPE_TEST(f) (scope_vmode&(f))
-VALUE (*ruby_sandbox_save)_((rb_thread_t));
-VALUE (*ruby_sandbox_restore)_((rb_thread_t));
+VALUE (*ruby_sandbox_save)(struct thread *) = NULL;
+VALUE (*ruby_sandbox_restore)(struct thread *) = NULL;
NODE* ruby_current_node;
int ruby_safe_level = 0;
/* safe-level:
@@ -455,8 +453,7 @@ rb_define_alloc_func(klass, func)
VALUE (*func) _((VALUE));
{
Check_Type(klass, T_CLASS);
- rb_add_method(rb_singleton_class(klass), ID_ALLOCATOR, NEW_CFUNC(func, 0),
- NOEX_PRIVATE);
+ rb_add_method(CLASS_OF(klass), ID_ALLOCATOR, NEW_CFUNC(func, 0), NOEX_PRIVATE);
}
void
@@ -464,7 +461,7 @@ rb_undef_alloc_func(klass)
VALUE klass;
{
Check_Type(klass, T_CLASS);
- rb_add_method(rb_singleton_class(klass), ID_ALLOCATOR, 0, NOEX_UNDEF);
+ rb_add_method(CLASS_OF(klass), ID_ALLOCATOR, 0, NOEX_UNDEF);
}
static NODE*
@@ -472,16 +469,16 @@ search_method(klass, id, origin)
VALUE klass, *origin;
ID id;
{
- st_data_t body;
+ NODE *body;
if (!klass) return 0;
- while (!st_lookup(RCLASS(klass)->m_tbl, id, &body)) {
+ while (!st_lookup(RCLASS(klass)->m_tbl, id, (st_data_t *)&body)) {
klass = RCLASS(klass)->super;
if (!klass) return 0;
}
if (origin) *origin = klass;
- return (NODE *)body;
+ return body;
}
static NODE*
@@ -560,8 +557,7 @@ remove_method(klass, mid)
VALUE klass;
ID mid;
{
- st_data_t data;
- NODE *body = 0;
+ NODE *body;
if (klass == rb_cObject) {
rb_secure(4);
@@ -573,14 +569,8 @@ remove_method(klass, mid)
if (mid == __id__ || mid == __send__ || mid == init) {
rb_warn("removing `%s' may cause serious problem", rb_id2name(mid));
}
- if (st_lookup(RCLASS(klass)->m_tbl, mid, &data)) {
- body = (NODE *)data;
- if (!body || !body->nd_body) body = 0;
- else {
- st_delete(RCLASS(klass)->m_tbl, &mid, &data);
- }
- }
- if (!body) {
+ if (!st_delete(RCLASS(klass)->m_tbl, &mid, (st_data_t *)&body) ||
+ !body->nd_body) {
rb_name_error(mid, "method `%s' not defined in %s",
rb_id2name(mid), rb_class2name(klass));
}
@@ -763,7 +753,7 @@ static struct SCOPE *top_scope;
static unsigned long frame_unique = 0;
#define PUSH_FRAME() do { \
- volatile struct FRAME _frame; \
+ struct FRAME _frame; \
_frame.prev = ruby_frame; \
_frame.tmp = 0; \
_frame.node = ruby_current_node; \
@@ -1060,7 +1050,7 @@ VALUE ruby_class;
static VALUE ruby_wrapper; /* security wrapper */
#define PUSH_CLASS(c) do { \
- volatile VALUE _class = ruby_class; \
+ VALUE _class = ruby_class; \
ruby_class = (c)
#define POP_CLASS() ruby_class = _class; \
@@ -1068,7 +1058,7 @@ static VALUE ruby_wrapper; /* security wrapper */
NODE *ruby_cref = 0;
NODE *ruby_top_cref;
-#define PUSH_CREF(c) ruby_cref = NEW_CREF(c,ruby_cref)
+#define PUSH_CREF(c) ruby_cref = NEW_NODE(NODE_CREF,(c),0,ruby_cref)
#define POP_CREF() ruby_cref = ruby_cref->nd_next
#define PUSH_SCOPE() do { \
@@ -1083,11 +1073,8 @@ NODE *ruby_top_cref;
ruby_scope = _scope; \
scope_vmode = SCOPE_PUBLIC
-rb_thread_t rb_curr_thread;
-rb_thread_t rb_main_thread;
-#define main_thread rb_main_thread
-#define curr_thread rb_curr_thread
-
+rb_thread_t curr_thread = 0;
+rb_thread_t main_thread;
static void scope_dup _((struct SCOPE *));
#define POP_SCOPE() \
@@ -1207,8 +1194,6 @@ error_pos()
}
}
-VALUE rb_check_backtrace(VALUE);
-
static VALUE
get_backtrace(info)
VALUE info;
@@ -1216,7 +1201,7 @@ get_backtrace(info)
if (NIL_P(info)) return Qnil;
info = rb_funcall(info, rb_intern("backtrace"), 0);
if (NIL_P(info)) return Qnil;
- return rb_check_backtrace(info);
+ return rb_check_array_type(info);
}
static void
@@ -1292,7 +1277,7 @@ error_print()
long len = elen;
if (RSTRING(epath)->ptr[0] == '#') epath = 0;
- if ((tail = memchr(einfo, '\n', elen)) != 0) {
+ if (tail = memchr(einfo, '\n', elen)) {
len = tail - einfo;
tail++; /* skip newline */
}
@@ -1303,9 +1288,8 @@ error_print()
warn_print2(RSTRING(epath)->ptr, RSTRING(epath)->len);
warn_print(")\n");
}
- if (tail && elen>len+1) {
+ if (tail) {
warn_print2(tail, elen-len-1);
- if (einfo[elen-1] != '\n') warn_print2("\n", 1);
}
}
}
@@ -1441,11 +1425,12 @@ eval_node(self, node)
int ruby_in_eval;
-static int rb_thread_join _((rb_thread_t, double));
-
static void rb_thread_cleanup _((void));
static void rb_thread_wait_other_threads _((void));
+static int thread_set_raised();
+static int thread_reset_raised();
+
static int thread_no_ensure _((void));
static VALUE exception_error;
@@ -1464,10 +1449,8 @@ error_handle(ex)
int ex;
{
int status = EXIT_FAILURE;
- rb_thread_t th = curr_thread;
- if (rb_thread_set_raised(th))
- return EXIT_FAILURE;
+ if (thread_set_raised()) return EXIT_FAILURE;
switch (ex & TAG_MASK) {
case 0:
status = EXIT_SUCCESS;
@@ -1520,7 +1503,7 @@ error_handle(ex)
rb_bug("Unknown longjmp status %d", ex);
break;
}
- rb_thread_reset_raised(th);
+ thread_reset_raised();
return status;
}
@@ -1579,14 +1562,11 @@ ruby_cleanup(ex)
int ex;
{
int state;
- volatile VALUE errs[2];
- int nerr;
+ volatile VALUE err = ruby_errinfo;
- errs[1] = ruby_errinfo;
ruby_safe_level = 0;
- Init_stack((void *)&state);
+ Init_stack((void*)&state);
ruby_finalize_0();
- errs[0] = ruby_errinfo;
PUSH_TAG(PROT_NONE);
PUSH_ITER(ITER_NOT);
if ((state = EXEC_TAG()) == 0) {
@@ -1597,39 +1577,21 @@ ruby_cleanup(ex)
ex = state;
}
POP_ITER();
- ruby_errinfo = errs[1];
+ ruby_errinfo = err;
ex = error_handle(ex);
ruby_finalize_1();
POP_TAG();
- for (nerr = 0; nerr < sizeof(errs) / sizeof(errs[0]); ++nerr) {
- VALUE err = errs[nerr];
-
- if (!RTEST(err)) continue;
-
+ if (err) {
if (rb_obj_is_kind_of(err, rb_eSystemExit)) {
- return sysexit_status(err);
+ VALUE st = rb_iv_get(err, "status");
+ return NUM2INT(st);
}
else if (rb_obj_is_kind_of(err, rb_eSignal)) {
VALUE sig = rb_iv_get(err, "signo");
ruby_default_signal(NUM2INT(sig));
}
- else if (ex == 0) {
- ex = 1;
- }
- }
-
-#if EXIT_SUCCESS != 0 || EXIT_FAILURE != 1
- switch (ex) {
-#if EXIT_SUCCESS != 0
- case 0: return EXIT_SUCCESS;
-#endif
-#if EXIT_FAILURE != 1
- case 1: return EXIT_FAILURE;
-#endif
}
-#endif
-
return ex;
}
@@ -1893,7 +1855,7 @@ rb_eval_cmd(cmd, arg, level)
POP_TAG();
POP_FRAME();
- if (state) jump_tag_but_local_jump(state, val);
+ jump_tag_but_local_jump(state, val);
return val;
}
@@ -2168,7 +2130,6 @@ rb_alias(klass, name, def)
VALUE origin;
NODE *orig, *body, *node;
VALUE singleton = 0;
- st_data_t data;
rb_frozen_class_p(klass);
if (name == def) return;
@@ -2196,8 +2157,7 @@ rb_alias(klass, name, def)
}
rb_clear_cache_by_id(name);
- if (RTEST(ruby_verbose) && st_lookup(RCLASS(klass)->m_tbl, name, &data)) {
- node = (NODE *)data;
+ if (RTEST(ruby_verbose) && st_lookup(RCLASS(klass)->m_tbl, name, (st_data_t *)&node)) {
if (node->nd_cnt == 0 && node->nd_body) {
rb_warning("discarding old %s", rb_id2name(name));
}
@@ -2205,9 +2165,6 @@ rb_alias(klass, name, def)
st_insert(RCLASS(klass)->m_tbl, name,
(st_data_t)NEW_METHOD(NEW_FBODY(body, def, origin),
NOEX_WITH_SAFE(orig->nd_noex)));
-
- if (!ruby_running) return;
-
if (singleton) {
rb_funcall(singleton, singleton_added, 1, ID2SYM(name));
}
@@ -2246,8 +2203,8 @@ rb_mod_alias_method(mod, newname, oldname)
return mod;
}
-NODE *
-rb_copy_node_scope(node, rval)
+static NODE*
+copy_node_scope(node, rval)
NODE *node;
NODE *rval;
{
@@ -2448,8 +2405,6 @@ is_defined(self, node, buf)
case NODE_ATTRSET:
case NODE_OP_ASGN1:
case NODE_OP_ASGN2:
- case NODE_OP_ASGN_OR:
- case NODE_OP_ASGN_AND:
case NODE_MASGN:
case NODE_LASGN:
case NODE_DASGN:
@@ -2713,7 +2668,6 @@ call_trace_func(event, node, self, id, klass)
NODE *node_save;
VALUE srcfile;
char *event_name;
- rb_thread_t th = curr_thread;
if (!trace_func) return;
if (tracing) return;
@@ -2745,7 +2699,7 @@ call_trace_func(event, node, self, id, klass)
}
}
PUSH_TAG(PROT_NONE);
- raised = rb_thread_reset_raised(th);
+ raised = thread_reset_raised();
if ((state = EXEC_TAG()) == 0) {
srcfile = rb_str_new2(ruby_sourcefile?ruby_sourcefile:"(ruby)");
event_name = get_event_name(event);
@@ -2757,7 +2711,7 @@ call_trace_func(event, node, self, id, klass)
klass),
Qundef, 0);
}
- if (raised) rb_thread_set_raised(th);
+ if (raised) thread_set_raised();
POP_TAG();
POP_FRAME();
@@ -2949,7 +2903,6 @@ rb_eval(self, n)
NODE * volatile node = n;
int state;
volatile VALUE result = Qnil;
- st_data_t data;
#define RETURN(v) do { \
result = (v); \
@@ -3541,10 +3494,6 @@ rb_eval(self, n)
}
argv = RARRAY(RBASIC(ruby_scope)->klass)->ptr;
}
- else if (!ruby_scope->local_vars) {
- argc = 0;
- argv = 0;
- }
else {
argv = ruby_scope->local_vars + 2;
}
@@ -3957,7 +3906,7 @@ rb_eval(self, n)
noex |= NOEX_NOSUPER;
}
- defn = rb_copy_node_scope(node->nd_defn, ruby_cref);
+ defn = copy_node_scope(node->nd_defn, ruby_cref);
rb_add_method(ruby_class, node->nd_mid, defn, noex);
if (scope_vmode == SCOPE_MODFUNC) {
rb_add_method(rb_singleton_class(ruby_class),
@@ -3985,8 +3934,7 @@ rb_eval(self, n)
if (OBJ_FROZEN(recv)) rb_error_frozen("object");
klass = rb_singleton_class(recv);
- if (st_lookup(RCLASS(klass)->m_tbl, node->nd_mid, &data)) {
- body = (NODE *)data;
+ if (st_lookup(RCLASS(klass)->m_tbl, node->nd_mid, (st_data_t *)&body)) {
if (ruby_safe_level >= 4) {
rb_raise(rb_eSecurityError, "redefining method prohibited");
}
@@ -3994,7 +3942,7 @@ rb_eval(self, n)
rb_warning("redefine %s", rb_id2name(node->nd_mid));
}
}
- defn = rb_copy_node_scope(node->nd_defn, ruby_cref);
+ defn = copy_node_scope(node->nd_defn, ruby_cref);
rb_add_method(klass, node->nd_mid, defn,
NOEX_PUBLIC|(body?body->nd_noex&NOEX_UNDEF:0));
result = Qnil;
@@ -4235,7 +4183,7 @@ rb_obj_respond_to(obj, id, priv)
int n = 0;
args[n++] = ID2SYM(id);
if (priv) args[n++] = Qtrue;
- return RTEST(rb_funcall2(obj, respond_to, n, args));
+ return rb_funcall2(obj, respond_to, n, args);
}
}
@@ -4573,9 +4521,8 @@ rb_longjmp(tag, mesg)
VALUE mesg;
{
VALUE at;
- rb_thread_t th = curr_thread;
- if (rb_thread_set_raised(th)) {
+ if (thread_set_raised()) {
ruby_errinfo = exception_error;
JUMP_TAG(TAG_FATAL);
}
@@ -4589,9 +4536,6 @@ rb_longjmp(tag, mesg)
at = get_backtrace(mesg);
if (NIL_P(at)) {
at = make_backtrace();
- if (OBJ_FROZEN(mesg)) {
- mesg = rb_obj_dup(mesg);
- }
set_backtrace(mesg, at);
}
}
@@ -4617,7 +4561,7 @@ rb_longjmp(tag, mesg)
ruby_errinfo = mesg;
}
else if (status) {
- rb_thread_reset_raised(th);
+ thread_reset_raised();
JUMP_TAG(status);
}
}
@@ -4632,20 +4576,11 @@ rb_longjmp(tag, mesg)
if (!prot_tag) {
error_print();
}
- rb_thread_raised_clear(th);
+ thread_reset_raised();
JUMP_TAG(tag);
}
void
-rb_exc_jump(mesg)
- VALUE mesg;
-{
- rb_thread_raised_clear(rb_curr_thread);
- ruby_errinfo = mesg;
- JUMP_TAG(TAG_RAISE);
-}
-
-void
rb_exc_raise(mesg)
VALUE mesg;
{
@@ -5063,10 +4998,8 @@ rb_yield_0(val, self, klass, flags, avalue)
CHECK_INTS;
goto redo;
case TAG_NEXT:
- if (!lambda) {
- state = 0;
- result = prot_tag->retval;
- }
+ state = 0;
+ result = prot_tag->retval;
break;
case TAG_BREAK:
if (TAG_DST()) {
@@ -5446,7 +5379,7 @@ rb_rescue2(b_proc, data1, r_proc, data2, va_alist)
if (handle) break;
handle = Qfalse;
va_init_list(args, data2);
- while ((eclass = va_arg(args, VALUE)) != 0) {
+ while (eclass = va_arg(args, VALUE)) {
if (rb_obj_is_kind_of(ruby_errinfo, eclass)) {
handle = Qtrue;
break;
@@ -5525,7 +5458,7 @@ rb_ensure(b_proc, data1, e_proc, data2)
POP_TAG();
retval = prot_tag ? prot_tag->retval : Qnil; /* save retval */
if (!thread_no_ensure()) {
- (*e_proc)(data2);
+ (*e_proc)(data2);
}
if (prot_tag) return_value(retval);
if (state) JUMP_TAG(state);
@@ -5561,11 +5494,18 @@ rb_with_disable_interrupt(proc, data)
static void
stack_check()
{
- rb_thread_t th = rb_curr_thread;
+ static int overflowing = 0;
- if (!rb_thread_raised_p(th, RAISED_STACKOVERFLOW) && ruby_stack_check()) {
- rb_thread_raised_set(th, RAISED_STACKOVERFLOW);
- rb_exc_raise(sysstack_error);
+ if (!overflowing && ruby_stack_check()) {
+ int state;
+ overflowing = 1;
+ PUSH_TAG(PROT_NONE);
+ if ((state = EXEC_TAG()) == 0) {
+ rb_exc_raise(sysstack_error);
+ }
+ POP_TAG();
+ overflowing = 0;
+ JUMP_TAG(state);
}
}
@@ -5804,7 +5744,8 @@ rb_call0(klass, recv, id, oid, argc, argv, body, flags)
TMP_PROTECT;
volatile int safe = -1;
- if (NOEX_SAFE(flags) > ruby_safe_level && NOEX_SAFE(flags) > 2) {
+ if (NOEX_SAFE(flags) > ruby_safe_level &&
+ !(flags&NOEX_TAINTED) && ruby_safe_level == 0 && NOEX_SAFE(flags) > 2) {
rb_raise(rb_eSecurityError, "calling insecure method: %s",
rb_id2name(id));
}
@@ -6551,17 +6492,16 @@ eval(self, src, scope, file, line)
if (state) {
if (state == TAG_RAISE) {
if (strcmp(file, "(eval)") == 0) {
- VALUE mesg, errat, bt2;
+ VALUE mesg, errat;
errat = get_backtrace(ruby_errinfo);
- mesg = rb_attr_get(ruby_errinfo, rb_intern("mesg"));
- if (!NIL_P(errat) && TYPE(errat) == T_ARRAY &&
- (bt2 = backtrace(-2), RARRAY(bt2)->len > 0)) {
+ mesg = rb_attr_get(ruby_errinfo, rb_intern("mesg"));
+ if (!NIL_P(errat) && TYPE(errat) == T_ARRAY) {
if (!NIL_P(mesg) && TYPE(mesg) == T_STRING) {
rb_str_update(mesg, 0, 0, rb_str_new2(": "));
rb_str_update(mesg, 0, 0, RARRAY(errat)->ptr[0]);
}
- RARRAY(errat)->ptr[0] = RARRAY(bt2)->ptr[0];
+ RARRAY(errat)->ptr[0] = RARRAY(backtrace(-2))->ptr[0];
}
}
rb_exc_raise(ruby_errinfo);
@@ -6853,6 +6793,7 @@ rb_load(fname, wrap)
volatile VALUE self = ruby_top_self;
NODE *volatile last_node;
NODE *saved_cref = ruby_cref;
+ TMP_PROTECT;
if (wrap && ruby_safe_level >= 4) {
StringValue(fname);
@@ -7005,16 +6946,16 @@ static const char *const loadable_ext[] = {
0
};
-static int rb_feature_p _((const char **, const char *, int));
+static int rb_feature_p _((const char *, const char *, int));
static int search_required _((VALUE, VALUE *, VALUE *));
static int
-rb_feature_p(ftptr, ext, rb)
- const char **ftptr, *ext;
+rb_feature_p(feature, ext, rb)
+ const char *feature, *ext;
int rb;
{
VALUE v;
- const char *f, *e, *feature = *ftptr;
+ const char *f, *e;
long i, len, elen;
if (ext) {
@@ -7032,21 +6973,18 @@ rb_feature_p(ftptr, ext, rb)
continue;
if (!*(e = f + len)) {
if (ext) continue;
- *ftptr = 0;
return 'u';
}
if (*e != '.') continue;
if ((!rb || !ext) && (IS_SOEXT(e) || IS_DLEXT(e))) {
- *ftptr = 0;
return 's';
}
if ((rb || !ext) && (strcmp(e, ".rb") == 0)) {
- *ftptr = 0;
return 'r';
}
}
if (loading_tbl) {
- if (st_lookup(loading_tbl, (st_data_t)feature, (st_data_t *)ftptr)) {
+ if (st_lookup(loading_tbl, (st_data_t)feature, 0)) {
if (!ext) return 'u';
return strcmp(ext, ".rb") ? 's' : 'r';
}
@@ -7058,7 +6996,7 @@ rb_feature_p(ftptr, ext, rb)
MEMCPY(buf, feature, char, len);
for (i = 0; (e = loadable_ext[i]) != 0; i++) {
strncpy(buf + len, e, DLEXT_MAXLEN + 1);
- if (st_lookup(loading_tbl, (st_data_t)buf, (st_data_t *)ftptr)) {
+ if (st_lookup(loading_tbl, (st_data_t)buf, 0)) {
return i ? 's' : 'r';
}
}
@@ -7066,7 +7004,6 @@ rb_feature_p(ftptr, ext, rb)
}
return 0;
}
-#define rb_feature_p(feature, ext, rb) rb_feature_p(&feature, ext, rb)
int
rb_provided(feature)
@@ -7080,8 +7017,7 @@ rb_provided(feature)
return Qfalse;
}
else if (IS_SOEXT(ext) || IS_DLEXT(ext)) {
- if (rb_feature_p(feature, ext, Qfalse)) return Qtrue;
- return Qfalse;
+ return Qfalse; /* may be overriden by .rb file */
}
}
if (rb_feature_p(feature, feature + strlen(feature), Qtrue))
@@ -7123,9 +7059,8 @@ load_lock(ftptr)
return (char *)ftptr;
}
do {
- rb_thread_t owner = (rb_thread_t)th;
- if (owner == curr_thread) return 0;
- rb_thread_join(owner->thread, -1.0);
+ if ((rb_thread_t)th == curr_thread) return 0;
+ CHECK_INTS;
} while (st_lookup(loading_tbl, (st_data_t)ftptr, &th));
return 0;
}
@@ -7176,7 +7111,7 @@ search_required(fname, featurep, path)
VALUE fname, *featurep, *path;
{
VALUE tmp;
- const char *ext, *ftptr;
+ char *ext, *ftptr;
int type;
*featurep = fname;
@@ -7184,18 +7119,12 @@ search_required(fname, featurep, path)
ext = strrchr(ftptr = RSTRING_PTR(fname), '.');
if (ext && !strchr(ext, '/')) {
if (strcmp(".rb", ext) == 0) {
- if (rb_feature_p(ftptr, ext, Qtrue)) {
- if (ftptr) *path = rb_str_new2(ftptr);
- return 'r';
- }
+ if (rb_feature_p(ftptr, ext, Qtrue)) return 'r';
if ((*path = rb_find_file(fname)) != 0) return 'r';
return 0;
}
else if (IS_SOEXT(ext)) {
- if (rb_feature_p(ftptr, ext, Qfalse)) {
- if (ftptr) *path = rb_str_new2(ftptr);
- return 's';
- }
+ if (rb_feature_p(ftptr, ext, Qfalse)) return 's';
tmp = rb_str_new(RSTRING_PTR(fname), ext-RSTRING_PTR(fname));
*featurep = tmp;
#ifdef DLEXT2
@@ -7208,16 +7137,13 @@ search_required(fname, featurep, path)
#else
rb_str_cat2(tmp, DLEXT);
OBJ_FREEZE(tmp);
- if ((*path = rb_find_file(tmp)) != 0) {
+ if (*path = rb_find_file(tmp)) {
return 's';
}
#endif
}
else if (IS_DLEXT(ext)) {
- if (rb_feature_p(ftptr, ext, Qfalse)) {
- if (ftptr) *path = rb_str_new2(ftptr);
- return 's';
- }
+ if (rb_feature_p(ftptr, ext, Qfalse)) return 's';
if ((*path = rb_find_file(fname)) != 0) return 's';
}
}
@@ -7226,16 +7152,13 @@ search_required(fname, featurep, path)
*featurep = tmp;
switch (type) {
case 0:
- type = rb_feature_p(ftptr, 0, Qfalse);
- if (type && ftptr) *path = rb_str_new2(ftptr);
- return type;
+ ftptr = RSTRING_PTR(tmp);
+ return rb_feature_p(ftptr, 0, Qfalse);
default:
ext = strrchr(ftptr = RSTRING(tmp)->ptr, '.');
- if (!rb_feature_p(ftptr, ext, !--type))
- *path = rb_find_file(tmp);
- else if (ftptr)
- *path = rb_str_new2(ftptr);
+ if (rb_feature_p(ftptr, ext, !--type)) break;
+ *path = rb_find_file(tmp);
}
return type ? 's' : 'r';
}
@@ -7596,7 +7519,7 @@ rb_mod_modfunc(argc, argv, module)
body = search_method(rb_cObject, id, &m);
}
if (body == 0 || body->nd_body == 0) {
- print_undef(module, id);
+ rb_bug("undefined method `%s'; can't happen", rb_id2name(id));
}
if (nd_type(body->nd_body) != NODE_ZSUPER) {
break; /* normal case: need not to follow 'super' link */
@@ -8035,11 +7958,11 @@ Init_eval()
__id__ = rb_intern("__id__");
__send__ = rb_intern("__send__");
- rb_global_variable((void *)&top_scope);
- rb_global_variable((void *)&ruby_eval_tree_begin);
+ rb_global_variable((VALUE*)&top_scope);
+ rb_global_variable((VALUE*)&ruby_eval_tree_begin);
- rb_global_variable((void *)&ruby_eval_tree);
- rb_global_variable((void *)&ruby_dyna_vars);
+ rb_global_variable((VALUE*)&ruby_eval_tree);
+ rb_global_variable((VALUE*)&ruby_dyna_vars);
rb_define_virtual_variable("$@", errat_getter, errat_setter);
rb_define_hooked_variable("$!", &ruby_errinfo, 0, errinfo_setter);
@@ -8052,7 +7975,7 @@ Init_eval()
rb_define_method(rb_mKernel, "respond_to?", obj_respond_to, -1);
respond_to = rb_intern("respond_to?");
- rb_global_variable((void *)&basic_respond_to);
+ rb_global_variable((VALUE*)&basic_respond_to);
basic_respond_to = rb_method_node(rb_cObject, respond_to);
rb_define_global_function("raise", rb_f_raise, -1);
@@ -8377,25 +8300,16 @@ proc_clone(self)
* MISSING: documentation
*/
-#define PROC_TSHIFT (FL_USHIFT+1)
-#define PROC_TMASK (FL_USER1|FL_USER2|FL_USER3)
-#define PROC_TMAX (PROC_TMASK >> PROC_TSHIFT)
-
-static int proc_get_safe_level(VALUE);
-
static VALUE
proc_dup(self)
VALUE self;
{
struct BLOCK *orig, *data;
VALUE bind;
- int safe = proc_get_safe_level(self);
Data_Get_Struct(self, struct BLOCK, orig);
bind = Data_Make_Struct(rb_obj_class(self),struct BLOCK,blk_mark,blk_free,data);
blk_dup(data, orig);
- if (safe > PROC_TMAX) safe = PROC_TMAX;
- FL_SET(bind, (safe << PROC_TSHIFT) & PROC_TMASK);
return bind;
}
@@ -8457,6 +8371,10 @@ rb_f_binding(self)
return bind;
}
+#define PROC_TSHIFT (FL_USHIFT+1)
+#define PROC_TMASK (FL_USER1|FL_USER2|FL_USER3)
+#define PROC_TMAX (PROC_TMASK >> PROC_TSHIFT)
+
#define SAFE_LEVEL_MAX PROC_TMASK
static void
@@ -8679,7 +8597,6 @@ proc_invoke(proc, args, self, klass)
proc_jump_error(TAG_RETRY, Qnil); /* xxx */
JUMP_TAG(state);
break;
- case TAG_NEXT:
case TAG_BREAK:
if (!pcall && result != Qundef) {
proc_jump_error(state, result);
@@ -9049,6 +8966,7 @@ mnew(klass, obj, id, mklass)
(FL_TEST(rklass, FL_SINGLETON) || TYPE(rklass) == T_ICLASS)) {
rklass = RCLASS(rklass)->super;
}
+ if (TYPE(klass) == T_ICLASS) klass = RBASIC(klass)->klass;
method = Data_Make_Struct(mklass, struct METHOD, bm_mark, free, data);
data->klass = klass;
data->recv = obj;
@@ -9056,7 +8974,7 @@ mnew(klass, obj, id, mklass)
data->body = body;
data->rklass = rklass;
data->oid = oid;
- data->safe_level = NOEX_WITH_SAFE(noex);
+ data->safe_level = NOEX_WITH_SAFE(0);
OBJ_INFECT(method, klass);
return method;
@@ -9523,12 +9441,8 @@ method_inspect(method)
else {
rb_str_buf_cat2(str, rb_class2name(data->rklass));
if (data->rklass != data->klass) {
- VALUE klass = data -> klass;
- if (TYPE(klass) == T_ICLASS) {
- klass = RBASIC(klass)->klass;
- }
rb_str_buf_cat2(str, "(");
- rb_str_buf_cat2(str, rb_class2name(klass));
+ rb_str_buf_cat2(str, rb_class2name(data->klass));
rb_str_buf_cat2(str, ")");
}
}
@@ -9736,17 +9650,12 @@ Init_Proc()
rb_define_method(rb_eLocalJumpError, "reason", localjump_reason, 0);
rb_global_variable(&exception_error);
- exception_error = rb_exc_new3(rb_eFatal,
- rb_obj_freeze(rb_str_new2("exception reentered")));
- OBJ_TAINT(exception_error);
- OBJ_FREEZE(exception_error);
+ exception_error = rb_exc_new2(rb_eFatal, "exception reentered");
rb_eSysStackError = rb_define_class("SystemStackError", rb_eStandardError);
rb_global_variable(&sysstack_error);
- sysstack_error = rb_exc_new3(rb_eSysStackError,
- rb_obj_freeze(rb_str_new2("stack level too deep")));
+ sysstack_error = rb_exc_new2(rb_eSysStackError, "stack level too deep");
OBJ_TAINT(sysstack_error);
- OBJ_FREEZE(sysstack_error);
rb_cProc = rb_define_class("Proc", rb_cObject);
rb_undef_alloc_func(rb_cProc);
@@ -9918,9 +9827,12 @@ extern VALUE rb_last_status;
# endif
#endif
+/* typedef struct thread * rb_thread_t; */
+
+#define THREAD_RAISED 0x200 /* temporary flag */
#define THREAD_TERMINATING 0x400 /* persistent flag */
-#define THREAD_NO_ENSURE 0x800 /* persistent flag */
-#define THREAD_FLAGS_MASK 0xfc00 /* mask for persistent flags */
+#define THREAD_NO_ENSURE 0x800 /* persistent flag */
+#define THREAD_FLAGS_MASK 0xc00 /* mask for persistent flags */
#define FOREACH_THREAD_FROM(f,x) x = f; do { x = x->next;
#define END_FOREACH_FROM(f,x) } while (x != f)
@@ -9939,7 +9851,7 @@ struct thread_status_t {
int safe;
- enum rb_thread_status status;
+ enum thread_status status;
int wait_for;
int fd;
fd_set readfds;
@@ -9972,25 +9884,19 @@ struct thread_status_t {
(dst)->join = (src)->join, \
0)
-int
-rb_thread_set_raised(th)
- rb_thread_t th;
+static int
+thread_set_raised()
{
- if (th->flags & RAISED_EXCEPTION) {
- return 1;
- }
- th->flags |= RAISED_EXCEPTION;
+ if (curr_thread->flags & THREAD_RAISED) return 1;
+ curr_thread->flags |= THREAD_RAISED;
return 0;
}
-int
-rb_thread_reset_raised(th)
- rb_thread_t th;
+static int
+thread_reset_raised()
{
- if (!(th->flags & RAISED_EXCEPTION)) {
- return 0;
- }
- th->flags &= ~RAISED_EXCEPTION;
+ if (!(curr_thread->flags & THREAD_RAISED)) return 0;
+ curr_thread->flags &= ~THREAD_RAISED;
return 1;
}
@@ -10047,7 +9953,7 @@ rb_trap_eval(cmd, sig, safe)
static const char *
thread_status_name(status)
- enum rb_thread_status status;
+ enum thread_status status;
{
switch (status) {
case THREAD_RUNNABLE:
@@ -10101,13 +10007,6 @@ static double
timeofday()
{
struct timeval tv;
-#ifdef CLOCK_MONOTONIC
- struct timespec tp;
-
- if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0) {
- return (double)tp.tv_sec + (double)tp.tv_nsec * 1e-9;
- }
-#endif
gettimeofday(&tv, NULL);
return (double)tv.tv_sec + (double)tv.tv_usec * 1e-6;
}
@@ -10230,8 +10129,8 @@ rb_gc_abort_threads()
} END_FOREACH_FROM(main_thread, th);
}
-static inline void
-stack_free(th)
+static void
+thread_free(th)
rb_thread_t th;
{
if (th->stk_ptr) free(th->stk_ptr);
@@ -10240,13 +10139,6 @@ stack_free(th)
if (th->bstr_ptr) free(th->bstr_ptr);
th->bstr_ptr = 0;
#endif
-}
-
-static void
-thread_free(th)
- rb_thread_t th;
-{
- stack_free(th);
if (th->locals) st_free_table(th->locals);
if (th->status != THREAD_KILLED) {
if (th->prev) th->prev->next = th->next;
@@ -10291,7 +10183,7 @@ rb_thread_save_context(th)
rb_thread_t th;
{
VALUE *pos;
- size_t len;
+ int len;
static VALUE tval;
len = ruby_stack_length(&pos);
@@ -10348,8 +10240,9 @@ rb_thread_save_context(th)
th->safe = ruby_safe_level;
th->node = ruby_current_node;
- if (ruby_sandbox_save != NULL) {
- ruby_sandbox_save(th);
+ if (ruby_sandbox_save != NULL)
+ {
+ ruby_sandbox_save(th);
}
}
@@ -10397,19 +10290,20 @@ rb_thread_switch(n)
(rb_thread_switch((FLUSH_REGISTER_WINDOWS, ruby_setjmp(rb_thread_save_context(th), (th)->context))))
NORETURN(static void rb_thread_restore_context _((rb_thread_t,int)));
-NORETURN(NOINLINE(static void rb_thread_restore_context_0(rb_thread_t,int)));
-NORETURN(NOINLINE(static void stack_extend(rb_thread_t, int)));
+NORETURN(NOINLINE(static void rb_thread_restore_context_0(rb_thread_t,int,void*)));
+NORETURN(NOINLINE(static void stack_extend(rb_thread_t, int, VALUE *)));
static void
-rb_thread_restore_context_0(rb_thread_t th, int exit)
+rb_thread_restore_context_0(rb_thread_t th, int exit, void *vp)
{
static rb_thread_t tmp;
static int ex;
static VALUE tval;
rb_trap_immediate = 0; /* inhibit interrupts from here */
- if (ruby_sandbox_restore != NULL) {
- ruby_sandbox_restore(th);
+ if (ruby_sandbox_restore != NULL)
+ {
+ ruby_sandbox_restore(th);
}
ruby_frame = th->frame;
ruby_scope = th->scope;
@@ -10457,9 +10351,9 @@ static volatile int C(f), C(g), C(h), C(i), C(j);
static volatile int C(k), C(l), C(m), C(n), C(o);
static volatile int C(p), C(q), C(r), C(s), C(t);
int rb_dummy_false = 0;
-NORETURN(NOINLINE(static void register_stack_extend(rb_thread_t, int, VALUE *)));
+NORETURN(NOINLINE(static void register_stack_extend(rb_thread_t, int, void *, VALUE *)));
static void
-register_stack_extend(rb_thread_t th, int exit, VALUE *curr_bsp)
+register_stack_extend(rb_thread_t th, int exit, void *vp, VALUE *curr_bsp)
{
if (rb_dummy_false) {
/* use registers as much as possible */
@@ -10473,63 +10367,52 @@ register_stack_extend(rb_thread_t th, int exit, VALUE *curr_bsp)
E(p) = E(q) = E(r) = E(s) = E(t) = 0;
}
if (curr_bsp < th->bstr_pos+th->bstr_len) {
- register_stack_extend(th, exit, (VALUE*)rb_ia64_bsp());
+ register_stack_extend(th, exit, &exit, (VALUE*)rb_ia64_bsp());
}
- stack_extend(th, exit);
+ rb_thread_restore_context_0(th, exit, &exit);
}
#undef C
#undef E
#endif
+# if defined(_MSC_VER) && _MSC_VER >= 1300
+__declspec(noinline) static void stack_extend(rb_thread_t, int, VALUE*);
+# endif
static void
-stack_extend(rb_thread_t th, int exit)
+stack_extend(rb_thread_t th, int exit, VALUE *addr_in_prev_frame)
{
#define STACK_PAD_SIZE 1024
- volatile VALUE space[STACK_PAD_SIZE], *sp = space;
+ VALUE space[STACK_PAD_SIZE];
-#if !STACK_GROW_DIRECTION
- if (space < rb_gc_stack_start) {
+#if STACK_GROW_DIRECTION < 0
+ if (addr_in_prev_frame > th->stk_pos) stack_extend(th, exit, &space[0]);
+#elif STACK_GROW_DIRECTION > 0
+ if (addr_in_prev_frame < th->stk_pos + th->stk_len) stack_extend(th, exit, &space[STACK_PAD_SIZE-1]);
+#else
+ if (addr_in_prev_frame < rb_gc_stack_start) {
/* Stack grows downward */
-#endif
-#if STACK_GROW_DIRECTION <= 0
- if (space > th->stk_pos) {
-# ifdef HAVE_ALLOCA
- sp = ALLOCA_N(VALUE, &space[0] - th->stk_pos);
-# else
- stack_extend(th, exit);
-# endif
- }
-#endif
-#if !STACK_GROW_DIRECTION
+ if (addr_in_prev_frame > th->stk_pos) stack_extend(th, exit, &space[0]);
}
else {
/* Stack grows upward */
-#endif
-#if STACK_GROW_DIRECTION >= 0
- if (&space[STACK_PAD_SIZE] < th->stk_pos + th->stk_len) {
-# ifdef HAVE_ALLOCA
- sp = ALLOCA_N(VALUE, th->stk_pos + th->stk_len - &space[STACK_PAD_SIZE]);
-# else
- stack_extend(th, exit);
-# endif
- }
-#endif
-#if !STACK_GROW_DIRECTION
+ if (addr_in_prev_frame < th->stk_pos + th->stk_len) stack_extend(th, exit, &space[STACK_PAD_SIZE-1]);
}
#endif
- rb_thread_restore_context_0(th, exit);
-}
#ifdef __ia64
-#define stack_extend(th, exit) register_stack_extend(th, exit, (VALUE*)rb_ia64_bsp())
+ register_stack_extend(th, exit, space, (VALUE*)rb_ia64_bsp());
+#else
+ rb_thread_restore_context_0(th, exit, space);
#endif
+}
static void
rb_thread_restore_context(th, exit)
rb_thread_t th;
int exit;
{
+ VALUE v;
if (!th->stk_ptr) rb_bug("unsaved context");
- stack_extend(th, exit);
+ stack_extend(th, exit, &v);
}
static void
@@ -10548,7 +10431,8 @@ rb_thread_die(th)
{
th->thgroup = 0;
th->status = THREAD_KILLED;
- stack_free(th);
+ if (th->stk_ptr) free(th->stk_ptr);
+ th->stk_ptr = 0;
}
static void
@@ -10691,7 +10575,6 @@ rb_thread_schedule()
rb_thread_t next; /* OK */
rb_thread_t th;
rb_thread_t curr;
- rb_thread_t th_found = 0;
int found = 0;
fd_set readfds;
@@ -10709,7 +10592,6 @@ rb_thread_schedule()
}
#endif
rb_thread_pending = 0;
- rb_gc_finalize_deferred();
if (curr_thread == curr_thread->next
&& curr_thread->status == THREAD_RUNNABLE)
return;
@@ -10837,22 +10719,28 @@ rb_thread_schedule()
if (n > 0) {
now = -1.0;
/* Some descriptors are ready.
- * Choose a thread which may run next.
- * Don't change the status of threads which don't run next.
- */
+ Make the corresponding threads runnable. */
FOREACH_THREAD_FROM(curr, th) {
if ((th->wait_for&WAIT_FD) && FD_ISSET(th->fd, &readfds)) {
- th_found = th;
+ /* Wake up only one thread per fd. */
+ FD_CLR(th->fd, &readfds);
+ th->status = THREAD_RUNNABLE;
+ th->fd = 0;
+ th->wait_for = 0;
found = 1;
- break;
}
if ((th->wait_for&WAIT_SELECT) &&
(match_fds(&readfds, &th->readfds, max) ||
match_fds(&writefds, &th->writefds, max) ||
match_fds(&exceptfds, &th->exceptfds, max))) {
- th_found = th;
- found = 1;
- break;
+ /* Wake up only one thread per fd. */
+ th->status = THREAD_RUNNABLE;
+ th->wait_for = 0;
+ n = intersect_fds(&readfds, &th->readfds, max) +
+ intersect_fds(&writefds, &th->writefds, max) +
+ intersect_fds(&exceptfds, &th->exceptfds, max);
+ th->select_value = n;
+ found = 1;
}
}
END_FOREACH_FROM(curr, th);
@@ -10868,23 +10756,9 @@ rb_thread_schedule()
next = th;
break;
}
- if ((th->status == THREAD_RUNNABLE || th == th_found) && th->stk_ptr) {
- if (!next || next->priority < th->priority) {
- if (th == th_found) {
- th_found->status = THREAD_RUNNABLE;
- th_found->wait_for = 0;
- if (th->wait_for&WAIT_FD) {
- th_found->fd = 0;
- }
- else { /* th->wait_for&WAIT_SELECT */
- n = intersect_fds(&readfds, &th_found->readfds, max) +
- intersect_fds(&writefds, &th_found->writefds, max) +
- intersect_fds(&exceptfds, &th_found->exceptfds, max);
- th_found->select_value = n;
- }
- }
- next = th;
- }
+ if (th->status == THREAD_RUNNABLE && th->stk_ptr) {
+ if (!next || next->priority < th->priority)
+ next = th;
}
}
END_FOREACH_FROM(curr, th);
@@ -11130,12 +11004,14 @@ rb_thread_select(max, read, write, except, timeout)
return curr_thread->select_value;
}
+static int rb_thread_join _((rb_thread_t, double));
+
static int
rb_thread_join(th, limit)
rb_thread_t th;
double limit;
{
- enum rb_thread_status last_status = THREAD_RUNNABLE;
+ enum thread_status last_status = THREAD_RUNNABLE;
if (rb_thread_critical) rb_thread_deadlock();
if (!rb_thread_dead(th)) {
@@ -11158,7 +11034,7 @@ rb_thread_join(th, limit)
if (!rb_thread_dead(th)) return Qfalse;
}
- if (!NIL_P(th->errinfo) && (th->flags & RAISED_EXCEPTION)) {
+ if (!NIL_P(th->errinfo) && (th->flags & THREAD_RAISED)) {
VALUE oldbt = get_backtrace(th->errinfo);
VALUE errat = make_backtrace();
VALUE errinfo = rb_obj_dup(th->errinfo);
@@ -11325,19 +11201,10 @@ VALUE
rb_thread_wakeup(thread)
VALUE thread;
{
- if (!RTEST(rb_thread_wakeup_alive(thread)))
- rb_raise(rb_eThreadError, "killed thread");
- return thread;
-}
-
-VALUE
-rb_thread_wakeup_alive(thread)
- VALUE thread;
-{
rb_thread_t th = rb_thread_check(thread);
if (th->status == THREAD_KILLED)
- return Qnil;
+ rb_raise(rb_eThreadError, "killed thread");
rb_thread_ready(th);
return thread;
@@ -11376,7 +11243,7 @@ rb_thread_run(thread)
static void
-rb_kill_thread(th, flags)
+kill_thread(th, flags)
rb_thread_t th;
int flags;
{
@@ -11411,8 +11278,8 @@ rb_thread_kill(thread)
{
rb_thread_t th = rb_thread_check(thread);
- rb_kill_thread(th, 0);
- return thread;
+ kill_thread(th, 0);
+ return thread;
}
@@ -11434,7 +11301,7 @@ rb_thread_kill_bang(thread)
VALUE thread;
{
rb_thread_t th = rb_thread_check(thread);
- rb_kill_thread(th, THREAD_NO_ENSURE);
+ kill_thread(th, THREAD_NO_ENSURE);
return thread;
}
@@ -11527,7 +11394,7 @@ rb_thread_pass()
VALUE
rb_thread_stop()
{
- enum rb_thread_status last_status = THREAD_RUNNABLE;
+ enum thread_status last_status = THREAD_RUNNABLE;
rb_thread_critical = 0;
if (curr_thread == curr_thread->next) {
@@ -11592,12 +11459,10 @@ rb_thread_sleep_forever()
/*
* call-seq:
* thr.priority => integer
- *
- * Returns the priority of <i>thr</i>. Default is inherited from the
- * current thread which creating the new thread, or zero for the
- * initial main thread; higher-priority threads will run before
- * lower-priority threads.
- *
+ *
+ * Returns the priority of <i>thr</i>. Default is zero; higher-priority threads
+ * will run before lower-priority threads.
+ *
* Thread.current.priority #=> 0
*/
@@ -11612,10 +11477,10 @@ rb_thread_priority(thread)
/*
* call-seq:
* thr.priority= integer => thr
- *
+ *
* Sets the priority of <i>thr</i> to <i>integer</i>. Higher-priority threads
* will run before lower-priority threads.
- *
+ *
* count1 = count2 = 0
* a = Thread.new do
* loop { count1 += 1 }
@@ -11765,15 +11630,6 @@ rb_thread_abort_exc_set(thread, val)
}
-enum rb_thread_status
-rb_thread_status(thread)
- VALUE thread;
-{
- rb_thread_t th = rb_thread_check(thread);
- return th->status;
-}
-
-
/*
* call-seq:
* thr.group => thgrp or nil
@@ -11802,7 +11658,7 @@ rb_thread_group(thread)
#endif
#define THREAD_ALLOC(th) do {\
- th = ALLOC(struct rb_thread);\
+ th = ALLOC(struct thread);\
\
th->next = 0;\
th->prev = 0;\
@@ -11844,9 +11700,9 @@ rb_thread_group(thread)
th->locals = 0;\
th->thread = 0;\
if (curr_thread == 0) {\
- th->sandbox = Qnil;\
+ th->sandbox = Qnil;\
} else {\
- th->sandbox = curr_thread->sandbox;\
+ th->sandbox = curr_thread->sandbox;\
}\
} while (0)
@@ -11867,7 +11723,7 @@ rb_thread_alloc(klass)
return th;
}
-static int thread_init;
+static int thread_init = 0;
#if defined(_THREAD_SAFE)
static void
@@ -11880,36 +11736,21 @@ catch_timer(sig)
/* cause EINTR */
}
-static int time_thread_alive_p = 0;
static pthread_t time_thread;
static void*
thread_timer(dummy)
void *dummy;
{
-#ifdef _THREAD_SAFE
-#define test_cancel() pthread_testcancel()
-#else
-#define test_cancel() /* void */
-#endif
-
- sigset_t all_signals;
-
- sigfillset(&all_signals);
- pthread_sigmask(SIG_BLOCK, &all_signals, 0);
-
for (;;) {
#ifdef HAVE_NANOSLEEP
struct timespec req, rem;
- test_cancel();
req.tv_sec = 0;
req.tv_nsec = 10000000;
nanosleep(&req, &rem);
#else
struct timeval tv;
-
- test_cancel();
tv.tv_sec = 0;
tv.tv_usec = 10000;
select(0, NULL, NULL, NULL, &tv);
@@ -11921,7 +11762,6 @@ thread_timer(dummy)
}
}
}
-#undef test_cancel
}
void
@@ -11933,26 +11773,6 @@ void
rb_thread_stop_timer()
{
}
-
-void
-rb_child_atfork()
-{
- time_thread_alive_p = 0;
-}
-
-void
-rb_thread_cancel_timer()
-{
-#ifdef _THREAD_SAFE
- if( time_thread_alive_p )
- {
- pthread_cancel( time_thread );
- pthread_join( time_thread, NULL );
- time_thread_alive_p = 0;
- }
- thread_init = 0;
-#endif
-}
#elif defined(HAVE_SETITIMER)
static void
catch_timer(sig)
@@ -11990,19 +11810,8 @@ rb_thread_stop_timer()
tval.it_value = tval.it_interval;
setitimer(ITIMER_VIRTUAL, &tval, NULL);
}
-
-void
-rb_thread_cancel_timer()
-{
-}
-
#else /* !(_THREAD_SAFE || HAVE_SETITIMER) */
int rb_thread_tick = THREAD_TICK;
-
-void
-rb_thread_cancel_timer()
-{
-}
#endif
static VALUE
@@ -12014,7 +11823,7 @@ rb_thread_start_0(fn, arg, th)
volatile rb_thread_t th_save = th;
volatile VALUE thread = th->thread;
struct BLOCK *volatile saved_block = 0;
- enum rb_thread_status status;
+ enum thread_status status;
int state;
if (OBJ_FROZEN(curr_thread->thgroup)) {
@@ -12033,8 +11842,6 @@ rb_thread_start_0(fn, arg, th)
#ifdef _THREAD_SAFE
pthread_create(&time_thread, 0, thread_timer, 0);
- time_thread_alive_p = 1;
- pthread_atfork(0, 0, rb_child_atfork);
#else
rb_thread_start_timer();
#endif
@@ -12087,7 +11894,7 @@ rb_thread_start_0(fn, arg, th)
}
if (state && status != THREAD_TO_KILL && !NIL_P(ruby_errinfo)) {
- th->flags |= RAISED_EXCEPTION;
+ th->flags |= THREAD_RAISED;
if (state == TAG_FATAL) {
/* fatal error within this thread, need to stop whole script */
main_thread->errinfo = ruby_errinfo;
@@ -12124,7 +11931,7 @@ rb_thread_create(fn, arg)
VALUE (*fn)();
void *arg;
{
- Init_stack((void *)&arg);
+ Init_stack((VALUE*)&arg);
return rb_thread_start_0(fn, arg, rb_thread_alloc(rb_cThread));
}
@@ -12299,13 +12106,13 @@ rb_thread_value(thread)
*/
static VALUE
-rb_thread_status_name(thread)
+rb_thread_status(thread)
VALUE thread;
{
rb_thread_t th = rb_thread_check(thread);
if (rb_thread_dead(th)) {
- if (!NIL_P(th->errinfo) && (th->flags & RAISED_EXCEPTION))
+ if (!NIL_P(th->errinfo) && (th->flags & THREAD_RAISED))
return Qnil;
return Qfalse;
}
@@ -12326,7 +12133,7 @@ rb_thread_status_name(thread)
* thr.alive? #=> false
*/
-VALUE
+static VALUE
rb_thread_alive_p(thread)
VALUE thread;
{
@@ -12791,38 +12598,6 @@ rb_thread_atfork()
}
-static void
-cc_purge(cc)
- rb_thread_t cc;
-{
- /* free continuation's stack if it has just died */
- if (NIL_P(cc->thread)) return;
- if (rb_thread_check(cc->thread)->status == THREAD_KILLED) {
- cc->thread = Qnil;
- rb_thread_die(cc); /* can't possibly activate this stack */
- }
-}
-
-static void
-cc_mark(cc)
- rb_thread_t cc;
-{
- /* mark this continuation's stack only if its parent thread is still alive */
- cc_purge(cc);
- thread_mark(cc);
-}
-
-static rb_thread_t
-rb_cont_check(data)
- VALUE data;
-{
- if (TYPE(data) != T_DATA || RDATA(data)->dmark != (RUBY_DATA_FUNC)cc_mark) {
- rb_raise(rb_eTypeError, "wrong argument type %s (expected Continuation)",
- rb_obj_classname(data));
- }
- return (rb_thread_t)RDATA(data)->data;
-}
-
/*
* Document-class: Continuation
*
@@ -12897,16 +12672,14 @@ rb_callcc(self)
struct RVarmap *vars;
THREAD_ALLOC(th);
- /* must finish th initialization before any possible gc.
- * brent@mbari.org */
- th->thread = curr_thread->thread;
- th->thgroup = cont_protect;
- cont = Data_Wrap_Struct(rb_cCont, cc_mark, thread_free, th);
+ cont = Data_Wrap_Struct(rb_cCont, thread_mark, thread_free, th);
scope_dup(ruby_scope);
for (tag=prot_tag; tag; tag=tag->prev) {
scope_dup(tag->scope);
}
+ th->thread = curr_thread->thread;
+ th->thgroup = cont_protect;
for (vars = ruby_dyna_vars; vars; vars = vars->next) {
if (FL_TEST(vars, DVAR_DONT_RECYCLE)) break;
@@ -12943,7 +12716,7 @@ rb_cont_call(argc, argv, cont)
VALUE *argv;
VALUE cont;
{
- rb_thread_t th = rb_cont_check(cont);
+ rb_thread_t th = rb_thread_check(cont);
if (th->thread != curr_thread->thread) {
rb_raise(rb_eRuntimeError, "continuation called across threads");
@@ -13119,6 +12892,10 @@ thgroup_add(group, thread)
rb_secure(4);
th = rb_thread_check(thread);
+ if (!th->next || !th->prev) {
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected Thread)",
+ rb_obj_classname(thread));
+ }
if (OBJ_FROZEN(group)) {
rb_raise(rb_eThreadError, "can't move to the frozen thread group");
@@ -13190,7 +12967,7 @@ Init_Thread()
rb_define_method(rb_cThread, "terminate!", rb_thread_kill_bang, 0);
rb_define_method(rb_cThread, "exit!", rb_thread_kill_bang, 0);
rb_define_method(rb_cThread, "value", rb_thread_value, 0);
- rb_define_method(rb_cThread, "status", rb_thread_status_name, 0);
+ rb_define_method(rb_cThread, "status", rb_thread_status, 0);
rb_define_method(rb_cThread, "join", rb_thread_join_m, -1);
rb_define_method(rb_cThread, "alive?", rb_thread_alive_p, 0);
rb_define_method(rb_cThread, "stop?", rb_thread_stop_p, 0);
diff --git a/ext/Win32API/Win32API.c b/ext/Win32API/Win32API.c
index a4fd0396f0..96ce8c6636 100644
--- a/ext/Win32API/Win32API.c
+++ b/ext/Win32API/Win32API.c
@@ -108,7 +108,7 @@ Win32API_initialize(self, dllname, proc, import, export)
}
if (16 < RARRAY(a_import)->len) {
- rb_raise(rb_eRuntimeError, "too many parameters: %ld\n", RARRAY(a_import)->len);
+ rb_raise(rb_eRuntimeError, "too many parameters: %d\n", RARRAY(a_import)->len);
}
rb_iv_set(self, "__import__", a_import);
diff --git a/ext/Win32API/lib/win32/registry.rb b/ext/Win32API/lib/win32/registry.rb
index 9a2f3827b7..2671551a33 100644
--- a/ext/Win32API/lib/win32/registry.rb
+++ b/ext/Win32API/lib/win32/registry.rb
@@ -493,7 +493,7 @@ module Win32
# utility functions
#
def self.expand_environ(str)
- str.gsub(/%([^%]+)%/) { ENV[$1] || ENV[$1.upcase] || $& }
+ str.gsub(/%([^%]+)%/) { ENV[$1] || $& }
end
@@type2name = { }
diff --git a/ext/Win32API/lib/win32/resolv.rb b/ext/Win32API/lib/win32/resolv.rb
index 92336fac28..6534d20760 100644
--- a/ext/Win32API/lib/win32/resolv.rb
+++ b/ext/Win32API/lib/win32/resolv.rb
@@ -11,7 +11,7 @@ module Win32
def self.get_hosts_path
path = get_hosts_dir
- path = File.expand_path('hosts', path)
+ path = File.join(path.gsub(/\\/, File::SEPARATOR), 'hosts')
File.exist?(path) ? path : nil
end
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 7400b313a4..a4b769e8cf 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -586,22 +586,19 @@ BigDecimal_to_f(VALUE self)
{
ENTER(1);
Real *p;
- double d;
+ double d, d2;
S_LONG e;
- char *buf;
GUARD_OBJ(p,GetVpValue(self,1));
if(VpVtoD(&d, &e, p)!=1) return rb_float_new(d);
- buf = ALLOCA_N(char,(unsigned int)VpNumOfChars(p,"E"));
- VpToString(p, buf, 0, 0);
errno = 0;
- d = strtod(buf, 0);
- if(errno == ERANGE) {
+ d2 = pow(10.0,(double)e);
+ if((errno == ERANGE && e>0) || (d2>1.0 && (fabs(d) > (DBL_MAX / d2)))) {
VpException(VP_EXCEPTION_OVERFLOW,"BigDecimal to Float conversion",0);
if(d>0.0) return rb_float_new(DBL_MAX);
else return rb_float_new(-DBL_MAX);
}
- return rb_float_new(d);
+ return rb_float_new(d*d2);
}
/* The coerce method provides support for Ruby type coercion. It is not
@@ -1054,7 +1051,7 @@ static VALUE
BigDecimal_remainder(VALUE self, VALUE r) /* remainder */
{
VALUE f;
- Real *d,*rv=0;
+ Real *d,*rv;
f = BigDecimal_divremain(self,r,&d,&rv);
if(f!=(VALUE)0) return f;
return ToValue(rv);
@@ -1508,7 +1505,7 @@ BigDecimal_to_s(int argc, VALUE *argv, VALUE self)
} else if(*psz=='+') {
fPlus = 2; psz++;
}
- while((ch=*psz++)!=0) {
+ while(ch=*psz++) {
if(ISSPACE(ch)) continue;
if(!ISDIGIT(ch)) {
if(ch=='F' || ch=='f') fmt = 1; /* F format */
@@ -1965,27 +1962,17 @@ static int gfCheckVal = 1; /* Value checking flag in VpNmlz() */
static U_LONG gnPrecLimit = 0; /* Global upper limit of the precision newly allocated */
static U_LONG gfRoundMode = VP_ROUND_HALF_UP; /* Mode for general rounding operation */
-#ifndef BASE_FIG
static U_LONG BASE_FIG = 4; /* =log10(BASE) */
static U_LONG BASE = 10000L; /* Base value(value must be 10**BASE_FIG) */
/* The value of BASE**2 + BASE must be represented */
/* within one U_LONG. */
static U_LONG HALF_BASE = 5000L;/* =BASE/2 */
+static S_LONG DBLE_FIG = 8; /* figure of double */
static U_LONG BASE1 = 1000L; /* =BASE/10 */
-#else
-#ifndef BASE
-#error BASE_FIG is defined but BASE is not
-#endif
-#define HALF_BASE (BASE/2)
-#define BASE1 (BASE/10)
-#endif
-#ifndef DBLE_FIG
-#define DBLE_FIG (DBL_DIG+1) /* figure of double */
-#endif
static Real *VpConstOne; /* constant 1.0 */
static Real *VpPt5; /* constant 0.5 */
-#define maxnr 100UL /* Maximum iterations for calcurating sqrt. */
+static U_LONG maxnr = 100; /* Maximum iterations for calcurating sqrt. */
/* used in VpSqrt() */
/* ETC */
@@ -2102,8 +2089,8 @@ VpSetRoundMode(unsigned long n)
* (to let the compiler know they may be changed in outside
* (... but not actually..)).
*/
-volatile const double gZero_ABCED9B1_CE73__00400511F31D = 0.0;
-volatile const double gOne_ABCED9B4_CE73__00400511F31D = 1.0;
+volatile double gZero_ABCED9B1_CE73__00400511F31D = 0.0;
+volatile double gOne_ABCED9B4_CE73__00400511F31D = 1.0;
static double
Zero(void)
{
@@ -2375,15 +2362,16 @@ VpNumOfChars(Real *vp,const char *pszFmt)
VP_EXPORT U_LONG
VpInit(U_LONG BaseVal)
{
+ U_LONG w;
+ double v;
+
/* Setup +/- Inf NaN -0 */
VpGetDoubleNaN();
VpGetDoublePosInf();
VpGetDoubleNegInf();
VpGetDoubleNegZero();
-#ifndef BASE_FIG
if(BaseVal <= 0) {
- U_LONG w;
/* Base <= 0, then determine Base by calcuration. */
BASE = 1;
while(
@@ -2400,8 +2388,6 @@ VpInit(U_LONG BaseVal)
BASE1 = BASE / 10;
BASE_FIG = 0;
while(BaseVal /= 10) ++BASE_FIG;
-#endif
-
/* Allocates Vp constants. */
VpConstOne = VpAlloc((U_LONG)1, "1");
VpPt5 = VpAlloc((U_LONG)1, ".5");
@@ -2410,6 +2396,15 @@ VpInit(U_LONG BaseVal)
gnAlloc = 0;
#endif /* _DEBUG */
+ /* Determine # of digits available in one 'double'. */
+
+ v = 1.0;
+ DBLE_FIG = 0;
+ while(v + 1.0 > 1.0) {
+ ++DBLE_FIG;
+ v /= 10;
+ }
+
#ifdef _DEBUG
if(gfDebug) {
printf("VpInit: BaseVal = %lu\n", BaseVal);
@@ -2512,7 +2507,7 @@ VpAlloc(U_LONG mx, const char *szVal)
psz = ALLOCA_N(char,strlen(szVal)+1);
i = 0;
ipn = 0;
- while((psz[i]=szVal[ipn])!=0) {
+ while(psz[i]=szVal[ipn]) {
if(ISDIGIT(psz[i])) ++ni;
if(psz[i]=='_') {
if(ni>0) {ipn++;continue;}
@@ -2555,7 +2550,7 @@ VpAlloc(U_LONG mx, const char *szVal)
else if(szVal[i] == '+') ++i;
/* Skip digits */
ni = 0; /* digits in mantissa */
- while((v = szVal[i]) != 0) {
+ while(v = szVal[i]) {
if(!ISDIGIT(v)) break;
++i;
++ni;
@@ -2569,7 +2564,7 @@ VpAlloc(U_LONG mx, const char *szVal)
if(szVal[i] == '.') { /* xxx. */
++i;
ipf = i;
- while((v = szVal[i]) != 0) { /* get fraction part. */
+ while(v = szVal[i]) { /* get fraction part. */
if(!ISDIGIT(v)) break;
++i;
++nf;
@@ -2587,7 +2582,7 @@ VpAlloc(U_LONG mx, const char *szVal)
ipe = i;
v = szVal[i];
if((v == '-') ||(v == '+')) ++i;
- while((v=szVal[i])!=0) {
+ while(v=szVal[i]) {
if(!ISDIGIT(v)) break;
++i;
++ne;
@@ -4345,11 +4340,6 @@ VpMidRound(Real *y, int f, int nf)
nf += y->exponent*((int)BASE_FIG);
exptoadd=0;
if (nf < 0) {
- /* rounding position too left(large). */
- if((f!=VP_ROUND_CEIL) && (f!=VP_ROUND_FLOOR)) {
- VpSetZero(y,VpGetSign(y)); /* truncate everything */
- return 0;
- }
exptoadd = -nf;
nf = 0;
}
@@ -4444,7 +4434,7 @@ VpLeftRound(Real *y, int f, int nf)
if(!VpHasVal(y)) return 0; /* Unable to round */
v = y->frac[0];
nf -= VpExponent(y)*BASE_FIG;
- while((v /= 10) != 0) nf--;
+ while(v=v/10) nf--;
nf += (BASE_FIG-1);
return VpMidRound(y,f,nf);
}
diff --git a/ext/bigdecimal/extconf.rb b/ext/bigdecimal/extconf.rb
index 864aaad862..a68a656044 100644
--- a/ext/bigdecimal/extconf.rb
+++ b/ext/bigdecimal/extconf.rb
@@ -1,12 +1,2 @@
require 'mkmf'
-
-base_fig = 0
-src = ("(BASE > 0) && "
- "(BASE * (BASE+1)) > BASE && "
- "(BASE * (BASE+1)) / BASE == (BASE+1)")
-while try_static_assert(src, nil, "-DBASE=10#{'0'*base_fig}UL")
- base_fig += 1
-end
-$defs << "-DBASE=1#{'0'*base_fig}UL" << "-DBASE_FIG=#{base_fig}"
-
create_makefile('bigdecimal')
diff --git a/ext/curses/extconf.rb b/ext/curses/extconf.rb
index 0124bbbf4a..01fe971093 100644
--- a/ext/curses/extconf.rb
+++ b/ext/curses/extconf.rb
@@ -20,7 +20,7 @@ end
if make
for f in %w(beep bkgd bkgdset curs_set deleteln doupdate flash getbkgd getnstr init isendwin keyname keypad resizeterm scrl set setscrreg ungetch wattroff wattron wattrset wbkgd wbkgdset wdeleteln wgetnstr wresize wscrl wsetscrreg def_prog_mode reset_prog_mode timeout wtimeout nodelay init_color wcolor_set)
- have_func(f) || (have_macro(f, curses) && $defs.push(format("-DHAVE_%s", f.upcase)))
+ have_func(f)
end
flag = "-D_XOPEN_SOURCE_EXTENDED"
src = "int test_var[(sizeof(char*)>sizeof(int))*2-1];"
diff --git a/ext/digest/digest.c b/ext/digest/digest.c
index 0b910e8c47..92a925c616 100644
--- a/ext/digest/digest.c
+++ b/ext/digest/digest.c
@@ -97,7 +97,7 @@ rb_digest_s_hexencode(VALUE klass, VALUE str)
static VALUE
rb_digest_instance_update(VALUE self, VALUE str)
{
- rb_raise(rb_eRuntimeError, "%s does not implement update()", RSTRING_PTR(rb_inspect(self)));
+ rb_raise(rb_eRuntimeError, "%s does not implement update()", rb_inspect(self));
}
/*
@@ -115,7 +115,7 @@ rb_digest_instance_update(VALUE self, VALUE str)
static VALUE
rb_digest_instance_finish(VALUE self)
{
- rb_raise(rb_eRuntimeError, "%s does not implement finish()", RSTRING_PTR(rb_inspect(self)));
+ rb_raise(rb_eRuntimeError, "%s does not implement finish()", rb_inspect(self));
}
/*
@@ -129,7 +129,7 @@ rb_digest_instance_finish(VALUE self)
static VALUE
rb_digest_instance_reset(VALUE self)
{
- rb_raise(rb_eRuntimeError, "%s does not implement reset()", RSTRING_PTR(rb_inspect(self)));
+ rb_raise(rb_eRuntimeError, "%s does not implement reset()", rb_inspect(self));
}
/*
@@ -358,7 +358,7 @@ rb_digest_instance_length(VALUE self)
static VALUE
rb_digest_instance_block_length(VALUE self)
{
- rb_raise(rb_eRuntimeError, "%s does not implement block_length()", RSTRING_PTR(rb_inspect(self)));
+ rb_raise(rb_eRuntimeError, "%s does not implement block_length()", rb_inspect(self));
}
/*
@@ -381,6 +381,7 @@ static VALUE
rb_digest_class_s_digest(int argc, VALUE *argv, VALUE klass)
{
VALUE str;
+ void *pctx;
volatile VALUE obj;
if (argc < 1) {
diff --git a/ext/digest/lib/digest.rb b/ext/digest/lib/digest.rb
index 0c4ee3c2cc..244cd436b3 100644
--- a/ext/digest/lib/digest.rb
+++ b/ext/digest/lib/digest.rb
@@ -12,11 +12,9 @@ module Digest
begin
require lib
rescue LoadError => e
- raise LoadError, "library not found for class Digest::#{name} -- #{lib}", caller(1)
- end
- unless Digest.const_defined?(name)
- raise NameError, "uninitialized constant Digest::#{name}", caller(1)
+ raise LoadError, "library not found for class Digest::#{name} -- #{lib}"
end
+
Digest.const_get(name)
end
diff --git a/ext/dl/dl.c b/ext/dl/dl.c
index 88e954c668..5ba3646ea3 100644
--- a/ext/dl/dl.c
+++ b/ext/dl/dl.c
@@ -522,15 +522,12 @@ rb_str_to_ptr(VALUE self)
{
char *ptr;
int len;
- VALUE p;
len = RSTRING(self)->len;
ptr = (char*)dlmalloc(len + 1);
memcpy(ptr, RSTRING(self)->ptr, len);
ptr[len] = '\0';
- p = rb_dlptr_new((void*)ptr,len,dlfree);
- OBJ_INFECT(p, self);
- return p;
+ return rb_dlptr_new((void*)ptr,len,dlfree);
}
VALUE
@@ -548,12 +545,7 @@ rb_ary_to_ptr(int argc, VALUE argv[], VALUE self)
ptr = rb_ary2cary(0, self, &size);
break;
}
- if (ptr) {
- VALUE p = rb_dlptr_new(ptr, size, dlfree);
- OBJ_INFECT(p, self);
- return p;
- }
- return Qnil;
+ return ptr ? rb_dlptr_new(ptr, size, dlfree) : Qnil;
}
VALUE
@@ -571,7 +563,7 @@ rb_io_to_ptr(VALUE self)
VALUE
rb_dl_dlopen(int argc, VALUE argv[], VALUE self)
{
- rb_secure(2);
+ rb_secure(4);
return rb_class_new_instance(argc, argv, rb_cDLHandle);
}
diff --git a/ext/dl/lib/dl/win32.rb b/ext/dl/lib/dl/win32.rb
index 0fed47c324..92f473d392 100644
--- a/ext/dl/lib/dl/win32.rb
+++ b/ext/dl/lib/dl/win32.rb
@@ -6,7 +6,7 @@ class Win32API
DLL = {}
def initialize(dllname, func, import, export = "0")
- prototype = (export + import.to_s).tr("VPpNnLlIi", "0SSI").sub(/^(.)0*$/, '\1')
+ prototype = (export + import.to_s).tr("VPpNnLlIi", "0SSI")
handle = DLL[dllname] ||= DL::Handle.new(dllname)
@sym = handle.sym(func, prototype)
end
diff --git a/ext/dl/ptr.c b/ext/dl/ptr.c
index 7e3d3549d3..4d75a3ddf2 100644
--- a/ext/dl/ptr.c
+++ b/ext/dl/ptr.c
@@ -4,22 +4,30 @@
#include <ruby.h>
#include <ctype.h>
-#include "st.h"
+#include <version.h> /* for ruby version code */
#include "dl.h"
VALUE rb_cDLPtrData;
VALUE rb_mDLMemorySpace;
-static st_table* st_memory_table;
+static VALUE DLMemoryTable;
#ifndef T_SYMBOL
# define T_SYMBOL T_FIXNUM
#endif
+#if RUBY_VERSION_CODE < 171
+static VALUE
+rb_hash_delete(VALUE hash, VALUE key)
+{
+ return rb_funcall(hash, rb_intern("delete"), 1, key);
+}
+#endif
+
static void
rb_dlmem_delete(void *ptr)
{
rb_secure(4);
- st_delete(st_memory_table, (st_data_t*)&ptr, NULL);
+ rb_hash_delete(DLMemoryTable, DLLONG2NUM(ptr));
}
static void
@@ -29,7 +37,7 @@ rb_dlmem_aset(void *ptr, VALUE obj)
rb_dlmem_delete(ptr);
}
else{
- st_insert(st_memory_table, (st_data_t)ptr, (st_data_t)obj);
+ rb_hash_aset(DLMemoryTable, DLLONG2NUM(ptr), DLLONG2NUM(obj));
}
}
@@ -38,8 +46,8 @@ rb_dlmem_aref(void *ptr)
{
VALUE val;
- if(!st_lookup(st_memory_table, (st_data_t)ptr, &val)) return Qnil;
- return val == Qundef ? Qnil : val;
+ val = rb_hash_aref(DLMemoryTable, DLLONG2NUM(ptr));
+ return val == Qnil ? Qnil : (VALUE)DLNUM2LONG(val);
}
void
@@ -458,9 +466,8 @@ rb_dlptr_inspect(VALUE self)
char str[1024];
Data_Get_Struct(self, struct ptr_data, data);
- snprintf(str, 1023, "#<%s:0x%lx ptr=0x%lx size=%ld free=0x%lx>",
- rb_class2name(CLASS_OF(self)), data, data->ptr, data->size,
- (long)data->free);
+ snprintf(str, 1023, "#<%s:0x%x ptr=0x%x size=%ld free=0x%x>",
+ rb_class2name(CLASS_OF(self)), data, data->ptr, data->size, data->free);
return rb_str_new2(str);
}
@@ -1002,18 +1009,20 @@ rb_dlptr_size(int argc, VALUE argv[], VALUE self)
}
}
-static int
-dlmem_each_i(void* key, VALUE value, void* arg)
+static VALUE
+dlmem_each_i(VALUE assoc, void *data)
{
- VALUE vkey = DLLONG2NUM(key);
- rb_yield(rb_assoc_new(vkey, value));
+ VALUE key, val;
+ key = rb_ary_entry(assoc, 0);
+ val = rb_ary_entry(assoc, 1);
+ rb_yield(rb_assoc_new(key,(VALUE)DLNUM2LONG(val)));
return Qnil;
}
VALUE
rb_dlmem_each(VALUE self)
{
- st_foreach(st_memory_table, dlmem_each_i, 0);
+ rb_iterate(rb_each, DLMemoryTable, dlmem_each_i, 0);
return Qnil;
}
@@ -1052,7 +1061,7 @@ Init_dlptr()
rb_define_method(rb_cDLPtrData, "size=", rb_dlptr_size, -1);
rb_mDLMemorySpace = rb_define_module_under(rb_mDL, "MemorySpace");
- st_memory_table = st_init_numtable();
- rb_define_const(rb_mDLMemorySpace, "MemoryTable", Qnil); /* historical */
+ DLMemoryTable = rb_hash_new();
+ rb_define_const(rb_mDLMemorySpace, "MemoryTable", DLMemoryTable);
rb_define_module_function(rb_mDLMemorySpace, "each", rb_dlmem_each, 0);
}
diff --git a/ext/dl/sym.c b/ext/dl/sym.c
index 933fb7f4f0..87d07e7cbe 100644
--- a/ext/dl/sym.c
+++ b/ext/dl/sym.c
@@ -268,7 +268,7 @@ rb_dlsym_inspect(VALUE self)
str_size = RSTRING(proto)->len + 100;
str = dlmalloc(str_size);
snprintf(str, str_size - 1,
- "#<DL::Symbol:0x%lx func=0x%lx '%s'>",
+ "#<DL::Symbol:0x%x func=0x%x '%s'>",
sym, sym->func, RSTRING(proto)->ptr);
val = rb_tainted_str_new2(str);
dlfree(str);
@@ -492,7 +492,6 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self)
rb_raise(rb_eDLTypeError, "unexpected type of argument #%d", i);
}
}
- rb_check_safe_obj(pval);
Data_Get_Struct(pval, struct ptr_data, data);
ANY2P(args[i]) = DLVOIDP(data->ptr);
}
diff --git a/ext/extmk.rb b/ext/extmk.rb
index fbec8a5bdf..ac396a0d80 100644
--- a/ext/extmk.rb
+++ b/ext/extmk.rb
@@ -112,10 +112,10 @@ def extmake(target)
Dir.chdir target
top_srcdir = $top_srcdir
topdir = $topdir
- hdrdir = $hdrdir
+ mk_srcdir = CONFIG["srcdir"]
+ mk_topdir = CONFIG["topdir"]
prefix = "../" * (target.count("/")+1)
- $top_srcdir = relative_from(top_srcdir, prefix)
- $hdrdir = relative_from(hdrdir, prefix)
+ $hdrdir = $top_srcdir = relative_from(top_srcdir, prefix)
$topdir = prefix + $topdir
$target = target
$mdir = target
@@ -127,45 +127,27 @@ def extmake(target)
makefile = "./Makefile"
ok = File.exist?(makefile)
unless $ignore
- rbconfig0 = Config::CONFIG
- mkconfig0 = CONFIG
- rbconfig = {
- "hdrdir" => $hdrdir,
- "srcdir" => $srcdir,
- "topdir" => $topdir,
- }
- mkconfig = {
- "top_srcdir" => ($hdrdir == top_srcdir) ? top_srcdir : "$(topdir)"+top_srcdir[2..-1],
- "hdrdir" => "$(top_srcdir)",
- "srcdir" => "$(top_srcdir)/ext/#{$mdir}",
- "topdir" => $topdir,
- }
- rbconfig0.each_pair {|key, val| rbconfig[key] ||= val.dup}
- mkconfig0.each_pair {|key, val| mkconfig[key] ||= val.dup}
- Config.module_eval {
- remove_const(:CONFIG)
- const_set(:CONFIG, rbconfig)
- remove_const(:MAKEFILE_CONFIG)
- const_set(:MAKEFILE_CONFIG, mkconfig)
- }
- Object.class_eval {
- remove_const(:CONFIG)
- const_set(:CONFIG, mkconfig)
- }
+ Config::CONFIG["hdrdir"] = $hdrdir
+ Config::CONFIG["srcdir"] = $srcdir
+ Config::CONFIG["topdir"] = $topdir
+ CONFIG["hdrdir"] = ($hdrdir == top_srcdir) ? top_srcdir : "$(topdir)"+top_srcdir[2..-1]
+ CONFIG["srcdir"] = "$(hdrdir)/ext/#{$mdir}"
+ CONFIG["topdir"] = $topdir
begin
$extconf_h = nil
ok &&= extract_makefile(makefile)
- conf = ["#{$srcdir}/makefile.rb", "#{$srcdir}/extconf.rb"].find {|f| File.exist?(f)}
if (($extconf_h && !File.exist?($extconf_h)) ||
!(t = modified?(makefile, MTIMES)) ||
- [conf, "#{$srcdir}/depend"].any? {|f| modified?(f, [t])})
+ ["#{$srcdir}/makefile.rb", "#{$srcdir}/extconf.rb", "#{$srcdir}/depend"].any? {|f| modified?(f, [t])})
then
ok = false
init_mkmf
Logging::logfile 'mkmf.log'
rm_f makefile
- if conf
- load $0 = conf
+ if File.exist?($0 = "#{$srcdir}/makefile.rb")
+ load $0
+ elsif File.exist?($0 = "#{$srcdir}/extconf.rb")
+ load $0
else
create_makefile(target)
end
@@ -199,11 +181,7 @@ def extmake(target)
$ignore or $continue or return false
end
$compiled[target] = true
- if $clean
- FileUtils.rm_f("mkmf.log")
- if $clean != true
- FileUtils.rm_f([makefile, $extconf_h || "extconf.h"])
- end
+ if $clean and $clean != true
File.unlink(makefile) rescue nil
end
if $static
@@ -217,21 +195,13 @@ def extmake(target)
$extpath |= $LIBPATH
end
ensure
- unless $ignore
- Config.module_eval {
- remove_const(:CONFIG)
- const_set(:CONFIG, rbconfig0)
- remove_const(:MAKEFILE_CONFIG)
- const_set(:MAKEFILE_CONFIG, mkconfig0)
- }
- Object.class_eval {
- remove_const(:CONFIG)
- const_set(:CONFIG, mkconfig0)
- }
- end
- $top_srcdir = top_srcdir
+ Config::CONFIG["srcdir"] = $top_srcdir
+ Config::CONFIG["topdir"] = topdir
+ CONFIG["srcdir"] = mk_srcdir
+ CONFIG["topdir"] = mk_topdir
+ CONFIG.delete("hdrdir")
+ $hdrdir = $top_srcdir = top_srcdir
$topdir = topdir
- $hdrdir = hdrdir
Dir.chdir dir
end
begin
@@ -315,7 +285,6 @@ def parse_args()
$continue = $mflags.set?(?k)
if $extout
$extout = '$(topdir)/'+$extout
- Config::CONFIG["extout"] = CONFIG["extout"] = $extout
$extout_prefix = $extout ? "$(extout)$(target_prefix)/" : ""
$mflags << "extout=#$extout" << "extout_prefix=#$extout_prefix"
end
@@ -354,12 +323,8 @@ elsif sep = config_string('BUILD_FILE_SEPARATOR')
else
$ruby = '$(topdir)/miniruby' + EXEEXT
end
-$ruby << " -I'$(topdir)' -I'$(top_srcdir)/lib'"
-$ruby << " -I'$(extout)/$(arch)' -I'$(extout)/common'" if $extout
-$ruby << " -I'$(hdrdir)/ext' -rpurelib.rb"
+$ruby << " -I'$(topdir)' -I'$(hdrdir)/lib'"
$config_h = '$(topdir)/config.h'
-ENV["RUBYLIB"] = "-"
-ENV["RUBYOPT"] = "-rpurelib.rb"
MTIMES = [__FILE__, 'rbconfig.rb', srcdir+'/lib/mkmf.rb'].collect {|f| File.mtime(f)}
@@ -435,14 +400,12 @@ dir = Dir.pwd
FileUtils::makedirs('ext')
Dir::chdir('ext')
-hdrdir = $hdrdir
$hdrdir = $top_srcdir = relative_from(srcdir, $topdir = "..")
exts.each do |d|
extmake(d) or abort
end
-$top_srcdir = srcdir
+$hdrdir = $top_srcdir = srcdir
$topdir = "."
-$hdrdir = hdrdir
extinit = Struct.new(:c, :o) {
def initialize(src)
diff --git a/ext/gdbm/gdbm.c b/ext/gdbm/gdbm.c
index 2057101206..82109fda90 100644
--- a/ext/gdbm/gdbm.c
+++ b/ext/gdbm/gdbm.c
@@ -303,10 +303,14 @@ rb_gdbm_fetch(dbm, key)
if (val.dptr == 0)
return Qnil;
- str = rb_str_new(val.dptr, val.dsize);
- free(val.dptr);
+ str = rb_obj_alloc(rb_cString);
+ RSTRING(str)->len = val.dsize;
+ RSTRING(str)->aux.capa = val.dsize;
+ RSTRING(str)->ptr = REALLOC_N(val.dptr,char,val.dsize+1);
+ RSTRING(str)->ptr[val.dsize] = '\0';
+
OBJ_TAINT(str);
- return str;
+ return (VALUE)str;
}
static VALUE
@@ -345,8 +349,12 @@ rb_gdbm_firstkey(dbm)
if (key.dptr == 0)
return Qnil;
- str = rb_str_new(key.dptr, key.dsize);
- free(key.dptr);
+ str = rb_obj_alloc(rb_cString);
+ RSTRING(str)->len = key.dsize;
+ RSTRING(str)->aux.capa = key.dsize;
+ RSTRING(str)->ptr = REALLOC_N(key.dptr,char,key.dsize+1);
+ RSTRING(str)->ptr[RSTRING(str)->len] = '\0';
+
OBJ_TAINT(str);
return str;
}
@@ -365,8 +373,12 @@ rb_gdbm_nextkey(dbm, keystr)
if (key2.dptr == 0)
return Qnil;
- str = rb_str_new(key2.dptr, key2.dsize);
- free(key2.dptr);
+ str = rb_obj_alloc(rb_cString);
+ RSTRING(str)->len = key2.dsize;
+ RSTRING(str)->aux.capa = key2.dsize;
+ RSTRING(str)->ptr = REALLOC_N(key2.dptr,char,key2.dsize+1);
+ RSTRING(str)->ptr[RSTRING(str)->len] = '\0';
+
OBJ_TAINT(str);
return str;
}
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
index 4674aa330e..1c9d607de9 100644
--- a/ext/iconv/iconv.c
+++ b/ext/iconv/iconv.c
@@ -101,7 +101,7 @@ static void iconv_dfree _((void *cd));
static VALUE iconv_free _((VALUE cd));
static VALUE iconv_try _((iconv_t cd, const char **inptr, size_t *inlen, char **outptr, size_t *outlen));
static VALUE rb_str_derive _((VALUE str, const char* ptr, int len));
-static VALUE iconv_convert _((iconv_t cd, VALUE str, long start, long length, struct iconv_env_t* env));
+static VALUE iconv_convert _((iconv_t cd, VALUE str, int start, int length, struct iconv_env_t* env));
static VALUE iconv_s_allocate _((VALUE klass));
static VALUE iconv_initialize _((VALUE self, VALUE to, VALUE from));
static VALUE iconv_s_open _((VALUE self, VALUE to, VALUE from));
@@ -170,7 +170,7 @@ iconv_create
}
if (cd == (iconv_t)-1) {
int inval = errno == EINVAL;
- const char *s = inval ? "invalid encoding " : "iconv";
+ char *s = inval ? "invalid encoding " : "iconv";
volatile VALUE msg = rb_str_new(0, strlen(s) + RSTRING(to)->len +
RSTRING(from)->len + 8);
@@ -362,13 +362,13 @@ rb_str_derive
static VALUE
iconv_convert
#ifdef HAVE_PROTOTYPES
- (iconv_t cd, VALUE str, long start, long length, struct iconv_env_t* env)
+ (iconv_t cd, VALUE str, int start, int length, struct iconv_env_t* env)
#else /* HAVE_PROTOTYPES */
(cd, str, start, length, env)
iconv_t cd;
VALUE str;
- long start;
- long length;
+ int start;
+ int length;
struct iconv_env_t *env;
#endif /* HAVE_PROTOTYPES */
{
@@ -417,9 +417,14 @@ iconv_convert
slen = RSTRING(str)->len;
inptr = RSTRING(str)->ptr;
- inptr += start;
- if (length < 0 || length > start + slen)
- length = slen - start;
+ if (start < 0 ? (start += slen) < 0 : start >= slen)
+ length = 0;
+ else if (length < 0 && (length += slen + 1) < 0)
+ length = 0;
+ else if ((length -= start) < 0)
+ length = 0;
+ else
+ inptr += start;
}
instart = inptr;
inlen = length;
@@ -644,7 +649,7 @@ iconv_s_iconv
/*
* Document-method: Iconv::conv
- * call-seq: Iconv.conv(to, from, str)
+ * call-seq: Iconv.iconv(to, from, *strs)
*
* Shorthand for
* Iconv.iconv(to, from, str).join
@@ -749,22 +754,14 @@ iconv_iconv
{
VALUE str, n1, n2;
VALUE cd = check_iconv(self);
- long start = 0, length = 0, slen = 0;
+ n1 = n2 = Qnil;
rb_scan_args(argc, argv, "12", &str, &n1, &n2);
- if (!NIL_P(str)) slen = RSTRING_LEN(StringValue(str));
- if (argc != 2 || !RTEST(rb_range_beg_len(n1, &start, &length, slen, 0))) {
- if (NIL_P(n1) || ((start = NUM2LONG(n1)) < 0 ? (start += slen) >= 0 : start < slen)) {
- if (NIL_P(n2)) {
- length = -1;
- }
- else if ((length = NUM2LONG(n2)) >= slen - start) {
- length = slen - start;
- }
- }
- }
- return iconv_convert(VALUE2ICONV(cd), str, start, length, NULL);
+ return iconv_convert(VALUE2ICONV(cd), str,
+ NIL_P(n1) ? 0 : NUM2INT(n1),
+ NIL_P(n2) ? -1 : NUM2INT(n2),
+ NULL);
}
/*
@@ -828,7 +825,7 @@ iconv_failure_inspect
VALUE self;
#endif /* HAVE_PROTOTYPES */
{
- const char *cname = rb_class2name(CLASS_OF(self));
+ char *cname = rb_class2name(CLASS_OF(self));
VALUE success = rb_attr_get(self, rb_success);
VALUE failed = rb_attr_get(self, rb_failed);
VALUE str = rb_str_buf_cat2(rb_str_new2("#<"), cname);
diff --git a/ext/nkf/nkf-utf8/nkf.c b/ext/nkf/nkf-utf8/nkf.c
index 9a31c9d879..3cd1b160da 100644
--- a/ext/nkf/nkf-utf8/nkf.c
+++ b/ext/nkf/nkf-utf8/nkf.c
@@ -41,13 +41,13 @@
***********************************************************************/
/* $Id$ */
#define NKF_VERSION "2.0.8"
-#define NKF_RELEASE_DATE "2008-11-08"
+#define NKF_RELEASE_DATE "2007-01-28"
#include "config.h"
#include "utf8tbl.h"
#define COPY_RIGHT \
"Copyright (C) 1987, FUJITSU LTD. (I.Ichikawa),2000 S. Kono, COW\n" \
- "Copyright (C) 2002-2008 Kono, Furukawa, Naruse, mastodon"
+ "Copyright (C) 2002-2006 Kono, Furukawa, Naruse, mastodon"
/*
@@ -3025,12 +3025,12 @@ h_conv(FILE *f, nkf_char c2, nkf_char c1)
code_status(c1);
}
while (p->name){
- if (p->status_func && p->score < result->score){
+ if (p->score < result->score){
result = p;
}
++p;
}
- set_iconv(TRUE, result->iconv_func);
+ set_iconv(FALSE, result->iconv_func);
}
diff --git a/ext/openssl/lib/net/ftptls.rb b/ext/openssl/lib/net/ftptls.rb
index a21c1f6c3c..f433457923 100644
--- a/ext/openssl/lib/net/ftptls.rb
+++ b/ext/openssl/lib/net/ftptls.rb
@@ -29,23 +29,13 @@ require 'net/ftp'
module Net
class FTPTLS < FTP
- def connect(host, port=FTP_PORT)
- @hostname = host
- super
- end
-
def login(user = "anonymous", passwd = nil, acct = nil)
- store = OpenSSL::X509::Store.new
- store.set_default_paths
ctx = OpenSSL::SSL::SSLContext.new('SSLv23')
- ctx.cert_store = store
- ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
ctx.key = nil
ctx.cert = nil
voidcmd("AUTH TLS")
@sock = OpenSSL::SSL::SSLSocket.new(@sock, ctx)
@sock.connect
- @sock.post_connection_check(@hostname)
super(user, passwd, acct)
voidcmd("PBSZ 0")
end
diff --git a/ext/openssl/lib/net/telnets.rb b/ext/openssl/lib/net/telnets.rb
index 2b69280432..a872f41e6a 100644
--- a/ext/openssl/lib/net/telnets.rb
+++ b/ext/openssl/lib/net/telnets.rb
@@ -134,9 +134,6 @@ module Net
@sock.verify_callback = @options['VerifyCallback']
@sock.verify_depth = @options['VerifyDepth']
@sock.connect
- if @options['VerifyMode'] != OpenSSL::SSL::VERIFY_NONE
- @sock.post_connection_check(@options['Host'])
- end
@ssl = true
end
''
diff --git a/ext/openssl/lib/openssl/ssl.rb b/ext/openssl/lib/openssl/ssl.rb
index 9e9a9448ba..ef7415f478 100644
--- a/ext/openssl/lib/openssl/ssl.rb
+++ b/ext/openssl/lib/openssl/ssl.rb
@@ -88,7 +88,7 @@ module OpenSSL
end
}
end
- raise SSLError, "hostname was not match with the server certificate"
+ raise SSLError, "hostname not match"
end
end
diff --git a/ext/openssl/openssl_missing.h b/ext/openssl/openssl_missing.h
index 7b1e019208..e8c75ca42c 100644
--- a/ext/openssl/openssl_missing.h
+++ b/ext/openssl/openssl_missing.h
@@ -15,10 +15,6 @@
extern "C" {
#endif
-#ifndef TYPEDEF_D2I_OF
-typedef char *d2i_of_void();
-#endif
-
/*
* These functions are not included in headers of OPENSSL <= 0.9.6b
*/
diff --git a/ext/openssl/ossl.h b/ext/openssl/ossl.h
index 0c23f10d38..c0325229c1 100644
--- a/ext/openssl/ossl.h
+++ b/ext/openssl/ossl.h
@@ -42,11 +42,6 @@ extern "C" {
#if defined(_WIN32)
# define OpenFile WINAPI_OpenFile
# define OSSL_NO_CONF_API 1
-# ifdef USE_WINSOCK2
-# include <winsock2.h>
-# else
-# include <winsock.h>
-# endif
#endif
#include <errno.h>
#include <openssl/err.h>
@@ -207,7 +202,6 @@ void ossl_debug(const char *, ...);
#include "ossl_ocsp.h"
#include "ossl_pkcs12.h"
#include "ossl_pkcs7.h"
-#include "ossl_pkcs5.h"
#include "ossl_pkey.h"
#include "ossl_rand.h"
#include "ossl_ssl.h"
diff --git a/ext/openssl/ossl_config.c b/ext/openssl/ossl_config.c
index f1d6a98253..ef89fdfe0d 100644
--- a/ext/openssl/ossl_config.c
+++ b/ext/openssl/ossl_config.c
@@ -245,10 +245,7 @@ set_conf_section_i(VALUE i, VALUE *arg)
static VALUE
ossl_config_set_section(VALUE self, VALUE section, VALUE hash)
{
- VALUE arg[2];
-
- arg[0] = self;
- arg[1] = section;
+ VALUE arg[2] = { self, section };
rb_iterate(rb_each, hash, set_conf_section_i, (VALUE)arg);
return hash;
}
diff --git a/ext/openssl/ossl_pkcs5.h b/ext/openssl/ossl_pkcs5.h
deleted file mode 100644
index a3b132bc50..0000000000
--- a/ext/openssl/ossl_pkcs5.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#if !defined(_OSSL_PKCS5_H_)
-#define _OSSL_PKCS5_H_
-
-void Init_ossl_pkcs5(void);
-
-#endif /* _OSSL_PKCS5_H_ */
diff --git a/ext/openssl/ossl_x509name.c b/ext/openssl/ossl_x509name.c
index 076d61fb96..c5ed8b5457 100644
--- a/ext/openssl/ossl_x509name.c
+++ b/ext/openssl/ossl_x509name.c
@@ -188,11 +188,11 @@ ossl_x509name_to_s(int argc, VALUE *argv, VALUE self)
return ossl_x509name_to_s_old(self);
else iflag = NUM2ULONG(flag);
if (!(out = BIO_new(BIO_s_mem())))
- ossl_raise(eX509NameError, NULL);
+ rb_raise(eX509NameError, NULL);
GetX509Name(self, name);
if (!X509_NAME_print_ex(out, name, 0, iflag)){
BIO_free(out);
- ossl_raise(eX509NameError, NULL);
+ rb_raise(eX509NameError, NULL);
}
str = ossl_membio2str(out);
diff --git a/ext/pty/lib/expect.rb b/ext/pty/lib/expect.rb
index 08191b05b9..aa9ab895d3 100644
--- a/ext/pty/lib/expect.rb
+++ b/ext/pty/lib/expect.rb
@@ -10,7 +10,7 @@ class IO
e_pat = pat
end
while true
- if !IO.select([self],nil,nil,timeout) or eof? then
+ if IO.select([self],nil,nil,timeout).nil? then
result = nil
break
end
diff --git a/ext/pty/pty.c b/ext/pty/pty.c
index 206d4cd131..8e263790a4 100644
--- a/ext/pty/pty.c
+++ b/ext/pty/pty.c
@@ -200,7 +200,7 @@ establishShell(argc, argv, info)
struct pty_info *info;
{
int i,master,slave;
- char *p, tmp, *getenv();
+ char *p,*getenv();
struct passwd *pwent;
VALUE v;
struct exec_info arg;
@@ -273,7 +273,6 @@ establishShell(argc, argv, info)
}
close(master);
#endif
- write(slave, "", 1);
dup2(slave,0);
dup2(slave,1);
dup2(slave,2);
@@ -289,7 +288,6 @@ establishShell(argc, argv, info)
_exit(1);
}
- read(master, &tmp, 1);
close(slave);
info->child_pid = i;
@@ -355,7 +353,6 @@ get_device_once(master, slave, fail)
#if defined I_PUSH && !defined linux
if(ioctl(j, I_PUSH, "ptem") != -1) {
if(ioctl(j, I_PUSH, "ldterm") != -1) {
- ioctl(j, I_PUSH, "ttcompat");
#endif
*master = i;
*slave = j;
diff --git a/ext/purelib.rb b/ext/purelib.rb
deleted file mode 100644
index 10ee06176c..0000000000
--- a/ext/purelib.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-if nul = $:.index("-")
- $:[nul..-1] = ["."]
-end
diff --git a/ext/readline/extconf.rb b/ext/readline/extconf.rb
index b820c0b32f..b57a36f3a5 100644
--- a/ext/readline/extconf.rb
+++ b/ext/readline/extconf.rb
@@ -42,9 +42,9 @@ else
end
end
-have_func("rl_filename_completion_function")
-have_func("rl_username_completion_function")
-have_func("rl_completion_matches")
+have_readline_var("rl_filename_completion_function")
+have_readline_var("rl_username_completion_function")
+have_readline_var("rl_completion_matches")
have_readline_var("rl_deprep_term_function")
have_readline_var("rl_completion_append_character")
have_readline_var("rl_basic_word_break_characters")
@@ -59,6 +59,7 @@ have_func("rl_cleanup_after_signal")
have_func("rl_clear_signals")
have_func("rl_vi_editing_mode")
have_func("rl_emacs_editing_mode")
+have_func("rl_clear_signals")
have_func("replace_history_entry")
have_func("remove_history")
create_makefile("readline")
diff --git a/ext/readline/readline.c b/ext/readline/readline.c
index 82ddc8a3cb..559e1c677b 100644
--- a/ext/readline/readline.c
+++ b/ext/readline/readline.c
@@ -42,32 +42,17 @@ static ID completion_proc, completion_case_fold;
# define rl_completion_matches completion_matches
#endif
+static int readline_event(void);
static char **readline_attempted_completion_function(const char *text,
int start, int end);
-#ifdef HAVE_RL_EVENT_HOOK
-#ifdef DOSISH
-#define BUSY_WAIT 1
-#else
-#define BUSY_WAIT 0
-#endif
-
-static int readline_event(void);
static int
readline_event()
{
-#if BUSY_WAIT
+ CHECK_INTS;
rb_thread_schedule();
-#else
- fd_set rset;
-
- FD_ZERO(&rset);
- FD_SET(fileno(rl_instream), &rset);
- rb_thread_select(fileno(rl_instream) + 1, &rset, NULL, NULL, NULL);
return 0;
-#endif
}
-#endif
static VALUE
readline_readline(argc, argv, self)
diff --git a/ext/sdbm/_sdbm.c b/ext/sdbm/_sdbm.c
index 5b34824afc..d4cf621ea5 100644
--- a/ext/sdbm/_sdbm.c
+++ b/ext/sdbm/_sdbm.c
@@ -71,7 +71,7 @@ static int duppair proto((char *, datum));
#include <stdio.h>
#include <stdlib.h>
-#ifdef DOSISH
+#ifdef MSDOS
#include <io.h>
#endif
#include <sys/types.h>
diff --git a/ext/socket/extconf.rb b/ext/socket/extconf.rb
index ece615865f..8a13ddba73 100644
--- a/ext/socket/extconf.rb
+++ b/ext/socket/extconf.rb
@@ -259,19 +259,6 @@ unless getaddr_info_ok and have_func("getnameinfo", "netdb.h") and have_func("ge
have_func("inet_ntop") or have_func("inet_ntoa")
have_func("inet_pton") or have_func("inet_aton")
have_func("getservbyport")
- if have_func("gai_strerror")
- unless checking_for("gai_strerror() returns const pointer") {!try_compile(<<EOF)}
-#{cpp_include(headers)}
-#include <stdlib.h>
-void
-conftest_gai_strerror_is_const()
-{
- *gai_strerror(0) = 0;
-}
-EOF
- $defs << "-DGAI_STRERROR_CONST"
- end
- end
have_header("arpa/nameser.h")
have_header("resolv.h")
end
diff --git a/ext/socket/getaddrinfo.c b/ext/socket/getaddrinfo.c
index 9b82296dba..9fb4ebcb06 100644
--- a/ext/socket/getaddrinfo.c
+++ b/ext/socket/getaddrinfo.c
@@ -39,9 +39,6 @@
*/
#include "config.h"
-#ifdef RUBY_EXTCONF_H
-#include RUBY_EXTCONF_H
-#endif
#include <sys/types.h>
#if !defined(_WIN32) && !defined(__VMS)
#include <sys/param.h>
@@ -202,8 +199,7 @@ if (pai->ai_flags & AI_CANONNAME) {\
#define ERR(err) { error = (err); goto bad; }
-#ifndef HAVE_GAI_STRERROR
-#ifdef GAI_STRERROR_CONST
+#if defined __UCLIBC__
const
#endif
char *
@@ -214,7 +210,6 @@ gai_strerror(ecode)
ecode = EAI_MAX;
return (char *)ai_errlist[ecode];
}
-#endif
void
freeaddrinfo(ai)
@@ -393,7 +388,7 @@ getaddrinfo(hostname, servname, hints, res)
port = htons((unsigned short)atoi(servname));
} else {
struct servent *sp;
- const char *proto;
+ char *proto;
proto = NULL;
switch (pai->ai_socktype) {
diff --git a/ext/socket/getnameinfo.c b/ext/socket/getnameinfo.c
index 66f7e8818a..4c9c8f03c4 100644
--- a/ext/socket/getnameinfo.c
+++ b/ext/socket/getnameinfo.c
@@ -35,7 +35,6 @@
*/
#include "config.h"
-#include <stdio.h>
#include <sys/types.h>
#ifndef _WIN32
#if defined(__BEOS__)
@@ -52,11 +51,15 @@
#endif
#include <netdb.h>
#if defined(HAVE_RESOLV_H)
+#ifdef _SX
+#include <stdio.h>
+#endif
#include <resolv.h>
#endif
#endif
#ifdef _WIN32
#include <winsock2.h>
+#include <stdio.h>
#define snprintf _snprintf
#endif
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 5b0c7049df..b3966872ea 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -625,7 +625,7 @@ s_recvfrom(sock, argc, argv, from)
rb_raise(rb_eTypeError, "sockaddr size differs - should not happen");
}
#endif
- if (alen && alen != sizeof(buf)) /* OSX doesn't return a 'from' result from recvfrom for connection-oriented sockets */
+ if (alen) /* OSX doesn't return a 'from' result from recvfrom for connection-oriented sockets */
return rb_assoc_new(str, ipaddr((struct sockaddr*)buf));
else
return rb_assoc_new(str, Qnil);
@@ -691,7 +691,7 @@ s_recvfrom_nonblock(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
return str;
case RECV_IP:
- if (alen && alen != sizeof(buf)) /* connection-oriented socket may not return a from result */
+ if (alen) /* connection-oriented socket may not return a from result */
addr = ipaddr((struct sockaddr*)buf);
break;
@@ -840,7 +840,7 @@ host_str(host, hbuf, len)
return NULL;
}
else if (rb_obj_is_kind_of(host, rb_cInteger)) {
- unsigned long i = NUM2ULONG(host);
+ long i = NUM2LONG(host);
make_inetaddr(htonl(i), hbuf, len);
return hbuf;
@@ -893,10 +893,10 @@ port_str(port, pbuf, len)
}
#ifndef NI_MAXHOST
-# define NI_MAXHOST 1025
+# define 1025
#endif
#ifndef NI_MAXSERV
-# define NI_MAXSERV 32
+# define 32
#endif
static struct addrinfo*
@@ -1464,24 +1464,6 @@ tcp_svr_init(argc, argv, sock)
return init_inetsock(sock, Qnil, arg1, Qnil, Qnil, INET_SERVER);
}
-static void
-make_fd_nonblock(int fd)
-{
- int flags;
-#ifdef F_GETFL
- flags = fcntl(fd, F_GETFL);
- if (flags == -1) {
- rb_sys_fail(0);
- }
-#else
- flags = 0;
-#endif
- flags |= O_NONBLOCK;
- if (fcntl(fd, F_SETFL, flags) == -1) {
- rb_sys_fail(0);
- }
-}
-
static VALUE
s_accept_nonblock(VALUE klass, OpenFile *fptr, struct sockaddr *sockaddr, socklen_t *len)
{
@@ -1493,7 +1475,6 @@ s_accept_nonblock(VALUE klass, OpenFile *fptr, struct sockaddr *sockaddr, sockle
if (fd2 < 0) {
rb_sys_fail("accept(2)");
}
- make_fd_nonblock(fd2);
return init_sock(rb_obj_alloc(klass), fd2);
}
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index b7c67f2aad..a64aaf837c 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -136,7 +136,6 @@ check_modifiable(ptr)
static VALUE strio_s_allocate _((VALUE));
static VALUE strio_s_open _((int, VALUE *, VALUE));
-static void strio_init _((int, VALUE *, struct StringIO *));
static VALUE strio_initialize _((int, VALUE *, VALUE));
static VALUE strio_finalize _((VALUE));
static VALUE strio_self _((VALUE));
@@ -218,24 +217,13 @@ strio_initialize(argc, argv, self)
VALUE self;
{
struct StringIO *ptr = check_strio(self);
+ VALUE string, mode;
+ int trunc = Qfalse;
if (!ptr) {
DATA_PTR(self) = ptr = strio_alloc();
}
rb_call_super(0, 0);
- strio_init(argc, argv, ptr);
- return self;
-}
-
-static void
-strio_init(argc, argv, ptr)
- int argc;
- VALUE *argv;
- struct StringIO *ptr;
-{
- VALUE string, mode;
- int trunc = Qfalse;
-
switch (rb_scan_args(argc, argv, "02", &string, &mode)) {
case 2:
if (FIXNUM_P(mode)) {
@@ -267,6 +255,7 @@ strio_init(argc, argv, ptr)
break;
}
ptr->string = string;
+ return self;
}
static VALUE
@@ -581,8 +570,7 @@ strio_reopen(argc, argv, self)
if (argc == 1 && TYPE(*argv) != T_STRING) {
return strio_copy(self, *argv);
}
- strio_init(argc, argv, StringIO(self));
- return self;
+ return strio_initialize(argc, argv, self);
}
/*
@@ -771,24 +759,15 @@ strio_ungetc(self, ch)
int cc = NUM2INT(ch);
long len, pos = ptr->pos;
- if (cc != EOF) {
- len = RSTRING(ptr->string)->len;
- if (pos == 0) {
- char *p;
- rb_str_resize(ptr->string, len + 1);
- p = RSTRING(ptr->string)->ptr;
- memmove(p + 1, p, len);
- }
- else {
- if (len < pos-- ||
- (unsigned char)RSTRING(ptr->string)->ptr[pos] !=
- (unsigned char)cc) {
- strio_extend(ptr, pos, 1);
- }
- --ptr->pos;
+ if (cc != EOF && pos > 0) {
+ if ((len = RSTRING(ptr->string)->len) < pos-- ||
+ (unsigned char)RSTRING(ptr->string)->ptr[pos] !=
+ (unsigned char)cc) {
+ strio_extend(ptr, pos, 1);
+ RSTRING(ptr->string)->ptr[pos] = cc;
+ OBJ_INFECT(ptr->string, self);
}
- RSTRING(ptr->string)->ptr[pos] = cc;
- OBJ_INFECT(ptr->string, self);
+ --ptr->pos;
ptr->flags &= ~STRIO_EOF;
}
return Qnil;
@@ -956,7 +935,7 @@ strio_readline(argc, argv, self)
VALUE *argv;
VALUE self;
{
- VALUE line = strio_gets(argc, argv, self);
+ VALUE line = strio_getline(argc, argv, readable(StringIO(self)));
if (NIL_P(line)) rb_eof_error();
return line;
}
diff --git a/ext/syck/rubyext.c b/ext/syck/rubyext.c
index 6de3546308..078de4f78d 100644
--- a/ext/syck/rubyext.c
+++ b/ext/syck/rubyext.c
@@ -2280,6 +2280,7 @@ Init_syck()
*/
cScalar = rb_define_class_under( rb_syck, "Scalar", cNode );
rb_define_alloc_func( cScalar, syck_scalar_alloc );
+ rb_define_attr( cNode, "value", 1, 0 );
rb_define_method( cScalar, "initialize", syck_scalar_initialize, 3 );
rb_define_method( cScalar, "value=", syck_scalar_value_set, 1 );
rb_define_method( cScalar, "style=", syck_scalar_style_set, 1 );
diff --git a/ext/syck/syck.h b/ext/syck/syck.h
index e7d07e9c0d..c49f740173 100644
--- a/ext/syck/syck.h
+++ b/ext/syck/syck.h
@@ -17,7 +17,6 @@
#define YAML_DOMAIN "yaml.org,2002"
#include <stdio.h>
-#include <stdlib.h>
#include <ctype.h>
#include "st.h"
@@ -400,7 +399,6 @@ int syck_scan_scalar( int, char *, long );
void syck_parser_handler( SyckParser *, SyckNodeHandler );
void syck_parser_error_handler( SyckParser *, SyckErrorHandler );
void syck_parser_bad_anchor_handler( SyckParser *, SyckBadAnchorHandler );
-void syck_parser_set_input_type( SyckParser *, enum syck_parser_input );
void syck_parser_file( SyckParser *, FILE *, SyckIoFileRead );
void syck_parser_str( SyckParser *, char *, long, SyckIoStrRead );
void syck_parser_str_auto( SyckParser *, char *, SyckIoStrRead );
diff --git a/ext/syslog/syslog.c b/ext/syslog/syslog.c
index ecc49318f7..477489ddfe 100644
--- a/ext/syslog/syslog.c
+++ b/ext/syslog/syslog.c
@@ -22,7 +22,6 @@ static void syslog_write(int pri, int argc, VALUE *argv)
{
VALUE str;
- rb_secure(4);
if (argc < 1) {
rb_raise(rb_eArgError, "no log message supplied");
}
@@ -39,7 +38,6 @@ static void syslog_write(int pri, int argc, VALUE *argv)
/* Syslog module methods */
static VALUE mSyslog_close(VALUE self)
{
- rb_secure(4);
if (!syslog_opened) {
rb_raise(rb_eRuntimeError, "syslog not opened");
}
@@ -134,7 +132,6 @@ static VALUE mSyslog_get_mask(VALUE self)
static VALUE mSyslog_set_mask(VALUE self, VALUE mask)
{
- rb_secure(4);
if (!syslog_opened) {
rb_raise(rb_eRuntimeError, "must open syslog before setting log mask");
}
diff --git a/ext/thread/thread.c b/ext/thread/thread.c
index bca807725e..d617185a26 100644
--- a/ext/thread/thread.c
+++ b/ext/thread/thread.c
@@ -12,9 +12,6 @@
#include <ruby.h>
#include <intern.h>
#include <rubysig.h>
-#include <node.h>
-
-enum rb_thread_status rb_thread_status _((VALUE));
static VALUE rb_cMutex;
static VALUE rb_cConditionVariable;
@@ -24,12 +21,11 @@ static VALUE rb_cSizedQueue;
static VALUE set_critical(VALUE value);
static VALUE
-thread_exclusive(VALUE (*func)(ANYARGS), VALUE arg)
+thread_exclusive_do(void)
{
- VALUE critical = rb_thread_critical;
-
rb_thread_critical = 1;
- return rb_ensure(func, arg, set_critical, (VALUE)critical);
+
+ return rb_yield(Qundef);
}
/*
@@ -44,7 +40,7 @@ thread_exclusive(VALUE (*func)(ANYARGS), VALUE arg)
static VALUE
rb_thread_exclusive(void)
{
- return thread_exclusive(rb_yield, Qundef);
+ return rb_ensure(thread_exclusive_do, Qundef, set_critical, rb_thread_critical);
}
typedef struct _Entry {
@@ -148,7 +144,7 @@ shift_list(List *list)
VALUE value;
entry = list->entries;
- if (!entry) return Qnil;
+ if (!entry) return Qundef;
list->entries = entry->next;
if (entry == list->last_entry) {
@@ -167,18 +163,13 @@ static void
remove_one(List *list, VALUE value)
{
Entry **ref;
- Entry *prev;
Entry *entry;
- for (ref = &list->entries, prev = NULL, entry = list->entries;
+ for (ref = &list->entries, entry = list->entries;
entry != NULL;
- ref = &entry->next, prev = entry, entry = entry->next) {
+ ref = &entry->next, entry = entry->next) {
if (entry->value == value) {
*ref = entry->next;
- list->size--;
- if (!entry->next) {
- list->last_entry = prev;
- }
recycle_entries(list, entry, entry);
break;
}
@@ -211,16 +202,15 @@ array_from_list(List const *list)
static VALUE
wake_thread(VALUE thread)
{
- return rb_thread_wakeup_alive(thread);
+ return rb_rescue2(rb_thread_wakeup, thread,
+ NULL, Qundef, rb_eThreadError, 0);
}
static VALUE
run_thread(VALUE thread)
{
- thread = wake_thread(thread);
- if (RTEST(thread) && !rb_thread_critical)
- rb_thread_schedule();
- return thread;
+ return rb_rescue2(rb_thread_run, thread,
+ NULL, Qundef, rb_eThreadError, 0);
}
static VALUE
@@ -230,9 +220,7 @@ wake_one(List *list)
waking = Qnil;
while (list->entries && !RTEST(waking)) {
- waking = shift_list(list);
- if (waking == Qundef) break;
- waking = wake_thread(waking);
+ waking = wake_thread(shift_list(list));
}
return waking;
@@ -270,12 +258,13 @@ wait_list(List *list)
}
static void
-kill_waiting_threads(List *waiting)
+assert_no_survivors(List *waiting, const char *label, void *addr)
{
Entry *entry;
-
for (entry = waiting->entries; entry; entry = entry->next) {
- rb_thread_kill(entry->value);
+ if (RTEST(wake_thread(entry->value))) {
+ rb_bug("%s %p freed with live thread(s) waiting", label, addr);
+ }
}
}
@@ -309,8 +298,6 @@ typedef struct _Mutex {
List waiting;
} Mutex;
-#define MUTEX_LOCKED_P(mutex) (RTEST((mutex)->owner) && rb_thread_alive_p((mutex)->owner))
-
static void
mark_mutex(Mutex *mutex)
{
@@ -327,7 +314,7 @@ finalize_mutex(Mutex *mutex)
static void
free_mutex(Mutex *mutex)
{
- kill_waiting_threads(&mutex->waiting);
+ assert_no_survivors(&mutex->waiting, "mutex", mutex);
finalize_mutex(mutex);
xfree(mutex);
}
@@ -369,7 +356,7 @@ rb_mutex_locked_p(VALUE self)
{
Mutex *mutex;
Data_Get_Struct(self, Mutex, mutex);
- return MUTEX_LOCKED_P(mutex) ? Qtrue : Qfalse;
+ return RTEST(mutex->owner) ? Qtrue : Qfalse;
}
/*
@@ -388,7 +375,7 @@ rb_mutex_try_lock(VALUE self)
Data_Get_Struct(self, Mutex, mutex);
- if (MUTEX_LOCKED_P(mutex))
+ if (RTEST(mutex->owner))
return Qfalse;
mutex->owner = rb_thread_current();
@@ -411,19 +398,11 @@ lock_mutex(Mutex *mutex)
rb_thread_critical = 1;
- if (!MUTEX_LOCKED_P(mutex)) {
- mutex->owner = current;
- }
- else {
- do {
- wait_list(&mutex->waiting);
- rb_thread_critical = 1;
- if (!MUTEX_LOCKED_P(mutex)) {
- mutex->owner = current;
- break;
- }
- } while (mutex->owner != current);
+ while (RTEST(mutex->owner)) {
+ wait_list(&mutex->waiting);
+ rb_thread_critical = 1;
}
+ mutex->owner = current;
rb_thread_critical = 0;
return Qnil;
@@ -438,22 +417,6 @@ rb_mutex_lock(VALUE self)
return self;
}
-static VALUE
-relock_mutex(Mutex *mutex)
-{
- VALUE current = rb_thread_current();
-
- switch (rb_thread_status(current)) {
- case THREAD_RUNNABLE:
- case THREAD_STOPPED:
- lock_mutex(mutex);
- break;
- default:
- break;
- }
- return Qundef;
-}
-
/*
* Document-method: unlock
*
@@ -466,12 +429,16 @@ unlock_mutex_inner(Mutex *mutex)
{
VALUE waking;
+ if (!RTEST(mutex->owner)) {
+ rb_raise(rb_eThreadError, "not owner");
+ }
+
if (mutex->owner != rb_thread_current()) {
rb_raise(rb_eThreadError, "not owner");
}
+ mutex->owner = Qnil;
waking = wake_one(&mutex->waiting);
- mutex->owner = waking;
return waking;
}
@@ -486,13 +453,18 @@ set_critical(VALUE value)
static VALUE
unlock_mutex(Mutex *mutex)
{
- VALUE waking = thread_exclusive(unlock_mutex_inner, (VALUE)mutex);
+ VALUE waking;
- if (!RTEST(waking)) {
+ rb_thread_critical = 1;
+ waking = rb_ensure(unlock_mutex_inner, (VALUE)mutex, set_critical, 0);
+
+ if (waking == Qundef) {
return Qfalse;
}
- run_thread(waking);
+ if (RTEST(waking)) {
+ run_thread(waking);
+ }
return Qtrue;
}
@@ -535,13 +507,16 @@ rb_mutex_exclusive_unlock(VALUE self)
VALUE waking;
Data_Get_Struct(self, Mutex, mutex);
- waking = thread_exclusive(rb_mutex_exclusive_unlock_inner, (VALUE)mutex);
+ rb_thread_critical = 1;
+ waking = rb_ensure(rb_mutex_exclusive_unlock_inner, (VALUE)mutex, set_critical, 0);
- if (!RTEST(waking)) {
+ if (waking == Qundef) {
return Qnil;
}
- run_thread(waking);
+ if (RTEST(waking)) {
+ run_thread(waking);
+ }
return self;
}
@@ -612,7 +587,7 @@ finalize_condvar(ConditionVariable *condvar)
static void
free_condvar(ConditionVariable *condvar)
{
- kill_waiting_threads(&condvar->waiting);
+ assert_no_survivors(&condvar->waiting, "condition variable", condvar);
finalize_condvar(condvar);
xfree(condvar);
}
@@ -653,18 +628,13 @@ rb_condvar_alloc(VALUE klass)
static void
wait_condvar(ConditionVariable *condvar, Mutex *mutex)
{
- VALUE waking;
-
rb_thread_critical = 1;
if (rb_thread_current() != mutex->owner) {
rb_thread_critical = 0;
rb_raise(rb_eThreadError, "not owner of the synchronization mutex");
}
- waking = unlock_mutex_inner(mutex);
- if (RTEST(waking)) {
- wake_thread(waking);
- }
- rb_ensure(wait_list, (VALUE)&condvar->waiting, relock_mutex, (VALUE)mutex);
+ unlock_mutex_inner(mutex);
+ rb_ensure(wait_list, (VALUE)&condvar->waiting, lock_mutex, (VALUE)mutex);
}
static VALUE
@@ -722,7 +692,8 @@ rb_condvar_broadcast(VALUE self)
Data_Get_Struct(self, ConditionVariable, condvar);
- thread_exclusive(wake_all, (VALUE)&condvar->waiting);
+ rb_thread_critical = 1;
+ rb_ensure(wake_all, (VALUE)&condvar->waiting, set_critical, 0);
rb_thread_schedule();
return self;
@@ -739,8 +710,9 @@ rb_condvar_broadcast(VALUE self)
static void
signal_condvar(ConditionVariable *condvar)
{
- VALUE waking = thread_exclusive(wake_one, (VALUE)&condvar->waiting);
-
+ VALUE waking;
+ rb_thread_critical = 1;
+ waking = rb_ensure(wake_one, (VALUE)&condvar->waiting, set_critical, 0);
if (RTEST(waking)) {
run_thread(waking);
}
@@ -815,9 +787,9 @@ finalize_queue(Queue *queue)
static void
free_queue(Queue *queue)
{
- kill_waiting_threads(&queue->mutex.waiting);
- kill_waiting_threads(&queue->space_available.waiting);
- kill_waiting_threads(&queue->value_available.waiting);
+ assert_no_survivors(&queue->mutex.waiting, "queue", queue);
+ assert_no_survivors(&queue->space_available.waiting, "queue", queue);
+ assert_no_survivors(&queue->value_available.waiting, "queue", queue);
finalize_queue(queue);
xfree(queue);
}
@@ -858,10 +830,10 @@ rb_queue_marshal_load(VALUE self, VALUE data)
array = rb_marshal_load(data);
if (TYPE(array) != T_ARRAY) {
- rb_raise(rb_eTypeError, "expected Array of queue data");
+ rb_raise(rb_eRuntimeError, "expected Array of queue data");
}
if (RARRAY(array)->len < 1) {
- rb_raise(rb_eArgError, "missing capacity value");
+ rb_raise(rb_eRuntimeError, "missing capacity value");
}
queue->capacity = NUM2ULONG(rb_ary_shift(array));
push_multiple_list(&queue->values, RARRAY(array)->ptr, (unsigned)RARRAY(array)->len);
diff --git a/ext/tk/ChangeLog.tkextlib b/ext/tk/ChangeLog.tkextlib
index 359b466a32..33bec9fb6e 100644
--- a/ext/tk/ChangeLog.tkextlib
+++ b/ext/tk/ChangeLog.tkextlib
@@ -1,13 +1,4 @@
-2007-05-26 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/lib/tkextlib/tcllib/tablelist.rb: fix typo.
-
- * ext/tk/lib/tkextlib/tile/dialog.rb: forget to give an argument.
-
- * ext/tk/lib/tkextlib/version.rb: update RELEASE_DATE.
-
2007-01-26 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
* ext/tk/lib/tkextlib/iwidgets/checkbox.rb: wrong number of arguments
[ruby-Bugs-7776].
diff --git a/ext/tk/lib/tkextlib/blt.rb b/ext/tk/lib/tkextlib/blt.rb
index 8d58c1f1bc..115eb927ba 100644
--- a/ext/tk/lib/tkextlib/blt.rb
+++ b/ext/tk/lib/tkextlib/blt.rb
@@ -26,14 +26,14 @@ module Tk
PATCH_LEVEL = tk_call('set', 'blt_patchLevel')
begin
- lib = TkCore::INTERP._invoke('set', 'blt_library')
+ lib = INTERP._invoke('set', 'blt_library')
rescue
lib = ''
end
LIBRARY = TkVarAccess.new('blt_library', lib)
begin
- lib = TkCore::INTERP._invoke('set', 'blt_libPath')
+ lib = INTERP._invoke('set', 'blt_libPath')
rescue
lib = ''
end
diff --git a/ext/tk/lib/tkextlib/blt/vector.rb b/ext/tk/lib/tkextlib/blt/vector.rb
index 5e17422cfc..540b6b9102 100644
--- a/ext/tk/lib/tkextlib/blt/vector.rb
+++ b/ext/tk/lib/tkextlib/blt/vector.rb
@@ -46,11 +46,11 @@ module Tk::BLT
size = size.join(':')
end
if size
- @id = TkCore::INTERP._invoke('::blt::vector', 'create',
- "#auto(#{size})", *hash_kv(keys))
+ @id = INTERP._invoke('::blt::vector', 'create',
+ "#auto(#{size})", *hash_kv(keys))
else
- @id = TkCore::INTERP._invoke('::blt::vector', 'create',
- "#auto", *hash_kv(keys))
+ @id = INTERP._invoke('::blt::vector', 'create',
+ "#auto", *hash_kv(keys))
end
TkVar_ID_TBL[@id] = self
@@ -63,7 +63,7 @@ module Tk::BLT
@trace_opts = nil
# teach Tk-ip that @id is global var
- TkCore::INTERP._invoke_without_enc('global', @id)
+ INTERP._invoke_without_enc('global', @id)
end
def destroy
@@ -237,7 +237,7 @@ module Tk::BLT
@trace_opts = nil
# teach Tk-ip that @id is global var
- TkCore::INTERP._invoke_without_enc('global', @id)
+ INTERP._invoke_without_enc('global', @id)
end
end
end
diff --git a/ext/tk/lib/tkextlib/tcllib/tablelist.rb b/ext/tk/lib/tkextlib/tcllib/tablelist.rb
index efeb8fbbac..42435a1971 100644
--- a/ext/tk/lib/tkextlib/tcllib/tablelist.rb
+++ b/ext/tk/lib/tkextlib/tcllib/tablelist.rb
@@ -23,5 +23,5 @@ else
# TkPackage.require('Tablelist', '4.2')
TkPackage.require('Tablelist')
- require 'tkextlib/tcllib/tablelist_core'
+ requrie 'tkextlib/tcllib/tablelist_core'
end
diff --git a/ext/tk/lib/tkextlib/tile/dialog.rb b/ext/tk/lib/tkextlib/tile/dialog.rb
index b10378d7de..f8ddf62598 100644
--- a/ext/tk/lib/tkextlib/tile/dialog.rb
+++ b/ext/tk/lib/tkextlib/tile/dialog.rb
@@ -51,7 +51,7 @@ class Tk::Tile::Dialog
alias display show
def client_frame
- window(tk_call_without_enc('::ttk::dialog::clientframe', @path))
+ window(tk_call_without_enc('::ttk::dialog::clientframe'))
end
def cget(slot)
diff --git a/ext/tk/lib/tkextlib/version.rb b/ext/tk/lib/tkextlib/version.rb
index c7816fd4a5..3d6995043a 100644
--- a/ext/tk/lib/tkextlib/version.rb
+++ b/ext/tk/lib/tkextlib/version.rb
@@ -2,5 +2,5 @@
# release date of tkextlib
#
module Tk
- Tkextlib_RELEASE_DATE = '2007-05-26'.freeze
+ Tkextlib_RELEASE_DATE = '2007-01-26'.freeze
end
diff --git a/ext/tk/tcltklib.c b/ext/tk/tcltklib.c
index ff1f7640bd..10b79f2970 100644
--- a/ext/tk/tcltklib.c
+++ b/ext/tk/tcltklib.c
@@ -4364,11 +4364,12 @@ delete_slaves(ip)
/* finalize operation */
-static void
+static VALUE
lib_mark_at_exit(self)
VALUE self;
{
at_exit = 1;
+ return Qnil;
}
static int
@@ -4413,13 +4414,13 @@ ip_finalize(ip)
}
if (Tcl_InterpDeleted(ip)) {
- DUMP2("ip(%p) is already deleted", ip);
+ DUMP2("ip(%lx) is already deleted", ip);
return;
}
#if TCL_NAMESPACE_DEBUG
if (ip_null_namespace(ip)) {
- DUMP2("ip(%p) has null namespace", ip);
+ DUMP2("ip(%lx) has null namespace", ip);
return;
}
#endif
@@ -7994,6 +7995,8 @@ Init_tcltklib()
/* --------------------------------------------------------------- */
+ rb_define_module_function(lib, "_mark_at_exit", lib_mark_at_exit, 0);
+
rb_define_module_function(lib, "mainloop", lib_mainloop, -1);
rb_define_module_function(lib, "mainloop_thread?",
lib_evloop_thread_p, 0);
@@ -8130,7 +8133,7 @@ Init_tcltklib()
/* --------------------------------------------------------------- */
- rb_set_end_proc(lib_mark_at_exit, 0);
+ rb_eval_string("at_exit{ TclTkLib._mark_at_exit }");
/* --------------------------------------------------------------- */
diff --git a/ext/win32ole/tests/testOLEEVENT.rb b/ext/win32ole/tests/testOLEEVENT.rb
new file mode 100644
index 0000000000..0901158642
--- /dev/null
+++ b/ext/win32ole/tests/testOLEEVENT.rb
@@ -0,0 +1,91 @@
+require 'rubyunit'
+require 'win32ole'
+
+class TestWIN32OLE_EVENT < RUNIT::TestCase
+ def setup
+ @excel = WIN32OLE.new("Excel.Application")
+ @excel.visible = true
+ @event = ""
+ @event2 = ""
+ end
+ def test_on_event
+ book = @excel.workbooks.Add
+ value = ""
+ begin
+ ev = WIN32OLE_EVENT.new(book, 'WorkbookEvents')
+ ev.on_event('SheetChange'){|arg1, arg2|
+ begin
+ value = arg1.value
+ rescue
+ value = $!.message
+ end
+ }
+ book.Worksheets(1).Range("A1").value = "OK"
+ ensure
+ book.saved = true
+ end
+ assert_equal("OK", value)
+ end
+
+ def handler1
+ @event += "handler1"
+ end
+ def handler2
+ @event += "handler2"
+ end
+
+ def handler3
+ @event += "handler3"
+ end
+
+ def test_on_event2
+ book = @excel.workbooks.Add
+ begin
+ ev = WIN32OLE_EVENT.new(book, 'WorkbookEvents')
+ ev.on_event('SheetChange'){|arg1, arg2|
+ handler1
+ }
+ ev.on_event('SheetChange'){|arg1, arg2|
+ handler2
+ }
+ book.Worksheets(1).Range("A1").value = "OK"
+ ensure
+ book.saved = true
+ end
+ assert_equal("handler2", @event)
+ end
+
+ def test_on_event3
+ book = @excel.workbooks.Add
+ begin
+ ev = WIN32OLE_EVENT.new(book, 'WorkbookEvents')
+ ev.on_event{ handler1 }
+ ev.on_event{ handler2 }
+ book.Worksheets(1).Range("A1").value = "OK"
+ ensure
+ book.saved = true
+ end
+ assert_equal("handler2", @event)
+ end
+
+ def test_on_event4
+ book = @excel.workbooks.Add
+ begin
+ ev = WIN32OLE_EVENT.new(book, 'WorkbookEvents')
+ ev.on_event{ handler1 }
+ ev.on_event{ handler2 }
+ ev.on_event('SheetChange'){|arg1, arg2| handler3 }
+ book.Worksheets(1).Range("A1").value = "OK"
+ ensure
+ book.saved = true
+ end
+ assert_equal("handler3", @event)
+ end
+
+ def teardown
+ @excel.quit
+ @excel = nil
+ GC.start
+ end
+end
+
diff --git a/ext/win32ole/tests/testWIN32OLE.rb b/ext/win32ole/tests/testWIN32OLE.rb
index d7f9dd2543..5c01507377 100644
--- a/ext/win32ole/tests/testWIN32OLE.rb
+++ b/ext/win32ole/tests/testWIN32OLE.rb
@@ -156,8 +156,7 @@ class TestWin32OLE < RUNIT::TestCase
sheet.range("A3").value = "=A1*10 + 9"
assert_equal(9999999999, sheet.range("A2").value)
assert_equal(9999999999, sheet.range("A3").value)
- sheet.range("A4").value = "2008/03/04"
- assert_equal("2008/03/04 00:00:00", sheet.range("A4").value)
+
ensure
book.saved = true
end
diff --git a/ext/win32ole/tests/test_win32ole_event.rb b/ext/win32ole/tests/test_win32ole_event.rb
deleted file mode 100644
index 744021dfd2..0000000000
--- a/ext/win32ole/tests/test_win32ole_event.rb
+++ /dev/null
@@ -1,133 +0,0 @@
-begin
- require 'win32ole'
-rescue LoadError
-end
-require 'test/unit'
-
-if defined?(WIN32OLE_EVENT)
- class TestWIN32OLE_EVENT < Test::Unit::TestCase
- def create_temp_html
- fso = WIN32OLE.new('Scripting.FileSystemObject')
- dummy_file = fso.GetTempName + ".html"
- cfolder = fso.getFolder(".")
- f = cfolder.CreateTextFile(dummy_file)
- f.writeLine("<html><body>This is test HTML file for Win32OLE.</body></html>")
- f.close
- dummy_path = cfolder.path + "\\" + dummy_file
- dummy_path
- end
-
- def setup
- @ie = WIN32OLE.new("InternetExplorer.Application")
- @ie.visible = true
- @event = ""
- @event2 = ""
- @event3 = ""
- @f = create_temp_html
- end
-
- def default_handler(event, *args)
- @event += event
- end
-
- def test_on_event
- ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
- ev.on_event {|*args| default_handler(*args)}
- @ie.navigate("file:///#{@f}")
- while @ie.busy
- WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
- GC.start
- sleep 0.1
- end
- assert_match(/BeforeNavigate/, @event)
- assert_match(/NavigateComplete/, @event)
- end
-
- def test_on_event2
- ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
- ev.on_event('BeforeNavigate') {|*args| handler1}
- ev.on_event('BeforeNavigate') {|*args| handler2}
- @ie.navigate("file:///#{@f}")
- while @ie.busy
- sleep 0.1
- end
- assert_equal("handler2", @event2)
- end
-
- def test_on_event3
- ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
- ev.on_event {|*args| handler1}
- ev.on_event {|*args| handler2}
- @ie.navigate("file:///#{@f}")
- while @ie.busy
- sleep 0.1
- end
- assert_equal("handler2", @event2)
- end
-
- def test_on_event4
- ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
- ev.on_event{|*args| handler1}
- ev.on_event{|*args| handler2}
- ev.on_event('NavigateComplete'){|*args| handler3(*args)}
- @ie.navigate("file:///#{@f}")
- while @ie.busy
- sleep 0.1
- end
- assert(@event3!="")
- assert("handler2", @event2)
- end
-
- def test_on_event5
- ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
- ev.on_event {|*args| default_handler(*args)}
- ev.on_event('NavigateComplete'){|*args| handler3(*args)}
- @ie.navigate("file:///#{@f}")
- while @ie.busy
- sleep 0.1
- end
- assert_match(/BeforeNavigate/, @event)
- assert(/NavigateComplete/ !~ @event)
- assert(@event!="")
- end
-
- def test_unadvise
- ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
- ev.on_event {|*args| default_handler(*args)}
- @ie.navigate("file:///#{@f}")
- while @ie.busy
- sleep 0.1
- end
- assert_match(/BeforeNavigate/, @event)
- ev.unadvise
- @event = ""
- @ie.navigate("file:///#{@f}")
- while @ie.busy
- sleep 0.1
- end
- assert_equal("", @event);
- assert_raise(WIN32OLERuntimeError) {
- ev.on_event {|*args| default_handler(*args)}
- }
- end
-
- def handler1
- @event2 = "handler1"
- end
-
- def handler2
- @event2 = "handler2"
- end
-
- def handler3(url)
- @event3 += url
- end
-
- def teardown
- @ie.quit
- @ie = nil
- File.unlink(@f)
- GC.start
- end
- end
-end
diff --git a/ext/win32ole/tests/testall.rb b/ext/win32ole/tests/testall.rb
index 553ce88509..d45541f571 100644
--- a/ext/win32ole/tests/testall.rb
+++ b/ext/win32ole/tests/testall.rb
@@ -12,5 +12,4 @@ require "testNIL2VTEMPTY"
require "test_ole_methods.rb"
require "test_propertyputref.rb"
require "test_word.rb"
-require "test_win32ole_event.rb"
# require "testOLEEVENT"
diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c
index dc1b77d5e9..950ff21fd9 100644
--- a/ext/win32ole/win32ole.c
+++ b/ext/win32ole/win32ole.c
@@ -29,7 +29,7 @@
#include <varargs.h>
#define va_init_list(a,b) va_start(a)
#endif
-#include <objidl.h>
+
#define DOUT fprintf(stderr,"[%d]\n",__LINE__)
#define DOUTS(x) fprintf(stderr,"[%d]:" #x "=%s\n",__LINE__,x)
@@ -79,7 +79,7 @@
#define WC2VSTR(x) ole_wc2vstr((x), TRUE)
-#define WIN32OLE_VERSION "0.7.6"
+#define WIN32OLE_VERSION "0.7.1"
typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX)
(REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*);
@@ -157,9 +157,6 @@ static VALUE com_hash;
static IDispatchVtbl com_vtbl;
static UINT cWIN32OLE_cp = CP_ACP;
static VARTYPE g_nil_to = VT_ERROR;
-static IMessageFilterVtbl message_filter;
-static IMessageFilter imessage_filter = { &message_filter };
-static IMessageFilter* previous_filter;
struct oledata {
IDispatch *pDispatch;
@@ -206,101 +203,6 @@ static char *ole_wc2mb(LPWSTR);
static VALUE ole_variant2val(VARIANT*);
static void ole_val2variant(VALUE, VARIANT*);
-static HRESULT (STDMETHODCALLTYPE mf_QueryInterface)(
- IMessageFilter __RPC_FAR * This,
- /* [in] */ REFIID riid,
- /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
-{
- if (MEMCMP(riid, &IID_IUnknown, GUID, 1) == 0
- || MEMCMP(riid, &IID_IMessageFilter, GUID, 1) == 0)
- {
- *ppvObject = &message_filter;
- return S_OK;
- }
- return E_NOINTERFACE;
-}
-
-static ULONG (STDMETHODCALLTYPE mf_AddRef)(
- IMessageFilter __RPC_FAR * This)
-{
- return 1;
-}
-
-static ULONG (STDMETHODCALLTYPE mf_Release)(
- IMessageFilter __RPC_FAR * This)
-{
- return 1;
-}
-
-static DWORD (STDMETHODCALLTYPE mf_HandleInComingCall)(
- IMessageFilter __RPC_FAR * pThis,
- DWORD dwCallType, //Type of incoming call
- HTASK threadIDCaller, //Task handle calling this task
- DWORD dwTickCount, //Elapsed tick count
- LPINTERFACEINFO lpInterfaceInfo //Pointer to INTERFACEINFO structure
- )
-{
-#ifdef DEBUG_MESSAGEFILTER
- printf("incoming %08X, %08X, %d\n", dwCallType, threadIDCaller, dwTickCount);
- fflush(stdout);
-#endif
- switch (dwCallType)
- {
- case CALLTYPE_ASYNC:
- case CALLTYPE_TOPLEVEL_CALLPENDING:
- case CALLTYPE_ASYNC_CALLPENDING:
- if (rb_during_gc()) {
- return SERVERCALL_RETRYLATER;
- }
- break;
- default:
- break;
- }
- if (previous_filter) {
- return previous_filter->lpVtbl->HandleInComingCall(previous_filter,
- dwCallType,
- threadIDCaller,
- dwTickCount,
- lpInterfaceInfo);
- }
- return SERVERCALL_ISHANDLED;
-}
-
-static DWORD (STDMETHODCALLTYPE mf_RetryRejectedCall)(
- IMessageFilter* pThis,
- HTASK threadIDCallee, //Server task handle
- DWORD dwTickCount, //Elapsed tick count
- DWORD dwRejectType //Returned rejection message
- )
-{
- if (previous_filter) {
- return previous_filter->lpVtbl->RetryRejectedCall(previous_filter,
- threadIDCallee,
- dwTickCount,
- dwRejectType);
- }
- return 1000;
-}
-
-static DWORD (STDMETHODCALLTYPE mf_MessagePending)(
- IMessageFilter* pThis,
- HTASK threadIDCallee, //Called applications task handle
- DWORD dwTickCount, //Elapsed tick count
- DWORD dwPendingType //Call type
- )
-{
- if (rb_during_gc()) {
- return PENDINGMSG_WAITNOPROCESS;
- }
- if (previous_filter) {
- return previous_filter->lpVtbl->MessagePending(previous_filter,
- threadIDCallee,
- dwTickCount,
- dwPendingType);
- }
- return PENDINGMSG_WAITNOPROCESS;
-}
-
typedef struct _Win32OLEIDispatch
{
IDispatch dispatch;
@@ -557,7 +459,7 @@ date2time_str(date)
double date;
{
int y, m, d, hh, mm, ss;
- char szTime[40];
+ char szTime[20];
double2time(date, &y, &m, &d, &hh, &mm, &ss);
sprintf(szTime,
"%4.4d/%02.2d/%02.2d %02.2d:%02.2d:%02.2d",
@@ -575,9 +477,8 @@ ole_wc2mb(pw)
LPSTR pm;
size = WideCharToMultiByte(cWIN32OLE_cp, 0, pw, -1, NULL, 0, NULL, NULL);
if (size) {
- pm = ALLOC_N(char, size + 1);
+ pm = ALLOC_N(char, size);
WideCharToMultiByte(cWIN32OLE_cp, 0, pw, -1, pm, size, NULL, NULL);
- pm[size] = '\0';
}
else {
pm = ALLOC_N(char, 1);
@@ -596,7 +497,7 @@ ole_hresult2msg(hr)
DWORD dwCount;
char strhr[100];
- sprintf(strhr, " HRESULT error code:0x%08lx\n ", hr);
+ sprintf(strhr, " HRESULT error code:0x%08x\n ", hr);
msg = rb_str_new2(strhr);
dwCount = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
@@ -620,15 +521,6 @@ ole_hresult2msg(hr)
return msg;
}
-static void
-ole_freeexceptinfo(pExInfo)
- EXCEPINFO *pExInfo;
-{
- SysFreeString(pExInfo->bstrDescription);
- SysFreeString(pExInfo->bstrSource);
- SysFreeString(pExInfo->bstrHelpFile);
-}
-
static VALUE
ole_excepinfo2msg(pExInfo)
EXCEPINFO *pExInfo;
@@ -668,7 +560,9 @@ ole_excepinfo2msg(pExInfo)
}
if(pSource) free(pSource);
if(pDescription) free(pDescription);
- ole_freeexceptinfo(pExInfo);
+ SysFreeString(pExInfo->bstrDescription);
+ SysFreeString(pExInfo->bstrSource);
+ SysFreeString(pExInfo->bstrHelpFile);
return error_msg;
}
@@ -723,11 +617,6 @@ ole_initialize()
/*
atexit((void (*)(void))ole_uninitialize);
*/
- hr = CoRegisterMessageFilter(&imessage_filter, &previous_filter);
- if(FAILED(hr)) {
- previous_filter = NULL;
- ole_raise(hr, rb_eRuntimeError, "fail: install OLE MessageFilter");
- }
}
}
@@ -1249,13 +1138,12 @@ reg_enum_key(hkey, i)
HKEY hkey;
DWORD i;
{
- char buf[BUFSIZ + 1];
- DWORD size_buf = sizeof(buf) - 1;
+ char buf[BUFSIZ];
+ DWORD size_buf = sizeof(buf);
FILETIME ft;
LONG err = RegEnumKeyEx(hkey, i, buf, &size_buf,
NULL, NULL, NULL, &ft);
if(err == ERROR_SUCCESS) {
- buf[BUFSIZ] = '\0';
return rb_str_new2(buf);
}
return Qnil;
@@ -1266,11 +1154,10 @@ reg_get_val(hkey, subkey)
HKEY hkey;
const char *subkey;
{
- char buf[BUFSIZ + 1];
- LONG size_buf = sizeof(buf) - 1;
+ char buf[BUFSIZ];
+ LONG size_buf = sizeof(buf);
LONG err = RegQueryValue(hkey, subkey, buf, &size_buf);
if (err == ERROR_SUCCESS) {
- buf[BUFSIZ] = '\0';
return rb_str_new2(buf);
}
return Qnil;
@@ -2213,15 +2100,12 @@ ole_invoke(argc, argv, self, wFlags)
&result, &excepinfo, &argErr);
if (FAILED(hr)) {
/* retry to call args by value */
- if(op.dp.cArgs >= cNamedArgs) {
+ if(op.dp.cArgs > cNamedArgs) {
for(i = cNamedArgs; i < op.dp.cArgs; i++) {
n = op.dp.cArgs - i + cNamedArgs - 1;
param = rb_ary_entry(paramS, i-cNamedArgs);
ole_val2variant(param, &op.dp.rgvarg[n]);
}
- if (hr == DISP_E_EXCEPTION) {
- ole_freeexceptinfo(&excepinfo);
- }
memset(&excepinfo, 0, sizeof(EXCEPINFO));
VariantInit(&result);
hr = pole->pDispatch->lpVtbl->Invoke(pole->pDispatch, DispID,
@@ -2234,9 +2118,6 @@ ole_invoke(argc, argv, self, wFlags)
* hResult == DISP_E_EXCEPTION. this only happens on
* functions whose DISPID > 0x8000 */
if ((hr == DISP_E_EXCEPTION || hr == DISP_E_MEMBERNOTFOUND) && DispID > 0x8000) {
- if (hr == DISP_E_EXCEPTION) {
- ole_freeexceptinfo(&excepinfo);
- }
memset(&excepinfo, 0, sizeof(EXCEPINFO));
hr = pole->pDispatch->lpVtbl->Invoke(pole->pDispatch, DispID,
&IID_NULL, lcid, wFlags,
@@ -2256,9 +2137,6 @@ ole_invoke(argc, argv, self, wFlags)
param = rb_ary_entry(paramS, i-cNamedArgs);
ole_val2variant2(param, &op.dp.rgvarg[n]);
}
- if (hr == DISP_E_EXCEPTION) {
- ole_freeexceptinfo(&excepinfo);
- }
memset(&excepinfo, 0, sizeof(EXCEPINFO));
VariantInit(&result);
hr = pole->pDispatch->lpVtbl->Invoke(pole->pDispatch, DispID,
@@ -3740,10 +3618,8 @@ ole_type_progid(pTypeInfo)
if (FAILED(hr))
return progid;
hr = ProgIDFromCLSID(&pTypeAttr->guid, &pbuf);
- if (SUCCEEDED(hr)) {
- progid = ole_wc2vstr(pbuf, FALSE);
- CoTaskMemFree(pbuf);
- }
+ if (SUCCEEDED(hr))
+ progid = WC2VSTR(pbuf);
OLE_RELEASE_TYPEATTR(pTypeInfo, pTypeAttr);
return progid;
}
@@ -4157,8 +4033,7 @@ folevariable_name(self)
return rb_ivar_get(self, rb_intern("name"));
}
-static VALUE
-ole_variable_ole_type(pTypeInfo, var_index)
+static ole_variable_ole_type(pTypeInfo, var_index)
ITypeInfo *pTypeInfo;
UINT var_index;
{
@@ -4202,8 +4077,7 @@ folevariable_ole_type(self)
return ole_variable_ole_type(pvar->pTypeInfo, pvar->index);
}
-static VALUE
-ole_variable_ole_type_detail(pTypeInfo, var_index)
+static ole_variable_ole_type_detail(pTypeInfo, var_index)
ITypeInfo *pTypeInfo;
UINT var_index;
{
@@ -4239,8 +4113,7 @@ folevariable_ole_type_detail(self)
return ole_variable_ole_type_detail(pvar->pTypeInfo, pvar->index);
}
-static VALUE
-ole_variable_value(pTypeInfo, var_index)
+static ole_variable_value(pTypeInfo, var_index)
ITypeInfo *pTypeInfo;
UINT var_index;
{
@@ -4286,8 +4159,7 @@ folevariable_value(self)
return ole_variable_value(pvar->pTypeInfo, pvar->index);
}
-static VALUE
-ole_variable_visible(pTypeInfo, var_index)
+static ole_variable_visible(pTypeInfo, var_index)
ITypeInfo *pTypeInfo;
UINT var_index;
{
@@ -4759,8 +4631,7 @@ folemethod_visible(self)
return ole_method_visible(pmethod->pTypeInfo, pmethod->index);
}
-static VALUE
-ole_method_event(pTypeInfo, method_index, method_name)
+static ole_method_event(pTypeInfo, method_index, method_name)
ITypeInfo *pTypeInfo;
WORD method_index;
VALUE method_name;
@@ -6238,14 +6109,6 @@ Init_win32ole()
com_vtbl.GetTypeInfo = GetTypeInfo;
com_vtbl.GetIDsOfNames = GetIDsOfNames;
com_vtbl.Invoke = Invoke;
-
- message_filter.QueryInterface = mf_QueryInterface;
- message_filter.AddRef = mf_AddRef;
- message_filter.Release = mf_Release;
- message_filter.HandleInComingCall = mf_HandleInComingCall;
- message_filter.RetryRejectedCall = mf_RetryRejectedCall;
- message_filter.MessagePending = mf_MessagePending;
-
com_hash = Data_Wrap_Struct(rb_cData, rb_mark_hash, st_free_table, st_init_numtable());
cWIN32OLE = rb_define_class("WIN32OLE", rb_cObject);
diff --git a/ext/zlib/extconf.rb b/ext/zlib/extconf.rb
index 53b971b189..b4e76af3c6 100644
--- a/ext/zlib/extconf.rb
+++ b/ext/zlib/extconf.rb
@@ -10,7 +10,7 @@ require 'rbconfig'
dir_config 'zlib'
-if %w'z libz zlib1 zlib zdll'.find {|z| have_library(z, 'deflateReset')} and
+if %w'z libz zlib zdll'.find {|z| have_library(z, 'deflateReset')} and
have_header('zlib.h') then
defines = []
@@ -22,7 +22,7 @@ if %w'z libz zlib1 zlib zdll'.find {|z| have_library(z, 'deflateReset')} and
os_code = 'AMIGA'
when /\Aos2[\-_]emx\z/ then
os_code = 'OS2'
- when /mswin|mingw|bccwin/ then
+ when 'mswin32', 'mingw32', 'bccwin32' then
# NOTE: cygwin should be regarded as Unix.
os_code = 'WIN32'
else
diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c
index 306e267856..8caadaeddc 100644
--- a/ext/zlib/zlib.c
+++ b/ext/zlib/zlib.c
@@ -1182,19 +1182,14 @@ static VALUE
rb_deflate_init_copy(self, orig)
VALUE self, orig;
{
- struct zstream *z1, *z2;
+ struct zstream *z1 = get_zstream(self);
+ struct zstream *z2 = get_zstream(orig);
int err;
- Data_Get_Struct(self, struct zstream, z1);
- z2 = get_zstream(orig);
-
err = deflateCopy(&z1->stream, &z2->stream);
if (err != Z_OK) {
raise_zlib_error(err, 0);
}
- z1->input = NIL_P(z2->input) ? Qnil : rb_str_dup(z2->input);
- z1->buf = NIL_P(z2->buf) ? Qnil : rb_str_dup(z2->buf);
- z1->buf_filled = z2->buf_filled;
z1->flags = z2->flags;
return self;
@@ -2491,7 +2486,7 @@ rb_gzfile_set_mtime(obj, mtime)
rb_raise(cGzError, "header is already written");
}
- if (FIXNUM_P(mtime)) {
+ if (FIXNUM_P(time)) {
gz->mtime = FIX2INT(mtime);
}
else {
@@ -3116,8 +3111,6 @@ gzreader_gets(argc, argv, obj)
if (NIL_P(rs)) {
dst = gzfile_read_all(gz);
if (RSTRING(dst)->len != 0) gz->lineno++;
- else
- return Qnil;
return dst;
}
@@ -3376,7 +3369,7 @@ void Init_zlib()
rb_define_singleton_method(cDeflate, "deflate", rb_deflate_s_deflate, -1);
rb_define_alloc_func(cDeflate, rb_deflate_s_allocate);
rb_define_method(cDeflate, "initialize", rb_deflate_initialize, -1);
- rb_define_method(cDeflate, "initialize_copy", rb_deflate_init_copy, 1);
+ rb_define_method(cDeflate, "initialize_copy", rb_deflate_init_copy, 0);
rb_define_method(cDeflate, "deflate", rb_deflate_deflate, -1);
rb_define_method(cDeflate, "<<", rb_deflate_addstr, 1);
rb_define_method(cDeflate, "flush", rb_deflate_flush, -1);
diff --git a/file.c b/file.c
index 8e8dae3a97..e392cd7b35 100644
--- a/file.c
+++ b/file.c
@@ -15,19 +15,12 @@
#ifdef _WIN32
#include "missing/file.h"
#endif
-#ifdef __CYGWIN__
-#define OpenFile WINAPI_OpenFile
-#include <windows.h>
-#include <sys/cygwin.h>
-#undef OpenFile
-#endif
#include "ruby.h"
#include "rubyio.h"
#include "rubysig.h"
#include "util.h"
#include "dln.h"
-#include <ctype.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
@@ -822,7 +815,6 @@ rb_file_lstat(obj)
#endif
}
-#ifndef HAVE_GROUP_MEMBER
static int
group_member(gid)
GETGROUPS_T gid;
@@ -852,7 +844,6 @@ group_member(gid)
#endif
return Qfalse;
}
-#endif
#ifndef S_IXUGO
# define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
@@ -2251,12 +2242,18 @@ rb_file_s_rename(klass, from, to)
errno = 0;
#endif
if (rename(src, dst) < 0) {
-#if defined DOSISH && !defined _WIN32
- switch (errno) {
- case EEXIST:
+#if defined __CYGWIN__
+ extern unsigned long __attribute__((stdcall)) GetLastError(void);
+ if (errno == 0) { /* This is a bug of old Cygwin */
+ /* incorrect as cygwin errno, but the last resort */
+ errno = GetLastError();
+ }
+#elif defined DOSISH && !defined _WIN32
+ if (errno == EEXIST
#if defined (__EMX__)
- case EACCES:
+ || errno == EACCES
#endif
+ ) {
if (chmod(dst, 0666) == 0 &&
unlink(dst) == 0 &&
rename(src, dst) == 0)
@@ -2305,29 +2302,12 @@ rb_file_s_umask(argc, argv)
return INT2FIX(omask);
}
-#ifdef __CYGWIN__
-#undef DOSISH
-#endif
-#if defined __CYGWIN__ || defined DOSISH
+#if defined DOSISH
#define DOSISH_UNC
-#define DOSISH_DRIVE_LETTER
#define isdirsep(x) ((x) == '/' || (x) == '\\')
#else
#define isdirsep(x) ((x) == '/')
#endif
-
-#if defined _WIN32 || defined __CYGWIN__
-#define USE_NTFS 1
-#else
-#define USE_NTFS 0
-#endif
-
-#if USE_NTFS
-#define istrailinggabage(x) ((x) == '.' || (x) == ' ')
-#else
-#define istrailinggabage(x) 0
-#endif
-
#ifndef CharNext /* defined as CharNext[AW] on Windows. */
# if defined(DJGPP)
# define CharNext(p) ((p) + mblen(p, MB_CUR_MAX))
@@ -2336,6 +2316,12 @@ rb_file_s_umask(argc, argv)
# endif
#endif
+#ifdef __CYGWIN__
+#undef DOSISH
+#define DOSISH_UNC
+#define DOSISH_DRIVE_LETTER
+#endif
+
#ifdef DOSISH_DRIVE_LETTER
static inline int
has_drive_letter(buf)
@@ -2447,7 +2433,7 @@ rb_path_last_separator(path)
return last;
}
-static char *
+char *
chompdirsep(path)
const char *path;
{
@@ -2472,40 +2458,15 @@ rb_path_end(path)
return chompdirsep(path);
}
-#if USE_NTFS
-static char *
-ntfs_tail(const char *path)
-{
- while (*path == '.') path++;
- while (*path && *path != ':') {
- if (istrailinggabage(*path)) {
- const char *last = path++;
- while (istrailinggabage(*path)) path++;
- if (!*path || *path == ':') return (char *)last;
- }
- else if (isdirsep(*path)) {
- const char *last = path++;
- while (isdirsep(*path)) path++;
- if (!*path) return (char *)last;
- if (*path == ':') path++;
- }
- else {
- path = CharNext(path);
- }
- }
- return (char *)path;
-}
-#endif
-
#define BUFCHECK(cond) do {\
long bdiff = p - buf;\
- if (cond) {\
- do {buflen *= 2;} while (cond);\
- rb_str_resize(result, buflen);\
- buf = RSTRING(result)->ptr;\
- p = buf + bdiff;\
- pend = buf + buflen;\
+ while (cond) {\
+ buflen *= 2;\
}\
+ rb_str_resize(result, buflen);\
+ buf = RSTRING(result)->ptr;\
+ p = buf + bdiff;\
+ pend = buf + buflen;\
} while (0)
#define BUFINIT() (\
@@ -2523,8 +2484,7 @@ static VALUE
file_expand_path(fname, dname, result)
VALUE fname, dname, result;
{
- const char *s, *b;
- char *buf, *p, *pend, *root;
+ char *s, *buf, *b, *p, *pend, *root;
long buflen, dirlen;
int tainted;
@@ -2665,21 +2625,15 @@ file_expand_path(fname, dname, result)
case '.':
if (*(s+1) == '\0' || isdirsep(*(s+1))) {
/* We must go back to the parent */
- char *n;
*p = '\0';
- if (!(n = strrdirsep(root))) {
+ if (!(b = strrdirsep(root))) {
*p = '/';
}
else {
- p = n;
+ p = b;
}
b = ++s;
}
-#if USE_NTFS
- else {
- do *++s; while (istrailinggabage(*s));
- }
-#endif
break;
case '/':
#if defined DOSISH || defined __CYGWIN__
@@ -2692,19 +2646,6 @@ file_expand_path(fname, dname, result)
break;
}
}
-#if USE_NTFS
- else {
- --s;
- case ' ': {
- const char *e = s;
- while (istrailinggabage(*s)) s++;
- if (!*s) {
- s = e;
- goto endpath;
- }
- }
- }
-#endif
break;
case '/':
#if defined DOSISH || defined __CYGWIN__
@@ -2727,77 +2668,15 @@ file_expand_path(fname, dname, result)
}
if (s > b) {
-#if USE_NTFS
- endpath:
- if (s > b + 6 && strncasecmp(s - 6, ":$DATA", 6) == 0) {
- /* alias of stream */
- /* get rid of a bug of x64 VC++ */
- if (*(s-7) == ':') s -= 7; /* prime */
- else if (memchr(b, ':', s - 6 - b)) s -= 6; /* alternative */
- }
-#endif
BUFCHECK(bdiff + (s-b) >= buflen);
memcpy(++p, b, s-b);
p += s-b;
}
if (p == skiproot(buf) - 1) p++;
-#if USE_NTFS
- *p = '\0';
- if ((s = strrdirsep(b = buf)) != 0 && !strpbrk(s, "*?")) {
- size_t len;
- WIN32_FIND_DATA wfd;
-#ifdef __CYGWIN__
- int lnk_added = 0, is_symlink = 0;
- struct stat st;
- char w32buf[MAXPATHLEN];
- p = (char *)s;
- if (lstat(buf, &st) == 0 && S_ISLNK(st.st_mode)) {
- is_symlink = 1;
- *p = '\0';
- }
- if (cygwin_conv_to_win32_path((*buf ? buf : "/"), w32buf) == 0) {
- b = w32buf;
- }
- if (is_symlink && b == w32buf) {
- *p = '\\';
- strlcat(w32buf, p, sizeof(w32buf));
- len = strlen(p);
- if (len > 4 && strcasecmp(p + len - 4, ".lnk") != 0) {
- lnk_added = 1;
- strlcat(w32buf, ".lnk", sizeof(w32buf));
- }
- }
- *p = '/';
-#endif
- HANDLE h = FindFirstFile(b, &wfd);
- if (h != INVALID_HANDLE_VALUE) {
- FindClose(h);
- len = strlen(wfd.cFileName);
-#ifdef __CYGWIN__
- if (lnk_added && len > 4 &&
- strcasecmp(wfd.cFileName + len - 4, ".lnk") == 0) {
- wfd.cFileName[len -= 4] = '\0';
- }
-#else
- p = (char *)s;
-#endif
- ++p;
- BUFCHECK(bdiff + len >= buflen);
- memcpy(p, wfd.cFileName, len + 1);
- p += len;
- }
-#ifdef __CYGWIN__
- else {
- p += strlen(p);
- }
-#endif
- }
-#endif
-
if (tainted) OBJ_TAINT(result);
RSTRING(result)->len = p - buf;
- RSTRING(result)->ptr[p - buf] = '\0';
+ *p = '\0';
return result;
}
@@ -2841,31 +2720,23 @@ rb_file_s_expand_path(argc, argv)
}
static int
-rmext(p, l1, e)
+rmext(p, e)
const char *p, *e;
- int l1;
{
- int l2;
+ int l1, l2;
if (!e) return 0;
+ l1 = chompdirsep(p) - p;
l2 = strlen(e);
if (l2 == 2 && e[1] == '*') {
- unsigned char c = *e;
- e = p + l1;
- do {
- if (e <= p) return 0;
- } while (*--e != c);
+ e = strrchr(p, *e);
+ if (!e) return 0;
return e - p;
}
if (l1 < l2) return l1;
-#if CASEFOLD_FILESYSTEM
-#define fncomp strncasecmp
-#else
-#define fncomp strncmp
-#endif
- if (fncomp(p+l1-l2, e, l2) == 0) {
+ if (strncmp(p+l1-l2, e, l2) == 0) {
return l1-l2;
}
return 0;
@@ -2895,7 +2766,7 @@ rb_file_s_basename(argc, argv)
#if defined DOSISH_DRIVE_LETTER || defined DOSISH_UNC
char *root;
#endif
- int f, n;
+ int f;
if (rb_scan_args(argc, argv, "11", &fname, &fext) == 2) {
StringValue(fext);
@@ -2929,22 +2800,18 @@ rb_file_s_basename(argc, argv)
#endif
#endif
}
- else {
- if (!(p = strrdirsep(name))) {
- p = name;
+ else if (!(p = strrdirsep(name))) {
+ if (NIL_P(fext) || !(f = rmext(name, StringValueCStr(fext)))) {
+ f = chompdirsep(name) - name;
+ if (f == RSTRING(fname)->len) return fname;
}
- else {
- while (isdirsep(*p)) p++; /* skip last / */
- }
-#if USE_NTFS
- n = ntfs_tail(p) - p;
-#else
- n = chompdirsep(p) - p;
-#endif
- if (NIL_P(fext) || !(f = rmext(p, n, StringValueCStr(fext)))) {
- f = n;
+ p = name;
+ }
+ else {
+ while (isdirsep(*p)) p++; /* skip last / */
+ if (NIL_P(fext) || !(f = rmext(p, StringValueCStr(fext)))) {
+ f = chompdirsep(p) - p;
}
- if (f == RSTRING_LEN(fname)) return fname;
}
basename = rb_str_new(p, f);
OBJ_INFECT(basename, fname);
@@ -3020,49 +2887,22 @@ static VALUE
rb_file_s_extname(klass, fname)
VALUE klass, fname;
{
- const char *name, *p, *e;
+ char *name, *p, *e;
VALUE extname;
name = StringValueCStr(fname);
p = strrdirsep(name); /* get the last path component */
if (!p)
- p = name;
+ p = name;
else
- name = ++p;
-
- e = 0;
- while (*p) {
- if (*p == '.' || istrailinggabage(*p)) {
-#if USE_NTFS
- const char *last = p++, *dot = last;
- while (istrailinggabage(*p)) {
- if (*p == '.') dot = p;
- p++;
- }
- if (!*p || *p == ':') {
- p = last;
- break;
- }
- if (*last == '.') e = dot;
- continue;
-#else
- e = p; /* get the last dot of the last component */
-#endif
- }
-#if USE_NTFS
- else if (*p == ':') {
- break;
- }
-#endif
- else if (isdirsep(*p))
- break;
- p = CharNext(p);
- }
- if (!e || e == name || e+1 == p) /* no dot, or the only dot is first or end? */
- return rb_str_new(0, 0);
- extname = rb_str_new(e, p - e); /* keep the dot, too! */
- OBJ_INFECT(extname, fname);
- return extname;
+ p++;
+
+ e = strrchr(p, '.'); /* get the last dot of the last component */
+ if (!e || e == p || !e[1]) /* no dot, or the only dot is first or end? */
+ return rb_str_new2("");
+ extname = rb_str_new(e, chompdirsep(e) - e); /* keep the dot, too! */
+ OBJ_INFECT(extname, fname);
+ return extname;
}
/*
@@ -3264,7 +3104,7 @@ rb_file_truncate(obj, len)
f = GetWriteFile(fptr);
fflush(f);
fseeko(f, (off_t)0, SEEK_CUR);
-#ifdef HAVE_FTRUNCATE
+#ifdef HAVE_TRUNCATE
if (ftruncate(fileno(f), pos) < 0)
rb_sys_fail(fptr->path);
#else
@@ -3292,10 +3132,8 @@ rb_file_truncate(obj, len)
# endif
#ifdef __CYGWIN__
-#include <winerror.h>
-extern unsigned long __attribute__((stdcall)) GetLastError(void);
-
static int
+#include <winerror.h>
cygwin_flock(int fd, int op)
{
int old_errno = errno;
diff --git a/gc.c b/gc.c
index 51ceb3db10..9ac3bfbf6f 100644
--- a/gc.c
+++ b/gc.c
@@ -74,22 +74,16 @@ static void run_final();
static VALUE nomem_error;
static void garbage_collect();
-NORETURN(void rb_exc_jump _((VALUE)));
-
void
rb_memerror()
{
- rb_thread_t th = rb_curr_thread;
+ static int recurse = 0;
- if (!nomem_error ||
- (rb_thread_raised_p(th, RAISED_NOMEMORY) && rb_safe_level() < 4)) {
+ if (!nomem_error || (recurse > 0 && rb_safe_level() < 4)) {
fprintf(stderr, "[FATAL] failed to allocate memory\n");
exit(1);
}
- if (rb_thread_raised_p(th, RAISED_NOMEMORY)) {
- rb_exc_jump(nomem_error);
- }
- rb_thread_raised_set(th, RAISED_NOMEMORY);
+ recurse++;
rb_exc_raise(nomem_error);
}
@@ -103,8 +97,9 @@ ruby_xmalloc(size)
rb_raise(rb_eNoMemError, "negative allocation size (or too big)");
}
if (size == 0) size = 1;
+ malloc_increase += size;
- if ((malloc_increase+size) > malloc_limit) {
+ if (malloc_increase > malloc_limit) {
garbage_collect();
}
RUBY_CRITICAL(mem = malloc(size));
@@ -115,7 +110,6 @@ ruby_xmalloc(size)
rb_memerror();
}
}
- malloc_increase += size;
return mem;
}
@@ -144,6 +138,7 @@ ruby_xrealloc(ptr, size)
}
if (!ptr) return xmalloc(size);
if (size == 0) size = 1;
+ malloc_increase += size;
RUBY_CRITICAL(mem = realloc(ptr, size));
if (!mem) {
garbage_collect();
@@ -152,7 +147,6 @@ ruby_xrealloc(ptr, size)
rb_memerror();
}
}
- malloc_increase += size;
return mem;
}
@@ -379,20 +373,11 @@ add_heap()
}
#define RANY(o) ((RVALUE*)(o))
-int
-rb_during_gc()
-{
- return during_gc;
-}
-
VALUE
rb_newobj()
{
VALUE obj;
- if (during_gc)
- rb_bug("object allocation during garbage collection phase");
-
if (!freelist) garbage_collect();
obj = (VALUE)freelist;
@@ -440,7 +425,7 @@ unsigned int _stacksize = 262144;
# define STACK_LEVEL_MAX (_stacksize - 4096)
# undef HAVE_GETRLIMIT
#elif defined(HAVE_GETRLIMIT) || defined(_WIN32)
-static size_t STACK_LEVEL_MAX = 655300;
+static unsigned int STACK_LEVEL_MAX = 655300;
#else
# define STACK_LEVEL_MAX 655300
#endif
@@ -453,19 +438,20 @@ static size_t STACK_LEVEL_MAX = 655300;
# if ( __GNUC__ == 3 && __GNUC_MINOR__ > 0 ) || __GNUC__ > 3
__attribute__ ((noinline))
# endif
-static void
-stack_end_address(VALUE **stack_end_p)
+static VALUE *
+stack_end_address(void)
{
- VALUE stack_end;
- *stack_end_p = &stack_end;
+ return (VALUE *)__builtin_frame_address(0);
}
-# define SET_STACK_END VALUE *stack_end; stack_end_address(&stack_end)
+# define SET_STACK_END VALUE *stack_end = stack_end_address()
# else
# define SET_STACK_END VALUE *stack_end = alloca(1)
# endif
# define STACK_END (stack_end)
#endif
-#if STACK_GROW_DIRECTION < 0
+#if defined(sparc) || defined(__sparc__)
+# define STACK_LENGTH (rb_gc_stack_start - STACK_END + 0x80)
+#elif STACK_GROW_DIRECTION < 0
# define STACK_LENGTH (rb_gc_stack_start - STACK_END)
#elif STACK_GROW_DIRECTION > 0
# define STACK_LENGTH (STACK_END - rb_gc_stack_start + 1)
@@ -499,7 +485,7 @@ stack_grow_direction(addr)
(ret) = (STACK_LENGTH > STACK_LEVEL_MAX + GC_WATER_MARK);\
} while (0)
-size_t
+int
ruby_stack_length(p)
VALUE **p;
{
@@ -537,18 +523,17 @@ char *
rb_source_filename(f)
const char *f;
{
- st_data_t name;
+ char *name;
- if (!st_lookup(source_filenames, (st_data_t)f, &name)) {
+ if (!st_lookup(source_filenames, (st_data_t)f, (st_data_t *)&name)) {
long len = strlen(f) + 1;
- char *ptr = ALLOC_N(char, len + 1);
- name = (st_data_t)ptr;
+ char *ptr = name = ALLOC_N(char, len + 1);
*ptr++ = 0;
MEMCPY(ptr, f, char, len);
- st_add_direct(source_filenames, (st_data_t)ptr, name);
+ st_add_direct(source_filenames, (st_data_t)ptr, (st_data_t)name);
return ptr;
}
- return (char *)name + 1;
+ return name + 1;
}
static void
@@ -684,31 +669,6 @@ rb_mark_tbl(tbl)
}
static int
-mark_key(key, value, lev)
- VALUE key, value;
- int lev;
-{
- gc_mark(key, lev);
- return ST_CONTINUE;
-}
-
-static void
-mark_set(tbl, lev)
- st_table *tbl;
- int lev;
-{
- if (!tbl) return;
- st_foreach(tbl, mark_key, lev);
-}
-
-void
-rb_mark_set(tbl)
- st_table *tbl;
-{
- mark_set(tbl, 0);
-}
-
-static int
mark_keyvalue(key, value, lev)
VALUE key;
VALUE value;
@@ -1037,16 +997,7 @@ gc_mark_children(ptr, lev)
}
}
-static int obj_free _((VALUE));
-
-static inline void
-add_freelist(p)
- RVALUE *p;
-{
- p->as.free.flags = 0;
- p->as.free.next = freelist;
- freelist = p;
-}
+static void obj_free _((VALUE));
static void
finalize_list(p)
@@ -1056,7 +1007,9 @@ finalize_list(p)
RVALUE *tmp = p->as.free.next;
run_final((VALUE)p);
if (!FL_TEST(p, FL_SINGLETON)) { /* not freeing page */
- add_freelist(p);
+ p->as.free.flags = 0;
+ p->as.free.next = freelist;
+ freelist = p;
}
p = tmp;
}
@@ -1081,8 +1034,6 @@ free_unused_heaps()
}
}
-#define T_DEFERRED 0x3a
-
void rb_gc_abort_threads(void);
static void
@@ -1126,28 +1077,26 @@ gc_sweep()
int n = 0;
RVALUE *free = freelist;
RVALUE *final = final_list;
- int deferred;
p = heaps[i].slot; pend = p + heaps[i].limit;
while (p < pend) {
if (!(p->as.basic.flags & FL_MARK)) {
- if (p->as.basic.flags &&
- ((deferred = obj_free((VALUE)p)) ||
- ((FL_TEST(p, FL_FINALIZE)) && need_call_final))) {
- if (!deferred) {
- p->as.free.flags = T_DEFERRED;
- RDATA(p)->dfree = 0;
- }
- p->as.free.flags |= FL_MARK;
+ if (p->as.basic.flags) {
+ obj_free((VALUE)p);
+ }
+ if (need_call_final && FL_TEST(p, FL_FINALIZE)) {
+ p->as.free.flags = FL_MARK; /* remain marked */
p->as.free.next = final_list;
final_list = p;
}
else {
- add_freelist(p);
+ p->as.free.flags = 0;
+ p->as.free.next = freelist;
+ freelist = p;
}
n++;
}
- else if (BUILTIN_TYPE(p) == T_DEFERRED) {
+ else if (RBASIC(p)->flags == FL_MARK) {
/* objects to be finalized */
/* do nothing remain marked */
}
@@ -1183,7 +1132,6 @@ gc_sweep()
/* clear finalization list */
if (final_list) {
deferred_final_list = final_list;
- rb_thread_pending = 1;
return;
}
free_unused_heaps();
@@ -1193,21 +1141,16 @@ void
rb_gc_force_recycle(p)
VALUE p;
{
- add_freelist(p);
-}
-
-static inline void
-make_deferred(p)
- RVALUE *p;
-{
- p->as.basic.flags = (p->as.basic.flags & ~T_MASK) | T_DEFERRED;
+ RANY(p)->as.free.flags = 0;
+ RANY(p)->as.free.next = freelist;
+ freelist = RANY(p);
}
-static int
+static void
obj_free(obj)
VALUE obj;
{
- switch (BUILTIN_TYPE(obj)) {
+ switch (RANY(obj)->as.basic.flags & T_MASK) {
case T_NIL:
case T_FIXNUM:
case T_TRUE:
@@ -1220,7 +1163,7 @@ obj_free(obj)
rb_free_generic_ivar((VALUE)obj);
}
- switch (BUILTIN_TYPE(obj)) {
+ switch (RANY(obj)->as.basic.flags & T_MASK) {
case T_OBJECT:
if (RANY(obj)->as.object.iv_tbl) {
st_free_table(RANY(obj)->as.object.iv_tbl);
@@ -1263,8 +1206,7 @@ obj_free(obj)
RUBY_CRITICAL(free(DATA_PTR(obj)));
}
else if (RANY(obj)->as.data.dfree) {
- make_deferred(RANY(obj));
- return 1;
+ (*RANY(obj)->as.data.dfree)(DATA_PTR(obj));
}
}
break;
@@ -1276,11 +1218,8 @@ obj_free(obj)
break;
case T_FILE:
if (RANY(obj)->as.file.fptr) {
- struct rb_io_t *fptr = RANY(obj)->as.file.fptr;
- make_deferred(RANY(obj));
- RDATA(obj)->dfree = (void (*)(void*))rb_io_fptr_finalize;
- RDATA(obj)->data = fptr;
- return 1;
+ rb_io_fptr_finalize(RANY(obj)->as.file.fptr);
+ RUBY_CRITICAL(free(RANY(obj)->as.file.fptr));
}
break;
case T_ICLASS:
@@ -1308,13 +1247,13 @@ obj_free(obj)
RUBY_CRITICAL(free(RANY(obj)->as.node.u1.node));
break;
}
- break; /* no need to free iv_tbl */
+ return; /* no need to free iv_tbl */
case T_SCOPE:
if (RANY(obj)->as.scope.local_vars &&
RANY(obj)->as.scope.flags != SCOPE_ALLOCA) {
VALUE *vars = RANY(obj)->as.scope.local_vars-1;
- if (!(RANY(obj)->as.scope.flags & SCOPE_CLONE) && vars[0] == 0)
+ if (!(RANY(obj)->as.scope.flags & SCOPE_CLONE) && vars[0] == 0)
RUBY_CRITICAL(free(RANY(obj)->as.scope.local_tbl));
if (RANY(obj)->as.scope.flags & SCOPE_MALLOC)
RUBY_CRITICAL(free(vars));
@@ -1331,8 +1270,6 @@ obj_free(obj)
rb_bug("gc_sweep(): unknown data type 0x%lx(0x%lx)",
RANY(obj)->as.basic.flags & T_MASK, obj);
}
-
- return 0;
}
void
@@ -1551,7 +1488,7 @@ Init_stack(addr)
rb_gc_stack_start = STACK_END_ADDRESS;
}
#else
- if (!addr) addr = (void *)&addr;
+ if (!addr) addr = (VALUE *)&addr;
STACK_UPPER(&addr, addr, ++addr);
if (rb_gc_stack_start) {
if (STACK_UPPER(&addr,
@@ -1662,6 +1599,38 @@ Init_heap()
}
static VALUE
+os_live_obj()
+{
+ int i;
+ int n = 0;
+
+ for (i = 0; i < heaps_used; i++) {
+ RVALUE *p, *pend;
+
+ p = heaps[i].slot; pend = p + heaps[i].limit;
+ for (;p < pend; p++) {
+ if (p->as.basic.flags) {
+ switch (TYPE(p)) {
+ case T_ICLASS:
+ case T_VARMAP:
+ case T_SCOPE:
+ case T_NODE:
+ continue;
+ case T_CLASS:
+ if (FL_TEST(p, FL_SINGLETON)) continue;
+ default:
+ if (!p->as.basic.klass) continue;
+ rb_yield((VALUE)p);
+ n++;
+ }
+ }
+ }
+ }
+
+ return INT2FIX(n);
+}
+
+static VALUE
os_obj_of(of)
VALUE of;
{
@@ -1674,19 +1643,17 @@ os_obj_of(of)
p = heaps[i].slot; pend = p + heaps[i].limit;
for (;p < pend; p++) {
if (p->as.basic.flags) {
- switch (BUILTIN_TYPE(p)) {
- case T_NONE:
+ switch (TYPE(p)) {
case T_ICLASS:
case T_VARMAP:
case T_SCOPE:
case T_NODE:
- case T_DEFERRED:
continue;
case T_CLASS:
if (FL_TEST(p, FL_SINGLETON)) continue;
default:
if (!p->as.basic.klass) continue;
- if (!of || rb_obj_is_kind_of((VALUE)p, of)) {
+ if (rb_obj_is_kind_of((VALUE)p, of)) {
rb_yield((VALUE)p);
n++;
}
@@ -1740,9 +1707,11 @@ os_each_obj(argc, argv)
rb_secure(4);
if (rb_scan_args(argc, argv, "01", &of) == 0) {
- of = 0;
+ return os_live_obj();
+ }
+ else {
+ return os_obj_of(of);
}
- return os_obj_of(of);
}
static VALUE finalizers;
@@ -1843,14 +1812,9 @@ define_final(argc, argv, os)
rb_obj_classname(block));
}
need_call_final = 1;
- if (!FL_ABLE(obj)) {
- rb_raise(rb_eArgError, "cannot define finalizer for %s",
- rb_obj_classname(obj));
- }
- RBASIC(obj)->flags |= FL_FINALIZE;
+ FL_SET(obj, FL_FINALIZE);
block = rb_ary_new3(2, INT2FIX(ruby_safe_level), block);
- OBJ_FREEZE(block);
if (!finalizer_table) {
finalizer_table = st_init_numtable();
@@ -1859,9 +1823,7 @@ define_final(argc, argv, os)
rb_ary_push(table, block);
}
else {
- table = rb_ary_new3(1, block);
- RBASIC(table)->klass = 0;
- st_add_direct(finalizer_table, obj, table);
+ st_add_direct(finalizer_table, obj, rb_ary_new3(1, block));
}
return block;
}
@@ -1929,21 +1891,6 @@ rb_gc_finalize_deferred()
}
}
-static int
-chain_finalized_object(st_data_t key, st_data_t val, st_data_t arg)
-{
- RVALUE *p = (RVALUE *)key, **final_list = (RVALUE **)arg;
- if ((p->as.basic.flags & (FL_FINALIZE|FL_MARK)) == FL_FINALIZE) {
- if (BUILTIN_TYPE(p) != T_DEFERRED) {
- p->as.free.flags = FL_MARK | T_DEFERRED; /* remain marked */
- RDATA(p)->dfree = 0;
- }
- p->as.free.next = *final_list;
- *final_list = p;
- }
- return ST_CONTINUE;
-}
-
void
rb_gc_call_finalizer_at_exit()
{
@@ -1952,14 +1899,20 @@ rb_gc_call_finalizer_at_exit()
/* run finalizers */
if (need_call_final) {
- do {
- p = deferred_final_list;
- deferred_final_list = 0;
- finalize_list(p);
- mark_tbl(finalizer_table, 0);
- st_foreach(finalizer_table, chain_finalized_object,
- (st_data_t)&deferred_final_list);
- } while (deferred_final_list);
+ p = deferred_final_list;
+ deferred_final_list = 0;
+ finalize_list(p);
+ for (i = 0; i < heaps_used; i++) {
+ p = heaps[i].slot; pend = p + heaps[i].limit;
+ while (p < pend) {
+ if (FL_TEST(p, FL_FINALIZE)) {
+ FL_UNSET(p, FL_FINALIZE);
+ p->as.basic.klass = 0;
+ run_final((VALUE)p);
+ }
+ p++;
+ }
+ }
}
/* run data object's finalizers */
for (i = 0; i < heaps_used; i++) {
@@ -2002,7 +1955,6 @@ id2ref(obj, objid)
VALUE obj, objid;
{
unsigned long ptr, p0;
- int type;
rb_secure(4);
p0 = ptr = NUM2ULONG(objid);
@@ -2019,8 +1971,7 @@ id2ref(obj, objid)
return ID2SYM(symid);
}
- if (!is_pointer_to_heap((void *)ptr)||
- (type = BUILTIN_TYPE(ptr)) > T_SYMBOL || type == T_ICLASS) {
+ if (!is_pointer_to_heap((void *)ptr)|| BUILTIN_TYPE(ptr) >= T_BLKTAG) {
rb_raise(rb_eRangeError, "0x%lx is not id value", p0);
}
if (BUILTIN_TYPE(ptr) == 0 || RBASIC(ptr)->klass == 0) {
@@ -2134,10 +2085,7 @@ Init_GC()
source_filenames = st_init_strtable();
rb_global_variable(&nomem_error);
- nomem_error = rb_exc_new3(rb_eNoMemError,
- rb_obj_freeze(rb_str_new2("failed to allocate memory")));
- OBJ_TAINT(nomem_error);
- OBJ_FREEZE(nomem_error);
+ nomem_error = rb_exc_new2(rb_eNoMemError, "failed to allocate memory");
rb_define_method(rb_mKernel, "hash", rb_obj_id, 0);
rb_define_method(rb_mKernel, "__id__", rb_obj_id, 0);
diff --git a/hash.c b/hash.c
index 557e3c8b5a..e2f7345f5a 100644
--- a/hash.c
+++ b/hash.c
@@ -590,23 +590,6 @@ index_i(key, value, args)
return ST_CONTINUE;
}
-static VALUE
-rb_hash_delete_key(hash, key)
- VALUE hash, key;
-{
- st_data_t ktmp = (st_data_t)key, val;
-
- if (RHASH(hash)->iter_lev > 0) {
- if (st_delete_safe(RHASH(hash)->tbl, &ktmp, &val, Qundef)) {
- FL_SET(hash, HASH_DELETED);
- return (VALUE)val;
- }
- }
- else if (st_delete(RHASH(hash)->tbl, &ktmp, &val))
- return (VALUE)val;
- return Qundef;
-}
-
/*
* call-seq:
* hsh.index(value) => key
@@ -686,8 +669,14 @@ rb_hash_delete(hash, key)
VALUE val;
rb_hash_modify(hash);
- val = rb_hash_delete_key(hash, key);
- if (val != Qundef) return val;
+ if (RHASH(hash)->iter_lev > 0) {
+ if (st_delete_safe(RHASH(hash)->tbl, (st_data_t*)&key, &val, Qundef)) {
+ FL_SET(hash, HASH_DELETED);
+ return val;
+ }
+ }
+ else if (st_delete(RHASH(hash)->tbl, (st_data_t*)&key, &val))
+ return val;
if (rb_block_given_p()) {
return rb_yield(key);
}
@@ -695,6 +684,7 @@ rb_hash_delete(hash, key)
}
struct shift_var {
+ int stop;
VALUE key;
VALUE val;
};
@@ -705,23 +695,13 @@ shift_i(key, value, var)
struct shift_var *var;
{
if (key == Qundef) return ST_CONTINUE;
- if (var->key != Qundef) return ST_STOP;
+ if (var->stop) return ST_STOP;
+ var->stop = 1;
var->key = key;
var->val = value;
return ST_DELETE;
}
-static int
-shift_i_safe(key, value, var)
- VALUE key, value;
- struct shift_var *var;
-{
- if (key == Qundef) return ST_CONTINUE;
- var->key = key;
- var->val = value;
- return ST_STOP;
-}
-
/*
* call-seq:
* hsh.shift -> anArray or obj
@@ -742,21 +722,10 @@ rb_hash_shift(hash)
struct shift_var var;
rb_hash_modify(hash);
- var.key = Qundef;
- if (RHASH(hash)->iter_lev > 0) {
- rb_hash_foreach(hash, shift_i_safe, (st_data_t)&var);
- if (var.key != Qundef) {
- st_data_t key = var.key;
- if (st_delete_safe(RHASH(hash)->tbl, &key, 0, Qundef)) {
- FL_SET(hash, HASH_DELETED);
- }
- }
- }
- else {
- rb_hash_foreach(hash, shift_i, (st_data_t)&var);
- }
+ var.stop = 0;
+ rb_hash_foreach(hash, shift_i, (st_data_t)&var);
- if (var.key != Qundef) {
+ if (var.stop) {
return rb_assoc_new(var.key, var.val);
}
else if (FL_TEST(hash, HASH_PROC_DEFAULT)) {
@@ -773,7 +742,7 @@ delete_if_i(key, value, hash)
{
if (key == Qundef) return ST_CONTINUE;
if (RTEST(rb_yield_values(2, key, value))) {
- rb_hash_delete_key(hash, key);
+ rb_hash_delete(hash, key);
}
return ST_CONTINUE;
}
diff --git a/intern.h b/intern.h
index 1c55a07390..65c916328c 100644
--- a/intern.h
+++ b/intern.h
@@ -114,7 +114,6 @@ VALUE rb_mod_ancestors _((VALUE));
VALUE rb_class_instance_methods _((int, VALUE*, VALUE));
VALUE rb_class_public_instance_methods _((int, VALUE*, VALUE));
VALUE rb_class_protected_instance_methods _((int, VALUE*, VALUE));
-VALUE rb_big_rshift(VALUE, VALUE);
VALUE rb_class_private_instance_methods _((int, VALUE*, VALUE));
VALUE rb_obj_singleton_methods _((int, VALUE*, VALUE));
void rb_define_method_id _((VALUE, ID, VALUE (*)(ANYARGS), int));
@@ -207,10 +206,8 @@ void rb_thread_sleep _((int));
void rb_thread_sleep_forever _((void));
VALUE rb_thread_stop _((void));
VALUE rb_thread_wakeup _((VALUE));
-VALUE rb_thread_wakeup_alive _((VALUE));
VALUE rb_thread_run _((VALUE));
VALUE rb_thread_kill _((VALUE));
-VALUE rb_thread_alive_p _((VALUE));
VALUE rb_thread_create _((VALUE (*)(ANYARGS), void*));
void rb_thread_interrupt _((void));
void rb_thread_trap_eval _((VALUE, int, int));
@@ -238,12 +235,10 @@ VALUE rb_file_directory_p _((VALUE,VALUE));
/* gc.c */
NORETURN(void rb_memerror __((void)));
int ruby_stack_check _((void));
-size_t ruby_stack_length _((VALUE**));
-int rb_during_gc _((void));
+int ruby_stack_length _((VALUE**));
char *rb_source_filename _((const char*));
void rb_gc_mark_locations _((VALUE*, VALUE*));
void rb_mark_tbl _((struct st_table*));
-void rb_mark_set _((struct st_table*));
void rb_mark_hash _((struct st_table*));
void rb_gc_mark_maybe _((VALUE));
void rb_gc_mark _((VALUE));
@@ -402,7 +397,6 @@ const char *ruby_signal_name _((int));
void ruby_default_signal _((int));
/* sprintf.c */
VALUE rb_f_sprintf _((int, VALUE*));
-VALUE rb_str_format _((int, VALUE*, VALUE));
/* string.c */
VALUE rb_str_new _((const char*, long));
VALUE rb_str_new2 _((const char*));
diff --git a/io.c b/io.c
index 257a0ea07e..e98520da36 100644
--- a/io.c
+++ b/io.c
@@ -245,7 +245,6 @@ flush_before_seek(fptr)
if (fptr->mode & FMODE_WBUF) {
io_fflush(GetWriteFile(fptr), fptr);
}
- errno = 0;
return fptr;
}
@@ -669,7 +668,7 @@ rb_io_tell(io)
GetOpenFile(io, fptr);
pos = io_tell(fptr);
- if (pos < 0 && errno) rb_sys_fail(fptr->path);
+ if (pos < 0) rb_sys_fail(fptr->path);
return OFFT2NUM(pos);
}
@@ -684,7 +683,7 @@ rb_io_seek(io, offset, whence)
pos = NUM2OFFT(offset);
GetOpenFile(io, fptr);
pos = io_seek(fptr, pos, whence);
- if (pos < 0 && errno) rb_sys_fail(fptr->path);
+ if (pos < 0) rb_sys_fail(fptr->path);
clearerr(fptr->f);
return INT2FIX(0);
@@ -1053,7 +1052,7 @@ read_buffered_data(ptr, len, f)
#endif
}
-static long
+long
io_fread(ptr, len, fptr)
char *ptr;
long len;
@@ -1275,8 +1274,6 @@ io_getpartial(int argc, VALUE *argv, VALUE io, int nonblock)
goto again;
rb_sys_fail(fptr->path);
}
- if (fptr->f) /* update pos in FILE structure [ruby-core:21561] */
- fflush(fptr->f);
}
rb_str_resize(str, n);
@@ -1725,7 +1722,7 @@ rb_io_getline(rs, io)
while ((c = appendline(fptr, newline, &str)) != EOF &&
(c != newline || RSTRING(str)->len < rslen ||
- ((rspara || rscheck(rsptr,rslen,rs)) && 0) ||
+ (rspara || rscheck(rsptr,rslen,rs), 0) ||
memcmp(RSTRING(str)->ptr+RSTRING(str)->len-rslen,rsptr,rslen)));
if (rspara) {
@@ -2171,7 +2168,6 @@ fptr_finalize(fptr, noraise)
{
int n1 = 0, n2 = 0, f1, f2 = -1;
- errno = 0;
if (fptr->f2) {
f2 = fileno(fptr->f2);
while (n2 = 0, fflush(fptr->f2) < 0) {
@@ -3030,29 +3026,11 @@ pipe_open(pstr, pname, mode)
{
int modef = rb_io_mode_flags(mode);
OpenFile *fptr;
+
#if defined(DJGPP) || defined(__human68k__) || defined(__VMS)
FILE *f;
-#else
- int pid;
-#ifdef _WIN32
- FILE *fpr, *fpw;
-#else
- int pr[2], pw[2];
-#endif
-#endif
- volatile int doexec;
if (!pname) pname = StringValueCStr(pstr);
- doexec = (strcmp("-", pname) != 0);
-
-#if defined(DJGPP) || defined(__human68k__) || defined(__VMS) || defined(_WIN32)
- if (!doexec) {
- rb_raise(rb_eNotImpError,
- "fork() function is unimplemented on this machine");
- }
-#endif
-
-#if defined(DJGPP) || defined(__human68k__) || defined(__VMS)
f = popen(pname, mode);
if (!f) rb_sys_fail(pname);
@@ -3074,6 +3052,10 @@ pipe_open(pstr, pname, mode)
}
#else
#ifdef _WIN32
+ int pid;
+ FILE *fpr, *fpw;
+
+ if (!pname) pname = StringValueCStr(pstr);
retry:
pid = pipe_exec(pname, rb_io_mode_modenum(mode), &fpr, &fpw);
if (pid == -1) { /* exec failed */
@@ -3103,10 +3085,16 @@ retry:
return (VALUE)port;
}
#else
+ int pid, pr[2], pw[2];
+ volatile int doexec;
+
+ if (!pname) pname = StringValueCStr(pstr);
+
if (((modef & FMODE_READABLE) && pipe(pr) == -1) ||
((modef & FMODE_WRITABLE) && pipe(pw) == -1))
rb_sys_fail(pname);
+ doexec = (strcmp("-", pname) != 0);
if (!doexec) {
fflush(stdin); /* is it really needed? */
fflush(stdout);
@@ -3258,7 +3246,7 @@ rb_io_s_popen(argc, argv, klass)
mode = rb_io_modenum_mode(FIX2INT(pmode));
}
else {
- mode = rb_io_flags_mode(rb_io_mode_flags(StringValueCStr(pmode)));
+ mode = rb_io_flags_mode(rb_io_mode_flags(StringValuePtr(pmode)));
}
SafeStringValue(pname);
port = pipe_open(pname, 0, mode);
@@ -3286,14 +3274,12 @@ rb_open_file(argc, argv, io)
VALUE io;
{
VALUE fname, vmode, perm;
- char *path, *mode;
- int flags;
- unsigned int fmode;
+ char *mode;
+ int flags, fmode;
rb_scan_args(argc, argv, "12", &fname, &vmode, &perm);
SafeStringValue(fname);
- path = StringValueCStr(fname);
if (FIXNUM_P(vmode) || !NIL_P(perm)) {
if (FIXNUM_P(vmode)) {
flags = FIX2INT(vmode);
@@ -3302,13 +3288,13 @@ rb_open_file(argc, argv, io)
SafeStringValue(vmode);
flags = rb_io_mode_modenum(RSTRING(vmode)->ptr);
}
- fmode = NIL_P(perm) ? 0666 : NUM2UINT(perm);
+ fmode = NIL_P(perm) ? 0666 : NUM2INT(perm);
- rb_file_sysopen_internal(io, path, flags, fmode);
+ rb_file_sysopen_internal(io, RSTRING(fname)->ptr, flags, fmode);
}
else {
- mode = NIL_P(vmode) ? "r" : StringValueCStr(vmode);
- rb_file_open_internal(io, path, mode);
+ mode = NIL_P(vmode) ? "r" : StringValuePtr(vmode);
+ rb_file_open_internal(io, RSTRING(fname)->ptr, mode);
}
return io;
}
@@ -3358,8 +3344,7 @@ rb_io_s_sysopen(argc, argv)
VALUE *argv;
{
VALUE fname, vmode, perm;
- int flags, fd;
- unsigned int fmode;
+ int flags, fmode, fd;
char *path;
rb_scan_args(argc, argv, "12", &fname, &vmode, &perm);
@@ -3372,7 +3357,7 @@ rb_io_s_sysopen(argc, argv)
flags = rb_io_mode_modenum(RSTRING(vmode)->ptr);
}
if (NIL_P(perm)) fmode = 0666;
- else fmode = NUM2UINT(perm);
+ else fmode = NUM2INT(perm);
path = ALLOCA_N(char, strlen(RSTRING(fname)->ptr)+1);
strcpy(path, RSTRING(fname)->ptr);
@@ -3662,7 +3647,7 @@ rb_io_reopen(argc, argv, file)
}
if (!NIL_P(nmode)) {
- fptr->mode = rb_io_mode_flags(StringValueCStr(nmode));
+ fptr->mode = rb_io_mode_flags(StringValuePtr(nmode));
}
if (fptr->path) {
@@ -3670,7 +3655,7 @@ rb_io_reopen(argc, argv, file)
fptr->path = 0;
}
- fptr->path = strdup(StringValueCStr(fname));
+ fptr->path = strdup(RSTRING(fname)->ptr);
mode = rb_io_flags_mode(fptr->mode);
if (!fptr->f) {
fptr->f = rb_fopen(fptr->path, mode);
@@ -3681,16 +3666,16 @@ rb_io_reopen(argc, argv, file)
return file;
}
- if (freopen(fptr->path, mode, fptr->f) == 0) {
+ if (freopen(RSTRING(fname)->ptr, mode, fptr->f) == 0) {
rb_sys_fail(fptr->path);
}
#ifdef USE_SETVBUF
if (setvbuf(fptr->f, NULL, _IOFBF, 0) != 0)
- rb_warn("setvbuf() can't be honoured for %s", fptr->path);
+ rb_warn("setvbuf() can't be honoured for %s", RSTRING(fname)->ptr);
#endif
if (fptr->f2) {
- if (freopen(fptr->path, "w", fptr->f2) == 0) {
+ if (freopen(RSTRING(fname)->ptr, "w", fptr->f2) == 0) {
rb_sys_fail(fptr->path);
}
}
@@ -4239,7 +4224,7 @@ rb_io_initialize(argc, argv, io)
}
else {
SafeStringValue(mode);
- flags = rb_io_mode_modenum(StringValueCStr(mode));
+ flags = rb_io_mode_modenum(RSTRING(mode)->ptr);
}
}
else {
@@ -4409,7 +4394,7 @@ next_argv()
retry:
if (RARRAY(rb_argv)->len > 0) {
filename = rb_ary_shift(rb_argv);
- fn = StringValueCStr(filename);
+ fn = StringValuePtr(filename);
if (strlen(fn) == 1 && fn[0] == '-') {
current_file = rb_stdin;
if (ruby_inplace_mode) {
@@ -5070,7 +5055,7 @@ rb_f_syscall(argc, argv)
if (!NIL_P(v)) {
StringValue(v);
rb_str_modify(v);
- arg[i] = (unsigned long)StringValueCStr(v);
+ arg[i] = (unsigned long)RSTRING(v)->ptr;
}
else {
arg[i] = (unsigned long)NUM2LONG(*argv);
@@ -5278,7 +5263,7 @@ rb_io_s_foreach(argc, argv)
else if (!NIL_P(arg.sep)) {
StringValue(arg.sep);
}
- arg.io = rb_io_open(StringValueCStr(fname), "r");
+ arg.io = rb_io_open(RSTRING(fname)->ptr, "r");
if (NIL_P(arg.io)) return Qnil;
return rb_ensure(io_s_foreach, (VALUE)&arg, rb_io_close, arg.io);
@@ -5317,7 +5302,7 @@ rb_io_s_readlines(argc, argv, io)
SafeStringValue(fname);
arg.argc = argc - 1;
- arg.io = rb_io_open(StringValueCStr(fname), "r");
+ arg.io = rb_io_open(RSTRING(fname)->ptr, "r");
if (NIL_P(arg.io)) return Qnil;
return rb_ensure(io_s_readlines, (VALUE)&arg, rb_io_close, arg.io);
}
@@ -5355,7 +5340,7 @@ rb_io_s_read(argc, argv, io)
SafeStringValue(fname);
arg.argc = argc ? 1 : 0;
- arg.io = rb_io_open(StringValueCStr(fname), "r");
+ arg.io = rb_io_open(RSTRING(fname)->ptr, "r");
if (NIL_P(arg.io)) return Qnil;
if (!NIL_P(offset)) {
rb_io_seek(arg.io, offset, SEEK_SET);
@@ -5631,7 +5616,7 @@ opt_i_set(val)
StringValue(val);
if (ruby_inplace_mode) free(ruby_inplace_mode);
ruby_inplace_mode = 0;
- ruby_inplace_mode = strdup(StringValueCStr(val));
+ ruby_inplace_mode = strdup(RSTRING(val)->ptr);
}
/*
diff --git a/lib/README b/lib/README
index d60c5cb1e9..19d6309166 100644
--- a/lib/README
+++ b/lib/README
@@ -6,7 +6,7 @@ benchmark.rb a benchmark utility
cgi-lib.rb simple CGI support library (old style)
cgi.rb CGI support library
cgi/session.rb CGI session class
-complex.rb complex number support
+complex.rb complex number suppor
csv.rb CSV parser/generator
date.rb date object
date/format.rb date parsing and formatting
diff --git a/lib/base64.rb b/lib/base64.rb
index 8628d611b2..05be9ddf78 100644
--- a/lib/base64.rb
+++ b/lib/base64.rb
@@ -110,7 +110,7 @@ module Base64
# UnVieQ==
def b64encode(bin, len = 60)
- encode64(bin).scan(/.{1,#{len}}/) do
+ encode64(bin).scan(/.{1,#{len}}/o) do
print $&, "\n"
end
end
diff --git a/lib/benchmark.rb b/lib/benchmark.rb
index 6ab0755613..36e593518f 100644
--- a/lib/benchmark.rb
+++ b/lib/benchmark.rb
@@ -304,10 +304,7 @@ module Benchmark
# Returns the elapsed real time used to execute the given block.
#
def realtime(&blk) # :yield:
- r0 = Time.now
- yield
- r1 = Time.now
- r1.to_f - r0.to_f
+ Benchmark::measure(&blk).real
end
@@ -333,7 +330,7 @@ module Benchmark
# Registers the given label and block pair in the job list.
#
def item(label = "", &blk) # :yield:
- raise ArgumentError, "no block" unless block_given?
+ raise ArgmentError, "no block" unless block_given?
label.concat ' '
w = label.length
@width = w if @width < w
diff --git a/lib/cgi.rb b/lib/cgi.rb
index bf64d5a54c..0c27f1f33a 100644
--- a/lib/cgi.rb
+++ b/lib/cgi.rb
@@ -1032,13 +1032,13 @@ class CGI
if "--" == $2
content_length = -1
end
- boundary_end = $2.dup
+ boundary_end = $2.dup
""
end
body.rewind
- /Content-Disposition:.* filename=(?:"((?:\\.|[^\"])*)"|([^;\s]*))/ni.match(head)
+ /Content-Disposition:.* filename=(?:"((?:\\.|[^\"])*)"|([^;]*))/ni.match(head)
filename = ($1 or $2 or "")
if /Mac/ni.match(env_table['HTTP_USER_AGENT']) and
/Mozilla/ni.match(env_table['HTTP_USER_AGENT']) and
@@ -1046,7 +1046,7 @@ class CGI
filename = CGI::unescape(filename)
end
- /Content-Type: ([^\s]*)/ni.match(head)
+ /Content-Type: (.*)/ni.match(head)
content_type = ($1 or "")
(class << body; self; end).class_eval do
@@ -1055,7 +1055,7 @@ class CGI
define_method(:content_type) {content_type.dup.taint}
end
- /Content-Disposition:.* name="?([^\";\s]*)"?/ni.match(head)
+ /Content-Disposition:.* name="?([^\";]*)"?/ni.match(head)
name = $1.dup
if params.has_key?(name)
@@ -1163,7 +1163,6 @@ class CGI
# retrieved; use #params() to get the array of values.
def [](key)
params = @params[key]
- return '' unless params
value = params[0]
if @multipart
if value
diff --git a/lib/cgi/session.rb b/lib/cgi/session.rb
index c148bf248a..82eb7534d8 100644
--- a/lib/cgi/session.rb
+++ b/lib/cgi/session.rb
@@ -182,6 +182,7 @@ class CGI
md5.update(String(rand(0)))
md5.update(String($$))
md5.update('foobar')
+ @new_session = true
md5.hexdigest
end
private :create_new_id
@@ -249,7 +250,6 @@ class CGI
unless session_id
if option['new_session']
session_id = create_new_id
- @new_session = true
end
end
unless session_id
@@ -265,7 +265,6 @@ class CGI
raise ArgumentError, "session_key `%s' should be supplied"%session_key
end
session_id = create_new_id
- @new_session = true
end
end
@session_id = session_id
@@ -276,8 +275,7 @@ class CGI
unless option.fetch('new_session', true)
raise ArgumentError, "invalid session_id `%s'"%session_id
end
- session_id = @session_id = create_new_id unless session_id
- @new_session = true
+ session_id = @session_id = create_new_id
retry
end
request.instance_eval do
@@ -393,9 +391,8 @@ class CGI
unless @hash
@hash = {}
begin
- lockf = File.open(@path+".lock", "r")
- lockf.flock File::LOCK_SH
f = File.open(@path, 'r')
+ f.flock File::LOCK_SH
for line in f
line.chomp!
k, v = line.split('=',2)
@@ -403,7 +400,6 @@ class CGI
end
ensure
f.close unless f.nil?
- lockf.close if lockf
end
end
@hash
@@ -413,17 +409,13 @@ class CGI
def update
return unless @hash
begin
- lockf = File.open(@path+".lock", File::CREAT|File::RDWR, 0600)
- lockf.flock File::LOCK_EX
- f = File.open(@path+".new", File::CREAT|File::TRUNC|File::WRONLY, 0600)
+ f = File.open(@path, File::CREAT|File::TRUNC|File::RDWR, 0600)
+ f.flock File::LOCK_EX
for k,v in @hash
f.printf "%s=%s\n", CGI::escape(k), CGI::escape(String(v))
end
- f.close
- File.rename @path+".new", @path
ensure
- f.close if f and !f.closed?
- lockf.close if lockf
+ f.close unless f.nil?
end
end
@@ -434,8 +426,6 @@ class CGI
# Close and delete the session's FileStore file.
def delete
- File::unlink @path+".lock" rescue nil
- File::unlink @path+".new" rescue nil
File::unlink @path
rescue Errno::ENOENT
end
diff --git a/lib/date.rb b/lib/date.rb
index ea557313f7..6da4d6aa8e 100644
--- a/lib/date.rb
+++ b/lib/date.rb
@@ -6,7 +6,7 @@
# Documentation: William Webber <william@williamwebber.com>
#
#--
-# $Id: date.rb,v 2.33 2007-12-22 14:41:34+09 tadf Exp $
+# $Id: date.rb,v 2.30 2006-12-30 21:43:41+09 tadf Exp $
#++
#
# == Overview
@@ -250,7 +250,7 @@ class Date
ABBR_DAYNAMES = %w(Sun Mon Tue Wed Thu Fri Sat)
[MONTHNAMES, DAYNAMES, ABBR_MONTHNAMES, ABBR_DAYNAMES].each do |xs|
- xs.each{|x| x.freeze unless x.nil?}.freeze
+ xs.each{|x| x.freeze}.freeze
end
class Infinity < Numeric # :nodoc:
@@ -275,8 +275,8 @@ class Date
def <=> (other)
case other
- when Infinity; return d <=> other.d
- when Numeric; return d
+ when Infinity; d <=> other.d
+ when Numeric; d
else
begin
l, r = other.coerce(self)
@@ -1619,23 +1619,12 @@ class Date
# Create a new Date object representing today.
#
# +sg+ specifies the Day of Calendar Reform.
- def self.today(sg=ITALY)
- t = Time.now
- jd = civil_to_jd(t.year, t.mon, t.mday, sg)
- new!(jd_to_ajd(jd, 0, 0), 0, sg)
- end
+ def self.today(sg=ITALY) Time.now.__send__(:to_date) .new_start(sg) end
# Create a new DateTime object representing the current time.
#
# +sg+ specifies the Day of Calendar Reform.
- def self.now(sg=ITALY)
- t = Time.now
- jd = civil_to_jd(t.year, t.mon, t.mday, sg)
- fr = time_to_day_fraction(t.hour, t.min, [t.sec, 59].min) +
- Rational(t.usec, 86400_000_000)
- of = Rational(t.utc_offset, 86400)
- new!(jd_to_ajd(jd, fr, of), of, sg)
- end
+ def self.now (sg=ITALY) Time.now.__send__(:to_datetime).new_start(sg) end
private_class_method :now
diff --git a/lib/date/format.rb b/lib/date/format.rb
index 6b082af40b..8bd14c7fd0 100644
--- a/lib/date/format.rb
+++ b/lib/date/format.rb
@@ -239,12 +239,12 @@ class Date
when 'j'; emit_n(yday, 3, f)
when 'k'; emit_a(hour, 2, f)
when 'L'
- emit_n((sec_fraction / (1.to_r/86400/(10**3))).floor, 3, f)
+ emit_n((sec_fraction / (1.to_r/86400/(10**3))).round, 3, f)
when 'l'; emit_a((hour % 12).nonzero? || 12, 2, f)
when 'M'; emit_n(min, 2, f)
when 'm'; emit_n(mon, 2, f)
when 'N'
- emit_n((sec_fraction / (1.to_r/86400/(10**9))).floor, 9, f)
+ emit_n((sec_fraction / (1.to_r/86400/(10**9))).round, 9, f)
when 'n'; "\n"
when 'P'; emit_ad(strftime('%p').downcase, 0, f)
when 'p'; emit_au(if hour < 12 then 'AM' else 'PM' end, 0, f)
diff --git a/lib/delegate.rb b/lib/delegate.rb
index ee5fe8d7fe..d810ccad42 100644
--- a/lib/delegate.rb
+++ b/lib/delegate.rb
@@ -164,9 +164,9 @@ class Delegator
# Checks for a method provided by this the delegate object by fowarding the
# call through \_\_getobj\_\_.
#
- def respond_to?(m, include_private = false)
+ def respond_to?(m)
return true if super
- return self.__getobj__.respond_to?(m, include_private)
+ return self.__getobj__.respond_to?(m)
end
#
@@ -228,15 +228,13 @@ class SimpleDelegator<Delegator
# Clone support for the object returned by \_\_getobj\_\_.
def clone
- new = super
- new.__setobj__(__getobj__.clone)
- new
+ super
+ __setobj__(__getobj__.clone)
end
# Duplication support for the object returned by \_\_getobj\_\_.
- def dup
- new = super
- new.__setobj__(__getobj__.clone)
- new
+ def dup(obj)
+ super
+ __setobj__(__getobj__.dup)
end
end
@@ -271,9 +269,9 @@ def DelegateClass(superclass)
end
@_dc_obj.__send__(m, *args)
end
- def respond_to?(m, include_private = false) # :nodoc:
+ def respond_to?(m) # :nodoc:
return true if super
- return @_dc_obj.respond_to?(m, include_private)
+ return @_dc_obj.respond_to?(m)
end
def __getobj__ # :nodoc:
@_dc_obj
@@ -283,14 +281,12 @@ def DelegateClass(superclass)
@_dc_obj = obj
end
def clone # :nodoc:
- new = super
- new.__setobj__(__getobj__.clone)
- new
+ super
+ __setobj__(__getobj__.clone)
end
def dup # :nodoc:
- new = super
- new.__setobj__(__getobj__.clone)
- new
+ super
+ __setobj__(__getobj__.dup)
end
}
for method in methods
diff --git a/lib/drb/drb.rb b/lib/drb/drb.rb
index cec279fd1b..25fbb3f788 100644
--- a/lib/drb/drb.rb
+++ b/lib/drb/drb.rb
@@ -1201,7 +1201,6 @@ module DRb
end
def alive? # :nodoc:
- return false unless @protocol
@protocol.alive?
end
end
diff --git a/lib/erb.rb b/lib/erb.rb
index d111e8f999..b714aa1ea6 100644
--- a/lib/erb.rb
+++ b/lib/erb.rb
@@ -365,22 +365,21 @@ class ERB
end
end
+ ExplicitTrimRegexp = /(^[ \t]*<%-)|(-%>\n?\z)|(<%-)|(-%>)|(<%%)|(%%>)|(<%=)|(<%#)|(<%)|(%>)|(\n)/
def explicit_trim_line(line)
- line.scan(/(.*?)(^[ \t]*<%\-|<%\-|<%%|%%>|<%=|<%#|<%|-%>\n|-%>|%>|\z)/m) do |tokens|
- tokens.each do |token|
- next if token.empty?
- if @stag.nil? && /[ \t]*<%-/ =~ token
- yield('<%')
- elsif @stag && token == "-%>\n"
- yield('%>')
- yield(:cr)
- elsif @stag && token == '-%>'
- yield('%>')
- else
- yield(token)
- end
- end
- end
+ line.split(ExplicitTrimRegexp).each do |token|
+ next if token.empty?
+ if @stag.nil? && /[ \t]*<%-/ =~ token
+ yield('<%')
+ elsif @stag && /-%>\n/ =~ token
+ yield('%>')
+ yield(:cr)
+ elsif @stag && token == '-%>'
+ yield('%>')
+ else
+ yield(token)
+ end
+ end
end
ERB_STAG = %w(<%= <%# <%)
@@ -422,6 +421,34 @@ class ERB
end
Scanner.regist_scanner(SimpleScanner2, nil, false)
+ class PercentScanner < Scanner # :nodoc:
+ def scan
+ new_line = true
+ stag_reg = /(.*?)(<%%|<%=|<%#|<%|\n|\z)/
+ etag_reg = /(.*?)(%%>|%>|\n|\z)/
+ scanner = StringScanner.new(@src)
+ while ! scanner.eos?
+ if new_line && @stag.nil?
+ if scanner.scan(/%%/)
+ yield('%')
+ new_line = false
+ next
+ elsif scanner.scan(/%/)
+ yield(PercentLine.new(scanner.scan(/.*?(\n|\z)/).chomp))
+ next
+ end
+ end
+ scanner.scan(@stag ? etag_reg : stag_reg)
+ text = scanner[1]
+ elem = scanner[2]
+ yield(text) unless text.empty?
+ yield(elem) unless elem.empty?
+ new_line = (elem == "\n")
+ end
+ end
+ end
+ Scanner.regist_scanner(PercentScanner, nil, true)
+
class ExplicitScanner < Scanner # :nodoc:
def scan
new_line = true
diff --git a/lib/ipaddr.rb b/lib/ipaddr.rb
index 1801d9d86f..17e47f016f 100644
--- a/lib/ipaddr.rb
+++ b/lib/ipaddr.rb
@@ -438,7 +438,7 @@ class IPAddr
if prefixlen
mask!(prefixlen)
else
- @mask_addr = (@family == Socket::AF_INET) ? IN4MASK : IN6MASK
+ @mask_addr = (family == Socket::AF_INET) ? IN4MASK : IN6MASK
end
end
diff --git a/lib/irb.rb b/lib/irb.rb
index 7580e39d43..1fb4397e68 100644
--- a/lib/irb.rb
+++ b/lib/irb.rb
@@ -149,15 +149,10 @@ module IRB
line.untaint
@context.evaluate(line, line_no)
output_value if @context.echo?
- exc = nil
- rescue Interrupt => exc
- rescue SystemExit, SignalException
- raise
- rescue Exception => exc
- end
- if exc
- print exc.class, ": ", exc, "\n"
- if exc.backtrace[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/
+ rescue StandardError, ScriptError, Abort
+ $! = RuntimeError.new("unknown exception raised") unless $!
+ print $!.class, ": ", $!, "\n"
+ if $@[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && $!.class.to_s !~ /^IRB/
irb_bug = true
else
irb_bug = false
@@ -166,7 +161,7 @@ module IRB
messages = []
lasts = []
levels = 0
- for m in exc.backtrace
+ for m in $@
m = @context.workspace.filter_backtrace(m) unless irb_bug
if m
if messages.size < @context.back_trace_limit
@@ -188,7 +183,8 @@ module IRB
print "Maybe IRB bug!!\n" if irb_bug
end
if $SAFE > 2
- abort "Error: irb does not work for $SAFE level higher than 2"
+ warn "Error: irb does not work for $SAFE level higher than 2"
+ exit 1
end
end
end
diff --git a/lib/logger.rb b/lib/logger.rb
index e9ab171cee..60e72424ad 100644
--- a/lib/logger.rb
+++ b/lib/logger.rb
@@ -170,8 +170,8 @@ require 'monitor'
class Logger
VERSION = "1.2.6"
- id, name, rev = %w$Id$
- ProgName = "#{name.chomp(",v")}/#{rev}"
+ /: (\S+),v (\S+)/ =~ %q$Id$
+ ProgName = "#{$1}/#{$2}"
class Error < RuntimeError; end
class ShiftingError < Error; end
diff --git a/lib/matrix.rb b/lib/matrix.rb
index c4fa8cefda..c62acdf9aa 100644
--- a/lib/matrix.rb
+++ b/lib/matrix.rb
@@ -1081,7 +1081,7 @@ class Vector
other.compare_by(@elements)
end
- alias eql? ==
+ alias eqn? ==
#
# For internal use.
diff --git a/lib/mkmf.rb b/lib/mkmf.rb
index de8dee1056..c4e4c04dae 100644
--- a/lib/mkmf.rb
+++ b/lib/mkmf.rb
@@ -266,7 +266,8 @@ ensure
end
def link_command(ldflags, opt="", libpath=$DEFLIBPATH|$LIBPATH)
- conf = Config::CONFIG.merge('hdrdir' => $hdrdir.quote,
+ Config::expand(TRY_LINK.dup,
+ CONFIG.merge('hdrdir' => $hdrdir.quote,
'src' => CONFTEST_C,
'INCFLAGS' => $INCFLAGS,
'CPPFLAGS' => $CPPFLAGS,
@@ -275,30 +276,22 @@ def link_command(ldflags, opt="", libpath=$DEFLIBPATH|$LIBPATH)
'LDFLAGS' => "#$LDFLAGS #{ldflags}",
'LIBPATH' => libpathflag(libpath),
'LOCAL_LIBS' => "#$LOCAL_LIBS #$libs",
- 'LIBS' => "#$LIBRUBYARG_STATIC #{opt} #$LIBS")
- Config::expand(TRY_LINK.dup, conf)
+ 'LIBS' => "#$LIBRUBYARG_STATIC #{opt} #$LIBS"))
end
def cc_command(opt="")
- conf = Config::CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote)
Config::expand("$(CC) #$INCFLAGS #$CPPFLAGS #$CFLAGS #$ARCH_FLAG #{opt} -c #{CONFTEST_C}",
- conf)
+ CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote))
end
def cpp_command(outfile, opt="")
- conf = Config::CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote)
Config::expand("$(CPP) #$INCFLAGS #$CPPFLAGS #$CFLAGS #{opt} #{CONFTEST_C} #{outfile}",
- conf)
+ CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote))
end
def libpathflag(libpath=$DEFLIBPATH|$LIBPATH)
libpath.map{|x|
- case x
- when "$(topdir)", /\A\./
- LIBPATHFLAG
- else
- LIBPATHFLAG+RPATHFLAG
- end % x.quote
+ (x == "$(topdir)" ? LIBPATHFLAG : LIBPATHFLAG+RPATHFLAG) % x.quote
}.join
end
@@ -438,7 +431,7 @@ def try_var(var, headers = nil, &b)
#{headers}
/*top*/
int main() { return 0; }
-int t() { const volatile void *volatile p; p = &(&#{var})[0]; return 0; }
+int t() { const volatile void *volatile p; p = (void *)&#{var}; return 0; }
SRC
end
@@ -1054,9 +1047,6 @@ topdir = #{($extmk ? CONFIG["topdir"] : $topdir).quote}
hdrdir = #{$extmk ? CONFIG["hdrdir"].quote : '$(topdir)'}
VPATH = #{vpath.join(CONFIG['PATH_SEPARATOR'])}
}
- if $extmk
- mk << "RUBYLIB = -\nRUBYOPT = -rpurelib.rb\n"
- end
if destdir = CONFIG["prefix"][$dest_prefix_pattern, 1]
mk << "\nDESTDIR = #{destdir}\n"
end
@@ -1086,7 +1076,6 @@ LIBRUBYARG_STATIC = #$LIBRUBYARG_STATIC
RUBY_EXTCONF_H = #{$extconf_h}
CFLAGS = #{$static ? '' : CONFIG['CCDLFLAGS']} #$CFLAGS #$ARCH_FLAG
INCFLAGS = -I. #$INCFLAGS
-DEFS = #{CONFIG['DEFS']}
CPPFLAGS = #{extconf_h}#{$CPPFLAGS}
CXXFLAGS = $(CFLAGS) #{CONFIG['CXXFLAGS']}
DLDFLAGS = #$LDFLAGS #$DLDFLAGS #$ARCH_FLAG
@@ -1333,9 +1322,7 @@ site-install-rb: install-rb
end
mfile.print "$(RUBYARCHDIR)/" if $extout
- mfile.print "$(DLLIB): "
- mfile.print "$(DEFFILE) " if makedef
- mfile.print "$(OBJS) Makefile\n"
+ mfile.print "$(DLLIB): ", (makedef ? "$(DEFFILE) " : ""), "$(OBJS)\n"
mfile.print "\t@-$(RM) $@\n"
mfile.print "\t@-$(MAKEDIRS) $(@D)\n" if $extout
link_so = LINK_SO.gsub(/^/, "\t")
@@ -1403,7 +1390,6 @@ site-install-rb: install-rb
unless suffixes.empty?
mfile.print ".SUFFIXES: .", suffixes.uniq.join(" ."), "\n\n"
end
- mfile.print "$(OBJS): $(RUBY_EXTCONF_H)\n\n" if $extconf_h
mfile.print depout
else
headers = %w[ruby.h defines.h]
@@ -1439,7 +1425,6 @@ def init_mkmf(config = CONFIG)
$LIBRUBYARG_STATIC = config['LIBRUBYARG_STATIC']
$LIBRUBYARG_SHARED = config['LIBRUBYARG_SHARED']
$DEFLIBPATH = $extmk ? ["$(topdir)"] : CROSS_COMPILING ? [] : ["$(libdir)"]
- $DEFLIBPATH.unshift(".")
$LIBPATH = []
$INSTALLFILES = nil
@@ -1453,7 +1438,6 @@ def init_mkmf(config = CONFIG)
$LOCAL_LIBS = ""
$cleanfiles = config_string('CLEANFILES') {|s| Shellwords.shellwords(s)} || []
- $cleanfiles << "mkmf.log"
$distcleanfiles = config_string('DISTCLEANFILES') {|s| Shellwords.shellwords(s)} || []
$extout ||= nil
@@ -1532,8 +1516,8 @@ LINK_SO = config_string('LINK_SO') ||
if CONFIG["DLEXT"] == $OBJEXT
"ld $(DLDFLAGS) -r -o $@ $(OBJS)\n"
else
- "$(LDSHARED) #{OUTFLAG}$@ $(OBJS) " \
- "$(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)"
+ "$(LDSHARED) $(DLDFLAGS) $(LIBPATH) #{OUTFLAG}$@ " \
+ "$(OBJS) $(LOCAL_LIBS) $(LIBS)"
end
LIBPATHFLAG = config_string('LIBPATHFLAG') || ' -L"%s"'
RPATHFLAG = config_string('RPATHFLAG') || ''
diff --git a/lib/monitor.rb b/lib/monitor.rb
index 4c146c8086..4ed4e41222 100644
--- a/lib/monitor.rb
+++ b/lib/monitor.rb
@@ -105,17 +105,14 @@ module MonitorMixin
return false
ensure
Thread.critical = true
- begin
- if timer && timer.alive?
- Thread.kill(timer)
- end
- if @waiters.include?(Thread.current) # interrupted?
- @waiters.delete(Thread.current)
- end
- @monitor.instance_eval {mon_enter_for_cond(count)}
- ensure
- Thread.critical = false
+ if timer && timer.alive?
+ Thread.kill(timer)
end
+ if @waiters.include?(Thread.current) # interrupted?
+ @waiters.delete(Thread.current)
+ end
+ @monitor.instance_eval {mon_enter_for_cond(count)}
+ Thread.critical = false
end
end
@@ -213,7 +210,6 @@ module MonitorMixin
Thread.critical = true
mon_acquire(@mon_entering_queue)
@mon_count += 1
- ensure
Thread.critical = false
end
@@ -303,9 +299,8 @@ module MonitorMixin
def mon_exit_for_cond
count = @mon_count
@mon_count = 0
- return count
- ensure
mon_release
+ return count
end
end
diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb
index 40e553e80e..dfbcf1499f 100644
--- a/lib/net/ftp.rb
+++ b/lib/net/ftp.rb
@@ -152,9 +152,9 @@ module Net
end
def open_socket(host, port)
- if defined? SOCKSSocket and ENV["SOCKS_SERVER"]
+ if defined? SOCKSsocket and ENV["SOCKS_SERVER"]
@passive = true
- return SOCKSSocket.open(host, port)
+ return SOCKSsocket.open(host, port)
else
return TCPSocket.open(host, port)
end
@@ -278,9 +278,12 @@ module Net
def sendport(host, port)
af = (@sock.peeraddr)[0]
if af == "AF_INET"
- cmd = "PORT " + (host.split(".") + port.divmod(256)).join(",")
+ hbytes = host.split(".")
+ pbytes = [port / 256, port % 256]
+ bytes = hbytes + pbytes
+ cmd = "PORT " + bytes.join(",")
elsif af == "AF_INET6"
- cmd = sprintf("EPRT |2|%s|%d|", host, port)
+ cmd = "EPRT |2|" + host + "|" + sprintf("%d", port) + "|"
else
raise FTPProtoError, host
end
@@ -374,11 +377,9 @@ module Net
synchronize do
resp = sendcmd('USER ' + user)
if resp[0] == ?3
- raise FTPReplyError, resp if passwd.nil?
resp = sendcmd('PASS ' + passwd)
end
if resp[0] == ?3
- raise FTPReplyError, resp if acct.nil?
resp = sendcmd('ACCT ' + acct)
end
end
@@ -666,9 +667,9 @@ module Net
begin
voidcmd("CDUP")
return
- rescue FTPPermError => e
- if e.message[0, 3] != "500"
- raise e
+ rescue FTPPermError
+ if $![0, 3] != "500"
+ raise FTPPermError, $!
end
end
end
diff --git a/lib/net/http.rb b/lib/net/http.rb
index 7dd1f24d4c..46d95b27b4 100644
--- a/lib/net/http.rb
+++ b/lib/net/http.rb
@@ -584,9 +584,6 @@ module Net #:nodoc:
HTTPResponse.read_new(@socket).value
end
s.connect
- if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE
- s.post_connection_check(@address)
- end
end
on_connect
end
diff --git a/lib/net/imap.rb b/lib/net/imap.rb
index 6162ffa0d0..547e23e618 100644
--- a/lib/net/imap.rb
+++ b/lib/net/imap.rb
@@ -284,13 +284,7 @@ module Net
# Disconnects from the server.
def disconnect
- begin
- # try to call SSL::SSLSocket#io.
- @sock.io.shutdown
- rescue NoMethodError
- # @sock is not an SSL::SSLSocket.
- @sock.shutdown
- end
+ @sock.shutdown unless @usessl
@receiver_thread.join
@sock.close
end
@@ -902,7 +896,6 @@ module Net
end
@sock = SSLSocket.new(@sock, context)
@sock.connect # start ssl session.
- @sock.post_connection_check(@host) if verify
else
@usessl = false
end
@@ -3062,7 +3055,7 @@ module Net
elsif $7
return Token.new(T_RPAR, $+)
else
- parse_error("[Net::IMAP BUG] DATA_REGEXP is invalid")
+ parse_error("[Net::IMAP BUG] BEG_REGEXP is invalid")
end
else
@str.index(/\S*/n, @pos)
@@ -3116,7 +3109,7 @@ module Net
$stderr.printf("@str: %s\n", @str.dump)
$stderr.printf("@pos: %d\n", @pos)
$stderr.printf("@lex_state: %s\n", @lex_state)
- if @token
+ if @token.symbol
$stderr.printf("@token.symbol: %s\n", @token.symbol)
$stderr.printf("@token.value: %s\n", @token.value.inspect)
end
diff --git a/lib/net/pop.rb b/lib/net/pop.rb
index f896464df9..2ecbcbdf28 100644
--- a/lib/net/pop.rb
+++ b/lib/net/pop.rb
@@ -462,8 +462,6 @@ module Net
def do_finish
@mails = nil
- @n_mails = nil
- @n_bytes = nil
@command.quit if @command
ensure
@started = false
@@ -752,7 +750,7 @@ module Net
@socket = sock
@error_occured = false
res = check_response(critical { recv_response() })
- @apop_stamp = res.slice(/<[!-~]+@[!-~]+>/)
+ @apop_stamp = res.slice(/<.+>/)
end
def inspect
diff --git a/lib/net/smtp.rb b/lib/net/smtp.rb
index a4a2c52d58..dda9dab072 100644
--- a/lib/net/smtp.rb
+++ b/lib/net/smtp.rb
@@ -309,9 +309,10 @@ module Net
# * IOError
# * TimeoutError
#
- def SMTP.start(address, port = nil, helo = 'localhost.localdomain',
- user = nil, secret = nil, authtype = nil,
- &block) # :yield: smtp
+ def SMTP.start( address, port = nil,
+ helo = 'localhost.localdomain',
+ user = nil, secret = nil, authtype = nil,
+ &block) # :yield: smtp
new(address, port).start(helo, user, secret, authtype, &block)
end
@@ -370,8 +371,8 @@ module Net
# * IOError
# * TimeoutError
#
- def start(helo = 'localhost.localdomain',
- user = nil, secret = nil, authtype = nil) # :yield: smtp
+ def start( helo = 'localhost.localdomain',
+ user = nil, secret = nil, authtype = nil ) # :yield: smtp
if block_given?
begin
do_start(helo, user, secret, authtype)
diff --git a/lib/net/telnet.rb b/lib/net/telnet.rb
index a55527f15e..c5f8b0429a 100644
--- a/lib/net/telnet.rb
+++ b/lib/net/telnet.rb
@@ -559,8 +559,7 @@ module Net
Integer(c.rindex(/#{IAC}#{SB}/no))
buf = preprocess(c[0 ... c.rindex(/#{IAC}#{SB}/no)])
rest = c[c.rindex(/#{IAC}#{SB}/no) .. -1]
- elsif pt = c.rindex(/#{IAC}[^#{IAC}#{AO}#{AYT}#{DM}#{IP}#{NOP}]?\z/no) ||
- c.rindex(/\r\z/no)
+ elsif pt = c.rindex(/#{IAC}[^#{IAC}#{AO}#{AYT}#{DM}#{IP}#{NOP}]?\z/no)
buf = preprocess(c[0 ... pt])
rest = c[pt .. -1]
else
@@ -572,15 +571,9 @@ module Net
#
# We cannot use preprocess() on this data, because that
# method makes some Telnetmode-specific assumptions.
- buf = rest + c
+ buf = c
+ buf.gsub!(/#{EOL}/no, "\n") unless @options["Binmode"]
rest = ''
- unless @options["Binmode"]
- if pt = buf.rindex(/\r\z/no)
- buf = buf[0 ... pt]
- rest = buf[pt .. -1]
- end
- buf.gsub!(/#{EOL}/no, "\n")
- end
end
@log.print(buf) if @options.has_key?("Output_log")
line += buf
@@ -712,7 +705,7 @@ module Net
# data is also yielded to the block as it is received.
def login(options, password = nil) # :yield: recvdata
login_prompt = /[Ll]ogin[: ]*\z/n
- password_prompt = /[Pp]ass(?:word|phrase)[: ]*\z/n
+ password_prompt = /Password[: ]*\z/n
if options.kind_of?(Hash)
username = options["Name"]
password = options["Password"]
diff --git a/lib/open-uri.rb b/lib/open-uri.rb
index 0dae95b6e6..d69f7dbe41 100644
--- a/lib/open-uri.rb
+++ b/lib/open-uri.rb
@@ -240,6 +240,16 @@ module OpenURI
resp = nil
http.start {
+ if target.class == URI::HTTPS
+ # xxx: information hiding violation
+ sock = http.instance_variable_get(:@socket)
+ if sock.respond_to?(:io)
+ sock = sock.io # 1.9
+ else
+ sock = sock.instance_variable_get(:@socket) # 1.8
+ end
+ sock.post_connection_check(target_host)
+ end
req = Net::HTTP::Get.new(request_uri, header)
if options.include? :http_basic_authentication
user, pass = options[:http_basic_authentication]
diff --git a/lib/optparse.rb b/lib/optparse.rb
index d4500266d5..2c91cd004f 100644
--- a/lib/optparse.rb
+++ b/lib/optparse.rb
@@ -379,7 +379,7 @@ class OptionParser
while s = lopts.shift
l = left[-1].length + s.length
l += arg.length if left.size == 1 && arg
- l < max or sopts.empty? or left << ''
+ l < max or left << ''
left[-1] << if left[-1].empty? then ' ' * 4 else ', ' end << s
end
@@ -630,19 +630,15 @@ class OptionParser
# method which is called on every option.
#
def summarize(*args, &block)
- sum = []
- list.reverse_each do |opt|
+ list.each do |opt|
if opt.respond_to?(:summarize) # perhaps OptionParser::Switch
- s = []
- opt.summarize(*args) {|l| s << l}
- sum.concat(s.reverse)
+ opt.summarize(*args, &block)
elsif !opt or opt.empty?
- sum << ""
+ yield("")
else
- sum.concat(opt.to_a.reverse)
+ opt.each(&block)
end
end
- sum.reverse_each(&block)
end
def add_banner(to) # :nodoc:
@@ -964,8 +960,7 @@ class OptionParser
# +indent+:: Indentation, defaults to @summary_indent.
#
def summarize(to = [], width = @summary_width, max = width - 1, indent = @summary_indent, &blk)
- blk ||= proc {|l| to << (l.index($/, -1) ? l : l + $/)}
- visit(:summarize, {}, {}, width, max, indent, &blk)
+ visit(:summarize, {}, {}, width, max, indent, &(blk || proc {|l| to << l + $/}))
to
end
@@ -1479,7 +1474,6 @@ class OptionParser
#
def environment(env = File.basename($0, '.*'))
env = ENV[env] || ENV[env.upcase] or return
- require 'shellwords'
parse(*Shellwords.shellwords(env))
end
diff --git a/lib/rdoc/options.rb b/lib/rdoc/options.rb
index bea7e6bdcd..4dfe45169c 100644
--- a/lib/rdoc/options.rb
+++ b/lib/rdoc/options.rb
@@ -550,12 +550,12 @@ class Options
ver = nil
IO.popen("dot -V 2>&1") do |io|
ver = io.read
- if ver =~ /dot.+version(?:\s+gviz)?\s+(\d+)\.(\d+)/
+ if ver =~ /dot\s+version(?:\s+gviz)?\s+(\d+)\.(\d+)/
ok = ($1.to_i > 1) || ($1.to_i == 1 && $2.to_i >= 8)
end
end
unless ok
- if ver =~ /^dot.+version/
+ if ver =~ /^dot version/
$stderr.puts "Warning: You may need dot V1.8.6 or later to use\n",
"the --diagram option correctly. You have:\n\n ",
ver,
diff --git a/lib/rdoc/parsers/parse_c.rb b/lib/rdoc/parsers/parse_c.rb
index 25fc66af3f..1311c5087d 100644
--- a/lib/rdoc/parsers/parse_c.rb
+++ b/lib/rdoc/parsers/parse_c.rb
@@ -169,7 +169,7 @@ module RDoc
attr_accessor :progress
extend ParserFactory
- parse_files_matching(/\.(?:([CcHh])\1?|c([+xp])\2|y)\z/)
+ parse_files_matching(/\.(c|cc|cpp|CC)$/)
@@known_bodies = {}
diff --git a/lib/rdoc/parsers/parse_rb.rb b/lib/rdoc/parsers/parse_rb.rb
index 750c483c15..58ba06084e 100644
--- a/lib/rdoc/parsers/parse_rb.rb
+++ b/lib/rdoc/parsers/parse_rb.rb
@@ -1546,15 +1546,10 @@ module RDoc
tk = get_tk
while tk.kind_of?(TkCOMMENT)
- if first_line && /\A#!/ =~ tk.text
- skip_tkspace
- tk = get_tk
- elsif first_line && /\A#\s*-\*-/ =~ tk.text
- first_line = false
+ if first_line && tk.text[0,2] == "#!"
skip_tkspace
tk = get_tk
else
- first_line = false
res << tk.text << "\n"
tk = get_tk
if tk.kind_of? TkNL
@@ -1562,6 +1557,7 @@ module RDoc
tk = get_tk
end
end
+ first_line = false
end
unget_tk(tk)
res
diff --git a/lib/resolv-replace.rb b/lib/resolv-replace.rb
index 63d58cea27..5d15b4577c 100644
--- a/lib/resolv-replace.rb
+++ b/lib/resolv-replace.rb
@@ -23,8 +23,7 @@ end
class UDPSocket
alias original_resolv_bind bind
def bind(host, port)
- host = IPSocket.getaddress(host) if host != ""
- original_resolv_bind(host, port)
+ original_resolv_bind(IPSocket.getaddress(host), port)
end
alias original_resolv_connect connect
diff --git a/lib/resolv.rb b/lib/resolv.rb
index 3f79ecc62c..49e40bdf07 100644
--- a/lib/resolv.rb
+++ b/lib/resolv.rb
@@ -194,11 +194,6 @@ require 'fcntl'
require 'timeout'
require 'thread'
-begin
- require 'securerandom'
-rescue LoadError
-end
-
class Resolv
def self.getaddress(name)
DefaultResolver.getaddress(name)
@@ -283,7 +278,7 @@ class Resolv
end
class Hosts
- if /mswin32|mingw|bccwin/ =~ RUBY_PLATFORM
+ if /mswin32|cygwin|mingw|bccwin/ =~ RUBY_PLATFORM
require 'win32/resolv'
DefaultFileName = Win32::Resolv.get_hosts_path
else
@@ -393,6 +388,13 @@ class Resolv
@mutex.synchronize {
unless @initialized
@config.lazy_initialize
+
+ if nameserver = @config.single?
+ @requester = Requester::ConnectedUDP.new(nameserver)
+ else
+ @requester = Requester::UnconnectedUDP.new
+ end
+
@initialized = true
end
}
@@ -402,6 +404,8 @@ class Resolv
def close
@mutex.synchronize {
if @initialized
+ @requester.close if @requester
+ @requester = nil
@initialized = false
end
}
@@ -460,7 +464,7 @@ class Resolv
def each_resource(name, typeclass, &proc)
lazy_initialize
- requester = make_requester
+ q = Queue.new
senders = {}
begin
@config.resolv(name) {|candidate, tout, nameserver|
@@ -469,9 +473,11 @@ class Resolv
msg.add_question(candidate, typeclass)
unless sender = senders[[candidate, nameserver]]
sender = senders[[candidate, nameserver]] =
- requester.sender(msg, candidate, nameserver)
+ @requester.sender(msg, candidate, q, nameserver)
end
- reply, reply_name = requester.request(sender, tout)
+ sender.send
+ reply = reply_name = nil
+ timeout(tout, ResolvTimeout) { reply, reply_name = q.pop }
case reply.rcode
when RCode::NoError
extract_resources(reply, reply_name, typeclass, &proc)
@@ -483,15 +489,7 @@ class Resolv
end
}
ensure
- requester.close
- end
- end
-
- def make_requester # :nodoc:
- if nameserver = @config.single?
- Requester::ConnectedUDP.new(nameserver)
- else
- Requester::UnconnectedUDP.new
+ @requester.delete(q)
end
end
@@ -526,105 +524,45 @@ class Resolv
}
end
- if defined? SecureRandom
- def self.random(arg) # :nodoc:
- begin
- SecureRandom.random_number(arg)
- rescue NotImplementedError
- rand(arg)
- end
- end
- else
- def self.random(arg) # :nodoc:
- rand(arg)
- end
- end
-
- def self.rangerand(range) # :nodoc:
- base = range.begin
- len = range.end - range.begin
- if !range.exclude_end?
- len += 1
- end
- base + random(len)
- end
-
- RequestID = {}
- RequestIDMutex = Mutex.new
-
- def self.allocate_request_id(host, port) # :nodoc:
- id = nil
- RequestIDMutex.synchronize {
- h = (RequestID[[host, port]] ||= {})
- begin
- id = rangerand(0x0000..0xffff)
- end while h[id]
- h[id] = true
- }
- id
- end
-
- def self.free_request_id(host, port, id) # :nodoc:
- RequestIDMutex.synchronize {
- key = [host, port]
- if h = RequestID[key]
- h.delete id
- if h.empty?
- RequestID.delete key
- end
- end
- }
- end
-
- def self.bind_random_port(udpsock) # :nodoc:
- begin
- port = rangerand(1024..65535)
- udpsock.bind("", port)
- rescue Errno::EADDRINUSE
- retry
- end
- end
-
class Requester
def initialize
@senders = {}
- @sock = nil
end
- def request(sender, tout)
- timelimit = Time.now + tout
- sender.send
- while (now = Time.now) < timelimit
- timeout = timelimit - now
- if !IO.select([@sock], nil, nil, timeout)
- raise ResolvTimeout
- end
- reply, from = recv_reply
- begin
- msg = Message.decode(reply)
- rescue DecodeError
- next # broken DNS message ignored
- end
- if s = @senders[[from,msg.id]]
- break
- else
- # unexpected DNS message ignored
+ def close
+ thread, sock, @thread, @sock = @thread, @sock
+ begin
+ if thread
+ thread.kill
+ thread.join
end
+ ensure
+ sock.close if sock
end
- return msg, s.data
end
- def close
- sock = @sock
- @sock = nil
- sock.close if sock
+ def delete(arg)
+ case arg
+ when Sender
+ @senders.delete_if {|k, s| s == arg }
+ when Queue
+ @senders.delete_if {|k, s| s.queue == arg }
+ else
+ raise ArgumentError.new("neither Sender or Queue: #{arg}")
+ end
end
- class Sender # :nodoc:
- def initialize(msg, data, sock)
+ class Sender
+ def initialize(msg, data, sock, queue)
@msg = msg
@data = data
@sock = sock
+ @queue = queue
+ end
+ attr_reader :queue
+
+ def recv(msg)
+ @queue.push([msg, @data])
end
end
@@ -632,38 +570,45 @@ class Resolv
def initialize
super()
@sock = UDPSocket.new
- @sock.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::F_SETFD
- DNS.bind_random_port(@sock)
- end
-
- def recv_reply
- reply, from = @sock.recvfrom(UDPSize)
- return reply, [from[3],from[1]]
+ @sock.fcntl(Fcntl::F_SETFD, 1) if defined? Fcntl::F_SETFD
+ @id = {}
+ @id.default = -1
+ @thread = Thread.new {
+ DNSThreadGroup.add Thread.current
+ loop {
+ reply, from = @sock.recvfrom(UDPSize)
+ msg = begin
+ Message.decode(reply)
+ rescue DecodeError
+ STDERR.print("DNS message decoding error: #{reply.inspect}\n")
+ next
+ end
+ if s = @senders[[[from[3],from[1]],msg.id]]
+ s.recv msg
+ else
+ #STDERR.print("non-handled DNS message: #{msg.inspect} from #{from.inspect}\n")
+ end
+ }
+ }
end
- def sender(msg, data, host, port=Port)
+ def sender(msg, data, queue, host, port=Port)
service = [host, port]
- id = DNS.allocate_request_id(host, port)
+ id = Thread.exclusive {
+ @id[service] = (@id[service] + 1) & 0xffff
+ }
request = msg.encode
request[0,2] = [id].pack('n')
return @senders[[service, id]] =
- Sender.new(request, data, @sock, host, port)
- end
-
- def close
- super
- @senders.each_key {|service, id|
- DNS.free_request_id(service[0], service[1], id)
- }
+ Sender.new(request, data, @sock, host, port, queue)
end
class Sender < Requester::Sender
- def initialize(msg, data, sock, host, port)
- super(msg, data, sock)
+ def initialize(msg, data, sock, host, port, queue)
+ super(msg, data, sock, queue)
@host = host
@port = port
end
- attr_reader :data
def send
@sock.send(@msg, 0, @host, @port)
@@ -677,38 +622,42 @@ class Resolv
@host = host
@port = port
@sock = UDPSocket.new(host.index(':') ? Socket::AF_INET6 : Socket::AF_INET)
- DNS.bind_random_port(@sock)
@sock.connect(host, port)
- @sock.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::F_SETFD
- end
-
- def recv_reply
- reply = @sock.recv(UDPSize)
- return reply, nil
+ @sock.fcntl(Fcntl::F_SETFD, 1) if defined? Fcntl::F_SETFD
+ @id = -1
+ @thread = Thread.new {
+ DNSThreadGroup.add Thread.current
+ loop {
+ reply = @sock.recv(UDPSize)
+ msg = begin
+ Message.decode(reply)
+ rescue DecodeError
+ STDERR.print("DNS message decoding error: #{reply.inspect}")
+ next
+ end
+ if s = @senders[msg.id]
+ s.recv msg
+ else
+ #STDERR.print("non-handled DNS message: #{msg.inspect}")
+ end
+ }
+ }
end
- def sender(msg, data, host=@host, port=@port)
+ def sender(msg, data, queue, host=@host, port=@port)
unless host == @host && port == @port
raise RequestError.new("host/port don't match: #{host}:#{port}")
end
- id = DNS.allocate_request_id(@host, @port)
+ id = Thread.exclusive { @id = (@id + 1) & 0xffff }
request = msg.encode
request[0,2] = [id].pack('n')
- return @senders[[nil,id]] = Sender.new(request, data, @sock)
- end
-
- def close
- super
- @senders.each_key {|from, id|
- DNS.free_request_id(@host, @port, id)
- }
+ return @senders[id] = Sender.new(request, data, @sock, queue)
end
class Sender < Requester::Sender
def send
@sock.send(@msg, 0)
end
- attr_reader :data
end
end
@@ -717,25 +666,39 @@ class Resolv
super()
@host = host
@port = port
- @sock = TCPSocket.new(@host, @port)
- @sock.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::F_SETFD
+ @sock = TCPSocket.new
+ @sock.connect(host, port)
+ @sock.fcntl(Fcntl::F_SETFD, 1) if defined? Fcntl::F_SETFD
+ @id = -1
@senders = {}
+ @thread = Thread.new {
+ DNSThreadGroup.add Thread.current
+ loop {
+ len = @sock.read(2).unpack('n')
+ reply = @sock.read(len)
+ msg = begin
+ Message.decode(reply)
+ rescue DecodeError
+ STDERR.print("DNS message decoding error: #{reply.inspect}")
+ next
+ end
+ if s = @senders[msg.id]
+ s.push msg
+ else
+ #STDERR.print("non-handled DNS message: #{msg.inspect}")
+ end
+ }
+ }
end
- def recv_reply
- len = @sock.read(2).unpack('n')[0]
- reply = @sock.read(len)
- return reply, nil
- end
-
- def sender(msg, data, host=@host, port=@port)
+ def sender(msg, data, queue, host=@host, port=@port)
unless host == @host && port == @port
raise RequestError.new("host/port don't match: #{host}:#{port}")
end
- id = DNS.allocate_request_id(@host, @port)
+ id = Thread.exclusive { @id = (@id + 1) & 0xffff }
request = msg.encode
request[0,2] = [request.length, id].pack('nn')
- return @senders[[nil,id]] = Sender.new(request, data, @sock)
+ return @senders[id] = Sender.new(request, data, @sock, queue)
end
class Sender < Requester::Sender
@@ -743,14 +706,6 @@ class Resolv
@sock.print(@msg)
@sock.flush
end
- attr_reader :data
- end
-
- def close
- super
- @senders.each_key {|from,id|
- DNS.free_request_id(@host, @port, id)
- }
end
end
@@ -804,7 +759,6 @@ class Resolv
config_hash = Config.parse_resolv_conf(filename)
else
if /mswin32|cygwin|mingw|bccwin/ =~ RUBY_PLATFORM
- require 'win32/resolv'
search, nameserver = Win32::Resolv.get_resolv_info
config_hash = {}
config_hash[:nameserver] = nameserver if nameserver
diff --git a/lib/rexml/attribute.rb b/lib/rexml/attribute.rb
index 89c1ada36c..a169148f32 100644
--- a/lib/rexml/attribute.rb
+++ b/lib/rexml/attribute.rb
@@ -18,41 +18,25 @@ module REXML
PATTERN = /\s*(#{NAME_STR})\s*=\s*(["'])(.*?)\2/um
# Constructor.
- # FIXME: The parser doesn't catch illegal characters in attributes
- #
- # first::
- # Either: an Attribute, which this new attribute will become a
- # clone of; or a String, which is the name of this attribute
- # second::
- # If +first+ is an Attribute, then this may be an Element, or nil.
- # If nil, then the Element parent of this attribute is the parent
- # of the +first+ Attribute. If the first argument is a String,
- # then this must also be a String, and is the content of the attribute.
- # If this is the content, it must be fully normalized (contain no
- # illegal characters).
- # parent::
- # Ignored unless +first+ is a String; otherwise, may be the Element
- # parent of this attribute, or nil.
- #
#
# Attribute.new( attribute_to_clone )
- # Attribute.new( attribute_to_clone, parent_element )
+ # Attribute.new( source )
# Attribute.new( "attr", "attr_value" )
# Attribute.new( "attr", "attr_value", parent_element )
def initialize( first, second=nil, parent=nil )
@normalized = @unnormalized = @element = nil
if first.kind_of? Attribute
self.name = first.expanded_name
- @unnormalized = first.value
+ @value = first.value
if second.kind_of? Element
@element = second
else
@element = first.element
end
elsif first.kind_of? String
- @element = parent
+ @element = parent if parent.kind_of? Element
self.name = first
- @normalized = second.to_s
+ @value = second.to_s
else
raise "illegal argument #{first.class.name} to Attribute constructor"
end
@@ -88,7 +72,7 @@ module REXML
# Returns true if other is an Attribute and has the same name and value,
# false otherwise.
def ==( other )
- other.kind_of?(Attribute) and other.name==name and other.value==value
+ other.kind_of?(Attribute) and other.name==name and other.value==@value
end
# Creates (and returns) a hash from both the name and value
@@ -103,11 +87,7 @@ module REXML
# b = Attribute.new( "ns:x", "y" )
# b.to_string # -> "ns:x='y'"
def to_string
- if @element and @element.context and @element.context[:attribute_quote] == :quote
- %Q^#@expanded_name="#{to_s().gsub(/"/, '&quote;')}"^
- else
- "#@expanded_name='#{to_s().gsub(/'/, '&apos;')}'"
- end
+ "#@expanded_name='#{to_s().gsub(/'/, '&apos;')}'"
end
# Returns the attribute value, with entities replaced
@@ -120,9 +100,8 @@ module REXML
doctype = doc.doctype if doc
end
- @normalized = Text::normalize( @unnormalized, doctype )
@unnormalized = nil
- @normalized
+ @normalized = Text::normalize( @value, doctype )
end
# Returns the UNNORMALIZED value of this attribute. That is, entities
@@ -134,9 +113,8 @@ module REXML
doc = @element.document
doctype = doc.doctype if doc
end
- @unnormalized = Text::unnormalize( @normalized, doctype )
@normalized = nil
- @unnormalized
+ @unnormalized = Text::unnormalize( @value, doctype )
end
# Returns a copy of this attribute
diff --git a/lib/rexml/cdata.rb b/lib/rexml/cdata.rb
index efcb71160a..046012ba61 100644
--- a/lib/rexml/cdata.rb
+++ b/lib/rexml/cdata.rb
@@ -39,26 +39,31 @@ module REXML
@string
end
- # == DEPRECATED
- # See the rexml/formatters package
- #
# Generates XML output of this object
#
# output::
# Where to write the string. Defaults to $stdout
# indent::
- # The amount to indent this node by
+ # An integer. If -1, no indenting will be used; otherwise, the
+ # indentation will be this number of spaces, and children will be
+ # indented an additional amount. Defaults to -1.
# transitive::
- # Ignored
+ # If transitive is true and indent is >= 0, then the output will be
+ # pretty-printed in such a way that the added whitespace does not affect
+ # the absolute *value* of the document -- that is, it leaves the value
+ # and number of Text nodes in the document unchanged.
# ie_hack::
- # Ignored
+ # Internet Explorer is the worst piece of crap to have ever been
+ # written, with the possible exception of Windows itself. Since IE is
+ # unable to parse proper XML, we have to provide a hack to generate XML
+ # that IE's limited abilities can handle. This hack inserts a space
+ # before the /> on empty tags.
#
# _Examples_
# c = CData.new( " Some text " )
# c.write( $stdout ) #-> <![CDATA[ Some text ]]>
def write( output=$stdout, indent=-1, transitive=false, ie_hack=false )
- Kernel.warn( "#{self.class.name}.write is deprecated" )
- indent( output, indent )
+ #indent( output, indent ) unless transitive
output << START
output << @string
output << STOP
diff --git a/lib/rexml/comment.rb b/lib/rexml/comment.rb
index 2b9b4b89c9..a4fcb58c8d 100644
--- a/lib/rexml/comment.rb
+++ b/lib/rexml/comment.rb
@@ -34,9 +34,6 @@ module REXML
Comment.new self
end
- # == DEPRECATED
- # See REXML::Formatters
- #
# output::
# Where to write the string
# indent::
@@ -48,7 +45,6 @@ module REXML
# ie_hack::
# Needed for conformity to the child API, but not used by this class.
def write( output, indent=-1, transitive=false, ie_hack=false )
- Kernel.warn("Comment.write is deprecated. See REXML::Formatters")
indent( output, indent )
output << START
output << @string
diff --git a/lib/rexml/doctype.rb b/lib/rexml/doctype.rb
index 05cd4ab331..4a1ffb4336 100644
--- a/lib/rexml/doctype.rb
+++ b/lib/rexml/doctype.rb
@@ -98,30 +98,38 @@ module REXML
# output::
# Where to write the string
# indent::
- # An integer. If -1, no indentation will be used; otherwise, the
+ # An integer. If -1, no indenting will be used; otherwise, the
# indentation will be this number of spaces, and children will be
# indented an additional amount.
# transitive::
- # Ignored
+ # If transitive is true and indent is >= 0, then the output will be
+ # pretty-printed in such a way that the added whitespace does not affect
+ # the absolute *value* of the document -- that is, it leaves the value
+ # and number of Text nodes in the document unchanged.
# ie_hack::
- # Ignored
+ # Internet Explorer is the worst piece of crap to have ever been
+ # written, with the possible exception of Windows itself. Since IE is
+ # unable to parse proper XML, we have to provide a hack to generate XML
+ # that IE's limited abilities can handle. This hack inserts a space
+ # before the /> on empty tags.
+ #
def write( output, indent=0, transitive=false, ie_hack=false )
- f = REXML::Formatters::Default.new
indent( output, indent )
output << START
output << ' '
output << @name
output << " #@external_id" if @external_id
- output << " #{@long_name.inspect}" if @long_name
- output << " #{@uri.inspect}" if @uri
+ output << " #@long_name" if @long_name
+ output << " #@uri" if @uri
unless @children.empty?
next_indent = indent + 1
output << ' ['
child = nil # speed
@children.each { |child|
output << "\n"
- f.write( child, output )
+ child.write( output, next_indent )
}
+ #output << ' '*next_indent
output << "\n]"
end
output << STOP
@@ -211,10 +219,8 @@ module REXML
@string+'>'
end
- # == DEPRECATED
- # See REXML::Formatters
- #
def write( output, indent )
+ output << (' '*indent) if indent > 0
output << to_s
end
end
@@ -258,6 +264,7 @@ module REXML
end
def write( output, indent=-1 )
+ output << (' '*indent) if indent > 0
output << to_s
end
diff --git a/lib/rexml/document.rb b/lib/rexml/document.rb
index 06983f2b7c..619a844257 100644
--- a/lib/rexml/document.rb
+++ b/lib/rexml/document.rb
@@ -31,8 +31,10 @@ module REXML
# to be sources of valid XML documents.
# @param context if supplied, contains the context of the document;
# this should be a Hash.
+ # NOTE that I'm not sure what the context is for; I cloned it out of
+ # the Electric XML API (in which it also seems to do nothing), and it
+ # is now legacy. It may do something, someday... it may disappear.
def initialize( source = nil, context = {} )
- @entity_expansion_count = 0
super()
@context = context
return if source.nil?
@@ -67,7 +69,6 @@ module REXML
def add( child )
if child.kind_of? XMLDecl
@children.unshift child
- child.parent = self
elsif child.kind_of? DocType
# Find first Element or DocType node and insert the decl right
# before it. If there is no such node, just insert the child at the
@@ -141,59 +142,42 @@ module REXML
xml_decl().stand_alone?
end
- # Write the XML tree out, optionally with indent. This writes out the
- # entire XML document, including XML declarations, doctype declarations,
- # and processing instructions (if any are given).
- #
- # A controversial point is whether Document should always write the XML
- # declaration (<?xml version='1.0'?>) whether or not one is given by the
- # user (or source document). REXML does not write one if one was not
- # specified, because it adds unneccessary bandwidth to applications such
- # as XML-RPC.
- #
- # See also the classes in the rexml/formatters package for the proper way
- # to change the default formatting of XML output
- #
- # _Examples_
- # Document.new("<a><b/></a>").serialize
- #
- # output_string = ""
- # tr = Transitive.new( output_string )
- # Document.new("<a><b/></a>").serialize( tr )
- #
- # output::
- # output an object which supports '<< string'; this is where the
- # document will be written.
- # indent::
- # An integer. If -1, no indenting will be used; otherwise, the
- # indentation will be twice this number of spaces, and children will be
- # indented an additional amount. For a value of 3, every item will be
- # indented 3 more levels, or 6 more spaces (2 * 3). Defaults to -1
- # trans::
- # If transitive is true and indent is >= 0, then the output will be
- # pretty-printed in such a way that the added whitespace does not affect
- # the absolute *value* of the document -- that is, it leaves the value
- # and number of Text nodes in the document unchanged.
- # ie_hack::
- # Internet Explorer is the worst piece of crap to have ever been
- # written, with the possible exception of Windows itself. Since IE is
- # unable to parse proper XML, we have to provide a hack to generate XML
- # that IE's limited abilities can handle. This hack inserts a space
- # before the /> on empty tags. Defaults to false
- def write( output=$stdout, indent=-1, trans=false, ie_hack=false )
- if xml_decl.encoding != "UTF-8" && !output.kind_of?(Output)
- output = Output.new( output, xml_decl.encoding )
- end
- formatter = if indent > -1
- if trans
- REXML::Formatters::Transitive.new( indent, ie_hack )
- else
- REXML::Formatters::Pretty.new( indent, ie_hack )
- end
- else
- REXML::Formatters::Default.new( ie_hack )
+ # Write the XML tree out, optionally with indent. This writes out the
+ # entire XML document, including XML declarations, doctype declarations,
+ # and processing instructions (if any are given).
+ # A controversial point is whether Document should always write the XML
+ # declaration (<?xml version='1.0'?>) whether or not one is given by the
+ # user (or source document). REXML does not write one if one was not
+ # specified, because it adds unneccessary bandwidth to applications such
+ # as XML-RPC.
+ #
+ #
+ # output::
+ # output an object which supports '<< string'; this is where the
+ # document will be written.
+ # indent::
+ # An integer. If -1, no indenting will be used; otherwise, the
+ # indentation will be this number of spaces, and children will be
+ # indented an additional amount. Defaults to -1
+ # transitive::
+ # If transitive is true and indent is >= 0, then the output will be
+ # pretty-printed in such a way that the added whitespace does not affect
+ # the absolute *value* of the document -- that is, it leaves the value
+ # and number of Text nodes in the document unchanged.
+ # ie_hack::
+ # Internet Explorer is the worst piece of crap to have ever been
+ # written, with the possible exception of Windows itself. Since IE is
+ # unable to parse proper XML, we have to provide a hack to generate XML
+ # that IE's limited abilities can handle. This hack inserts a space
+ # before the /> on empty tags. Defaults to false
+ def write( output=$stdout, indent=-1, transitive=false, ie_hack=false )
+ output = Output.new( output, xml_decl.encoding ) if xml_decl.encoding != "UTF-8" && !output.kind_of?(Output)
+ @children.each { |node|
+ indent( output, indent ) if node.node_type == :element
+ if node.write( output, indent, transitive, ie_hack )
+ output << "\n" unless indent<0 or node == @children[-1]
end
- formatter.write( self, output )
+ }
end
@@ -201,27 +185,6 @@ module REXML
Parsers::StreamParser.new( source, listener ).parse
end
- @@entity_expansion_limit = 10_000
-
- # Set the entity expansion limit. By default the limit is set to 10000.
- def Document::entity_expansion_limit=( val )
- @@entity_expansion_limit = val
- end
-
- # Get the entity expansion limit. By default the limit is set to 10000.
- def Document::entity_expansion_limit
- return @@entity_expansion_limit
- end
-
- attr_reader :entity_expansion_count
-
- def record_entity_expansion
- @entity_expansion_count += 1
- if @entity_expansion_count > @@entity_expansion_limit
- raise "number of entity expansions exceeded, processing aborted."
- end
- end
-
private
def build( source )
Parsers::TreeParser.new( source, self ).parse
diff --git a/lib/rexml/dtd/dtd.rb b/lib/rexml/dtd/dtd.rb
index 4f735d4812..81119cfa9b 100644
--- a/lib/rexml/dtd/dtd.rb
+++ b/lib/rexml/dtd/dtd.rb
@@ -25,7 +25,7 @@ module REXML
when ElementDecl.PATTERN_RE
match = $&
source = $'
- contents << ElementDecl.new( match )
+ contents << EleemntDecl.new( match )
when AttlistDecl.PATTERN_RE
matchdata = $~
source = $'
diff --git a/lib/rexml/element.rb b/lib/rexml/element.rb
index 92612036a1..11e2039609 100644
--- a/lib/rexml/element.rb
+++ b/lib/rexml/element.rb
@@ -14,64 +14,64 @@ module REXML
# context node and convert it back when we write it.
@@namespaces = {}
- # Represents a tagged XML element. Elements are characterized by
- # having children, attributes, and names, and can themselves be
- # children.
- class Element < Parent
- include Namespace
-
- UNDEFINED = "UNDEFINED"; # The default name
-
- # Mechanisms for accessing attributes and child elements of this
- # element.
- attr_reader :attributes, :elements
- # The context holds information about the processing environment, such as
- # whitespace handling.
- attr_accessor :context
-
- # Constructor
- # arg::
- # if not supplied, will be set to the default value.
- # If a String, the name of this object will be set to the argument.
- # If an Element, the object will be shallowly cloned; name,
- # attributes, and namespaces will be copied. Children will +not+ be
- # copied.
- # parent::
- # if supplied, must be a Parent, and will be used as
- # the parent of this object.
- # context::
- # If supplied, must be a hash containing context items. Context items
- # include:
- # * <tt>:respect_whitespace</tt> the value of this is :+all+ or an array of
- # strings being the names of the elements to respect
- # whitespace for. Defaults to :+all+.
- # * <tt>:compress_whitespace</tt> the value can be :+all+ or an array of
- # strings being the names of the elements to ignore whitespace on.
- # Overrides :+respect_whitespace+.
- # * <tt>:ignore_whitespace_nodes</tt> the value can be :+all+ or an array
- # of strings being the names of the elements in which to ignore
- # whitespace-only nodes. If this is set, Text nodes which contain only
- # whitespace will not be added to the document tree.
- # * <tt>:raw</tt> can be :+all+, or an array of strings being the names of
- # the elements to process in raw mode. In raw mode, special
- # characters in text is not converted to or from entities.
- def initialize( arg = UNDEFINED, parent=nil, context=nil )
- super(parent)
-
- @elements = Elements.new(self)
- @attributes = Attributes.new(self)
- @context = context
-
- if arg.kind_of? String
- self.name = arg
- elsif arg.kind_of? Element
- self.name = arg.expanded_name
- arg.attributes.each_attribute{ |attribute|
- @attributes << Attribute.new( attribute )
- }
- @context = arg.context
- end
- end
+ # Represents a tagged XML element. Elements are characterized by
+ # having children, attributes, and names, and can themselves be
+ # children.
+ class Element < Parent
+ include Namespace
+
+ UNDEFINED = "UNDEFINED"; # The default name
+
+ # Mechanisms for accessing attributes and child elements of this
+ # element.
+ attr_reader :attributes, :elements
+ # The context holds information about the processing environment, such as
+ # whitespace handling.
+ attr_accessor :context
+
+ # Constructor
+ # arg::
+ # if not supplied, will be set to the default value.
+ # If a String, the name of this object will be set to the argument.
+ # If an Element, the object will be shallowly cloned; name,
+ # attributes, and namespaces will be copied. Children will +not+ be
+ # copied.
+ # parent::
+ # if supplied, must be a Parent, and will be used as
+ # the parent of this object.
+ # context::
+ # If supplied, must be a hash containing context items. Context items
+ # include:
+ # * <tt>:respect_whitespace</tt> the value of this is :+all+ or an array of
+ # strings being the names of the elements to respect
+ # whitespace for. Defaults to :+all+.
+ # * <tt>:compress_whitespace</tt> the value can be :+all+ or an array of
+ # strings being the names of the elements to ignore whitespace on.
+ # Overrides :+respect_whitespace+.
+ # * <tt>:ignore_whitespace_nodes</tt> the value can be :+all+ or an array
+ # of strings being the names of the elements in which to ignore
+ # whitespace-only nodes. If this is set, Text nodes which contain only
+ # whitespace will not be added to the document tree.
+ # * <tt>:raw</tt> can be :+all+, or an array of strings being the names of
+ # the elements to process in raw mode. In raw mode, special
+ # characters in text is not converted to or from entities.
+ def initialize( arg = UNDEFINED, parent=nil, context=nil )
+ super(parent)
+
+ @elements = Elements.new(self)
+ @attributes = Attributes.new(self)
+ @context = context
+
+ if arg.kind_of? String
+ self.name = arg
+ elsif arg.kind_of? Element
+ self.name = arg.expanded_name
+ arg.attributes.each_attribute{ |attribute|
+ @attributes << Attribute.new( attribute )
+ }
+ @context = arg.context
+ end
+ end
def inspect
rv = "<#@expanded_name"
@@ -89,18 +89,18 @@ module REXML
end
- # Creates a shallow copy of self.
- # d = Document.new "<a><b/><b/><c><d/></c></a>"
- # new_a = d.root.clone
- # puts new_a # => "<a/>"
- def clone
- self.class.new self
- end
+ # Creates a shallow copy of self.
+ # d = Document.new "<a><b/><b/><c><d/></c></a>"
+ # new_a = d.root.clone
+ # puts new_a # => "<a/>"
+ def clone
+ self.class.new self
+ end
- # Evaluates to the root node of the document that this element
- # belongs to. If this element doesn't belong to a document, but does
- # belong to another Element, the parent's root will be returned, until the
- # earliest ancestor is found.
+ # Evaluates to the root node of the document that this element
+ # belongs to. If this element doesn't belong to a document, but does
+ # belong to another Element, the parent's root will be returned, until the
+ # earliest ancestor is found.
#
# Note that this is not the same as the document element.
# In the following example, <a> is the document element, and the root
@@ -111,14 +111,14 @@ module REXML
# The only time this isn't true is when an Element is created that is
# not part of any Document. In this case, the ancestor that has no
# parent acts as the root node.
- # d = Document.new '<a><b><c/></b></a>'
- # a = d[1] ; c = a[1][1]
- # d.root_node == d # TRUE
- # a.root_node # namely, d
- # c.root_node # again, d
- def root_node
- parent.nil? ? self : parent.root_node
- end
+ # d = Document.new '<a><b><c/></b></a>'
+ # a = d[1] ; c = a[1][1]
+ # d.root_node == d # TRUE
+ # a.root_node # namely, d
+ # c.root_node # again, d
+ def root_node
+ parent.nil? ? self : parent.root_node
+ end
def root
return elements[1] if self.kind_of? Document
@@ -126,410 +126,415 @@ module REXML
return parent.root
end
- # Evaluates to the document to which this element belongs, or nil if this
- # element doesn't belong to a document.
- def document
+ # Evaluates to the document to which this element belongs, or nil if this
+ # element doesn't belong to a document.
+ def document
rt = root
- rt.parent if rt
- end
-
- # Evaluates to +true+ if whitespace is respected for this element. This
- # is the case if:
- # 1. Neither :+respect_whitespace+ nor :+compress_whitespace+ has any value
- # 2. The context has :+respect_whitespace+ set to :+all+ or
- # an array containing the name of this element, and
+ rt.parent if rt
+ end
+
+ # Evaluates to +true+ if whitespace is respected for this element. This
+ # is the case if:
+ # 1. Neither :+respect_whitespace+ nor :+compress_whitespace+ has any value
+ # 2. The context has :+respect_whitespace+ set to :+all+ or
+ # an array containing the name of this element, and
# :+compress_whitespace+ isn't set to :+all+ or an array containing the
# name of this element.
- # The evaluation is tested against +expanded_name+, and so is namespace
- # sensitive.
- def whitespace
- @whitespace = nil
- if @context
- if @context[:respect_whitespace]
- @whitespace = (@context[:respect_whitespace] == :all or
- @context[:respect_whitespace].include? expanded_name)
- end
- @whitespace = false if (@context[:compress_whitespace] and
- (@context[:compress_whitespace] == :all or
- @context[:compress_whitespace].include? expanded_name)
- )
- end
- @whitespace = true unless @whitespace == false
- @whitespace
- end
-
- def ignore_whitespace_nodes
- @ignore_whitespace_nodes = false
- if @context
- if @context[:ignore_whitespace_nodes]
- @ignore_whitespace_nodes =
- (@context[:ignore_whitespace_nodes] == :all or
- @context[:ignore_whitespace_nodes].include? expanded_name)
- end
- end
- end
-
- # Evaluates to +true+ if raw mode is set for this element. This
- # is the case if the context has :+raw+ set to :+all+ or
- # an array containing the name of this element.
- #
- # The evaluation is tested against +expanded_name+, and so is namespace
- # sensitive.
- def raw
- @raw = (@context and @context[:raw] and
- (@context[:raw] == :all or
- @context[:raw].include? expanded_name))
- @raw
- end
-
- #once :whitespace, :raw, :ignore_whitespace_nodes
-
- #################################################
- # Namespaces #
- #################################################
-
- # Evaluates to an +Array+ containing the prefixes (names) of all defined
- # namespaces at this context node.
- # doc = Document.new("<a xmlns:x='1' xmlns:y='2'><b/><c xmlns:z='3'/></a>")
- # doc.elements['//b'].prefixes # -> ['x', 'y']
- def prefixes
- prefixes = []
- prefixes = parent.prefixes if parent
- prefixes |= attributes.prefixes
- return prefixes
- end
-
- def namespaces
- namespaces = {}
- namespaces = parent.namespaces if parent
- namespaces = namespaces.merge( attributes.namespaces )
- return namespaces
- end
-
- # Evalutas to the URI for a prefix, or the empty string if no such
- # namespace is declared for this element. Evaluates recursively for
- # ancestors. Returns the default namespace, if there is one.
- # prefix::
- # the prefix to search for. If not supplied, returns the default
- # namespace if one exists
- # Returns::
- # the namespace URI as a String, or nil if no such namespace
- # exists. If the namespace is undefined, returns an empty string
- # doc = Document.new("<a xmlns='1' xmlns:y='2'><b/><c xmlns:z='3'/></a>")
- # b = doc.elements['//b']
- # b.namespace # -> '1'
- # b.namespace("y") # -> '2'
- def namespace(prefix=nil)
- if prefix.nil?
- prefix = prefix()
- end
- if prefix == ''
- prefix = "xmlns"
- else
- prefix = "xmlns:#{prefix}" unless prefix[0,5] == 'xmlns'
- end
- ns = attributes[ prefix ]
- ns = parent.namespace(prefix) if ns.nil? and parent
- ns = '' if ns.nil? and prefix == 'xmlns'
- return ns
- end
-
- # Adds a namespace to this element.
- # prefix::
- # the prefix string, or the namespace URI if +uri+ is not
- # supplied
- # uri::
- # the namespace URI. May be nil, in which +prefix+ is used as
- # the URI
- # Evaluates to: this Element
- # a = Element.new("a")
- # a.add_namespace("xmlns:foo", "bar" )
- # a.add_namespace("foo", "bar") # shorthand for previous line
- # a.add_namespace("twiddle")
- # puts a #-> <a xmlns:foo='bar' xmlns='twiddle'/>
- def add_namespace( prefix, uri=nil )
- unless uri
- @attributes["xmlns"] = prefix
- else
- prefix = "xmlns:#{prefix}" unless prefix =~ /^xmlns:/
- @attributes[ prefix ] = uri
- end
- self
- end
-
- # Removes a namespace from this node. This only works if the namespace is
- # actually declared in this node. If no argument is passed, deletes the
- # default namespace.
- #
- # Evaluates to: this element
- # doc = Document.new "<a xmlns:foo='bar' xmlns='twiddle'/>"
- # doc.root.delete_namespace
- # puts doc # -> <a xmlns:foo='bar'/>
- # doc.root.delete_namespace 'foo'
- # puts doc # -> <a/>
- def delete_namespace namespace="xmlns"
- namespace = "xmlns:#{namespace}" unless namespace == 'xmlns'
- attribute = attributes.get_attribute(namespace)
- attribute.remove unless attribute.nil?
- self
- end
-
- #################################################
- # Elements #
- #################################################
-
- # Adds a child to this element, optionally setting attributes in
- # the element.
- # element::
- # optional. If Element, the element is added.
- # Otherwise, a new Element is constructed with the argument (see
- # Element.initialize).
- # attrs::
- # If supplied, must be a Hash containing String name,value
- # pairs, which will be used to set the attributes of the new Element.
- # Returns:: the Element that was added
- # el = doc.add_element 'my-tag'
- # el = doc.add_element 'my-tag', {'attr1'=>'val1', 'attr2'=>'val2'}
- # el = Element.new 'my-tag'
- # doc.add_element el
- def add_element element, attrs=nil
+ # The evaluation is tested against +expanded_name+, and so is namespace
+ # sensitive.
+ def whitespace
+ @whitespace = nil
+ if @context
+ if @context[:respect_whitespace]
+ @whitespace = (@context[:respect_whitespace] == :all or
+ @context[:respect_whitespace].include? expanded_name)
+ end
+ @whitespace = false if (@context[:compress_whitespace] and
+ (@context[:compress_whitespace] == :all or
+ @context[:compress_whitespace].include? expanded_name)
+ )
+ end
+ @whitespace = true unless @whitespace == false
+ @whitespace
+ end
+
+ def ignore_whitespace_nodes
+ @ignore_whitespace_nodes = false
+ if @context
+ if @context[:ignore_whitespace_nodes]
+ @ignore_whitespace_nodes =
+ (@context[:ignore_whitespace_nodes] == :all or
+ @context[:ignore_whitespace_nodes].include? expanded_name)
+ end
+ end
+ end
+
+ # Evaluates to +true+ if raw mode is set for this element. This
+ # is the case if the context has :+raw+ set to :+all+ or
+ # an array containing the name of this element.
+ #
+ # The evaluation is tested against +expanded_name+, and so is namespace
+ # sensitive.
+ def raw
+ @raw = (@context and @context[:raw] and
+ (@context[:raw] == :all or
+ @context[:raw].include? expanded_name))
+ @raw
+ end
+
+ #once :whitespace, :raw, :ignore_whitespace_nodes
+
+ #################################################
+ # Namespaces #
+ #################################################
+
+ # Evaluates to an +Array+ containing the prefixes (names) of all defined
+ # namespaces at this context node.
+ # doc = Document.new("<a xmlns:x='1' xmlns:y='2'><b/><c xmlns:z='3'/></a>")
+ # doc.elements['//b'].prefixes # -> ['x', 'y']
+ def prefixes
+ prefixes = []
+ prefixes = parent.prefixes if parent
+ prefixes |= attributes.prefixes
+ return prefixes
+ end
+
+ def namespaces
+ namespaces = {}
+ namespaces = parent.namespaces if parent
+ namespaces = namespaces.merge( attributes.namespaces )
+ return namespaces
+ end
+
+ # Evalutas to the URI for a prefix, or the empty string if no such
+ # namespace is declared for this element. Evaluates recursively for
+ # ancestors. Returns the default namespace, if there is one.
+ # prefix::
+ # the prefix to search for. If not supplied, returns the default
+ # namespace if one exists
+ # Returns::
+ # the namespace URI as a String, or nil if no such namespace
+ # exists. If the namespace is undefined, returns an empty string
+ # doc = Document.new("<a xmlns='1' xmlns:y='2'><b/><c xmlns:z='3'/></a>")
+ # b = doc.elements['//b']
+ # b.namespace # -> '1'
+ # b.namespace("y") # -> '2'
+ def namespace(prefix=nil)
+ if prefix.nil?
+ prefix = prefix()
+ end
+ if prefix == ''
+ prefix = "xmlns"
+ else
+ prefix = "xmlns:#{prefix}" unless prefix[0,5] == 'xmlns'
+ end
+ ns = attributes[ prefix ]
+ ns = parent.namespace(prefix) if ns.nil? and parent
+ ns = '' if ns.nil? and prefix == 'xmlns'
+ return ns
+ end
+
+ # Adds a namespace to this element.
+ # prefix::
+ # the prefix string, or the namespace URI if +uri+ is not
+ # supplied
+ # uri::
+ # the namespace URI. May be nil, in which +prefix+ is used as
+ # the URI
+ # Evaluates to: this Element
+ # a = Element.new("a")
+ # a.add_namespace("xmlns:foo", "bar" )
+ # a.add_namespace("foo", "bar") # shorthand for previous line
+ # a.add_namespace("twiddle")
+ # puts a #-> <a xmlns:foo='bar' xmlns='twiddle'/>
+ def add_namespace( prefix, uri=nil )
+ unless uri
+ @attributes["xmlns"] = prefix
+ else
+ prefix = "xmlns:#{prefix}" unless prefix =~ /^xmlns:/
+ @attributes[ prefix ] = uri
+ end
+ self
+ end
+
+ # Removes a namespace from this node. This only works if the namespace is
+ # actually declared in this node. If no argument is passed, deletes the
+ # default namespace.
+ #
+ # Evaluates to: this element
+ # doc = Document.new "<a xmlns:foo='bar' xmlns='twiddle'/>"
+ # doc.root.delete_namespace
+ # puts doc # -> <a xmlns:foo='bar'/>
+ # doc.root.delete_namespace 'foo'
+ # puts doc # -> <a/>
+ def delete_namespace namespace="xmlns"
+ namespace = "xmlns:#{namespace}" unless namespace == 'xmlns'
+ attribute = attributes.get_attribute(namespace)
+ attribute.remove unless attribute.nil?
+ self
+ end
+
+ #################################################
+ # Elements #
+ #################################################
+
+ # Adds a child to this element, optionally setting attributes in
+ # the element.
+ # element::
+ # optional. If Element, the element is added.
+ # Otherwise, a new Element is constructed with the argument (see
+ # Element.initialize).
+ # attrs::
+ # If supplied, must be a Hash containing String name,value
+ # pairs, which will be used to set the attributes of the new Element.
+ # Returns:: the Element that was added
+ # el = doc.add_element 'my-tag'
+ # el = doc.add_element 'my-tag', {'attr1'=>'val1', 'attr2'=>'val2'}
+ # el = Element.new 'my-tag'
+ # doc.add_element el
+ def add_element element, attrs=nil
raise "First argument must be either an element name, or an Element object" if element.nil?
- el = @elements.add(element)
- attrs.each do |key, value|
- el.attributes[key]=Attribute.new(key,value,self)
- end if attrs.kind_of? Hash
- el
- end
-
- # Deletes a child element.
- # element::
- # Must be an +Element+, +String+, or +Integer+. If Element,
- # the element is removed. If String, the element is found (via XPath)
- # and removed. <em>This means that any parent can remove any
- # descendant.<em> If Integer, the Element indexed by that number will be
- # removed.
- # Returns:: the element that was removed.
- # doc.delete_element "/a/b/c[@id='4']"
- # doc.delete_element doc.elements["//k"]
- # doc.delete_element 1
- def delete_element element
- @elements.delete element
- end
-
- # Evaluates to +true+ if this element has at least one child Element
- # doc = Document.new "<a><b/><c>Text</c></a>"
- # doc.root.has_elements # -> true
- # doc.elements["/a/b"].has_elements # -> false
- # doc.elements["/a/c"].has_elements # -> false
- def has_elements?
- !@elements.empty?
- end
-
- # Iterates through the child elements, yielding for each Element that
- # has a particular attribute set.
- # key::
- # the name of the attribute to search for
- # value::
- # the value of the attribute
- # max::
- # (optional) causes this method to return after yielding
- # for this number of matching children
- # name::
- # (optional) if supplied, this is an XPath that filters
- # the children to check.
- #
- # doc = Document.new "<a><b @id='1'/><c @id='2'/><d @id='1'/><e/></a>"
- # # Yields b, c, d
- # doc.root.each_element_with_attribute( 'id' ) {|e| p e}
- # # Yields b, d
- # doc.root.each_element_with_attribute( 'id', '1' ) {|e| p e}
- # # Yields b
- # doc.root.each_element_with_attribute( 'id', '1', 1 ) {|e| p e}
- # # Yields d
- # doc.root.each_element_with_attribute( 'id', '1', 0, 'd' ) {|e| p e}
- def each_element_with_attribute( key, value=nil, max=0, name=nil, &block ) # :yields: Element
- each_with_something( proc {|child|
- if value.nil?
- child.attributes[key] != nil
- else
- child.attributes[key]==value
- end
- }, max, name, &block )
- end
-
- # Iterates through the children, yielding for each Element that
- # has a particular text set.
- # text::
- # the text to search for. If nil, or not supplied, will itterate
- # over all +Element+ children that contain at least one +Text+ node.
- # max::
- # (optional) causes this method to return after yielding
- # for this number of matching children
- # name::
- # (optional) if supplied, this is an XPath that filters
- # the children to check.
- #
- # doc = Document.new '<a><b>b</b><c>b</c><d>d</d><e/></a>'
- # # Yields b, c, d
- # doc.each_element_with_text {|e|p e}
- # # Yields b, c
- # doc.each_element_with_text('b'){|e|p e}
- # # Yields b
- # doc.each_element_with_text('b', 1){|e|p e}
- # # Yields d
- # doc.each_element_with_text(nil, 0, 'd'){|e|p e}
- def each_element_with_text( text=nil, max=0, name=nil, &block ) # :yields: Element
- each_with_something( proc {|child|
- if text.nil?
- child.has_text?
- else
- child.text == text
- end
- }, max, name, &block )
- end
-
- # Synonym for Element.elements.each
- def each_element( xpath=nil, &block ) # :yields: Element
- @elements.each( xpath, &block )
- end
-
- # Synonym for Element.to_a
- # This is a little slower than calling elements.each directly.
- # xpath:: any XPath by which to search for elements in the tree
- # Returns:: an array of Elements that match the supplied path
- def get_elements( xpath )
- @elements.to_a( xpath )
- end
-
- # Returns the next sibling that is an element, or nil if there is
- # no Element sibling after this one
- # doc = Document.new '<a><b/>text<c/></a>'
- # doc.root.elements['b'].next_element #-> <c/>
- # doc.root.elements['c'].next_element #-> nil
- def next_element
- element = next_sibling
- element = element.next_sibling until element.nil? or element.kind_of? Element
- return element
- end
-
- # Returns the previous sibling that is an element, or nil if there is
- # no Element sibling prior to this one
- # doc = Document.new '<a><b/>text<c/></a>'
- # doc.root.elements['c'].previous_element #-> <b/>
- # doc.root.elements['b'].previous_element #-> nil
- def previous_element
- element = previous_sibling
- element = element.previous_sibling until element.nil? or element.kind_of? Element
- return element
- end
-
-
- #################################################
- # Text #
- #################################################
-
- # Evaluates to +true+ if this element has at least one Text child
- def has_text?
- not text().nil?
- end
-
- # A convenience method which returns the String value of the _first_
- # child text element, if one exists, and +nil+ otherwise.
- #
- # <em>Note that an element may have multiple Text elements, perhaps
- # separated by other children</em>. Be aware that this method only returns
- # the first Text node.
- #
- # This method returns the +value+ of the first text child node, which
- # ignores the +raw+ setting, so always returns normalized text. See
- # the Text::value documentation.
- #
- # doc = Document.new "<p>some text <b>this is bold!</b> more text</p>"
- # # The element 'p' has two text elements, "some text " and " more text".
- # doc.root.text #-> "some text "
- def text( path = nil )
- rv = get_text(path)
- return rv.value unless rv.nil?
- nil
- end
-
- # Returns the first child Text node, if any, or +nil+ otherwise.
- # This method returns the actual +Text+ node, rather than the String content.
- # doc = Document.new "<p>some text <b>this is bold!</b> more text</p>"
- # # The element 'p' has two text elements, "some text " and " more text".
- # doc.root.get_text.value #-> "some text "
- def get_text path = nil
- rv = nil
- if path
- element = @elements[ path ]
- rv = element.get_text unless element.nil?
- else
- rv = @children.find { |node| node.kind_of? Text }
- end
- return rv
- end
-
- # Sets the first Text child of this object. See text() for a
- # discussion about Text children.
- #
- # If a Text child already exists, the child is replaced by this
- # content. This means that Text content can be deleted by calling
- # this method with a nil argument. In this case, the next Text
- # child becomes the first Text child. In no case is the order of
- # any siblings disturbed.
- # text::
- # If a String, a new Text child is created and added to
- # this Element as the first Text child. If Text, the text is set
- # as the first Child element. If nil, then any existing first Text
- # child is removed.
- # Returns:: this Element.
- # doc = Document.new '<a><b/></a>'
- # doc.root.text = 'Sean' #-> '<a><b/>Sean</a>'
- # doc.root.text = 'Elliott' #-> '<a><b/>Elliott</a>'
- # doc.root.add_element 'c' #-> '<a><b/>Elliott<c/></a>'
- # doc.root.text = 'Russell' #-> '<a><b/>Russell<c/></a>'
- # doc.root.text = nil #-> '<a><b/><c/></a>'
+ el = @elements.add(element)
+ if attrs.kind_of? Hash
+ attrs.each do |key, value|
+ el.attributes[key]=value if key =~ /^xmlns:/
+ end
+ attrs.each do |key, value|
+ el.attributes[key]=value if key !~ /^xmlns:/
+ end
+ end
+ el
+ end
+
+ # Deletes a child element.
+ # element::
+ # Must be an +Element+, +String+, or +Integer+. If Element,
+ # the element is removed. If String, the element is found (via XPath)
+ # and removed. <em>This means that any parent can remove any
+ # descendant.<em> If Integer, the Element indexed by that number will be
+ # removed.
+ # Returns:: the element that was removed.
+ # doc.delete_element "/a/b/c[@id='4']"
+ # doc.delete_element doc.elements["//k"]
+ # doc.delete_element 1
+ def delete_element element
+ @elements.delete element
+ end
+
+ # Evaluates to +true+ if this element has at least one child Element
+ # doc = Document.new "<a><b/><c>Text</c></a>"
+ # doc.root.has_elements # -> true
+ # doc.elements["/a/b"].has_elements # -> false
+ # doc.elements["/a/c"].has_elements # -> false
+ def has_elements?
+ !@elements.empty?
+ end
+
+ # Iterates through the child elements, yielding for each Element that
+ # has a particular attribute set.
+ # key::
+ # the name of the attribute to search for
+ # value::
+ # the value of the attribute
+ # max::
+ # (optional) causes this method to return after yielding
+ # for this number of matching children
+ # name::
+ # (optional) if supplied, this is an XPath that filters
+ # the children to check.
+ #
+ # doc = Document.new "<a><b @id='1'/><c @id='2'/><d @id='1'/><e/></a>"
+ # # Yields b, c, d
+ # doc.root.each_element_with_attribute( 'id' ) {|e| p e}
+ # # Yields b, d
+ # doc.root.each_element_with_attribute( 'id', '1' ) {|e| p e}
+ # # Yields b
+ # doc.root.each_element_with_attribute( 'id', '1', 1 ) {|e| p e}
+ # # Yields d
+ # doc.root.each_element_with_attribute( 'id', '1', 0, 'd' ) {|e| p e}
+ def each_element_with_attribute( key, value=nil, max=0, name=nil, &block ) # :yields: Element
+ each_with_something( proc {|child|
+ if value.nil?
+ child.attributes[key] != nil
+ else
+ child.attributes[key]==value
+ end
+ }, max, name, &block )
+ end
+
+ # Iterates through the children, yielding for each Element that
+ # has a particular text set.
+ # text::
+ # the text to search for. If nil, or not supplied, will itterate
+ # over all +Element+ children that contain at least one +Text+ node.
+ # max::
+ # (optional) causes this method to return after yielding
+ # for this number of matching children
+ # name::
+ # (optional) if supplied, this is an XPath that filters
+ # the children to check.
+ #
+ # doc = Document.new '<a><b>b</b><c>b</c><d>d</d><e/></a>'
+ # # Yields b, c, d
+ # doc.each_element_with_text {|e|p e}
+ # # Yields b, c
+ # doc.each_element_with_text('b'){|e|p e}
+ # # Yields b
+ # doc.each_element_with_text('b', 1){|e|p e}
+ # # Yields d
+ # doc.each_element_with_text(nil, 0, 'd'){|e|p e}
+ def each_element_with_text( text=nil, max=0, name=nil, &block ) # :yields: Element
+ each_with_something( proc {|child|
+ if text.nil?
+ child.has_text?
+ else
+ child.text == text
+ end
+ }, max, name, &block )
+ end
+
+ # Synonym for Element.elements.each
+ def each_element( xpath=nil, &block ) # :yields: Element
+ @elements.each( xpath, &block )
+ end
+
+ # Synonym for Element.to_a
+ # This is a little slower than calling elements.each directly.
+ # xpath:: any XPath by which to search for elements in the tree
+ # Returns:: an array of Elements that match the supplied path
+ def get_elements( xpath )
+ @elements.to_a( xpath )
+ end
+
+ # Returns the next sibling that is an element, or nil if there is
+ # no Element sibling after this one
+ # doc = Document.new '<a><b/>text<c/></a>'
+ # doc.root.elements['b'].next_element #-> <c/>
+ # doc.root.elements['c'].next_element #-> nil
+ def next_element
+ element = next_sibling
+ element = element.next_sibling until element.nil? or element.kind_of? Element
+ return element
+ end
+
+ # Returns the previous sibling that is an element, or nil if there is
+ # no Element sibling prior to this one
+ # doc = Document.new '<a><b/>text<c/></a>'
+ # doc.root.elements['c'].previous_element #-> <b/>
+ # doc.root.elements['b'].previous_element #-> nil
+ def previous_element
+ element = previous_sibling
+ element = element.previous_sibling until element.nil? or element.kind_of? Element
+ return element
+ end
+
+
+ #################################################
+ # Text #
+ #################################################
+
+ # Evaluates to +true+ if this element has at least one Text child
+ def has_text?
+ not text().nil?
+ end
+
+ # A convenience method which returns the String value of the _first_
+ # child text element, if one exists, and +nil+ otherwise.
+ #
+ # <em>Note that an element may have multiple Text elements, perhaps
+ # separated by other children</em>. Be aware that this method only returns
+ # the first Text node.
+ #
+ # This method returns the +value+ of the first text child node, which
+ # ignores the +raw+ setting, so always returns normalized text. See
+ # the Text::value documentation.
+ #
+ # doc = Document.new "<p>some text <b>this is bold!</b> more text</p>"
+ # # The element 'p' has two text elements, "some text " and " more text".
+ # doc.root.text #-> "some text "
+ def text( path = nil )
+ rv = get_text(path)
+ return rv.value unless rv.nil?
+ nil
+ end
+
+ # Returns the first child Text node, if any, or +nil+ otherwise.
+ # This method returns the actual +Text+ node, rather than the String content.
+ # doc = Document.new "<p>some text <b>this is bold!</b> more text</p>"
+ # # The element 'p' has two text elements, "some text " and " more text".
+ # doc.root.get_text.value #-> "some text "
+ def get_text path = nil
+ rv = nil
+ if path
+ element = @elements[ path ]
+ rv = element.get_text unless element.nil?
+ else
+ rv = @children.find { |node| node.kind_of? Text }
+ end
+ return rv
+ end
+
+ # Sets the first Text child of this object. See text() for a
+ # discussion about Text children.
+ #
+ # If a Text child already exists, the child is replaced by this
+ # content. This means that Text content can be deleted by calling
+ # this method with a nil argument. In this case, the next Text
+ # child becomes the first Text child. In no case is the order of
+ # any siblings disturbed.
+ # text::
+ # If a String, a new Text child is created and added to
+ # this Element as the first Text child. If Text, the text is set
+ # as the first Child element. If nil, then any existing first Text
+ # child is removed.
+ # Returns:: this Element.
+ # doc = Document.new '<a><b/></a>'
+ # doc.root.text = 'Sean' #-> '<a><b/>Sean</a>'
+ # doc.root.text = 'Elliott' #-> '<a><b/>Elliott</a>'
+ # doc.root.add_element 'c' #-> '<a><b/>Elliott<c/></a>'
+ # doc.root.text = 'Russell' #-> '<a><b/>Russell<c/></a>'
+ # doc.root.text = nil #-> '<a><b/><c/></a>'
def text=( text )
if text.kind_of? String
text = Text.new( text, whitespace(), nil, raw() )
elsif text and !text.kind_of? Text
text = Text.new( text.to_s, whitespace(), nil, raw() )
end
- old_text = get_text
- if text.nil?
- old_text.remove unless old_text.nil?
- else
- if old_text.nil?
- self << text
- else
- old_text.replace_with( text )
- end
- end
- return self
- end
-
- # A helper method to add a Text child. Actual Text instances can
- # be added with regular Parent methods, such as add() and <<()
- # text::
- # if a String, a new Text instance is created and added
- # to the parent. If Text, the object is added directly.
- # Returns:: this Element
- # e = Element.new('a') #-> <e/>
- # e.add_text 'foo' #-> <e>foo</e>
- # e.add_text Text.new(' bar') #-> <e>foo bar</e>
- # Note that at the end of this example, the branch has <b>3</b> nodes; the 'e'
- # element and <b>2</b> Text node children.
- def add_text( text )
- if text.kind_of? String
- if @children[-1].kind_of? Text
- @children[-1] << text
- return
- end
- text = Text.new( text, whitespace(), nil, raw() )
- end
- self << text unless text.nil?
- return self
- end
+ old_text = get_text
+ if text.nil?
+ old_text.remove unless old_text.nil?
+ else
+ if old_text.nil?
+ self << text
+ else
+ old_text.replace_with( text )
+ end
+ end
+ return self
+ end
+
+ # A helper method to add a Text child. Actual Text instances can
+ # be added with regular Parent methods, such as add() and <<()
+ # text::
+ # if a String, a new Text instance is created and added
+ # to the parent. If Text, the object is added directly.
+ # Returns:: this Element
+ # e = Element.new('a') #-> <e/>
+ # e.add_text 'foo' #-> <e>foo</e>
+ # e.add_text Text.new(' bar') #-> <e>foo bar</e>
+ # Note that at the end of this example, the branch has <b>3</b> nodes; the 'e'
+ # element and <b>2</b> Text node children.
+ def add_text( text )
+ if text.kind_of? String
+ if @children[-1].kind_of? Text
+ @children[-1] << text
+ return
+ end
+ text = Text.new( text, whitespace(), nil, raw() )
+ end
+ self << text unless text.nil?
+ return self
+ end
def node_type
:element
@@ -546,147 +551,162 @@ module REXML
return path_elements.reverse.join( "/" )
end
- #################################################
- # Attributes #
- #################################################
+ #################################################
+ # Attributes #
+ #################################################
- def attribute( name, namespace=nil )
- prefix = nil
+ def attribute( name, namespace=nil )
+ prefix = nil
prefix = namespaces.index(namespace) if namespace
- prefix = nil if prefix == 'xmlns'
- attributes.get_attribute( "#{prefix ? prefix + ':' : ''}#{name}" )
- end
-
- # Evaluates to +true+ if this element has any attributes set, false
- # otherwise.
- def has_attributes?
- return !@attributes.empty?
- end
-
- # Adds an attribute to this element, overwriting any existing attribute
- # by the same name.
- # key::
- # can be either an Attribute or a String. If an Attribute,
- # the attribute is added to the list of Element attributes. If String,
- # the argument is used as the name of the new attribute, and the value
- # parameter must be supplied.
- # value::
- # Required if +key+ is a String, and ignored if the first argument is
- # an Attribute. This is a String, and is used as the value
- # of the new Attribute. This should be the unnormalized value of the
- # attribute (without entities).
- # Returns:: the Attribute added
- # e = Element.new 'e'
- # e.add_attribute( 'a', 'b' ) #-> <e a='b'/>
- # e.add_attribute( 'x:a', 'c' ) #-> <e a='b' x:a='c'/>
- # e.add_attribute Attribute.new('b', 'd') #-> <e a='b' x:a='c' b='d'/>
- def add_attribute( key, value=nil )
- if key.kind_of? Attribute
- @attributes << key
- else
- @attributes[key] = value
- end
- end
-
- # Add multiple attributes to this element.
- # hash:: is either a hash, or array of arrays
- # el.add_attributes( {"name1"=>"value1", "name2"=>"value2"} )
- # el.add_attributes( [ ["name1","value1"], ["name2"=>"value2"] ] )
- def add_attributes hash
- if hash.kind_of? Hash
- hash.each_pair {|key, value| @attributes[key] = value }
- elsif hash.kind_of? Array
- hash.each { |value| @attributes[ value[0] ] = value[1] }
- end
- end
-
- # Removes an attribute
- # key::
- # either an Attribute or a String. In either case, the
- # attribute is found by matching the attribute name to the argument,
- # and then removed. If no attribute is found, no action is taken.
- # Returns::
- # the attribute removed, or nil if this Element did not contain
- # a matching attribute
- # e = Element.new('E')
- # e.add_attribute( 'name', 'Sean' ) #-> <E name='Sean'/>
- # r = e.add_attribute( 'sur:name', 'Russell' ) #-> <E name='Sean' sur:name='Russell'/>
- # e.delete_attribute( 'name' ) #-> <E sur:name='Russell'/>
- # e.delete_attribute( r ) #-> <E/>
- def delete_attribute(key)
- attr = @attributes.get_attribute(key)
- attr.remove unless attr.nil?
- end
-
- #################################################
- # Other Utilities #
- #################################################
-
- # Get an array of all CData children.
- # IMMUTABLE
- def cdatas
- find_all { |child| child.kind_of? CData }.freeze
- end
-
- # Get an array of all Comment children.
- # IMMUTABLE
- def comments
- find_all { |child| child.kind_of? Comment }.freeze
- end
-
- # Get an array of all Instruction children.
- # IMMUTABLE
- def instructions
- find_all { |child| child.kind_of? Instruction }.freeze
- end
-
- # Get an array of all Text children.
- # IMMUTABLE
- def texts
- find_all { |child| child.kind_of? Text }.freeze
- end
-
- # == DEPRECATED
- # See REXML::Formatters
- #
- # Writes out this element, and recursively, all children.
- # output::
- # output an object which supports '<< string'; this is where the
- # document will be written.
- # indent::
- # An integer. If -1, no indenting will be used; otherwise, the
- # indentation will be this number of spaces, and children will be
- # indented an additional amount. Defaults to -1
- # transitive::
- # If transitive is true and indent is >= 0, then the output will be
- # pretty-printed in such a way that the added whitespace does not affect
- # the parse tree of the document
- # ie_hack::
- # Internet Explorer is the worst piece of crap to have ever been
- # written, with the possible exception of Windows itself. Since IE is
- # unable to parse proper XML, we have to provide a hack to generate XML
- # that IE's limited abilities can handle. This hack inserts a space
- # before the /> on empty tags. Defaults to false
- #
- # out = ''
- # doc.write( out ) #-> doc is written to the string 'out'
- # doc.write( $stdout ) #-> doc written to the console
- def write(writer=$stdout, indent=-1, transitive=false, ie_hack=false)
- Kernel.warn("#{self.class.name}.write is deprecated. See REXML::Formatters")
- formatter = if indent > -1
- if transitive
- REXML::Formatters::Transitive.new( indent, ie_hack )
- else
- REXML::Formatters::Pretty.new( indent, ie_hack )
- end
- else
- REXML::Formatters::Default.new( ie_hack )
+ attributes.get_attribute( "#{prefix ? prefix + ':' : ''}#{name}" )
+ end
+
+ # Evaluates to +true+ if this element has any attributes set, false
+ # otherwise.
+ def has_attributes?
+ return !@attributes.empty?
+ end
+
+ # Adds an attribute to this element, overwriting any existing attribute
+ # by the same name.
+ # key::
+ # can be either an Attribute or a String. If an Attribute,
+ # the attribute is added to the list of Element attributes. If String,
+ # the argument is used as the name of the new attribute, and the value
+ # parameter must be supplied.
+ # value::
+ # Required if +key+ is a String, and ignored if the first argument is
+ # an Attribute. This is a String, and is used as the value
+ # of the new Attribute.
+ # Returns:: the Attribute added
+ # e = Element.new 'e'
+ # e.add_attribute( 'a', 'b' ) #-> <e a='b'/>
+ # e.add_attribute( 'x:a', 'c' ) #-> <e a='b' x:a='c'/>
+ # e.add_attribute Attribute.new('b', 'd') #-> <e a='b' x:a='c' b='d'/>
+ def add_attribute( key, value=nil )
+ if key.kind_of? Attribute
+ @attributes << key
+ else
+ @attributes[key] = value
+ end
+ end
+
+ # Add multiple attributes to this element.
+ # hash:: is either a hash, or array of arrays
+ # el.add_attributes( {"name1"=>"value1", "name2"=>"value2"} )
+ # el.add_attributes( [ ["name1","value1"], ["name2"=>"value2"] ] )
+ def add_attributes hash
+ if hash.kind_of? Hash
+ hash.each_pair {|key, value| @attributes[key] = value }
+ elsif hash.kind_of? Array
+ hash.each { |value| @attributes[ value[0] ] = value[1] }
+ end
+ end
+
+ # Removes an attribute
+ # key::
+ # either an Attribute or a String. In either case, the
+ # attribute is found by matching the attribute name to the argument,
+ # and then removed. If no attribute is found, no action is taken.
+ # Returns::
+ # the attribute removed, or nil if this Element did not contain
+ # a matching attribute
+ # e = Element.new('E')
+ # e.add_attribute( 'name', 'Sean' ) #-> <E name='Sean'/>
+ # r = e.add_attribute( 'sur:name', 'Russell' ) #-> <E name='Sean' sur:name='Russell'/>
+ # e.delete_attribute( 'name' ) #-> <E sur:name='Russell'/>
+ # e.delete_attribute( r ) #-> <E/>
+ def delete_attribute(key)
+ attr = @attributes.get_attribute(key)
+ attr.remove unless attr.nil?
+ end
+
+ #################################################
+ # Other Utilities #
+ #################################################
+
+ # Get an array of all CData children.
+ # IMMUTABLE
+ def cdatas
+ find_all { |child| child.kind_of? CData }.freeze
+ end
+
+ # Get an array of all Comment children.
+ # IMMUTABLE
+ def comments
+ find_all { |child| child.kind_of? Comment }.freeze
+ end
+
+ # Get an array of all Instruction children.
+ # IMMUTABLE
+ def instructions
+ find_all { |child| child.kind_of? Instruction }.freeze
+ end
+
+ # Get an array of all Text children.
+ # IMMUTABLE
+ def texts
+ find_all { |child| child.kind_of? Text }.freeze
+ end
+
+ # Writes out this element, and recursively, all children.
+ # output::
+ # output an object which supports '<< string'; this is where the
+ # document will be written.
+ # indent::
+ # An integer. If -1, no indenting will be used; otherwise, the
+ # indentation will be this number of spaces, and children will be
+ # indented an additional amount. Defaults to -1
+ # transitive::
+ # If transitive is true and indent is >= 0, then the output will be
+ # pretty-printed in such a way that the added whitespace does not affect
+ # the parse tree of the document
+ # ie_hack::
+ # Internet Explorer is the worst piece of crap to have ever been
+ # written, with the possible exception of Windows itself. Since IE is
+ # unable to parse proper XML, we have to provide a hack to generate XML
+ # that IE's limited abilities can handle. This hack inserts a space
+ # before the /> on empty tags. Defaults to false
+ #
+ # out = ''
+ # doc.write( out ) #-> doc is written to the string 'out'
+ # doc.write( $stdout ) #-> doc written to the console
+ def write(writer=$stdout, indent=-1, transitive=false, ie_hack=false)
+ #print "ID:#{indent}"
+ writer << "<#@expanded_name"
+
+ @attributes.each_attribute do |attr|
+ writer << " "
+ attr.write( writer, indent )
+ end unless @attributes.empty?
+
+ if @children.empty?
+ if transitive and indent>-1
+ writer << "\n"
+ indent( writer, indent )
+ elsif ie_hack
+ writer << " "
end
- formatter.write( self, output )
- end
-
-
- private
+ writer << "/"
+ else
+ if transitive and indent>-1 and !@children[0].kind_of? Text
+ writer << "\n"
+ indent writer, indent+1
+ end
+ writer << ">"
+ write_children( writer, indent, transitive, ie_hack )
+ writer << "</#{expanded_name}"
+ end
+ if transitive and indent>-1 and !@children.empty?
+ writer << "\n"
+ indent -= 1 if next_sibling.nil?
+ indent(writer, indent)
+ end
+ writer << ">"
+ end
+
+
+ private
def __to_xpath_helper node
rv = node.expanded_name.clone
if node.parent
@@ -701,514 +721,528 @@ module REXML
rv
end
- # A private helper method
- def each_with_something( test, max=0, name=nil )
- num = 0
- child=nil
- @elements.each( name ){ |child|
- yield child if test.call(child) and num += 1
- return if max>0 and num == max
- }
- end
- end
-
- ########################################################################
- # ELEMENTS #
- ########################################################################
-
- # A class which provides filtering of children for Elements, and
- # XPath search support. You are expected to only encounter this class as
- # the <tt>element.elements</tt> object. Therefore, you are
- # _not_ expected to instantiate this yourself.
- class Elements
- include Enumerable
- # Constructor
- # parent:: the parent Element
- def initialize parent
- @element = parent
- end
-
- # Fetches a child element. Filters only Element children, regardless of
- # the XPath match.
- # index::
- # the search parameter. This is either an Integer, which
- # will be used to find the index'th child Element, or an XPath,
- # which will be used to search for the Element. <em>Because
- # of the nature of XPath searches, any element in the connected XML
- # document can be fetched through any other element.</em> <b>The
- # Integer index is 1-based, not 0-based.</b> This means that the first
- # child element is at index 1, not 0, and the +n+th element is at index
- # +n+, not <tt>n-1</tt>. This is because XPath indexes element children
- # starting from 1, not 0, and the indexes should be the same.
- # name::
- # optional, and only used in the first argument is an
- # Integer. In that case, the index'th child Element that has the
- # supplied name will be returned. Note again that the indexes start at 1.
- # Returns:: the first matching Element, or nil if no child matched
- # doc = Document.new '<a><b/><c id="1"/><c id="2"/><d/></a>'
- # doc.root.elements[1] #-> <b/>
- # doc.root.elements['c'] #-> <c id="1"/>
- # doc.root.elements[2,'c'] #-> <c id="2"/>
- def []( index, name=nil)
- if index.kind_of? Integer
- raise "index (#{index}) must be >= 1" if index < 1
- name = literalize(name) if name
- num = 0
- child = nil
- @element.find { |child|
- child.kind_of? Element and
- (name.nil? ? true : child.has_name?( name )) and
- (num += 1) == index
- }
- else
- return XPath::first( @element, index )
- #{ |element|
- # return element if element.kind_of? Element
- #}
- #return nil
- end
- end
-
- # Sets an element, replacing any previous matching element. If no
- # existing element is found ,the element is added.
- # index:: Used to find a matching element to replace. See []().
- # element::
- # The element to replace the existing element with
- # the previous element
- # Returns:: nil if no previous element was found.
- #
- # doc = Document.new '<a/>'
- # doc.root.elements[10] = Element.new('b') #-> <a><b/></a>
- # doc.root.elements[1] #-> <b/>
- # doc.root.elements[1] = Element.new('c') #-> <a><c/></a>
- # doc.root.elements['c'] = Element.new('d') #-> <a><d/></a>
- def []=( index, element )
- previous = self[index]
- if previous.nil?
- @element.add element
- else
- previous.replace_with element
- end
- return previous
- end
-
- # Returns +true+ if there are no +Element+ children, +false+ otherwise
- def empty?
- @element.find{ |child| child.kind_of? Element}.nil?
- end
-
- # Returns the index of the supplied child (starting at 1), or -1 if
- # the element is not a child
- # element:: an +Element+ child
- def index element
- rv = 0
- found = @element.find do |child|
- child.kind_of? Element and
- (rv += 1) and
- child == element
- end
- return rv if found == element
- return -1
- end
-
- # Deletes a child Element
- # element::
- # Either an Element, which is removed directly; an
- # xpath, where the first matching child is removed; or an Integer,
- # where the n'th Element is removed.
- # Returns:: the removed child
- # doc = Document.new '<a><b/><c/><c id="1"/></a>'
- # b = doc.root.elements[1]
- # doc.root.elements.delete b #-> <a><c/><c id="1"/></a>
- # doc.elements.delete("a/c[@id='1']") #-> <a><c/></a>
- # doc.root.elements.delete 1 #-> <a/>
- def delete element
- if element.kind_of? Element
- @element.delete element
- else
- el = self[element]
- el.remove if el
- end
- end
-
- # Removes multiple elements. Filters for Element children, regardless of
- # XPath matching.
- # xpath:: all elements matching this String path are removed.
- # Returns:: an Array of Elements that have been removed
- # doc = Document.new '<a><c/><c/><c/><c/></a>'
- # deleted = doc.elements.delete_all 'a/c' #-> [<c/>, <c/>, <c/>, <c/>]
- def delete_all( xpath )
- rv = []
- XPath::each( @element, xpath) {|element|
- rv << element if element.kind_of? Element
- }
- rv.each do |element|
- @element.delete element
- element.remove
- end
- return rv
- end
-
- # Adds an element
- # element::
- # if supplied, is either an Element, String, or
- # Source (see Element.initialize). If not supplied or nil, a
- # new, default Element will be constructed
- # Returns:: the added Element
- # a = Element.new('a')
- # a.elements.add(Element.new('b')) #-> <a><b/></a>
- # a.elements.add('c') #-> <a><b/><c/></a>
- def add element=nil
- rv = nil
- if element.nil?
- Element.new("", self, @element.context)
- elsif not element.kind_of?(Element)
- Element.new(element, self, @element.context)
- else
- @element << element
- element.context = @element.context
- element
- end
- end
-
- alias :<< :add
-
- # Iterates through all of the child Elements, optionally filtering
- # them by a given XPath
- # xpath::
- # optional. If supplied, this is a String XPath, and is used to
- # filter the children, so that only matching children are yielded. Note
- # that XPaths are automatically filtered for Elements, so that
- # non-Element children will not be yielded
- # doc = Document.new '<a><b/><c/><d/>sean<b/><c/><d/></a>'
- # doc.root.each {|e|p e} #-> Yields b, c, d, b, c, d elements
- # doc.root.each('b') {|e|p e} #-> Yields b, b elements
- # doc.root.each('child::node()') {|e|p e}
- # #-> Yields <b/>, <c/>, <d/>, <b/>, <c/>, <d/>
- # XPath.each(doc.root, 'child::node()', &block)
- # #-> Yields <b/>, <c/>, <d/>, sean, <b/>, <c/>, <d/>
- def each( xpath=nil, &block)
- XPath::each( @element, xpath ) {|e| yield e if e.kind_of? Element }
- end
-
- def collect( xpath=nil, &block )
- collection = []
- XPath::each( @element, xpath ) {|e|
- collection << yield(e) if e.kind_of?(Element)
- }
- collection
- end
-
- def inject( xpath=nil, initial=nil, &block )
- first = true
- XPath::each( @element, xpath ) {|e|
- if (e.kind_of? Element)
- if (first and initial == nil)
- initial = e
- first = false
- else
- initial = yield( initial, e ) if e.kind_of? Element
- end
- end
- }
- initial
- end
-
- # Returns the number of +Element+ children of the parent object.
- # doc = Document.new '<a>sean<b/>elliott<b/>russell<b/></a>'
- # doc.root.size #-> 6, 3 element and 3 text nodes
- # doc.root.elements.size #-> 3
- def size
- count = 0
- @element.each {|child| count+=1 if child.kind_of? Element }
- count
- end
-
- # Returns an Array of Element children. An XPath may be supplied to
- # filter the children. Only Element children are returned, even if the
- # supplied XPath matches non-Element children.
- # doc = Document.new '<a>sean<b/>elliott<c/></a>'
- # doc.root.elements.to_a #-> [ <b/>, <c/> ]
- # doc.root.elements.to_a("child::node()") #-> [ <b/>, <c/> ]
- # XPath.match(doc.root, "child::node()") #-> [ sean, <b/>, elliott, <c/> ]
- def to_a( xpath=nil )
- rv = XPath.match( @element, xpath )
- return rv.find_all{|e| e.kind_of? Element} if xpath
- rv
- end
-
- private
- # Private helper class. Removes quotes from quoted strings
- def literalize name
- name = name[1..-2] if name[0] == ?' or name[0] == ?" #'
- name
- end
- end
-
- ########################################################################
- # ATTRIBUTES #
- ########################################################################
-
- # A class that defines the set of Attributes of an Element and provides
- # operations for accessing elements in that set.
- class Attributes < Hash
- # Constructor
- # element:: the Element of which this is an Attribute
- def initialize element
- @element = element
- end
-
- # Fetches an attribute value. If you want to get the Attribute itself,
- # use get_attribute()
- # name:: an XPath attribute name. Namespaces are relevant here.
- # Returns::
- # the String value of the matching attribute, or +nil+ if no
- # matching attribute was found. This is the unnormalized value
- # (with entities expanded).
- #
- # doc = Document.new "<a foo:att='1' bar:att='2' att='&lt;'/>"
- # doc.root.attributes['att'] #-> '<'
- # doc.root.attributes['bar:att'] #-> '2'
- def [](name)
- attr = get_attribute(name)
- return attr.value unless attr.nil?
- return nil
- end
-
- def to_a
- values.flatten
- end
-
- # Returns the number of attributes the owning Element contains.
- # doc = Document "<a x='1' y='2' foo:x='3'/>"
- # doc.root.attributes.length #-> 3
- def length
- c = 0
- each_attribute { c+=1 }
- c
- end
- alias :size :length
-
- # Itterates over the attributes of an Element. Yields actual Attribute
- # nodes, not String values.
- #
- # doc = Document.new '<a x="1" y="2"/>'
- # doc.root.attributes.each_attribute {|attr|
- # p attr.expanded_name+" => "+attr.value
- # }
- def each_attribute # :yields: attribute
- each_value do |val|
- if val.kind_of? Attribute
- yield val
- else
- val.each_value { |atr| yield atr }
- end
- end
- end
-
- # Itterates over each attribute of an Element, yielding the expanded name
- # and value as a pair of Strings.
- #
- # doc = Document.new '<a x="1" y="2"/>'
- # doc.root.attributes.each {|name, value| p name+" => "+value }
- def each
- each_attribute do |attr|
- yield attr.expanded_name, attr.value
- end
- end
-
- # Fetches an attribute
- # name::
- # the name by which to search for the attribute. Can be a
- # <tt>prefix:name</tt> namespace name.
- # Returns:: The first matching attribute, or nil if there was none. This
- # value is an Attribute node, not the String value of the attribute.
- # doc = Document.new '<a x:foo="1" foo="2" bar="3"/>'
- # doc.root.attributes.get_attribute("foo").value #-> "2"
- # doc.root.attributes.get_attribute("x:foo").value #-> "1"
- def get_attribute( name )
- attr = fetch( name, nil )
- if attr.nil?
- return nil if name.nil?
- # Look for prefix
- name =~ Namespace::NAMESPLIT
- prefix, n = $1, $2
- if prefix
- attr = fetch( n, nil )
- # check prefix
- if attr == nil
- elsif attr.kind_of? Attribute
- return attr if prefix == attr.prefix
- else
- attr = attr[ prefix ]
- return attr
- end
- end
+ # A private helper method
+ def each_with_something( test, max=0, name=nil )
+ num = 0
+ child=nil
+ @elements.each( name ){ |child|
+ yield child if test.call(child) and num += 1
+ return if max>0 and num == max
+ }
+ end
+
+ # A private helper method
+ def write_children( writer, indent, transitive, ie_hack )
+ cr = (indent < 0) ? '' : "\n"
+ if indent == -1
+ each { |child| child.write( writer, indent, transitive, ie_hack ) }
+ else
+ next_indent = indent+1
+ last_child=nil
+ each { |child|
+ unless child.kind_of? Text or last_child.kind_of? Text or transitive
+ writer << cr
+ indent(writer, next_indent)
+ end
+ child.write( writer, next_indent, transitive, ie_hack )
+ last_child = child
+ }
+ unless last_child.kind_of? Text or transitive
+ writer << cr
+ indent( writer, indent )
+ end
+ end
+ end
+ end
+
+ ########################################################################
+ # ELEMENTS #
+ ########################################################################
+
+ # A class which provides filtering of children for Elements, and
+ # XPath search support. You are expected to only encounter this class as
+ # the <tt>element.elements</tt> object. Therefore, you are
+ # _not_ expected to instantiate this yourself.
+ class Elements
+ include Enumerable
+ # Constructor
+ # parent:: the parent Element
+ def initialize parent
+ @element = parent
+ end
+
+ # Fetches a child element. Filters only Element children, regardless of
+ # the XPath match.
+ # index::
+ # the search parameter. This is either an Integer, which
+ # will be used to find the index'th child Element, or an XPath,
+ # which will be used to search for the Element. <em>Because
+ # of the nature of XPath searches, any element in the connected XML
+ # document can be fetched through any other element.</em> <b>The
+ # Integer index is 1-based, not 0-based.</b> This means that the first
+ # child element is at index 1, not 0, and the +n+th element is at index
+ # +n+, not <tt>n-1</tt>. This is because XPath indexes element children
+ # starting from 1, not 0, and the indexes should be the same.
+ # name::
+ # optional, and only used in the first argument is an
+ # Integer. In that case, the index'th child Element that has the
+ # supplied name will be returned. Note again that the indexes start at 1.
+ # Returns:: the first matching Element, or nil if no child matched
+ # doc = Document.new '<a><b/><c id="1"/><c id="2"/><d/></a>'
+ # doc.root.elements[1] #-> <b/>
+ # doc.root.elements['c'] #-> <c id="1"/>
+ # doc.root.elements[2,'c'] #-> <c id="2"/>
+ def []( index, name=nil)
+ if index.kind_of? Integer
+ raise "index (#{index}) must be >= 1" if index < 1
+ name = literalize(name) if name
+ num = 0
+ child = nil
+ @element.find { |child|
+ child.kind_of? Element and
+ (name.nil? ? true : child.has_name?( name )) and
+ (num += 1) == index
+ }
+ else
+ return XPath::first( @element, index )
+ #{ |element|
+ # return element if element.kind_of? Element
+ #}
+ #return nil
+ end
+ end
+
+ # Sets an element, replacing any previous matching element. If no
+ # existing element is found ,the element is added.
+ # index:: Used to find a matching element to replace. See []().
+ # element::
+ # The element to replace the existing element with
+ # the previous element
+ # Returns:: nil if no previous element was found.
+ #
+ # doc = Document.new '<a/>'
+ # doc.root.elements[10] = Element.new('b') #-> <a><b/></a>
+ # doc.root.elements[1] #-> <b/>
+ # doc.root.elements[1] = Element.new('c') #-> <a><c/></a>
+ # doc.root.elements['c'] = Element.new('d') #-> <a><d/></a>
+ def []=( index, element )
+ previous = self[index]
+ if previous.nil?
+ @element.add element
+ else
+ previous.replace_with element
+ end
+ return previous
+ end
+
+ # Returns +true+ if there are no +Element+ children, +false+ otherwise
+ def empty?
+ @element.find{ |child| child.kind_of? Element}.nil?
+ end
+
+ # Returns the index of the supplied child (starting at 1), or -1 if
+ # the element is not a child
+ # element:: an +Element+ child
+ def index element
+ rv = 0
+ found = @element.find do |child|
+ child.kind_of? Element and
+ (rv += 1) and
+ child == element
+ end
+ return rv if found == element
+ return -1
+ end
+
+ # Deletes a child Element
+ # element::
+ # Either an Element, which is removed directly; an
+ # xpath, where the first matching child is removed; or an Integer,
+ # where the n'th Element is removed.
+ # Returns:: the removed child
+ # doc = Document.new '<a><b/><c/><c id="1"/></a>'
+ # b = doc.root.elements[1]
+ # doc.root.elements.delete b #-> <a><c/><c id="1"/></a>
+ # doc.elements.delete("a/c[@id='1']") #-> <a><c/></a>
+ # doc.root.elements.delete 1 #-> <a/>
+ def delete element
+ if element.kind_of? Element
+ @element.delete element
+ else
+ el = self[element]
+ el.remove if el
+ end
+ end
+
+ # Removes multiple elements. Filters for Element children, regardless of
+ # XPath matching.
+ # xpath:: all elements matching this String path are removed.
+ # Returns:: an Array of Elements that have been removed
+ # doc = Document.new '<a><c/><c/><c/><c/></a>'
+ # deleted = doc.elements.delete_all 'a/c' #-> [<c/>, <c/>, <c/>, <c/>]
+ def delete_all( xpath )
+ rv = []
+ XPath::each( @element, xpath) {|element|
+ rv << element if element.kind_of? Element
+ }
+ rv.each do |element|
+ @element.delete element
+ element.remove
+ end
+ return rv
+ end
+
+ # Adds an element
+ # element::
+ # if supplied, is either an Element, String, or
+ # Source (see Element.initialize). If not supplied or nil, a
+ # new, default Element will be constructed
+ # Returns:: the added Element
+ # a = Element.new 'a'
+ # a.elements.add Element.new 'b' #-> <a><b/></a>
+ # a.elements.add 'c' #-> <a><b/><c/></a>
+ def add element=nil
+ rv = nil
+ if element.nil?
+ Element.new "", self, @element.context
+ elsif not element.kind_of?(Element)
+ Element.new element, self, @element.context
+ else
+ @element << element
+ element.context = @element.context
+ element
+ end
+ end
+
+ alias :<< :add
+
+ # Iterates through all of the child Elements, optionally filtering
+ # them by a given XPath
+ # xpath::
+ # optional. If supplied, this is a String XPath, and is used to
+ # filter the children, so that only matching children are yielded. Note
+ # that XPaths are automatically filtered for Elements, so that
+ # non-Element children will not be yielded
+ # doc = Document.new '<a><b/><c/><d/>sean<b/><c/><d/></a>'
+ # doc.root.each {|e|p e} #-> Yields b, c, d, b, c, d elements
+ # doc.root.each('b') {|e|p e} #-> Yields b, b elements
+ # doc.root.each('child::node()') {|e|p e}
+ # #-> Yields <b/>, <c/>, <d/>, <b/>, <c/>, <d/>
+ # XPath.each(doc.root, 'child::node()', &block)
+ # #-> Yields <b/>, <c/>, <d/>, sean, <b/>, <c/>, <d/>
+ def each( xpath=nil, &block)
+ XPath::each( @element, xpath ) {|e| yield e if e.kind_of? Element }
+ end
+
+ def collect( xpath=nil, &block )
+ collection = []
+ XPath::each( @element, xpath ) {|e|
+ collection << yield(e) if e.kind_of?(Element)
+ }
+ collection
+ end
+
+ def inject( xpath=nil, initial=nil, &block )
+ first = true
+ XPath::each( @element, xpath ) {|e|
+ if (e.kind_of? Element)
+ if (first and initial == nil)
+ initial = e
+ first = false
+ else
+ initial = yield( initial, e ) if e.kind_of? Element
+ end
+ end
+ }
+ initial
+ end
+
+ # Returns the number of +Element+ children of the parent object.
+ # doc = Document.new '<a>sean<b/>elliott<b/>russell<b/></a>'
+ # doc.root.size #-> 6, 3 element and 3 text nodes
+ # doc.root.elements.size #-> 3
+ def size
+ count = 0
+ @element.each {|child| count+=1 if child.kind_of? Element }
+ count
+ end
+
+ # Returns an Array of Element children. An XPath may be supplied to
+ # filter the children. Only Element children are returned, even if the
+ # supplied XPath matches non-Element children.
+ # doc = Document.new '<a>sean<b/>elliott<c/></a>'
+ # doc.root.elements.to_a #-> [ <b/>, <c/> ]
+ # doc.root.elements.to_a("child::node()") #-> [ <b/>, <c/> ]
+ # XPath.match(doc.root, "child::node()") #-> [ sean, <b/>, elliott, <c/> ]
+ def to_a( xpath=nil )
+ rv = XPath.match( @element, xpath )
+ return rv.find_all{|e| e.kind_of? Element} if xpath
+ rv
+ end
+
+ private
+ # Private helper class. Removes quotes from quoted strings
+ def literalize name
+ name = name[1..-2] if name[0] == ?' or name[0] == ?" #'
+ name
+ end
+ end
+
+ ########################################################################
+ # ATTRIBUTES #
+ ########################################################################
+
+ # A class that defines the set of Attributes of an Element and provides
+ # operations for accessing elements in that set.
+ class Attributes < Hash
+ # Constructor
+ # element:: the Element of which this is an Attribute
+ def initialize element
+ @element = element
+ end
+
+ # Fetches an attribute value. If you want to get the Attribute itself,
+ # use get_attribute()
+ # name:: an XPath attribute name. Namespaces are relevant here.
+ # Returns::
+ # the String value of the matching attribute, or +nil+ if no
+ # matching attribute was found.
+ #
+ # doc = Document.new "<a foo:att='1' bar:att='2' att='3'/>"
+ # doc.root.attributes['att'] #-> '3'
+ # doc.root.attributes['bar:att'] #-> '2'
+ def [](name)
+ attr = get_attribute(name)
+ return attr.value unless attr.nil?
+ return nil
+ end
+
+ def to_a
+ values.flatten
+ end
+
+ # Returns the number of attributes the owning Element contains.
+ # doc = Document "<a x='1' y='2' foo:x='3'/>"
+ # doc.root.attributes.length #-> 3
+ def length
+ c = 0
+ each_attribute { c+=1 }
+ c
+ end
+ alias :size :length
+
+ # Itterates over the attributes of an Element. Yields actual Attribute
+ # nodes, not String values.
+ #
+ # doc = Document.new '<a x="1" y="2"/>'
+ # doc.root.attributes.each_attribute {|attr|
+ # p attr.expanded_name+" => "+attr.value
+ # }
+ def each_attribute # :yields: attribute
+ each_value do |val|
+ if val.kind_of? Attribute
+ yield val
+ else
+ val.each_value { |atr| yield atr }
+ end
+ end
+ end
+
+ # Itterates over each attribute of an Element, yielding the expanded name
+ # and value as a pair of Strings.
+ #
+ # doc = Document.new '<a x="1" y="2"/>'
+ # doc.root.attributes.each {|name, value| p name+" => "+value }
+ def each
+ each_attribute do |attr|
+ yield attr.expanded_name, attr.value
+ end
+ end
+
+ # Fetches an attribute
+ # name::
+ # the name by which to search for the attribute. Can be a
+ # <tt>prefix:name</tt> namespace name.
+ # Returns:: The first matching attribute, or nil if there was none. This
+ # value is an Attribute node, not the String value of the attribute.
+ # doc = Document.new '<a x:foo="1" foo="2" bar="3"/>'
+ # doc.root.attributes.get_attribute("foo").value #-> "2"
+ # doc.root.attributes.get_attribute("x:foo").value #-> "1"
+ def get_attribute( name )
+ attr = fetch( name, nil )
+ if attr.nil?
+ return nil if name.nil?
+ # Look for prefix
+ name =~ Namespace::NAMESPLIT
+ prefix, n = $1, $2
+ if prefix
+ attr = fetch( n, nil )
+ # check prefix
+ if attr == nil
+ elsif attr.kind_of? Attribute
+ return attr if prefix == attr.prefix
+ else
+ attr = attr[ prefix ]
+ return attr
+ end
+ end
element_document = @element.document
- if element_document and element_document.doctype
- expn = @element.expanded_name
- expn = element_document.doctype.name if expn.size == 0
- attr_val = element_document.doctype.attribute_of(expn, name)
- return Attribute.new( name, attr_val ) if attr_val
- end
- return nil
- end
- if attr.kind_of? Hash
- attr = attr[ @element.prefix ]
- end
- return attr
- end
-
- # Sets an attribute, overwriting any existing attribute value by the
- # same name. Namespace is significant.
- # name:: the name of the attribute
- # value::
- # (optional) If supplied, the value of the attribute. If
- # nil, any existing matching attribute is deleted.
- # Returns::
- # Owning element
- # doc = Document.new "<a x:foo='1' foo='3'/>"
- # doc.root.attributes['y:foo'] = '2'
- # doc.root.attributes['foo'] = '4'
- # doc.root.attributes['x:foo'] = nil
- def []=( name, value )
- if value.nil? # Delete the named attribute
- attr = get_attribute(name)
- delete attr
- return
- end
- element_document = @element.document
- unless value.kind_of? Attribute
- if @element.document and @element.document.doctype
- value = Text::normalize( value, @element.document.doctype )
- else
- value = Text::normalize( value, nil )
- end
- value = Attribute.new(name, value)
- end
- value.element = @element
- old_attr = fetch(value.name, nil)
- if old_attr.nil?
- store(value.name, value)
- elsif old_attr.kind_of? Hash
- old_attr[value.prefix] = value
- elsif old_attr.prefix != value.prefix
- # Check for conflicting namespaces
- raise ParseException.new(
- "Namespace conflict in adding attribute \"#{value.name}\": "+
- "Prefix \"#{old_attr.prefix}\" = "+
- "\"#{@element.namespace(old_attr.prefix)}\" and prefix "+
- "\"#{value.prefix}\" = \"#{@element.namespace(value.prefix)}\"") if
- value.prefix != "xmlns" and old_attr.prefix != "xmlns" and
- @element.namespace( old_attr.prefix ) ==
- @element.namespace( value.prefix )
- store value.name, { old_attr.prefix => old_attr,
- value.prefix => value }
- else
- store value.name, value
- end
- return @element
- end
-
- # Returns an array of Strings containing all of the prefixes declared
- # by this set of # attributes. The array does not include the default
- # namespace declaration, if one exists.
- # doc = Document.new("<a xmlns='foo' xmlns:x='bar' xmlns:y='twee' "+
- # "z='glorp' p:k='gru'/>")
- # prefixes = doc.root.attributes.prefixes #-> ['x', 'y']
- def prefixes
- ns = []
- each_attribute do |attribute|
- ns << attribute.name if attribute.prefix == 'xmlns'
- end
- if @element.document and @element.document.doctype
- expn = @element.expanded_name
- expn = @element.document.doctype.name if expn.size == 0
- @element.document.doctype.attributes_of(expn).each {
- |attribute|
- ns << attribute.name if attribute.prefix == 'xmlns'
- }
- end
- ns
- end
-
- def namespaces
- namespaces = {}
- each_attribute do |attribute|
- namespaces[attribute.name] = attribute.value if attribute.prefix == 'xmlns' or attribute.name == 'xmlns'
- end
- if @element.document and @element.document.doctype
- expn = @element.expanded_name
- expn = @element.document.doctype.name if expn.size == 0
- @element.document.doctype.attributes_of(expn).each {
- |attribute|
- namespaces[attribute.name] = attribute.value if attribute.prefix == 'xmlns' or attribute.name == 'xmlns'
- }
- end
- namespaces
- end
-
- # Removes an attribute
- # attribute::
- # either a String, which is the name of the attribute to remove --
- # namespaces are significant here -- or the attribute to remove.
- # Returns:: the owning element
- # doc = Document.new "<a y:foo='0' x:foo='1' foo='3' z:foo='4'/>"
- # doc.root.attributes.delete 'foo' #-> <a y:foo='0' x:foo='1' z:foo='4'/>"
- # doc.root.attributes.delete 'x:foo' #-> <a y:foo='0' z:foo='4'/>"
- # attr = doc.root.attributes.get_attribute('y:foo')
- # doc.root.attributes.delete attr #-> <a z:foo='4'/>"
- def delete( attribute )
- name = nil
- prefix = nil
- if attribute.kind_of? Attribute
- name = attribute.name
- prefix = attribute.prefix
- else
- attribute =~ Namespace::NAMESPLIT
- prefix, name = $1, $2
- prefix = '' unless prefix
- end
- old = fetch(name, nil)
- attr = nil
- if old.kind_of? Hash # the supplied attribute is one of many
- attr = old.delete(prefix)
- if old.size == 1
- repl = nil
- old.each_value{|v| repl = v}
- store name, repl
- end
- elsif old.nil?
- return @element
- else # the supplied attribute is a top-level one
- attr = old
- res = super(name)
- end
- @element
- end
-
- # Adds an attribute, overriding any existing attribute by the
- # same name. Namespaces are significant.
- # attribute:: An Attribute
- def add( attribute )
- self[attribute.name] = attribute
- end
-
- alias :<< :add
-
- # Deletes all attributes matching a name. Namespaces are significant.
- # name::
- # A String; all attributes that match this path will be removed
- # Returns:: an Array of the Attributes that were removed
- def delete_all( name )
- rv = []
- each_attribute { |attribute|
- rv << attribute if attribute.expanded_name == name
- }
- rv.each{ |attr| attr.remove }
- return rv
- end
-
+ if element_document and element_document.doctype
+ expn = @element.expanded_name
+ expn = element_document.doctype.name if expn.size == 0
+ attr_val = element_document.doctype.attribute_of(expn, name)
+ return Attribute.new( name, attr_val ) if attr_val
+ end
+ return nil
+ end
+ if attr.kind_of? Hash
+ attr = attr[ @element.prefix ]
+ end
+ return attr
+ end
+
+ # Sets an attribute, overwriting any existing attribute value by the
+ # same name. Namespace is significant.
+ # name:: the name of the attribute
+ # value::
+ # (optional) If supplied, the value of the attribute. If
+ # nil, any existing matching attribute is deleted.
+ # Returns::
+ # Owning element
+ # doc = Document.new "<a x:foo='1' foo='3'/>"
+ # doc.root.attributes['y:foo'] = '2'
+ # doc.root.attributes['foo'] = '4'
+ # doc.root.attributes['x:foo'] = nil
+ def []=( name, value )
+ if value.nil? # Delete the named attribute
+ attr = get_attribute(name)
+ delete attr
+ return
+ end
+ value = Attribute.new(name, value) unless value.kind_of? Attribute
+ value.element = @element
+ old_attr = fetch(value.name, nil)
+ if old_attr.nil?
+ store(value.name, value)
+ elsif old_attr.kind_of? Hash
+ old_attr[value.prefix] = value
+ elsif old_attr.prefix != value.prefix
+ # Check for conflicting namespaces
+ raise ParseException.new(
+ "Namespace conflict in adding attribute \"#{value.name}\": "+
+ "Prefix \"#{old_attr.prefix}\" = "+
+ "\"#{@element.namespace(old_attr.prefix)}\" and prefix "+
+ "\"#{value.prefix}\" = \"#{@element.namespace(value.prefix)}\"") if
+ value.prefix != "xmlns" and old_attr.prefix != "xmlns" and
+ @element.namespace( old_attr.prefix ) ==
+ @element.namespace( value.prefix )
+ store value.name, { old_attr.prefix => old_attr,
+ value.prefix => value }
+ else
+ store value.name, value
+ end
+ return @element
+ end
+
+ # Returns an array of Strings containing all of the prefixes declared
+ # by this set of # attributes. The array does not include the default
+ # namespace declaration, if one exists.
+ # doc = Document.new("<a xmlns='foo' xmlns:x='bar' xmlns:y='twee' "+
+ # "z='glorp' p:k='gru'/>")
+ # prefixes = doc.root.attributes.prefixes #-> ['x', 'y']
+ def prefixes
+ ns = []
+ each_attribute do |attribute|
+ ns << attribute.name if attribute.prefix == 'xmlns'
+ end
+ if @element.document and @element.document.doctype
+ expn = @element.expanded_name
+ expn = @element.document.doctype.name if expn.size == 0
+ @element.document.doctype.attributes_of(expn).each {
+ |attribute|
+ ns << attribute.name if attribute.prefix == 'xmlns'
+ }
+ end
+ ns
+ end
+
+ def namespaces
+ namespaces = {}
+ each_attribute do |attribute|
+ namespaces[attribute.name] = attribute.value if attribute.prefix == 'xmlns' or attribute.name == 'xmlns'
+ end
+ if @element.document and @element.document.doctype
+ expn = @element.expanded_name
+ expn = @element.document.doctype.name if expn.size == 0
+ @element.document.doctype.attributes_of(expn).each {
+ |attribute|
+ namespaces[attribute.name] = attribute.value if attribute.prefix == 'xmlns' or attribute.name == 'xmlns'
+ }
+ end
+ namespaces
+ end
+
+ # Removes an attribute
+ # attribute::
+ # either a String, which is the name of the attribute to remove --
+ # namespaces are significant here -- or the attribute to remove.
+ # Returns:: the owning element
+ # doc = Document.new "<a y:foo='0' x:foo='1' foo='3' z:foo='4'/>"
+ # doc.root.attributes.delete 'foo' #-> <a y:foo='0' x:foo='1' z:foo='4'/>"
+ # doc.root.attributes.delete 'x:foo' #-> <a y:foo='0' z:foo='4'/>"
+ # attr = doc.root.attributes.get_attribute('y:foo')
+ # doc.root.attributes.delete attr #-> <a z:foo='4'/>"
+ def delete( attribute )
+ name = nil
+ prefix = nil
+ if attribute.kind_of? Attribute
+ name = attribute.name
+ prefix = attribute.prefix
+ else
+ attribute =~ Namespace::NAMESPLIT
+ prefix, name = $1, $2
+ prefix = '' unless prefix
+ end
+ old = fetch(name, nil)
+ attr = nil
+ if old.kind_of? Hash # the supplied attribute is one of many
+ attr = old.delete(prefix)
+ if old.size == 1
+ repl = nil
+ old.each_value{|v| repl = v}
+ store name, repl
+ end
+ elsif old.nil?
+ return @element
+ else # the supplied attribute is a top-level one
+ attr = old
+ res = super(name)
+ end
+ @element
+ end
+
+ # Adds an attribute, overriding any existing attribute by the
+ # same name. Namespaces are significant.
+ # attribute:: An Attribute
+ def add( attribute )
+ self[attribute.name] = attribute
+ end
+
+ alias :<< :add
+
+ # Deletes all attributes matching a name. Namespaces are significant.
+ # name::
+ # A String; all attributes that match this path will be removed
+ # Returns:: an Array of the Attributes that were removed
+ def delete_all( name )
+ rv = []
+ each_attribute { |attribute|
+ rv << attribute if attribute.expanded_name == name
+ }
+ rv.each{ |attr| attr.remove }
+ return rv
+ end
+
# The +get_attribute_ns+ method retrieves a method by its namespace
# and name. Thus it is possible to reliably identify an attribute
# even if an XML processor has changed the prefix.
@@ -1217,11 +1251,11 @@ module REXML
def get_attribute_ns(namespace, name)
each_attribute() { |attribute|
if name == attribute.name &&
- namespace == attribute.namespace()
+ namespace == attribute.namespace()
return attribute
end
}
nil
end
- end
+ end
end
diff --git a/lib/rexml/encoding.rb b/lib/rexml/encoding.rb
index a01763be99..e35c3acf7c 100644
--- a/lib/rexml/encoding.rb
+++ b/lib/rexml/encoding.rb
@@ -56,15 +56,10 @@ module REXML
def check_encoding str
# We have to recognize UTF-16, LSB UTF-16, and UTF-8
- if str[0] == 0xfe && str[1] == 0xff
- str[0,2] = ""
- return UTF_16
- elsif str[0] == 0xff && str[1] == 0xfe
- str[0,2] = ""
- return UNILE
- end
- str =~ /^\s*<\?xml\s+version\s*=\s*(['"]).*?\1\s+encoding\s*=\s*(["'])(.*?)\2/um
- return $3.upcase if $3
+ return UTF_16 if /\A\xfe\xff/n =~ str
+ return UNILE if /\A\xff\xfe/n =~ str
+ str =~ /^\s*<?xml\s*version\s*=\s*(['"]).*?\2\s*encoding\s*=\s*(["'])(.*?)\2/um
+ return $1.upcase if $1
return UTF_8
end
end
diff --git a/lib/rexml/encodings/CP-1252.rb b/lib/rexml/encodings/CP-1252.rb
index 8675f9ff98..51179f119f 100644
--- a/lib/rexml/encodings/CP-1252.rb
+++ b/lib/rexml/encodings/CP-1252.rb
@@ -3,49 +3,43 @@
#
module REXML
module Encoding
- register( "CP-1252" ) do |o|
- class << o
- alias encode encode_cp1252
- alias decode decode_cp1252
- end
- end
-
+ @@__REXML_encoding_methods = %q~
# Convert from UTF-8
- def encode_cp1252(content)
+ def encode content
array_utf8 = content.unpack('U*')
array_enc = []
array_utf8.each do |num|
case num
# shortcut first bunch basic characters
- when 0..0xFF; array_enc << num
+ when 0..0xFF: array_enc << num
# characters added compared to iso-8859-1
- when 0x20AC; array_enc << 0x80 # 0xe2 0x82 0xac
- when 0x201A; array_enc << 0x82 # 0xe2 0x82 0x9a
- when 0x0192; array_enc << 0x83 # 0xc6 0x92
- when 0x201E; array_enc << 0x84 # 0xe2 0x82 0x9e
- when 0x2026; array_enc << 0x85 # 0xe2 0x80 0xa6
- when 0x2020; array_enc << 0x86 # 0xe2 0x80 0xa0
- when 0x2021; array_enc << 0x87 # 0xe2 0x80 0xa1
- when 0x02C6; array_enc << 0x88 # 0xcb 0x86
- when 0x2030; array_enc << 0x89 # 0xe2 0x80 0xb0
- when 0x0160; array_enc << 0x8A # 0xc5 0xa0
- when 0x2039; array_enc << 0x8B # 0xe2 0x80 0xb9
- when 0x0152; array_enc << 0x8C # 0xc5 0x92
- when 0x017D; array_enc << 0x8E # 0xc5 0xbd
- when 0x2018; array_enc << 0x91 # 0xe2 0x80 0x98
- when 0x2019; array_enc << 0x92 # 0xe2 0x80 0x99
- when 0x201C; array_enc << 0x93 # 0xe2 0x80 0x9c
- when 0x201D; array_enc << 0x94 # 0xe2 0x80 0x9d
- when 0x2022; array_enc << 0x95 # 0xe2 0x80 0xa2
- when 0x2013; array_enc << 0x96 # 0xe2 0x80 0x93
- when 0x2014; array_enc << 0x97 # 0xe2 0x80 0x94
- when 0x02DC; array_enc << 0x98 # 0xcb 0x9c
- when 0x2122; array_enc << 0x99 # 0xe2 0x84 0xa2
- when 0x0161; array_enc << 0x9A # 0xc5 0xa1
- when 0x203A; array_enc << 0x9B # 0xe2 0x80 0xba
- when 0x0152; array_enc << 0x9C # 0xc5 0x93
- when 0x017E; array_enc << 0x9E # 0xc5 0xbe
- when 0x0178; array_enc << 0x9F # 0xc5 0xb8
+ when 0x20AC: array_enc << 0x80 # 0xe2 0x82 0xac
+ when 0x201A: array_enc << 0x82 # 0xe2 0x82 0x9a
+ when 0x0192: array_enc << 0x83 # 0xc6 0x92
+ when 0x201E: array_enc << 0x84 # 0xe2 0x82 0x9e
+ when 0x2026: array_enc << 0x85 # 0xe2 0x80 0xa6
+ when 0x2020: array_enc << 0x86 # 0xe2 0x80 0xa0
+ when 0x2021: array_enc << 0x87 # 0xe2 0x80 0xa1
+ when 0x02C6: array_enc << 0x88 # 0xcb 0x86
+ when 0x2030: array_enc << 0x89 # 0xe2 0x80 0xb0
+ when 0x0160: array_enc << 0x8A # 0xc5 0xa0
+ when 0x2039: array_enc << 0x8B # 0xe2 0x80 0xb9
+ when 0x0152: array_enc << 0x8C # 0xc5 0x92
+ when 0x017D: array_enc << 0x8E # 0xc5 0xbd
+ when 0x2018: array_enc << 0x91 # 0xe2 0x80 0x98
+ when 0x2019: array_enc << 0x92 # 0xe2 0x80 0x99
+ when 0x201C: array_enc << 0x93 # 0xe2 0x80 0x9c
+ when 0x201D: array_enc << 0x94 # 0xe2 0x80 0x9d
+ when 0x2022: array_enc << 0x95 # 0xe2 0x80 0xa2
+ when 0x2013: array_enc << 0x96 # 0xe2 0x80 0x93
+ when 0x2014: array_enc << 0x97 # 0xe2 0x80 0x94
+ when 0x02DC: array_enc << 0x98 # 0xcb 0x9c
+ when 0x2122: array_enc << 0x99 # 0xe2 0x84 0xa2
+ when 0x0161: array_enc << 0x9A # 0xc5 0xa1
+ when 0x203A: array_enc << 0x9B # 0xe2 0x80 0xba
+ when 0x0152: array_enc << 0x9C # 0xc5 0x93
+ when 0x017E: array_enc << 0x9E # 0xc5 0xbe
+ when 0x0178: array_enc << 0x9F # 0xc5 0xb8
else
# all remaining basic characters can be used directly
if num <= 0xFF
@@ -60,44 +54,45 @@ module REXML
end
# Convert to UTF-8
- def decode_cp1252(str)
+ def decode(str)
array_latin9 = str.unpack('C*')
array_enc = []
array_latin9.each do |num|
case num
# characters that added compared to iso-8859-1
- when 0x80; array_enc << 0x20AC # 0xe2 0x82 0xac
- when 0x82; array_enc << 0x201A # 0xe2 0x82 0x9a
- when 0x83; array_enc << 0x0192 # 0xc6 0x92
- when 0x84; array_enc << 0x201E # 0xe2 0x82 0x9e
- when 0x85; array_enc << 0x2026 # 0xe2 0x80 0xa6
- when 0x86; array_enc << 0x2020 # 0xe2 0x80 0xa0
- when 0x87; array_enc << 0x2021 # 0xe2 0x80 0xa1
- when 0x88; array_enc << 0x02C6 # 0xcb 0x86
- when 0x89; array_enc << 0x2030 # 0xe2 0x80 0xb0
- when 0x8A; array_enc << 0x0160 # 0xc5 0xa0
- when 0x8B; array_enc << 0x2039 # 0xe2 0x80 0xb9
- when 0x8C; array_enc << 0x0152 # 0xc5 0x92
- when 0x8E; array_enc << 0x017D # 0xc5 0xbd
- when 0x91; array_enc << 0x2018 # 0xe2 0x80 0x98
- when 0x92; array_enc << 0x2019 # 0xe2 0x80 0x99
- when 0x93; array_enc << 0x201C # 0xe2 0x80 0x9c
- when 0x94; array_enc << 0x201D # 0xe2 0x80 0x9d
- when 0x95; array_enc << 0x2022 # 0xe2 0x80 0xa2
- when 0x96; array_enc << 0x2013 # 0xe2 0x80 0x93
- when 0x97; array_enc << 0x2014 # 0xe2 0x80 0x94
- when 0x98; array_enc << 0x02DC # 0xcb 0x9c
- when 0x99; array_enc << 0x2122 # 0xe2 0x84 0xa2
- when 0x9A; array_enc << 0x0161 # 0xc5 0xa1
- when 0x9B; array_enc << 0x203A # 0xe2 0x80 0xba
- when 0x9C; array_enc << 0x0152 # 0xc5 0x93
- when 0x9E; array_enc << 0x017E # 0xc5 0xbe
- when 0x9F; array_enc << 0x0178 # 0xc5 0xb8
+ when 0x80: array_enc << 0x20AC # 0xe2 0x82 0xac
+ when 0x82: array_enc << 0x201A # 0xe2 0x82 0x9a
+ when 0x83: array_enc << 0x0192 # 0xc6 0x92
+ when 0x84: array_enc << 0x201E # 0xe2 0x82 0x9e
+ when 0x85: array_enc << 0x2026 # 0xe2 0x80 0xa6
+ when 0x86: array_enc << 0x2020 # 0xe2 0x80 0xa0
+ when 0x87: array_enc << 0x2021 # 0xe2 0x80 0xa1
+ when 0x88: array_enc << 0x02C6 # 0xcb 0x86
+ when 0x89: array_enc << 0x2030 # 0xe2 0x80 0xb0
+ when 0x8A: array_enc << 0x0160 # 0xc5 0xa0
+ when 0x8B: array_enc << 0x2039 # 0xe2 0x80 0xb9
+ when 0x8C: array_enc << 0x0152 # 0xc5 0x92
+ when 0x8E: array_enc << 0x017D # 0xc5 0xbd
+ when 0x91: array_enc << 0x2018 # 0xe2 0x80 0x98
+ when 0x92: array_enc << 0x2019 # 0xe2 0x80 0x99
+ when 0x93: array_enc << 0x201C # 0xe2 0x80 0x9c
+ when 0x94: array_enc << 0x201D # 0xe2 0x80 0x9d
+ when 0x95: array_enc << 0x2022 # 0xe2 0x80 0xa2
+ when 0x96: array_enc << 0x2013 # 0xe2 0x80 0x93
+ when 0x97: array_enc << 0x2014 # 0xe2 0x80 0x94
+ when 0x98: array_enc << 0x02DC # 0xcb 0x9c
+ when 0x99: array_enc << 0x2122 # 0xe2 0x84 0xa2
+ when 0x9A: array_enc << 0x0161 # 0xc5 0xa1
+ when 0x9B: array_enc << 0x203A # 0xe2 0x80 0xba
+ when 0x9C: array_enc << 0x0152 # 0xc5 0x93
+ when 0x9E: array_enc << 0x017E # 0xc5 0xbe
+ when 0x9F: array_enc << 0x0178 # 0xc5 0xb8
else
array_enc << num
end
end
array_enc.pack('U*')
end
+ ~
end
end
diff --git a/lib/rexml/encodings/ISO-8859-15.rb b/lib/rexml/encodings/ISO-8859-15.rb
index 8dea0d38a4..ce565e7dd5 100644
--- a/lib/rexml/encodings/ISO-8859-15.rb
+++ b/lib/rexml/encodings/ISO-8859-15.rb
@@ -3,37 +3,33 @@
#
module REXML
module Encoding
- register("ISO-8859-15") do |o|
- alias encode to_iso_8859_15
- alias decode from_iso_8859_15
- end
-
+ @@__REXML_encoding_methods = %q~
# Convert from UTF-8
- def to_iso_8859_15(content)
+ def to_iso_8859_15 content
array_utf8 = content.unpack('U*')
array_enc = []
array_utf8.each do |num|
case num
# shortcut first bunch basic characters
- when 0..0xA3; array_enc << num
+ when 0..0xA3: array_enc << num
# characters removed compared to iso-8859-1
- when 0xA4; array_enc << '&#164;'
- when 0xA6; array_enc << '&#166;'
- when 0xA8; array_enc << '&#168;'
- when 0xB4; array_enc << '&#180;'
- when 0xB8; array_enc << '&#184;'
- when 0xBC; array_enc << '&#188;'
- when 0xBD; array_enc << '&#189;'
- when 0xBE; array_enc << '&#190;'
+ when 0xA4: array_enc << '&#164;'
+ when 0xA6: array_enc << '&#166;'
+ when 0xA8: array_enc << '&#168;'
+ when 0xB4: array_enc << '&#180;'
+ when 0xB8: array_enc << '&#184;'
+ when 0xBC: array_enc << '&#188;'
+ when 0xBD: array_enc << '&#189;'
+ when 0xBE: array_enc << '&#190;'
# characters added compared to iso-8859-1
- when 0x20AC; array_enc << 0xA4 # 0xe2 0x82 0xac
- when 0x0160; array_enc << 0xA6 # 0xc5 0xa0
- when 0x0161; array_enc << 0xA8 # 0xc5 0xa1
- when 0x017D; array_enc << 0xB4 # 0xc5 0xbd
- when 0x017E; array_enc << 0xB8 # 0xc5 0xbe
- when 0x0152; array_enc << 0xBC # 0xc5 0x92
- when 0x0153; array_enc << 0xBD # 0xc5 0x93
- when 0x0178; array_enc << 0xBE # 0xc5 0xb8
+ when 0x20AC: array_enc << 0xA4 # 0xe2 0x82 0xac
+ when 0x0160: array_enc << 0xA6 # 0xc5 0xa0
+ when 0x0161: array_enc << 0xA8 # 0xc5 0xa1
+ when 0x017D: array_enc << 0xB4 # 0xc5 0xbd
+ when 0x017E: array_enc << 0xB8 # 0xc5 0xbe
+ when 0x0152: array_enc << 0xBC # 0xc5 0x92
+ when 0x0153: array_enc << 0xBD # 0xc5 0x93
+ when 0x0178: array_enc << 0xBE # 0xc5 0xb8
else
# all remaining basic characters can be used directly
if num <= 0xFF
@@ -54,19 +50,20 @@ module REXML
array_latin9.each do |num|
case num
# characters that differ compared to iso-8859-1
- when 0xA4; array_enc << 0x20AC
- when 0xA6; array_enc << 0x0160
- when 0xA8; array_enc << 0x0161
- when 0xB4; array_enc << 0x017D
- when 0xB8; array_enc << 0x017E
- when 0xBC; array_enc << 0x0152
- when 0xBD; array_enc << 0x0153
- when 0xBE; array_enc << 0x0178
+ when 0xA4: array_enc << 0x20AC
+ when 0xA6: array_enc << 0x0160
+ when 0xA8: array_enc << 0x0161
+ when 0xB4: array_enc << 0x017D
+ when 0xB8: array_enc << 0x017E
+ when 0xBC: array_enc << 0x0152
+ when 0xBD: array_enc << 0x0153
+ when 0xBE: array_enc << 0x0178
else
array_enc << num
end
end
array_enc.pack('U*')
end
+ ~
end
end
diff --git a/lib/rexml/encodings/SHIFT-JIS.rb b/lib/rexml/encodings/SHIFT-JIS.rb
index 9e0f4af20e..93c7877afd 100644
--- a/lib/rexml/encodings/SHIFT-JIS.rb
+++ b/lib/rexml/encodings/SHIFT-JIS.rb
@@ -13,8 +13,8 @@ module REXML
rescue LoadError
require 'nkf'
- SJISTOU8 = '-Swm0x'
- U8TOSJIS = '-Wsm0x'
+ SJISTOU8 = '-Swm0'
+ U8TOSJIS = '-Wsm0'
def decode_sjis(str)
NKF.nkf(SJISTOU8, str)
diff --git a/lib/rexml/encodings/UTF-16.rb b/lib/rexml/encodings/UTF-16.rb
index 007c493d9c..792adfd44d 100644
--- a/lib/rexml/encodings/UTF-16.rb
+++ b/lib/rexml/encodings/UTF-16.rb
@@ -16,7 +16,7 @@ module REXML
end
def decode_utf16(str)
- str = str[2..-1] if /^\376\377/n =~ str
+ str = str[2..-1] if /^\376\377/ =~ str
array_enc=str.unpack('C*')
array_utf8 = []
0.step(array_enc.size-1, 2){|i|
diff --git a/lib/rexml/entity.rb b/lib/rexml/entity.rb
index 7e9b4e5e1a..4b88a3c553 100644
--- a/lib/rexml/entity.rb
+++ b/lib/rexml/entity.rb
@@ -73,7 +73,6 @@ module REXML
# all entities -- both %ent; and &ent; entities. This differs from
# +value()+ in that +value+ only replaces %ent; entities.
def unnormalized
- document.record_entity_expansion unless document.nil?
v = value()
return nil if v.nil?
@unnormalized = Text::unnormalize(v, parent)
@@ -90,12 +89,6 @@ module REXML
# Write out a fully formed, correct entity definition (assuming the Entity
# object itself is valid.)
- #
- # out::
- # An object implementing <TT>&lt;&lt;<TT> to which the entity will be
- # output
- # indent::
- # *DEPRECATED* and ignored
def write out, indent=-1
out << '<!ENTITY '
out << '% ' if @reference
diff --git a/lib/rexml/formatters/default.rb b/lib/rexml/formatters/default.rb
deleted file mode 100644
index 77381bdf84..0000000000
--- a/lib/rexml/formatters/default.rb
+++ /dev/null
@@ -1,109 +0,0 @@
-module REXML
- module Formatters
- class Default
- # Prints out the XML document with no formatting -- except if id_hack is
- # set.
- #
- # ie_hack::
- # If set to true, then inserts whitespace before the close of an empty
- # tag, so that IE's bad XML parser doesn't choke.
- def initialize( ie_hack=false )
- @ie_hack = ie_hack
- end
-
- # Writes the node to some output.
- #
- # node::
- # The node to write
- # output::
- # A class implementing <TT>&lt;&lt;</TT>. Pass in an Output object to
- # change the output encoding.
- def write( node, output )
- case node
-
- when Document
- if node.xml_decl.encoding != "UTF-8" && !output.kind_of?(Output)
- output = Output.new( output, node.xml_decl.encoding )
- end
- write_document( node, output )
-
- when Element
- write_element( node, output )
-
- when Declaration, ElementDecl, NotationDecl, ExternalEntity, Entity,
- Attribute, AttlistDecl
- node.write( output,-1 )
-
- when Instruction
- write_instruction( node, output )
-
- when DocType, XMLDecl
- node.write( output )
-
- when Comment
- write_comment( node, output )
-
- when CData
- write_cdata( node, output )
-
- when Text
- write_text( node, output )
-
- else
- raise Exception.new("XML FORMATTING ERROR")
-
- end
- end
-
- protected
- def write_document( node, output )
- node.children.each { |child| write( child, output ) }
- end
-
- def write_element( node, output )
- output << "<#{node.expanded_name}"
-
- node.attributes.each_attribute do |attr|
- output << " "
- attr.write( output )
- end unless node.attributes.empty?
-
- if node.children.empty?
- output << " " if @ie_hack
- output << "/"
- else
- output << ">"
- node.children.each { |child|
- write( child, output )
- }
- output << "</#{node.expanded_name}"
- end
- output << ">"
- end
-
- def write_text( node, output )
- output << node.to_s()
- end
-
- def write_comment( node, output )
- output << Comment::START
- output << node.to_s
- output << Comment::STOP
- end
-
- def write_cdata( node, output )
- output << CData::START
- output << node.to_s
- output << CData::STOP
- end
-
- def write_instruction( node, output )
- output << Instruction::START.sub(/\\/u, '')
- output << node.target
- output << ' '
- output << node.content
- output << Instruction::STOP.sub(/\\/u, '')
- end
- end
- end
-end
diff --git a/lib/rexml/formatters/pretty.rb b/lib/rexml/formatters/pretty.rb
deleted file mode 100644
index 9766ea6348..0000000000
--- a/lib/rexml/formatters/pretty.rb
+++ /dev/null
@@ -1,138 +0,0 @@
-require 'rexml/formatters/default'
-
-module REXML
- module Formatters
- # Pretty-prints an XML document. This destroys whitespace in text nodes
- # and will insert carriage returns and indentations.
- #
- # TODO: Add an option to print attributes on new lines
- class Pretty < Default
-
- # If compact is set to true, then the formatter will attempt to use as
- # little space as possible
- attr_accessor :compact
- # The width of a page. Used for formatting text
- attr_accessor :width
-
- # Create a new pretty printer.
- #
- # output::
- # An object implementing '<<(String)', to which the output will be written.
- # indentation::
- # An integer greater than 0. The indentation of each level will be
- # this number of spaces. If this is < 1, the behavior of this object
- # is undefined. Defaults to 2.
- # ie_hack::
- # If true, the printer will insert whitespace before closing empty
- # tags, thereby allowing Internet Explorer's feeble XML parser to
- # function. Defaults to false.
- def initialize( indentation=2, ie_hack=false )
- @indentation = indentation
- @level = 0
- @ie_hack = ie_hack
- @width = 80
- end
-
- protected
- def write_element(node, output)
- output << ' '*@level
- output << "<#{node.expanded_name}"
-
- node.attributes.each_attribute do |attr|
- output << " "
- attr.write( output )
- end unless node.attributes.empty?
-
- if node.children.empty?
- if @ie_hack
- output << " "
- end
- output << "/"
- else
- output << ">"
- # If compact and all children are text, and if the formatted output
- # is less than the specified width, then try to print everything on
- # one line
- skip = false
- if compact
- if node.children.inject(true) {|s,c| s & c.kind_of?(Text)}
- string = ""
- old_level = @level
- @level = 0
- node.children.each { |child| write( child, string ) }
- @level = old_level
- if string.length < @width
- output << string
- skip = true
- end
- end
- end
- unless skip
- output << "\n"
- @level += @indentation
- node.children.each { |child|
- next if child.kind_of?(Text) and child.to_s.strip.length == 0
- write( child, output )
- output << "\n"
- }
- @level -= @indentation
- output << ' '*@level
- end
- output << "</#{node.expanded_name}"
- end
- output << ">"
- end
-
- def write_text( node, output )
- s = node.to_s()
- s.gsub!(/\s/,' ')
- s.squeeze!(" ")
- s = wrap(s, 80-@level)
- s = indent_text(s, @level, " ", true)
- output << (' '*@level + s)
- end
-
- def write_comment( node, output)
- output << ' ' * @level
- super
- end
-
- def write_cdata( node, output)
- output << ' ' * @level
- super
- end
-
- def write_document( node, output )
- # Ok, this is a bit odd. All XML documents have an XML declaration,
- # but it may not write itself if the user didn't specifically add it,
- # either through the API or in the input document. If it doesn't write
- # itself, then we don't need a carriage return... which makes this
- # logic more complex.
- node.children.each { |child|
- next if child == node.children[-1] and child.instance_of?(Text)
- unless child == node.children[0] or child.instance_of?(Text) or
- (child == node.children[1] and !node.children[0].writethis)
- output << "\n"
- end
- write( child, output )
- }
- end
-
- private
- def indent_text(string, level=1, style="\t", indentfirstline=true)
- return string if level < 0
- string.gsub(/\n/, "\n#{style*level}")
- end
-
- def wrap(string, width)
- # Recursivly wrap string at width.
- return string if string.length <= width
- place = string.rindex(' ', width) # Position in string with last ' ' before cutoff
- return string if place.nil?
- return string[0,place] + "\n" + wrap(string[place+1..-1], width)
- end
-
- end
- end
-end
-
diff --git a/lib/rexml/formatters/transitive.rb b/lib/rexml/formatters/transitive.rb
deleted file mode 100644
index 1d80f21fbb..0000000000
--- a/lib/rexml/formatters/transitive.rb
+++ /dev/null
@@ -1,56 +0,0 @@
-require 'rexml/formatters/pretty'
-
-module REXML
- module Formatters
- # The Transitive formatter writes an XML document that parses to an
- # identical document as the source document. This means that no extra
- # whitespace nodes are inserted, and whitespace within text nodes is
- # preserved. Within these constraints, the document is pretty-printed,
- # with whitespace inserted into the metadata to introduce formatting.
- #
- # Note that this is only useful if the original XML is not already
- # formatted. Since this formatter does not alter whitespace nodes, the
- # results of formatting already formatted XML will be odd.
- class Transitive < Default
- def initialize( indentation=2 )
- @indentation = indentation
- @level = 0
- end
-
- protected
- def write_element( node, output )
- output << "<#{node.expanded_name}"
-
- node.attributes.each_attribute do |attr|
- output << " "
- attr.write( output )
- end unless node.attributes.empty?
-
- output << "\n"
- output << ' '*@level
- if node.children.empty?
- output << "/"
- else
- output << ">"
- # If compact and all children are text, and if the formatted output
- # is less than the specified width, then try to print everything on
- # one line
- skip = false
- @level += @indentation
- node.children.each { |child|
- write( child, output )
- }
- @level -= @indentation
- output << "</#{node.expanded_name}"
- output << "\n"
- output << ' '*@level
- end
- output << ">"
- end
-
- def write_text( node, output )
- output << node.to_s()
- end
- end
- end
-end
diff --git a/lib/rexml/functions.rb b/lib/rexml/functions.rb
index 8293e9c5ac..cad4f6a8c9 100644
--- a/lib/rexml/functions.rb
+++ b/lib/rexml/functions.rb
@@ -339,6 +339,7 @@ module REXML
object.to_f
else
str = string( object )
+ #puts "STRING OF #{object.inspect} = #{str}"
# If XPath ever gets scientific notation...
#if str =~ /^\s*-?(\d*\.?\d+|\d+\.)([Ee]\d*)?\s*$/
if str =~ /^\s*-?(\d*\.?\d+|\d+\.)\s*$/
diff --git a/lib/rexml/instruction.rb b/lib/rexml/instruction.rb
index c16b894b4a..f24f7786f7 100644
--- a/lib/rexml/instruction.rb
+++ b/lib/rexml/instruction.rb
@@ -38,11 +38,7 @@ module REXML
Instruction.new self
end
- # == DEPRECATED
- # See the rexml/formatters package
- #
def write writer, indent=-1, transitive=false, ie_hack=false
- Kernel.warn( "#{self.class.name}.write is deprecated" )
indent(writer, indent)
writer << START.sub(/\\/u, '')
writer << @target
diff --git a/lib/rexml/node.rb b/lib/rexml/node.rb
index 9780376829..7226e5be6c 100644
--- a/lib/rexml/node.rb
+++ b/lib/rexml/node.rb
@@ -1,6 +1,4 @@
require "rexml/parseexception"
-require "rexml/formatters/pretty"
-require "rexml/formatters/default"
module REXML
# Represents a node in the tree. Nodes are never encountered except as
@@ -20,19 +18,10 @@ module REXML
@parent[ ind - 1 ]
end
- # indent::
- # *DEPRECATED* This parameter is now ignored. See the formatters in the
- # REXML::Formatters package for changing the output style.
- def to_s indent=nil
- unless indent.nil?
- Kernel.warn( "#{self.class.name}.to_s(indent) parameter is deprecated" )
- f = REXML::Formatters::Pretty.new( indent )
- f.write( self, rv, indent )
- else
- f = REXML::Formatters::Default.new
- f.write( self, rv = "" )
- end
- return rv
+ def to_s indent=-1
+ rv = ""
+ write rv,indent
+ rv
end
def indent to, ind
diff --git a/lib/rexml/parsers/baseparser.rb b/lib/rexml/parsers/baseparser.rb
index fc2354a67f..fecd801d6f 100644
--- a/lib/rexml/parsers/baseparser.rb
+++ b/lib/rexml/parsers/baseparser.rb
@@ -1,7 +1,5 @@
require 'rexml/parseexception'
-require 'rexml/undefinednamespaceexception'
require 'rexml/source'
-require 'set'
module REXML
module Parsers
@@ -26,8 +24,7 @@ module REXML
# Nat Price gave me some good ideas for the API.
class BaseParser
NCNAME_STR= '[\w:][\-\w\d.]*'
- NAME_STR= "(?:(#{NCNAME_STR}):)?(#{NCNAME_STR})"
- UNAME_STR= "(?:#{NCNAME_STR}:)?#{NCNAME_STR}"
+ NAME_STR= "(?:#{NCNAME_STR}:)?#{NCNAME_STR}"
NAMECHAR = '[\-\w\d\.:]'
NAME = "([\\w:]#{NAMECHAR}*)"
@@ -38,7 +35,7 @@ module REXML
DOCTYPE_START = /\A\s*<!DOCTYPE\s/um
DOCTYPE_PATTERN = /\s*<!DOCTYPE\s+(.*?)(\[|>)/um
- ATTRIBUTE_PATTERN = /\s*(#{NAME_STR})\s*=\s*(["'])(.*?)\4/um
+ ATTRIBUTE_PATTERN = /\s*(#{NAME_STR})\s*=\s*(["'])(.*?)\2/um
COMMENT_START = /\A<!--/u
COMMENT_PATTERN = /<!--(.*?)-->/um
CDATA_START = /\A<!\[CDATA\[/u
@@ -48,7 +45,7 @@ module REXML
XMLDECL_PATTERN = /<\?xml\s+(.*?)\?>/um
INSTRUCTION_START = /\A<\?/u
INSTRUCTION_PATTERN = /<\?(.*?)(\s+.*?)?\?>/um
- TAG_MATCH = /^<((?>#{NAME_STR}))\s*((?>\s+#{UNAME_STR}\s*=\s*(["']).*?\5)*)\s*(\/)?>/um
+ TAG_MATCH = /^<((?>#{NAME_STR}))\s*((?>\s+#{NAME_STR}\s*=\s*(["']).*?\3)*)\s*(\/)?>/um
CLOSE_MATCH = /^\s*<\/(#{NAME_STR})\s*>/um
VERSION = /\bversion\s*=\s*["'](.*?)['"]/um
@@ -56,7 +53,7 @@ module REXML
STANDALONE = /\bstandalone\s*=\s["'](.*?)['"]/um
ENTITY_START = /^\s*<!ENTITY/
- IDENTITY = /^([!\*\w\-]+)(\s+#{NCNAME_STR})?(\s+["'](.*?)['"])?(\s+['"](.*?)["'])?/u
+ IDENTITY = /^([!\*\w\-]+)(\s+#{NCNAME_STR})?(\s+["'].*?['"])?(\s+['"].*?["'])?/u
ELEMENTDECL_START = /^\s*<!ELEMENT/um
ELEMENTDECL_PATTERN = /^\s*(<!ELEMENT.*?)>/um
SYSTEMENTITY = /^\s*(%.*?;)\s*$/um
@@ -136,7 +133,6 @@ module REXML
@tags = []
@stack = []
@entities = []
- @nsstack = []
end
def position
@@ -192,7 +188,6 @@ module REXML
end
return [ :end_document ] if empty?
return @stack.shift if @stack.size > 0
- #STDERR.puts @source.encoding
@source.read if @source.buffer.size<2
#STDERR.puts "BUFFER = #{@source.buffer.inspect}"
if @document_status == nil
@@ -218,15 +213,14 @@ module REXML
return [ :processing_instruction, *@source.match(INSTRUCTION_PATTERN, true)[1,2] ]
when DOCTYPE_START
md = @source.match( DOCTYPE_PATTERN, true )
- @nsstack.unshift(curr_ns=Set.new)
identity = md[1]
close = md[2]
identity =~ IDENTITY
name = $1
- raise REXML::ParseException.new("DOCTYPE is missing a name") if name.nil?
+ raise REXML::ParseException("DOCTYPE is missing a name") if name.nil?
pub_sys = $2.nil? ? nil : $2.strip
- long_name = $4.nil? ? nil : $4.strip
- uri = $6.nil? ? nil : $6.strip
+ long_name = $3.nil? ? nil : $3.strip
+ uri = $4.nil? ? nil : $4.strip
args = [ :start_doctype, name, pub_sys, long_name, uri ]
if close == ">"
@document_status = :after_doctype
@@ -294,9 +288,6 @@ module REXML
val = attdef[3]
val = attdef[4] if val == "#FIXED "
pairs[attdef[0]] = val
- if attdef[0] =~ /^xmlns:(.*)/
- @nsstack[0] << $1
- end
end
end
return [ :attlistdecl, element, pairs, contents ]
@@ -321,7 +312,6 @@ module REXML
begin
if @source.buffer[0] == ?<
if @source.buffer[1] == ?/
- @nsstack.shift
last_tag = @tags.pop
#md = @source.match_to_consume( '>', CLOSE_MATCH)
md = @source.match( CLOSE_MATCH, true )
@@ -355,47 +345,19 @@ module REXML
raise REXML::ParseException.new("missing attribute quote", @source) if @source.match(MISSING_ATTRIBUTE_QUOTES )
raise REXML::ParseException.new("malformed XML: missing tag start", @source)
end
- attributes = {}
- prefixes = Set.new
- prefixes << md[2] if md[2]
- @nsstack.unshift(curr_ns=Set.new)
- if md[4].size > 0
- attrs = md[4].scan( ATTRIBUTE_PATTERN )
+ attrs = []
+ if md[2].size > 0
+ attrs = md[2].scan( ATTRIBUTE_PATTERN )
raise REXML::ParseException.new( "error parsing attributes: [#{attrs.join ', '}], excess = \"#$'\"", @source) if $' and $'.strip.size > 0
- attrs.each { |a,b,c,d,e|
- if b == "xmlns"
- if c == "xml"
- if d != "http://www.w3.org/XML/1998/namespace"
- msg = "The 'xml' prefix must not be bound to any other namespace "+
- "(http://www.w3.org/TR/REC-xml-names/#ns-decl)"
- raise REXML::ParseException.new( msg, @source, self )
- end
- elsif c == "xmlns"
- msg = "The 'xmlns' prefix must not be declared "+
- "(http://www.w3.org/TR/REC-xml-names/#ns-decl)"
- raise REXML::ParseException.new( msg, @source, self)
- end
- curr_ns << c
- elsif b
- prefixes << b unless b == "xml"
- end
- attributes[a] = e
- }
end
- # Verify that all of the prefixes have been defined
- for prefix in prefixes
- unless @nsstack.find{|k| k.member?(prefix)}
- raise UndefinedNamespaceException.new(prefix,@source,self)
- end
- end
-
- if md[6]
+ if md[4]
@closed = md[1]
- @nsstack.shift
else
@tags.push( md[1] )
end
+ attributes = {}
+ attrs.each { |a,b,c| attributes[a] = c }
return [ :start_element, md[1], attributes ]
end
else
@@ -409,8 +371,6 @@ module REXML
# return PullEvent.new( :text, md[1], unnormalized )
return [ :text, md[1] ]
end
- rescue REXML::UndefinedNamespaceException
- raise
rescue REXML::ParseException
raise
rescue Exception, NameError => error
diff --git a/lib/rexml/parsers/sax2parser.rb b/lib/rexml/parsers/sax2parser.rb
index e402eb7747..6c7fbe000a 100644
--- a/lib/rexml/parsers/sax2parser.rb
+++ b/lib/rexml/parsers/sax2parser.rb
@@ -94,8 +94,6 @@ module REXML
when :end_document
handle( :end_document )
break
- when :start_doctype
- handle( :doctype, *event[1..-1])
when :end_doctype
context = context[1]
when :start_element
@@ -169,7 +167,7 @@ module REXML
when :entitydecl
@entities[ event[1] ] = event[2] if event.size == 3
handle( *event )
- when :processing_instruction, :comment, :attlistdecl,
+ when :processing_instruction, :comment, :doctype, :attlistdecl,
:elementdecl, :cdata, :notationdecl, :xmldecl
handle( *event )
end
diff --git a/lib/rexml/parsers/treeparser.rb b/lib/rexml/parsers/treeparser.rb
index 5c3e142ea7..a53fa41925 100644
--- a/lib/rexml/parsers/treeparser.rb
+++ b/lib/rexml/parsers/treeparser.rb
@@ -1,5 +1,4 @@
require 'rexml/validation/validationexception'
-require 'rexml/undefinednamespaceexception'
module REXML
module Parsers
@@ -30,7 +29,8 @@ module REXML
return
when :start_element
tag_stack.push(event[1])
- el = @build_context = @build_context.add_element( event[1], event[2] )
+ # find the observers for namespaces
+ @build_context = @build_context.add_element( event[1], event[2] )
when :end_element
tag_stack.pop
@build_context = @build_context.parent
@@ -86,8 +86,6 @@ module REXML
end
rescue REXML::Validation::ValidationException
raise
- rescue REXML::UndefinedNamespaceException
- raise
rescue
raise ParseException.new( $!.message, @parser.source, @parser, $! )
end
diff --git a/lib/rexml/parsers/xpathparser.rb b/lib/rexml/parsers/xpathparser.rb
index de2530e347..6f5b21cd93 100644
--- a/lib/rexml/parsers/xpathparser.rb
+++ b/lib/rexml/parsers/xpathparser.rb
@@ -551,7 +551,7 @@ module REXML
end
end
#puts "BEFORE WITH '#{rest}'"
- rest = LocationPath(rest, n) if rest =~ /\A[\/\.\@\[\w_*]/
+ rest = LocationPath(rest, n) if rest =~ /^[\/\.\@\[\w_*]/
parsed.concat(n)
return rest
end
diff --git a/lib/rexml/rexml.rb b/lib/rexml/rexml.rb
index 95bc2a7f6d..bff1cd9815 100644
--- a/lib/rexml/rexml.rb
+++ b/lib/rexml/rexml.rb
@@ -1,4 +1,3 @@
-# -*- encoding: utf-8 -*-
# REXML is an XML toolkit for Ruby[http://www.ruby-lang.org], in Ruby.
#
# REXML is a _pure_ Ruby, XML 1.0 conforming,
@@ -11,9 +10,8 @@
#
# Main page:: http://www.germane-software.com/software/rexml
# Author:: Sean Russell <serATgermaneHYPHENsoftwareDOTcom>
-# Version:: 3.1.7.2
-# Date:: 2007/275
-# Revision:: $Revision$
+# Version:: 3.1.6
+# Date:: 2006/335
#
# This API documentation can be downloaded from the REXML home page, or can
# be accessed online[http://www.germane-software.com/software/rexml_doc]
@@ -22,10 +20,9 @@
# or can be accessed
# online[http://www.germane-software.com/software/rexml/docs/tutorial.html]
module REXML
- COPYRIGHT = "Copyright \xC2\xA9 2001-2006 Sean Russell <ser@germane-software.com>"
- VERSION = "3.1.7.3"
- DATE = "2007/275"
- REVISION = "$Revision$".gsub(/\$Revision:|\$/,'').strip
+ COPYRIGHT = "Copyright © 2001-2006 Sean Russell <ser@germane-software.com>"
+ DATE = "2006/335"
+ VERSION = "3.1.6"
Copyright = COPYRIGHT
Version = VERSION
diff --git a/lib/rexml/source.rb b/lib/rexml/source.rb
index ce7a2c98b0..2fee99c0e9 100644
--- a/lib/rexml/source.rb
+++ b/lib/rexml/source.rb
@@ -1,140 +1,139 @@
require 'rexml/encoding'
module REXML
- # Generates Source-s. USE THIS CLASS.
- class SourceFactory
- # Generates a Source object
- # @param arg Either a String, or an IO
- # @return a Source, or nil if a bad argument was given
- def SourceFactory::create_from(arg)
+ # Generates Source-s. USE THIS CLASS.
+ class SourceFactory
+ # Generates a Source object
+ # @param arg Either a String, or an IO
+ # @return a Source, or nil if a bad argument was given
+ def SourceFactory::create_from(arg)
if arg.kind_of? String
- Source.new(arg)
+ Source.new(arg)
elsif arg.respond_to? :read and
arg.respond_to? :readline and
arg.respond_to? :nil? and
arg.respond_to? :eof?
- IOSource.new(arg)
+ IOSource.new(arg)
elsif arg.kind_of? Source
arg
else
- raise "#{arg.class} is not a valid input stream. It must walk \n"+
- "like either a String, an IO, or a Source."
+ raise "#{source.class} is not a valid input stream. It must walk \n"+
+ "like either a String, IO, or Source."
end
- end
- end
-
- # A Source can be searched for patterns, and wraps buffers and other
- # objects and provides consumption of text
- class Source
- include Encoding
- # The current buffer (what we're going to read next)
- attr_reader :buffer
- # The line number of the last consumed text
- attr_reader :line
- attr_reader :encoding
-
- # Constructor
- # @param arg must be a String, and should be a valid XML document
+ end
+ end
+
+ # A Source can be searched for patterns, and wraps buffers and other
+ # objects and provides consumption of text
+ class Source
+ include Encoding
+ # The current buffer (what we're going to read next)
+ attr_reader :buffer
+ # The line number of the last consumed text
+ attr_reader :line
+ attr_reader :encoding
+
+ # Constructor
+ # @param arg must be a String, and should be a valid XML document
# @param encoding if non-null, sets the encoding of the source to this
# value, overriding all encoding detection
- def initialize(arg, encoding=nil)
- @orig = @buffer = arg
+ def initialize(arg, encoding=nil)
+ @orig = @buffer = arg
if encoding
self.encoding = encoding
else
self.encoding = check_encoding( @buffer )
end
- @line = 0
- end
-
-
- # Inherited from Encoding
- # Overridden to support optimized en/decoding
- def encoding=(enc)
- return unless super
- @line_break = encode( '>' )
- if enc != UTF_8
- @buffer = decode(@buffer)
- @to_utf = true
- else
- @to_utf = false
- end
- end
-
- # Scans the source for a given pattern. Note, that this is not your
- # usual scan() method. For one thing, the pattern argument has some
- # requirements; for another, the source can be consumed. You can easily
- # confuse this method. Originally, the patterns were easier
- # to construct and this method more robust, because this method
- # generated search regexes on the fly; however, this was
- # computationally expensive and slowed down the entire REXML package
- # considerably, since this is by far the most commonly called method.
- # @param pattern must be a Regexp, and must be in the form of
- # /^\s*(#{your pattern, with no groups})(.*)/. The first group
- # will be returned; the second group is used if the consume flag is
- # set.
- # @param consume if true, the pattern returned will be consumed, leaving
- # everything after it in the Source.
- # @return the pattern, if found, or nil if the Source is empty or the
- # pattern is not found.
- def scan(pattern, cons=false)
- return nil if @buffer.nil?
- rv = @buffer.scan(pattern)
- @buffer = $' if cons and rv.size>0
- rv
- end
-
- def read
- end
-
- def consume( pattern )
- @buffer = $' if pattern.match( @buffer )
- end
-
- def match_to( char, pattern )
- return pattern.match(@buffer)
- end
-
- def match_to_consume( char, pattern )
- md = pattern.match(@buffer)
- @buffer = $'
- return md
- end
-
- def match(pattern, cons=false)
- md = pattern.match(@buffer)
- @buffer = $' if cons and md
- return md
- end
-
- # @return true if the Source is exhausted
- def empty?
- @buffer == ""
- end
+ @line = 0
+ end
+
+
+ # Inherited from Encoding
+ # Overridden to support optimized en/decoding
+ def encoding=(enc)
+ return unless super
+ @line_break = encode( '>' )
+ if enc != UTF_8
+ @buffer = decode(@buffer)
+ @to_utf = true
+ else
+ @to_utf = false
+ end
+ end
+
+ # Scans the source for a given pattern. Note, that this is not your
+ # usual scan() method. For one thing, the pattern argument has some
+ # requirements; for another, the source can be consumed. You can easily
+ # confuse this method. Originally, the patterns were easier
+ # to construct and this method more robust, because this method
+ # generated search regexes on the fly; however, this was
+ # computationally expensive and slowed down the entire REXML package
+ # considerably, since this is by far the most commonly called method.
+ # @param pattern must be a Regexp, and must be in the form of
+ # /^\s*(#{your pattern, with no groups})(.*)/. The first group
+ # will be returned; the second group is used if the consume flag is
+ # set.
+ # @param consume if true, the pattern returned will be consumed, leaving
+ # everything after it in the Source.
+ # @return the pattern, if found, or nil if the Source is empty or the
+ # pattern is not found.
+ def scan(pattern, cons=false)
+ return nil if @buffer.nil?
+ rv = @buffer.scan(pattern)
+ @buffer = $' if cons and rv.size>0
+ rv
+ end
+
+ def read
+ end
+
+ def consume( pattern )
+ @buffer = $' if pattern.match( @buffer )
+ end
+
+ def match_to( char, pattern )
+ return pattern.match(@buffer)
+ end
+
+ def match_to_consume( char, pattern )
+ md = pattern.match(@buffer)
+ @buffer = $'
+ return md
+ end
+
+ def match(pattern, cons=false)
+ md = pattern.match(@buffer)
+ @buffer = $' if cons and md
+ return md
+ end
+
+ # @return true if the Source is exhausted
+ def empty?
+ @buffer == ""
+ end
def position
@orig.index( @buffer )
end
- # @return the current line in the source
- def current_line
- lines = @orig.split
- res = lines.grep @buffer[0..30]
- res = res[-1] if res.kind_of? Array
- lines.index( res ) if res
- end
- end
+ # @return the current line in the source
+ def current_line
+ lines = @orig.split
+ res = lines.grep @buffer[0..30]
+ res = res[-1] if res.kind_of? Array
+ lines.index( res ) if res
+ end
+ end
- # A Source that wraps an IO. See the Source class for method
- # documentation
- class IOSource < Source
- #attr_reader :block_size
+ # A Source that wraps an IO. See the Source class for method
+ # documentation
+ class IOSource < Source
+ #attr_reader :block_size
# block_size has been deprecated
- def initialize(arg, block_size=500, encoding=nil)
- @er_source = @source = arg
- @to_utf = false
-
+ def initialize(arg, block_size=500, encoding=nil)
+ @er_source = @source = arg
+ @to_utf = false
# Determining the encoding is a deceptively difficult issue to resolve.
# First, we check the first two bytes for UTF-16. Then we
# assume that the encoding is at least ASCII enough for the '>', and
@@ -146,94 +145,88 @@ module REXML
str = @source.read( 2 )
if encoding
self.encoding = encoding
- elsif 0xfe == str[0] && 0xff == str[1]
- @line_break = "\000>"
- elsif 0xff == str[0] && 0xfe == str[1]
- @line_break = ">\000"
- elsif 0xef == str[0] && 0xbb == str[1]
- str += @source.read(1)
- str = '' if (0xbf == str[2])
- @line_break = ">"
+ elsif /\A(?:\xfe\xff|\xff\xfe)/n =~ str
+ self.encoding = check_encoding( str )
else
- @line_break = ">"
+ @line_break = '>'
end
super str+@source.readline( @line_break )
end
- def scan(pattern, cons=false)
- rv = super
- # You'll notice that this next section is very similar to the same
- # section in match(), but just a liiittle different. This is
- # because it is a touch faster to do it this way with scan()
- # than the way match() does it; enough faster to warrent duplicating
- # some code
- if rv.size == 0
- until @buffer =~ pattern or @source.nil?
- begin
- # READLINE OPT
- #str = @source.read(@block_size)
- str = @source.readline(@line_break)
- str = decode(str) if @to_utf and str
- @buffer << str
+ def scan(pattern, cons=false)
+ rv = super
+ # You'll notice that this next section is very similar to the same
+ # section in match(), but just a liiittle different. This is
+ # because it is a touch faster to do it this way with scan()
+ # than the way match() does it; enough faster to warrent duplicating
+ # some code
+ if rv.size == 0
+ until @buffer =~ pattern or @source.nil?
+ begin
+ # READLINE OPT
+ #str = @source.read(@block_size)
+ str = @source.readline(@line_break)
+ str = decode(str) if @to_utf and str
+ @buffer << str
rescue Iconv::IllegalSequence
raise
- rescue
- @source = nil
- end
- end
- rv = super
- end
- rv.taint
- rv
- end
-
- def read
- begin
+ rescue
+ @source = nil
+ end
+ end
+ rv = super
+ end
+ rv.taint
+ rv
+ end
+
+ def read
+ begin
str = @source.readline(@line_break)
- str = decode(str) if @to_utf and str
- @buffer << str
- rescue Exception, NameError
- @source = nil
- end
- end
-
- def consume( pattern )
- match( pattern, true )
- end
-
- def match( pattern, cons=false )
- rv = pattern.match(@buffer)
- @buffer = $' if cons and rv
- while !rv and @source
- begin
+ str = decode(str) if @to_utf and str
+ @buffer << str
+ rescue Exception, NameError
+ @source = nil
+ end
+ end
+
+ def consume( pattern )
+ match( pattern, true )
+ end
+
+ def match( pattern, cons=false )
+ rv = pattern.match(@buffer)
+ @buffer = $' if cons and rv
+ while !rv and @source
+ begin
str = @source.readline(@line_break)
- str = decode(str) if @to_utf and str
- @buffer << str
- rv = pattern.match(@buffer)
- @buffer = $' if cons and rv
- rescue
- @source = nil
- end
- end
- rv.taint
- rv
- end
-
- def empty?
- super and ( @source.nil? || @source.eof? )
- end
+ str = decode(str) if @to_utf and str
+ @buffer << str
+ rv = pattern.match(@buffer)
+ @buffer = $' if cons and rv
+ rescue
+ @source = nil
+ end
+ end
+ rv.taint
+ rv
+ end
+
+ def empty?
+ super and ( @source.nil? || @source.eof? )
+ end
def position
@er_source.stat.pipe? ? 0 : @er_source.pos
end
- # @return the current line in the source
- def current_line
+ # @return the current line in the source
+ def current_line
begin
- pos = @er_source.pos # The byte position in the source
- lineno = @er_source.lineno # The XML < position in the source
+ pos = @er_source.pos # The byte position in the source
+ lineno = @er_source.lineno # The XML < position in the source
@er_source.rewind
- line = 0 # The \r\n position in the source
+ line = 0 # The \r\n position in the source
begin
while @er_source.pos < pos
@er_source.readline
@@ -245,7 +238,7 @@ module REXML
pos = -1
line = -1
end
- [pos, lineno, line]
- end
- end
+ [pos, lineno, line]
+ end
+ end
end
diff --git a/lib/rexml/text.rb b/lib/rexml/text.rb
index 9804aa710b..3de9170623 100644
--- a/lib/rexml/text.rb
+++ b/lib/rexml/text.rb
@@ -211,17 +211,16 @@ module REXML
return new_string
end
- # == DEPRECATED
- # See REXML::Formatters
- #
def write( writer, indent=-1, transitive=false, ie_hack=false )
- Kernel.warn("#{self.class.name}.write is deprecated. See REXML::Formatters")
- formatter = if indent > -1
- REXML::Formatters::Pretty.new( indent )
- else
- REXML::Formatters::Default.new
+ s = to_s()
+ if not (@parent and @parent.whitespace) then
+ s = wrap(s, 60, false) if @parent and @parent.context[:wordwrap] == :all
+ if @parent and not @parent.context[:indentstyle].nil? and indent > 0 and s.count("\n") > 0
+ s = indent_text(s, indent, @parent.context[:indentstyle], false)
end
- formatter.write( self, writer )
+ s.squeeze!(" \n\t") if @parent and !@parent.whitespace
+ end
+ writer << s
end
# FIXME
diff --git a/lib/rexml/undefinednamespaceexception.rb b/lib/rexml/undefinednamespaceexception.rb
deleted file mode 100644
index 8ebfdfd0a9..0000000000
--- a/lib/rexml/undefinednamespaceexception.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require 'rexml/parseexception'
-module REXML
- class UndefinedNamespaceException < ParseException
- def initialize( prefix, source, parser )
- super( "Undefined prefix #{prefix} found" )
- end
- end
-end
diff --git a/lib/rexml/xmldecl.rb b/lib/rexml/xmldecl.rb
index 427eb78cf8..b65604b762 100644
--- a/lib/rexml/xmldecl.rb
+++ b/lib/rexml/xmldecl.rb
@@ -13,7 +13,7 @@ module REXML
STOP = '\?>';
attr_accessor :version, :standalone
- attr_reader :writeencoding, :writethis
+ attr_reader :writeencoding
def initialize(version=DEFAULT_VERSION, encoding=nil, standalone=nil)
@writethis = true
@@ -37,14 +37,9 @@ module REXML
XMLDecl.new(self)
end
- # indent::
- # Ignored. There must be no whitespace before an XML declaration
- # transitive::
- # Ignored
- # ie_hack::
- # Ignored
- def write(writer, indent=-1, transitive=false, ie_hack=false)
+ def write writer, indent=-1, transitive=false, ie_hack=false
return nil unless @writethis or writer.kind_of? Output
+ indent( writer, indent )
writer << START.sub(/\\/u, '')
if writer.kind_of? Output
writer << " #{content writer.encoding}"
diff --git a/lib/rexml/xpath_parser.rb b/lib/rexml/xpath_parser.rb
index eb608fdb34..3393113d6a 100644
--- a/lib/rexml/xpath_parser.rb
+++ b/lib/rexml/xpath_parser.rb
@@ -160,7 +160,6 @@ module REXML
node_types = ELEMENTS
return nodeset if path_stack.length == 0 || nodeset.length == 0
while path_stack.length > 0
- #puts "#"*5
#puts "Path stack = #{path_stack.inspect}"
#puts "Nodeset is #{nodeset.inspect}"
if nodeset.length == 0
@@ -352,8 +351,7 @@ module REXML
when :following_sibling
#puts "FOLLOWING_SIBLING 1: nodeset = #{nodeset}"
results = []
- nodeset.each do |node|
- next if node.parent.nil?
+ for node in nodeset
all_siblings = node.parent.children
current_index = all_siblings.index( node )
following_siblings = all_siblings[ current_index+1 .. -1 ]
@@ -364,14 +362,13 @@ module REXML
when :preceding_sibling
results = []
- nodeset.each do |node|
- next if node.parent.nil?
+ for node in nodeset
all_siblings = node.parent.children
current_index = all_siblings.index( node )
- preceding_siblings = all_siblings[ 0, current_index ].reverse
- results += preceding_siblings
+ preceding_siblings = all_siblings[ 0 .. current_index-1 ].reverse
+ #results += expr( path_stack.dclone, preceding_siblings )
end
- nodeset = results
+ nodeset = preceding_siblings || []
node_types = ELEMENTS
when :preceding
@@ -392,21 +389,15 @@ module REXML
node_types = ELEMENTS
when :namespace
- #puts "In :namespace"
new_nodeset = []
prefix = path_stack.shift
for node in nodeset
if (node.node_type == :element or node.node_type == :attribute)
- if @namespaces
- namespaces = @namespaces
- elsif (node.node_type == :element)
+ if (node.node_type == :element)
namespaces = node.namespaces
else
namespaces = node.element.namesapces
end
- #puts "Namespaces = #{namespaces.inspect}"
- #puts "Prefix = #{prefix.inspect}"
- #puts "Node.namespace = #{node.namespace}"
if (node.namespace == namespaces[prefix])
new_nodeset << node
end
diff --git a/lib/rinda/tuplespace.rb b/lib/rinda/tuplespace.rb
index 6d58a0fd15..73e79bb401 100644
--- a/lib/rinda/tuplespace.rb
+++ b/lib/rinda/tuplespace.rb
@@ -404,6 +404,7 @@ module Rinda
def write(tuple, sec=nil)
entry = TupleEntry.new(tuple, sec)
+ start_keeper
synchronize do
if entry.expired?
@read_waiter.find_all_template(entry).each do |template|
@@ -413,7 +414,6 @@ module Rinda
notify_event('delete', entry.value)
else
@bag.push(entry)
- start_keeper if entry.expires
@read_waiter.find_all_template(entry).each do |template|
template.read(tuple)
end
@@ -439,6 +439,7 @@ module Rinda
def move(port, tuple, sec=nil)
template = WaitTemplateEntry.new(self, tuple, sec)
yield(template) if block_given?
+ start_keeper
synchronize do
entry = @bag.find(template)
if entry
@@ -451,7 +452,6 @@ module Rinda
begin
@take_waiter.push(template)
- start_keeper if template.expires
while true
raise RequestCanceledError if template.canceled?
raise RequestExpiredError if template.expired?
@@ -476,6 +476,7 @@ module Rinda
def read(tuple, sec=nil)
template = WaitTemplateEntry.new(self, tuple, sec)
yield(template) if block_given?
+ start_keeper
synchronize do
entry = @bag.find(template)
return entry.value if entry
@@ -483,7 +484,6 @@ module Rinda
begin
@read_waiter.push(template)
- start_keeper if template.expires
template.wait
raise RequestCanceledError if template.canceled?
raise RequestExpiredError if template.expired?
@@ -566,11 +566,8 @@ module Rinda
def start_keeper
return if @keeper && @keeper.alive?
@keeper = Thread.new do
- while true
- synchronize do
- break unless need_keeper?
- keep_clean
- end
+ while need_keeper?
+ keep_clean
sleep(@period)
end
end
diff --git a/lib/scanf.rb b/lib/scanf.rb
index a54485661d..2972bf9d60 100644
--- a/lib/scanf.rb
+++ b/lib/scanf.rb
@@ -357,7 +357,7 @@ module Scanf
# %i
when /%\*?i/
- [ "([-+]?(?:(?:0[0-7]+)|(?:0[Xx]#{h}+)|(?:[1-9]\\d*)))", :extract_integer ]
+ [ "([-+]?(?:(?:0[0-7]+)|(?:0[Xx]#{h}+)|(?:[1-9]\\d+)))", :extract_integer ]
# %5i
when /%\*?(\d+)i/
diff --git a/lib/set.rb b/lib/set.rb
index d3f85f8422..5a9287ba89 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -228,7 +228,7 @@ class Set
# Deletes every element of the set for which block evaluates to
# true, and returns self.
def delete_if
- to_a.each { |o| @hash.delete(o) if yield(o) }
+ @hash.delete_if { |o,| yield(o) }
self
end
@@ -486,7 +486,7 @@ class SortedSet < Set
def delete_if
n = @hash.size
- super
+ @hash.delete_if { |o,| yield(o) }
@keys = nil if @hash.size != n
self
end
@@ -498,7 +498,6 @@ class SortedSet < Set
def each
to_a.each { |o| yield(o) }
- self
end
def to_a
@@ -1162,33 +1161,11 @@ class TC_SortedSet < Test::Unit::TestCase
assert_equal([-10,-8,-6,-4,-2], s.to_a)
prev = nil
- ret = s.each { |o| assert(prev < o) if prev; prev = o }
+ s.each { |o| assert(prev < o) if prev; prev = o }
assert_not_nil(prev)
- assert_same(s, ret)
s = SortedSet.new([2,1,3]) { |o| o * -2 }
assert_equal([-6,-4,-2], s.to_a)
-
- s = SortedSet.new(['one', 'two', 'three', 'four'])
- a = []
- ret = s.delete_if { |o| a << o; o[0] == ?t }
- assert_same(s, ret)
- assert_equal(['four', 'one'], s.to_a)
- assert_equal(['four', 'one', 'three', 'two'], a)
-
- s = SortedSet.new(['one', 'two', 'three', 'four'])
- a = []
- ret = s.reject! { |o| a << o; o[0] == ?t }
- assert_same(s, ret)
- assert_equal(['four', 'one'], s.to_a)
- assert_equal(['four', 'one', 'three', 'two'], a)
-
- s = SortedSet.new(['one', 'two', 'three', 'four'])
- a = []
- ret = s.reject! { |o| a << o; false }
- assert_same(nil, ret)
- assert_equal(['four', 'one', 'three', 'two'], s.to_a)
- assert_equal(['four', 'one', 'three', 'two'], a)
end
end
diff --git a/lib/shell/command-processor.rb b/lib/shell/command-processor.rb
index b0e4fb70db..ecf6c7d5eb 100644
--- a/lib/shell/command-processor.rb
+++ b/lib/shell/command-processor.rb
@@ -155,7 +155,6 @@ class Shell
# sh[:exists?, "foo"]
# sh["exists?", "foo"]
#
- alias top_level_test test
def test(command, file1, file2=nil)
file1 = expand_path(file1)
file2 = expand_path(file2) if file2
@@ -163,11 +162,7 @@ class Shell
case command
when Integer
- if file2
- top_level_test(command, file1, file2)
- else
- top_level_test(command, file1)
- end
+ top_level_test(command, file1, file2)
when String
if command.size == 1
if file2
diff --git a/lib/singleton.rb b/lib/singleton.rb
index 31fb950378..0ab8517275 100644
--- a/lib/singleton.rb
+++ b/lib/singleton.rb
@@ -70,7 +70,8 @@ module Singleton
def dup
raise TypeError, "can't dup instance of singleton #{self.class}"
end
-
+
+ private
# default marshalling strategy
def _dump(depth=-1)
''
diff --git a/lib/sync.rb b/lib/sync.rb
index 9e522c2466..79522ed885 100644
--- a/lib/sync.rb
+++ b/lib/sync.rb
@@ -54,7 +54,6 @@ module Sync_m
# exceptions
class Err < StandardError
def Err.Fail(*opt)
- Thread.critical = false
fail self, sprintf(self::Message, *opt)
end
@@ -130,10 +129,10 @@ module Sync_m
# locking methods.
def sync_try_lock(mode = EX)
- return unlock if mode == UN
+ return unlock if sync_mode == UN
Thread.critical = true
- ret = sync_try_lock_sub(mode)
+ ret = sync_try_lock_sub(sync_mode)
Thread.critical = false
ret
end
diff --git a/lib/timeout.rb b/lib/timeout.rb
index 5a99c28092..dc92964c0b 100644
--- a/lib/timeout.rb
+++ b/lib/timeout.rb
@@ -32,13 +32,8 @@ module Timeout
##
# Raised by Timeout#timeout when the block times out.
- class Error < Interrupt
+ class Error<Interrupt
end
- class ExitException < ::Exception # :nodoc:
- end
-
- THIS_FILE = /\A#{Regexp.quote(__FILE__)}:/o
- CALLER_OFFSET = ((c = caller[0]) && THIS_FILE =~ c) ? 1 : 0
##
# Executes the method's block. If the block execution terminates before +sec+
@@ -49,10 +44,9 @@ module Timeout
# Timeout' into your classes so they have a #timeout method, as well as a
# module method, so you can call it directly as Timeout.timeout().
- def timeout(sec, klass = nil)
+ def timeout(sec, exception=Error)
return yield if sec == nil or sec.zero?
raise ThreadError, "timeout within critical session" if Thread.critical
- exception = klass || Class.new(ExitException)
begin
x = Thread.current
y = Thread.start {
@@ -61,17 +55,6 @@ module Timeout
}
yield sec
# return true
- rescue exception => e
- rej = /\A#{Regexp.quote(__FILE__)}:#{__LINE__-4}\z/o
- (bt = e.backtrace).reject! {|m| rej =~ m}
- level = -caller(CALLER_OFFSET).size
- while THIS_FILE =~ bt[level]
- bt.delete_at(level)
- level += 1
- end
- raise if klass # if exception class is specified, it
- # would be expected outside.
- raise Error, e.message, e.backtrace
ensure
y.kill if y and y.alive?
end
@@ -89,7 +72,7 @@ end
# Defined for backwards compatibility with earlier versions of timeout.rb, see
# Timeout#timeout.
-def timeout(n, e = nil, &block) # :nodoc:
+def timeout(n, e=Timeout::Error, &block) # :nodoc:
Timeout::timeout(n, e, &block)
end
diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb
index 50b69ba9ad..434d1bf053 100644
--- a/lib/tmpdir.rb
+++ b/lib/tmpdir.rb
@@ -10,23 +10,16 @@ class Dir
begin
require 'Win32API'
- CSIDL_LOCAL_APPDATA = 0x001c
max_pathlen = 260
- windir = "\0"*(max_pathlen+1)
+ windir = ' '*(max_pathlen+1)
begin
- getdir = Win32API.new('shell32', 'SHGetFolderPath', 'LLLLP', 'L')
- raise RuntimeError if getdir.call(0, CSIDL_LOCAL_APPDATA, 0, 0, windir) != 0
- windir = File.expand_path(windir.rstrip)
+ getdir = Win32API.new('kernel32', 'GetSystemWindowsDirectory', 'PL', 'L')
rescue RuntimeError
- begin
- getdir = Win32API.new('kernel32', 'GetSystemWindowsDirectory', 'PL', 'L')
- rescue RuntimeError
- getdir = Win32API.new('kernel32', 'GetWindowsDirectory', 'PL', 'L')
- end
- len = getdir.call(windir, windir.size)
- windir = File.expand_path(windir[0, len])
+ getdir = Win32API.new('kernel32', 'GetWindowsDirectory', 'PL', 'L')
end
- temp = File.join(windir.untaint, 'temp')
+ len = getdir.call(windir, windir.size)
+ windir = File.expand_path(windir[0, len])
+ temp = File.join(windir, 'temp')
@@systmpdir = temp if File.directory?(temp) and File.writable?(temp)
rescue LoadError
end
@@ -46,7 +39,7 @@ class Dir
break
end
end
- File.expand_path(tmp)
end
+ File.expand_path(tmp)
end
end
diff --git a/lib/uri/common.rb b/lib/uri/common.rb
index af6aaf26fb..f74f0eb2e1 100644
--- a/lib/uri/common.rb
+++ b/lib/uri/common.rb
@@ -110,7 +110,7 @@ module URI
SERVER = "(?:#{USERINFO}@)?#{HOSTPORT}"
# reg_name = 1*( unreserved | escaped | "$" | "," |
# ";" | ":" | "@" | "&" | "=" | "+" )
- REG_NAME = "(?:[#{UNRESERVED}$,;:@&=+]|#{ESCAPED})+"
+ REG_NAME = "(?:[#{UNRESERVED}$,;+@&=+]|#{ESCAPED})+"
# authority = server | reg_name
AUTHORITY = "(?:#{SERVER}|#{REG_NAME})"
diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb
index 88b5078466..2b66adeb93 100644
--- a/lib/uri/generic.rb
+++ b/lib/uri/generic.rb
@@ -1103,9 +1103,8 @@ module URI
end
end
- @@to_s = Kernel.instance_method(:to_s)
def inspect
- @@to_s.bind(self).call.sub!(/>\z/) {" URL:#{self}>"}
+ sprintf("#<%s:%#0x URL:%s>", self.class.to_s, self.object_id, self.to_s)
end
def coerce(oth)
diff --git a/lib/webrick/httprequest.rb b/lib/webrick/httprequest.rb
index 4021259072..1d32293a27 100644
--- a/lib/webrick/httprequest.rb
+++ b/lib/webrick/httprequest.rb
@@ -225,7 +225,7 @@ module WEBrick
@request_line = read_line(socket) if socket
@request_time = Time.now
raise HTTPStatus::EOFError unless @request_line
- if /^(\S+)\s+(\S+?)(?:\s+HTTP\/(\d+\.\d+))?\r?\n/mo =~ @request_line
+ if /^(\S+)\s+(\S+)(?:\s+HTTP\/(\d+\.\d+))?\r?\n/mo =~ @request_line
@request_method = $1
@unparsed_uri = $2
@http_version = HTTPVersion.new($3 ? $3 : "0.9")
diff --git a/lib/webrick/httpservlet/abstract.rb b/lib/webrick/httpservlet/abstract.rb
index 5375c4622d..03861e8fc7 100644
--- a/lib/webrick/httpservlet/abstract.rb
+++ b/lib/webrick/httpservlet/abstract.rb
@@ -58,7 +58,7 @@ module WEBrick
def redirect_to_directory_uri(req, res)
if req.path[-1] != ?/
- location = WEBrick::HTTPUtils.escape_path(req.path + "/")
+ location = req.path + "/"
if req.query_string && req.query_string.size > 0
location << "?" << req.query_string
end
diff --git a/lib/webrick/httpservlet/cgi_runner.rb b/lib/webrick/httpservlet/cgi_runner.rb
index 006abd458e..1069a68d58 100644
--- a/lib/webrick/httpservlet/cgi_runner.rb
+++ b/lib/webrick/httpservlet/cgi_runner.rb
@@ -39,9 +39,7 @@ dir = File::dirname(ENV["SCRIPT_FILENAME"])
Dir::chdir dir
if interpreter = ARGV[0]
- argv = ARGV.dup
- argv << ENV["SCRIPT_FILENAME"]
- exec(*argv)
+ exec(interpreter, ENV["SCRIPT_FILENAME"])
# NOTREACHED
end
exec ENV["SCRIPT_FILENAME"]
diff --git a/lib/webrick/httpservlet/filehandler.rb b/lib/webrick/httpservlet/filehandler.rb
index 24f59d7142..410cc6f9a9 100644
--- a/lib/webrick/httpservlet/filehandler.rb
+++ b/lib/webrick/httpservlet/filehandler.rb
@@ -163,7 +163,6 @@ module WEBrick
end
end
end
- prevent_directory_traversal(req, res)
super(req, res)
end
@@ -199,38 +198,10 @@ module WEBrick
private
- def trailing_pathsep?(path)
- # check for trailing path separator:
- # File.dirname("/aaaa/bbbb/") #=> "/aaaa")
- # File.dirname("/aaaa/bbbb/x") #=> "/aaaa/bbbb")
- # File.dirname("/aaaa/bbbb") #=> "/aaaa")
- # File.dirname("/aaaa/bbbbx") #=> "/aaaa")
- return File.dirname(path) != File.dirname(path+"x")
- end
-
- def prevent_directory_traversal(req, res)
- # Preventing directory traversal on Windows platforms;
- # Backslashes (0x5c) in path_info are not interpreted as special
- # character in URI notation. So the value of path_info should be
- # normalize before accessing to the filesystem.
-
- if trailing_pathsep?(req.path_info)
- # File.expand_path removes the trailing path separator.
- # Adding a character is a workaround to save it.
- # File.expand_path("/aaa/") #=> "/aaa"
- # File.expand_path("/aaa/" + "x") #=> "/aaa/x"
- expanded = File.expand_path(req.path_info + "x")
- expanded.chop! # remove trailing "x"
- else
- expanded = File.expand_path(req.path_info)
- end
- req.path_info = expanded
- end
-
def exec_handler(req, res)
raise HTTPStatus::NotFound, "`#{req.path}' not found" unless @root
if set_filename(req, res)
- handler = get_handler(req, res)
+ handler = get_handler(req)
call_callback(:HandlerCallback, req, res)
h = handler.get_instance(@config, res.filename)
h.service(req, res)
@@ -240,13 +211,9 @@ module WEBrick
return false
end
- def get_handler(req, res)
- suffix1 = (/\.(\w+)\z/ =~ res.filename) && $1.downcase
- if /\.(\w+)\.([\w\-]+)\z/ =~ res.filename
- if @options[:AcceptableLanguages].include?($2.downcase)
- suffix2 = $1.downcase
- end
- end
+ def get_handler(req)
+ suffix1 = (/\.(\w+)$/ =~ req.script_name) && $1.downcase
+ suffix2 = (/\.(\w+)\.[\w\-]+$/ =~ req.script_name) && $1.downcase
handler_table = @options[:HandlerTable]
return handler_table[suffix1] || handler_table[suffix2] ||
HandlerTable[suffix1] || HandlerTable[suffix2] ||
@@ -259,13 +226,15 @@ module WEBrick
path_info.unshift("") # dummy for checking @root dir
while base = path_info.first
+ check_filename(req, res, base)
break if base == "/"
- break unless File.directory?(File.expand_path(res.filename + base))
+ break unless File.directory?(res.filename + base)
shift_path_info(req, res, path_info)
call_callback(:DirectoryCallback, req, res)
end
if base = path_info.first
+ check_filename(req, res, base)
if base == "/"
if file = search_index_file(req, res)
shift_path_info(req, res, path_info, file)
@@ -286,10 +255,12 @@ module WEBrick
end
def check_filename(req, res, name)
- if nondisclosure_name?(name) || windows_ambiguous_name?(name)
- @logger.warn("the request refers nondisclosure name `#{name}'.")
- raise HTTPStatus::NotFound, "`#{req.path}' not found."
- end
+ @options[:NondisclosureName].each{|pattern|
+ if File.fnmatch("/#{pattern}", name)
+ @logger.warn("the request refers nondisclosure name `#{name}'.")
+ raise HTTPStatus::NotFound, "`#{req.path}' not found."
+ end
+ }
end
def shift_path_info(req, res, path_info, base=nil)
@@ -297,8 +268,7 @@ module WEBrick
base = base || tmp
req.path_info = path_info.join
req.script_name << base
- res.filename = File.expand_path(res.filename + base)
- check_filename(req, res, File.basename(res.filename))
+ res.filename << base
end
def search_index_file(req, res)
@@ -338,15 +308,9 @@ module WEBrick
end
end
- def windows_ambiguous_name?(name)
- return true if /[. ]+\z/ =~ name
- return true if /::\$DATA\z/ =~ name
- return false
- end
-
def nondisclosure_name?(name)
@options[:NondisclosureName].each{|pattern|
- if File.fnmatch(pattern, name, File::FNM_CASEFOLD)
+ if File.fnmatch(pattern, name)
return true
end
}
@@ -362,8 +326,7 @@ module WEBrick
list = Dir::entries(local_path).collect{|name|
next if name == "." || name == ".."
next if nondisclosure_name?(name)
- next if windows_ambiguous_name?(name)
- st = (File::stat(File.join(local_path, name)) rescue nil)
+ st = (File::stat(local_path + name) rescue nil)
if st.nil?
[ name, nil, -1 ]
elsif st.directory?
@@ -403,7 +366,7 @@ module WEBrick
res.body << "<A HREF=\"?S=#{d1}\">Size</A>\n"
res.body << "<HR>\n"
- list.unshift [ "..", File::mtime(local_path+"/.."), -1 ]
+ list.unshift [ "..", File::mtime(local_path+".."), -1 ]
list.each{ |name, time, size|
if name == ".."
dname = "Parent Directory"
diff --git a/lib/webrick/httputils.rb b/lib/webrick/httputils.rb
index 976d3e915e..c57af2c860 100644
--- a/lib/webrick/httputils.rb
+++ b/lib/webrick/httputils.rb
@@ -23,8 +23,16 @@ module WEBrick
ret = path.dup
ret.gsub!(%r{/+}o, '/') # // => /
- while ret.sub!(%r'/\.(?:/|\Z)', '/'); end # /. => /
- while ret.sub!(%r'/(?!\.\./)[^/]+/\.\.(?:/|\Z)', '/'); end # /foo/.. => /foo
+ while ret.sub!(%r{/\.(/|\Z)}o, '/'); end # /. => /
+ begin # /foo/.. => /foo
+ match = ret.sub!(%r{/([^/]+)/\.\.(/|\Z)}o){
+ if $1 == ".."
+ raise "abnormal path `#{path}'"
+ else
+ "/"
+ end
+ }
+ end while match
raise "abnormal path `#{path}'" if %r{/\.\.(/|\Z)} =~ ret
ret
@@ -146,8 +154,8 @@ module WEBrick
module_function :parse_header
def split_header_value(str)
- str.scan(%r'\G((?:"(?:\\.|[^"])+?"|[^",]+)+)
- (?:,\s*|\Z)'xn).flatten
+ str.scan(/((?:"(?:\\.|[^"])+?"|[^",]+)+)
+ (?:,\s*|\Z)/xn).collect{|v| v[0] }
end
module_function :split_header_value
diff --git a/lib/xmlrpc/client.rb b/lib/xmlrpc/client.rb
index 726945ea39..10f547b632 100644
--- a/lib/xmlrpc/client.rb
+++ b/lib/xmlrpc/client.rb
@@ -530,9 +530,6 @@ module XMLRPC
}
else
# reuse the HTTP object for each call => connection alive is possible
- # we must start connection explicitely first time so that http.request
- # does not assume that we don't want keepalive
- @http.start if not @http.started?
# post request
resp = @http.post2(@path, request, header)
@@ -552,9 +549,9 @@ module XMLRPC
ct = parse_content_type(resp["Content-Type"]).first
if ct != "text/xml"
if ct == "text/html"
- raise "Wrong content-type (received '#{ct}' but expected 'text/xml'): \n#{data}"
+ raise "Wrong content-type: \n#{data}"
else
- raise "Wrong content-type (received '#{ct}' but expected 'text/xml')"
+ raise "Wrong content-type"
end
end
diff --git a/lib/xmlrpc/parser.rb b/lib/xmlrpc/parser.rb
index 6d10fde9d9..d27d7c3827 100644
--- a/lib/xmlrpc/parser.rb
+++ b/lib/xmlrpc/parser.rb
@@ -92,7 +92,7 @@ module XMLRPC
if $7
ofs = $8.to_i*3600 + $9.to_i*60
ofs = -ofs if $7=='+'
- utc = Time.utc(*a) + ofs
+ utc = Time.utc(a.reverse) + ofs
a = [ utc.year, utc.month, utc.day, utc.hour, utc.min, utc.sec ]
end
XMLRPC::DateTime.new(*a)
@@ -106,7 +106,7 @@ module XMLRPC
if $7
ofs = $8.to_i*3600 + $9.to_i*60
ofs = -ofs if $7=='+'
- utc = Time.utc(*a) + ofs
+ utc = Time.utc(a.reverse) + ofs
a = [ utc.year, utc.month, utc.day, utc.hour, utc.min, utc.sec ]
end
XMLRPC::DateTime.new(*a)
diff --git a/lib/xmlrpc/server.rb b/lib/xmlrpc/server.rb
index 0ee88c8c8f..59a5869408 100644
--- a/lib/xmlrpc/server.rb
+++ b/lib/xmlrpc/server.rb
@@ -267,9 +267,7 @@ class BasicServer
if obj.kind_of? Proc
methods << name
else
- obj.class.public_instance_methods(false).each do |meth|
- methods << "#{name}#{meth}"
- end
+ obj.methods.each {|meth| methods << name + meth}
end
end
methods
@@ -641,11 +639,11 @@ class Server < WEBrickServlet
def serve
if RUBY_PLATFORM =~ /mingw|mswin32/
- signals = [1]
+ signal = 1
else
- signals = %w[INT TERM HUP]
+ signal = "HUP"
end
- signals.each { |signal| trap(signal) { @server.shutdown } }
+ trap(signal) { @server.shutdown }
@server.start
end
diff --git a/lib/xmlrpc/utils.rb b/lib/xmlrpc/utils.rb
index f0966fee40..85c6bba372 100644
--- a/lib/xmlrpc/utils.rb
+++ b/lib/xmlrpc/utils.rb
@@ -157,7 +157,7 @@ module XMLRPC
module ParseContentType
def parse_content_type(str)
a, *b = str.split(";")
- return a.strip.downcase, *b
+ return a.strip, *b
end
end
diff --git a/lib/yaml.rb b/lib/yaml.rb
index a8da42a321..fe8335c8f0 100644
--- a/lib/yaml.rb
+++ b/lib/yaml.rb
@@ -384,10 +384,6 @@ module YAML
else
emitter.reset( opts )
end
- oid =
- case oid when Fixnum, NilClass; oid
- else oid = "#{oid.object_id}-#{oid.hash}"
- end
out.emit( oid, &e )
end
diff --git a/lib/yaml/basenode.rb b/lib/yaml/basenode.rb
index 5439903f42..d24f6172e9 100644
--- a/lib/yaml/basenode.rb
+++ b/lib/yaml/basenode.rb
@@ -184,7 +184,7 @@ module YAML
#
def []( *key )
if Hash === @value
- v = @value.detect { |k,| k.transform == key.first }
+ v = @value.detect { |k,v| k.transform == key.first }
v[1] if v
elsif Array === @value
@value.[]( *key )
diff --git a/lib/yaml/rubytypes.rb b/lib/yaml/rubytypes.rb
index dc6bb3359f..eebf027135 100644
--- a/lib/yaml/rubytypes.rb
+++ b/lib/yaml/rubytypes.rb
@@ -12,7 +12,7 @@ class Object
def to_yaml_style; end
def to_yaml_properties; instance_variables.sort; end
def to_yaml( opts = {} )
- YAML::quick_emit( self, opts ) do |out|
+ YAML::quick_emit( object_id, opts ) do |out|
out.map( taguri, to_yaml_style ) do |map|
to_yaml_properties.each do |m|
map.add( m[1..-1], instance_variable_get( m ) )
@@ -35,7 +35,7 @@ class Hash
end
end
def to_yaml( opts = {} )
- YAML::quick_emit( self, opts ) do |out|
+ YAML::quick_emit( object_id, opts ) do |out|
out.map( taguri, to_yaml_style ) do |map|
each do |k, v|
map.add( k, v )
@@ -83,7 +83,7 @@ class Struct
end
end
def to_yaml( opts = {} )
- YAML::quick_emit( self, opts ) do |out|
+ YAML::quick_emit( object_id, opts ) do |out|
#
# Basic struct is passed as a YAML map
#
@@ -104,7 +104,7 @@ class Array
yaml_as "tag:yaml.org,2002:seq"
def yaml_initialize( tag, val ); concat( val.to_a ); end
def to_yaml( opts = {} )
- YAML::quick_emit( self, opts ) do |out|
+ YAML::quick_emit( object_id, opts ) do |out|
out.seq( taguri, to_yaml_style ) do |seq|
each do |x|
seq.add( x )
@@ -124,7 +124,7 @@ class Exception
o
end
def to_yaml( opts = {} )
- YAML::quick_emit( self, opts ) do |out|
+ YAML::quick_emit( object_id, opts ) do |out|
out.map( taguri, to_yaml_style ) do |map|
map.add( 'message', message )
to_yaml_properties.each do |m|
@@ -161,7 +161,7 @@ class String
end
end
def to_yaml( opts = {} )
- YAML::quick_emit( is_complex_yaml? ? self : nil, opts ) do |out|
+ YAML::quick_emit( is_complex_yaml? ? object_id : nil, opts ) do |out|
if is_binary_data?
out.scalar( "tag:yaml.org,2002:binary", [self].pack("m"), :literal )
elsif to_yaml_properties.empty?
@@ -227,7 +227,7 @@ class Range
end
end
def to_yaml( opts = {} )
- YAML::quick_emit( self, opts ) do |out|
+ YAML::quick_emit( object_id, opts ) do |out|
# if self.begin.is_complex_yaml? or self.begin.respond_to? :to_str or
# self.end.is_complex_yaml? or self.end.respond_to? :to_str or
# not to_yaml_properties.empty?
@@ -310,7 +310,7 @@ class Time
end
end
def to_yaml( opts = {} )
- YAML::quick_emit( self, opts ) do |out|
+ YAML::quick_emit( object_id, opts ) do |out|
tz = "Z"
# from the tidy Tobias Peters <t-peters@gmx.de> Thanks!
unless self.utc?
@@ -347,7 +347,7 @@ end
class Date
yaml_as "tag:yaml.org,2002:timestamp#ymd"
def to_yaml( opts = {} )
- YAML::quick_emit( self, opts ) do |out|
+ YAML::quick_emit( object_id, opts ) do |out|
out.scalar( "tag:yaml.org,2002:timestamp", self.to_s, :plain )
end
end
diff --git a/lib/yaml/types.rb b/lib/yaml/types.rb
index 3871c628fe..05113f216d 100644
--- a/lib/yaml/types.rb
+++ b/lib/yaml/types.rb
@@ -10,6 +10,7 @@ module YAML
#
class PrivateType
def self.tag_subclasses?; false; end
+ attr_accessor :type_id, :value
verbose, $VERBOSE = $VERBOSE, nil
def initialize( type, val )
@type_id = type; @value = val
@@ -27,6 +28,7 @@ module YAML
#
class DomainType
def self.tag_subclasses?; false; end
+ attr_accessor :domain, :type_id, :value
verbose, $VERBOSE = $VERBOSE, nil
def initialize( domain, type, val )
@domain = domain; @type_id = type; @value = val
@@ -45,7 +47,7 @@ module YAML
class Object
def self.tag_subclasses?; false; end
def to_yaml( opts = {} )
- YAML::quick_emit( self, opts ) do |out|
+ YAML::quick_emit( object_id, opts ) do |out|
out.map( "tag:ruby.yaml.org,2002:object:#{ @class }", to_yaml_style ) do |map|
@ivars.each do |k,v|
map.add( k, v )
@@ -123,7 +125,7 @@ module YAML
true
end
def to_yaml( opts = {} )
- YAML::quick_emit( self, opts ) do |out|
+ YAML::quick_emit( self.object_id, opts ) do |out|
out.seq( taguri, to_yaml_style ) do |seq|
self.each do |v|
seq.add( Hash[ *v ] )
@@ -173,7 +175,7 @@ module YAML
true
end
def to_yaml( opts = {} )
- YAML::quick_emit( self, opts ) do |out|
+ YAML::quick_emit( self.object_id, opts ) do |out|
out.seq( taguri, to_yaml_style ) do |seq|
self.each do |v|
seq.add( Hash[ *v ] )
diff --git a/marshal.c b/marshal.c
index 235a076529..51771fdf52 100644
--- a/marshal.c
+++ b/marshal.c
@@ -81,7 +81,7 @@ shortlen(len, ds)
#define TYPE_LINK '@'
static ID s_dump, s_load, s_mdump, s_mload;
-static ID s_dump_data, s_load_data, s_alloc, s_call;
+static ID s_dump_data, s_load_data, s_alloc;
static ID s_getc, s_read, s_write, s_binmode;
struct dump_arg {
@@ -90,7 +90,6 @@ struct dump_arg {
st_table *symbols;
st_table *data;
int taint;
- VALUE wrapper;
};
struct dump_call_arg {
@@ -99,27 +98,6 @@ struct dump_call_arg {
int limit;
};
-static void
-check_dump_arg(arg, sym)
- struct dump_arg *arg;
- ID sym;
-{
- if (!DATA_PTR(arg->wrapper)) {
- rb_raise(rb_eRuntimeError, "Marshal.dump reentered at %s",
- rb_id2name(sym));
- }
-}
-
-static void
-mark_dump_arg(ptr)
- void *ptr;
-{
- struct dump_arg *p = ptr;
- if (!ptr)
- return;
- rb_mark_set(p->data);
-}
-
static VALUE
class2path(klass)
VALUE klass;
@@ -395,8 +373,8 @@ w_extended(klass, arg, check)
{
char *path;
- if (check && FL_TEST(klass, FL_SINGLETON)) {
- if (RCLASS(klass)->m_tbl->num_entries ||
+ if (FL_TEST(klass, FL_SINGLETON)) {
+ if (check && RCLASS(klass)->m_tbl->num_entries ||
(RCLASS(klass)->iv_tbl && RCLASS(klass)->iv_tbl->num_entries > 1)) {
rb_raise(rb_eTypeError, "singleton can't be dumped");
}
@@ -490,7 +468,7 @@ w_object(obj, arg, limit)
return;
}
- if ((ivtbl = rb_generic_ivar_table(obj)) != 0) {
+ if (ivtbl = rb_generic_ivar_table(obj)) {
w_byte(TYPE_IVAR, arg);
}
if (obj == Qnil) {
@@ -524,10 +502,9 @@ w_object(obj, arg, limit)
st_add_direct(arg->data, obj, arg->data->num_entries);
if (rb_respond_to(obj, s_mdump)) {
- volatile VALUE v;
+ VALUE v;
v = rb_funcall(obj, s_mdump, 0, 0);
- check_dump_arg(arg, s_mdump);
w_class(TYPE_USRMARSHAL, obj, arg, Qfalse);
w_object(v, arg, limit);
if (ivtbl) w_ivar(0, &c_arg);
@@ -537,7 +514,6 @@ w_object(obj, arg, limit)
VALUE v;
v = rb_funcall(obj, s_dump, 1, INT2NUM(limit));
- check_dump_arg(arg, s_dump);
if (TYPE(v) != T_STRING) {
rb_raise(rb_eTypeError, "_dump() must return string");
}
@@ -676,14 +652,13 @@ w_object(obj, arg, limit)
{
VALUE v;
+ w_class(TYPE_DATA, obj, arg, Qtrue);
if (!rb_respond_to(obj, s_dump_data)) {
rb_raise(rb_eTypeError,
"no marshal_dump is defined for class %s",
rb_obj_classname(obj));
}
v = rb_funcall(obj, s_dump_data, 0);
- check_dump_arg(arg, s_dump_data);
- w_class(TYPE_DATA, obj, arg, Qtrue);
w_object(v, arg, limit);
}
break;
@@ -715,15 +690,11 @@ static VALUE
dump_ensure(arg)
struct dump_arg *arg;
{
- if (!DATA_PTR(arg->wrapper)) return 0;
st_free_table(arg->symbols);
st_free_table(arg->data);
- DATA_PTR(arg->wrapper) = 0;
- arg->wrapper = 0;
if (arg->taint) {
OBJ_TAINT(arg->str);
}
-
return 0;
}
@@ -776,27 +747,25 @@ marshal_dump(argc, argv)
else port = a1;
}
arg.dest = 0;
- arg.symbols = st_init_numtable();
- arg.data = st_init_numtable();
- arg.taint = Qfalse;
- arg.str = rb_str_buf_new(0);
- RBASIC(arg.str)->klass = 0;
- arg.wrapper = Data_Wrap_Struct(rb_cData, mark_dump_arg, 0, &arg);
if (!NIL_P(port)) {
if (!rb_respond_to(port, s_write)) {
type_error:
rb_raise(rb_eTypeError, "instance of IO needed");
}
+ arg.str = rb_str_buf_new(0);
arg.dest = port;
if (rb_respond_to(port, s_binmode)) {
rb_funcall2(port, s_binmode, 0, 0);
- check_dump_arg(&arg, s_binmode);
}
}
else {
- port = arg.str;
+ port = rb_str_buf_new(0);
+ arg.str = port;
}
+ arg.symbols = st_init_numtable();
+ arg.data = st_init_numtable();
+ arg.taint = Qfalse;
c_arg.obj = obj;
c_arg.arg = &arg;
c_arg.limit = limit;
@@ -805,7 +774,6 @@ marshal_dump(argc, argv)
w_byte(MARSHAL_MINOR, &arg);
rb_ensure(dump, (VALUE)&c_arg, dump_ensure, (VALUE)&arg);
- RBASIC(arg.str)->klass = rb_cString;
return port;
}
@@ -814,33 +782,11 @@ struct load_arg {
VALUE src;
long offset;
st_table *symbols;
- st_table *data;
+ VALUE data;
VALUE proc;
int taint;
- VALUE wrapper;
};
-static void
-check_load_arg(arg, sym)
- struct load_arg *arg;
- ID sym;
-{
- if (!DATA_PTR(arg->wrapper)) {
- rb_raise(rb_eRuntimeError, "Marshal.load reentered at %s",
- rb_id2name(sym));
- }
-}
-
-static void
-mark_load_arg(ptr)
- void *ptr;
-{
- struct load_arg *p = ptr;
- if (!ptr)
- return;
- rb_mark_tbl(p->data);
-}
-
static VALUE r_object _((struct load_arg *arg));
static int
@@ -860,7 +806,6 @@ r_byte(arg)
else {
VALUE src = arg->src;
VALUE v = rb_funcall2(src, s_getc, 0, 0);
- check_load_arg(arg, s_getc);
if (NIL_P(v)) rb_eof_error();
c = (unsigned char)FIX2INT(v);
}
@@ -928,7 +873,7 @@ r_bytes0(len, arg)
if (len == 0) return rb_str_new(0, 0);
if (TYPE(arg->src) == T_STRING) {
- if (RSTRING(arg->src)->len - arg->offset >= len) {
+ if (RSTRING(arg->src)->len > arg->offset) {
str = rb_str_new(RSTRING(arg->src)->ptr+arg->offset, len);
arg->offset += len;
}
@@ -941,7 +886,6 @@ r_bytes0(len, arg)
VALUE src = arg->src;
VALUE n = LONG2NUM(len);
str = rb_funcall2(src, s_read, 1, &n);
- check_load_arg(arg, s_read);
if (NIL_P(str)) goto too_short;
StringValue(str);
if (RSTRING(str)->len != len) goto too_short;
@@ -1004,7 +948,7 @@ r_entry(v, arg)
VALUE v;
struct load_arg *arg;
{
- st_insert(arg->data, arg->data->num_entries, (st_data_t)v);
+ rb_hash_aset(arg->data, INT2FIX(RHASH(arg->data)->tbl->num_entries), v);
if (arg->taint) OBJ_TAINT(v);
return v;
}
@@ -1060,15 +1004,14 @@ r_object0(arg, proc, ivp, extmod)
VALUE v = Qnil;
int type = r_byte(arg);
long id;
- st_data_t link;
switch (type) {
case TYPE_LINK:
id = r_long(arg);
- if (!st_lookup(arg->data, (st_data_t)id, &link)) {
+ v = rb_hash_aref(arg->data, LONG2FIX(id));
+ if (NIL_P(v)) {
rb_raise(rb_eArgError, "dump format error (unlinked)");
}
- v = (st_data_t)link;
return v;
case TYPE_IVAR:
@@ -1296,7 +1239,6 @@ r_object0(arg, proc, ivp, extmod)
*ivp = Qfalse;
}
v = rb_funcall(klass, s_load, 1, data);
- check_load_arg(arg, s_load);
r_entry(v, arg);
}
break;
@@ -1320,7 +1262,6 @@ r_object0(arg, proc, ivp, extmod)
r_entry(v, arg);
data = r_object(arg);
rb_funcall(v, s_mload, 1, data);
- check_load_arg(arg, s_mload);
}
break;
@@ -1347,7 +1288,6 @@ r_object0(arg, proc, ivp, extmod)
warn = Qfalse;
}
v = rb_funcall(klass, s_alloc, 0);
- check_load_arg(arg, s_alloc);
}
else {
v = rb_obj_alloc(klass);
@@ -1362,7 +1302,6 @@ r_object0(arg, proc, ivp, extmod)
rb_class2name(klass));
}
rb_funcall(v, s_load_data, 1, r_object0(arg, 0, 0, extmod));
- check_load_arg(arg, s_load_data);
}
break;
@@ -1405,8 +1344,7 @@ r_object0(arg, proc, ivp, extmod)
break;
}
if (proc) {
- rb_funcall(proc, s_call, 1, v);
- check_load_arg(arg, s_call);
+ rb_funcall(proc, rb_intern("call"), 1, v);
}
return v;
}
@@ -1429,11 +1367,7 @@ static VALUE
load_ensure(arg)
struct load_arg *arg;
{
- if (!DATA_PTR(arg->wrapper)) return 0;
st_free_table(arg->symbols);
- st_free_table(arg->data);
- DATA_PTR(arg->wrapper) = 0;
- arg->wrapper = 0;
return 0;
}
@@ -1459,10 +1393,9 @@ marshal_load(argc, argv)
struct load_arg arg;
rb_scan_args(argc, argv, "11", &port, &proc);
- v = rb_check_string_type(port);
- if (!NIL_P(v)) {
+ if (rb_respond_to(port, rb_intern("to_str"))) {
arg.taint = OBJ_TAINTED(port); /* original taintedness */
- port = v;
+ StringValue(port); /* possible conversion */
}
else if (rb_respond_to(port, s_getc) && rb_respond_to(port, s_read)) {
if (rb_respond_to(port, s_binmode)) {
@@ -1475,10 +1408,6 @@ marshal_load(argc, argv)
}
arg.src = port;
arg.offset = 0;
- arg.symbols = st_init_numtable();
- arg.data = st_init_numtable();
- arg.proc = 0;
- arg.wrapper = Data_Wrap_Struct(rb_cData, mark_load_arg, 0, &arg);
major = r_byte(&arg);
minor = r_byte(&arg);
@@ -1493,7 +1422,10 @@ marshal_load(argc, argv)
MARSHAL_MAJOR, MARSHAL_MINOR, major, minor);
}
- if (!NIL_P(proc)) arg.proc = proc;
+ arg.symbols = st_init_numtable();
+ arg.data = rb_hash_new();
+ if (NIL_P(proc)) arg.proc = 0;
+ else arg.proc = proc;
v = rb_ensure(load, (VALUE)&arg, load_ensure, (VALUE)&arg);
return v;
@@ -1544,7 +1476,6 @@ Init_marshal()
s_dump_data = rb_intern("_dump_data");
s_load_data = rb_intern("_load_data");
s_alloc = rb_intern("_alloc");
- s_call = rb_intern("call");
s_getc = rb_intern("getc");
s_read = rb_intern("read");
s_write = rb_intern("write");
diff --git a/math.c b/math.c
index cf78fc4f2a..60dd0b7204 100644
--- a/math.c
+++ b/math.c
@@ -34,7 +34,7 @@ domain_check(x, msg)
if (isnan(x)) {
#if defined(EDOM)
errno = EDOM;
-#elif defined(ERANGE)
+#elif define(ERANGE)
errno = ERANGE;
#endif
continue;
diff --git a/misc/ruby-mode.el b/misc/ruby-mode.el
index 779a52def4..25c6b3008d 100644
--- a/misc/ruby-mode.el
+++ b/misc/ruby-mode.el
@@ -255,7 +255,7 @@ The variable ruby-indent-level controls the amount of indentation.
(make-local-variable 'add-log-current-defun-function)
(setq add-log-current-defun-function 'ruby-add-log-current-method)
- (run-mode-hooks 'ruby-mode-hook))
+ (run-hooks 'ruby-mode-hook))
(defun ruby-current-indentation ()
(save-excursion
diff --git a/missing/isinf.c b/missing/isinf.c
index c9e49c6795..e44ef6c3c1 100644
--- a/missing/isinf.c
+++ b/missing/isinf.c
@@ -28,19 +28,12 @@ isinf(n)
#include <ieeefp.h>
#endif
-/*
- * isinf may be provided only as a macro.
- * ex. HP-UX, Solaris 10
- * http://www.gnu.org/software/automake/manual/autoconf/Function-Portability.html
- */
-#ifndef isinf
int
isinf(n)
double n;
{
return (!finite(n) && !isnan(n));
}
-#endif
#else
diff --git a/missing/strftime.c b/missing/strftime.c
index caa5eb8719..5522226ec1 100644
--- a/missing/strftime.c
+++ b/missing/strftime.c
@@ -115,22 +115,17 @@ extern char *strchr();
#define range(low, item, hi) max(low, min(item, hi))
-#ifdef __CYGWIN__
-#define DLL_IMPORT __declspec(dllimport)
-#endif
-#ifdef __WIN32__
-#define DLL_IMPORT __declspec(dllimport)
-#endif
#if !defined(OS2) && !defined(MSDOS) && defined(HAVE_TZNAME)
-extern DLL_IMPORT char *tzname[2];
-#ifdef HAVE_DAYLIGHT
-extern DLL_IMPORT int daylight;
-#endif
-#ifdef HAVE_VAR_TIMEZONE
-extern DLL_IMPORT TYPEOF_VAR_TIMEZONE timezone;
+extern char *tzname[2];
+extern int daylight;
+#ifdef SOLARIS
+extern long timezone, altzone;
+#else
+#ifdef __hpux
+extern long timezone;
+#else
+extern int timezone, altzone;
#endif
-#ifdef HAVE_VAR_ALTZONE
-extern DLL_IMPORT TYPEOF_VAR_ALTZONE altzone;
#endif
#endif
@@ -194,8 +189,16 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr)
#endif /* POSIX_SEMANTICS */
#ifndef HAVE_TM_ZONE
#ifndef HAVE_TM_NAME
+#ifndef HAVE_TZNAME
+ extern char *timezone();
struct timeval tv;
struct timezone zone;
+#else
+#ifdef __hpux
+ struct timeval tv;
+ struct timezone zone;
+#endif
+#endif /* HAVE_TZNAME */
#endif /* HAVE_TM_NAME */
#endif /* HAVE_TM_ZONE */
@@ -419,18 +422,21 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr)
*/
off = timeptr->tm_gmtoff / 60;
#else /* !HAVE_TM_ZONE */
-#ifdef HAVE_GETTIMEOFDAY
+#if HAVE_TZNAME
+ /*
+ * Systems with tzname[] probably have timezone as
+ * secs west of GMT. Convert to mins east of GMT.
+ */
+#ifdef __hpux
gettimeofday(&tv, &zone);
off = -zone.tz_minuteswest;
#else
-#if HAVE_VAR_TIMEZONE
-#if HAVE_VAR_ALTZONE
off = -(daylight ? timezone : altzone) / 60;
-#else
- off = -timezone / 60;
-#endif
-#endif
#endif
+#else /* !HAVE_TZNAME */
+ gettimeofday(&tv, &zone);
+ off = -zone.tz_minuteswest;
+#endif /* !HAVE_TZNAME */
#endif /* !HAVE_TM_ZONE */
#endif /* !HAVE_TM_NAME */
if (off < 0) {
@@ -439,7 +445,7 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr)
} else {
tbuf[0] = '+';
}
- sprintf(tbuf+1, "%02u%02u", (unsigned)off/60, (unsigned)off%60);
+ sprintf(tbuf+1, "%02d%02d", off/60, off%60);
break;
#endif /* MAILHEADER_EXT */
@@ -454,15 +460,13 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr)
#ifdef HAVE_TM_NAME
strcpy(tbuf, timeptr->tm_name);
#else
-#ifdef HAVE_TIMEZONE
gettimeofday(& tv, & zone);
-#ifdef TIMEZONE_VOID
+#ifdef __CYGWIN__
strcpy(tbuf, timezone());
#else
strcpy(tbuf, timezone(zone.tz_minuteswest,
timeptr->tm_isdst > 0));
-#endif /* TIMEZONE_VOID */
-#endif /* HAVE_TIMEZONE */
+#endif
#endif /* HAVE_TM_NAME */
#endif /* HAVE_TM_ZONE */
#endif /* HAVE_TZNAME */
@@ -641,7 +645,7 @@ iso8601wknum(const struct tm *timeptr)
* main body of the standard. Thus it requires week 53.
*/
- int weeknum, jan1day;
+ int weeknum, jan1day, diff;
/* get week number, Monday as first day of the week */
weeknum = weeknumber(timeptr, 1);
diff --git a/mkconfig.rb b/mkconfig.rb
index bffefdad14..fdc3dcf0af 100755
--- a/mkconfig.rb
+++ b/mkconfig.rb
@@ -68,7 +68,7 @@ File.foreach "config.status" do |line|
end
if name
- next if /^(?:ac_.*|configure_input|(?:top_)?srcdir|\w+OBJS)$/ =~ name
+ next if /^(?:ac_.*|DEFS|configure_input|(?:top_)?srcdir|\w+OBJS)$/ =~ name
next if /^\$\(ac_\w+\)$/ =~ val
next if /^\$\{ac_\w+\}$/ =~ val
next if /^\$ac_\w+$/ =~ val
diff --git a/node.h b/node.h
index 476a826883..ec0a6f4fe8 100644
--- a/node.h
+++ b/node.h
@@ -319,7 +319,7 @@ extern NODE *ruby_top_cref;
#define NEW_MODULE(n,b) NEW_NODE(NODE_MODULE,n,NEW_SCOPE(b),0)
#define NEW_COLON2(c,i) NEW_NODE(NODE_COLON2,c,i,0)
#define NEW_COLON3(i) NEW_NODE(NODE_COLON3,0,i,0)
-#define NEW_CREF(c,n) NEW_NODE(NODE_CREF,c,0,n)
+#define NEW_CREF(c) (NEW_NODE(NODE_CREF,0,0,c))
#define NEW_DOT2(b,e) NEW_NODE(NODE_DOT2,b,e,0)
#define NEW_DOT3(b,e) NEW_NODE(NODE_DOT3,b,e,0)
#define NEW_ATTRSET(a) NEW_NODE(NODE_ATTRSET,a,0,0)
@@ -338,8 +338,8 @@ extern NODE *ruby_top_cref;
#define NOEX_PUBLIC 0
#define NOEX_NOSUPER 1
#define NOEX_PRIVATE 2
-#define NOEX_PROTECTED 4
-#define NOEX_MASK 6
+#define NOEX_PROTECTED 4
+#define NOEX_MASK 6
#define NOEX_UNDEF NOEX_NOSUPER
@@ -371,7 +371,6 @@ typedef unsigned int rb_event_t;
#define RUBY_EVENT_ALL 0xff
typedef void (*rb_event_hook_func_t) _((rb_event_t,NODE*,VALUE,ID,VALUE));
-NODE *rb_copy_node_scope _((NODE *, NODE *));
void rb_add_event_hook _((rb_event_hook_func_t,rb_event_t));
int rb_remove_event_hook _((rb_event_hook_func_t));
@@ -391,17 +390,17 @@ typedef struct {
typedef jmp_buf rb_jmpbuf_t;
#endif
-enum rb_thread_status {
+enum thread_status {
THREAD_TO_KILL,
THREAD_RUNNABLE,
THREAD_STOPPED,
THREAD_KILLED,
};
-typedef struct rb_thread *rb_thread_t;
+typedef struct thread * rb_thread_t;
-struct rb_thread {
- rb_thread_t next, prev;
+struct thread {
+ struct thread *next, *prev;
rb_jmpbuf_t context;
#if (defined _WIN32 && !defined _WIN32_WCE) || defined __CYGWIN__
unsigned long win32_exception_list;
@@ -409,13 +408,13 @@ struct rb_thread {
VALUE result;
- size_t stk_len;
- size_t stk_max;
+ long stk_len;
+ long stk_max;
VALUE *stk_ptr;
VALUE *stk_pos;
#ifdef __ia64
- size_t bstr_len;
- size_t bstr_max;
+ long bstr_len;
+ long bstr_max;
VALUE *bstr_ptr;
VALUE *bstr_pos;
#endif
@@ -442,7 +441,7 @@ struct rb_thread {
int safe;
- enum rb_thread_status status;
+ enum thread_status status;
int wait_for;
int fd;
fd_set readfds;
@@ -456,30 +455,17 @@ struct rb_thread {
int priority;
VALUE thgroup;
- struct st_table *locals;
+ st_table *locals;
VALUE thread;
VALUE sandbox;
};
-extern VALUE (*ruby_sandbox_save)_((rb_thread_t));
-extern VALUE (*ruby_sandbox_restore)_((rb_thread_t));
-extern rb_thread_t rb_curr_thread;
-extern rb_thread_t rb_main_thread;
-
-enum {
- RAISED_EXCEPTION = 0x1000,
- RAISED_STACKOVERFLOW = 0x2000,
- RAISED_NOMEMORY = 0x4000,
- RAISED_MASK = 0xf000
-};
-int rb_thread_set_raised(rb_thread_t th);
-int rb_thread_reset_raised(rb_thread_t th);
-#define rb_thread_raised_set(th, f) ((th)->flags |= (f))
-#define rb_thread_raised_reset(th, f) ((th)->flags &= ~(f))
-#define rb_thread_raised_p(th, f) (((th)->flags & (f)) != 0)
-#define rb_thread_raised_clear(th) (rb_thread_raised_reset(th, RAISED_MASK))
+extern VALUE (*ruby_sandbox_save)(struct thread *);
+extern VALUE (*ruby_sandbox_restore)(struct thread *);
+extern rb_thread_t curr_thread;
+extern rb_thread_t main_thread;
#if defined(__cplusplus)
} /* extern "C" { */
diff --git a/numeric.c b/numeric.c
index 21a4f2af4c..23d35a1cd5 100644
--- a/numeric.c
+++ b/numeric.c
@@ -63,25 +63,6 @@
#define DBL_EPSILON 2.2204460492503131e-16
#endif
-#ifndef HAVE_ROUND
-double
-round(x)
- double x;
-{
- double f;
-
- if (x > 0.0) {
- f = floor(x);
- x = f + (x - f >= 0.5);
- }
- else if (x < 0.0) {
- f = ceil(x);
- x = f - (f - x >= 0.5);
- }
- return x;
-}
-#endif
-
static ID id_coerce, id_to_i, id_eq;
VALUE rb_cNumeric;
@@ -121,9 +102,7 @@ num_coerce(x, y)
{
if (CLASS_OF(x) == CLASS_OF(y))
return rb_assoc_new(y, x);
- x = rb_Float(x);
- y = rb_Float(y);
- return rb_assoc_new(y, x);
+ return rb_assoc_new(rb_Float(y), rb_Float(x));
}
static VALUE
@@ -683,10 +662,7 @@ flodivmod(x, y, divp, modp)
mod = x - z * y;
}
#endif
- if (isinf(x) && !isinf(y) && !isnan(y))
- div = x;
- else
- div = (x - mod) / y;
+ div = (x - mod) / y;
if (y*mod < 0) {
mod += y;
div -= 1.0;
@@ -759,11 +735,11 @@ flo_divmod(x, y)
}
flodivmod(RFLOAT(x)->value, fy, &div, &mod);
if (FIXABLE(div)) {
- val = round(div);
- a = LONG2FIX(val);
+ val = div;
+ a = LONG2FIX(val);
}
else {
- a = rb_dbl2big(div);
+ a = rb_dbl2big(div);
}
b = rb_float_new(mod);
return rb_assoc_new(a, b);
@@ -1315,7 +1291,8 @@ flo_round(num)
double f = RFLOAT(num)->value;
long val;
- f = round(f);
+ if (f > 0.0) f = floor(f+0.5);
+ if (f < 0.0) f = ceil(f-0.5);
if (!FIXABLE(f)) {
return rb_dbl2big(f);
@@ -1536,7 +1513,6 @@ long
rb_num2long(val)
VALUE val;
{
- again:
if (NIL_P(val)) {
rb_raise(rb_eTypeError, "no implicit conversion from nil to integer");
}
@@ -1554,7 +1530,7 @@ rb_num2long(val)
char *s;
sprintf(buf, "%-.10g", RFLOAT(val)->value);
- if ((s = strchr(buf, ' ')) != 0) *s = '\0';
+ if (s = strchr(buf, ' ')) *s = '\0';
rb_raise(rb_eRangeError, "float %s out of range of integer", buf);
}
@@ -1563,7 +1539,7 @@ rb_num2long(val)
default:
val = rb_to_int(val);
- goto again;
+ return NUM2LONG(val);
}
}
@@ -1597,21 +1573,11 @@ check_int(num)
}
static void
-check_uint(num, sign)
+check_uint(num)
unsigned long num;
- VALUE sign;
{
- static const unsigned long mask = ~(unsigned long)UINT_MAX;
-
- if (RTEST(sign)) {
- /* minus */
- if ((num & mask) != mask || (num & ~mask) <= INT_MAX + 1UL)
- rb_raise(rb_eRangeError, "integer %ld too small to convert to `unsigned int'", num);
- }
- else {
- /* plus */
- if ((num & mask) != 0)
- rb_raise(rb_eRangeError, "integer %lu too big to convert to `unsigned int'", num);
+ if (num > UINT_MAX) {
+ rb_raise(rb_eRangeError, "integer %lu too big to convert to `unsigned int'", num);
}
}
@@ -1641,7 +1607,9 @@ rb_num2uint(val)
{
unsigned long num = rb_num2ulong(val);
- check_uint(num, rb_funcall(val, '<', 1, INT2FIX(0)));
+ if (RTEST(rb_funcall(INT2FIX(0), '<', 1, val))) {
+ check_uint(num);
+ }
return num;
}
@@ -1655,8 +1623,9 @@ rb_fix2uint(val)
return rb_num2uint(val);
}
num = FIX2ULONG(val);
-
- check_uint(num, rb_funcall(val, '<', 1, INT2FIX(0)));
+ if (FIX2LONG(val) > 0) {
+ check_uint(num);
+ }
return num;
}
#else
@@ -1712,7 +1681,7 @@ rb_num2ll(val)
char *s;
sprintf(buf, "%-.10g", RFLOAT(val)->value);
- if ((s = strchr(buf, ' ')) != 0) *s = '\0';
+ if (s = strchr(buf, ' ')) *s = '\0';
rb_raise(rb_eRangeError, "float %s out of range of long long", buf);
}
@@ -2208,15 +2177,6 @@ fix_divmod(x, y)
return rb_num_coerce_bin(x, y);
}
-static VALUE
-int_even_p(VALUE num)
-{
- if (rb_funcall(num, '%', 1, INT2FIX(2)) == INT2FIX(0)) {
- return Qtrue;
- }
- return Qfalse;
-}
-
/*
* call-seq:
* fix ** other => Numeric
@@ -2233,51 +2193,22 @@ static VALUE
fix_pow(x, y)
VALUE x, y;
{
- static const double zero = 0.0;
- long a = FIX2LONG(x);
-
if (FIXNUM_P(y)) {
- long b;
+ long a, b;
b = FIX2LONG(y);
if (b == 0) return INT2FIX(1);
if (b == 1) return x;
a = FIX2LONG(x);
- if (a == 0) {
- if (b > 0) return INT2FIX(0);
- return rb_float_new(1.0 / zero);
- }
- if (a == 1) return INT2FIX(1);
- if (a == -1) {
- if (b % 2 == 0)
- return INT2FIX(1);
- else
- return INT2FIX(-1);
- }
if (b > 0) {
return rb_big_pow(rb_int2big(a), y);
}
return rb_float_new(pow((double)a, (double)b));
+ } else if (TYPE(y) == T_FLOAT) {
+ long a = FIX2LONG(x);
+ return rb_float_new(pow((double)a, RFLOAT(y)->value));
}
- switch (TYPE(y)) {
- case T_BIGNUM:
- if (a == 0) return INT2FIX(0);
- if (a == 1) return INT2FIX(1);
- if (a == -1) {
- if (int_even_p(y)) return INT2FIX(1);
- else return INT2FIX(-1);
- }
- x = rb_int2big(FIX2LONG(x));
- return rb_big_pow(x, y);
- case T_FLOAT:
- if (a == 0) {
- return rb_float_new(RFLOAT(y)->value < 0 ? (1.0 / zero) : 0.0);
- }
- if (a == 1) return rb_float_new(1.0);
- return rb_float_new(pow((double)a, RFLOAT(y)->value));
- default:
- return rb_num_coerce_bin(x, y);
- }
+ return rb_num_coerce_bin(x, y);
}
/*
@@ -2434,16 +2365,6 @@ fix_rev(num)
return LONG2NUM(val);
}
-static VALUE
-fix_coerce(x)
- VALUE x;
-{
- while (!FIXNUM_P(x) && TYPE(x) != T_BIGNUM) {
- x = rb_to_int(x);
- }
- return x;
-}
-
/*
* call-seq:
* fix & other => integer
@@ -2457,10 +2378,10 @@ fix_and(x, y)
{
long val;
- if (!FIXNUM_P(y = fix_coerce(y))) {
+ if (TYPE(y) == T_BIGNUM) {
return rb_big_and(y, x);
}
- val = FIX2LONG(x) & FIX2LONG(y);
+ val = FIX2LONG(x) & NUM2LONG(y);
return LONG2NUM(val);
}
@@ -2477,10 +2398,10 @@ fix_or(x, y)
{
long val;
- if (!FIXNUM_P(y = fix_coerce(y))) {
+ if (TYPE(y) == T_BIGNUM) {
return rb_big_or(y, x);
}
- val = FIX2LONG(x) | FIX2LONG(y);
+ val = FIX2LONG(x) | NUM2LONG(y);
return LONG2NUM(val);
}
@@ -2497,15 +2418,14 @@ fix_xor(x, y)
{
long val;
- if (!FIXNUM_P(y = fix_coerce(y))) {
+ if (TYPE(y) == T_BIGNUM) {
return rb_big_xor(y, x);
}
- val = FIX2LONG(x) ^ FIX2LONG(y);
+ val = FIX2LONG(x) ^ NUM2LONG(y);
return LONG2NUM(val);
}
-static VALUE fix_lshift _((long, unsigned long));
-static VALUE fix_rshift _((long, unsigned long));
+static VALUE fix_rshift _((VALUE, VALUE));
/*
* call-seq:
@@ -2515,28 +2435,18 @@ static VALUE fix_rshift _((long, unsigned long));
*/
static VALUE
-rb_fix_lshift(x, y)
+fix_lshift(x, y)
VALUE x, y;
{
long val, width;
val = NUM2LONG(x);
- if (!FIXNUM_P(y))
- return rb_big_lshift(rb_int2big(val), y);
- width = FIX2LONG(y);
+ width = NUM2LONG(y);
if (width < 0)
- return fix_rshift(val, (unsigned long)-width);
- return fix_lshift(val, width);
-}
-
-static VALUE
-fix_lshift(val, width)
- long val;
- unsigned long width;
-{
+ return fix_rshift(x, LONG2FIX(-width));
if (width > (sizeof(VALUE)*CHAR_BIT-1)
|| ((unsigned long)val)>>(sizeof(VALUE)*CHAR_BIT-1-width) > 0) {
- return rb_big_lshift(rb_int2big(val), ULONG2NUM(width));
+ return rb_big_lshift(rb_int2big(val), y);
}
val = val << width;
return LONG2NUM(val);
@@ -2550,24 +2460,16 @@ fix_lshift(val, width)
*/
static VALUE
-rb_fix_rshift(x, y)
+fix_rshift(x, y)
VALUE x, y;
{
long i, val;
- val = FIX2LONG(x);
- if (!FIXNUM_P(y))
- return rb_big_rshift(rb_int2big(val), y);
- i = FIX2LONG(y);
- if (i == 0) return x;
+ i = NUM2LONG(y);
if (i < 0)
- return fix_lshift(val, (unsigned long)-i);
- return fix_rshift(val, i);
-}
-
-static VALUE
-fix_rshift(long val, unsigned long i)
-{
+ return fix_lshift(x, LONG2FIX(-i));
+ if (i == 0) return x;
+ val = FIX2LONG(x);
if (i >= sizeof(long)*CHAR_BIT-1) {
if (val < 0) return INT2FIX(-1);
return INT2FIX(0);
@@ -2599,7 +2501,7 @@ fix_aref(fix, idx)
long val = FIX2LONG(fix);
long i;
- if (!FIXNUM_P(idx = fix_coerce(idx))) {
+ if (TYPE(idx) == T_BIGNUM) {
idx = rb_big_norm(idx);
if (!FIXNUM_P(idx)) {
if (!RBIGNUM(idx)->sign || val >= 0)
@@ -2607,7 +2509,7 @@ fix_aref(fix, idx)
return INT2FIX(1);
}
}
- i = FIX2LONG(idx);
+ i = NUM2LONG(idx);
if (i < 0) return INT2FIX(0);
if (sizeof(VALUE)*CHAR_BIT-1 < i) {
@@ -2968,8 +2870,8 @@ Init_Numeric()
rb_define_method(rb_cFixnum, "^", fix_xor, 1);
rb_define_method(rb_cFixnum, "[]", fix_aref, 1);
- rb_define_method(rb_cFixnum, "<<", rb_fix_lshift, 1);
- rb_define_method(rb_cFixnum, ">>", rb_fix_rshift, 1);
+ rb_define_method(rb_cFixnum, "<<", fix_lshift, 1);
+ rb_define_method(rb_cFixnum, ">>", fix_rshift, 1);
rb_define_method(rb_cFixnum, "to_f", fix_to_f, 0);
rb_define_method(rb_cFixnum, "size", fix_size, 0);
diff --git a/object.c b/object.c
index 60df9b3386..706455713c 100644
--- a/object.c
+++ b/object.c
@@ -839,6 +839,28 @@ nil_inspect(obj)
return rb_str_new2("nil");
}
+#ifdef NIL_PLUS
+static VALUE
+nil_plus(x, y)
+ VALUE x, y;
+{
+ switch (TYPE(y)) {
+ case T_NIL:
+ case T_FIXNUM:
+ case T_FLOAT:
+ case T_BIGNUM:
+ case T_STRING:
+ case T_ARRAY:
+ return y;
+ default:
+ rb_raise(rb_eTypeError, "tried to add %s(%s) to nil",
+ RSTRING(rb_inspect(y))->ptr,
+ rb_obj_classname(y));
+ }
+ /* not reached */
+}
+#endif
+
static VALUE
main_to_s(obj)
VALUE obj;
@@ -2281,7 +2303,6 @@ rb_cstr_to_dbl(p, badcheck)
else {
while (ISSPACE(*p) || *p == '_') p++;
}
- errno = 0;
d = strtod(p, &end);
if (errno == ERANGE) {
OutOfRange();
diff --git a/pack.c b/pack.c
index 08f72465f8..e5324d1e8e 100644
--- a/pack.c
+++ b/pack.c
@@ -494,9 +494,7 @@ pack_pack(ary, fmt)
}
}
if (*p == '*') { /* set data length */
- len = strchr("@Xxu", type) ? 0
- : strchr("PMm", type) ? 1
- : items;
+ len = strchr("@Xxu", type) ? 0 : items;
p++;
}
else if (ISDIGIT(*p)) {
@@ -612,7 +610,7 @@ pack_pack(ary, fmt)
long i, j = 0;
if (len > plen) {
- j = (len + 1) / 2 - (plen + 1) / 2;
+ j = (len - plen + 1)/2;
len = plen;
}
for (i=0; i++ < len; ptr++) {
@@ -643,7 +641,7 @@ pack_pack(ary, fmt)
long i, j = 0;
if (len > plen) {
- j = (len + 1) / 2 - (plen + 1) / 2;
+ j = (len - plen + 1)/2;
len = plen;
}
for (i=0; i++ < len; ptr++) {
@@ -1003,7 +1001,6 @@ pack_pack(ary, fmt)
if (associates) {
rb_str_associate(res, associates);
}
- OBJ_INFECT(res, fmt);
return res;
}
diff --git a/parse.y b/parse.y
index 1d7cf8753e..c30e42315a 100644
--- a/parse.y
+++ b/parse.y
@@ -124,8 +124,6 @@ static int compile_for_eval = 0;
static ID cur_mid = 0;
static int command_start = Qtrue;
-static NODE *deferred_nodes;
-
static NODE *cond();
static NODE *logop();
static int cond_negative();
@@ -183,8 +181,6 @@ static NODE *dyna_init();
static void top_local_init();
static void top_local_setup();
-static void fixup_nodes();
-
#define RE_OPTION_ONCE 0x80
#define NODE_STRTERM NODE_ZARRAY /* nothing to gc */
@@ -395,7 +391,6 @@ bodystmt : compstmt
compstmt : stmts opt_terms
{
void_stmts($1);
- fixup_nodes(&deferred_nodes);
$$ = $1;
}
;
@@ -411,7 +406,7 @@ stmts : none
}
| error stmt
{
- $$ = remove_begin($2);
+ $$ = $2;
}
;
@@ -441,7 +436,7 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
}
| stmt kIF_MOD expr_value
{
- $$ = NEW_IF(cond($3), remove_begin($1), 0);
+ $$ = NEW_IF(cond($3), $1, 0);
fixpos($$, $3);
if (cond_negative(&$$->nd_cond)) {
$$->nd_else = $$->nd_body;
@@ -450,7 +445,7 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
}
| stmt kUNLESS_MOD expr_value
{
- $$ = NEW_UNLESS(cond($3), remove_begin($1), 0);
+ $$ = NEW_UNLESS(cond($3), $1, 0);
fixpos($$, $3);
if (cond_negative(&$$->nd_cond)) {
$$->nd_body = $$->nd_else;
@@ -483,8 +478,7 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
}
| stmt kRESCUE_MOD stmt
{
- NODE *resq = NEW_RESBODY(0, remove_begin($3), 0);
- $$ = NEW_RESCUE(remove_begin($1), resq, 0);
+ $$ = NEW_RESCUE($1, NEW_RESBODY(0,$3,0), 0);
}
| klBEGIN
{
@@ -1082,20 +1076,26 @@ arg : lhs '=' arg
{
value_expr($1);
value_expr($3);
- $$ = NEW_DOT2($1, $3);
if (nd_type($1) == NODE_LIT && FIXNUM_P($1->nd_lit) &&
nd_type($3) == NODE_LIT && FIXNUM_P($3->nd_lit)) {
- deferred_nodes = list_append(deferred_nodes, $$);
+ $1->nd_lit = rb_range_new($1->nd_lit, $3->nd_lit, Qfalse);
+ $$ = $1;
+ }
+ else {
+ $$ = NEW_DOT2($1, $3);
}
}
| arg tDOT3 arg
{
value_expr($1);
value_expr($3);
- $$ = NEW_DOT3($1, $3);
if (nd_type($1) == NODE_LIT && FIXNUM_P($1->nd_lit) &&
nd_type($3) == NODE_LIT && FIXNUM_P($3->nd_lit)) {
- deferred_nodes = list_append(deferred_nodes, $$);
+ $1->nd_lit = rb_range_new($1->nd_lit, $3->nd_lit, Qtrue);
+ $$ = $1;
+ }
+ else {
+ $$ = NEW_DOT3($1, $3);
}
}
| arg '+' arg
@@ -2143,7 +2143,6 @@ dsym : tSYMBEG xstring_contents tSTRING_END
{
lex_state = EXPR_END;
if (!($$ = $2)) {
- $$ = NEW_NIL();
yyerror("empty symbol literal");
}
else {
@@ -2342,8 +2341,6 @@ f_rest_arg : restarg_mark tIDENTIFIER
{
if (!is_local_id($2))
yyerror("rest argument must be local variable");
- else if (local_id($2))
- yyerror("duplicate rest argument name");
if (dyna_in_block()) {
rb_dvar_push($2, Qnil);
}
@@ -2518,9 +2515,7 @@ static int
yyerror(msg)
const char *msg;
{
- const int max_line_margin = 30;
- const char *p, *pe;
- char *buf;
+ char *p, *pe, *buf;
int len, i;
rb_compile_error("%s", msg);
@@ -2539,32 +2534,17 @@ yyerror(msg)
len = pe - p;
if (len > 4) {
- char *p2;
- const char *pre = "", *post = "";
-
- if (len > max_line_margin * 2 + 10) {
- int re_mbc_startpos _((const char *, int, int, int));
- if ((len = lex_p - p) > max_line_margin) {
- p = p + re_mbc_startpos(p, len, len - max_line_margin, 0);
- pre = "...";
- }
- if ((len = pe - lex_p) > max_line_margin) {
- pe = lex_p + re_mbc_startpos(lex_p, len, max_line_margin, 1);
- post = "...";
- }
- len = pe - p;
- }
buf = ALLOCA_N(char, len+2);
MEMCPY(buf, p, char, len);
buf[len] = '\0';
- rb_compile_error_append("%s%s%s", pre, buf, post);
+ rb_compile_error_append("%s", buf);
i = lex_p - p;
- p2 = buf; pe = buf + len;
+ p = buf; pe = p + len;
- while (p2 < pe) {
- if (*p2 != '\t') *p2 = ' ';
- p2++;
+ while (p < pe) {
+ if (*p != '\t') *p = ' ';
+ p++;
}
buf[i] = '^';
buf[i+1] = '\0';
@@ -2601,8 +2581,11 @@ yycompile(f, line)
hash = rb_const_get(rb_cObject, rb_intern("SCRIPT_LINES__"));
if (TYPE(hash) == T_HASH) {
fname = rb_str_new2(f);
- ruby_debug_lines = rb_ary_new();
- rb_hash_aset(hash, fname, ruby_debug_lines);
+ ruby_debug_lines = rb_hash_aref(hash, fname);
+ if (NIL_P(ruby_debug_lines)) {
+ ruby_debug_lines = rb_ary_new();
+ rb_hash_aset(hash, fname, ruby_debug_lines);
+ }
}
if (line > 1) {
VALUE str = rb_str_new(0,0);
@@ -2615,12 +2598,10 @@ yycompile(f, line)
ruby__end__seen = 0;
ruby_eval_tree = 0;
- ruby_eval_tree_begin = 0;
heredoc_end = 0;
lex_strterm = 0;
ruby_current_node = 0;
ruby_sourcefile = rb_source_filename(f);
- deferred_nodes = 0;
n = yyparse();
ruby_debug_lines = 0;
compile_for_eval = 0;
@@ -2632,7 +2613,6 @@ yycompile(f, line)
in_single = 0;
in_def = 0;
cur_mid = 0;
- deferred_nodes = 0;
vp = ruby_dyna_vars;
ruby_dyna_vars = vars;
@@ -2643,7 +2623,7 @@ yycompile(f, line)
rb_gc_force_recycle((VALUE)tmp);
}
if (n == 0) node = ruby_eval_tree;
- if (ruby_nerrs) ruby_eval_tree_begin = 0;
+ else ruby_eval_tree_begin = 0;
return node;
}
@@ -3368,7 +3348,6 @@ arg_ambiguous()
}
#define IS_ARG() (lex_state == EXPR_ARG || lex_state == EXPR_CMDARG)
-#define IS_BEG() (lex_state == EXPR_BEG || lex_state == EXPR_MID || lex_state == EXPR_CLASS)
static int
yylex()
@@ -3454,7 +3433,7 @@ yylex()
rb_warning("`*' interpreted as argument prefix");
c = tSTAR;
}
- else if (IS_BEG()) {
+ else if (lex_state == EXPR_BEG || lex_state == EXPR_MID) {
c = tSTAR;
}
else {
@@ -3683,7 +3662,7 @@ yylex()
rb_warning("`&' interpreted as argument prefix");
c = tAMPER;
}
- else if (IS_BEG()) {
+ else if (lex_state == EXPR_BEG || lex_state == EXPR_MID) {
c = tAMPER;
}
else {
@@ -3737,7 +3716,7 @@ yylex()
lex_state = EXPR_BEG;
return tOP_ASGN;
}
- if (IS_BEG() ||
+ if (lex_state == EXPR_BEG || lex_state == EXPR_MID ||
(IS_ARG() && space_seen && !ISSPACE(c))) {
if (IS_ARG()) arg_ambiguous();
lex_state = EXPR_BEG;
@@ -3767,7 +3746,7 @@ yylex()
lex_state = EXPR_BEG;
return tOP_ASGN;
}
- if (IS_BEG() ||
+ if (lex_state == EXPR_BEG || lex_state == EXPR_MID ||
(IS_ARG() && space_seen && !ISSPACE(c))) {
if (IS_ARG()) arg_ambiguous();
lex_state = EXPR_BEG;
@@ -3905,8 +3884,7 @@ yylex()
nondigit = c;
continue;
}
- if (c < '0' || c > '9') break;
- if (c > '7') goto invalid_octal;
+ if (c < '0' || c > '7') break;
nondigit = 0;
tokadd(c);
} while ((c = nextc()) != -1);
@@ -3923,7 +3901,6 @@ yylex()
}
}
if (c > '7' && c <= '9') {
- invalid_octal:
yyerror("Illegal octal digit");
}
else if (c == '.' || c == 'e' || c == 'E') {
@@ -4028,7 +4005,8 @@ yylex()
case ':':
c = nextc();
if (c == ':') {
- if (IS_BEG() || (IS_ARG() && space_seen)) {
+ if (lex_state == EXPR_BEG || lex_state == EXPR_MID ||
+ lex_state == EXPR_CLASS || (IS_ARG() && space_seen)) {
lex_state = EXPR_BEG;
return tCOLON3;
}
@@ -4055,7 +4033,7 @@ yylex()
return tSYMBEG;
case '/':
- if (IS_BEG()) {
+ if (lex_state == EXPR_BEG || lex_state == EXPR_MID) {
lex_strterm = NEW_STRTERM(str_regexp, '/', 0);
return tREGEXP_BEG;
}
@@ -4117,7 +4095,7 @@ yylex()
case '(':
command_start = Qtrue;
- if (IS_BEG()) {
+ if (lex_state == EXPR_BEG || lex_state == EXPR_MID) {
c = tLPAREN;
}
else if (space_seen) {
@@ -4147,7 +4125,7 @@ yylex()
pushback(c);
return '[';
}
- else if (IS_BEG()) {
+ else if (lex_state == EXPR_BEG || lex_state == EXPR_MID) {
c = tLBRACK;
}
else if (IS_ARG() && space_seen) {
@@ -4180,7 +4158,7 @@ yylex()
return '\\';
case '%':
- if (IS_BEG()) {
+ if (lex_state == EXPR_BEG || lex_state == EXPR_MID) {
int term;
int paren;
@@ -4371,7 +4349,6 @@ yylex()
else {
rb_compile_error("`@@%c' is not allowed as a class variable name", c);
}
- return 0;
}
if (!is_identchar(c)) {
pushback(c);
@@ -4493,7 +4470,6 @@ yylex()
lex_state == EXPR_MID ||
lex_state == EXPR_DOT ||
lex_state == EXPR_ARG ||
- lex_state == EXPR_CLASS ||
lex_state == EXPR_CMDARG) {
if (cmd_state) {
lex_state = EXPR_CMDARG;
@@ -4555,13 +4531,10 @@ newline_node(node)
{
NODE *nl = 0;
if (node) {
- int line;
if (nd_type(node) == NODE_NEWLINE) return node;
- line = nd_line(node);
- node = remove_begin(node);
- nl = NEW_NEWLINE(node);
- nd_set_line(nl, line);
- nl->nd_nth = line;
+ nl = NEW_NEWLINE(node);
+ fixpos(nl, node);
+ nl->nd_nth = nd_line(node);
}
return nl;
}
@@ -5216,7 +5189,7 @@ void_stmts(node)
for (;;) {
if (!node->nd_next) return;
- void_expr0(node->nd_head);
+ void_expr(node->nd_head);
node = node->nd_next;
}
}
@@ -5310,36 +5283,6 @@ warning_unless_e_option(node, str)
if (!e_option_supplied()) parser_warning(node, str);
}
-static void
-fixup_nodes(rootnode)
- NODE **rootnode;
-{
- NODE *node, *next, *head;
-
- for (node = *rootnode; node; node = next) {
- enum node_type type;
- VALUE val;
-
- next = node->nd_next;
- head = node->nd_head;
- rb_gc_force_recycle((VALUE)node);
- *rootnode = next;
- switch (type = nd_type(head)) {
- case NODE_DOT2:
- case NODE_DOT3:
- val = rb_range_new(head->nd_beg->nd_lit, head->nd_end->nd_lit,
- type == NODE_DOT3 ? Qtrue : Qfalse);
- rb_gc_force_recycle((VALUE)head->nd_beg);
- rb_gc_force_recycle((VALUE)head->nd_end);
- nd_set_type(head, NODE_LIT);
- head->nd_lit = val;
- break;
- default:
- break;
- }
- }
-}
-
static NODE *cond0();
static NODE*
@@ -5348,19 +5291,21 @@ range_op(node)
{
enum node_type type;
+ if (!e_option_supplied()) return node;
if (node == 0) return 0;
+ value_expr(node);
+ node = cond0(node);
type = nd_type(node);
if (type == NODE_NEWLINE) {
node = node->nd_next;
type = nd_type(node);
}
- value_expr(node);
if (type == NODE_LIT && FIXNUM_P(node->nd_lit)) {
warn_unless_e_option(node, "integer literal in conditional range");
return call_op(node,tEQ,1,NEW_GVAR(rb_intern("$.")));
}
- return cond0(node);
+ return node;
}
static int
@@ -5769,7 +5714,7 @@ top_local_setup()
rb_mem_clear(vars+i, len-i);
}
else {
- *vars++ = 0;
+ *vars++ = (VALUE)ruby_scope;
rb_mem_clear(vars, len);
}
ruby_scope->local_vars = vars;
@@ -5785,7 +5730,6 @@ top_local_setup()
if (!(ruby_scope->flags & SCOPE_CLONE))
xfree(ruby_scope->local_tbl);
}
- ruby_scope->local_vars[-1] = 0; /* no reference needed */
ruby_scope->local_tbl = local_tbl();
}
}
@@ -5877,7 +5821,6 @@ rb_gc_mark_parser()
rb_gc_mark(lex_lastline);
rb_gc_mark(lex_input);
rb_gc_mark((VALUE)lex_strterm);
- rb_gc_mark((VALUE)deferred_nodes);
}
void
@@ -6163,7 +6106,6 @@ rb_id2name(id)
ID id;
{
char *name;
- st_data_t data;
if (id < tLAST_TOKEN) {
int i;
@@ -6174,8 +6116,8 @@ rb_id2name(id)
}
}
- if (st_lookup(sym_rev_tbl, id, &data))
- return (char *)data;
+ if (st_lookup(sym_rev_tbl, id, (st_data_t *)&name))
+ return name;
if (is_attrset_id(id)) {
ID id2 = (id & ~ID_SCOPE_MASK) | ID_LOCAL;
@@ -6388,7 +6330,7 @@ rb_parser_free(ptr)
{
NODE **prev = &parser_heap, *n;
- while ((n = *prev) != 0) {
+ while (n = *prev) {
if (n->u1.node == ptr) {
*prev = n->u2.node;
rb_gc_force_recycle((VALUE)n);
diff --git a/process.c b/process.c
index 718b8ff67b..3aaf689621 100644
--- a/process.c
+++ b/process.c
@@ -42,7 +42,7 @@ struct timeval rb_time_interval _((VALUE));
#ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h>
#endif
-#ifdef HAVE_SYS_RESOURCE_H
+#ifdef HAVE_GETPRIORITY
# include <sys/resource.h>
#endif
#include "st.h"
@@ -101,13 +101,6 @@ static VALUE S_Tms;
#define BROKEN_SETREGID 1
#endif
-#ifdef BROKEN_SETREUID
-#define setreuid ruby_setreuid
-#endif
-#ifdef BROKEN_SETREGID
-#define setregid ruby_setregid
-#endif
-
#if defined(HAVE_44BSD_SETUID) || defined(__MacOS_X__)
#if !defined(USE_SETREUID) && !defined(BROKEN_SETREUID)
#define OBSOLETE_SETREUID 1
@@ -117,9 +110,6 @@ static VALUE S_Tms;
#endif
#endif
-#define preserving_errno(stmts) \
- do {int saved_errno = errno; stmts; errno = saved_errno;} while (0)
-
/*
* call-seq:
@@ -848,22 +838,23 @@ proc_waitall()
}
static VALUE
-detach_process_watcher(arg)
- void *arg;
+detach_process_watcher(pid_p)
+ int *pid_p;
{
- int pid = (int)(VALUE)arg, status;
+ int cpid, status;
- while (rb_waitpid(pid, &status, WNOHANG) == 0) {
+ for (;;) {
+ cpid = rb_waitpid(*pid_p, &status, WNOHANG);
+ if (cpid != 0) return Qnil;
rb_thread_sleep(1);
}
- return rb_last_status;
}
VALUE
rb_detach_process(pid)
int pid;
{
- return rb_thread_create(detach_process_watcher, (void*)(VALUE)pid);
+ return rb_thread_create(detach_process_watcher, (void*)&pid);
}
@@ -882,11 +873,6 @@ rb_detach_process(pid)
* terminate. <code>detach</code> only checks the status
* periodically (currently once each second).
*
- * The waiting thread returns the exit status of the detached process
- * when it terminates, so you can use <code>Thread#join</code> to
- * know the result. If specified _pid_ is not a valid child process
- * ID, the thread returns +nil+ immediately.
- *
* In this first example, we don't reap the first child process, so
* it appears as a zombie in the process status display.
*
@@ -995,9 +981,8 @@ proc_exec_v(argv, prog)
}
#endif /* MSDOS or __human68k__ or __EMX__ */
before_exec();
- rb_thread_cancel_timer();
execv(prog, argv);
- preserving_errno(after_exec());
+ after_exec();
return -1;
}
@@ -1066,7 +1051,7 @@ rb_proc_exec(str)
#else
before_exec();
execl("/bin/sh", "sh", "-c", str, (char *)NULL);
- preserving_errno(after_exec());
+ after_exec();
#endif
#endif
return -1;
@@ -1075,8 +1060,8 @@ rb_proc_exec(str)
a = argv = ALLOCA_N(char*, (s-str)/2+2);
ss = ALLOCA_N(char, s-str+1);
strcpy(ss, str);
- if ((*a++ = strtok(ss, " \t")) != 0) {
- while ((t = strtok(NULL, " \t")) != 0) {
+ if (*a++ = strtok(ss, " \t")) {
+ while (t = strtok(NULL, " \t")) {
*a++ = t;
}
*a = NULL;
@@ -1195,53 +1180,6 @@ proc_spawn(sv)
#endif
#endif
-struct rb_exec_arg {
- int argc;
- VALUE *argv;
- VALUE prog;
-};
-
-static void
-proc_prepare_args(e, argc, argv, prog)
- struct rb_exec_arg *e;
- int argc;
- VALUE *argv;
- VALUE prog;
-{
- int i;
-
- MEMZERO(e, struct rb_exec_arg, 1);
- if (prog) {
- SafeStringValue(prog);
- StringValueCStr(prog);
- }
- for (i = 0; i < argc; i++) {
- SafeStringValue(argv[i]);
- StringValueCStr(argv[i]);
- }
- security(RSTRING(prog ? prog : argv[0])->ptr);
- e->prog = prog;
- e->argc = argc;
- e->argv = argv;
-}
-
-static VALUE
-proc_exec_args(earg)
- VALUE earg;
-{
- struct rb_exec_arg *e = (struct rb_exec_arg *)earg;
- int argc = e->argc;
- VALUE *argv = e->argv;
- VALUE prog = e->prog;
-
- if (argc == 1 && prog == 0) {
- return (VALUE)rb_proc_exec(RSTRING(argv[0])->ptr);
- }
- else {
- return (VALUE)proc_exec_n(argc, argv, prog);
- }
-}
-
/*
* call-seq:
* exec(command [, arg, ...])
@@ -1274,10 +1212,8 @@ rb_f_exec(argc, argv)
{
VALUE prog = 0;
VALUE tmp;
- struct rb_exec_arg earg;
if (argc == 0) {
- rb_last_status = Qnil;
rb_raise(rb_eArgError, "wrong number of arguments");
}
@@ -1290,8 +1226,15 @@ rb_f_exec(argc, argv)
argv[0] = RARRAY(tmp)->ptr[1];
SafeStringValue(prog);
}
- proc_prepare_args(&earg, argc, argv, prog);
- proc_exec_args((VALUE)&earg);
+ if (argc == 1 && prog == 0) {
+ VALUE cmd = argv[0];
+
+ SafeStringValue(cmd);
+ rb_proc_exec(RSTRING(cmd)->ptr);
+ }
+ else {
+ proc_exec_n(argc, argv, prog);
+ }
rb_sys_fail(RSTRING(argv[0])->ptr);
return Qnil; /* dummy */
}
@@ -1525,9 +1468,6 @@ rb_f_system(argc, argv)
}
#if !defined(_WIN32)
last_status_set(status == -1 ? 127 : status, 0);
-#else
- if (status == -1)
- last_status_set(0x7f << 8, 0);
#endif
#elif defined(__VMS)
VALUE cmd;
@@ -1551,7 +1491,7 @@ rb_f_system(argc, argv)
#else
volatile VALUE prog = 0;
int pid;
- struct rb_exec_arg earg;
+ int i;
RETSIGTYPE (*chfunc)(int);
fflush(stdout);
@@ -1568,15 +1508,27 @@ rb_f_system(argc, argv)
prog = RARRAY(argv[0])->ptr[0];
argv[0] = RARRAY(argv[0])->ptr[1];
}
- proc_prepare_args(&earg, argc, argv, prog);
+ if (prog) {
+ SafeStringValue(prog);
+ StringValueCStr(prog);
+ }
+ for (i = 0; i < argc; i++) {
+ SafeStringValue(argv[i]);
+ StringValueCStr(argv[i]);
+ }
+ security(RSTRING(prog ? prog : argv[0])->ptr);
chfunc = signal(SIGCHLD, SIG_DFL);
retry:
pid = fork();
if (pid == 0) {
/* child process */
- rb_thread_atfork();
- rb_protect(proc_exec_args, (VALUE)&earg, NULL);
+ if (argc == 1 && prog == 0) {
+ rb_proc_exec(RSTRING(argv[0])->ptr);
+ }
+ else {
+ proc_exec_n(argc, argv, prog);
+ }
_exit(127);
}
if (pid < 0) {
@@ -3717,8 +3669,8 @@ Init_process()
rb_define_module_function(rb_mProcGID, "change_privilege", p_gid_change_privilege, 1);
rb_define_module_function(rb_mProcUID, "grant_privilege", p_uid_grant_privilege, 1);
rb_define_module_function(rb_mProcGID, "grant_privilege", p_gid_grant_privilege, 1);
- rb_define_alias(rb_singleton_class(rb_mProcUID), "eid=", "grant_privilege");
- rb_define_alias(rb_singleton_class(rb_mProcGID), "eid=", "grant_privilege");
+ rb_define_alias(rb_mProcUID, "eid=", "grant_privilege");
+ rb_define_alias(rb_mProcGID, "eid=", "grant_privilege");
rb_define_module_function(rb_mProcUID, "re_exchange", p_uid_exchange, 0);
rb_define_module_function(rb_mProcGID, "re_exchange", p_gid_exchange, 0);
rb_define_module_function(rb_mProcUID, "re_exchangeable?", p_uid_exchangeable, 0);
diff --git a/random.c b/random.c
index 4aad42baea..6fa4f2ec02 100644
--- a/random.c
+++ b/random.c
@@ -189,6 +189,7 @@ genrand_real(void)
#include <fcntl.h>
#endif
+static int first = 1;
static VALUE saved_seed = INT2FIX(0);
static VALUE
@@ -244,6 +245,7 @@ rand_init(vseed)
len--;
init_by_array(buf, len);
}
+ first = 0;
old = saved_seed;
saved_seed = seed;
free(buf);
@@ -308,8 +310,8 @@ random_seed()
* srand(number=0) => old_seed
*
* Seeds the pseudorandom number generator to the value of
- * <i>number</i>.<code>to_i.abs</code>. If <i>number</i> is omitted,
- * seeds the generator using a combination of the time, the
+ * <i>number</i>.<code>to_i.abs</code>. If <i>number</i> is omitted
+ * or zero, seeds the generator using a combination of the time, the
* process id, and a sequence number. (This is also the behavior if
* <code>Kernel::rand</code> is called without previously calling
* <code>srand</code>, but without the sequence.) By setting the seed
@@ -443,6 +445,9 @@ rb_f_rand(argc, argv, obj)
long val, max;
rb_scan_args(argc, argv, "01", &vmax);
+ if (first) {
+ rand_init(random_seed());
+ }
switch (TYPE(vmax)) {
case T_FLOAT:
if (RFLOAT(vmax)->value <= LONG_MAX && RFLOAT(vmax)->value >= LONG_MIN) {
@@ -476,7 +481,6 @@ rb_f_rand(argc, argv, obj)
default:
vmax = rb_Integer(vmax);
if (TYPE(vmax) == T_BIGNUM) goto bignum;
- /* fall through */
case T_FIXNUM:
max = FIX2LONG(vmax);
break;
@@ -493,7 +497,6 @@ rb_f_rand(argc, argv, obj)
void
Init_Random()
{
- rand_init(random_seed());
rb_define_global_function("srand", rb_f_srand, -1);
rb_define_global_function("rand", rb_f_rand, -1);
rb_global_variable(&saved_seed);
diff --git a/range.c b/range.c
index 568b24d4b8..3f575de91b 100644
--- a/range.c
+++ b/range.c
@@ -319,11 +319,8 @@ range_step(argc, argv, range)
if (unit == 0) rb_raise(rb_eArgError, "step can't be 0");
if (!EXCL(range)) end += 1;
- i = FIX2LONG(b);
- while (i < end) {
+ for (i=FIX2LONG(b); i<end; i+=unit) {
rb_yield(LONG2NUM(i));
- if (i + unit < i) break;
- i += unit;
}
}
else {
diff --git a/re.c b/re.c
index cdb21720bb..446ea4fa24 100644
--- a/re.c
+++ b/re.c
@@ -78,7 +78,7 @@ rb_memcicmp(x, y, len)
int tmp;
while (len--) {
- if ((tmp = casetable[(unsigned)*p1++] - casetable[(unsigned)*p2++]) != 0)
+ if (tmp = casetable[(unsigned)*p1++] - casetable[(unsigned)*p2++])
return tmp;
}
return 0;
@@ -682,14 +682,6 @@ match_alloc(klass)
return (VALUE)match;
}
-static void
-match_check(VALUE match)
-{
- if (!RMATCH(match)->str) {
- rb_raise(rb_eTypeError, "uninitialized Match");
- }
-}
-
/* :nodoc: */
static VALUE
match_init_copy(obj, orig)
@@ -725,7 +717,6 @@ static VALUE
match_size(match)
VALUE match;
{
- match_check(match);
return INT2FIX(RMATCH(match)->regs->num_regs);
}
@@ -748,7 +739,6 @@ match_offset(match, n)
{
int i = NUM2INT(n);
- match_check(match);
if (i < 0 || RMATCH(match)->regs->num_regs <= i)
rb_raise(rb_eIndexError, "index %d out of matches", i);
@@ -778,7 +768,6 @@ match_begin(match, n)
{
int i = NUM2INT(n);
- match_check(match);
if (i < 0 || RMATCH(match)->regs->num_regs <= i)
rb_raise(rb_eIndexError, "index %d out of matches", i);
@@ -807,7 +796,6 @@ match_end(match, n)
{
int i = NUM2INT(n);
- match_check(match);
if (i < 0 || RMATCH(match)->regs->num_regs <= i)
rb_raise(rb_eIndexError, "index %d out of matches", i);
@@ -904,7 +892,7 @@ rb_reg_search(re, str, pos, reverse)
{
long result;
VALUE match;
- struct re_registers regs;
+ static struct re_registers regs;
long range;
if (pos > RSTRING(str)->len || pos < 0) {
@@ -926,7 +914,6 @@ rb_reg_search(re, str, pos, reverse)
else {
range = RSTRING(str)->len - pos;
}
- MEMZERO(&regs, struct re_registers, 1);
result = re_search(RREGEXP(re)->ptr,RSTRING(str)->ptr,RSTRING(str)->len,
pos, range, &regs);
@@ -939,7 +926,6 @@ rb_reg_search(re, str, pos, reverse)
}
if (result < 0) {
- re_free_registers(&regs);
rb_backref_set(Qnil);
return result;
}
@@ -956,7 +942,6 @@ rb_reg_search(re, str, pos, reverse)
}
re_copy_registers(RMATCH(match)->regs, &regs);
- re_free_registers(&regs);
RMATCH(match)->str = rb_str_new4(str);
rb_backref_set(match);
@@ -971,7 +956,6 @@ rb_reg_nth_defined(nth, match)
VALUE match;
{
if (NIL_P(match)) return Qnil;
- match_check(match);
if (nth >= RMATCH(match)->regs->num_regs) {
return Qnil;
}
@@ -992,7 +976,6 @@ rb_reg_nth_match(nth, match)
long start, end, len;
if (NIL_P(match)) return Qnil;
- match_check(match);
if (nth >= RMATCH(match)->regs->num_regs) {
return Qnil;
}
@@ -1035,7 +1018,6 @@ rb_reg_match_pre(match)
VALUE str;
if (NIL_P(match)) return Qnil;
- match_check(match);
if (RMATCH(match)->BEG(0) == -1) return Qnil;
str = rb_str_substr(RMATCH(match)->str, 0, RMATCH(match)->BEG(0));
if (OBJ_TAINTED(match)) OBJ_TAINT(str);
@@ -1062,7 +1044,6 @@ rb_reg_match_post(match)
long pos;
if (NIL_P(match)) return Qnil;
- match_check(match);
if (RMATCH(match)->BEG(0) == -1) return Qnil;
str = RMATCH(match)->str;
pos = RMATCH(match)->END(0);
@@ -1078,7 +1059,6 @@ rb_reg_match_last(match)
int i;
if (NIL_P(match)) return Qnil;
- match_check(match);
if (RMATCH(match)->BEG(0) == -1) return Qnil;
for (i=RMATCH(match)->regs->num_regs-1; RMATCH(match)->BEG(i) == -1 && i > 0; i--)
@@ -1116,17 +1096,12 @@ match_array(match, start)
VALUE match;
int start;
{
- struct re_registers *regs;
- VALUE ary;
- VALUE target;
+ struct re_registers *regs = RMATCH(match)->regs;
+ VALUE ary = rb_ary_new2(regs->num_regs);
+ VALUE target = RMATCH(match)->str;
int i;
int taint = OBJ_TAINTED(match);
-
- match_check(match);
- regs = RMATCH(match)->regs;
- ary = rb_ary_new2(regs->num_regs);
- target = RMATCH(match)->str;
-
+
for (i=start; i<regs->num_regs; i++) {
if (regs->beg[i] == -1) {
rb_ary_push(ary, Qnil);
@@ -1258,7 +1233,6 @@ match_values_at(argc, argv, match)
VALUE *argv;
VALUE match;
{
- match_check(match);
return rb_values_at(match, RMATCH(match)->regs->num_regs, argc, argv, match_entry);
}
@@ -1285,16 +1259,12 @@ match_select(argc, argv, match)
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
}
else {
- struct re_registers *regs;
- VALUE target;
+ struct re_registers *regs = RMATCH(match)->regs;
+ VALUE target = RMATCH(match)->str;
VALUE result = rb_ary_new();
int i;
int taint = OBJ_TAINTED(match);
- match_check(match);
- regs = RMATCH(match)->regs;
- target = RMATCH(match)->str;
-
for (i=0; i<regs->num_regs; i++) {
VALUE str = rb_str_substr(target, regs->beg[i], regs->end[i]-regs->beg[i]);
if (taint) OBJ_TAINT(str);
@@ -1344,7 +1314,6 @@ static VALUE
match_string(match)
VALUE match;
{
- match_check(match);
return RMATCH(match)->str; /* str is frozen */
}
@@ -1785,7 +1754,7 @@ rb_reg_quote(str)
goto meta_found;
}
}
- return rb_str_new3(str);
+ return str;
meta_found:
tmp = rb_str_new(0, RSTRING(str)->len*2);
diff --git a/regex.c b/regex.c
index 54f6b4c9a1..fa04871c1b 100644
--- a/regex.c
+++ b/regex.c
@@ -50,9 +50,6 @@
/* We need this for `regex.h', and perhaps for the Emacs include files. */
# include <sys/types.h>
#endif
-#ifdef HAVE_STDLIB_H
-# include <stdlib.h>
-#endif
#if !defined(__STDC__) && !defined(_MSC_VER)
# define volatile
@@ -66,10 +63,6 @@
#ifdef RUBY_PLATFORM
#include "defines.h"
-#undef xmalloc
-#undef xrealloc
-#undef xcalloc
-#undef xfree
# define RUBY
extern int rb_prohibit_interrupt;
@@ -111,11 +104,6 @@ void *alloca ();
# include <strings.h>
#endif
-#define xmalloc malloc
-#define xrealloc realloc
-#define xcalloc calloc
-#define xfree free
-
#ifdef C_ALLOCA
#define FREE_VARIABLES() alloca(0)
#else
@@ -139,12 +127,10 @@ void *alloca ();
unsigned int xlen = stacke - stackb; \
if (stackb == stacka) { \
stackx = (type*)xmalloc(2 * xlen * sizeof(type)); \
- if (!stackx) goto memory_exhausted; \
memcpy(stackx, stackb, xlen * sizeof (type)); \
} \
else { \
stackx = (type*)xrealloc(stackb, 2 * xlen * sizeof(type)); \
- if (!stackx) goto memory_exhausted; \
} \
/* Rearrange the pointers. */ \
stackp = stackx + (stackp - stackb); \
@@ -2783,8 +2769,8 @@ bm_search(little, llen, big, blen, skip, translate)
The caller must supply the address of a (1 << BYTEWIDTH)-byte data
area as bufp->fastmap.
The other components of bufp describe the pattern to be used. */
-static int
-re_compile_fastmap0(bufp)
+void
+re_compile_fastmap(bufp)
struct re_pattern_buffer *bufp;
{
unsigned char *pattern = (unsigned char*)bufp->buffer;
@@ -2952,7 +2938,7 @@ re_compile_fastmap0(bufp)
fastmap[j] = 1;
}
if (bufp->can_be_null) {
- FREE_AND_RETURN(stackb, 0);
+ FREE_AND_RETURN_VOID(stackb);
}
/* Don't return; check the alternative paths
so we can set can_be_null if appropriate. */
@@ -3118,42 +3104,11 @@ re_compile_fastmap0(bufp)
else
break;
}
- FREE_AND_RETURN(stackb, 0);
- memory_exhausted:
- FREE_AND_RETURN(stackb, -2);
-}
-
-void
-re_compile_fastmap(bufp)
- struct re_pattern_buffer *bufp;
-{
- (void)re_compile_fastmap0(bufp);
+ FREE_AND_RETURN_VOID(stackb);
}
/* adjust startpos value to the position between characters. */
int
-re_mbc_startpos(string, size, startpos, range)
- const char *string;
- int size, startpos, range;
-{
- int i = mbc_startpos(string, startpos);
-
- if (i < startpos) {
- if (range > 0) {
- startpos = i + mbclen(string[i]);
- }
- else {
- int len = mbclen(string[i]);
- if (i + len <= startpos)
- startpos = i + len;
- else
- startpos = i;
- }
- }
- return startpos;
-}
-
-int
re_adjust_startpos(bufp, string, size, startpos, range)
struct re_pattern_buffer *bufp;
const char *string;
@@ -3161,13 +3116,25 @@ re_adjust_startpos(bufp, string, size, startpos, range)
{
/* Update the fastmap now if not correct already. */
if (!bufp->fastmap_accurate) {
- int ret = re_compile_fastmap0(bufp);
- if (ret) return ret;
+ re_compile_fastmap(bufp);
}
/* Adjust startpos for mbc string */
if (current_mbctype && startpos>0 && !(bufp->options&RE_OPTIMIZE_BMATCH)) {
- startpos = re_mbc_startpos(string, size, startpos, range);
+ int i = mbc_startpos(string, startpos);
+
+ if (i < startpos) {
+ if (range > 0) {
+ startpos = i + mbclen(string[i]);
+ }
+ else {
+ int len = mbclen(string[i]);
+ if (i + len <= startpos)
+ startpos = i + len;
+ else
+ startpos = i;
+ }
+ }
}
return startpos;
}
@@ -3201,15 +3168,10 @@ re_search(bufp, string, size, startpos, range, regs)
/* Check for out-of-range starting position. */
if (startpos < 0 || startpos > size)
return -1;
- if (!string) {
- if (size == 0) string = "";
- else return -1;
- }
/* Update the fastmap now if not correct already. */
if (fastmap && !bufp->fastmap_accurate) {
- int ret = re_compile_fastmap0(bufp);
- if (ret) return ret;
+ re_compile_fastmap(bufp);
}
@@ -3599,7 +3561,7 @@ re_match_exec(bufp, string_arg, size, pos, beg, regs)
``dummy''; if a failure happens and the failure point is a dummy, it
gets discarded and the next next one is tried. */
- unsigned char **const stacka = 0;
+ unsigned char **stacka;
unsigned char **stackb;
unsigned char **stackp;
unsigned char **stacke;
@@ -3648,7 +3610,8 @@ re_match_exec(bufp, string_arg, size, pos, beg, regs)
}
/* Initialize the stack. */
- stackb = TMALLOC(MAX_NUM_FAILURE_ITEMS * NFAILURES, unsigned char*);
+ stacka = RE_TALLOC(MAX_NUM_FAILURE_ITEMS * NFAILURES, unsigned char*);
+ stackb = stacka;
stackp = stackb;
stacke = &stackb[MAX_NUM_FAILURE_ITEMS * NFAILURES];
@@ -4418,8 +4381,6 @@ re_match_exec(bufp, string_arg, size, pos, beg, regs)
goto restore_best_regs;
FREE_AND_RETURN(stackb,(-1)); /* Failure to match. */
- memory_exhausted:
- FREE_AND_RETURN(stackb,(-2));
}
@@ -4683,5 +4644,5 @@ utf8_startpos(string, pos)
mode : C
c-file-style : "gnu"
tab-width : 8
- End
+ End :
*/
diff --git a/ruby.c b/ruby.c
index 6fbb6d2dc0..39b209d9e4 100644
--- a/ruby.c
+++ b/ruby.c
@@ -15,9 +15,6 @@
#if defined _WIN32 || defined __CYGWIN__
#include <windows.h>
#endif
-#if defined __CYGWIN__
-#include <sys/cygwin.h>
-#endif
#ifdef _WIN32_WCE
#include <winsock.h>
#include "wince.h"
@@ -112,141 +109,127 @@ NULL
extern VALUE rb_load_path;
-#ifndef CharNext /* defined as CharNext[AW] on Windows. */
-#define CharNext(p) ((p) + mblen(p, RUBY_MBCHAR_MAXSIZE))
-#endif
-
-#if defined DOSISH || defined __CYGWIN__
-static inline void
-translate_char(char *p, int from, int to)
-{
- while (*p) {
- if ((unsigned char)*p == from)
- *p = to;
- p = CharNext(p);
- }
-}
-#endif
+#define STATIC_FILE_LENGTH 255
#if defined _WIN32 || defined __CYGWIN__ || defined __DJGPP__
-static VALUE
-rubylib_mangled_path(const char *s, unsigned int l)
+static char *
+rubylib_mangle(s, l)
+ char *s;
+ unsigned int l;
{
static char *newp, *oldp;
static int newl, oldl, notfound;
- char *ptr;
- VALUE ret;
+ static char newsub[STATIC_FILE_LENGTH+1];
if (!newp && !notfound) {
newp = getenv("RUBYLIB_PREFIX");
if (newp) {
- oldp = newp = strdup(newp);
+ char *s;
+
+ oldp = newp;
while (*newp && !ISSPACE(*newp) && *newp != ';') {
- newp = CharNext(newp); /* Skip digits. */
+ newp++; oldl++; /* Skip digits. */
}
- oldl = newp - oldp;
while (*newp && (ISSPACE(*newp) || *newp == ';')) {
- newp = CharNext(newp); /* Skip whitespace. */
+ newp++; /* Skip whitespace. */
}
newl = strlen(newp);
- if (newl == 0 || oldl == 0) {
+ if (newl == 0 || oldl == 0 || newl > STATIC_FILE_LENGTH) {
rb_fatal("malformed RUBYLIB_PREFIX");
}
- translate_char(newp, '\\', '/');
+ strcpy(newsub, newp);
+ s = newsub;
+ while (*s) {
+ if (*s == '\\') *s = '/';
+ s++;
+ }
}
else {
notfound = 1;
}
}
+ if (l == 0) {
+ l = strlen(s);
+ }
if (!newp || l < oldl || strncasecmp(oldp, s, oldl) != 0) {
- return rb_str_new(s, l);
+ static char ret[STATIC_FILE_LENGTH+1];
+ strncpy(ret, s, l);
+ ret[l] = 0;
+ return ret;
}
- ret = rb_str_new(0, l + newl - oldl);
- ptr = RSTRING_PTR(ret);
- memcpy(ptr, newp, newl);
- memcpy(ptr + newl, s + oldl, l - oldl);
- ptr[l + newl - oldl] = 0;
- return ret;
-}
-
-static VALUE
-rubylib_mangled_path2(const char *s)
-{
- return rubylib_mangled_path(s, strlen(s));
+ if (l + newl - oldl > STATIC_FILE_LENGTH || newl > STATIC_FILE_LENGTH) {
+ rb_fatal("malformed RUBYLIB_PREFIX");
+ }
+ strcpy(newsub + newl, s + oldl);
+ newsub[l + newl - oldl] = 0;
+ return newsub;
}
+#define rubylib_mangled_path(s, l) rb_str_new2(rubylib_mangle((s), (l)))
+#define rubylib_mangled_path2(s) rb_str_new2(rubylib_mangle((s), 0))
#else
-#define rubylib_mangled_path rb_str_new
-#define rubylib_mangled_path2 rb_str_new2
+#define rubylib_mangled_path(s, l) rb_str_new((s), (l))
+#define rubylib_mangled_path2(s) rb_str_new2(s)
#endif
-static void push_include _((const char *path));
-
-static void
-push_include(path)
+void
+ruby_incpush(path)
const char *path;
{
const char sep = PATH_SEP_CHAR;
- const char *p, *s;
- p = path;
- while (*p) {
- while (*p == sep)
- p++;
- if (!*p) break;
- for (s = p; *s && *s != sep; s = CharNext(s));
- rb_ary_push(rb_load_path, rubylib_mangled_path(p, s - p));
- p = s;
+ if (path == 0) return;
+#if defined(__CYGWIN__)
+ {
+ char rubylib[FILENAME_MAX];
+ conv_to_posix_path(path, rubylib, FILENAME_MAX);
+ path = rubylib;
}
-}
-
-#ifdef __CYGWIN__
-static void
-push_include_cygwin(const char *path)
-{
- const char *p, *s;
- char rubylib[FILENAME_MAX];
- VALUE buf = 0;
-
- p = path;
- while (*p) {
- unsigned int len;
- while (*p == ';')
- p++;
- if (!*p) break;
- for (s = p; *s && *s != ';'; s = CharNext(s));
- len = s - p;
- if (*s) {
- if (!buf) {
- buf = rb_str_new(p, len);
- p = RSTRING_PTR(buf);
+#endif
+ if (strchr(path, sep)) {
+ const char *p, *s;
+ VALUE ary = rb_ary_new();
+
+ p = path;
+ while (*p) {
+ while (*p == sep) p++;
+ if ((s = strchr(p, sep)) != 0) {
+ rb_ary_push(ary, rubylib_mangled_path(p, (int)(s-p)));
+ p = s + 1;
}
else {
- rb_str_resize(buf, len);
- p = strncpy(RSTRING_PTR(buf), p, len);
+ rb_ary_push(ary, rubylib_mangled_path2(p));
+ break;
}
}
- if (cygwin_conv_to_posix_path(p, rubylib) == 0)
- p = rubylib;
- push_include(p);
- if (!*s) break;
- p = s + 1;
+ rb_ary_concat(rb_load_path, ary);
+ }
+ else {
+ rb_ary_push(rb_load_path, rubylib_mangled_path2(path));
}
}
-#define push_include push_include_cygwin
+#if defined DOSISH || defined __CYGWIN__
+#define LOAD_RELATIVE 1
#endif
-void
-ruby_incpush(path)
- const char *path;
+#if defined DOSISH || defined __CYGWIN__
+static inline void translate_char _((char *, int, int));
+
+static inline void
+translate_char(p, from, to)
+ char *p;
+ int from, to;
{
- if (path == 0)
- return;
- push_include(path);
+ while (*p) {
+ if ((unsigned char)*p == from)
+ *p = to;
+#ifdef CharNext /* defined as CharNext[AW] on Windows. */
+ p = CharNext(p);
+#else
+ p += mblen(p, MB_CUR_MAX);
+#endif
+ }
}
-
-#if defined DOSISH || defined __CYGWIN__
-#define LOAD_RELATIVE 1
#endif
void
@@ -277,19 +260,13 @@ ruby_init_loadpath()
#endif
libpath[FILENAME_MAX] = '\0';
-#if defined DOSISH
+#if defined DOSISH || defined __CYGWIN__
translate_char(libpath, '\\', '/');
-#elif defined __CYGWIN__
- {
- char rubylib[FILENAME_MAX];
- cygwin_conv_to_posix_path(libpath, rubylib);
- strncpy(libpath, rubylib, sizeof(libpath));
- }
#endif
p = strrchr(libpath, '/');
if (p) {
*p = 0;
- if (p - libpath > 3 && !strcasecmp(p - 4, "/bin")) {
+ if (p-libpath > 3 && !strcasecmp(p-4, "/bin")) {
p -= 4;
*p = 0;
}
@@ -305,31 +282,30 @@ ruby_init_loadpath()
#else
#define RUBY_RELATIVE(path) (path)
#endif
-#define incpush(path) rb_ary_push(rb_load_path, rubylib_mangled_path2(path))
if (rb_safe_level() == 0) {
ruby_incpush(getenv("RUBYLIB"));
}
#ifdef RUBY_SEARCH_PATH
- incpush(RUBY_RELATIVE(RUBY_SEARCH_PATH));
+ ruby_incpush(RUBY_RELATIVE(RUBY_SEARCH_PATH));
#endif
- incpush(RUBY_RELATIVE(RUBY_SITE_LIB2));
+ ruby_incpush(RUBY_RELATIVE(RUBY_SITE_LIB2));
#ifdef RUBY_SITE_THIN_ARCHLIB
- incpush(RUBY_RELATIVE(RUBY_SITE_THIN_ARCHLIB));
+ ruby_incpush(RUBY_RELATIVE(RUBY_SITE_THIN_ARCHLIB));
#endif
- incpush(RUBY_RELATIVE(RUBY_SITE_ARCHLIB));
- incpush(RUBY_RELATIVE(RUBY_SITE_LIB));
+ ruby_incpush(RUBY_RELATIVE(RUBY_SITE_ARCHLIB));
+ ruby_incpush(RUBY_RELATIVE(RUBY_SITE_LIB));
- incpush(RUBY_RELATIVE(RUBY_LIB));
+ ruby_incpush(RUBY_RELATIVE(RUBY_LIB));
#ifdef RUBY_THIN_ARCHLIB
- incpush(RUBY_RELATIVE(RUBY_THIN_ARCHLIB));
+ ruby_incpush(RUBY_RELATIVE(RUBY_THIN_ARCHLIB));
#endif
- incpush(RUBY_RELATIVE(RUBY_ARCHLIB));
+ ruby_incpush(RUBY_RELATIVE(RUBY_ARCHLIB));
if (rb_safe_level() == 0) {
- incpush(".");
+ ruby_incpush(".");
}
}
@@ -775,7 +751,7 @@ proc_options(argc, argv)
}
}
if (!*s) break;
- if (!strchr("IdvwWrK", *s))
+ if (!strchr("IdvwrK", *s))
rb_raise(rb_eRuntimeError, "illegal switch in RUBYOPT: -%c", *s);
s = moreswitches(s);
}
@@ -1029,50 +1005,15 @@ set_arg0space()
#define set_arg0space() ((void)0)
#endif
-static int
-get_arglen(int argc, char **argv)
-{
- char *s = argv[0];
- int i;
-
- if (!argc) return 0;
- s += strlen(s);
- /* See if all the arguments are contiguous in memory */
- for (i = 1; i < argc; i++) {
- if (argv[i] == s + 1) {
- s++;
- s += strlen(s); /* this one is ok too */
- }
- else {
- break;
- }
- }
-#if defined(USE_ENVSPACE_FOR_ARG0)
- if (environ && (s == environ[0])) {
- s += strlen(s);
- for (i = 1; environ[i]; i++) {
- if (environ[i] == s + 1) {
- s++;
- s += strlen(s); /* this one is ok too */
- }
- }
- ruby_setenv("", NULL); /* duplicate environ vars */
- }
-#endif
- return s - argv[0];
-}
-
static void
set_arg0(val, id)
VALUE val;
ID id;
{
- VALUE progname;
char *s;
long i;
- int j;
#if !defined(PSTAT_SETCMD) && !defined(HAVE_SETPROCTITLE)
- static int len = 0;
+ static int len;
#endif
if (origargv == 0) rb_raise(rb_eRuntimeError, "$0 not initialized");
@@ -1093,13 +1034,33 @@ set_arg0(val, id)
j.pst_command = s;
pstat(PSTAT_SETCMD, j, i, 0, 0);
}
- progname = rb_tainted_str_new(s, i);
+ rb_progname = rb_tainted_str_new(s, i);
#elif defined(HAVE_SETPROCTITLE)
setproctitle("%.*s", (int)i, s);
- progname = rb_tainted_str_new(s, i);
+ rb_progname = rb_tainted_str_new(s, i);
#else
if (len == 0) {
- len = get_arglen(origargc, origargv);
+ char *s = origargv[0];
+ int i;
+
+ s += strlen(s);
+ /* See if all the arguments are contiguous in memory */
+ for (i = 1; i < origargc; i++) {
+ if (origargv[i] == s + 1) {
+ s++;
+ s += strlen(s); /* this one is ok too */
+ }
+ else {
+ break;
+ }
+ }
+#if defined(USE_ENVSPACE_FOR_ARG0)
+ if (s + 1 == envspace.begin) {
+ s = envspace.end;
+ ruby_setenv("", NULL); /* duplicate environ vars */
+ }
+#endif
+ len = s - origargv[0];
}
if (i >= len) {
@@ -1109,13 +1070,10 @@ set_arg0(val, id)
s = origargv[0] + i;
*s = '\0';
if (++i < len) memset(s + 1, ' ', len - i);
- for (i = len-1, j = origargc-1; j > 0 && i >= 0; --i, --j) {
- origargv[j] = origargv[0] + i;
- *origargv[j] = '\0';
- }
- progname = rb_tainted_str_new2(origargv[0]);
+ for (i = 1; i < origargc; i++)
+ origargv[i] = s;
+ rb_progname = rb_tainted_str_new2(origargv[0]);
#endif
- rb_progname = rb_obj_freeze(progname);
}
void
@@ -1123,7 +1081,7 @@ ruby_script(name)
const char *name;
{
if (name) {
- rb_progname = rb_obj_freeze(rb_tainted_str_new2(name));
+ rb_progname = rb_tainted_str_new2(name);
ruby_sourcefile = rb_source_filename(name);
}
}
diff --git a/ruby.h b/ruby.h
index 2701f0dc77..40c95f2050 100644
--- a/ruby.h
+++ b/ruby.h
@@ -166,7 +166,7 @@ VALUE rb_ull2inum _((unsigned LONG_LONG));
#define FIX2LONG(x) RSHIFT((long)x,1)
#define FIX2ULONG(x) (((unsigned long)(x))>>1)
#define FIXNUM_P(f) (((long)(f))&FIXNUM_FLAG)
-#define POSFIXABLE(f) ((f) < FIXNUM_MAX+1)
+#define POSFIXABLE(f) ((f) <= FIXNUM_MAX)
#define NEGFIXABLE(f) ((f) >= FIXNUM_MIN)
#define FIXABLE(f) (POSFIXABLE(f) && NEGFIXABLE(f))
diff --git a/rubysig.h b/rubysig.h
index 3eb877855e..f716824877 100644
--- a/rubysig.h
+++ b/rubysig.h
@@ -78,12 +78,12 @@ RUBY_EXTERN rb_atomic_t rb_trap_pending;
void rb_trap_restore_mask _((void));
RUBY_EXTERN int rb_thread_critical;
-RUBY_EXTERN int rb_thread_pending;
void rb_thread_schedule _((void));
#if defined(HAVE_SETITIMER) || defined(_THREAD_SAFE)
+RUBY_EXTERN int rb_thread_pending;
# define CHECK_INTS do {\
if (!(rb_prohibit_interrupt || rb_thread_critical)) {\
- if (rb_thread_pending) rb_thread_schedule();\
+ if (rb_thread_pending) rb_thread_schedule();\
if (rb_trap_pending) rb_trap_exec();\
}\
} while (0)
@@ -93,9 +93,9 @@ RUBY_EXTERN int rb_thread_tick;
#define THREAD_TICK 500
#define CHECK_INTS do {\
if (!(rb_prohibit_interrupt || rb_thread_critical)) {\
- if (rb_thread_pending || rb_thread_tick-- <= 0) {\
+ if (rb_thread_tick-- <= 0) {\
rb_thread_tick = THREAD_TICK;\
- rb_thread_schedule();\
+ rb_thread_schedule();\
}\
}\
if (rb_trap_pending) rb_trap_exec();\
diff --git a/runruby.rb b/runruby.rb
index f442d90a9c..cc04895c33 100755
--- a/runruby.rb
+++ b/runruby.rb
@@ -32,17 +32,18 @@ unless File.exist?(ruby)
abort "#{ruby} is not found.\nTry `make' first, then `make test', please.\n"
end
-libs = [abs_archdir]
+libs = [abs_archdir, File.expand_path("lib", srcdir)]
if extout
abs_extout = File.expand_path(extout)
libs << File.expand_path("common", abs_extout) << File.expand_path(RUBY_PLATFORM, abs_extout)
end
-libs << File.expand_path("lib", srcdir)
config["bindir"] = abs_archdir
ENV["RUBY"] = File.expand_path(ruby)
ENV["PATH"] = [abs_archdir, ENV["PATH"]].compact.join(File::PATH_SEPARATOR)
- libs << File.expand_path("ext", srcdir) << "-"
+if e = ENV["RUBYLIB"]
+ libs |= e.split(File::PATH_SEPARATOR)
+end
ENV["RUBYLIB"] = $:.replace(libs).join(File::PATH_SEPARATOR)
libruby_so = File.join(abs_archdir, config['LIBRUBY_SO'])
@@ -55,7 +56,4 @@ if File.file?(libruby_so)
end
end
-cmd = [ruby]
-cmd << "-rpurelib.rb"
-cmd.concat(ARGV)
-exec(*cmd)
+exec ruby, *ARGV
diff --git a/sample/test.rb b/sample/test.rb
index 741e96ee9d..e7f2d251b7 100644
--- a/sample/test.rb
+++ b/sample/test.rb
@@ -1697,10 +1697,7 @@ else
end
def valid_syntax?(code, fname)
- code = code.sub(/\A(?:\s*\#.*$)*(\n)?/n) {
- "#$&#{"\n" if $1 && !$2}BEGIN{return true}\n"
- }
- eval(code, nil, fname, 0)
+ eval("BEGIN {return true}\n#{code}", nil, fname, 0)
rescue Exception
puts $!.message
false
diff --git a/signal.c b/signal.c
index b6cad9dc84..0f1171b30b 100644
--- a/signal.c
+++ b/signal.c
@@ -21,12 +21,6 @@
#undef SIGBUS
#endif
-#if defined HAVE_SIGPROCMASK || defined HAVE_SIGSETMASK
-#define USE_TRAP_MASK 1
-#else
-#define USE_TRAP_MASK 0
-#endif
-
#ifndef NSIG
# ifdef DJGPP
# define NSIG SIGMAX
@@ -569,17 +563,16 @@ sighandler(sig)
#if defined(HAVE_NATIVETHREAD) && defined(HAVE_NATIVETHREAD_KILL)
if (!is_ruby_native_thread() && !rb_trap_accept_nativethreads[sig]) {
- sigsend_to_ruby_thread(sig);
- return;
+ sigsend_to_ruby_thread(sig);
+ return;
}
#endif
#if !defined(BSD_SIGNAL) && !defined(POSIX_SIGNAL)
if (rb_trap_accept_nativethreads[sig]) {
- ruby_nativethread_signal(sig, sighandler);
- }
- else {
- ruby_signal(sig, sighandler);
+ ruby_nativethread_signal(sig, sighandler);
+ } else {
+ ruby_signal(sig, sighandler);
}
#endif
@@ -670,7 +663,7 @@ rb_trap_exec()
}
struct trap_arg {
-#if USE_TRAP_MASK
+#ifndef _WIN32
# ifdef HAVE_SIGPROCMASK
sigset_t mask;
# else
@@ -819,7 +812,7 @@ trap(arg)
trap_list[sig].cmd = command;
trap_list[sig].safe = ruby_safe_level;
/* enable at least specified signal. */
-#if USE_TRAP_MASK
+#ifndef _WIN32
#ifdef HAVE_SIGPROCMASK
sigdelset(&arg->mask, sig);
#else
@@ -829,7 +822,7 @@ trap(arg)
return oldcmd;
}
-#if USE_TRAP_MASK
+#ifndef _WIN32
static VALUE
trap_ensure(arg)
struct trap_arg *arg;
@@ -848,7 +841,7 @@ trap_ensure(arg)
void
rb_trap_restore_mask()
{
-#if USE_TRAP_MASK
+#ifndef _WIN32
# ifdef HAVE_SIGPROCMASK
sigprocmask(SIG_SETMASK, &trap_last_mask, NULL);
# else
@@ -908,7 +901,7 @@ sig_trap(argc, argv)
if (OBJ_TAINTED(arg.cmd)) {
rb_raise(rb_eSecurityError, "Insecure: tainted signal trap");
}
-#if USE_TRAP_MASK
+#ifndef _WIN32
/* disable interrupt */
# ifdef HAVE_SIGPROCMASK
sigfillset(&arg.mask);
@@ -991,7 +984,7 @@ init_sigchld(sig)
int sig;
{
sighandler_t oldfunc;
-#if USE_TRAP_MASK
+#ifndef _WIN32
# ifdef HAVE_SIGPROCMASK
sigset_t mask;
# else
@@ -999,7 +992,7 @@ init_sigchld(sig)
# endif
#endif
-#if USE_TRAP_MASK
+#ifndef _WIN32
/* disable interrupt */
# ifdef HAVE_SIGPROCMASK
sigfillset(&mask);
@@ -1016,7 +1009,7 @@ init_sigchld(sig)
trap_list[sig].cmd = 0;
}
-#if USE_TRAP_MASK
+#ifndef _WIN32
#ifdef HAVE_SIGPROCMASK
sigdelset(&mask, sig);
sigprocmask(SIG_SETMASK, &mask, NULL);
diff --git a/sprintf.c b/sprintf.c
index ba1c40022b..ffe4e22855 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -18,8 +18,6 @@
#include <math.h>
#define BIT_DIGITS(N) (((N)*146)/485 + 1) /* log2(10) =~ 146/485 */
-#define BITSPERDIG (SIZEOF_BDIGITS*CHAR_BIT)
-#define EXTENDSIGN(n, l) (((~0 << (n)) >> (((n)*(l)) % BITSPERDIG)) & ~(~0 << (n)))
static void fmt_setup _((char*,int,int,int,int));
@@ -38,7 +36,7 @@ remove_sign_bits(str, base)
}
}
else if (base == 8) {
- *t |= EXTENDSIGN(3, strlen(t));
+ if (*t == '3') t++;
while (*t == '7') {
t++;
}
@@ -84,7 +82,6 @@ sign_bits(base, p)
#define FSPACE 16
#define FWIDTH 32
#define FPREC 64
-#define FPREC0 128
#define CHECK(l) do {\
while (blen + (l) >= bsiz) {\
@@ -113,7 +110,9 @@ sign_bits(base, p)
#define GETNTHARG(nth) \
((nth >= argc) ? (rb_raise(rb_eArgError, "too few arguments"), 0) : argv[nth])
-#define GETNUM(n, val) \
+#define GETASTER(val) do { \
+ t = p++; \
+ n = 0; \
for (; p < end && ISDIGIT(*p); p++) { \
int next_n = 10 * n + (*p - '0'); \
if (next_n / 10 != n) {\
@@ -123,12 +122,7 @@ sign_bits(base, p)
} \
if (p >= end) { \
rb_raise(rb_eArgError, "malformed format string - %%*[0-9]"); \
- }
-
-#define GETASTER(val) do { \
- t = p++; \
- n = 0; \
- GETNUM(n, val); \
+ } \
if (*p == '$') { \
tmp = GETPOSARG(n); \
} \
@@ -249,15 +243,7 @@ rb_f_sprintf(argc, argv)
int argc;
VALUE *argv;
{
- return rb_str_format(argc - 1, argv + 1, GETNTHARG(0));
-}
-
-VALUE
-rb_str_format(argc, argv, fmt)
- int argc;
- VALUE *argv;
VALUE fmt;
-{
const char *p, *end;
char *buf;
int blen, bsiz;
@@ -271,23 +257,7 @@ rb_str_format(argc, argv, fmt)
VALUE tmp;
VALUE str;
-#define CHECK_FOR_WIDTH(f) \
- if ((f) & FWIDTH) { \
- rb_raise(rb_eArgError, "width given twice"); \
- } \
- if ((f) & FPREC0) { \
- rb_raise(rb_eArgError, "width after precision"); \
- }
-#define CHECK_FOR_FLAGS(f) \
- if ((f) & FWIDTH) { \
- rb_raise(rb_eArgError, "flag after width"); \
- } \
- if ((f) & FPREC0) { \
- rb_raise(rb_eArgError, "flag after precision"); \
- }
-
- ++argc;
- --argv;
+ fmt = GETNTHARG(0);
if (OBJ_TAINTED(fmt)) tainted = 1;
StringValue(fmt);
fmt = rb_str_new4(fmt);
@@ -322,31 +292,26 @@ rb_str_format(argc, argv, fmt)
break;
case ' ':
- CHECK_FOR_FLAGS(flags);
flags |= FSPACE;
p++;
goto retry;
case '#':
- CHECK_FOR_FLAGS(flags);
flags |= FSHARP;
p++;
goto retry;
case '+':
- CHECK_FOR_FLAGS(flags);
flags |= FPLUS;
p++;
goto retry;
case '-':
- CHECK_FOR_FLAGS(flags);
flags |= FMINUS;
p++;
goto retry;
case '0':
- CHECK_FOR_FLAGS(flags);
flags |= FZERO;
p++;
goto retry;
@@ -354,7 +319,16 @@ rb_str_format(argc, argv, fmt)
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
n = 0;
- GETNUM(n, width);
+ for (; p < end && ISDIGIT(*p); p++) {
+ int next_n = 10 * n + (*p - '0');
+ if (next_n / 10 != n) {
+ rb_raise(rb_eArgError, "width too big");
+ }
+ n = 10 * n + (*p - '0');
+ }
+ if (p >= end) {
+ rb_raise(rb_eArgError, "malformed format string - %%[0-9]");
+ }
if (*p == '$') {
if (nextvalue != Qundef) {
rb_raise(rb_eArgError, "value given twice - %d$", n);
@@ -363,13 +337,15 @@ rb_str_format(argc, argv, fmt)
p++;
goto retry;
}
- CHECK_FOR_WIDTH(flags);
width = n;
flags |= FWIDTH;
goto retry;
case '*':
- CHECK_FOR_WIDTH(flags);
+ if (flags & FWIDTH) {
+ rb_raise(rb_eArgError, "width given twice");
+ }
+
flags |= FWIDTH;
GETASTER(width);
if (width < 0) {
@@ -380,10 +356,10 @@ rb_str_format(argc, argv, fmt)
goto retry;
case '.':
- if (flags & FPREC0) {
+ if (flags & FPREC) {
rb_raise(rb_eArgError, "precision given twice");
}
- flags |= FPREC|FPREC0;
+ flags |= FPREC;
prec = 0;
p++;
@@ -396,12 +372,17 @@ rb_str_format(argc, argv, fmt)
goto retry;
}
- GETNUM(prec, precision);
+ for (; p < end && ISDIGIT(*p); p++) {
+ prec = 10 * prec + (*p - '0');
+ }
+ if (p >= end) {
+ rb_raise(rb_eArgError, "malformed format string - %%.[0-9]");
+ }
goto retry;
case '\n':
- case '\0':
p--;
+ case '\0':
case '%':
if (flags != FNONE) {
rb_raise(rb_eArgError, "illegal format character - %%");
@@ -474,13 +455,13 @@ rb_str_format(argc, argv, fmt)
{
volatile VALUE val = GETARG();
char fbuf[32], nbuf[64], *s, *t;
- const char *prefix = 0;
+ char *prefix = 0;
int sign = 0;
char sc = 0;
long v = 0;
int base, bignum = 0;
int len, pos;
- volatile VALUE tmp;
+ VALUE tmp;
volatile VALUE tmp1;
switch (*p) {
@@ -551,7 +532,6 @@ rb_str_format(argc, argv, fmt)
default:
base = 10; break;
}
-
if (!bignum) {
if (base == 2) {
val = rb_int2big(v);
@@ -697,7 +677,7 @@ rb_str_format(argc, argv, fmt)
else {
char c;
- if (!sign && bignum && !RBIGNUM(val)->sign)
+ if (bignum && !RBIGNUM(val)->sign)
c = sign_bits(base, p);
else
c = '0';
@@ -738,8 +718,6 @@ rb_str_format(argc, argv, fmt)
need = strlen(expr);
if ((!isnan(fval) && fval < 0.0) || (flags & FPLUS))
need++;
- else if (flags & FSPACE)
- need++;
if ((flags & FWIDTH) && need < width)
need = width;
diff --git a/string.c b/string.c
index d625c542a1..08c958d8e4 100644
--- a/string.c
+++ b/string.c
@@ -306,7 +306,6 @@ rb_obj_as_string(obj)
return str;
}
-static VALUE rb_str_s_alloc _((VALUE));
static VALUE rb_str_replace _((VALUE, VALUE));
VALUE
@@ -453,18 +452,23 @@ rb_str_times(str, times)
*/
static VALUE
-rb_str_format_m(str, arg)
+rb_str_format(str, arg)
VALUE str, arg;
{
- volatile VALUE tmp = rb_check_array_type(arg);
+ VALUE *argv;
- if (!NIL_P(tmp)) {
- return rb_str_format(RARRAY_LEN(tmp), RARRAY_PTR(tmp), str);
+ if (TYPE(arg) == T_ARRAY) {
+ argv = ALLOCA_N(VALUE, RARRAY(arg)->len + 1);
+ argv[0] = str;
+ MEMCPY(argv+1, RARRAY(arg)->ptr, VALUE, RARRAY(arg)->len);
+ return rb_f_sprintf(RARRAY(arg)->len+1, argv);
}
- return rb_str_format(1, &arg, str);
-}
-static const char null_str[] = "";
+ argv = ALLOCA_N(VALUE, 2);
+ argv[0] = str;
+ argv[1] = arg;
+ return rb_f_sprintf(2, argv);
+}
static int
str_independent(str)
@@ -476,7 +480,6 @@ str_independent(str)
if (OBJ_FROZEN(str)) rb_error_frozen("string");
if (!OBJ_TAINTED(str) && rb_safe_level() >= 4)
rb_raise(rb_eSecurityError, "Insecure: can't modify string");
- if (RSTRING(str)->ptr == null_str) return 0;
if (!FL_TEST(str, ELTS_SHARED)) return 1;
return 0;
}
@@ -535,20 +538,7 @@ rb_str_associated(str)
return Qfalse;
}
-#define make_null_str(s) do { \
- FL_SET(s, ELTS_SHARED); \
- RSTRING(s)->ptr = (char *)null_str; \
- RSTRING(s)->aux.shared = 0; \
- } while (0)
-
-static VALUE
-rb_str_s_alloc(klass)
- VALUE klass;
-{
- VALUE str = str_alloc(klass);
- make_null_str(str);
- return str;
-}
+static char *null_str = "";
VALUE
rb_string_value(ptr)
@@ -560,7 +550,8 @@ rb_string_value(ptr)
*ptr = s;
}
if (!RSTRING(s)->ptr) {
- make_null_str(s);
+ FL_SET(s, ELTS_SHARED);
+ RSTRING(s)->ptr = null_str;
}
return s;
}
@@ -591,7 +582,8 @@ rb_check_string_type(str)
{
str = rb_check_convert_type(str, T_STRING, "String", "to_str");
if (!NIL_P(str) && !RSTRING(str)->ptr) {
- make_null_str(str);
+ FL_SET(str, ELTS_SHARED);
+ RSTRING(str)->ptr = null_str;
}
return str;
}
@@ -702,19 +694,19 @@ rb_str_resize(str, len)
return str;
}
-static VALUE
-str_buf_cat(str, ptr, len)
+VALUE
+rb_str_buf_cat(str, ptr, len)
VALUE str;
const char *ptr;
long len;
{
- long capa, total, off = -1;;
+ long capa, total;
- rb_str_modify(str);
- if (ptr >= RSTRING(str)->ptr && ptr <= RSTRING(str)->ptr + RSTRING(str)->len) {
- off = ptr - RSTRING(str)->ptr;
+ if (len == 0) return str;
+ if (len < 0) {
+ rb_raise(rb_eArgError, "negative string size (or size too big)");
}
- if (len == 0) return 0;
+ rb_str_modify(str);
if (FL_TEST(str, STR_ASSOC)) {
FL_UNSET(str, STR_ASSOC);
capa = RSTRING(str)->aux.capa = RSTRING(str)->len;
@@ -722,23 +714,13 @@ str_buf_cat(str, ptr, len)
else {
capa = RSTRING(str)->aux.capa;
}
- if (RSTRING(str)->len >= LONG_MAX - len) {
- rb_raise(rb_eArgError, "string sizes too big");
- }
total = RSTRING(str)->len+len;
if (capa <= total) {
while (total > capa) {
- if (capa + 1 >= LONG_MAX / 2) {
- capa = total;
- break;
- }
capa = (capa + 1) * 2;
}
RESIZE_CAPA(str, capa);
}
- if (off != -1) {
- ptr = RSTRING(str)->ptr + off;
- }
memcpy(RSTRING(str)->ptr + RSTRING(str)->len, ptr, len);
RSTRING(str)->len = total;
RSTRING(str)->ptr[total] = '\0'; /* sentinel */
@@ -747,19 +729,6 @@ str_buf_cat(str, ptr, len)
}
VALUE
-rb_str_buf_cat(str, ptr, len)
- VALUE str;
- const char *ptr;
- long len;
-{
- if (len == 0) return str;
- if (len < 0) {
- rb_raise(rb_eArgError, "negative string size (or size too big)");
- }
- return str_buf_cat(str, ptr, len);
-}
-
-VALUE
rb_str_buf_cat2(str, ptr)
VALUE str;
const char *ptr;
@@ -778,7 +747,7 @@ rb_str_cat(str, ptr, len)
}
if (FL_TEST(str, STR_ASSOC)) {
rb_str_modify(str);
- REALLOC_N(RSTRING(str)->ptr, char, RSTRING(str)->len+len+1);
+ REALLOC_N(RSTRING(str)->ptr, char, RSTRING(str)->len+len);
memcpy(RSTRING(str)->ptr + RSTRING(str)->len, ptr, len);
RSTRING(str)->len += len;
RSTRING(str)->ptr[RSTRING(str)->len] = '\0'; /* sentinel */
@@ -800,8 +769,29 @@ VALUE
rb_str_buf_append(str, str2)
VALUE str, str2;
{
- str_buf_cat(str, RSTRING(str2)->ptr, RSTRING(str2)->len);
+ long capa, len;
+
+ rb_str_modify(str);
+ if (FL_TEST(str, STR_ASSOC)) {
+ FL_UNSET(str, STR_ASSOC);
+ capa = RSTRING(str)->aux.capa = RSTRING(str)->len;
+ }
+ else {
+ capa = RSTRING(str)->aux.capa;
+ }
+ len = RSTRING(str)->len+RSTRING(str2)->len;
+ if (capa <= len) {
+ while (len > capa) {
+ capa = (capa + 1) * 2;
+ }
+ RESIZE_CAPA(str, capa);
+ }
+ memcpy(RSTRING(str)->ptr + RSTRING(str)->len,
+ RSTRING(str2)->ptr, RSTRING(str2)->len);
+ RSTRING(str)->len += RSTRING(str2)->len;
+ RSTRING(str)->ptr[RSTRING(str)->len] = '\0'; /* sentinel */
OBJ_INFECT(str, str2);
+
return str;
}
@@ -1657,7 +1647,7 @@ rb_str_splice(str, beg, len, val)
}
beg += RSTRING(str)->len;
}
- if (RSTRING(str)->len < len || RSTRING(str)->len < beg + len) {
+ if (RSTRING(str)->len < beg + len) {
len = RSTRING(str)->len - beg;
}
@@ -2271,18 +2261,9 @@ rb_str_replace(str, str2)
RSTRING(str)->aux.shared = RSTRING(str2)->aux.shared;
}
else {
- if (str_independent(str)) {
- rb_str_resize(str, RSTRING(str2)->len);
- memcpy(RSTRING(str)->ptr, RSTRING(str2)->ptr, RSTRING(str2)->len);
- if (!RSTRING(str)->ptr) {
- make_null_str(str);
- }
- }
- else {
- RSTRING(str)->ptr = RSTRING(str2)->ptr;
- RSTRING(str)->len = RSTRING(str2)->len;
- str_make_independent(str);
- }
+ rb_str_modify(str);
+ rb_str_resize(str, RSTRING(str2)->len);
+ memcpy(RSTRING(str)->ptr, RSTRING(str2)->ptr, RSTRING(str2)->len);
if (FL_TEST(str2, STR_ASSOC)) {
FL_SET(str, STR_ASSOC);
RSTRING(str)->aux.shared = RSTRING(str2)->aux.shared;
@@ -4666,7 +4647,7 @@ Init_String()
rb_cString = rb_define_class("String", rb_cObject);
rb_include_module(rb_cString, rb_mComparable);
rb_include_module(rb_cString, rb_mEnumerable);
- rb_define_alloc_func(rb_cString, rb_str_s_alloc);
+ rb_define_alloc_func(rb_cString, str_alloc);
rb_define_method(rb_cString, "initialize", rb_str_init, -1);
rb_define_method(rb_cString, "initialize_copy", rb_str_replace, 1);
rb_define_method(rb_cString, "<=>", rb_str_cmp_m, 1);
@@ -4676,7 +4657,7 @@ Init_String()
rb_define_method(rb_cString, "casecmp", rb_str_casecmp, 1);
rb_define_method(rb_cString, "+", rb_str_plus, 1);
rb_define_method(rb_cString, "*", rb_str_times, 1);
- rb_define_method(rb_cString, "%", rb_str_format_m, 1);
+ rb_define_method(rb_cString, "%", rb_str_format, 1);
rb_define_method(rb_cString, "[]", rb_str_aref_m, -1);
rb_define_method(rb_cString, "[]=", rb_str_aset_m, -1);
rb_define_method(rb_cString, "insert", rb_str_insert, 2);
diff --git a/struct.c b/struct.c